Security chip firmware import method, security chip, and computer-readable storage medium

CN115688120BActive Publication Date: 2026-08-11HANGZHOU FEISHU TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-01
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0005]本发明要解决的技术问题在于,针对现有固件烧录方式无法满足安全芯片对固件可靠性要求的问题,提供一种安全芯片固件导入方法、安全芯片及计算机可读存储介质

Benefits of technology

[0016]本发明具有以下有益效果:通过对将安全芯片的固件分为引导启动程序、算法库及功能程序,并在对只读存储器中的引导启动程序及算法库的完整性验证成功后再将功能程序写入到嵌入式闪存,可在提高安全芯片使用的灵活性的同时,保证安全芯片固件导入的完整性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115688120B_ABST
    Figure CN115688120B_ABST
Patent Text Reader

Abstract

This invention provides a method for importing firmware into a security chip, a security chip, and a computer-readable storage medium. The method includes: after a bootloader and algorithm library are burned into the read-only memory and powered on again, performing a first hash operation on the data in the read-only memory to obtain a first digest; obtaining a second digest from a programmable memory, wherein the second digest is generated by a host computer performing the first hash operation on the bootloader and algorithm library, and the second digest is written to the programmable memory before or during the burning of the bootloader and algorithm library into the read-only memory; and receiving the functional program of the firmware from the host computer in response to the first digest and the second digest being consistent, and writing the functional program into the embedded flash memory. This invention can improve the flexibility of using security chips while ensuring the integrity of security chip firmware import.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of device security, and more specifically, to a method for importing firmware into a security chip, a security chip, and a computer-readable storage medium. Background Technology

[0002] Modern computers and electronic devices typically include one or more microcontrollers, which can be considered the "brain" of these devices. Firmware is an electronic instruction set stored inside the microcontroller. By executing this set of instructions, the microcontroller can generate pre-defined control signals to control the device's operation. For example, the microcontroller in a digital watch uses firmware to track time and handle user-defined alarms and ringtones; the microcontroller in a mobile phone uses firmware to provide the user interface, mobile phone transmission / reception protocols, audio processing, and so on.

[0003] Since firmware directly defines the device's operating logic, any firmware error will pose a significant threat to the device's operation. To prevent firmware errors during the flashing process, existing solutions involve performing a CRC check on the firmware upon receipt and comparing the calculated check result with the received CRC check result. If the comparison fails, the firmware will be rejected.

[0004] While the above methods can address issues like data loss or corruption during firmware transmission to some extent, they cannot prevent malicious modification or replacement of the firmware. For example, if a third party maliciously modifies both the firmware and the CRC checksum, the device may be unable to detect that the newly input firmware has been maliciously tampered with. For security chips with high security levels, the above solutions clearly cannot meet their firmware reliability requirements. Summary of the Invention

[0005] The technical problem to be solved by the present invention is to provide a method for importing firmware into a security chip, a security chip, and a computer-readable storage medium, addressing the issue that existing firmware burning methods cannot meet the firmware reliability requirements of security chips.

[0006] The technical solution of this invention to solve the above-mentioned technical problems is to provide a method for importing firmware into a security chip, wherein the security chip includes a read-only memory, a programmable memory, and an embedded flash memory, and the firmware includes a boot program, an algorithm library, and a function program; the method includes: After the bootloader and algorithm library are fixed to the read-only memory and the power is turned on again, a first hash operation is performed on the data in the read-only memory to obtain a first digest; A second digest is obtained from the programmable memory. The second digest is generated by the host computer performing a first hash operation on the boot program and the algorithm library. The second digest is written to the programmable memory before or when the boot program and the algorithm library are fixed to the read-only memory. In response to the first digest and the second digest being consistent, the function program of the firmware is received from the host computer and written into the embedded flash memory.

[0007] As a further improvement of the present invention, the program header of the boot program has a preset key; The step of receiving the firmware function program from the host computer and writing the function program into the embedded flash memory includes: The encrypted data is received from the host computer, and the encrypted data is generated by the host computer using a preset key to execute the first encryption algorithm in the function program. After obtaining a preset key from the program header of the boot program in the read-only memory, and decrypting the encrypted data using the preset key to obtain the functional program, the functional program is written to the data storage area of ​​the embedded flash memory, and the boot address and program header of the functional program are written to the info area of ​​the embedded flash memory. As a further improvement of the present invention, before writing the startup address of the functional program and the program header of the functional program into the info area of ​​the embedded flash memory, the method includes: performing integrity verification on the functional program in the embedded flash memory.

[0008] As a further improvement of the present invention, the first preset position of the program header of the functional program has a third digest, which is obtained by the host computer performing a second hash operation on the part of the program header of the functional program other than the first preset position; The integrity verification of the functional programs in the embedded flash memory includes: The program header of the functional program is read from the embedded flash memory, and a second hash operation is performed on the part of the program header of the functional program other than the first preset position to obtain a fourth digest; The fourth digest is compared with the third digest at the first preset position of the program header of the functional program, and a firmware import error message is output when the fourth digest and the third digest are inconsistent.

[0009] As a further improvement of the present invention, the second preset position of the program header of the functional program has a fifth digest, which is obtained by the host computer performing a third hash operation on the main body of the functional program; The integrity verification of the functional programs in the embedded flash memory includes: The main body of the functional program is read from the embedded flash memory, and a third hash operation is performed on the main body of the functional program to obtain a sixth digest; The sixth digest is compared with the fifth digest at the second preset position of the program header of the functional program, and a firmware error message is output when the sixth digest and the fifth digest are inconsistent.

[0010] As a further improvement of the present invention, the third preset position of the program header of the functional program has a preset identifier, a preset public key and a first calculated value. The first calculated value is obtained by the host computer using a preset private key to perform a preset operation on the preset identifier and the length of the functional program. The preset public key corresponds to the preset private key. After the integrity verification of the functional program in the embedded flash memory is passed, the following steps are also included: Read the preset identifier, preset public key and first calculated value from the third preset position of the program header of the functional program, and obtain the length of the functional program written to the embedded flash memory; The preset public key is used to perform a preset operation on the preset identifier and the length of the functional program written to the embedded flash memory to obtain a second calculated value; When the second calculated value matches the first calculated value, the startup address of the functional program and the program header of the functional program are written into the info area of ​​the embedded flash memory.

[0011] As a further improvement of the present invention, after the integrity verification of the boot program and algorithm library is passed, the function program is confirmed to be imported completely by reading the info area of ​​the embedded flash memory, and the function program is received from the host computer if the function program is not imported completely.

[0012] As a further improvement of the present invention, when the functional program is written to the data storage area of ​​the embedded flash memory, access protection operations are performed sequentially on each memory page that has been written. As a further improvement of the present invention, the method further includes: when the functional program is written to the data storage area of ​​the embedded flash memory, canceling the access protection of the storage page storing the functional program, and performing write protection operation on all storage pages storing the functional program.

[0013] As a further improvement of the present invention, after writing the startup address and program header of the functional program into the info area of ​​the embedded flash memory, the method further includes: Preset data is written into the sensitive data area of ​​the embedded flash memory to close the test port of the security chip.

[0014] The present invention also provides a security chip, including a main controller, a read-only memory, a programmable memory, an embedded flash memory, and a hardware encryption unit. The read-only memory stores a firmware boot program and an algorithm library. When the main controller executes the firmware boot program, it implements the steps of the security chip firmware import method described above.

[0015] The present invention also provides a readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the security chip firmware import method described above.

[0016] The present invention has the following beneficial effects: by dividing the firmware of the security chip into a boot program, an algorithm library and a function program, and writing the function program into the embedded flash memory only after successfully verifying the integrity of the boot program and algorithm library in the read-only memory, the flexibility of the security chip can be improved while ensuring the integrity of the security chip firmware import. Attached Figure Description

[0017] Figure 1 This is a schematic diagram of the connection between the security chip and the host computer in the security chip firmware import method provided in this embodiment of the invention; Figure 2 This is a flowchart illustrating the security chip firmware import method provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the process for verifying the integrity of the bootloader and algorithm library in the security chip firmware import method provided in this embodiment of the invention; Figure 4 This is a flowchart illustrating the process of verifying the integrity of the program header of a functional program in the security chip firmware import method provided in this embodiment of the invention. Figure 5 This is a flowchart illustrating the integrity verification of the main body of the functional program in the security chip firmware import method provided in this embodiment of the invention. Figure 6 This is a flowchart illustrating the validity verification of functional programs in the security chip firmware import method provided in this embodiment of the invention. Detailed Implementation

[0018] 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 accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0019] like Figure 2The diagram shown is a flowchart illustrating the firmware import method for a security chip provided in an embodiment of the present invention. This method can be applied to firmware import for a Trusted Platform Module (TPM) and can meet the high security requirements of security chips. Combined with... Figure 1 As shown, the security chip 20 includes a read-only memory 22, an embedded flash memory (eFlash) 23, and a programmable memory (Efuse) 26. Furthermore, the security chip 20 may also include a main controller 21, a hardware encryption unit 24, and static random access memory (SRAM). These components can be integrated into a single unit and are interconnected via internal circuitry. A connection interface 25 for connecting to external devices is provided, such as an SPI interface, a USB interface, or a JTAG interface. The hardware encryption unit 24 can specifically employ a hardware encryption chip or a hardware encryption circuit, and it incorporates multiple encryption algorithms, such as SM2, SM3, and SM4. This hardware encryption unit enables encryption and decryption of input data. The hardware structure of the aforementioned security chip can be directly adopted from existing solutions, and will not be described in detail here.

[0020] In this embodiment, the firmware running on the security chip includes a bootloader, an algorithm library (for defining general algorithms), and function programs (for defining specific algorithms). The bootloader and algorithm library are burned into the security chip's read-only memory 22 using a dedicated programming device before the security chip leaves the factory (for example, the bootloader and algorithm library exist in the read-only memory 22 in the form of a gate-level netlist). Because the read-only memory 22 is read-only and cannot be written to, and does not disappear after power-off, the bootloader and algorithm library can be successfully loaded each time the chip is powered on.

[0021] The method of this embodiment can be executed by the main controller 21 of the security chip 20 after the security chip leaves the factory (i.e., after the boot program and algorithm library are fixed to the read-only memory 22 of the security chip). When executing this method, the security chip needs to be connected to the host computer 10 through the connection interface 25 (SPI interface or USB interface) (or connected to the host computer 10 through a dedicated network device). Specifically, the method includes: Step S31: After the bootloader and algorithm library are fixed to the read-only memory and the power is turned on again, a first hash operation (e.g., SM3 operation) is performed on the data in the read-only memory to obtain a first digest. This first hash operation may be performed by a hardware encryption unit.

[0022] Step S32: Obtain a second digest from the programmable memory. The second digest is generated by the host computer performing a first hash operation on the bootloader and algorithm library. The second digest is written to the programmable memory before the bootloader and algorithm library are fixed to the read-only memory, or the second digest is written to the programmable memory when the bootloader and algorithm library are fixed to the read-only memory.

[0023] Step S33: Determine whether the first summary and the second summary are consistent. If the first summary and the second summary are consistent, proceed to step S34; otherwise, proceed to step S35.

[0024] Step S34: An error is detected, and subsequent firmware import is terminated. The inconsistency between the first and second digests indicates that the bootloader and algorithm library in the security chip 20 are incomplete or have been tampered with. In this case, the main controller 21 of the security chip will return an error value and enter the error handling mechanism. Within this mechanism, a waiting loop occurs, causing the program to stop executing and preventing the security chip 20 from booting normally.

[0025] Step S35: Receive the function program of the firmware from the host computer 10 and write the function program into the embedded flash memory 23.

[0026] The aforementioned functional program can be generated by the host computer 10 or obtained by the host computer 10 from other devices (such as remote servers) and stored in the memory 12. The processor 11 of the host computer 10 transmits the functional program to the connection interface 25 of the security chip 20 through the data transmission interface circuit 13.

[0027] The purpose of performing integrity verification on the bootloader and algorithm library in the read-only memory 22 is to ensure that there are no errors in the bootloader and algorithm library in the read-only memory 22. The aforementioned method for importing security chip firmware divides the security chip firmware into a bootloader, an algorithm library, and functional programs. It also writes a second digest, used for verifying the integrity of data in the read-only memory, into a programmable memory. After successfully verifying the bootloader and algorithm library in the read-only memory, the functional programs are then written into the embedded flash memory. This method improves the flexibility of using the security chip (i.e., users can customize functional programs and write them into the embedded flash memory to increase the functionality of the security chip) while preventing maliciously modified bootloaders from being embedded into the security chip, thereby greatly enhancing the security of importing security chip firmware.

[0028] Specifically, in step S35 above, when writing the functional program to the data storage area of ​​the embedded flash memory 23, access protection operations are performed on each completed storage page (typically 8K). In this way, during the process of writing the functional program to the embedded flash memory 23, access protection is applied to the storage space of each page (8K) written, thereby ensuring that the functional program is not illegally accessed or read during the writing process to the embedded flash memory 23, thus improving security.

[0029] Furthermore, after the functional program is fully imported into the embedded flash memory 23, the access protection of the address space of the embedded flash memory 23 where the functional program resides is removed. Instead, write protection is applied to the address space of the embedded flash memory 23. That is, when the functional program is successfully imported into the embedded flash memory 23 for the first time, the main controller 21 executes the bootloader to enable the write protection mechanism of the functional firmware. At this time, the address space where the functional program is located can no longer be written to. Therefore, during the entire process from the successful import of the functional program until the bootloader itself enters the functional program, neither external programs nor the bootloader itself can import the functional program again. Since there is no erasure or write operation on its own address space in the functional program, this write protection mechanism will not affect the normal use of the functional program. Moreover, in subsequent use, external programs cannot modify the address space in the embedded flash memory 23 where the functional program is stored, ensuring the stability of the functional program.

[0030] Combination Figure 3 In one embodiment of the present invention, the bootloader's program header (i.e., the bootloader's header) has a preset key (the position of the preset key in the bootloader's program header can be set as needed), and the functional program is transmitted to the security chip after being encrypted by the host computer 10 using the preset key (e.g., using the SM4 encryption algorithm). Accordingly, receiving the firmware's functional program from the host computer and writing the functional program into the embedded flash memory in step S35 includes: Step S351: Receive encrypted data from the host computer 10. This encrypted data is generated by the host computer using a preset key to encrypt the function program using the first encryption algorithm. That is, the function program is transmitted in encrypted form between the host computer 10 and the security chip 20.

[0031] Step S352: Obtain a preset key from the program header of the boot program in the read-only memory 22, and use the preset key to decrypt the encrypted data to obtain the functional program. The decryption of the encrypted data using the preset key can be performed by the hardware encryption unit.

[0032] Step S353: Write the function program to the data storage area of ​​the embedded flash memory (e.g., store it in the embedded flash memory 23 as a BIN file), and write the startup address of the function program and the program header of the function program to the info area of ​​the embedded flash memory (the info area is equivalent to the directory area of ​​the embedded flash memory 23), thereby completing the firmware import of the security chip.

[0033] By using the above method, the functional program can be prevented from being intercepted by others during the process of being imported from the host computer 10 to the security chip 20, thereby improving security.

[0034] Specifically, in one embodiment of the present invention, after the integrity verification of the bootloader and algorithm library is passed, the main controller 21 of the security chip 20 can confirm whether the function program has been imported successfully by reading the info area of ​​the embedded flash memory 23. If the function program has not been imported successfully, it receives the function program from the host computer and enters a waiting state. That is, each time the security chip is powered on and reset, the main controller 21 executes the bootloader and determines whether the corresponding address space contains the function program header by checking whether the info area of ​​the embedded flash memory 23 contains the function program. If the function program exists, it directly jumps to the firmware startup without entering the SPI waiting stage for firmware import. This process also avoids the situation of repeated import of the function program.

[0035] In one embodiment of the present invention, Figure 3 In step S313, after the function program is written to the data storage area of ​​the embedded flash memory 23 and before the start address and program header of the function program are written to the info area of ​​the embedded flash memory 23, an integrity verification step can be performed on the function program written to the embedded flash memory 23 to ensure that the function program written to the embedded flash memory 23 is accurate and complete.

[0036] As a further improvement of the present invention, the first preset position of the program header (i.e., the header of the function program) has a third digest, which is obtained by the host computer 10 performing a hash operation (e.g., by executing the SM3 algorithm) on the part of the program header of the function program other than the first preset position.

[0037] Accordingly, combined Figure 4 As shown, the integrity verification of the functional program in the embedded flash memory 23 includes: Step S3611: Read the program header of the function program from the embedded flash memory 23, and perform a hash operation on the part of the program header of the function program other than the first preset position through the hardware encryption unit to obtain the fourth digest.

[0038] Step S3612: Obtain the third digest from the first preset location of the program header of the function program in the read-only memory 22.

[0039] Step S3613: Determine whether the fourth digest obtained in step S3611 is the same as the third digest obtained in step S3612. If the fourth digest is the same as the third digest, proceed to step S3614; otherwise, proceed to step S3615.

[0040] Step S3614: Confirm that the program header of the function program is complete, and the main controller 21 of the security chip executes the subsequent steps.

[0041] Step S3615: Confirm that the program header of the function program is incomplete. The main controller of the security chip outputs firmware import error information, such as boot address error information, to facilitate error location, and returns to step S351 to repeat the function program import process.

[0042] By performing integrity verification on the program header of the function program in the embedded flash memory 23, errors that occur in the function program when it is transmitted from the host computer to the security chip can be quickly detected, thereby avoiding subsequent complex operations that take a long time.

[0043] Combination Figure 5 As shown, in one embodiment of the present invention, a fifth digest is present at a second preset position in the program header (i.e., the header of the function program). This fifth digest is obtained by the host computer 10 performing a hash operation (e.g., by executing the SM3 algorithm) on the main body of the function program (i.e., the part excluding the program header). Accordingly, integrity verification of the function program in the embedded flash memory 23 includes: Step S3621: Read the main body of the function program from the embedded flash memory 23, and perform a hash operation on the main body of the function program through the hardware encryption unit to obtain the sixth digest.

[0044] Step S3622: Obtain the fifth digest from the second preset location of the program header of the function program in the read-only memory 22.

[0045] Step S3623: Determine whether the sixth digest obtained in step S3621 is the same as the fifth digest obtained in step S3622. If the sixth digest is the same as the fifth digest, proceed to step S3624; otherwise, proceed to step S3625.

[0046] Step S3624: Confirm that the main part of the functional program is complete, and the main controller 21 of the security chip executes the subsequent steps.

[0047] Step S3625: Confirm that the main part of the function program is incomplete. The main controller of the security chip outputs firmware import error information, such as boot address error information, to facilitate error location, and returns to step S351 to repeat the function program import process.

[0048] By performing integrity verification on the main body of the functional program in the embedded flash memory 23, errors that may occur during the transfer of the main body of the functional program from the host computer to the security chip can be prevented. In practical applications, the integrity verification of the program header and the main body of the functional program can also be performed sequentially to avoid errors during the import of the functional program.

[0049] After the integrity verification of the functional program written to the embedded flash memory 23 is passed, the validity verification of the functional program written to the embedded flash memory 23 may also be included. At this time, the third preset position of the program header of the boot program in the read-only memory 22 has a preset identifier, a public key, and a first calculated value. The first calculated value is obtained by the host computer using a private key (corresponding to the aforementioned public key) to perform a preset operation (e.g., SM4 encryption operation) on the preset identifier and the length of the functional program. Accordingly, combined with Figure 6 As shown, the validity of the functional program written to the embedded flash memory 23 is verified, including: Step S3631: Read the preset identifier (e.g., user ID), public key, and first calculated value from the third preset location of the program header of the boot program in the read-only memory 22.

[0050] Step S3632: Obtain the length of the function program written to the embedded flash memory 23 (e.g., the number of bytes occupied by the function program in the embedded flash memory 23).

[0051] Step S3633: Control the hardware encryption unit 24 to perform a preset operation (e.g., SM4 encryption operation) on the preset identifier and the length of the function program written to the embedded flash memory using the public key to obtain a second calculated value. The above preset operation can be specifically executed by the hardware encryption unit.

[0052] Step S3634: Determine whether the second calculated value obtained in step S3633 is consistent with the first calculated value obtained in step S3631. If the second calculated value is consistent with the first calculated value, execute step S3636; otherwise, execute step S3635.

[0053] Step S3635: The main controller of the security chip outputs firmware import error information, such as boot address error information, to facilitate error location, and returns to step S3351 to repeat the function program import process.

[0054] Step S3636: Write the startup address and program header of the function program into the info area of ​​the embedded flash memory, and indicate that the function program burning is complete.

[0055] The above methods ensure the validity of the functional program's source. Because the functional program has a unique header verification mechanism, and this header contains the third digest required for firmware body data verification, the first calculated value required for validating the functional program, the public key, etc., to successfully import the functional program, the corresponding header must first be obtained. The header packaging tool can be kept strictly confidential by the user, and the entire functional program import process is encrypted (i.e., the imported functional program is encrypted). Without the corresponding header, the functional program cannot be decrypted, making it difficult to obtain valid information by stealing the functional program during SPI transmission, greatly increasing the difficulty of cracking the security chip.

[0056] Specifically, after writing the startup address and program header of the function program into the info area of ​​the embedded flash memory 23, preset data can be written into the sensitive data area of ​​the embedded flash memory 23 to close the test port of the security chip. This makes the function program storage area inaccessible and ineradicable even to the main controller 21, and can only be accessed and read by the internal hardware logic circuit. After the security chip 20 is powered on and reset, the test interface is closed by hardware.

[0057] The present invention also provides a security chip, including a main controller, a read-only memory, a programmable memory, an embedded flash memory, and a hardware encryption unit. The read-only memory stores a firmware boot program and an algorithm library. When the main controller executes the firmware boot program, it implements the steps of the security chip firmware import method described above.

[0058] The security chip in this embodiment is the same as the one described above. Figure 1-6 The security chip firmware import methods in the corresponding embodiments belong to the same concept. The specific implementation process can be found in the corresponding method embodiments. The technical features in the method embodiments are all applicable to this device embodiment, and will not be repeated here.

[0059] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the security chip firmware import method described above.

[0060] The computer-readable storage medium in this embodiment is the same as described above. Figure 1-6 The security chip firmware import methods in the corresponding embodiments belong to the same concept. The specific implementation process can be found in the corresponding method embodiments. The technical features in the method embodiments are all applicable to this device embodiment, and will not be repeated here.

[0061] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0062] Those skilled in the art will understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the functions can be assigned to different functional units and modules as needed. The functional units and modules in the embodiments can be integrated into a single processor, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units can be implemented in hardware or as software functional units. Furthermore, the specific names of the functional units and modules are merely for easy differentiation and are not intended to limit the scope of protection of this application. The specific working processes of the units and modules in the above system can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0063] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0064] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0065] In the embodiments provided in this application, it should be understood that the disclosed security chip firmware import method and security chip can be implemented in other ways. For example, the solid-state chip embodiments described above are merely illustrative. Furthermore, the functional units in the various embodiments of this application can be integrated into a single processor, or each unit can exist physically separately, or two or more units can be integrated into a single unit. The integrated units described above can be implemented in hardware or as software functional units.

[0066] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or interface switching device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.

[0067] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for importing firmware into a security chip, characterized in that, The security chip includes a read-only memory, a programmable memory, and an embedded flash memory, and the firmware includes a bootloader, an algorithm library, and functional programs; the method includes: After the bootloader and algorithm library are fixed to the read-only memory and the power is turned on again, a first hash operation is performed on the data in the read-only memory to obtain a first digest; A second digest is obtained from the programmable memory. The second digest is generated by the host computer performing a first hash operation on the boot program and the algorithm library. The second digest is written to the programmable memory before or when the boot program and the algorithm library are fixed to the read-only memory. In response to the first digest and the second digest being identical, the function program of the firmware is received from the host computer and written into the embedded flash memory; The bootloader's header contains a preset key; The step of receiving the firmware function program from the host computer and writing the function program into the embedded flash memory includes: The encrypted data is received from the host computer, and the encrypted data is generated by the host computer using a preset key to execute the first encryption algorithm in the function program. After obtaining a preset key from the program header of the boot program in the read-only memory, and decrypting the encrypted data using the preset key to obtain the functional program, the functional program is written to the data storage area of ​​the embedded flash memory, and the boot address and program header of the functional program are written to the info area of ​​the embedded flash memory.

2. The security chip firmware import method according to claim 1, characterized in that, Before writing the startup address and program header of the functional program into the info area of ​​the embedded flash memory, the process includes: performing integrity verification on the functional program in the embedded flash memory.

3. The security chip firmware import method according to claim 2, characterized in that, The first preset position of the program header of the functional program has a third digest, which is obtained by the host computer performing a second hash operation on the part of the program header of the functional program other than the first preset position. The integrity verification of the functional programs in the embedded flash memory includes: The program header of the functional program is read from the embedded flash memory, and a second hash operation is performed on the part of the program header of the functional program other than the first preset position to obtain a fourth digest; The fourth digest is compared with the third digest at the first preset position of the program header of the functional program, and a firmware import error message is output when the fourth digest and the third digest are inconsistent.

4. The security chip firmware import method according to claim 2, characterized in that, The second preset position of the program header of the functional program has a fifth digest, which is obtained by the host computer performing a third hash operation on the main body of the functional program; The integrity verification of the functional programs in the embedded flash memory includes: The main body of the functional program is read from the embedded flash memory, and a third hash operation is performed on the main body of the functional program to obtain a sixth digest; The sixth digest is compared with the fifth digest at the second preset position of the program header of the functional program, and a firmware error message is output when the sixth digest and the fifth digest are inconsistent.

5. The security chip firmware import method according to claim 2, characterized in that, The third preset position of the program header of the functional program has a preset identifier, a preset public key and a first calculated value. The first calculated value is obtained by the host computer using a preset private key to perform a preset operation on the preset identifier and the length of the functional program. The preset public key corresponds to the preset private key. After the integrity verification of the functional program in the embedded flash memory is passed, the following steps are also included: Read the preset identifier, preset public key and first calculated value from the third preset position of the program header of the functional program, and obtain the length of the functional program written to the embedded flash memory; The preset public key is used to perform a preset operation on the preset identifier and the length of the functional program written to the embedded flash memory to obtain a second calculated value; When the second calculated value matches the first calculated value, the startup address of the functional program and the program header of the functional program are written into the info area of ​​the embedded flash memory.

6. The method for importing firmware into a security chip according to claim 1, characterized in that, After the integrity verification of the boot program and algorithm library is passed, the function program is confirmed to have been imported successfully by reading the info area of ​​the embedded flash memory, and the function program is received from the host computer if the function program has not been imported successfully.

7. The security chip firmware import method according to claim 1, characterized in that, When writing the functional program to the data storage area of ​​the embedded flash memory, access protection operations are performed sequentially on each completed storage page.

8. The security chip firmware import method according to claim 7, characterized in that, The method further includes: when the function program is written to the data storage area of ​​the embedded flash memory, removing the access protection of the storage page storing the function program, and performing write protection operation on all storage pages storing the function program.

9. The method for importing firmware into a security chip according to claim 1, characterized in that, After writing the startup address and program header of the functional program into the info area of ​​the embedded flash memory, the method further includes: Preset data is written into the sensitive data area of ​​the embedded flash memory to close the test port of the security chip.

10. A security chip, comprising a main controller, a read-only memory, a programmable memory, an embedded flash memory, and a hardware encryption unit, characterized in that, The read-only memory stores the firmware boot program and algorithm library. When the main controller executes the firmware boot program, it implements the steps of the security chip firmware import method according to any one of claims 1 to 9.

11. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, implements the steps of the security chip firmware import method as described in any one of claims 1 to 9.

Citation Information

Patent Citations

  • Chip and method for starting chip

    CN109542518A

  • Method for burning firmware to storage device and controller

    CN113434853A