An MCU program encryption and decryption method

By performing logical operations on MCU program instructions and addresses at the compiler level to generate encrypted instructions, and then performing hardware decryption in the MCU chip, the problem of MCU programs being easily cracked is solved, achieving low-cost and efficient program protection.

CN116561715BActive Publication Date: 2026-06-30WUXI SIJIE MICROELECTRONICS CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
WUXI SIJIE MICROELECTRONICS CO LTD
Filing Date
2019-12-20
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing MCU programs are easily decompiled and cracked, leading to the risk of intellectual property leakage. Existing encryption methods cannot effectively protect MCU programs.

Method used

The compiler performs logical operations on program instructions and addresses to generate encrypted instructions, and then performs hardware decryption in the MCU chip through built-in decryption combinational logic circuits, using the unique correlation between program addresses and instructions to achieve encryption.

Benefits of technology

The encrypted program instructions are unpredictable, making them difficult to decompile or crack. They are also low-cost and difficult to decipher, effectively protecting the intellectual property rights of MCU programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116561715B_ABST
    Figure CN116561715B_ABST
Patent Text Reader

Abstract

This divisional application relates to the field of MCU program encryption technology, and in particular to an MCU program encryption and decryption method. Specifically, when writing an MCU program using software, the program instructions are encrypted at the compiler level. Encrypted program instructions are generated by performing logical operations on the program instructions and their corresponding instruction addresses. The encrypted program instructions are then decrypted in the chip using built-in decryption logic circuits. This invention, based on the unique correlation between program addresses and program instructions, achieves encryption and decryption of the MCU program through software encryption and hardware decryption. The encrypted program instructions are unpredictable, and the instructions read during chip programming and use cannot be decompiled or cracked. Since the MCU program is encrypted binary machine code in the ROM, directly reading the chip's ROM module via pin piercing also fails to decipher it. The encryption and decryption method described in this application is low-cost, has good encryption effect, and is difficult to decrypt.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application of application number 201911325274.7, application date December 20, 2019, and invention title "A Method for Encrypting and Decrypting MCU Programs". Technical Field

[0002] This invention relates to the field of MCU program encryption technology, and in particular to a method for encrypting and decrypting MCU programs. Background Technology

[0003] Conventional RISC (Reduced Instruction Set Computing) systems are simple and easy to use, and the compiled binary machine code is relatively easy to understand. However, this also makes them vulnerable to decompilation into assembly instructions, leading to program cracking and even porting to similar alternative chips. For MCU solution designers, the developed MCU program is intellectual property and needs protection. Existing MCU development, encryption, programming, and decryption processes, such as... Figure 1 As shown, from Figure 1 As can be seen, although designers implement encryption protection at the chip level, making the program generally unreadable, the source code can still be deciphered by analyzing the programming timing with the help of programming documentation and a programmer. Therefore, the developed program is not fully protected, and there remains a risk of intellectual property leakage for MCU solution designers. Thus, a simple and effective encryption method is urgently needed to solve the problem of MCU programs being easily cracked. Summary of the Invention

[0004] To address the problems in the existing technology, this invention provides a method for encrypting and decrypting MCU programs.

[0005] To achieve the above technical objectives, the technical solution of the present invention is as follows:

[0006] An MCU program encryption and decryption method involves encrypting program instructions at the compiler level when writing the MCU program in software. The encrypted program instructions are generated by performing logical operations on the program instructions and their corresponding instruction addresses. The encrypted program instructions are then decrypted in hardware within the MCU chip using corresponding built-in decryption combinational logic circuits.

[0007] Preferably, the method for performing logical operations between the program instructions and their corresponding addresses is as follows: Program instructions at even-numbered addresses are denoted as operand A. Operand A's high and low bytes are swapped to obtain operand B. The address of the corresponding instruction is operand C. Operand D is a constant. Operand B and operand C are XORed, and then XORed with operand D to generate encrypted program instructions. Program instructions at odd-numbered addresses are denoted as operand A'. The address of the corresponding instruction is instruction C'. Operand D' is a constant. Operand A' and operand C' are XORed, and then XORed with operand D' to generate encrypted program instructions.

[0008] As an improvement, operands D and D' have the same value.

[0009] As an improvement, operands D and D' are different values.

[0010] Preferably, the method for performing logical operations between the program instructions and the addresses corresponding to the original program instructions is as follows: the program instructions are grouped into groups of four according to the instruction address lines; the program instructions with even-numbered addresses in each group are denoted as operand A, the instruction address corresponding to the program instruction is operand C, and operand D is a constant; operand A, operand C, and operand D are subjected to the A+ACD operation to obtain the result E; the program instructions with odd-numbered addresses in each group are denoted as operand A'; operand A' is obtained by swapping the high and low bytes, the instruction address corresponding to the program instruction is operand C', and operand D' is a constant; operand A', operand B', operand C', and operand D' are subjected to the A'+B'-C'-D' operation to obtain the result E'; the result E or result E' located at the first two address bits in each group is right-shifted by one bit to generate encrypted program instructions, and the result E or result E' located at the last two address bits is left-shifted by one bit to generate encrypted program instructions.

[0011] As an improvement, operands D and D' have the same value.

[0012] As an improvement, operands D and D' are different values.

[0013] As can be seen from the above description, the present invention has the following advantages:

[0014] This invention, based on the unique correlation between program addresses and program instructions, achieves encryption and decryption of MCU programs through software encryption and hardware decryption. The encrypted program instructions are unpredictable, and the instructions read during MCU chip programming and use cannot be decompiled, cracked, or ported. Since the MCU program is also encrypted binary machine code in ROM, directly reading the ROM module of the MCU chip by pricking it with a pin will also fail to decipher it. However, the encryption and decryption method described in this invention can be implemented by adding a small amount of hardware digital logic inside the MCU chip. It not only has low encryption and decryption costs but also good encryption effect and is difficult to decrypt. Attached Figure Description

[0015] Figure 1 It is the existing MCU program development, encryption, burning, and decryption process;

[0016] Figure 2 This is the MCU program development, encryption, burning, and decryption process of Embodiment 1 of the present invention. Detailed Implementation

[0017] Combination Figure 2 This invention provides a detailed description of specific embodiments of the invention, but does not limit the scope of the claims.

[0018] A hardware encryption and decryption method for MCU programs involves encrypting program instructions at the compiler level when writing MCU programs in software. Encrypted program instructions are generated by performing logical operations on the program instructions and their corresponding instruction addresses. The encrypted program instructions are then hardware decrypted in the MCU chip using corresponding built-in decryption combination logic circuits.

[0019] Based on the above encryption and decryption methods, an encryption and decryption design is implemented for a segment of instructions, and two implementation examples are designed.

[0020] Example 1:

[0021] Take a simple instruction MOV A,@0X00, which assigns the immediate value 0x00 to the accumulator ACC;

[0022] The compiled binary code is 0x0800;

[0023] Next, perform a simple operation on 0x0800 based on the instruction address. The operation rule is: for program instructions with even addresses, swap the high and low bytes, XOR the result with the corresponding instruction address, and then XOR the result with the constant 0xABCD. For program instructions with odd addresses, XOR the result directly with the corresponding instruction address and then XOR the result with the constant 0xABCD.

[0024] The results of the same program instruction MOV A,@0X00 at different addresses are shown in Table 1:

[0025] Table 1

[0026] instruction address Calculation result MOV A,@0X00 0x0000 0xABC5 MOV A,@0X00 0x0001 0xA3CC MOV A,@0X00 0x0002 0xABC7 MOV A,@0X00 0x03FE 0xA83B MOV A,@0X00 0x03FF 0xA032

[0027] As can be seen from the table above, the operation results are unpredictable. Based on the above operation rules, if the constant for the XOR operation involving odd addresses is changed to 0xDCBA, or if an additional addition operation is added, the operation process will become more complex and the difficulty of cracking will increase significantly. During decryption, a simple combinational logic circuit can be added inside the MCU to decompile the value back to the original instruction 0x0800.

[0028] It should be noted that when the MCU program is developed, the assembly instructions used are compiled into hexadecimal machine code. When the programmer burns the program to the chip, it is converted into binary machine code. Therefore, the encrypted program instructions are stored in ROM as binary machine code. During decryption, the values ​​can be decompiled back to the original instructions by performing the corresponding combinational logic circuits inside the MCU according to the encryption rules.

[0029] like Figure 1 The diagram illustrates the MCU program development, encryption, burning, and decryption process described in this embodiment.

[0030] Example 2:

[0031] Take a simple instruction MOV A,@0X00, which assigns the immediate value 0x00 to the accumulator ACC;

[0032] The compiled binary code is 0x0800;

[0033] Then perform simple operations on 0x0800 according to the instruction address. The operation rules are shown in Table 2: (1) Divide the program instructions into groups of 4 according to the instruction address lines; (2) Add the program instruction (operand A) at the even address in each group to itself, then subtract the instruction address (operand C) corresponding to the program instruction, and then subtract the constant 1 (operand D) to obtain the operation result; (3) After swapping the high and low bytes of the program instruction (operand A') at the odd address in each group (operand B'), add it to itself, then subtract the instruction address (operand C') corresponding to the program instruction, and then subtract the constant 0001 (operand D') to obtain the operation result; (4) Shift the operation result of the first two address bits in each group one bit to the right to generate the encrypted program instruction, and shift the operation result of the last two address bits one bit to the left to generate the encrypted program instruction.

[0034] Table 2

[0035]

[0036] Based on the above calculation method, the results of the same program instruction MOV A,@0X00 at different addresses are shown in Table 3:

[0037] Table 3

[0038]

[0039]

[0040] As can be seen from the table above, the calculation results are unpredictable and more complex than those in Example 1, making them more difficult to decipher. In this example, operands D and D' can use the same constant or different constants. Similarly, during decryption, a simple combinational logic circuit can be implemented inside the MCU to decompile the value back to the original instruction 0x0800.

[0041] It should be noted that when the MCU program is developed, the assembly instructions used are compiled into hexadecimal machine code. When the programmer burns the program to the chip, it is converted into binary machine code. Therefore, the encrypted program instructions are stored in ROM as binary machine code. During decryption, the values ​​can be decompiled back to the original instructions by performing the corresponding combinational logic circuits inside the MCU according to the encryption rules.

[0042] Typically, a complete MCU program consists of various instructions. After being encrypted using the above method with a simple algorithm, the compiled instructions become extremely complex and varied, greatly increasing the difficulty of cracking them. Not only can the instructions read during MCU chip programming and use not be decompiled or cracked and ported, but since the MCU program is also encrypted binary machine code in the ROM, directly reading the ROM module of the MCU chip by pricking it with a pin also cannot be deciphered. However, the encryption and decryption method described in this invention can be implemented by adding a small amount of hardware digital logic inside the MCU chip. It not only has low encryption and decryption costs but also good encryption effect and high decryption difficulty, thereby achieving the maximum degree of encryption protection for the MCU program.

[0043] The method described in this invention is not limited to the operation rules described in Embodiments 1 and 2. Users can design corresponding algorithms on the compiler side during program design based on the encryption complexity requirements and the difficulty and cost of hardware decryption circuit design, as long as the required level of encryption protection can be achieved.

[0044] In summary, the present invention has the following advantages:

[0045] This invention, based on the unique correlation between program addresses and program instructions, achieves encryption and decryption of MCU programs through software encryption and hardware decryption. The encrypted program instructions are unpredictable, and the instructions read during MCU chip programming and use cannot be decompiled, cracked, or ported. Since the MCU program is also encrypted binary machine code in ROM, directly reading the ROM module of the MCU chip by pricking it with a pin will also fail to decipher it. However, the encryption and decryption method described in this invention can be implemented by adding a small amount of hardware digital logic inside the MCU chip. It not only has low encryption and decryption costs but also good encryption effect and is difficult to decrypt.

[0046] It is understood that the above detailed description of the present invention is for illustrative purposes only and is not intended to limit the technical solutions described in the embodiments of the present invention. Those skilled in the art should understand that modifications or equivalent substitutions can still be made to the present invention to achieve the same technical effects; as long as the usage requirements are met, they are all within the protection scope of the present invention.

Claims

1. A method for encrypting and decrypting MCU programs, characterized in that: When writing MCU programs using software, the program instructions are encrypted at the compiler end. The encrypted program instructions are generated by performing logical operations on the program instructions and their corresponding instruction addresses. The encrypted program instructions are then decrypted in the MCU chip using the corresponding built-in decryption combination logic circuit. The method for performing logical operations between the program instructions and their corresponding addresses is as follows: Divide the program instructions into groups of four, based on the instruction address lines. The program instruction with an even address in each group is denoted as operand A, the address of the corresponding instruction is operand C, and operand D is a constant. The operation A+ACD is performed on operands A, C, and D to obtain the result E. The program instruction with an odd address in each group is denoted as operand A'. After swapping the high and low bytes of operand A', operand B' is obtained. The address of the instruction corresponding to the program instruction is operand C'. Operand D' is a constant. After performing the operation A'+B'-C'-D' on operands A', B', C', and D', the result E' is obtained. The encrypted program instruction is generated by right-shifting the result E or E' of the operation located in the first two address bits in each group, and the encrypted program instruction is generated by left-shifting the result E or E' of the operation located in the last two address bits.

2. The MCU program encryption and decryption method according to claim 1, characterized in that: Operand D and operand D' have the same value.

3. The MCU program encryption and decryption method according to claim 1, characterized in that: Operand D and operand D' are different values.