Method for confidentially burning microcontroller and burning equipment
The software code is encrypted through the asymmetric encryption algorithm negotiation shared key and symmetric encryption algorithm, combined with data flow signature and authenticity judgment, which solves the problem of confidential burning of microcontrollers in an unsafe environment and realizes the safe transmission and transmission of software code. Simplification of production processes.
Patent Information
- Application Number
- CN202311469038.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-07
- Publication Date
- 2024-08-23
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing microcontroller burning protocols cannot achieve confidential transmission of software code in an unsafe environment, and pre-writing a confidential BootLoader increases production workload and steps.
An asymmetric encryption algorithm is used to negotiate the shared key information, a symmetric encryption algorithm is used to encrypt the software code, and the confidentiality of data transmission is ensured through data flow signature and authenticity judgment, without the need to write a confidential BootLoader in advance.
It realizes the confidentiality of encrypted transmission of software code in an unsafe environment, simplifies the production process, reduces the workload, and prevents third-party theft through data flow signature and authenticity judgment.
Smart Images

Figure CN118535173A
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of communication technology and computer technology, and in particular to a method for confidentially burning a microcontroller and a burning device. Background Art
[0002] At present, many electronic devices need to use microprocessors or microcontrollers to achieve intelligent control. Microcontrollers have non-volatile memories such as FLASH inside to store software codes.
[0003] The burning device is specially used to write software code into the microcontroller. Usually, the burning device is connected to the microcontroller through a communication interface such as a serial port, SWD, JTAG, etc., and communicates according to the microcontroller's inherent protocol to burn the software code into the microcontroller. This type of microcontroller's inherent burning communication protocol is usually called ISP or ICP protocol.
[0004] The working environment for burning the microcontroller, if it is a safe and confidential environment, can be directly burned using the ISP or ICP protocol, which can also ensure that the burned software code is confidential and cannot be stolen by a third party.
[0005] However, microcontrollers often need to be programmed in an unsafe and non-confidential programming environment. For example, if a product that has already been sold needs to have its software upgraded, the user may need to do it themselves; if programming is done in an outsourced product manufacturing factory, it is difficult to ensure that all personnel will not steal secrets; even if the product is programmed by the production company itself, there is a possibility that the operator may be bribed or leak information unintentionally.
[0006] Therefore, the microcontrollers currently on the market have inherent ISP and ICP protocols, and data is transmitted in plain text, and confidential burning cannot be achieved. In other words, as long as all communication data is recorded and analyzed, a third party can obtain the burned software code.
[0007] Currently, the purpose of confidential burning can be achieved by pre-writing a confidential user-specific BootLoader code into the microcontroller in a confidential environment and configuring the microcontroller to be unreadable. This method is generally called confidential IAP. However, the step of pre-writing the BootLoader will increase the production workload and work steps, and the BootLoader contains encryption and decryption keys, which itself needs to be kept confidential and still needs to be performed in a safe and confidential environment.
[0008] Therefore, it is necessary to find a confidential burning method so that the software code can be encrypted and transmitted to the target microcontroller without the need to pre-write a confidential BootLoader. Summary of the invention
[0009] The purpose of the present invention is to provide a method and a burning device for confidentially burning a microcontroller, wherein the software code in the burning device is sent to the inside of a target microcontroller in an encrypted form and then burned into the non-volatile memory of the target microcontroller, without the need to pre-write a confidential BootLoader.
[0010] To achieve this object, the present invention adopts the following technical solutions:
[0011] A method for confidentially burning a microcontroller comprises the following steps:
[0012] S1: The target microcontroller runs the confidentiality burning module;
[0013] S2: The burning device and the target microcontroller each obtain a random number through a random number generation unit, and use the asymmetric encryption calculation unit to generate their own public and private key pairs, and exchange public keys. Each uses the other party's public key and its own private key to negotiate the shared key information;
[0014] S3: A key is derived from the negotiated shared key information, and the burned software code is encrypted using a symmetric key encryption unit; the burning device sends the encrypted software code to the target microcontroller;
[0015] S4: The confidentiality burning module in the target microcontroller decrypts the software code and writes it into the non-volatile memory of the target microcontroller.
[0016] Preferably, after pre-configuring the read protection of the target microcontroller to be in an effective state, the confidentiality burning module is run to start transmitting confidential information; or after running the confidentiality burning module, the read protection of the target microcontroller is first configured to be valid but not effective, and once any reset of the target microcontroller occurs, it will take effect, and then start transmitting confidential information.
[0017] Preferably, the confidentiality burning module in step S1 is fixed in the target microcontroller before leaving the factory or downloaded by the burning device and sent to the target microcontroller.
[0018] Preferably, the communication data packets between the burning device and the confidential burning module are signed with a data stream, and the data stream signature is generated by cumulatively calculating the data stream formed by the communication data packets in and out using a hash algorithm.
[0019] Preferably, after the two parties have negotiated the shared key information, the shared key information is involved in the calculation of the data stream signature, and the data stream formed by the communication data packets is cumulatively calculated using a hash algorithm to generate it.
[0020] Preferably, the method further includes: sending and running one or more authenticity determination codes of the target microcontroller to the target microcontroller, and if the authenticity determination code passes, the target microcontroller is determined to be a real one, and the subsequent steps are continued.
[0021] Preferably, the method specifically comprises the steps of:
[0022] a: The burning device downloads the confidential burning module to the target microcontroller and negotiates the shared key information;
[0023] b: The burning device downloads an authenticity determination code to the target microcontroller;
[0024] c: Run the authenticity judgment code and return the result to the burning device;
[0025] d: Determine whether the authenticity judgment code is abnormal. If so, proceed to step e; otherwise, proceed to step f;
[0026] e: authenticity judgment exception handling;
[0027] f: whether to repeat the authenticity judgment, if yes, return to step 2; otherwise, go to step g;
[0028] g: Start sending confidential information.
[0029] Preferably, the method further includes monitoring the work site where the target microcontroller is burned by video means to prevent a third party from using a logic simulation system to simulate the target microcontroller and deceive the burning device to obtain software codes that need to be kept confidential.
[0030] A burning device for confidentially burning a microcontroller, comprising:
[0031] A random number generating unit, used for obtaining random numbers;
[0032] The asymmetric encryption calculation unit is used to generate public and private key pairs from the acquired random numbers, exchange public keys, and negotiate shared key information using the other party's public key and its own private key;
[0033] The data communication unit is used for sending and receiving data packets between the burning device and the target microcontroller;
[0034] A symmetric encryption calculation unit, used to derive a key from the negotiated shared key information, and encrypt the burned software code using a symmetric key encryption algorithm;
[0035] Preferably, it also includes a data stream signature unit for performing data stream signature on the communication data packets between the burning device and the target microcontroller.
[0036] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0037] The present invention adopts an asymmetric encryption algorithm between the burning device and the target microcontroller to negotiate shared key information known only to both parties for encrypted transmission of the burned software code. The purpose of keeping the software code to be burned confidential is achieved without presetting any confidential information, and the invention has the advantages of simple structure, small workload, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0039] Figure 1 A flow chart of a method provided in Embodiment 1 of the present invention;
[0040] Figure 2 This is a flow chart of negotiating shared key information in Embodiment 1 of the present invention;
[0041] Figure 3 This is a flowchart of the start time of reading protection and transmitting confidential information in Embodiment 2 of the present invention;
[0042] Figure 4 This is a block diagram of the data stream signature principle of Embodiment 3 of the present invention;
[0043] Figure 5 This is a flowchart of the authenticity determination code of the fourth embodiment of the present invention;
[0044] Figure 6 This is a structural diagram of a video-based monitoring burning site in Embodiment 5 of the present invention. DETAILED DESCRIPTION
[0045] The core idea of the present invention is as follows: the present invention uses an asymmetric encryption algorithm to negotiate key information shared only by the burning device and the target microcontroller, which is used for the encrypted transmission of the burned software code; at the same time, a data summary algorithm is used to calculate and verify the data stream signature for all data packets sent and received between the two parties, ensuring that the data stream between the two parties is and only is sent and received by the two parties; a third party can neither insert a data packet into the data stream nor remove a data packet; and authenticity judgment and video monitoring are used to prevent a third party from simulating the target microcontroller with a logic simulation system.
[0046] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] The technical solution of the present invention is further described below with reference to the accompanying drawings and through specific implementation methods.
[0048] Embodiment 1
[0049] like Figure 1 As shown, a method for confidentially burning a microcontroller comprises:
[0050] Step 101: The target microcontroller runs a secure programming module (SecureIsp);
[0051] This embodiment takes the domestic GD32F303ZKT6 microcontroller as an example, which has 3MB of FLASH non-volatile memory, 96KB of SRAM memory, and a CortexM4 arm core. It has a complete set of Read, Erase, Program, and ReadOutProtect commands, and supports burning the chip's FLASH.
[0052] First, write a secure programming module (SecureIsp) for secure programming into SRAM, and then use the JumpTo command of the serial port ISP command set of GD32F303ZKT6 to run the code. Correspondingly, the programming device is called Programmer.
[0053] The secure programming module (SecureIsp) is similar to the programming device (Programmer), and both include the following software units: a random number generation unit, an asymmetric encryption calculation unit, a symmetric encryption calculation unit, and a data communication unit.
[0054] A random number generating unit, used for obtaining random numbers;
[0055] Specifically, the ADC module inside the chip can be used to continuously sample the internal ADC input signal. Since the internal ADC input signal has a certain amount of noise, it can be regarded as a physical random number generator. On the other hand, there are multiple internal clocks such as IRC8M, IRC48M, IRC40K inside the chip, which also have a certain amount of physical noise. Other methods can also be used, such as configuring GPIO as a high-impedance input state, and its input will change randomly with environmental noise, etc. After accumulating enough entropy values, random numbers can be obtained. For other different models of target microcontrollers, different random number acquisition methods can be used. Of course, some microcontrollers have hardware random number generators, which can be used directly.
[0056] The asymmetric encryption calculation unit is used to generate respective public-private key pairs from the acquired random numbers, and exchange public keys. Each party uses the other party's public key and its own private key to negotiate shared key information. For the ECC elliptic encryption algorithm, it mainly includes functional codes and calculation functions for implementing large integer operations such as point addition and point multiplication of elliptic curves, and usually uses tens of KB of FLASH code and read-only data storage space, and several KB to more than ten KB of SRAM data storage space (including stack STACK and heap HEAP).
[0057] To implement asymmetric encryption code, large integer operations must be used, and the heap HEAP is usually used for dynamic memory allocation and release. When performing asymmetric encryption operations, HEAP space is dynamically allocated (malloc or calloc function), and the HEAP space is released after the calculation is completed (free function). Allocation and release need to be paired, otherwise it will cause exceptions such as memory leaks. Frequent allocation and release will also cause heap fragmentation problems. Usually, the heap LIB of the C language compiler itself does not have a heap_reset heap reset function. We can specially design a heap_reset function to replace all free functions after asymmetric encryption calculations, release all allocated heap space at one time, and eliminate memory leaks and heap fragmentation. We can also use a custom heap memory management library to achieve more flexible heap memory management, which is conducive to improving the speed of asymmetric encryption operations.
[0058] The data communication unit is used for sending and receiving data packets between the programming device and the secure programming module (SecureIsp) of the target microcontroller.
[0059] The symmetric encryption calculation unit uses the key derived from the negotiated shared key information and uses the symmetric key encryption algorithm to encrypt the burned software code. Algorithms such as AES and SM4 can be used;
[0060] In this embodiment, the asymmetric encryption calculation unit adopts the national secret algorithm SM2, which is an asymmetric encryption algorithm based on elliptic curves based on ECC elliptic curve cryptography and announced by the China National Cryptography Administration, and has a key length of 256 bits.
[0061] Curve parameters:
[0062] p=FFFFFFFE FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 00000000 FFFFFFFFFFFFFFFF
[0063] a=FFFFFFFE FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 00000000 FFFFFFFFFFFFFFFC
[0064] b=28E9FA9E 9D9F5E34 4D5A9E4B CF6509A7 F39789F5 15AB8F92 DDBCBD414D940E93
[0065] n=FFFFFFFE FFFFFFFF FFFFFFFF FFFFFFFF 7203DF6B 21C6052B 53BBF40939D54123
[0066] Gx=32C4AE2C 1F198119 5F990446 6A39C994 8FE30BBF F2660BE1 715A4589334C74C7
[0067] Gy=BC3736A2 F4F6779C 59BDCEE3 6B692153D0A9877C C62A474002DF32E52139F0A0
[0068] Among them, Gx and Gy can be called Gbase_sm2, which is the base point of the SM2 elliptic curve.
[0069] Step 102: The burning device and the target microcontroller each obtain a random number through a random number generating unit, and generate their own public and private key pairs from the obtained random number through an asymmetric encryption calculation unit, and exchange public keys, and each uses the other party's public key and its own private key to negotiate shared key information;
[0070] In this embodiment, specifically Figure 2 As shown,
[0071] The secure burning module (SecureIsp) uses the random number generation unit to obtain a 256-bit random number, called Nrandom. The secure burning module (SecureIsp) uses the asymmetric encryption calculation unit, takes this Nrandom as the private key Mcu_PrivKey of the public-private key pair, and uses the SM2 curve to perform an ECC point multiplication operation to calculate the public key Mcu_PubKey, Mcu_PubKey = Mcu_PrivKey*Gbase_sm2.
[0072] The programmer also uses the random number generator to obtain a 256-bit random number, called Mrandom. The programmer uses an asymmetric encryption calculation unit to use Mrandom as the private key Prog_PrivKey of the public-private key pair, and uses the SM2 curve to perform an ECC point multiplication operation to calculate the public key Prog_PubKey, Prog_PubKey = Prog_PrivKey*Gbase_sm2.
[0073] The secure programming module (SecureIsp) uses the data communication unit to share Mcu_PubKey with the programming device (Programmer). The Programmer uses the data communication unit to share Prog_PubKey with the secure programming module (SecureIsp).
[0074] The secure programming module (SecureIsp) uses an asymmetric encryption calculation unit to calculate Share_Msg = Mcu_PrivKey*Prog_PubKey; the programming device (Programmer) uses an asymmetric encryption calculation unit to calculate Share_Msg = Prog_PrivKey*Mcu_PubKey. Due to the characteristics of the ECC point multiplication operation, the Share_Msg obtained by both must be equal (Share_Msg = Mcu_PrivKey*Prog_PrivKey*Gbase_sm2).
[0075] At this point, the programmer and the secure programming module (SecureIsp) have obtained the shared key information Share_Msg, which is unknown to the outside world. This process is also called the Diffie-Hellman Key Exchange mechanism, which has been widely used in the field of computer cryptography. It can be used in combination with the asymmetric encryption algorithm of RSA or ECC.
[0076] Step 103: a key is derived from the negotiated shared key information, and the burned software code is encrypted using a symmetric key encryption algorithm; the burning device sends the encrypted software code to the target microcontroller;
[0077] After obtaining the shared key information Share_Msg, the programming device (Programmer) and the secure programming module (SecureIsp) can use this as a basis to generate the key AesKey for the symmetric encryption algorithm, AesKey = KDF_func (Share_Msg), KDF_func refers to a key derivation algorithm, usually a hash algorithm, to avoid the shared key information Share_Msg being directly used for symmetric encryption and decryption, and the symmetric encryption algorithm being partially cracked, causing Share_Msg to be directly cracked.
[0078] Usually, the KDF key derivation algorithm adds some other non-confidential data, called salting, to the shared key information Share_Msg. Using the KDF key derivation algorithm, any number of symmetric encryption algorithm keys AesKey can be generated from the shared key information Share_Msg.
[0079] Step 104: The secure programming module (SecureIsp) in the target microcontroller decrypts the software code and writes it into the non-volatile memory of the target microcontroller.
[0080] Specifically, it includes:
[0081] 1. The programmer takes out 16 bytes of ProgCode16 from the software code ProgCode to be burned, encrypts it with AesKey, and obtains CipherCode16.
[0082] 2. The programming device (Programmer) sends CipherCode16 to the secure programming module (SecureIsp).
[0083] 3. The secure burning module (SecureIsp) decrypts CipherCode16 using AesKey to obtain ProgCode16.
[0084] 4. The secure burning module (SecureIsp) writes ProgCode16 into the first 16 bytes of the microcontroller FLASH.
[0085] 5. Repeat steps 1 to 4 until all software code ProgCode is written into FLASH.
[0086] In the above steps, the software code ProgCode is encrypted and decrypted in groups, but it is not necessarily transmitted in 16-byte groups and written into FLASH in groups. The programming device (Programmer) can also encrypt multiple 16-byte groups and send them to the secure programming module (SecureIsp) together, and then decrypt them in groups and write them into FLASH.
[0087] The secure burning module (SecureIsp) can be divided into multiple parts and sent to the target microcontroller and run to suit the size of the SRAM storage space of the target microcontroller. For example, the secure burning module (SecureIsp) for setting the read protection state is sent first and runs, and then the secure burning module (SecureIsp) for the random number generation part is sent and runs to generate random numbers, and then the secure burning module (SecureIsp) for the asymmetric encryption algorithm is sent and runs to implement ECC point multiplication operations and obtain shared key information, and finally the secure burning module (SecureIsp) for the symmetric key encryption algorithm and the non-volatile memory of the target microcontroller is sent and runs to write the software code into the non-volatile memory of the target microcontroller.
[0088] The burning device can also use a random number generator and an asymmetric encryption algorithm to generate a pair of Prog_PrivKey and Prog_PubKey in advance, and send the Prog_PubKey to the target microcontroller together with the built-in secure burning module (SecureIsp). This can simplify the subsequent step of transmitting the Prog_PubKey to the secure burning module (SecureIsp).
[0089] The secure programming module (SecureIsp) can also be used as the factory BootLoader of the chip and solidified in the target microcontroller. This can save the step of the programming device downloading the secure programming module (SecureIsp) to the target microcontroller.
[0090] In this case, in order to save the FLASH or ROM space occupied by the BootLoader (usually tens of KB are required), we can only solidify a small BootLoader, and then download the main confidential burning module (SecureIsp) to the SRAM memory of the target microcontroller through the burning device (for target microcontrollers with less SRAM, FLASH memory can also be used), and use the hash algorithm to verify this part of the confidential burning module (SecureIsp), and match it with the hash value in the solidified small BootLoader (it can be multiple hash values matching multiple parts of the confidential burning module (SecureIsp)). In this way, the solidified small BootLoader can be reduced to hundreds of bytes, thereby reducing the chip cost. If the public key owned by the target microcontroller manufacturer is used, and the asymmetric encryption algorithm is used to sign and verify this part of the confidential burning module (SecureIsp), this part of the confidential burning module (SecureIsp) can also be unfixed, and only needs to be signed by the private key owned by the microcontroller manufacturer.
[0091] The burning device storing the confidential software code and the target microcontroller can communicate at different locations through remote connections such as the Internet. If the target microcontroller does not have a remote connection interface, it can be adapted through a remote connection-burning interface communication conversion module. For example, an Ethernet-serial port converter, etc. Thus, the burning device can be placed in a safe and confidential environment to prevent confidential information from being stolen. In other words, the burning device is divided into two parts, one part stores confidential information in a safe and confidential environment; the other part connects and communicates with the target microcontroller in an unsafe and unconfidential environment; the two parts communicate through a remote connection.
[0092] The Diffie-Hellman key exchange in step 102 can be performed multiple times, and multiple asymmetric encryption algorithms can be mixed to enhance and increase the shared key information, making confidentiality stronger. For example, the ECC elliptic encryption curve, 256-bit ones include China's ECC_SM2, Europe's BrainPool-256, and the United States NIST's P-256. We use three ECC curves in combination to obtain three copies of shared key information, and then derive symmetric encryption keys based on this; a third party must crack all three curves to obtain complete key information, to avoid a backdoor or weakness in a certain ECC curve that is easy to be cracked.
[0093] At present, the most suitable asymmetric encryption algorithm for this application is the ECC elliptic curve encryption algorithm. However, this application is not limited to the ECC elliptic curve encryption algorithm.
[0094] The target microcontroller described in this application can be a microcontroller chip with a core such as 8051, ARM Cortex-M3, ARM Cortex-M0, RISV-V, HCS08, AVR, AVR32, etc., or it can be an integrated circuit such as CPLD, FPGA, etc. that can constitute a microcontroller. For example, the CortexM1 core is an ARM core suitable for CPLD and FPGA, and the technical principles of this application can also be applied.
[0095] Embodiment 2
[0096] Embodiment 1 The communication between the burning device and the target microcontroller is encrypted by Diffie-Hellman key exchange to prevent confidential information from being stolen by a third party during communication. However, the burning device and the target microcontroller themselves must also have confidentiality. Usually, the burning device is easy to use more and more expensive devices to achieve strong confidentiality; in some occasions, the burning device can separate the part storing confidential information and place it in a safe and confidential environment, and then use the key information generated by the Diffie-Hellman key exchange to encrypt and transmit with the target microcontroller through a remote Internet connection.
[0097] Therefore, in the entire burning system, after the target microcontroller receives the burned software code that needs to be kept confidential, the confidentiality of the confidentiality mechanism is the weakest link and shortcoming, and should be strengthened to avoid subsequent theft by a third party.
[0098] Embodiment 2 combines the read protection mechanism of the target microcontroller with the Diffie-Hellman key exchange of embodiment 1 to prevent a third party from stealing secrets from the target microcontroller. Almost all microcontroller chips have a read protection configuration function. After the setting takes effect, normal technical means cannot read the contents of the FLASH and other memories inside the chip. The actual names of the read protection function are varied. For example, the STM32 chip is called ReadOutProtect (RDP), the PIC16 series chip is called Code Protection Bit, and the MC9S08 series chip is called Security State Code (SEC01:SEC00). After setting the read protection to be effective, some microcontrollers must be powered on and reset to make the read protection state effective; some microcontrollers can take effect at any reset; some microcontrollers take effect immediately once configured.
[0099] See also Figure 3As shown, in this embodiment, a step method needs to first burn the secure burning module (SecureIsp) into the FLASH of the target microcontroller chip, and set the read protection of the target microcontroller to a valid state. After the target microcontroller is powered on and reset, the read protection is enabled, and the secure burning module (SecureIsp) in the FLASH is loaded and run, and communicates with the burning device (Programmer) to implement subsequent FLASH burning. Only in this way can the burned software code and the negotiated key information be protected by the chip read protection.
[0100] The secure burning module (SecureIsp) in FLASH can copy and load the code into SRAM for operation after power-on reset. This releases this part of FLASH, which can be erased and written with the burned software code. The advantage of this is that it is not limited by the read protection configuration mechanism of the target microcontroller. The disadvantage is that it may occupy the front part of the FLASH area. For example, for GD32F303ZKT6, once the read protection is configured, the front 4KB FLASH space is locked and cannot be erased. Therefore, the software code that needs to be burned cannot be written. However, for microcontrollers such as HC32L136, CW32L052, etc., setting read protection will not lock some FLASH spaces and make them non-erasable, which is more applicable.
[0101] This step method can make the read protection effective after the target microcontroller is powered on and reset, first configure other target microcontrollers, and then continue to load and run the confidentiality burning module (SecureIsp) in the FLASH of this target microcontroller. In this way, a batch of 1,000 target microcontrollers can be burned in two or more steps, and a forced random order can be added, which can increase the difficulty of third-party theft, because all communication data of the entire batch of 1,000 target microcontrollers must be recorded in order to analyze, crack, and steal secrets.
[0102] Another step method of this embodiment, for example, the read protection function of the GD32F303 chip is called SecurityProtection value (SPC). When the SPC option byte at address 0x1FFF F800 is a value other than 0xA5, the chip read protection takes effect, and the internal FLASH, SRAM, etc. cannot be read out. In the chip user manual, the SPC option byte has the following description: "Protected state: When the SPC byte and its complement byte value are set to any value other than 0x5AA5, the security protection state takes effect after the system is reset. It should be noted that if the MCU's debugging module is still connected to the external JTAG / SWD device during the modification process, a power-on reset is required instead of a system reset to make the modified protection state effective.
[0103] In other words, the GD32F303 chip can be configured with read protection enabled, but it does not take effect. The SecureIsp module continues to execute to maintain control over the target microcontroller. Once any reset occurs, the read protection takes effect immediately. At this time, the SecureIsp module stops running, but the read protection also takes effect at the same time, which can also protect the confidential information in the target microcontroller from being stolen by a third party. Because the SecureIsp module controls the target microcontroller when it is running, a third party cannot steal it. The third party must reset the target microcontroller to gain control of the target microcontroller.
[0104] The secure programming module (SecureIsp) sets the SPC to read protection state, that is, write a value other than 0xA5, such as 0xFF when performing an erase operation. At this time, the chip is still in a non-read protection state, but once any reset occurs, the chip will switch to a read protection state;
[0105] Setting the SPC to read protection can also be done after the shared key information is negotiated, and it only needs to be done before the burned software code is transferred to the target microcontroller. This is because our goal is to keep the burned software code confidential, and the negotiated shared key information only needs to be kept confidential after the burned software code is transferred to the target microcontroller. It is okay for the shared key information to be leaked before the confidential information is transferred.
[0106] Even if the microcontroller chip is set with read protection, normal technical means cannot read the software code stored in the FLASH inside the chip. However, through some unconventional technical means such as chip cracking (opening the chip package, electron microscopy, electron microprobe, etc.), almost all microcontroller chips can read the internal confidential data. It’s just that the cost and time of cracking are different for different chips. Some commonly used chips can be read out in a few days for as low as a few hundred yuan; some confidentiality and security microcontrollers used in the financial field may require millions of yuan and several months to read out successfully.
[0107] Therefore, the encryption strength of the asymmetric encryption algorithm used in our Diffie-Hellman key exchange and the strength of the symmetric encryption algorithm used to encrypt confidential information can be selected based on the cracking cost of the target microcontroller chip. For example, for confidentiality and security microcontrollers, the cracking cost is high, so we can choose 512-bit and above ECC encryption algorithms, or a combination of multiple ECC encryption algorithms, combined with the AES256 symmetric encryption algorithm. For ordinary microcontrollers whose cracking cost is only a few hundred yuan, it is sufficient for us to choose a 192-bit ECC encryption algorithm, because even for a 192-bit ECC encryption algorithm, cracking calculations require a lot of computing power and the cost is high enough.
[0108] For the GD32F303 chip, you must take action to disconnect the microcontroller debug module from the SWD interface to ensure that any system reset makes the set read protection effective before starting to transmit confidential information. Otherwise, if only the power-on reset can make the read protection effective, a third party can interrupt the operation of the secure burning module (SecureIsp) through other resets and read the confidential information that has been transmitted to the target microcontroller. Moreover, if the debug module is not disconnected, a third party can also control the target microcontroller through the debug module, causing the secure burning module to lose control of the target microcontroller, thereby causing the confidential information to be leaked. Specifically, the method of disconnecting the debug module is to configure the CDBGPWRUPREQ bit of the CTRL / STAT register according to the arm manual to power off the debug module. And AFIO_PCF0's SWJ_CFG[2:0] is set to 100. In this step, different models of microcontrollers have different characteristics and need to be handled differently.
[0109] After the secure programming module (SecureIsp) sets read protection, the programming device should verify and confirm it as promptly and effectively as possible to prevent a third party from bypassing this step and causing the subsequent confidential information to be stolen.
[0110] Embodiment 3
[0111] This embodiment is based on the first embodiment, and adds a data stream signature unit for signing each communication data packet (ie, data stream) between the burning device and the target microcontroller within a certain period of time, thereby further preventing a third party from stealing confidential information.
[0112] For example, by selecting the SHA256 hash algorithm. For data of any length, a 256-bit 32-byte data digest value is calculated, and no one can tamper with the data to obtain the same data digest value. For each data packet sent and received between the target microcontroller's secure burning module (SecureIsp) and the burning device (Programmer), a data stream signature with a length of 32 bytes is attached. The SHA256 hash algorithm is used to calculate all data packets sent and received from a specific point in time. When either party receives a data packet, the latest data stream signature is calculated. Once a third party uses technical means to impersonate a burning device and remove or insert data packets from the data stream, the data stream signature will be inconsistent with the expected one. After the burning device detects this inconsistency, it can immediately interrupt the burning work, clear the confidential information, and prevent the burned software code from being stolen.
[0113] For example Figure 4 As shown, the burning device sends data packets PktP0...PktPn to the target microcontroller, and the data packets returned by the target microcontroller are recorded as PktM0...PktMn. PktPn contains the SHA256 {PktP0~PktPn-1,PktM0~PktMn-1} value calculated by {PktP0~PktPn-1} and {PktM0~PktMn-1}, recorded as SgPn value, and the target microcontroller also has a series of SgMn values as data stream signatures. As long as a third party uses technical means to make any party miss any data packet, the SHA256 value will be completely different; or if a third party uses technical means to impersonate any party and send a forged data packet to the other party, the SHA256 value will also be completely different and thus be detected.
[0114] Of course, this data stream signature cannot detect a third party using technical means to completely take over the burning device or target microcontroller and send and receive the remaining data packets.
[0115] Therefore, further, after the two parties have negotiated the shared key information, the shared key information can be involved in the calculation of the data stream signature, that is, SHA256{PktP0~PktPn-1,PktM0~PktMn-1,ShareMsg}. This can not only monitor the removal or insertion of data packets by a third party, but also prevent a third party from taking over the burning device or target microcontroller to send and receive the remaining data packets, because the third party does not have the shared key information and cannot calculate the correct data stream signature, and thus cannot impersonate any party to send any data packet to the other party.
[0116] Although we can store all the sent and received data packets and then calculate the data flow signature based on them, it will consume a lot of storage space and require a lot of calculations.
[0117] A better solution is to use the data of each data packet and the previous data stream signature to calculate a new hash value as a new data stream signature. In this way, we only need to store one data stream signature, and the amount of calculation each time is not large. The monitoring effect of the data stream signature is the same as calculating all sent and received data packets. The calculation formula is: SgP0 = SHA256{PktP0}; SgM0 = SHA256{PktM0, SgP0}; SgP1 = SHA256{SgM0, Pkt P1}; SgM1 = SHA256{SgP1, PktM1}; ...; SgPn = SHA256{PktPn, SgMn-1}; SgMn = SHA256{PktMn, SgPn}.
[0118] Since the software code to be burned needs to be kept confidential and is stored in the burning device, what we need to monitor and prevent is that a third party uses technical means to impersonate the target microcontroller to send and receive data packets to deceive the burning device to send the burned software code. Therefore, the monitoring of data flow signatures is mainly performed by the burning device. The target microcontroller can only calculate the data flow signature and include it in the data packet to send. Of course, it would be better if the target microcontroller also monitors the data flow signature to make the monitoring more timely.
[0119] At the same time, the target microcontroller is a subordinate and passive party in sending and receiving data packets. The data packets it sends can and should be predefined to the greatest extent possible, that is, according to the content of the data packets sent by the burning device, only the pre-defined return data packets will be considered correct, otherwise it will be considered that a third party is stealing secrets.
[0120] The communication interface we are talking about can be divided into physical interface and logical interface. The physical interface can be understood as how to transmit a basic data (byte, word, etc.), such as the serial port refers to the UART interface, which uses 10 bits (1StartBit+8DataBit+1StopBit) or 11 bits (1StartBit+8DataBit+1CheckBit+1StopBit) to transmit a byte. The logical interface refers to how to use multiple bytes to form a data packet, such as the character "{" as the beginning of the data packet, the character "}" as the end of the data packet; one byte of data is expressed with 2 HEX characters; and so on.
[0121] If you use the serial port to program the GD32F303 target microcontroller, after running the secure programming module (SecureIsp) through the JumpTo command, the secure programming module (SecureIsp) can fully control the serial port's transmission and reception, and can continue to use the serial port physical interface for communication, but the logical layer protocol such as the data packet structure is re-established between the secure programming module (SecureIsp) and the programming device, and the data stream signature is added.
[0122] The SWD debugging protocol has a more complex transmission physical interface. In fact, the structure of the data packet has been specified at the physical level, and it has physical control over the target microcontroller. A third party can use the SWD interface to directly control the debug module in the target microcontroller without being restricted by the burning device and the secure burning module (SecureIsp), and access and modify the memory in the target microcontroller, thereby bypassing the data stream signature mechanism. Therefore, after adding the data stream signature, the secure burning module (SecureIsp) must use another physical interface, and cannot continue to use debug interfaces such as the SWD interface, and the debug module must be turned off.
[0123] Before starting to transmit confidential information, another hardware communication interface must be used to replace the SWD interface, and the debug module must be turned off for subsequent communication between the programming device and the target microcontroller to add a data stream signature to each data packet. The SWD interface is only used to load the confidential programming module (SecureIsp) to the target microcontroller and run it.
[0124] This new communication interface connecting the secure programming module (SecureIsp) and the programming device (Programmer) can be a communication protocol such as a serial port, SPI port, I2C, or a communication protocol directly implemented using GPIO;
[0125] You can either use the original SWDCK and SWDIO lines of the SWD interface and configure them as GPIO, serial port, etc., or use other communication pins of the target microcontroller. On the one hand, it is most convenient to use the original two lines of the SWD interface without increasing the number of hardware connection lines; on the other hand, adding more additional communication pins can increase the communication speed. Use custom non-standard protocols as much as possible for communication protocols, which can also increase the difficulty of monitoring, tampering, and stealing by third parties.
[0126] After switching to a communication interface that allows data stream signatures to be added, data stream signatures should be added to each data packet as soon as possible to detect third-party insertion and tampering as early as possible.
[0127] For example, if the secure programming module (SecureIsp) is embedded in the target microcontroller, the communication can have a data stream signature from the beginning, and the insertion and tampering of the third party can be monitored and prevented from the beginning.
[0128] If the confidential information has been transmitted, the secure programming module (SecureIsp) and the programming device (Programmer) enter a simple communication state that does not require confidential communication, and can also end the addition and monitoring of data stream signatures in data packets.
[0129] Embodiment 4
[0130] With respect to the first to third embodiments, if a third party uses a logic simulation system to simulate the target microcontroller, accepts and runs the secure burning module (SecureIsp), the burned software code can actually be stolen.
[0131] However, the simulated system is always different from the target microcontroller, and it is very difficult to achieve 100% simulation fidelity. We can send and run one or more target microcontroller authenticity judgment codes to the target microcontroller. After all the judgments are passed, it is determined to be the real target microcontroller, and the confidentiality burning module (SecureIsp) is continued to be executed to transmit confidential information.
[0132] The programmer can configure a microcontroller or product system for reference or comparison and place them together in a confidential and secure environment.
[0133] For example, the pipelines of instruction fetch, decoding, and execution of each target microcontroller may be different, so the time consumed to run a piece of code may be different. We can use a piece of authenticity judgment code to compare the number of clocks consumed by running on the target microcontroller and the number of clocks consumed by running on a reference microcontroller set by the burning device. If there is a difference, it can be considered that the target microcontroller may be simulated by the logic simulation system.
[0134] In addition to judging the target microcontroller, the PCBA board equipped with the target microcontroller, or the entire microcontroller product device, may have physical characteristics that are more difficult to simulate than the target microcontroller. We can send and run one or more target product system authenticity judgment codes to the target product system to check not only the characteristics of the target microcontroller, but also the characteristics of the target board or target product system.
[0135] For relatively simple target product systems or target microcontrollers, we can add some peripheral devices to form a target system that is more difficult to simulate and forge, such as adding one or more dedicated microcontrollers, CPLDs, FPGAs, analog devices, sound and light emitting devices, temperature and humidity sensors, sound and light sensors, etc. The authenticity judgment code conducts complex communication interactions with these peripheral devices to distinguish whether it is a real physical system or a logical simulation system.
[0136] The authenticity judgment code should be as random as possible to make it difficult for a third party to predict. For example, there are many copies of the authenticity judgment code, or one authenticity code can be randomly transformed into many variants, and one copy is randomly selected to be downloaded to the target microcontroller and run; the number of authenticity judgments can also be randomized.
[0137] In order to increase the difficulty for a third party to crack and simulate the authenticity judgment code, the authenticity judgment code is encrypted with shared key information as much as possible before sending it to the target microcontroller, rather than sending the authenticity judgment code in plain text.
[0138] Specific reference Figure 5 As shown, the steps include:
[0139] Step 501: The burning device downloads the secure burning module (SecureIsp) to the target microcontroller and negotiates the shared key information;
[0140] Step 502: The burning device downloads an authenticity determination code to the target microcontroller;
[0141] Step 503: Run the authenticity determination code and return the result to the burning device;
[0142] Step 504: Determine whether the authenticity determination code is abnormal. If so, proceed to step 505; otherwise, proceed to step 506;
[0143] Step 505: authenticity judgment exception handling;
[0144] Step 506: whether to repeat the authenticity judgment, if yes, return to step 502; otherwise, go to step 507;
[0145] Step 507: Start transmitting confidential information.
[0146] Embodiment 5
[0147] See also Figure 6As shown, this embodiment also uses a logic simulation system for a third party to simulate the target microcontroller. The method adopted is to use video means to monitor the entire burning production site composed of the burning equipment, the target microcontroller, and the target product system, and find abnormalities to avoid logic simulation by a third party. Logical simulation of a target microcontroller usually requires a relatively large circuit system. Through video monitoring, it is easy to detect and eliminate this way of stealing secrets. Video monitoring can be done by manual monitoring or by combining the display interface of the burning equipment, so that it falls into the field of view of video monitoring together with the target microcontroller, and then use artificial intelligence AI for video recognition to achieve automatic monitoring.
[0148] Figure 6 In the case of remote connection, the monitoring end is placed at a remote location. In some cases, remote connection is not allowed. The monitoring video obtained by the camera can be directly connected to the burning device for direct video recognition. If an abnormality is found, it can be directly processed, such as erasing confidential information in the burning device.
[0149] For example, the burning equipment or additional circuits for authenticity judgment in the monitored burning environment can be equipped with display mechanisms, action mechanisms, and sensors. According to the instructions of the monitoring end, they can display unpredictable content, emit unpredictable background light, make unpredictable movements, etc. The monitoring end can then analyze and monitor through video recognition. It will be difficult for a third party to simulate. It is similar to the facial recognition authentication that we currently use widely.
[0150] The display mechanism can be an LCD screen, an LED screen, an OLED screen, etc. It can be a segment character display screen or a dot matrix graphic display screen. It can also be composed of light-emitting tubes to form a specific display screen.
[0151] The action mechanism can be an electric motor, a stepper motor, a sound generator, etc.
[0152] Sensors can monitor the environment's temperature, light, humidity, pressure, sound, etc.
[0153] In this embodiment, the burning device in the monitored burning production site may not store confidential information such as the burned software code because it is in an unconfidential and unsafe environment. Instead, after turning on the video surveillance, it is connected to the storage device storing the confidential information through the remote communication connection, and the storage device and the target microcontroller directly transmit the confidential information to the target microcontroller through the confidential communication established in Example 1; or the burning device in the monitored burning production site only stores the confidential information in a power-off and loss-instant mode (volatile storage, such as SRAM, DRAM, etc.), and each time the power is turned on and the video surveillance is turned on, it is connected to the storage device storing the confidential information through the remote communication connection to obtain the confidential information, and then the confidential burning is performed with the target microcontroller using the method of Example 1.
[0154] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for confidentially burning a microcontroller, characterized in that: Includes steps: S1: The target microcontroller runs the confidentiality burning module; S2: The burning device and the target microcontroller each obtain a random number through a random number generation unit, and use the asymmetric encryption calculation unit to generate their own public and private key pairs, and exchange public keys. Each uses the other party's public key and its own private key to negotiate the shared key information; S3: A key is derived from the negotiated shared key information, and the burned software code is encrypted using a symmetric key encryption unit; the burning device sends the encrypted software code to the target microcontroller; S4: The confidentiality burning module in the target microcontroller decrypts the software code and writes it into the non-volatile memory of the target microcontroller.
2. The method for confidentiality burning of a microcontroller according to claim 1, characterized in that: After pre-configuring the read protection of the target microcontroller to be in an effective state, run the confidentiality burning module and start transmitting confidential information; or after running the confidentiality burning module, first configure the read protection of the target microcontroller to be effective but not effective, and once any reset of the target microcontroller occurs, it will take effect, and then start transmitting confidential information.
3. The method for confidentiality burning of a microcontroller according to claim 1, characterized in that: The confidentiality burning module in step S1 is fixed in the target microcontroller before leaving the factory or downloaded by the burning device and sent to the target microcontroller.
4. The method for confidentiality burning of a microcontroller according to claim 1, characterized in that: The communication data packets between the burning device and the confidential burning module are signed with a data stream, and the data stream signature is generated by cumulatively calculating the data stream formed by the communication data packets in and out using a hash algorithm.
5. The method for confidentially burning a microcontroller according to claim 4, characterized in that: After the two parties have negotiated the shared key information, the shared key information is included in the calculation of the data stream signature.
6. The method for securely burning a microcontroller according to claim 1, characterized in that: Also includes: Send and run one or more target microcontroller authenticity determination codes to the target microcontroller. If the authenticity determination code passes, the target microcontroller is determined to be a real target microcontroller, and the subsequent steps are continued.
7. The method for securely burning a microcontroller according to claim 6, characterized in that: The specific steps include: a: The burning device downloads the confidential burning module to the target microcontroller and negotiates the shared key information; b: The burning device downloads an authenticity determination code to the target microcontroller; c: Run the authenticity judgment code and return the result to the burning device; d: Determine whether the authenticity judgment code is abnormal. If so, proceed to step e; otherwise, proceed to step f; e: authenticity judgment exception handling; f: whether to repeat the authenticity judgment, if yes, return to step 2; otherwise, go to step g; g: Start sending confidential information.
8. The method for securely burning a microcontroller according to claim 1, characterized in that: It also includes using video to monitor the work site where the target microcontroller is burned to prevent a third party from using a logic simulation system to simulate the target microcontroller and deceive the burning equipment to obtain software codes that need to be kept confidential.
9. A burning device for confidentially burning a microcontroller, characterized in that: include: A random number generating unit, used for obtaining random numbers; The asymmetric encryption calculation unit is used to generate public and private key pairs from the acquired random numbers, exchange public keys, and negotiate shared key information using the other party's public key and its own private key; Data communication unit, used for sending and receiving data packets between the burning device and the target microcontroller; The symmetric encryption calculation unit is used to derive a key from the negotiated shared key information and encrypt the burned software code using a symmetric key encryption algorithm.
10. The device for programming a microcontroller in a confidential manner according to claim 9, characterized in that: The device also includes a data stream signature unit, which is used for performing data stream signature on the communication data packets between the burning device and the target microcontroller.
