An embedded BootLoader security upgrade method based on double check and dynamic key

The embedded BootLoader security upgrade method using dual verification and dynamic keys achieves high-security and high-reliability firmware upgrades for embedded devices. It solves the problems of insufficient device state constraints and inadequate identity authentication in existing technologies, and reduces the risk of man-in-the-middle attacks and firmware tampering.

CN123137689APending Publication Date: 2026-11-20仲海旭
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611482122.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-22
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing embedded BootLoader firmware remote upgrade solutions suffer from a lack of device security state constraints in key derivation, and a lack of two-way authentication and firmware downgrade prevention verification. This results in a high risk of man-in-the-middle attacks, replay attacks, and firmware tampering, failing to meet the high security and high reliability requirements of embedded devices.

Method used

An embedded BootLoader security upgrade method employing dual verification and dynamic keys is adopted. A session dynamic key is generated through two-way authentication, combined with version number verification and secondary re-verification, to ensure the security and reliability of firmware upgrades.

Benefits of technology

It reduces the risk of man-in-the-middle attacks and firmware replay, prevents the redeployment of older firmware versions, and improves the security and reliability of firmware upgrades.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123137689A_ABST
    Figure CN123137689A_ABST
Patent Text Reader

Abstract

The application discloses a kind of embedded BootLoader security upgrade method based on double check and dynamic key, it is related to embedded system firmware upgrade technical field.The method includes: BootLoader and server complete two-way identity authentication, and based on equipment unique hardware identification, first random number, server random number, time stamp and current security version number session dynamic key is derived;Server uses session dynamic key to authenticate and encrypt upgrade package, and upgrade package includes header metadata and firmware data body;BootLoader decrypts and verifies authentication tag, and sequentially carries out integrity check, digital signature verification and version check;After all pass, execute atomic flashing and secondary recheck, pass and update monotonic counter version, otherwise terminate upgrade or roll back old firmware.The application includes current security version number into session dynamic key derivation, combined with double check and anti-downgrade judgment, reduce man-in-the-middle attack, replay attack and firmware downgrade risk, suitable for resource-restricted embedded device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of embedded system firmware upgrade, specifically an embedded BootLoader security upgrade method based on dual verification and dynamic keys. Background Technology

[0002] In embedded devices, the BootLoader, as the first program executed after the system powers on, undertakes critical functions such as hardware initialization, firmware loading, upgrade verification, and startup control, serving as the root of trust in the entire device's trust chain. With the large-scale deployment of massive terminals such as the Internet of Things, connected vehicles, and smart meters, remote online firmware upgrades have become an important means of device maintenance and vulnerability patching. However, the upgrade process faces various security threats, including firmware tampering, man-in-the-middle attacks, and replay attacks.

[0003] Existing embedded bootloader firmware remote upgrade solutions mostly adopt a security mechanism that combines fixed keys or simple dynamic keys with one-way identity verification. Key derivation lacks freshness constraints such as device security status, timestamp, and version number, and lacks a complete two-way identity authentication and firmware anti-downgrade verification system. This makes it very easy to cause man-in-the-middle attacks, replay attacks, and firmware downgrade and tampering problems. The security mechanism has poor linkage and cannot meet the high security and high reliability firmware upgrade requirements of embedded devices. Summary of the Invention

[0004] The purpose of this invention is to provide a secure upgrade method for an embedded BootLoader based on dual verification and dynamic keys, so as to solve the problems mentioned in the background art.

[0005] To achieve the above objectives, the present invention provides the following technical solution: a secure upgrade method for an embedded BootLoader based on dual verification and dynamic keys, comprising the following steps:

[0006] Step S1: The BootLoader generates a first random number, reads the current security version number of the monotonic counter and the locally stored unique hardware identifier of the device, and sends an upgrade request; the server matches the hash digest of the unique hardware identifier of the device carried in the upgrade request with the pre-stored unique hardware identifier of the device, generates a server random number and a timestamp, and sends it to the BootLoader through an authentication response; after two-way authentication is completed, both parties generate a session dynamic key based on the unique hardware identifier of the device, the first random number, the server random number, the timestamp, and the current security version number;

[0007] Step S2: The server uses the session dynamic key to authenticate and encrypt the upgrade package to obtain an encrypted upgrade package; the upgrade package includes header metadata and firmware data body. The header metadata records the target version number, target partition number, integrity check value and digital signature. The digital signature is generated by the server using its own private key to sign the firmware data body.

[0008] Step S3: The BootLoader receives the encrypted upgrade package, uses the session dynamic key to complete authentication decryption and verify the authentication tag, and obtains the header metadata, the firmware data body and the authentication verification result.

[0009] Step S4: The BootLoader calculates the integrity check value of the firmware data body, compares it with the integrity check value in the header metadata to obtain the integrity check result, and uses a preset public key to verify the digital signature to obtain the signature verification result.

[0010] Step S5: The BootLoader extracts the target version number from the header metadata, compares and determines that the target version number is greater than the current security version number, and obtains the version verification result;

[0011] Step S6: When the authentication verification result, the integrity verification result, the signature verification result, and the version verification result all pass, the BootLoader atomically writes the firmware data body to the target partition corresponding to the target partition number and performs a second re-verification; if the second re-verification passes, the current security version number of the monotonic counter is updated to the target version number; if any verification result fails, the upgrade is terminated; if the second re-verification fails, the firmware is rolled back to the old version in the backup partition.

[0012] Furthermore, the two-way authentication described in step S1 includes:

[0013] The BootLoader sends an upgrade request to the server. The upgrade request carries a hash digest of the device's unique hardware identifier, the first random number, the current security version number, and the device signature. The device signature is generated by the BootLoader using the device's private key to sign the first random number and the current security version number.

[0014] The server uses the device public key to verify the device signature. After successful verification, it generates the server random number and the timestamp, and uses the server private key to sign the server random number and the timestamp. It then generates a server authentication response containing the server random number, the timestamp, and a first signature value, and sends it to the BootLoader.

[0015] After BootLoader verifies that the timestamp is within a preset time window, it uses the server's public key to verify the first signature value. After successful verification, it uses the device's private key to sign the server's random number and the timestamp, generating a device authentication response containing a second signature value and uploading it to the server.

[0016] The server uses the device's public key to verify the second signature value, and completes two-way authentication upon successful verification.

[0017] Furthermore, before step S1, there is also a BootLoader integrity self-verification: the BootLoader reads all its own code segment data and calculates the code segment hash value using the SHA-256 algorithm; the code segment hash value is compared with the standard hash value pre-stored in the one-time programmable memory; if the comparison is consistent, the self-verification is deemed to have passed and step S1 is executed; if the comparison is inconsistent, the BootLoader enters the security recovery mode, rejects all remote upgrade requests, and reports alarm information to the server through the communication interface.

[0018] Furthermore, the unique hardware identifier of the device is a private identifier securely stored locally on the device and is not transmitted in plaintext to the outside world; the derivation of the session dynamic key adopts the HMAC-SHA256 or HKDF algorithm.

[0019] Furthermore, the authentication encryption algorithm adopts AES-GCM or SM4-GCM; the header metadata also includes an upgrade strategy; in step S3, after the BootLoader completes the authentication decryption, it verifies whether the target partition number is valid, and determines the firmware data body flashing method according to the upgrade strategy.

[0020] Furthermore, the integrity verification value is generated using any one of the algorithms CRC, SHA-256, or SM3; the digital signature is generated using the ECC, RSA, or SM2 algorithm; and the preset public key is pre-stored in the BootLoader's trusted storage area.

[0021] Furthermore, the header metadata also includes a version commitment; the version commitment is generated by the server using the session dynamic key to authenticate and encrypt the target version number; in step S5, the BootLoader decrypts the version commitment, compares the target version number contained in it with the target version number in the header metadata, and if they match, then determines whether the target version number is greater than the current security version number, thus completing the version verification.

[0022] Furthermore, the monotonic counter includes a software monotonic counter and an eFuse hardware version storage unit; in step S6, after the second re-check passes, the software monotonic counter updates the stored current security version number to the target version number; the eFuse hardware version storage unit updates the stored version value to the target version number by melting the corresponding bit.

[0023] Furthermore, the secondary re-check in step S6 includes: rereading the firmware data body that has been flashed in the target partition, recalculating the integrity check value, and comparing it with the integrity check value in the header metadata. If the comparison is consistent, the secondary re-check is determined to be passed.

[0024] Furthermore, after step S6 is completed, the BootLoader overwrites and clears the RAM area storing the session dynamic key, and clears the key derivation cache data of the device's unique hardware identifier, the first random number, the server random number, the timestamp, and the current security version number.

[0025] Compared with the prior art, the beneficial effects of the present invention are:

[0026] 1. In this invention, through two-way authentication between the BootLoader and the server, both parties verify each other's identities before the generation of the session dynamic key, reducing the risk of unauthorized acquisition of firmware upgrades or session dynamic keys due to man-in-the-middle attacks.

[0027] 2. In this invention, the current security version number is introduced during the session dynamic key derivation process, so that the session dynamic key is bound to the current security status of the device. The session dynamic key corresponding to the historical upgrade package cannot be reproduced after the device version changes, thereby reducing the risk of historical legitimate upgrade packages being replayed.

[0028] 3. In this invention, after the double verification passes, the target version number is compared with the current security version number in the monotonic counter. Only firmware with a target version number greater than the current security version number is allowed to be flashed. Combined with atomic flashing and secondary verification, the risk of old firmware being redeployed and flashing failure causing device abnormalities is reduced. Attached Figure Description

[0029] Figure 1 This is a flowchart illustrating an embedded BootLoader security upgrade method based on dual verification and dynamic keys according to the present invention. Detailed Implementation

[0030] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0031] Figure 1 The flowchart of an embedded BootLoader security upgrade method based on dual verification and dynamic key according to an embodiment of the present invention is shown, including steps S1 to S6.

[0032] In this embodiment, the embedded device includes a BootLoader, an application firmware partition, a backup partition, a monotonic counter, a trusted storage area, and a communication interface. The server is a remote upgrade server, storing the device's unique hardware identifier, device certificate, device public key, server private key, and firmware upgrade package.

[0033] Step S1: Two-way authentication and dynamic session key derivation

[0034] After the BootLoader powers on, it first performs an integrity self-verification (optional step S0). Specifically, the BootLoader reads all bytes of its own code segment data and calculates the code segment hash value using the SHA-256 algorithm; it compares the code segment hash value with the standard hash value pre-stored in the one-time programmable memory; if the comparison matches, the self-verification is deemed successful and continues; if the comparison does not match, it enters a secure recovery mode, rejects all remote upgrade requests, and reports alarm information to the server through the communication interface.

[0035] After the self-verification passes, the BootLoader generates the first random number. Read the current security version number stored in the monotonic counter. The unique hardware identifier of the device that reads local secure storage. The BootLoader sends an upgrade request to the server, the upgrade request carrying... ( (hash digest) , and device signature Device signature is generated by the BootLoader using the device's private key. and Generate a signature.

[0036] The server, based on the upgrade request... The query matches the pre-stored data. The server verifies the device signature using the device's public key. After successful verification, the server generates a server random number. and current timestamp Using the server's private key and Signature, generate containing , The server authenticates the response with the first signature value and sends it to the BootLoader.

[0037] BootLoader verification Within a preset time window, the system verifies the first signature value using the server's public key. Upon successful verification, the BootLoader uses the device's private key to... and The system generates a device authentication response containing a second signature value and uploads it to the server. The server uses the device's public key to verify the second signature value. Once the verification is successful, two-way authentication is completed.

[0038] After two-way authentication is completed, both parties will respectively base their authentication on... , , , and The session dynamic key is generated using a preset key derivation function (such as HMAC-SHA256 or HKDF). .

[0039] Example key derivation expression:

[0040]

[0041] in" "" indicates data splicing.

[0042] During the key derivation process, the device side and the server side each use the original value of the device's unique hardware identifier stored locally to participate in the calculation. This original value is not transmitted over the network and is only used for local key derivation. The hash digest of the device's unique hardware identifier carried in the upgrade request is only used by the server side to match the device identity and does not participate in key derivation.

[0043] Step S2: Server Encryption Upgrade Package

[0044] server utilization The upgrade package is authenticated and encrypted to obtain an encrypted upgrade package. The upgrade package includes header metadata and firmware data body. The header metadata records the target version number. Target partition number Integrity check value and digital signatures $$

[0045] The integrity check value can be calculated from the firmware data body using any of the algorithms CRC, SHA-256, or SM3. The digital signature is generated by the server using its own private key to sign the firmware data body; the signature algorithm can be ECC, RSA, or SM2. The authentication encryption algorithm can be AES-GCM or SM4-GCM, and the authentication tag is attached to the encryption upgrade package.

[0046] Step S3: BootLoader Authentication Decryption

[0047] The BootLoader receives the encrypted upgrade package and uses it. The encrypted upgrade package is authenticated and decrypted, and the authentication tag is verified to obtain the header metadata, firmware data body, and authentication verification result. If the authentication tag verification fails, the authentication verification result is not passed, and the upgrade is terminated.

[0048] Step S4: Integrity Verification and Signature Verification

[0049] The BootLoader calculates the integrity check value of the firmware data body and compares it with the integrity check value in the header metadata to obtain the integrity check result. If the two are inconsistent, the integrity check result fails, and the upgrade is terminated. If the integrity check passes, the BootLoader uses a pre-stored public key in a trusted storage area to verify the digital signature and obtain the signature verification result. If the signature verification fails, the upgrade is terminated.

[0050] The trusted storage area is a secure storage area in the MCU's on-chip Flash memory, protected by hardware read / write protection mechanisms, and accessible only to the BootLoader.

[0051] Step S5: Version Verification

[0052] The BootLoader extracts the target version number from the header metadata. Read the current security version number of the monotonic counter. ,judge Is it greater than The version verification result is obtained. Not greater than If the risk of a downgrade attack is identified, the upgrade will be terminated.

[0053] Optionally, the header metadata may also include a version commitment. The version commitment is adopted by the server. right The authentication encryption is generated. The BootLoader decrypts the version commitment, compares the target version number contained within it with the target version number in the header metadata, and only performs the above version size comparison after they match, to prevent the target version number in the header metadata from being tampered with separately.

[0054] Step S6: Atomic write, secondary verification and version update

[0055] When the authentication verification result, integrity verification result, signature verification result, and version verification result all pass, the BootLoader atomically flashes the firmware data body to the target partition corresponding to the target partition number. Specifically, the BootLoader can write the firmware data body in blocks to the target partition, and perform a second re-verification after all blocks have been written. The second re-verification includes: rereading the firmware data body that has already been flashed in the target partition, recalculating the integrity verification value, and comparing it with the integrity verification value in the header metadata. If the comparison is consistent, the second re-verification is considered to have passed.

[0056] If the second verification passes, the BootLoader updates the current security version number in the monotonic counter to the target version number. When the monotonic counter is a software monotonic counter, its stored value is updated to... When the monotonic counter is the eFuse hardware version storage unit, the stored version value is updated by fusing the corresponding eFuse bit. You can then reboot the device to load the new firmware.

[0057] If any verification result fails, the upgrade process is terminated, and the old firmware version is retained. If the second verification fails, the BootLoader performs a rollback operation, rolling back to the old firmware version in the backup partition, and refusing to boot the newly flashed firmware.

[0058] After step S6 is completed, BootLoader also overwrites and clears the RAM area storing the session dynamic key, and clears the key derivation cache data including the device's unique hardware identifier, the first random number, the server random number, the timestamp, and the current security version number to prevent key residue.

[0059] Through the above steps, this invention achieves integrated security management of two-way authentication, dynamic keys, dual verification, anti-downgrade, atomic writing, and failure rollback during the embedded BootLoader security upgrade process, which has high practical value on resource-constrained embedded devices.

[0060] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A secure upgrade method for an embedded BootLoader based on dual verification and dynamic keys, characterized in that, include: Step S1: The BootLoader generates the first random number, reads the current security version number of the monotonic counter and the unique hardware identifier of the device stored locally, and sends an upgrade request. The server matches the pre-stored unique hardware identifier of the device with the hash digest of the unique hardware identifier of the device carried in the upgrade request, generates a server random number and a timestamp, and sends it to the BootLoader through an authentication response; after the two-way authentication is completed, both parties generate a session dynamic key based on the unique hardware identifier of the device, the first random number, the server random number, the timestamp, and the current security version number; Step S2: The server uses the session dynamic key to authenticate and encrypt the upgrade package to obtain an encrypted upgrade package; the upgrade package includes header metadata and firmware data body. The header metadata records the target version number, target partition number, integrity check value and digital signature. The digital signature is generated by the server using its own private key to sign the firmware data body. Step S3: The BootLoader receives the encrypted upgrade package, uses the session dynamic key to complete authentication decryption and verify the authentication tag, and obtains the header metadata, the firmware data body and the authentication verification result. Step S4: The BootLoader calculates the integrity check value of the firmware data body, compares it with the integrity check value in the header metadata to obtain the integrity check result, and uses a preset public key to verify the digital signature to obtain the signature verification result. Step S5: The BootLoader extracts the target version number from the header metadata, compares and determines that the target version number is greater than the current security version number, and obtains the version verification result; Step S6: When the authentication verification result, the integrity verification result, the signature verification result, and the version verification result all pass, the BootLoader atomically flashes the firmware data body to the target partition corresponding to the target partition number and performs a second re-verification; if the second re-verification passes, the current security version number of the monotonic counter is updated to the target version number; The upgrade will be terminated if any verification result fails. If the second re-inspection fails, the firmware will be rolled back to the old version in the backup partition.

2. The method according to claim 1, characterized in that, The two-way authentication mentioned in step S1 includes: The BootLoader sends an upgrade request to the server. The upgrade request carries a hash digest of the device's unique hardware identifier, the first random number, the current security version number, and the device signature. The device signature is generated by the BootLoader using the device's private key to sign the first random number and the current security version number. The server uses the device public key to verify the device signature. After successful verification, it generates the server random number and the timestamp, and uses the server private key to sign the server random number and the timestamp. It then generates a server authentication response containing the server random number, the timestamp, and a first signature value, and sends it to the BootLoader. After BootLoader verifies that the timestamp is within a preset time window, it uses the server's public key to verify the first signature value. After successful verification, it uses the device's private key to sign the server's random number and the timestamp, generating a device authentication response containing a second signature value and uploading it to the server. The server uses the device's public key to verify the second signature value, and completes two-way authentication upon successful verification.

3. The method according to claim 1, characterized in that, Step S1 is preceded by a BootLoader integrity self-verification: The BootLoader reads all its own code segment data and calculates the code segment hash value using the SHA-256 algorithm. It then compares the code segment hash value with the standard hash value pre-stored in the one-time programmable memory. If the comparison matches, the self-verification is deemed successful and step S1 is executed. If the comparison does not match, the BootLoader enters the security recovery mode, rejects all remote upgrade requests, and reports alarm information to the server through the communication interface.

4. The method according to claim 1, characterized in that, The unique hardware identifier of the device is a private identifier securely stored locally on the device and is not transmitted in plaintext to the outside world; the derivation of the session dynamic key adopts the HMAC-SHA256 or HKDF algorithm.

5. The method according to claim 1, characterized in that, The authentication encryption algorithm adopts AES-GCM or SM4-GCM; the header metadata also includes an upgrade strategy; in step S3, after the BootLoader completes the authentication decryption, it verifies whether the target partition number is valid, and determines the firmware data body flashing method according to the upgrade strategy.

6. The method according to claim 1, characterized in that, The integrity verification value is generated using any one of the algorithms CRC, SHA-256, or SM3; the digital signature is generated using the algorithms ECC, RSA, or SM2; and the preset public key is pre-stored in the BootLoader's trusted storage area.

7. The method according to claim 1, characterized in that, The header metadata also includes a version commitment; the version commitment is generated by the server using the session dynamic key to authenticate and encrypt the target version number; in step S5, the BootLoader decrypts the version commitment, compares the target version number contained in it with the target version number in the header metadata, and if they match, then determines whether the target version number is greater than the current security version number, thus completing the version verification.

8. The method according to claim 1, characterized in that, The monotonic counter includes a software monotonic counter and an eFuse hardware version storage unit; in step S6, after the second re-check passes, the software monotonic counter updates the stored current security version number to the target version number; the eFuse hardware version storage unit updates the stored version value to the target version number by melting the corresponding bit.

9. The method according to claim 1, characterized in that, The secondary re-check in step S6 includes: rereading the firmware data body that has been flashed in the target partition, recalculating the integrity check value, and comparing it with the integrity check value in the header metadata. If the comparison is consistent, the secondary re-check is determined to be passed.

10. The method according to claim 1, characterized in that, After step S6 is completed, the BootLoader overwrites and clears the RAM area storing the session dynamic key, and clears the key derivation cache data of the device's unique hardware identifier, the first random number, the server random number, the timestamp, and the current security version number.