Method, device, equipment and medium for preventing reversal and abuse of HSM firmware
By applying obfuscation technology based on obfuscation keys in HSM firmware, the reverse cracking and abuse of HSM firmware in automotive SoC chips is solved, and the security and uniqueness of the firmware are achieved, preventing the risk of technical leakage and safety accidents.
Patent Information
- Application Number
- CN202411896391.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2044-12-23
AI Technical Summary
The security of HSM firmware in automotive SoC chips is threatened by reverse cracking and abuse, resulting in the risk of technological leakage, economic losses and safety accidents.
Through obfuscation technology based on obfuscation keys, code execution process encryption, key address obfuscation and string access encryption are configured, different obfuscation technology combinations are generated, and the corresponding HSM firmware is compiled to establish the corresponding relationship between obfuscation key, HSM firmware version number and firmware.
Effectively prevent HSM firmware from being reversely cracked, relying on obfuscated keys in eFuse, preventing abuse and secondary sales after firmware leakage, ensuring the security and uniqueness of HSM firmware, and preventing a single customer firmware version from affecting other versions and customers' security after being cracked.
Smart Images

Figure CN119377920B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information security technology, and in particular to a method, device, equipment and medium for preventing reversal and abuse of HSM firmware. Background Art
[0002] Modern cars are increasingly dependent on complex electronic control units (ECUs) and system-on-chips (SoCs), which run a large amount of firmware and software. The firmware is responsible for controlling and managing various functions of the car, such as the engine, braking system, in-car entertainment system, etc. With the development of Internet of Vehicles technology, cars are increasingly connected to external networks and cloud services. This connectivity increases the risk of cyber attacks and malware faced by automotive systems.
[0003] HSM (Hardware Security Module) is a specially designed hardware device that is mainly used to protect sensitive data and ensure the security of encryption processes, such as in financial transactions, digital signatures, identity authentication and other fields. HSM usually has physical protection measures to prevent unauthorized access and attacks. In automotive electronics, HSM is used to protect the vehicle's electronic systems and data from attacks. The role of HSM in automotive chip SoC is crucial. It provides data encryption, key management, secure boot, authentication and Internet of Vehicles communication protection. Through these functions, HSM ensures the overall security and data privacy of the vehicle system, preventing malicious attacks and data leakage.
[0004] As the security anchor of automotive SoC chips, the firmware security of HSM has attracted much attention. Cracking of HSM firmware will cause technology leakage and economic losses to enterprises, and in serious cases, it will cause safety accidents and threaten the lives of drivers and passengers. Therefore, how to protect HSM firmware from reverse cracking and unauthorized use has become an urgent problem to be solved. Summary of the invention
[0005] The present application provides a method, device, equipment and medium for preventing the reversal and abuse of HSM firmware, which can effectively prevent the HSM firmware from being reverse cracked, resold and other problems.
[0006] In a first aspect, an embodiment of the present application provides a method for preventing reversal and abuse of HSM firmware, and the method for preventing reversal and abuse of HSM firmware includes:
[0007] Based on the obfuscation key, configure the relevant obfuscation technology to apply to the specified key function, and use the obfuscation key as a parameter of the obfuscation behavior at compile time;
[0008] The obfuscation key is used as the parameter of the obfuscation technology combination, and the version number of the HSM firmware is combined to generate different obfuscation technology combinations, and the corresponding HSM firmware is compiled;
[0009] Establish the correspondence between the obfuscation key, HSM firmware version number, and HSM firmware;
[0010] Among them, the related obfuscation technologies include code execution process encryption processing, key address obfuscation, and string access encryption.
[0011] In conjunction with the first aspect, in one implementation, the encryption process for the code execution process specifically includes:
[0012] Randomly take a value from the obfuscated key of the eFuse, and randomly select an operator of a relational operation expression during conditional comparison, or an operator of a relational operation expression and a logical operator of a combined relational operation expression;
[0013] Combining random values with selected operators, or combining random values with selected operators and logical operators, selects immediate values and constructs constant conditions;
[0014] Depending on the type of constant condition:
[0015] When it is a constant true condition, the code jumps to the basic block when the condition is met;
[0016] When it is a false condition, the code jumps to the basic block when the condition is not met.
[0017] In combination with the first aspect, in one implementation,
[0018] The operators of the relational operation expression include greater than, less than, equal to, greater than or equal to, less than or equal to, and not equal to;
[0019] The logical operators of the combined relational operation expression include AND, OR, and NOT;
[0020] The key parameters of the constant condition include the number of relational operation expressions, the operator selected for each relational operation expression, the logical operator used to combine the relational operation expressions, and the constant condition type.
[0021] In combination with the first aspect, in one implementation,
[0022] The key address obfuscation includes function address encryption, global variable access encryption, and branch jump encryption;
[0023] The function address encryption is applicable to the function call instruction, which is used to achieve the obfuscation of the called function address;
[0024] The applicable object of the global variable access encryption is the instruction that references the global variable, which is used to achieve the obfuscation of the referenced global variable address;
[0025] The branch jump encryption is applicable to jump instructions, which are used to implement jump address obfuscation.
[0026] In combination with the first aspect, in one implementation,
[0027] The key address obfuscation includes an offset processing logic and a de-offset instruction insertion logic;
[0028] The offset processing logic specifically includes:
[0029] Perform offset calculation on the key address to obtain an offset address and an index, where the index is the subscript of the offset address in the global obfuscated address array;
[0030] Associating the index with the obfuscation key for obtaining an offset parameter in the offset calculation in the obfuscation key;
[0031] The de-skew instruction insertion logic specifically includes:
[0032] Get the offset address from the global obfuscation address array according to the index, get the offset parameter from the obfuscation key, and calculate the key address by combining the obtained offset address and offset parameter;
[0033] Insert an instruction set of the key address obtained from the offset address. Based on the type of the key address, for function call instructions, replace the function call instruction with a call to the key address; for global variable access, replace the global variable access with a reference to the original address data; for jump instructions, replace the jump instruction with a jump to the key address.
[0034] In conjunction with the first aspect, in one implementation, the string access encryption specifically includes:
[0035] XOR-encrypt the original string based on the obfuscation key, and concatenate all the encrypted strings to form a global encryption array. The starting position and length of the encrypted string are recorded during the concatenation operation.
[0036] Insert a string decryption function into the HSM firmware, perform XOR decryption on the global encryption array based on the obfuscation key, decrypt to obtain a new string, and change the string reference instruction to reference the new string;
[0037] The input parameters of the string decryption function are the starting position and length of the recorded encrypted string.
[0038] In combination with the first aspect, in one implementation, the obfuscation key is used as a parameter of the obfuscation technology combination, and different obfuscation technology combinations are generated in combination with the version number of the HSM firmware, and the corresponding HSM firmware is compiled, specifically including:
[0039] The obfuscation key and the HSM firmware version number are used as factors for generating obfuscation parameters to generate obfuscation parameters, thereby compiling different HSM firmwares. The obfuscation parameters include the number of relational operation expressions during code execution process encryption, the operator selected for each relational operation expression, the logical operator used for combining relational operation expressions, the constant condition type, and the characterization operator between the key parameter and the offset parameter during key address obfuscation.
[0040] In a second aspect, an embodiment of the present application provides an anti-reversal and anti-abuse device for HSM firmware, wherein the anti-reversal and anti-abuse device for HSM firmware includes:
[0041] A configuration module, which is used to configure related obfuscation technologies based on an obfuscation key to apply to a specified key function, and use the obfuscation key as a parameter of the obfuscation behavior at compile time;
[0042] A generation module, which is used to use the obfuscation key as a parameter of the obfuscation technology combination, combine the version number of the HSM firmware to generate different obfuscation technology combinations, and compile to obtain the corresponding HSM firmware;
[0043] Establish a module for establishing a correspondence between an obfuscation key, an HSM firmware version number, and an HSM firmware;
[0044] Among them, the related obfuscation technologies include code execution process encryption processing, key address obfuscation, and string access encryption.
[0045] In a third aspect, an embodiment of the present application provides an anti-reversal and anti-abuse device for HSM firmware, wherein the anti-reversal and anti-abuse device for HSM firmware comprises a processor, a memory, and an anti-reversal and anti-abuse program for HSM firmware stored in the memory and executable by the processor, wherein when the anti-reversal and anti-abuse program for HSM firmware is executed by the processor, the steps of the anti-reversal and anti-abuse method for HSM firmware described above are implemented.
[0046] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which is stored an anti-reversal and abuse program for HSM firmware. When the anti-reversal and abuse program for HSM firmware is executed by a processor, the steps of the above-mentioned anti-reversal and abuse method for HSM firmware are implemented.
[0047] The beneficial effects brought by the technical solution provided in the embodiments of the present application include:
[0048] (1) By using obfuscation techniques such as code execution process encryption, key address obfuscation, and string access encryption on the HSM firmware of the SoC, the firmware can be effectively prevented from being reverse cracked. At the same time, the obfuscation process relies on the obfuscation key in the eFuse, so that the runtime firmware relies on the obfuscation key, effectively preventing abuse and secondary sales after the firmware is leaked;
[0049] (2) The obfuscation key and HSM version number are used as factors for generating obfuscation parameters. Different obfuscation keys are written for SoCs sold to different manufacturers, and the HSM version number is bound to the obfuscation parameters. The same code will generate different HSM firmware after different obfuscation parameter combinations. This can effectively prevent a single customer firmware version from being cracked and affecting the security of subsequent versions and other customers' HSM firmware. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 A flowchart of a method for preventing reversal and abuse of HSM firmware in this application;
[0051] Figure 2 This is a schematic diagram of the encryption effect of the code execution process;
[0052] Figure 3 This is a schematic diagram of the key address obfuscation process;
[0053] Figure 4 A schematic diagram of the functional modules of the anti-reversal and anti-abuse device of the HSM firmware of this application;
[0054] Figure 5 Schematic diagram of the hardware structure of the anti-reversal and anti-abuse device of the HSM firmware of this application. DETAILED DESCRIPTION
[0055] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0056] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0057] In a first aspect, an embodiment of the present application provides a method for preventing reversal and abuse of HSM firmware.
[0058] First of all, it should be noted that the application of HSM in vehicles mainly includes the following aspects: 1. Data encryption, protecting data in vehicle communications, such as information on the vehicle network (CAN bus), ensuring the confidentiality and integrity of data during transmission; 2. Key management, securely generating, storing and managing encryption keys for various electronic systems and applications in automobiles; 3. Authentication, ensuring the identity of vehicles and vehicle systems, and preventing unauthorized devices or users from accessing key functions; 4. Software updates, providing security guarantees during the software update process of the vehicle system to prevent the implantation and tampering of malicious software. Through the above functions, HSM helps improve the security and reliability of automotive electronic systems. Usually, HSM is equipped with a dedicated eFuse (electronic fuse) to enhance security and prevent illegal access.
[0059] In one embodiment, referring to Figure 1 , Figure 1 This is a flowchart of the method for preventing reverse engineering and abuse of HSM firmware in this application. Figure 1 As shown, methods to prevent reversal and abuse of HSM firmware include:
[0060] S1: Based on the obfuscation key, configure relevant obfuscation technology to apply to the specified key function, and use the obfuscation key as a parameter of the obfuscation behavior at compile time; the relevant obfuscation technology includes code execution process encryption processing, key address obfuscation, and string access encryption;
[0061] Specifically, based on the obfuscation key (OBFK) in the eFuse, obfuscation techniques such as code execution process encryption, key address obfuscation, and string access encryption can be used to apply obfuscation techniques to certain designated key functions in the HSM firmware. At the same time, the obfuscation key can be used as a parameter for the obfuscation behavior at compile time, such as a key for string encryption, so that the runtime firmware relies on the obfuscation key to prevent abuse and secondary sales after the firmware is leaked.
[0062] S2: Use the obfuscation key as a parameter of the obfuscation technology combination, combine it with the version number of the HSM firmware, generate different obfuscation technology combinations, and compile to obtain the corresponding HSM firmware;
[0063] S3: Establish the correspondence between the obfuscation key, HSM firmware version number, and HSM firmware.
[0064] Specifically, the obfuscation key is used as a parameter of the obfuscation technology combination, and combined with the version number of the HSM firmware to generate different obfuscation technology combinations, thereby compiling different HSM firmwares. At the same time, a one-to-one correspondence is formed between the obfuscation key, the HSM firmware version number, and the HSM firmware to avoid the overall security risks caused by the cracking of a single customer and a single version of the HSM firmware.
[0065] It should be noted that for eFuse, the eFuse chip is an integrated circuit used to store and protect information. Its main function is to provide the system with unchangeable configuration data, keys and other important information. The main features of eFuse include: 1. One-way programmability. The eFuse chip cannot be changed after programming, which means that once the data is written, it cannot be modified or deleted. This feature is suitable for storing important information such as security keys and encryption parameters; 2. Security. The data stored in eFuse can be used for device authentication, encryption and decryption operations, and secure startup, thereby protecting the device from unauthorized access and tampering; 3. Reliability. The eFuse chip has high durability and stability and can work stably for a long time in harsh environments. eFuse chips are widely used in consumer electronics, automobiles, communication equipment and other fields to help ensure the security of equipment and data.
[0066] It should be noted that code obfuscation technology is a technology that protects software source code, which aims to prevent the code from being stolen or cracked by making the code more difficult to understand and reverse engineer.
[0067] It should be noted that the encryption of the code execution process is aimed at the sequential execution process without jumps. The control flow of the original function is modified by adding conditional jumps in the middle. When adding conditional jumps, the basic block (Original Block) is copied to obtain a copy basic block (Copy Block), and then the instructions in the Copy Block are randomly replaced and reordered. The added conditional jump instructions point to the Original Block and Copy Block. The added conditional jump instructions always calculate the same value at runtime, ensuring that only the OriginalBlock is executed during the runtime.
[0068] Furthermore, in one embodiment, the encryption process of the code execution process specifically includes:
[0069] S101: randomly taking a value from the obfuscated key of the eFuse, and randomly selecting an operator of a relational operation expression during conditional comparison, or an operator of a relational operation expression and a logical operator of a combined relational operation expression;
[0070] S102: Combining the random value and the selected operator, or combining the random value and the selected operator and the logical operator, selecting an immediate value and constructing a constant condition;
[0071] S103: According to the type of constant condition:
[0072] When it is a constant true condition, the code jumps to the basic block when the condition is met;
[0073] When it is a false condition, the code jumps to the basic block when the condition is not met.
[0074] For example, a value is randomly taken from the obfuscated key of the eFuse, and the value is 5. Then, an operator of the relational operation expression during the conditional comparison is randomly selected. For example, if the selected operator is greater than, then an immediate value is selected in combination with the random value and the selected operator to construct a constant condition. For example, if the selected immediate value is 6, since the value 5 is not greater than the immediate value 6, the type of the constructed constant condition is a always false condition. If the selected immediate value is 4, since the value 5 is greater than the immediate value 4, the type of the constructed constant condition is a always true condition.
[0075] Specifically, the present application can design a constant condition generation module, which is used to generate constant conditional statements when the code execution process is encrypted. The constant condition generation module will randomly take values from the obfuscated key, and the value size can be 1 byte, 2 bytes or 4 bytes, and then conditionally compare the value data with the immediate number. In the present application, the operators of the relational operation expression include greater than, less than, equal to, greater than or equal to, less than or equal to, and not equal to. The logical operators of the combined relational operation expression include AND, OR, and NOT. Constant conditional statements are divided into two types: true conditions and false conditions. When it is a true condition, the code jumps to the Original Block when the condition is met; when it is a false condition, the code jumps to the Original Block when the condition is not met, ensuring that the code execution process always goes to the Original Block.
[0076] In an example, for an expression: (X1>5)&&(Y4== 72), X1 represents a 1-byte value taken from OBFK, and Y4 is a 4-byte value. They are respectively subjected to relational operations with the immediate values 5 and 72, and the results are then subjected to AND operations to obtain the conditional statement for the conditional jump. Figure 2 As shown, it can be seen that it is a constant true condition. Since the configuration parameters of the constant condition generation module include the value of OBFK, when generating the constant true condition, it can be based on X 1、 The actual value of Y4 is used to select the immediate number that makes the condition true, thereby ensuring that the condition is always true, and further ensuring that the code can still be executed according to the expected process when it is executed.
[0077] It can be seen that the key parameters of the constant condition include the number of relational operation expressions, the operator selected for each relational operation expression, the logical operator used to combine the relational operation expressions, and the constant condition type (always true or always false). These four parameters jointly affect the generation of the relational operation expression of the constant condition.
[0078] For the expression in the above example, there are 2 relational expressions, namely (X1>5) and (Y4== 72). The operators of the relational expressions are > and ==. The logical operator used to combine relational expressions is &&. The constant condition type is always true. The expression is changed to (X1>α)&&(Y4== β). The immediate values 5 and 72 are a set of special solutions of α and β. The calculation process is combined with X 1、 The Y4 value is a set of solutions obtained by flipping the expression as a whole and then randomly selected from the set.
[0079] In computer architecture and programming, an immediate value is a constant value included directly in an instruction. An immediate value is a simple and efficient way to embed a fixed value directly into an instruction without reading it from memory or passing it through a register. Assembly language example: MOV R0, #10 means loading the immediate value 10 into register R0; ADD R1, R0, #5 means adding the immediate value 5 to the value of register R0 and storing it in register R1.
[0080] Furthermore, in the present application, key address obfuscation includes function address encryption, global variable access encryption, and branch jump encryption; the applicable object of function address encryption is function call instructions, which are used to achieve obfuscation of the called function address; the applicable object of global variable access encryption is instructions for referencing global variables, which are used to achieve obfuscation of the referenced global variable addresses; the applicable object of branch jump encryption is jump instructions, which are used to achieve obfuscation of jump addresses.
[0081] Furthermore, the key address obfuscation includes offset processing logic and de-offset instruction insertion logic;
[0082] The offset processing logic includes:
[0083] S1111: perform offset calculation on the key address to obtain an offset address and an index, where the index is the subscript of the offset address in the global obfuscation address array; in actual applications, the key address may be a key address specified in the HSM firmware that has a greater impact on the HSM firmware.
[0084] Specifically, an offset addition module and a de-offset instruction insertion module can be designed for key address obfuscation. The offset addition module is used to calculate the key address. The input is the key address, and the output is the index (x for short) and the offset address after the key address is offset. The offset addition module is also responsible for the maintenance of the global obfuscated address array.
[0085] S1112: Associating the index with the obfuscation key, so as to obtain an offset parameter in the offset addition calculation in the obfuscation key.
[0086] The above offset processing logic can be expressed as follows in one example:
[0087] Offset parameter = OBFK[x % OBFK length]
[0088] Offset address = key address ◎Offset parameter
[0089] Global obfuscation array [x] = offset address
[0090] The ◎ operator is a characterization operator defined by the add-offset module, which can be one of addition, subtraction, AND operation, and XOR operation.
[0091] The main work content of the de-offset instruction insertion module is to insert the de-offset instruction set before the function call instruction, before the global variable access and before the branch jump. The function of the de-offset instruction set is to de-offset the above offset address to obtain the original key address.
[0092] The de-skew instruction insertion logic includes:
[0093] S1121: Obtain an offset address from the global obfuscation address array according to the index, obtain an offset parameter from the obfuscation key, and calculate a key address by combining the obtained offset address and offset parameter;
[0094] S1122: Insert an instruction set of the key address obtained from the offset address. Based on the type of the key address, for function call instructions, replace the function call instruction with a call to the key address; for global variable access, replace the global variable access with a reference to the original address data; for jump instructions, replace the jump instruction with a jump to the key address.
[0095] Specifically, the input of the offset removal instruction insertion module is index x and the global obfuscation address array. First, the offset address is taken out from the global obfuscation address array according to index x, and then the offset parameter is obtained from the obfuscation key according to index x, and the key address is calculated by combining the offset address and the offset parameter. For step S1121, in an example, it can be expressed as:
[0096] Offset address = global obfuscation array [x]
[0097] Offset parameter = OBFK[x % OBFK length]
[0098] Key address = offset address ⊙ offset parameter
[0099] The ⊙ operator is the inverse operation of the ◎ operator in the add offset module, and correspondingly, it can be one of subtraction, addition, OR operation, and XOR operation.
[0100] After obtaining the key address, the original instruction is replaced. First, the instruction set that obtains the key address from the offset address is inserted, and then different replacement operations are performed for different types of key addresses. For function call instructions, it is replaced with a call to the key address; for global variable access, it is replaced with a reference to the original address data; for jump instructions, it is replaced with a jump to the key address.
[0101] The technical principle of key address obfuscation is as follows: for the HSM firmware source code containing the key address, the offset module is added to confuse the key address to obtain the offset address, and then the offset instruction insertion module inserts the code logic that restores the offset address to the original key address to obtain the obfuscated code. The obfuscated code is compiled to obtain the obfuscated firmware.
[0102] The offset adding module and the offset removing instruction insertion module jointly complete the obfuscation of the key address. The input and output are as follows: Figure 3 As shown. The input parameter of the offset adding module is the ◎ operator, which can be a choice of subtraction, addition, or operation, or XOR operation, which can be selected as needed. The output of the offset adding module is the offset address, index x, and the inverse operation ⊙ operator, which will also be used as the input of the de-offset instruction insertion module to generate the final code obfuscation instruction set.
[0103] Furthermore, string access encryption includes:
[0104] S121: XOR-encrypting the original string based on the obfuscation key, and concatenating all encrypted strings to form a global encryption array, and recording the starting position and length of the encrypted string during the concatenation operation;
[0105] S122: Insert a string decryption function into the HSM firmware, perform XOR decryption on the global encryption array based on the obfuscation key, decrypt to obtain a new string, and change the string reference instruction to reference the new string; wherein the input parameter of the string decryption function is the starting position and length of the recorded encrypted string.
[0106] The obfuscation technology principle for string access encryption is described as follows.
[0107] During the compilation process, all referenced strings are compiled, encrypted using the obfuscation key, and concatenated into a global encryption array. Then, the string decryption function logic is inserted, and the original string reference is replaced by decrypting the global encryption array and then referencing it.
[0108] During the running process, the string reference is triggered, the string decryption function is called, the obfuscation key is used to decrypt the global encryption array, the decrypted data is saved as a new string, and then the new string is referenced.
[0109] Through the above obfuscation technologies, you can configure them at compile time. By filtering the function names, you can support the application of the configured obfuscation technology to the specified key functions to reduce the impact of the increase in firmware size and the decrease in execution efficiency caused by obfuscation.
[0110] Furthermore, the obfuscation key is used as a parameter of the obfuscation technology combination, and different obfuscation technology combinations are generated in combination with the version number of the HSM firmware, and the corresponding HSM firmware is compiled, including:
[0111] The obfuscation key and the HSM firmware version number are used as factors for generating obfuscation parameters to generate obfuscation parameters, thereby compiling different HSM firmwares. The obfuscation parameters include the number of relational operation expressions during code execution process encryption, the operator selected for each relational operation expression, the logical operator used for combining relational operation expressions, the constant condition type, and the characterization operator between the key parameter and the offset parameter during key address obfuscation.
[0112] Specifically, an obfuscation parameter generation module can be designed, and the obfuscation key and HSM firmware version number can be used as factors for generating obfuscation parameters to generate obfuscation parameters and compile different firmware. This can achieve the following: (1) Writing different OBFKs to HSM chips sold to different customers so that these chips correspond to different firmware versions, which can prevent a single customer firmware version from being cracked and affecting the security of subsequent versions and other customers' HSM firmware; (2) Using OBFK and version number as factors for generating obfuscation parameters, different obfuscation technologies can be used for each version of each customer to generate different versions of firmware, thereby achieving the goal of not affecting the security of other versions if a single version is cracked.
[0113] The above obfuscation parameters include the number of relational operation expressions during the encryption process of the code execution process, the operator selected for each relational operation expression, the logical operator used for the combined relational operation expression, the constant condition type, and the characterization operator between the key parameter and the offset parameter during the key address obfuscation. The input of the obfuscation parameter generation module is the obfuscation key and the HSM firmware version number, and the output is the above 5 obfuscation parameters. The obfuscation parameter generation module is a pre-module used to guide the execution of the obfuscation technology.
[0114] In one embodiment, in order to achieve a sufficient diffusion effect, the OBFK and the version number may be used as inputs of a hash function, and the hash function may select SHA256, and the generated 32-byte hash value may be divided into meanings for selecting different parameters, as shown in Table 1 below.
[0115] Table 1
[0116]
[0117] In view of the defect that the current obfuscation technology can only increase the difficulty of reverse analysis to a certain extent, but cannot completely block the possibility of reverse analysis of the correct code logic, this application introduces OBFK into the process of code obfuscation. Under the condition that the reverse engineer cannot get OBFK, the intention of reverse analysis to discover the real code flow can be completely blocked. OBFK is written into eFuse by the chip manufacturer during the production stage. It cannot be modified after writing and usually has read security protection. If the manufacturer does not disclose OBFK, its reverse analysis difficulty is much higher than the existing technology.
[0118] The anti-reversal and anti-abuse method of the HSM firmware of the embodiment of the present application effectively prevents the firmware from being reverse cracked by performing obfuscation technologies such as code execution process encryption, key address obfuscation, and string access encryption on the HSM firmware of the SoC. At the same time, the obfuscation process relies on the obfuscation key in the eFuse, so that the runtime firmware relies on the obfuscation key, which effectively prevents abuse and secondary sales after the firmware is leaked; the obfuscation key and the HSM version number are used as generation factors of the obfuscation parameters, different obfuscation keys are written for SoCs sold to different manufacturers, and the HSM version number is bound to the obfuscation parameters. The same code will generate different HSM firmware after different obfuscation parameter combinations, which can effectively prevent a certain version of a single customer's firmware from being cracked, affecting the security of subsequent versions and other customers' HSM firmware.
[0119] In a second aspect, an embodiment of the present application also provides an anti-reversal and anti-abuse device for HSM firmware.
[0120] In one embodiment, referring to Figure 4 , Figure 4 This is a functional module diagram of the anti-reversal and abuse device of the HSM firmware of this application. Figure 4 As shown, the anti-reversal and anti-abuse device of the HSM firmware includes: a configuration module, a generation module, and a creation module.
[0121] The configuration module is used to configure the relevant obfuscation technology based on the obfuscation key to apply to the specified key function, and use the obfuscation key as the parameter of the obfuscation behavior during compilation; the generation module is used to use the obfuscation key as the parameter of the obfuscation technology combination, and generate different obfuscation technology combinations in combination with the version number of the HSM firmware, and compile to obtain the corresponding HSM firmware; the establishment module is used to establish the corresponding relationship between the obfuscation key, the HSM firmware version number, and the HSM firmware. Among them, the relevant obfuscation technology includes code execution process encryption processing, key address obfuscation, and string access encryption.
[0122] In a third aspect, an embodiment of the present application provides an anti-reversal and anti-abuse device for HSM firmware. The anti-reversal and anti-abuse device for HSM firmware can be a personal computer (PC), a laptop computer, a server, or other device with data processing functions.
[0123] Reference Figure 5 , Figure 5 The hardware structure diagram of the anti-reversal and abuse device of the HSM firmware involved in the embodiment of the present application is shown in FIG. In the embodiment of the present application, the anti-reversal and abuse device of the HSM firmware may include a processor, a memory, a communication interface, and a communication bus.
[0124] The communication bus may be of any type and is used to interconnect the processor, the memory, and the communication interface.
[0125] The communication interface includes input / output (I / O) interface, physical interface and logical interface, etc., which are used to interconnect the devices inside the HSM firmware anti-reversal and anti-abuse device, and the interface used to interconnect the HSM firmware anti-reversal and anti-abuse device with other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, a fiber optic interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.
[0126] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0127] The processor may be a general-purpose processor, which may call the anti-reversal and abuse program of the HSM firmware stored in the memory, and execute the anti-reversal and abuse method of the HSM firmware provided in the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). The method executed when the anti-reversal and abuse program of the HSM firmware is called may refer to the various embodiments of the anti-reversal and abuse method of the HSM firmware of the present application, which will not be repeated here.
[0128] Those skilled in the art will understand that Figure 5The hardware structure shown in the figure does not constitute a limitation on the present application, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0129] In a fourth aspect, an embodiment of the present application also provides a computer-readable storage medium.
[0130] The computer-readable storage medium of the present application stores an anti-reversal and anti-abuse program for HSM firmware, wherein when the anti-reversal and anti-abuse program for HSM firmware is executed by a processor, the steps of the anti-reversal and anti-abuse method for HSM firmware as described above are implemented.
[0131] Among them, the method implemented when the anti-reversal and abuse program of the HSM firmware is executed can refer to the various embodiments of the anti-reversal and abuse method of the HSM firmware of the present application, and will not be repeated here.
[0132] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.
[0133] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.
[0134] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; the “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.
[0135] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.
[0136] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.
[0137] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for preventing reversal and abuse of HSM firmware, characterized in that: The HSM firmware anti-reversal and anti-abuse methods include: Based on the obfuscation key, configure the relevant obfuscation technology to apply to the specified key function, and use the obfuscation key as a parameter of the obfuscation behavior at compile time; The obfuscation key is used as the parameter of the obfuscation technology combination, and the version number of the HSM firmware is combined to generate different obfuscation technology combinations, and the corresponding HSM firmware is compiled; Establish the correspondence between the obfuscation key, HSM firmware version number, and HSM firmware; Among them, the relevant obfuscation technologies include code execution process encryption processing, key address obfuscation, and string access encryption; The encryption process of code execution process includes: Randomly take a value from the obfuscated key of the eFuse, and randomly select an operator of a relational operation expression during conditional comparison, or an operator of a relational operation expression and a logical operator of a combined relational operation expression; Combining random values with selected operators, or combining random values with selected operators and logical operators, selects immediate values and constructs constant conditions; Depending on the type of constant condition: When it is a constant true condition, the code jumps to the basic block when the condition is met; When it is a false condition, the code jumps to the basic block when the condition is not met.
2. A method for preventing reversal and abuse of HSM firmware as claimed in claim 1, characterized in that: The operators of the relational operation expression include greater than, less than, equal to, greater than or equal to, less than or equal to, and not equal to; The logical operators of the combined relational operation expression include AND, OR, and NOT; The key parameters of the constant condition include the number of relational operation expressions, the operator selected for each relational operation expression, the logical operator used to combine the relational operation expressions, and the constant condition type.
3. A method for preventing reversal and abuse of HSM firmware as claimed in claim 1, characterized in that: The key address obfuscation includes function address encryption, global variable access encryption, and branch jump encryption; The function address encryption is applicable to the function call instruction, which is used to achieve the obfuscation of the called function address; The applicable object of the global variable access encryption is the instruction that references the global variable, which is used to achieve the obfuscation of the referenced global variable address; The branch jump encryption is applicable to jump instructions, which are used to implement jump address obfuscation.
4. A method for preventing reversal and abuse of HSM firmware as claimed in claim 3, characterized in that: The key address obfuscation includes an offset processing logic and a de-offset instruction insertion logic; The offset processing logic specifically includes: Perform offset calculation on the key address to obtain an offset address and an index, where the index is the subscript of the offset address in the global obfuscated address array; Associating the index with the obfuscation key for obtaining an offset parameter in the offset calculation in the obfuscation key; The de-skew instruction insertion logic specifically includes: Get the offset address from the global obfuscation address array according to the index, get the offset parameter from the obfuscation key, and calculate the key address by combining the obtained offset address and offset parameter; Insert an instruction set of the key address obtained from the offset address. Based on the type of the key address, for function call instructions, replace the function call instruction with a call to the key address; for global variable access, replace the global variable access with a reference to the original address data; for jump instructions, replace the jump instruction with a jump to the key address.
5. A method for preventing reversal and abuse of HSM firmware as claimed in claim 1, characterized in that: For string access encryption, specifically including: XOR-encrypt the original string based on the obfuscation key, and concatenate all the encrypted strings to form a global encryption array. The starting position and length of the encrypted string are recorded during the concatenation operation. Insert a string decryption function into the HSM firmware, perform XOR decryption on the global encryption array based on the obfuscation key, decrypt to obtain a new string, and change the string reference instruction to reference the new string; The input parameters of the string decryption function are the starting position and length of the recorded encrypted string.
6. A method for preventing reversal and abuse of HSM firmware as claimed in claim 1, characterized in that: The obfuscation key is used as a parameter of the obfuscation technology combination, and different obfuscation technology combinations are generated in combination with the version number of the HSM firmware, and the corresponding HSM firmware is compiled, specifically including: The obfuscation key and the HSM firmware version number are used as factors for generating obfuscation parameters to generate obfuscation parameters, thereby compiling different HSM firmwares. The obfuscation parameters include the number of relational operation expressions during code execution process encryption, the operator selected for each relational operation expression, the logical operator used for combining relational operation expressions, the constant condition type, and the characterization operator between the key parameter and the offset parameter during key address obfuscation.
7. A device for preventing reversal and abuse of HSM firmware, characterized in that: The HSM firmware's anti-reversal and abuse features include: A configuration module, which is used to configure related obfuscation technologies based on an obfuscation key to apply to a specified key function, and use the obfuscation key as a parameter of the obfuscation behavior at compile time; A generation module, which is used to use the obfuscation key as a parameter of the obfuscation technology combination, combine the version number of the HSM firmware to generate different obfuscation technology combinations, and compile to obtain the corresponding HSM firmware; Establish a module for establishing a correspondence between an obfuscation key, an HSM firmware version number, and an HSM firmware; Among them, the relevant obfuscation technologies include code execution process encryption processing, key address obfuscation, and string access encryption; The encryption process of code execution process includes: Randomly take a value from the obfuscated key of the eFuse, and randomly select an operator of a relational operation expression during conditional comparison, or an operator of a relational operation expression and a logical operator of a combined relational operation expression; Combining random values with selected operators, or combining random values with selected operators and logical operators, selects immediate values and constructs constant conditions; Depending on the type of constant condition: When it is a constant true condition, the code jumps to the basic block when the condition is met; When it is a false condition, the code jumps to the basic block when the condition is not met.
8. A device for preventing reversal and abuse of HSM firmware, characterized in that: The HSM firmware anti-reversal and anti-abuse device includes a processor, a memory, and an HSM firmware anti-reversal and anti-abuse program stored in the memory and executable by the processor, wherein when the HSM firmware anti-reversal and anti-abuse program is executed by the processor, the steps of the HSM firmware anti-reversal and anti-abuse method as described in any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an anti-reversal and anti-abuse program for HSM firmware, wherein when the anti-reversal and anti-abuse program for HSM firmware is executed by a processor, the steps of the anti-reversal and anti-abuse method for HSM firmware as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Software generation method and device
CN108804880A
Enhanced secure boot
CN109983465A
Application program running method and device, electronic equipment and readable storage medium
CN110008662A