A device firmware data integrity self-checking method, an electronic device, and a storage medium
By combining quantum key distribution with integrity self-checking during the device startup phase, the problem of low security in existing firmware integrity verification schemes is solved, and self-checking and security assurance of device firmware data are achieved.
Patent Information
- Application Number
- CN202611317344.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-11-06
AI Technical Summary
Existing firmware integrity verification schemes are not very secure. Attackers can cause device malfunctions by tampering with firmware baseline values. Existing schemes are also unable to perform self-checks during device startup.
During the device startup phase, integrity self-checks are performed using quantum keys. This is achieved by appending a MAC checksum to the Flash memory and calculating the MAC checksum using the quantum key, thus ensuring the integrity of the device firmware data.
It effectively prevents third parties from tampering with the device firmware code, improves the security of device firmware data, and ensures the integrity self-check of the device during the boot process.
Smart Images

Figure CN123055403A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of quantum information systems and embedded software technology, specifically to a method for self-testing the integrity of device firmware data, an electronic device, and a storage medium. Background Technology
[0002] Quantum technology is an interdisciplinary field encompassing physics, information theory, mathematical sciences, and computational science, particularly involved in the development of software systems such as post-processing systems and embedded systems. Embedded products typically provide a bootloader and application firmware. Existing firmware integrity verification schemes verify firmware integrity by calculating a checksum and comparing it with a pre-stored baseline value. This is commonly seen in the self-test process during the startup phase of embedded systems, where firmware integrity verification is implemented through the bootloader. However, attackers can reverse engineer and tamper with the firmware while simultaneously modifying the baseline value, resulting in low security.
[0003] Furthermore, existing firmware integrity checks are typically performed during the firmware burning process. For example, the device firmware transmits data via network, CAN bus, or serial bus and is burned using a bootloader. After burning, the host computer returns a verification code to the other end to verify the firmware's integrity. However, this approach does not implement self-checks during the device's boot process. If an attacker maliciously tampers with the firmware and modifies the device's operating data, this can lead to security issues or cause the device to malfunction.
[0004] Therefore, existing firmware integrity verification schemes are not secure enough and cannot protect the security of device firmware data. Summary of the Invention
[0005] To address the issue of insufficient security in existing firmware integrity verification schemes, this invention provides a device firmware data integrity self-testing method, electronic device, and storage medium.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0007] A device firmware data integrity self-test method includes the following steps:
[0008] S1: Compile and generate the bin file of the device firmware, and record the size of the device firmware;
[0009] S2: Determine the Flash memory address of the device firmware verification area based on the device firmware size, and recompile to generate a new bin file;
[0010] S3: Append a MAC checksum to the new bin file;
[0011] S4: Burn the bin file with the MAC checksum appended in step S3 to the Flash memory;
[0012] S5: Power on the device and perform a self-check of the device firmware integrity based on the MAC checksum;
[0013] If the integrity is correct, the device will set the default key flag to zero and proceed to step S6;
[0014] If the integrity is incorrect, the device enters a hardware error state and executes step S10;
[0015] S6: Charge the device with quantum keys, set the first charged quantum key as the quantum verification key, and store the subsequently charged quantum keys in blocks in the device's eMMC memory;
[0016] S7: Use the quantum verification key to recalculate the MAC checksum in the device firmware and store it in the device firmware verification area;
[0017] S8: Perform a software reset on the device and determine whether the default key flag is set to zero;
[0018] If so, the quantum key is read from the device's eMMC memory as the new quantum verification key to calculate the new MAC checksum;
[0019] If not, the new MAC checksum is calculated using the default verification key in the device's read-only storage.
[0020] S9: Determine whether the new MAC checksum matches the MAC checksum in the Flash memory;
[0021] If they match, the device firmware data integrity self-test is complete;
[0022] If they do not match, return to step S4;
[0023] S10: Execution complete.
[0024] In the above scheme, by combining the integrity self-check with quantum key distribution during the device startup phase, the tampering of the device firmware code by third parties is effectively prevented, ensuring the integrity of the device firmware data and improving the security of the device firmware data.
[0025] Preferably, the size of the new bin file generated in step S2 is the same as the size of the bin file generated in step S1.
[0026] Preferably, step S3 further includes appending a default key flag and file size to the new bin file.
[0027] Preferably, the default key flag length is 2 bytes.
[0028] Preferably, the file size is 4 bytes in length.
[0029] Preferably, the MAC checksum is calculated using the SM4-CBC-MAC method.
[0030] Preferably, the length of the MAC checksum is 16 bytes.
[0031] Preferably, in step S5, the device firmware integrity is self-checked based on the MAC checksum through the following steps:
[0032] S5.1: Read device firmware verification area data, including default key flag and MAC checksum;
[0033] S5.2: Determine if the default key flag is true;
[0034] If true, the first MAC checksum is calculated using the default verification key in the device's read-only storage area;
[0035] If not true, the quantum key is read from the device's eMMC memory to calculate the first MAC checksum;
[0036] S5.3: Compare whether the first MAC checksum and the MAC checksum are the same;
[0037] If so, the device firmware integrity is correct, the device will set the default key flag to zero, and proceed to step S6;
[0038] If not, the device firmware integrity is incorrect, the device enters a hardware error state, and step S10 is executed.
[0039] Based on the aforementioned device firmware data integrity self-test method, this invention also proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it causes the processor to execute the aforementioned device firmware data integrity self-test method.
[0040] Based on the aforementioned device firmware data integrity self-test method, this invention also proposes a computer storage medium storing a computer program thereon. When the computer program is executed by a processor, the processor executes the aforementioned device firmware data integrity self-test method.
[0041] Beneficial technical effects of the present invention:
[0042] This invention provides a device firmware data integrity self-test method, an electronic device, and a storage medium. By performing integrity self-testing during the device startup phase and in conjunction with quantum key distribution, it effectively prevents third parties from tampering with the device firmware code, ensuring device firmware data integrity and improving device firmware data security. Attached Figure Description
[0043] Figure 1 This is a schematic diagram of the Flash region division in this invention;
[0044] Figure 2 This is a flowchart illustrating the implementation steps of the technical solution of the present invention. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the embodiments. However, the scope of protection of this invention is not limited to the specific embodiments described below.
[0046] Example 1
[0047] like Figure 1-2 As shown, a device firmware data integrity self-test method includes the following steps:
[0048] S1: Use the cross-compilation toolchain to compile and generate the bin file of the device firmware, and record the size of the device firmware;
[0049] S2: Determine the Flash memory address of the device firmware verification area based on the device firmware size, and recompile to generate a new bin file;
[0050] S3: Use a MAC checksum appending tool to append a MAC checksum to the new bin file;
[0051] S4: Burn the bin file with the MAC checksum appended in step S3 to the Flash memory;
[0052] S5: Power on the device and perform a self-check of the device firmware integrity based on the MAC checksum;
[0053] If the integrity is correct, the device will set the default key flag to zero and proceed to step S6;
[0054] If the integrity is incorrect, the device enters a hardware error state and executes step S10;
[0055] S6: Use a quantum key injection tool on the host (PC) to inject quantum keys into the device through a serial communication interface (usb, can, sdio, uart), set the first injected quantum key as the quantum verification key, and store the subsequently injected quantum keys in blocks in the device's eMMC memory;
[0056] S7: Use the quantum verification key to recalculate the MAC checksum in the device firmware and store it in the device firmware verification area;
[0057] S8: Perform a software reset on the device and determine whether the default key flag is set to zero;
[0058] If so, the quantum key is read from the device's eMMC memory as the new quantum verification key to calculate the new MAC checksum;
[0059] If not, the new MAC checksum is calculated using the default verification key in the device's read-only storage.
[0060] S9: Determine whether the new MAC checksum matches the MAC checksum in the Flash memory;
[0061] If they match, the device firmware data integrity self-test is complete;
[0062] If they do not match, return to step S4;
[0063] S10: Execution complete.
[0064] In practice, by combining the device startup phase with quantum key distribution for integrity self-checks, the system effectively prevents third parties from tampering with the device firmware code, ensuring the integrity of the device firmware data and improving the security of the device firmware data.
[0065] Example 2
[0066] A device firmware data integrity self-test method includes the following steps:
[0067] S1: Use the cross-compilation toolchain to compile and generate the bin file of the device firmware, and record the size of the device firmware;
[0068] S2: Determine the Flash memory address of the device firmware verification area based on the device firmware size, and recompile to generate a new bin file;
[0069] More specifically, the new bin file generated in step S2 is the same size as the bin file generated in step S1.
[0070] S3: Use a MAC checksum appending tool to append a MAC checksum to the new bin file;
[0071] More specifically, step S3 also includes appending a default key flag and file size to the new bin file.
[0072] More specifically, the default key flag is 2 bytes long.
[0073] More specifically, the file size is 4 bytes long.
[0074] In the specific implementation process, the file padding size is first determined based on the size of the bin file, and the padding data is 0. The file padding size is determined by looking up a table to ensure that the file size after padding is consistent with the starting address offset of the firmware verification area flash. Then, the default key flag, file size and MAC checksum are appended to the file. The initial key is the device's default verification key, which is determined by the configuration file of the MAC checksum appending tool. The default checksum is consistent with the checksum on the device firmware code.
[0075] S4: Burn the bin file with the MAC checksum appended in step S3 to the Flash memory;
[0076] S5: Power on the device and perform a self-check of the device firmware integrity based on the MAC checksum;
[0077] More specifically, in step S5, the device firmware integrity is self-checked based on the MAC checksum through the following steps:
[0078] S5.1: Read device firmware verification area data, including default key flag and MAC checksum;
[0079] S5.2: Determine if the default key flag is true;
[0080] If true, the first MAC checksum is calculated using the default verification key in the device's read-only storage area;
[0081] If not true, the quantum key is read from the device's eMMC memory to calculate the first MAC checksum;
[0082] S5.3: Compare whether the first MAC checksum and the MAC checksum are the same;
[0083] If so, the device firmware integrity is correct, the device will set the default key flag to zero, and proceed to step S6;
[0084] If not, the device firmware integrity is incorrect, the device enters a hardware error state, and step S10 is executed.
[0085] S6: Use a quantum key injection tool on the host (PC) to inject quantum keys into the device through a serial communication interface (usb, can, sdio, uart), set the first injected quantum key as the quantum verification key, and store the subsequently injected quantum keys in blocks in the device's eMMC memory;
[0086] S7: Use the quantum verification key to recalculate the MAC checksum in the device firmware and store it in the device firmware verification area;
[0087] S8: Perform a software reset on the device and determine whether the default key flag is set to zero;
[0088] If so, the quantum key is read from the device's eMMC memory as the new quantum verification key to calculate the new MAC checksum;
[0089] If not, the new MAC checksum is calculated using the default verification key in the device's read-only storage.
[0090] S9: Determine whether the new MAC checksum matches the MAC checksum in the Flash memory;
[0091] If they match, the device firmware data integrity self-test is complete;
[0092] If they do not match, return to step S4;
[0093] S10: Execution complete.
[0094] More specifically, the MAC checksum is calculated using the sm4-cbc-mac method.
[0095] More specifically, the MAC checksum is 16 bytes long.
[0096] Example 3
[0097] Based on the aforementioned device firmware data integrity self-test method, this invention also proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it causes the processor to execute the aforementioned device firmware data integrity self-test method.
[0098] Example 4
[0099] Based on the aforementioned device firmware data integrity self-test method, this invention also proposes a computer storage medium storing a computer program thereon. When the computer program is executed by a processor, the processor executes the aforementioned device firmware data integrity self-test method.
[0100] Based on the disclosure and teachings of the foregoing specification, those skilled in the art can make changes and modifications to the above embodiments. Therefore, the present invention is not limited to the specific embodiments disclosed and described above, and some modifications and changes to the invention should also fall within the protection scope of the claims of the present invention. Furthermore, although some specific terms are used in this specification, these terms are only for convenience of explanation and do not constitute any limitation on the present invention.
Claims
1. A method for self-checking the integrity of device firmware data, characterized in that, Includes the following steps: S1: Compile and generate the bin file of the device firmware, and record the size of the device firmware; S2: Determine the Flash memory address of the device firmware verification area based on the device firmware size, and recompile to generate a new bin file; S3: Append a MAC checksum to the new bin file; S4: Burn the bin file with the MAC checksum appended in step S3 to the Flash memory; S5: Power on the device and perform a self-check of the device firmware integrity based on the MAC checksum; If the integrity is correct, the device will set the default key flag to zero and proceed to step S6; If the integrity is incorrect, the device enters a hardware error state and executes step S10; S6: Charge the device with quantum keys, set the first charged quantum key as the quantum verification key, and store the subsequently charged quantum keys in blocks in the device's eMMC memory; S7: Use the quantum verification key to recalculate the MAC checksum in the device firmware and store it in the device firmware verification area; S8: Perform a software reset on the device and determine whether the default key flag is set to zero; If so, the quantum key is read from the device's eMMC memory as the new quantum verification key to calculate the new MAC checksum; If not, the new MAC checksum is calculated using the default verification key in the device's read-only storage. S9: Determine whether the new MAC checksum matches the MAC checksum in the Flash memory; If they match, the device firmware data integrity self-test is complete; If they do not match, return to step S4; S10: Execution complete.
2. The device firmware data integrity self-test method according to claim 1, characterized in that, The size of the new bin file generated in step S2 is the same as the size of the bin file generated in step S1.
3. The device firmware data integrity self-test method according to claim 1, characterized in that, Step S3 also includes appending a default key flag and file size to the new bin file.
4. The device firmware data integrity self-test method according to claim 3, characterized in that, The default key flag length is 2 bytes.
5. The device firmware data integrity self-test method according to claim 3, characterized in that, The file size is 4 bytes long.
6. The device firmware data integrity self-test method according to claim 1, characterized in that, The MAC checksum is calculated using the SM4-CBC-MAC method.
7. The device firmware data integrity self-test method according to claim 1, characterized in that, The MAC checksum is 16 bytes long.
8. A device firmware data integrity self-test method according to claim 3, characterized in that, In step S5, the device firmware integrity is self-checked based on the MAC checksum using the following steps: S5.1: Read device firmware verification area data, including default key flag and MAC checksum; S5.2: Determine if the default key flag is true; If true, the first MAC checksum is calculated using the default verification key in the device's read-only storage area; If not true, the quantum key is read from the device's eMMC memory to calculate the first MAC checksum; S5.3: Compare whether the first MAC checksum and the MAC checksum are the same; If so, the device firmware integrity is correct, the device will set the default key flag to zero, and proceed to step S6; If not, the device firmware integrity is incorrect, the device enters a hardware error state, and step S10 is executed.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the self-testing method as described in any one of claims 1 to 8.
10. A computer storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the self-testing method as described in any one of claims 1 to 8.
