A segmented metric security starting method and system based on a national secret algorithm
By segmenting the motherboard firmware image and using national cryptographic algorithms for measurement and signature verification, combined with a hardware monotonic counter and unique key management, the security issues of motherboard firmware during the upgrade process are solved, enabling reliable booting and secure recovery of the motherboard firmware.
Patent Information
- Application Number
- CN202611377643.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-07
- Publication Date
- 2026-11-24
AI Technical Summary
Motherboard firmware is susceptible to tampering, replacement, out-of-order loading, cross-device copying, or rollback to historical versions during upgrades, repairs, or storage. Furthermore, backup images are switched without sufficient verification, leading to issues with device reliability and security.
A segmented measurement secure boot method based on national cryptographic algorithms is adopted, which divides the firmware image into several boot function segments. The source, content and loading order of each firmware segment are verified by the firmware measurement list with SM3 segment digest and SM2 signature. The version state is constrained by the hardware monotonic counter, and the SM4 decryption key is derived using the device hardware unique key to control the dual-image boot state machine to perform differentiated security processing.
It effectively solves the problems of firmware tampering, out-of-order loading, cross-device copying, and historical version rollback, improves the security and reliability of motherboard firmware boot, and reduces the risk of fixed key leakage and firmware cross-device copying.
Smart Images

Figure CN123158644A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of startup security technology, and more particularly to a segmented measurement secure startup method and system based on Chinese cryptographic algorithms. Background Technology
[0002] The motherboard is a core component in industrial control, energy metering, and smart terminal equipment, responsible for data acquisition, logic control, communication interaction, and business processing. Internally, it typically houses a main control unit, function control units, display components, communication components, and interface components. The motherboard firmware performs tasks such as operational status detection, signal acquisition, data processing and computation, parameter reading, data uploading, and equipment interlocking control. Its operational status directly impacts the reliability of the equipment and the security of its business processes.
[0003] In motherboard network management, remote upgrades, and intelligent operation and maintenance functions, firmware images may be illegally replaced, partially tampered with, or rolled back during upgrade transmission, equipment repair, or storage. For example, tampering with the control program may cause abnormal data processing results or control logic anomalies; reloading historical firmware may cause patched security vulnerabilities to reappear; and mixing different versions of functional programs may cause interface incompatibility or control logic anomalies. Therefore, it is necessary to verify the source, integrity, and version validity of the motherboard firmware before loading it.
[0004] Furthermore, existing motherboards use fixed keys or unified device keys to decrypt firmware, and these decryption keys lack correlation with the motherboard hardware identity, firmware version, and actual measurement results. If the key is leaked, the encrypted firmware may be copied and used on other motherboards. Existing dual-image recovery mechanisms often switch to the backup image directly based on whether the boot process is successful, without verifying the backup image based on abnormal firmware segments, abnormal boot stages, and version status. This can easily lead to issues such as repeated image switching, loading of lower-version firmware, or abnormally exposed debug interfaces. Summary of the Invention
[0005] To address the aforementioned issues, this invention provides a segmented measurement-based secure boot method and system based on national cryptographic algorithms.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows: A segmented measurement-based secure boot method based on Chinese cryptographic algorithms includes the following steps: The firmware image is divided into several boot function segments according to the motherboard boot dependency relationship. The SM3 segment digest of each boot function segment is calculated, and a firmware metric list signed by SM2 is generated based on the segment identifier, the preceding segment identifier, the SM3 segment digest, the firmware version number and the boot stage identifier. The target firmware segment is determined based on the current startup phase. The firmware metric list is verified with SM2 signature, and the target firmware segment is verified for digest consistency. The target firmware segment with valid signature and consistent digest is determined as a trusted firmware segment. The current stage metric is generated based on the previous stage metric, the SM3 segment digest of the trusted firmware segment, and the startup stage identifier. The firmware version number is then compared with the security version value recorded by the hardware monotonic counter to determine the firmware segment to be loaded. The SM4 decryption key is derived based on the device hardware unique key, the current stage metric value, and the firmware version number. The firmware segment to be loaded is decrypted and loaded. Based on the signature verification error, digest error, or version rollback, the dual-mirror startup state machine is controlled to perform one of the following actions: mirror switching, key clearing, and debug interface locking.
[0007] Furthermore, the division of the firmware image into several boot function segments according to the motherboard boot dependency includes: Analyze the image header, segment table, and call relationships of the motherboard firmware image to determine the entry address, loading order, and pre-order dependencies of each image region; A startup dependency graph is constructed using each mirror region as a node and the preceding dependency relationship as a directed edge, and the startup stage corresponding to each mirror region is determined based on the startup dependency graph. The firmware image is divided according to the startup stage and loading order, and segment boundaries are set at the control transfer position and access permission switching position to obtain several startup function segments.
[0008] Further, the calculation of the SM3 segment digest of each boot function segment and the generation of the SM2-signed firmware metric list includes: Read segment data according to the address range of each startup function segment, and calculate the corresponding SM3 segment digest using the SM3 algorithm; Encode the segment identifier, preceding segment identifier, SM3 segment summary, firmware version number and boot stage identifier according to the preset field order to generate metric entries corresponding to each boot functional segment. The metric entries are arranged according to the loading order of each startup function segment, and the arranged metric entries are signed with the SM2 private key to generate a firmware metric list.
[0009] Furthermore, the determination of the trusted firmware segment includes: Read the current startup stage identifier and the loaded segment identifier, and select the startup function segment whose startup stage identifier is consistent with the current startup stage identifier and whose preceding segment identifier is consistent with the loaded segment identifier from the firmware metric list, as the target firmware segment; Read the preset SM2 public key from the secure storage area, and verify the signature in the firmware metric list using the SM2 public key; Recalculate the SM3 segment digest of the target firmware segment and compare it with the SM3 segment digest in the corresponding metric entry. Target firmware segments with valid signatures and consistent SM3 segment digests are identified as trusted firmware segments.
[0010] Furthermore, generating the current stage metric includes: Based on the preceding segment identifier of the trusted firmware segment, the corresponding preceding stage metric value is read from the secure storage area, where the first startup functional segment corresponds to the preset initial metric value; The preceding stage metric value, the SM3 segment digest of the trusted firmware segment, and the startup stage identifier are encoded according to a preset field order to obtain stage metric data. Perform SM3 operation on the stage measurement data to obtain the current stage measurement value, and write the current stage measurement value into the secure storage area as the preceding stage measurement value of the next startup function segment.
[0011] Furthermore, determining the firmware segment to be loaded includes: Read the security version value recorded by the hardware monotonic counter, and extract the firmware version number corresponding to the trustworthy firmware segment from the firmware metric list; Firmware version numbers lower than the security version value are identified as version rollbacks, and trusted firmware segments with firmware version numbers not lower than the security version value and whose preceding startup function segments have all been measured are identified as firmware segments to be loaded. After the firmware image completes boot, a firmware version number higher than the security version value is written to a hardware monotonic counter to update the security version value.
[0012] Furthermore, the step of decrypting and loading the firmware segment to be loaded by deriving an SM4 decryption key based on the device hardware unique key, the current stage metric value, and the firmware version number includes: Using the device hardware unique key as the root key, the current stage metric value and firmware version number are input into the SM3-based key derivation function to obtain the stage base key; Based on the stage base key, the segment identifier of the firmware segment to be loaded, and the preceding segment identifier, a secondary key derivation is performed to obtain the SM4 decryption key associated with the boot sequence.
[0013] Furthermore, the control of the dual-mirror startup state machine to perform mirror switching, key clearing, or debug interface locking includes: A startup failure record is generated based on the exception type, exception segment identifier, startup stage identifier, and current image identifier, and the failure status of the corresponding startup stage of the current image is updated. Based on signature verification anomalies or digest anomalies, extract the corresponding startup phase and its preceding startup phase from another image, determine the candidate recovery image based on the signature validity, preceding dependency integrity and firmware version number of the metric entries, and switch the candidate recovery image to the trial operation image. Update the trial image loaded during the abnormal startup phase to the current image; if both images encounter anomalies or version rollbacks during the same startup phase, clear the corresponding phase base key and SM4 decryption key, and lock the debug interface.
[0014] Further, determining the candidate recovery image includes: Starting with the metric entry corresponding to the abnormal startup phase in another mirror, backtrack sequentially to the first startup functional segment according to the preceding segment identifier to obtain the candidate recovery dependency chain; The signature, preceding segment identifier, and startup stage identifier of each metric entry in the candidate recovery dependency chain are verified, and the SM3 segment digest of the corresponding startup function segment is recalculated. Another image with a valid signature, continuous preceding dependencies, consistent SM3 segment digests, firmware version number not lower than the security version value, and no failure records in the corresponding boot phase is identified as a candidate recovery image.
[0015] A segmented measurement-based secure boot system based on national cryptographic algorithms includes: The firmware segment signing module is used to divide the firmware image into several boot function segments according to the motherboard boot dependency relationship, calculate the SM3 segment digest of each boot function segment, and generate a firmware metric list signed by SM2 based on the segment identifier, the preceding segment identifier, the SM3 segment digest, the firmware version number and the boot stage identifier. The trusted firmware determination module is used to determine the target firmware segment based on the current startup phase, perform SM2 signature verification on the firmware metric list, and perform digest consistency verification on the target firmware segment, and determine the target firmware segment with valid signature and consistent digest as a trusted firmware segment. The stage measurement control module is used to generate the current stage measurement value based on the previous stage measurement value, the SM3 segment digest of the trusted firmware segment and the startup stage identifier, and compare the firmware version number with the security version value recorded by the hardware monotonic counter to determine the firmware segment to be loaded. The secure boot execution module is used to derive an SM4 decryption key based on the device hardware unique key, the current stage metric value, and the firmware version number, to decrypt and load the firmware segment to be loaded, and to control the dual-image boot state machine to perform one of the following actions based on signature verification failure, digest failure, or version rollback: image switching, key clearing, and debug interface locking.
[0016] The beneficial effects of this invention are as follows: This invention divides the firmware image into several boot function segments according to the motherboard boot dependency relationship. Through SM3 segment digests and a firmware metric list signed with SM2, the content, preceding relationships, firmware version, and boot stage of each firmware segment are bound together. A target firmware segment is selected based on the current boot stage, and a trusted firmware segment is determined by combining SM2 signature verification and digest consistency checks, thereby verifying the firmware source and content integrity, and avoiding the mixed use of different version firmware segments or out-of-order loading of firmware segments. Furthermore, the preceding stage metric values are incorporated into the generation of the current stage metric value, forming a continuous metric chain among the boot function segments. A hardware monotonic counter restricts the loading of lower version firmware, solving the problem of historical firmware rollback. An SM4 decryption key is derived based on the device hardware unique key, the current stage metric value, and the firmware version number, binding the decryption key to a specific motherboard, specific firmware version, and actual boot state, reducing the risk of fixed key leakage and firmware cross-device copying. Differentiated security handling is performed on the dual-image boot state machine based on signature anomalies, digest anomalies, or version rollback, effectively solving the problems of repeated switching of abnormal images, low-version recovery, and abnormally open debugging interfaces. Attached Figure Description
[0017] Figure 1 This is a flowchart of the steps of a segmented measurement secure startup method based on national cryptographic algorithms in this invention.
[0018] Figure 2 This is a flowchart illustrating the steps of dividing the firmware image into several boot function segments according to the motherboard boot dependency relationship in this invention.
[0019] Figure 3 This is a flowchart of the steps in this invention to control the dual-mirror startup state machine to perform mirror switching, key clearing, or debug interface locking.
[0020] Figure 4 This is a diagram of a segmented measurement secure startup system based on national cryptographic algorithms in this invention. Detailed Implementation
[0021] Please see Figures 1-4 As shown, this invention relates to a segmented measurement secure startup method and system based on Chinese cryptographic algorithms.
[0022] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. 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 of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0023] It should be noted that the motherboard firmware image refers to the set of program data used to implement functions such as motherboard booting, metering control, communication interaction, transaction processing, and device interlocking. A boot function segment refers to a firmware region divided according to the firmware loading order, prior dependencies, control transfer location, or access permission switching location. Boot dependencies characterize the sequential loading relationship between boot function segments; a subsequent boot function segment requires the previous boot function segment to complete a trust measurement as a loading condition.
[0024] The SM2 algorithm is used to digitally sign and verify the firmware metric manifest to confirm the firmware's origin; the SM3 algorithm is used to calculate the digest and stage metric value of the boot function segment to verify the integrity of the firmware content; and the SM4 algorithm is used to encrypt and decrypt the boot function segment. The firmware metric manifest is a set of signed data consisting of a segment identifier, a pre-sequence segment identifier, an SM3 segment digest, a firmware version number, and a boot stage identifier.
[0025] This invention primarily addresses the issues of motherboard firmware being tampered with, replaced, loaded out of order, copied across devices, or rolled back to historical versions during upgrades, repairs, or storage, as well as the problem of backup images being switched without sufficient verification. To address these issues, this invention segments the firmware image according to boot dependencies, verifies the source, content, and loading order of each firmware segment using SM2 signatures and SM3 digests; constrains the trusted transmission and version status of firmware segments through continuous stage metrics and a hardware monotonic counter; derives an SM4 decryption key based on the device's unique hardware key, the current stage metric value, and the firmware version number, binding decryption permissions to the device, version, and actual boot state; and controls dual-image switching, key clearing, and debug interface locking based on different boot anomalies, thereby improving the security of the motherboard firmware boot and anomaly recovery process.
[0026] Example 1 Figure 1 This illustrates the overall step-by-step flow of the present invention, including segmented signature, trusted verification, chained measurement, decryption loading, and exception handling. (See also...) Figure 1 This invention proposes a segmented measurement-based secure startup method based on national cryptographic algorithms, comprising the following steps: S1. Divide the firmware image into several boot function segments according to the motherboard boot dependency relationship, calculate the SM3 segment digest of each boot function segment, and generate a firmware metric list signed by SM2 based on the segment identifier, the preceding segment identifier, the SM3 segment digest, the firmware version number and the boot stage identifier. S2. Determine the target firmware segment based on the current startup phase, perform SM2 signature verification on the firmware metric list, and perform digest consistency verification on the target firmware segment. Determine the target firmware segment with valid signature and consistent digest as a trusted firmware segment. S3. Generate the current stage measurement value based on the previous stage measurement value, the SM3 segment summary of the trusted firmware segment and the startup stage identifier, and compare the firmware version number with the security version value recorded by the hardware monotonic counter to determine the firmware segment to be loaded. S4. Derive the SM4 decryption key based on the device hardware unique key, the current stage measurement value and firmware version number, decrypt and load the firmware segment to be loaded, and control the dual-image startup state machine to perform one of the following actions based on the signature verification error, digest error or version rollback: image switching, key clearing and debug interface locking.
[0027] The above steps take segmented signature as the starting point of trust, verify the target segment signature and digest to confirm the current loading object, constrain the loading order and version with continuous stage measurement and monotonic counter, and complete decryption loading and anomaly handling with device-level derived key and dual-image state machine. This forms a closed-loop secure boot scheme from firmware release, trusted verification to recovery control, which can reduce the risks of partial tampering, version mixing, out-of-order loading, cross-device copying, historical version rollback and repeated switching of abnormal images.
[0028] In step S1, the startup dependency relationship refers to the sequential dependency relationship formed between various program areas of the motherboard firmware in terms of loading order, function calls, and control transfer. For example, after the bootloader completes hardware initialization, it loads the security initialization program, and then loads the metering control program, communication program, and transaction processing program in sequence. The subsequent startup function segment is started only after the previous startup function segment has completed loading and measurement.
[0029] Based on the entry address, loading order, and prior dependencies of each mirror region, segment boundaries are set at control transfer points or access permission switching points. A segment identifier uniquely identifies a startup functional segment, a preceding segment identifier indicates its dependency on the previous startup functional segment, and a startup stage identifier characterizes its position in the startup process. An SM3 segment digest is calculated for each startup functional segment, and the segment identifier, preceding segment identifier, SM3 segment digest, firmware version number, and startup stage identifier are encoded into metric entries. These entries are then signed with an SM2 private key to form a firmware metric list. This integrates firmware content, version, and loading relationships into a signature-protected system, preventing the mixing of different firmware version segments or out-of-order loading.
[0030] This step divides the firmware into segments based on the location of control transfer and permission switching, and incorporates the segment content, dependencies, version, and stage identifier into the signature protection. This solves the problem that full image verification is difficult to identify in terms of partial replacement, mixed versions, and out-of-order loading, enabling subsequent verification to accurately locate the boot function segment.
[0031] In step S2, the current startup stage is determined based on the loaded segment identifier and startup status record. A startup functional segment whose startup stage identifier matches the current startup stage and whose preceding segment identifier corresponds to the loaded segment identifier is selected as the target firmware segment. A preset SM2 public key is read from the secure storage area to verify the signature on the firmware metric list; the SM3 segment digest of the target firmware segment is recalculated and compared with the digest in the corresponding metric entry. Only target firmware segments with valid signatures and consistent digests are identified as trusted firmware segments, thereby simultaneously verifying the firmware source and content integrity, preventing tampered or unauthorized firmware from being loaded.
[0032] This step uses a combination of verification methods, including list signature verification, segment digest recalculation, and preceding identifier matching, to address the issue that verifying only the image signature is insufficient to confirm the currently loaded segment and its dependencies, thereby preventing tampered, unauthorized, or out-of-order segments from entering the execution area.
[0033] In step S3, the preceding stage metric value is the cumulative metric result formed after the previous startup functional segment completes the trust verification. The first startup functional segment uses a preset initial metric value. The current stage metric value can be expressed as: Replacement of any preceding firmware segment or change in loading order will alter the metrics of subsequent stages, thus disrupting the trusted boot chain. The system reads the security version value recorded by the hardware monotonic counter, identifying firmware versions lower than the security version value as version rollbacks, and identifying trusted firmware segments with firmware versions at or above the security version value and whose preceding boot functional segments have all completed metrics as firmware segments to be loaded. After the firmware image completes booting, the hardware monotonic counter is updated to prevent the reloading of historical firmware with security risks.
[0034] This step addresses the issues of lack of continuous trust transfer in independent segmented verification and the possibility of historical firmware being reloaded by recursively pushing the results of previous measurements to the current stage and constraining the minimum security version with a monotonic counter. This ensures that any changes in previous content or sequence can be detected in subsequent measurements and version determinations.
[0035] In step S4, the device hardware unique key is a root key that corresponds to the identity of a single motherboard hardware and is stored in a secure storage area. Using the device hardware unique key as the root key, a stage baseline key is generated based on the current stage metric and firmware version number. Then, an SM4 decryption key is derived by combining the segment identifier and preceding segment identifier of the firmware segment to be loaded. The SM4 decryption key is used to decrypt the firmware segment to be loaded and write it to the corresponding loading address. After control is transferred, the temporary key is cleared. This binds decryption permissions to the motherboard hardware, firmware version, and actual boot state, reducing the risk of fixed key leakage and firmware copying across devices.
[0036] For signature verification or digest anomalies, record the abnormal segment and startup phase, and verify the signature, digest, predecessor dependencies, and firmware version of another image. If the requirements are met, switch to the trial run image. For version rollback, prohibit loading the corresponding firmware segment and clear the derived key. If both images have anomalies in the same startup phase, clear the relevant keys and lock the debug interface.
[0037] This step addresses the issues of fixed keys being reused across devices, unverified backup images being switched directly, and abnormal interfaces being exposed by binding the decryption key to a single device, firmware version, actual measurement results, and inter-segment dependencies, and performing recovery or locking differently according to the anomaly type.
[0038] Furthermore, Figure 2 This illustrates the process of constructing a startup dependency graph and setting segment boundaries based on the mirror region call relationships. See also... Figure 2 In step S1, dividing the firmware image into several boot function segments according to the motherboard boot dependency includes: Analyze the image header, segment table, and call relationships of the motherboard firmware image to determine the entry address, loading order, and pre-order dependencies of each image region; A startup dependency graph is constructed using each mirror region as a node and the preceding dependency relationship as a directed edge, and the startup stage corresponding to each mirror region is determined based on the startup dependency graph. The firmware image is divided according to the startup stage and loading order, and segment boundaries are set at the control transfer position and access permission switching position to obtain several startup function segments.
[0039] Specifically, first, the image header and segment table of the motherboard firmware image are parsed. The boot entry address, firmware version number, image length, and segment table offset are extracted from the image header. The start address, data length, entry address, load address, and access permissions of each image region are extracted from the segment table, and corresponding image region attribute records are formed according to the address range. Function call instructions, jump instructions, relocation entries, and import symbols in each image region are scanned to extract the corresponding target addresses. The target addresses are matched with the address ranges of each image region. When a target address is located between the start and end addresses of a certain image region, the target address is mapped to the corresponding image region. If a call instruction, jump instruction, or load record points to another image region in one image region, a pre-order dependency is established between them.
[0040] An adjacency matrix is constructed based on the preorder dependencies between each mirror region. The rows and columns of the adjacency matrix correspond to different mirror regions. When there is a call, jump, or loading relationship between two mirror regions, the relationship value at the corresponding position is set to one; otherwise, it is set to zero. This converts the program call relationship in the firmware image into startup dependency data that can be processed.
[0041] Secondly, a startup dependency graph is constructed using each mirror region as a node and the aforementioned preorder dependencies as directed edges, with the mirror region containing the startup entry address serving as the starting node. A depth-first search is used to traverse the startup dependency graph to determine mirror regions that can be reached directly or indirectly from the starting node. For multiple mirror regions with mutual call relationships, a strongly connected component algorithm is used to merge them into the same dependency node, transforming the startup dependency graph into a directed acyclic graph and preventing circular calls from affecting the determination of the startup phase.
[0042] The directed acyclic graph is topologically sorted, and dependent nodes that have no predecessor nodes but contain a startup entry address are identified as the first startup phase. For the remaining dependent nodes, all predecessor nodes pointing to that dependent node are found, and the maximum startup phase among all predecessor nodes is incremented by one to become the startup phase of the current dependent node. If multiple dependent nodes belong to the same startup phase, they are arranged in ascending order of loading address, and the loading order within the same startup phase is adjusted based on the order of arrival of control rights. This yields the startup phase, predecessor dependencies, and loading order corresponding to each mirror region.
[0043] Finally, candidate segment locations are determined based on the startup phase and loading order. Segment boundaries are set at control transfer addresses between adjacent startup phases, call target addresses across mirror regions, and addresses where access permissions change. These access permission changes include switching between read-only and write permissions, switching between non-executable and executable permissions, and switching between secure execution regions and normal execution regions.
[0044] Adjacent mirror regions with the same startup phase, contiguous addresses, consistent access permissions, and identical prior dependencies are merged; mirror regions with cross-phase calls, changes in access permissions, or independent entry addresses are kept separate, resulting in several startup function segments.
[0045] This specific step establishes dependencies by calling, jumping, and loading records, and determines segment boundaries at control transfers and access permission changes. It solves the problem that cutting into fixed-size blocks cannot reflect the true startup semantics and is prone to incorrectly splitting interdependent programs, so that each startup functional segment has a clear stage affiliation and verifiable precedence relationship.
[0046] Further, in step S1, calculating the SM3 segment digest of each boot function segment and generating the firmware metric list signed by SM2 includes: Read segment data according to the address range of each startup function segment, and calculate the corresponding SM3 segment digest using the SM3 algorithm; Encode the segment identifier, preceding segment identifier, SM3 segment summary, firmware version number and boot stage identifier according to the preset field order to generate metric entries corresponding to each boot functional segment. The metric entries are arranged according to the loading order of each startup function segment, and the arranged metric entries are signed with the SM2 private key to generate a firmware metric list.
[0047] Specifically, the firmware release end reads segment data according to the starting address and data length of each boot function segment. To avoid consuming too much memory at once, the data can be read in 4096-byte blocks and sequentially sent to the SM3 processing unit; if the last block is less than 4096 bytes, it is padded according to the SM3 specification, and finally a 32-byte segment digest is output. In this embodiment, the digest object is the data body to be stored in the boot function segment and its authentication tag, excluding the key encapsulation area written subsequently.
[0048] Each read block participates in the digest operation in ascending order of address, with the intermediate operation state formed by the previous read block serving as the input state for the next read block. After the last block is padded and compressed, the 32-byte result output by the SM3 operation unit is determined as the SM3 segment digest of the corresponding startup functional segment. This allows for the overwriting of the entire segment data under limited startup memory conditions and avoids obtaining the same measurement result even after the read block order changes.
[0049] After obtaining the SM3 segment digest, the metric entries are encoded according to a fixed length and big-endian byte order. The segment identifier and pre-segment identifier each occupy two bytes, the SM3 segment digest occupies 32 bytes, the firmware version number occupies four bytes, and the boot stage identifier occupies two bytes. The pre-segment identifier of the first boot functional segment is set to the preset root identifier. Fixed field lengths avoid encoding ambiguities when concatenating different fields.
[0050] The metrics items are arranged from lowest to highest startup phase, and within the same startup phase, they are arranged in loading order and then sequentially assembled to form the main body of the list. During assembly, the metrics items for the first startup functional segment are written first, followed by the metrics items for each subsequent startup functional segment. The list header records the number of items, the length of each item, and the total length of the main body. The verification terminal parses the main body of the list item by item based on the length information; if the number of items or the total length is inconsistent, the list structure is directly determined to be abnormal.
[0051] The SM3 digest is calculated on the list body, and the signature is executed using the SM2 private key stored in the hardware cryptographic device. SM2 uses 256-bit elliptic curve parameters, and the signature result consists of two 32-byte integers. During the signing process, the SM3 operation is first performed on the complete list body, and then the resulting 32-byte list digest and the signer identifier are input into the SM2 signature operation. The hardware cryptographic device generates the signature result using the non-derivative SM2 private key. The signature result is appended to the list body in a fixed 64-byte format.
[0052] Write the main body of the list, the signature result, and the number of metric entries into the firmware metric list. Since the signature covers all metric entries, any change to any summary, version number, preamble identifier, or startup phase identifier will invalidate the signature verification result.
[0053] This specific step uses sequential block digests, fixed field encoding, and SM2 signatures that cover all metric entries to solve the problems of limited startup memory, ambiguity in field splicing, and the lack of overall signature protection for a single digest. This ensures that any changes to any content, version, or dependent fields can be identified during the signature verification stage.
[0054] Further, in step S2, determining the trusted firmware segment includes: Read the current startup stage identifier and the loaded segment identifier, and select the startup function segment whose startup stage identifier is consistent with the current startup stage identifier and whose preceding segment identifier is consistent with the loaded segment identifier from the firmware metric list, as the target firmware segment; Read the preset SM2 public key from the secure storage area, and verify the signature in the firmware metric list using the SM2 public key; Recalculate the SM3 segment digest of the target firmware segment and compare it with the SM3 segment digest in the corresponding metric entry. Target firmware segments with valid signatures and consistent SM3 segment digests are identified as trusted firmware segments.
[0055] Specifically, after the motherboard resets, the current boot stage identifier and the loaded segment identifier are read from the Secure Boot Status Register. The firmware metric list is searched for metric entries with the same boot stage identifier and a preceding segment identifier that matches the loaded segment identifier. If the search result is one, its corresponding boot function segment is identified as the target firmware segment; if the search result is empty or more than one, it is identified as a dependency missing exception or a dependency conflict exception, respectively, and loading of that boot stage is stopped.
[0056] The SM2 public key is read from the on-chip read-only secure storage area. This public key uses 256-bit elliptic curve coordinates to perform SM2 signature verification on the body of the firmware metric manifest and the 64-byte signature result. Public key reading, digest calculation, and signature verification are all completed within a secure execution environment; ordinary business programs only receive the signature verification status and do not access the public key storage address.
[0057] The SM3 digest for the target firmware segment is recalculated according to the same 4096-byte block rule as the firmware release client. A constant-time comparison method is then used to compare the recalculated digest byte-by-byte with the 32-byte digest in the metric entry. The constant-time comparison does not terminate prematurely based on the first inconsistent byte to reduce the risk of leaking the location of digest differences due to comparison time consumption.
[0058] A valid firmware metric manifest signature, a consistent target firmware segment digest, and a matching preamble identifier are all considered as trust conditions. If any trust condition is not met, no stage metric register is written, and execution permissions for the corresponding loaded region of the target firmware segment are not granted. Only when all trust conditions are met is the trusted firmware segment and its metric entry output, providing input for chained metrics and version determination.
[0059] This specific step uses the current stage, the loaded segment, and the securely stored public key to jointly define the verification object, and adopts constant time comparison to verify the segment digest. This solves the problem that existing whole image verification is difficult to locate the current segment and the digest comparison may reveal the difference location. As a result, only firmware segments with reliable source, content and dependency relationship are output to the subsequent measurement stage.
[0060] Furthermore, generating the current stage metric includes: Based on the preceding segment identifier of the trusted firmware segment, the corresponding preceding stage metric value is read from the secure storage area, where the first startup functional segment corresponds to the preset initial metric value; The preceding stage metric value, the SM3 segment digest of the trusted firmware segment, and the startup stage identifier are encoded according to a preset field order to obtain stage metric data. Perform SM3 operation on the stage measurement data to obtain the current stage measurement value, and write the current stage measurement value into the secure storage area as the preceding stage measurement value of the next startup function segment.
[0061] Specifically, both the preceding stage metric and the current stage metric are set to 32 bytes. The initial metric corresponding to the first startup function segment is obtained by performing SM3 operations on the device model identifier, firmware trust domain identifier, and manufacturer-preset random value, and is written to the read-only secure storage area during the motherboard security initialization stage.
[0062] The preceding stage metric value, the SM3 segment digest of the trusted firmware segment, and the startup stage identifier are concatenated in a fixed length according to the following order, and then the SM3 operation is performed. Specifically, the 32-byte preceding stage metric value is placed at the beginning, the 32-byte SM3 segment digest is placed in the middle, and the two-byte startup stage identifier is placed at the end, forming 66 bytes of stage metric data; the 32-byte result obtained by performing the SM3 operation on the stage metric data is determined as the current stage metric value.
[0063] After completing the trust verification of the current startup functional segment, the current stage metric value is written to the security metric register, and the completion flag of the corresponding startup stage is set to one. In the event of digest anomaly, signature verification anomaly, or write verification failure, the metric value of the previous stage remains unchanged, and the completion flag of the current startup stage is set to zero.
[0064] Since the metric value of the next stage contains the metric value of the previous stage, any change in the content, order, or stage identifier of any preceding startup function segment will change all subsequent stage metric values, making it impossible for subsequent stages to derive the correct decryption key, thus forming a continuous and reliable transmission relationship.
[0065] This specific step recursively writes the measurement value from the previous stage into the calculation input of the next stage, solving the problem that independent measurements in each segment cannot reflect previous tampering or changes in loading order, and preventing measurement in an erroneous stage from deriving the correct decryption key for the subsequent stage.
[0066] Furthermore, determining the firmware segment to be loaded includes: Read the security version value recorded by the hardware monotonic counter, and extract the firmware version number corresponding to the trusted firmware segment from the firmware metric list; Firmware version numbers lower than the security version value are identified as version rollbacks, and trusted firmware segments with firmware version numbers not lower than the security version value and whose preceding startup function segments have all been measured are identified as firmware segments to be loaded. After the firmware image completes boot, a firmware version number higher than the security version value is written to a hardware monotonic counter to update the security version value.
[0067] Specifically, the firmware version number uses four single-byte version fields, representing the major version, minor version, revision version, and build version, respectively. Each version field has a value ranging from 0 to 255. These four version fields are converted into a 32-bit unsigned integer for comparison with a hardware monotonic counter on a uniform numerical scale. During the conversion, the major version field is written to the highest eight bits of the 32-bit unsigned integer, the minor version field to the next eight bits, the revision version field to the next eight bits, and the build version field to the lowest eight bits. The four fields are combined in big-endian order to obtain the firmware version value, giving the major version, minor version, revision version, and build version a decreasing comparison priority.
[0068] Read the 32-bit security version value from the hardware monotonic counter and check each of the preceding stage completion flags corresponding to the trusted firmware segment. If the firmware version value is less than the security version value, output a version rollback status; if the firmware version value is not less than the security version value and all preceding stage completion flags are one, determine the corresponding trusted firmware segment as the firmware segment to be loaded.
[0069] The hardware monotonic counter is updated only after all boot function segments have completed measurement, decryption, and loading, and generated a boot completion flag. When the firmware version value is greater than the security version value, it is first written to the candidate version register and read back for verification, then the commit flag is set, and the hardware atomically updates the candidate version value to the monotonic counter. If the motherboard experiences an abnormal power failure during the update process, candidate versions without the commit flag set will not take effect, preventing the security version value from being prematurely increased and causing a valid image to fail to boot.
[0070] This specific step updates the hardware monotonic counter using hierarchical version values and atomic commits, resolving the issues of reloading lower version images and the inconsistency between the safe version value and the valid image caused by update interruptions, thus balancing rollback constraints and recoverability after abnormal power outages.
[0071] Furthermore, the step of decrypting and loading the firmware segment to be loaded by deriving an SM4 decryption key based on the device hardware unique key, the current stage metric value, and the firmware version number includes: Using the device hardware unique key as the root key, the current stage metric value and firmware version number are input into the SM3-based key derivation function to obtain the stage base key; Based on the stage base key, the segment identifier of the firmware segment to be loaded, and the preceding segment identifier, a secondary key derivation is performed to obtain the SM4 decryption key associated with the boot sequence.
[0072] Specifically, the device hardware unique key uses a 256-bit root key and is stored in the non-derivative key area of the security chip. Using the current stage metric, the 32-bit firmware version value, and the first field separation constant as the derivation context, a 256-bit stage base key is generated through an SM3-based key derivation function. During key derivation, the device hardware unique key is used as the key material, and the current stage metric, firmware version value, and the first field separation constant are input sequentially, with the derivation count incremented from the beginning. The outputs of each SM3 iteration are concatenated sequentially, and the first 256 bits are truncated as the stage base key.
[0073] The stage base key, the segment identifier and preceding segment identifier of the firmware segment to be loaded are concatenated with the second field separation constant, and the SM3 operation is performed, truncating the first 128 bits to obtain the SM4 decryption key. Specifically, the stage base key is placed at the beginning of the derived input, the two-byte segment identifier and the two-byte preceding segment identifier are placed in the middle, and the second field separation constant is placed at the end. By fixing the input order, different segment identifiers or different preceding relationships within the same firmware version correspond to different SM4 decryption keys.
[0074] The first field separation constant and the second field separation constant are set to 0x01 and 0x02 respectively, which are used to distinguish between stage key derivation and segment key derivation, and to avoid the same input generating the same key under different uses.
[0075] In one specific implementation, each firmware segment to be loaded is configured with a 128-bit random content key. The content key is used to generate ciphertext of the firmware segment and a 16-byte authentication tag using SM4 authentication encryption. The content key is then encapsulated into a key encapsulation area using the corresponding SM4 decryption key. During startup, the content key is first obtained by decapsulating the ciphertext using the SM4 decryption key, and then the ciphertext of the firmware segment is decrypted using the content key to verify the authentication tag. Authentication uses a 12-byte initialization vector, which is calculated and truncated from the current stage metric, segment identifier, and firmware version value.
[0076] Decrypted data is first written to a non-executable temporary storage area. Once the authentication tag is valid and the decrypted data length matches the measurement entry record, it is copied to the corresponding loading address and execution permissions are granted. If control is transferred or any decryption verification fails, a zero-overwrite is performed on the memory containing the stage base key, SM4 decryption key, and content key. This ensures that firmware decryption is simultaneously constrained by device identity, firmware version, previous measurement results, and boot order.
[0077] This specific step uses a two-level derivation method based on the device root key, stage metric value, version value, segment identifier, and preceding segment identifier. Execution permissions are only granted after authentication is successful, thus resolving the issues of fixed decryption keys being copied across devices, reused across stages, and decrypted plaintext being executed prematurely.
[0078] Furthermore, Figure 3 This illustrates the handling process of the dual-mirror startup state machine for signature verification anomalies, digest anomalies, and version rollbacks, including mirror switching, key clearing, and interface locking. (See also...) Figure 3 In step S4, controlling the dual-mirror startup state machine to perform mirror switching, key clearing, or debug interface locking includes: A startup failure record is generated based on the exception type, exception segment identifier, startup stage identifier, and current image identifier, and the failure status of the corresponding startup stage of the current image is updated. Based on signature verification anomalies or digest anomalies, extract the corresponding startup phase and its preceding startup phase from another image, determine the candidate recovery image based on the signature validity, preceding dependency integrity and firmware version number of the metric entries, and switch the candidate recovery image to the trial operation image. Update the trial image loaded during the abnormal startup phase to the current image; if both images encounter anomalies or version rollbacks during the same startup phase, clear the corresponding phase base key and SM4 decryption key, and lock the debug interface.
[0079] Specifically, the dual-mirror boot state machine is configured with five states: normal, failure pending recovery, trial operation, currently valid, and security lock. Boot failure records include at least the mirror identifier, exception type, exception segment identifier, boot stage identifier, firmware version number, current stage metric, and number of failures, with an SM3 checksum appended to the end of the record. Boot failure records are stored in dual-copy format, with the latest valid copy selected by incrementing the sequence number to prevent incomplete state records due to abnormal power outages.
[0080] If the firmware metric manifest signature verification fails or the target firmware segment digest fails, the current image is updated from its current valid state to a failed recovery state, and a candidate recovery verification is performed on another image. If the other image meets the signature, digest, predecessor dependencies, and version conditions, it is marked as a trial image, but the original current image identifier is retained to prevent the original boot path from being permanently overwritten before the trial is completed.
[0081] After the trial image completes the measurement and loading of the original abnormal startup phase and its subsequent startup phases, it atomically updates the trial image to the current image by first writing the new image identifier and then setting the effective flag. If the trial image encounters a signature verification error or digest error again in the original abnormal startup phase, it is determined that both images are abnormal in the same startup phase, and the state machine is updated to a secure locked state.
[0082] Version rollback status does not trigger trial runs of lower version images; instead, it directly prohibits the loading of the corresponding firmware segment. When both images experience an anomaly at the same stage or version rollback status is established, the stage base key, SM4 decryption key, and temporarily stored plaintext are cleared, a lock value is written to the processor debug control register, and the Joint Test Action Group (JTAG) interface and Serial Wire Debug (SWD) interface are closed. This lock value remains after a normal reset and is only allowed to be released by a signed, verified higher version recovery procedure under controlled maintenance conditions.
[0083] This specific procedure isolates candidate images based on failure records and trial operation status, and selects to restore, disable loading, or lock security according to the type of exception. This solves the problems of the backup image directly replacing the current image without verification, repeated switching of exceptions at the same stage, and the debugging interface still being available when rolling back the version.
[0084] Further, determining the candidate recovery image includes: Starting with the metric entry corresponding to the abnormal startup phase in another mirror, backtrack sequentially to the first startup functional segment according to the preceding segment identifier to obtain the candidate recovery dependency chain; The signature, preceding segment identifier, and startup stage identifier of each metric entry in the candidate recovery dependency chain are verified, and the SM3 segment digest of the corresponding startup function segment is recalculated. Another image with a valid signature, continuous preceding dependencies, consistent SM3 segment digests, firmware version number not lower than the security version value, and no failure records in the corresponding boot phase is identified as a candidate recovery image.
[0085] Specifically, the metric entries corresponding to the abnormal startup phase identifiers are read from another mirror, and an access flag table with a length consistent with the number of metric entries is established. Starting from this metric entry, the preceding segment identifier is read, and the corresponding access flag is set to one for each preceding segment backtracked. If a preceding segment is missing, the same segment is accessed repeatedly, or the number of backtracking exceeds the total number of metric entries, it is determined that the candidate recovery dependency chain is discontinuous, and the backtracking is terminated.
[0086] After tracing back to the preset root identifier, the obtained metric entries are arranged in reverse order to form a candidate recovery dependency chain from the first boot functional segment to the abnormal boot stage. The SM2 signature of the metric list of another image firmware is verified, and the pre-sequence identifier and boot stage identifier of adjacent metric entries are checked one by one; the SM3 segment digest of each boot functional segment is recalculated according to the read block of 4096 bytes each time, and a constant time comparison is performed with the corresponding metric entry.
[0087] The determination of a candidate recovery image is jointly based on the signature validity status, dependency chain continuity status, digest consistency status, version comparison status, and historical failure status. Specifically, a candidate recovery validity status is output when all conditions are met: the firmware metric manifest signature of the other image is valid, the candidate recovery dependency chain is continuous, the recalculated digests of each boot functional segment are consistent with the manifest records, the firmware version value is not lower than the security version value, and the other image has no failure records in the corresponding boot phase. If any condition is not met, a candidate recovery invalid status is output, and image switching is not performed.
[0088] The security version value is read by a hardware monotonic counter, and the historical failure status is determined by the startup failure records in the dual-image startup state machine. Only when all five of the above conditions are met simultaneously will the other image be identified as a candidate recovery image and written into the trial run status, thereby avoiding repeated image switching in cases of incomplete dependency chains, version rollbacks, or existing failure records at the same stage.
[0089] This specific step addresses the error recovery problem caused by selecting a backup image solely based on image readability or startup results through a combination of dependency chain backtracking and five criteria: signature, dependency, digest, version, and historical failures. This ensures that the candidate image has a verifiable and complete startup path before switching.
[0090] Example 2 See Figure 4 The present invention also discloses a segmented measurement secure boot system based on national cryptographic algorithms, comprising: The firmware segment signing module corresponding to step S1 is used to divide the firmware image into several boot function segments according to the motherboard boot dependency relationship, calculate the SM3 segment digest of each boot function segment, and generate a firmware metric list signed by SM2 based on the segment identifier, the preceding segment identifier, the SM3 segment digest, the firmware version number and the boot stage identifier. The trusted firmware determination module corresponding to step S2 is used to determine the target firmware segment according to the current startup stage, perform SM2 signature verification on the firmware metric list, and perform digest consistency verification on the target firmware segment, and determine the target firmware segment with valid signature and consistent digest as a trusted firmware segment. The stage measurement control module corresponding to step S3 is used to generate the current stage measurement value based on the previous stage measurement value, the SM3 segment summary of the trusted firmware segment and the startup stage identifier, and compare the firmware version number with the security version value recorded by the hardware monotonic counter to determine the firmware segment to be loaded. The secure boot execution module corresponding to step S4 is used to derive an SM4 decryption key based on the device hardware unique key, the current stage metric value and firmware version number, decrypt and load the firmware segment to be loaded, and control the dual-image boot state machine to perform one of the following actions based on signature verification failure, digest failure or version rollback: image switching, key clearing and debug interface locking.
[0091] Specifically, the firmware segment signing module is deployed in the trusted construction environment of the motherboard firmware release terminal. The trusted construction environment includes a firmware parsing processor and a hardware cryptographic device that stores the SM2 private key. The firmware parsing processor is used to parse the image header, segment table, and call relationships, construct the boot dependency graph, and generate each boot function segment; the hardware cryptographic device is used to calculate the segment digest, protect the SM2 private key, and output the firmware metric list signature.
[0092] The trusted firmware determination module and the stage measurement control module are deployed in the secure boot environment of the motherboard's main control chip. The secure boot environment includes a national cryptographic algorithm operation unit, a secure storage area, a secure measurement register, and a hardware monotonic counter. The secure storage area stores the SM2 public key, the initial measurement value, and the device's unique hardware key; the secure measurement register stores the current stage measurement value and the completion flags for each boot stage.
[0093] The secure boot execution module is deployed between the motherboard's main control chip and the dual-mirror firmware memory. It includes a key derivation processing circuit, an SM4 decryption processing circuit, a load address control circuit, a dual-mirror status register, and a debug interface control circuit. The dual-mirror firmware memory is configured with a current mirror area and a restore mirror area. Each mirror area stores encrypted firmware segments, a key encapsulation area, and a firmware metric list, respectively.
[0094] During system runtime, the firmware metric list output by the firmware segment signing module is written to the dual-image firmware storage along with the firmware image; the trusted firmware determination module reads the corresponding firmware segment according to the current boot stage and outputs the trusted verification result; the stage metric control module updates the stage metric value based on the trusted verification result and completes version determination; the secure boot execution module receives the firmware segment to be loaded and the current stage metric value, and completes key derivation, decryption loading, and abnormal state handling. The four modules use the trusted output of the previous module as the execution condition for the next module, forming a continuous security chain from firmware release to motherboard boot execution.
[0095] The above embodiments are merely descriptions of preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made by those skilled in the art to the technical solutions of the present invention without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.
Claims
1. A segmented metric security boot method based on a national secret algorithm, characterized in that, Includes the following steps: The firmware image is divided into several boot function segments according to the motherboard boot dependency relationship. The SM3 segment digest of each boot function segment is calculated, and a firmware metric list signed by SM2 is generated based on the segment identifier, the preceding segment identifier, the SM3 segment digest, the firmware version number and the boot stage identifier. The target firmware segment is determined based on the current startup phase. The firmware metric list is verified with SM2 signature, and the target firmware segment is verified for digest consistency. The target firmware segment with valid signature and consistent digest is determined as a trusted firmware segment. The current stage metric is generated based on the previous stage metric, the SM3 segment digest of the trusted firmware segment, and the startup stage identifier. The firmware version number is then compared with the security version value recorded by the hardware monotonic counter to determine the firmware segment to be loaded. The SM4 decryption key is derived based on the device hardware unique key, the current stage metric value, and the firmware version number. The firmware segment to be loaded is decrypted and loaded. Based on the signature verification error, digest error, or version rollback, the dual-mirror startup state machine is controlled to perform one of the following actions: mirror switching, key clearing, and debug interface locking.
2. The segmented measurement secure startup method based on national cryptographic algorithms according to claim 1, characterized in that, The process of dividing the firmware image into several boot function segments according to the motherboard boot dependency includes: Analyze the image header, segment table, and call relationships of the motherboard firmware image to determine the entry address, loading order, and pre-order dependencies of each image region; A startup dependency graph is constructed using each mirror region as a node and the preceding dependency relationship as a directed edge, and the startup stage corresponding to each mirror region is determined based on the startup dependency graph. The firmware image is divided according to the startup stage and loading order, and segment boundaries are set at the control transfer position and access permission switching position to obtain several startup function segments.
3. The segmented measurement secure boot method based on national cryptographic algorithms according to claim 2, characterized in that, The calculation of the SM3 segment digest for each boot function segment and the generation of the SM2-signed firmware metric list include: Read segment data according to the address range of each startup function segment, and calculate the corresponding SM3 segment digest using the SM3 algorithm; Encode the segment identifier, preceding segment identifier, SM3 segment summary, firmware version number and boot stage identifier according to the preset field order to generate metric entries corresponding to each boot functional segment. The metric entries are arranged according to the loading order of each startup function segment, and the arranged metric entries are signed with the SM2 private key to generate a firmware metric list.
4. The segmented measurement secure boot method based on national cryptographic algorithms according to claim 1, characterized in that, The determined trusted firmware segment includes: Read the current startup stage identifier and the loaded segment identifier, and select the startup function segment whose startup stage identifier is consistent with the current startup stage identifier and whose preceding segment identifier is consistent with the loaded segment identifier from the firmware metric list, as the target firmware segment; Read the preset SM2 public key from the secure storage area, and verify the signature in the firmware metric list using the SM2 public key; Recalculate the SM3 segment digest of the target firmware segment and compare it with the SM3 segment digest in the corresponding metric entry. Target firmware segments with valid signatures and consistent SM3 segment digests are identified as trusted firmware segments.
5. The segmented measurement secure boot method based on national cryptographic algorithms according to claim 1, characterized in that, The generation of the current stage metric includes: Based on the preceding segment identifier of the trusted firmware segment, the corresponding preceding stage metric value is read from the secure storage area, where the first startup functional segment corresponds to the preset initial metric value; The preceding stage metric value, the SM3 segment digest of the trusted firmware segment, and the startup stage identifier are encoded according to a preset field order to obtain stage metric data. Perform SM3 operation on the stage measurement data to obtain the current stage measurement value, and write the current stage measurement value into the secure storage area as the preceding stage measurement value of the next startup function segment.
6. The segmented measurement secure boot method based on national cryptographic algorithms according to claim 1, characterized in that, The determination of the firmware segment to be loaded includes: Read the security version value recorded by the hardware monotonic counter, and extract the firmware version number corresponding to the trusted firmware segment from the firmware metric list; Firmware version numbers lower than the security version value are identified as version rollbacks, and trusted firmware segments with firmware version numbers not lower than the security version value and whose preceding startup function segments have all been measured are identified as firmware segments to be loaded. After the firmware image completes boot, a firmware version number higher than the security version value is written to a hardware monotonic counter to update the security version value.
7. The segmented measurement secure boot method based on national cryptographic algorithms according to claim 1, characterized in that, The step of decrypting and loading the firmware segment to be loaded by deriving the SM4 decryption key based on the device's unique hardware key, the current stage metric value, and the firmware version number includes: Using the device hardware unique key as the root key, the current stage metric value and firmware version number are input into the SM3-based key derivation function to obtain the stage base key; Based on the stage base key, the segment identifier of the firmware segment to be loaded, and the preceding segment identifier, a secondary key derivation is performed to obtain the SM4 decryption key associated with the boot sequence.
8. The segmented measurement secure boot method based on national cryptographic algorithms according to claim 7, characterized in that, The control of the dual-mirror startup state machine to perform mirror switching, key clearing, or debug interface locking includes: A startup failure record is generated based on the exception type, exception segment identifier, startup stage identifier, and current image identifier, and the failure status of the corresponding startup stage of the current image is updated. Based on signature verification anomalies or digest anomalies, extract the corresponding startup phase and its preceding startup phase from another image, determine the candidate recovery image based on the signature validity, preceding dependency integrity and firmware version number of the metric entries, and switch the candidate recovery image to the trial operation image. Update the trial image loaded during the abnormal startup phase to the current image; if both images encounter anomalies or version rollbacks during the same startup phase, clear the corresponding phase base key and SM4 decryption key, and lock the debug interface.
9. A segmented measurement-based secure boot method based on national cryptographic algorithms according to claim 8, characterized in that, The determination of candidate recovery images includes: Starting with the metric entry corresponding to the abnormal startup phase in another mirror, backtrack sequentially to the first startup functional segment according to the preceding segment identifier to obtain the candidate recovery dependency chain; The signature, preceding segment identifier, and startup stage identifier of each metric entry in the candidate recovery dependency chain are verified, and the SM3 segment digest of the corresponding startup function segment is recalculated. Another image with a valid signature, continuous preceding dependencies, consistent SM3 segment digests, firmware version number not lower than the security version value, and no failure records in the corresponding boot phase is identified as a candidate recovery image.
10. A segmented measurement-based secure boot system based on national cryptographic algorithms, characterized in that, include: The firmware segment signing module is used to divide the firmware image into several boot function segments according to the motherboard boot dependency relationship, calculate the SM3 segment digest of each boot function segment, and generate a firmware metric list signed by SM2 based on the segment identifier, the preceding segment identifier, the SM3 segment digest, the firmware version number and the boot stage identifier. The trusted firmware determination module is used to determine the target firmware segment based on the current startup phase, perform SM2 signature verification on the firmware metric list, and perform digest consistency verification on the target firmware segment, and determine the target firmware segment with valid signature and consistent digest as a trusted firmware segment. The stage measurement control module is used to generate the current stage measurement value based on the previous stage measurement value, the SM3 segment digest of the trusted firmware segment and the startup stage identifier, and compare the firmware version number with the security version value recorded by the hardware monotonic counter to determine the firmware segment to be loaded. The secure boot execution module is used to derive an SM4 decryption key based on the device hardware unique key, the current stage metric value, and the firmware version number, to decrypt and load the firmware segment to be loaded, and to control the dual-image boot state machine to perform one of the following actions based on signature verification failure, digest failure, or version rollback: image switching, key clearing, and debug interface locking.
