Method and system for flashing a hardware security module

The hardware security module upgrade method, which uses encrypted transmission and signature verification, solves the problems of HSM software failure to upgrade and abnormal power loss, and achieves safe and reliable software updates, ensuring the safety and integrity of vehicle functions.

CN115495123BActive Publication Date: 2026-11-06SUZHOU ZHITU TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211157528.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-22
Publication Date
2026-11-06
Estimated Expiration
2042-09-22

AI Technical Summary

Technical Problem

In the existing technology, the software update scheme of hardware security module (HSM) has problems such as inability to upgrade, plaintext transmission, and failure due to abnormal power loss, which affect the functional safety of the vehicle and the safety of the occupants.

Method used

HSM software upgrades are performed using encrypted transmission and signature verification. Upgrade files are stored in a reserved cache area to ensure that the flashing process can still be completed after an abnormal power outage. The validity is verified by combining a preset algorithm and key.

Benefits of technology

It enables secure software upgrades in the presence of vulnerabilities, ensuring the confidentiality and security of HSM application software, preventing functional failures caused by unauthorized upgrades and abnormal power outages, and ensuring the safety and integrity of vehicle operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115495123B_ABST
    Figure CN115495123B_ABST
Patent Text Reader

Abstract

The application provides a kind of hardware security module's flashing method and system, method is applied to the host end in electronic control system ECU;Host end is respectively connected with the communication connection of the hardware security module HSM end in ECU, flashing tool end;The first cache area of host end is stored with HSM upgrade file;Method includes: after receiving the start flashing request sent by flashing tool end, extract ciphertext and first signature from the HSM upgrade file in the first cache area and send to HSM end, to make HSM end according to ciphertext and first signature carries out signature check;Ciphertext includes: Header ciphertext and HSM application software ciphertext;When receiving the signature check success information returned by HSM end, send upgrade flashing request to HSM end, to make HSM end execute upgrade flashing operation.The application can carry out safe software flashing process when HSM exists vulnerability, and still can carry out again flashing process after abnormal power failure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of autonomous driving technology, and in particular to a method and system for flashing a hardware security module. Background Technology

[0002] With the continuous development of intelligent and connected modern automobiles, while bringing convenience and improved driving experience, it also provides hackers with more avenues for cyberattacks. Attackers can gain access to sensitive data and remotely control vehicles by breaching in-vehicle networks or electronic components, affecting vehicle functional safety and posing a threat to the lives of passengers. Therefore, in existing ECUs (Electronic Control Units), to effectively protect the confidentiality and integrity of assets, ECUs with Hardware Security Modules (HSMs) are typically chosen to protect related assets. The HSM is responsible for performing all cryptographic applications, including symmetric key-based encryption and decryption, integrity checks, asymmetric key-based encryption and decryption, digital signature generation and verification, secure boot, and random number generation for secure applications.

[0003] With the widespread application of HSM (Hardware Service Controller), engineers have become concerned about how to upgrade the software inside the HSM. Currently, the common solutions in the automotive industry are: 1. Treating the HSM application software as firmware, which is flashed during mass production and never updated again; 2. Updating the HSM application software directly through the bootloader on the host side of the ECU.

[0004] From the perspectives of convenience and security, existing flashing solutions mainly have the following problems:

[0005] (1) If there are software problems or security vulnerabilities, and the HSM application software in the ECU needs to be updated, Option 1 cannot complete the upgrade of the HSM application software because it does not support the flashing function, which in turn affects the functional safety of the vehicle and poses a threat to the life safety of the driver and passengers.

[0006] (2) Although the HSM application software can be upgraded through the Host side Bootloader in the ECU, the HSM software must be transmitted to the Host side in plaintext, which violates the network security standard requirements and poses a security problem.

[0007] (3) If the ECU experiences an abnormal power failure during the flashing process of the HSM application software when using Scheme 2, the HSM application software will become unusable forever, and the HSM will lose the network security functions required for secure boot, encryption, and signing. Summary of the Invention

[0008] The purpose of this application is to provide a method and system for flashing a hardware security module, which can perform a secure software flashing process when there is a vulnerability in the HSM, and can still perform the flashing process after an abnormal power outage.

[0009] In a first aspect, embodiments of this application provide a method for flashing a hardware security module, the method being applied to the host end of an electronic control system (ECU); the host end is communicatively connected to a flashing tool and a hardware security module (HSM) end in the ECU; a first buffer on the host end stores an HSM upgrade file; the method includes: after receiving a start flashing request sent by the flashing tool, extracting target ciphertext and target signature from the HSM upgrade file in the first buffer and sending them to the HSM end, so that the HSM end performs signature verification based on the ciphertext and the first signature; the target ciphertext includes: header ciphertext and HSM application software ciphertext; upon receiving a signature verification success message returned by the HSM end, sending an upgrade flashing request to the HSM end, so that the HSM end performs an upgrade flashing operation.

[0010] In a preferred embodiment of this application, before the step of extracting the target ciphertext and target signature from the HSM upgrade file in the first cache and sending them to the HSM terminal after receiving the start flashing request sent by the flashing tool terminal, the method further includes: after receiving the HSM upgrade file transmitted by the flashing tool terminal, storing the HSM upgrade file in the first cache.

[0011] In a preferred embodiment of this application, after the above-described step of enabling the HSM terminal to perform signature verification based on the target ciphertext and the target signature, the method further includes: upon receiving a signature verification failure message returned by the HSM terminal, erasing the HSM upgrade file in the first cache area, and sending the HSM upgrade failure message to the flashing tool terminal.

[0012] In a preferred embodiment of this application, the method further includes: after receiving the flashing result corresponding to the upgrade flashing operation sent by the HSM terminal, sending the flashing result to the flashing tool terminal.

[0013] Secondly, this application also provides a method for flashing a hardware security module, which is applied to the HSM terminal in an ECU; the HSM terminal is communicatively connected to the host terminal in the ECU; the method includes: after receiving the target ciphertext and target signature sent by the host terminal, performing signature verification based on the target ciphertext and target signature, and sending signature verification information to the host terminal so that the host terminal can determine whether to trigger the flashing operation of the HSM terminal based on the signature verification information; the signature verification information includes: signature verification success information or signature verification failure information; the target ciphertext includes: header ciphertext and HSM application software ciphertext; after receiving the upgrade flashing request sent by the host terminal, performing a preset check based on the header ciphertext; the preset check includes: CMAC check and header ciphertext information check; if the check is successful, performing the flashing operation; if the check fails, recording the reason for the flashing failure, and returning HSM flashing failure information to the host terminal.

[0014] In a preferred embodiment of this application, the steps of performing signature verification based on the target ciphertext and the target signature, and sending signature verification information to the host, include: calculating a first hash value by using a preset secure hash algorithm to process the Header ciphertext and the HSM application software ciphertext in the target ciphertext; decrypting the target signature using a preset asymmetric algorithm and a preset public key to obtain a second hash value; determining whether the second hash value is consistent with the first hash value; if yes, sending a signature verification success message to the host; if no, sending a signature verification failure message to the host.

[0015] In a preferred embodiment of this application, the above-mentioned step of performing a preset verification based on the Header ciphertext includes: decrypting the Header ciphertext based on a preset symmetric encryption algorithm and a pre-stored private key to obtain Header plaintext; the Header plaintext includes a first CMAC checksum and upgrade-related data; the upgrade-related data includes at least one of the following: data corresponding to the HSM application software, starting address, software size, and software version number; calculating the upgrade-related data based on the private key and the preset symmetric encryption algorithm to obtain a second CMAC checksum; determining whether the second CMAC checksum and the first CMAC checksum are consistent; if so, checking whether the data contained in the Header plaintext meets the preset data requirements; if so, determining that the verification is successful.

[0016] In a preferred embodiment of this application, the second cache area of ​​the HSM terminal stores historical HSM application software; the step of performing the write operation includes: performing an erase operation on the second cache area; decrypting the ciphertext of the HSM application software based on a preset symmetric encryption algorithm and a pre-stored private key, and writing the decrypted HSM application software to the second cache area; performing integrity verification on the data written to the second cache area; if the verification is successful, writing the application software valid flag bit into the second cache area, and recording the write success information; if the verification fails, continuing to perform the steps of recording the write failure reason and returning the HSM write failure information to the host.

[0017] Thirdly, this application also provides a method for flashing a hardware security module. The method is applied to a flashing tool; the flashing tool is connected to a host in the ECU; the method includes: sending a memory erase command to the host to enable the host to check the erase address and length, and erase the first buffer used to temporarily store the HSM upgrade file; transmitting the HSM upgrade file to the host by requesting download, transmitting download data, and requesting to exit the service, so that the host temporarily stores the HSM upgrade file in the first buffer; sending a start flashing request to the host to enable the host to trigger the flashing process based on the target ciphertext and target signature extracted from the HSM upgrade file in the first buffer; and sending a flashing result acquisition command to the host according to a preset period to obtain the flashing result of the HSM application software from the host.

[0018] Fourthly, embodiments of this application also provide a hardware security module flashing system, the system comprising: a flashing tool, a host terminal in an electronic control system (ECU), and an HSM terminal; the host terminal is communicatively connected to the flashing tool and the HSM terminal respectively; the host terminal is used to execute the method described in the first aspect; the HSM terminal is used to execute the method described in the second aspect; and the flashing tool is used to execute the method described in the third aspect.

[0019] The hardware security module flashing method and system provided in this application embodiment are applied to the host terminal in the electronic control system ECU. The host terminal is communicatively connected to both the flashing tool terminal and the hardware security module (HSM) terminal in the ECU. The first buffer of the host terminal stores the HSM upgrade file. After receiving the start flashing request sent by the flashing tool terminal, the host terminal extracts the target ciphertext and target signature from the HSM upgrade file in the first buffer and sends them to the HSM terminal so that the HSM terminal can perform signature verification based on the target ciphertext and target signature. The target ciphertext includes: Header ciphertext and HSM application software ciphertext. When the host terminal receives the signature verification success information returned by the HSM terminal, it sends an upgrade flashing request to the HSM terminal so that the HSM terminal can perform the upgrade flashing operation. In this embodiment, when the HSM application software has problems or security vulnerabilities, the host can send the target ciphertext and target signature to the HSM terminal based on the HSM upgrade file stored in the first cache area, so that the HSM terminal can perform subsequent signature verification and software flashing operations. The confidentiality and security of the HSM application software can be guaranteed by transmitting the ciphertext. In addition, if an abnormal power failure occurs during the upgrade flashing process, the HSM terminal can execute the flashing process again after the ECU is powered on again because the previously stored HSM upgrade file is still stored in the first cache area. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0021] Figure 1 A structural diagram of a hardware security module flashing system provided in this application embodiment;

[0022] Figure 2 A flowchart illustrating a method for flashing a hardware security module as provided in an embodiment of this application;

[0023] Figure 3 A schematic diagram illustrating a method for flashing a hardware security module according to an embodiment of this application;

[0024] Figure 4 A flowchart illustrating another method for flashing a hardware security module provided in an embodiment of this application;

[0025] Figure 5 A schematic diagram illustrating another method for flashing a hardware security module provided in an embodiment of this application;

[0026] Figure 6This is a schematic diagram of a Header structure provided in an embodiment of this application;

[0027] Figure 7 A flowchart illustrating another method for flashing a hardware security module provided in an embodiment of this application;

[0028] Figure 8 This is a schematic diagram of another method for flashing a hardware security module provided in an embodiment of this application. Detailed Implementation

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

[0030] Currently, the automotive industry typically employs two solutions for handling HSMs: 1. Treating the HSM application software as firmware, which is flashed during mass production and never updated again; 2. Updating the HSM application software directly through the bootloader on the host side of the ECU. Both methods have certain problems, as follows:

[0031] (1) If there are software problems or security vulnerabilities, and the HSM application software in the ECU needs to be updated, Option 1 cannot complete the upgrade of the HSM application software because it does not support the flashing function, which in turn affects the functional safety of the vehicle and poses a threat to the life safety of the driver and passengers.

[0032] (2) While upgrading the HSM application software can be achieved through the Host-side Bootloader in the ECU, the HSM software must be transmitted to the Host side in plaintext. According to network security requirements, to ensure the HSM software is protected from network attacks and theft, it must be transmitted in encrypted form, and the Flash storage area it uses must be accessible only to the HSM kernel; other kernels (the Host kernel) have no access. Solution two violates network security standards.

[0033] (3) If the ECU experiences an abnormal power failure during the flashing process of the HSM application software when using Scheme 2, the HSM application software will become unusable forever, and the HSM will lose the network security functions required for secure boot, encryption, and signing.

[0034] Based on this, the embodiments of this application provide a method and system for flashing a hardware security module, which can perform a secure software flashing process when there is a vulnerability in the HSM, and can still perform the flashing process again after an abnormal power failure.

[0035] To facilitate understanding of this embodiment, a detailed description of a hardware security module flashing system disclosed in this application embodiment will be provided first.

[0036] See Figure 1 As shown, this application embodiment also provides a hardware security module flashing system, which includes: a flashing tool terminal 11, a host terminal 121 (i.e., the Host side) and an HSM terminal 122 in the electronic control system ECU 12; the host terminal 121 is communicatively connected to the flashing tool terminal 11 and the HSM terminal 122 respectively; the host terminal 121, the HSM terminal 122 and the flashing tool terminal 11 can realize the hardware security module flashing process through interaction.

[0037] After obtaining the HSM upgrade file, the flashing tool 11 sends it to the host 121. The host 121 stores the HSM upgrade file in the reserved first cache area, i.e. the Flash cache area. After receiving the start flashing request from the flashing tool 11, the host 121 triggers the interaction between the HSM terminals 122 based on the HSM upgrade file in the first cache area, so that the HSM terminals 122 complete the software flashing operation and feed back the flashing result to the flashing tool 11.

[0038] The following section provides a detailed description of the flashing methods for the three terminals: host terminal 121, HSM terminal 122, and flashing tool terminal 11.

[0039] Figure 2 The flowchart illustrates a method for flashing a hardware security module provided in this application embodiment. This method is applied to the host unit of an electronic control system (ECU). The host unit is communicatively connected to both the flashing tool and the hardware security module (HSM) in the ECU. The first buffer of the host unit stores the HSM upgrade file. The flashing method specifically includes the following steps:

[0040] Step S202: After receiving the start flashing request sent by the flashing tool, extract the target ciphertext and target signature from the HSM upgrade file in the first cache area and send them to the HSM terminal so that the HSM terminal can perform signature verification based on the target ciphertext and target signature; wherein, the target ciphertext includes: Header ciphertext and HSM application software ciphertext.

[0041] Step S204: Upon receiving the signature verification success message returned by the HSM terminal, an upgrade flashing request is sent to the HSM terminal so that the HSM terminal can perform the upgrade flashing operation.

[0042] In this embodiment, when the HSM application software has problems or security vulnerabilities, the host can send the target ciphertext and target signature to the HSM terminal based on the HSM upgrade file stored in the first cache area, so that the HSM terminal can perform subsequent signature verification and software flashing operations. The confidentiality and security of the HSM application software can be guaranteed by transmitting the ciphertext. In addition, if an abnormal power failure occurs during the upgrade flashing process, the HSM terminal can execute the flashing process again after the ECU is powered on again because the previously stored HSM upgrade file is still stored in the first cache area.

[0043] This application embodiment also provides another method for flashing a hardware security module. This method is implemented based on the previous embodiment. Before the step of extracting the target ciphertext and target signature from the HSM upgrade file in the first cache and sending them to the HSM terminal after receiving the start flashing request sent by the flashing tool, the method further includes: after receiving the HSM upgrade file transmitted by the flashing tool, storing the HSM upgrade file in the first cache.

[0044] After the step of enabling the HSM end to perform signature verification based on the target ciphertext and the target signature, another scenario is included: upon receiving the signature verification failure information returned by the HSM end, the HSM upgrade file in the first buffer is erased, and the HSM upgrade failure information is sent to the flashing tool.

[0045] After the step of enabling the HSM terminal to perform the upgrade flashing operation, the method further includes: after receiving the flashing result corresponding to the upgrade flashing operation sent by the HSM terminal, sending the flashing result to the flashing tool terminal.

[0046] See Figure 3 As shown, the interaction process between the host side and the HSM side in the ECU is as follows:

[0047] After receiving the HSM upgrade file transmitted by the external flashing tool, the Host-side Bootloader in the ECU temporarily stores it in the reserved Flash area, namely the first buffer area mentioned above. At the same time, after receiving the start flashing request sent by the external flashing tool, the Host side will trigger the HSM to perform the flashing operation.

[0048] (1) After the Host-side Bootloader software receives the flashing tool's request to start flashing HSM, it will start the HSM flashing process.

[0049] (2) The Host side will extract two parts, Header (ciphertext) + HSM Software (ciphertext) and Signature, from the HSM upgrade file in the Flash area according to the predefined protocol. The Signature is generated by operating on the ciphertext Header and HSM Software by combining asymmetric algorithms (such as RSA-2048) and SHA (Secure Hash Algorithm, such as SHA-256), while the ciphertext Header and HSM Software are generated by encrypting them by combining symmetric encryption algorithms (such as AES-128) and Secret Key.

[0050] (3) The Host-side Bootloader software triggers the HSM-side application software to perform Signature verification.

[0051] (4) After receiving the Signature verification request, the HSM side will use a predefined SHA (such as SHA-256) to calculate the Header ciphertext and HSM Software ciphertext, and output the first Hash value. Then, the input Signature will be decrypted using a predefined RSA (Rivest Shamir Adleman, asymmetric encryption algorithm, such as RSA-2048) and Public Key, and the result will be used as the second Hash value. The two will be compared and the verification result will be returned.

[0052] (5) The Host-side Bootloader software obtains the verification result returned by the HSM side. If the Signature verification is successful, it means that the upgrade file has been successfully authorized and is legitimate, and the HSM side will be triggered to execute the flashing process. Otherwise, the verification fails, and the subsequent HSM flashing process will be rejected. At the same time, the Host-side Bootloader software will erase the Flash area storing the upgrade file and return an upgrade failure to the flashing tool.

[0053] The hardware security module flashing method provided in this application has the following advantages:

[0054] ① If there are problems or security vulnerabilities in the mass-produced software, since the HSM has a bootloader that supports flashing applications, the application software in the HSM can be upgraded through an external diagnostic tool or remote upgrade technology, which can quickly eliminate security problems or vulnerabilities and ensure vehicle operation safety.

[0055] ② To ensure the confidentiality and security of HSM application software, considering network security standards, the HSM application software will be stored in encrypted form in the Flash area on the Host side. After the HSM-side Bootloader software completes the relevant verification, it will directly obtain the encrypted data from the Flash area on the Host side, decrypt it using the stored key, and then flash the Flash area of ​​the HSM application software.

[0056] ③ In this invention patent, the received HSM-side application software (in encrypted form) is temporarily stored in the reserved Flash area on the Host side, and then the HSM-side Bootloader software is triggered to complete the application software upgrade. Even if an abnormal power failure occurs during the upgrade process, when the ECU is powered on again, the previously stored upgrade file is still stored in the reserved Flash area, so the HSM-side Bootloader can execute the flashing process again.

[0057] Based on the above method embodiments, this application also provides a method for flashing a hardware security module, which is applied to the HSM terminal in an ECU; the HSM terminal is communicatively connected to the host terminal in the ECU; see [link to previous document]. Figure 4 As shown, the method specifically includes the following steps:

[0058] Step S402: After receiving the target ciphertext and target signature sent by the host, perform signature verification based on the target ciphertext and target signature, and send signature verification information to the host so that the host can determine whether to trigger the HSM terminal to perform a flashing operation based on the signature verification information.

[0059] The signature verification information includes either a successful signature verification message or a failed signature verification message.

[0060] The steps described above for performing signature verification based on the target ciphertext and the target signature, and sending signature verification information to the host, include: calculating the Header ciphertext and HSM application software ciphertext in the target ciphertext using a preset secure hash algorithm to obtain a first hash value; decrypting the target signature using a preset asymmetric algorithm and a preset public key to obtain a second hash value; determining whether the second hash value is consistent with the first hash value; if so, sending a signature verification success message to the host; if not, sending a signature verification failure message to the host.

[0061] Step S404: After receiving the upgrade flashing request sent by the host, perform a preset check based on the Header ciphertext; the preset check includes: CMAC (Cipher-based Message Authentication Code) verification and Header ciphertext information verification.

[0062] In practice, the Header ciphertext is decrypted using a preset symmetric encryption algorithm and a pre-stored private key to obtain the Header plaintext. The Header plaintext includes a first CMAC checksum and upgrade-related data. The upgrade-related data includes at least one of the following: data corresponding to the HSM application software, starting address, software size, and software version number. The upgrade-related data is calculated using the private key and the preset symmetric encryption algorithm to obtain a second CMAC checksum. It is then determined whether the second CMAC checksum and the first CMAC checksum are consistent. If they are, it is checked whether the data contained in the Header plaintext meets the preset data requirements. If they are, the verification is confirmed to be successful.

[0063] Step S406: If the verification is successful, perform the flashing operation; if the verification fails, record the reason for the flashing failure and return the HSM flashing failure information to the host.

[0064] The second buffer area of ​​the aforementioned HSM terminal stores historical HSM application software. The steps for performing the write operation include: performing an erase operation on the second buffer area; decrypting the ciphertext of the HSM application software based on a preset symmetric encryption algorithm and a pre-stored private key, and writing the decrypted HSM application software to the second buffer area; performing integrity verification on the data written to the second buffer area; if the verification is successful, writing the application software valid flag bit into the second buffer area, and recording the write success information; if the verification fails, continuing to execute the steps of recording the write failure reason and returning the HSM write failure information to the host.

[0065] The hardware security module flashing method provided in this application embodiment can quickly fix problems or security vulnerabilities in HSM application software; protect the confidentiality of HSM application software and avoid intellectual property leakage during transmission; increase the verification of the legality of upgrade files to prevent unauthorized entities from illegally upgrading HSM application software; prevent the HSM side from becoming unavailable due to abnormal power loss during HSM flashing; and record upgrade logs in HSM to facilitate analysis of the specific reasons for failure.

[0066] See Figure 5 As shown, the specific flashing process of the HSM-side Bootloader is as follows:

[0067] After receiving the HSM upgrade request from the Host side, the HSM application software will jump to the Bootloader software to complete the upgrade operation of the HSM application software.

[0068] ①After receiving the upgrade request from the Host side, the HSM side will jump to the Bootloader software on the HSM side.

[0069] ②If the HSM-side Bootloader software detects a flash request, it will begin the upgrade process.

[0070] ③ The HSM-side bootloader software first loads the encrypted header from the host-side Flash area. It then uses a pre-stored Secret Key and AES (Advanced Encryption Standard, a symmetric encryption algorithm such as AES-128) to decrypt the encrypted data, obtaining the plaintext header. The specific data structure of the header is as follows: Figure 6 As shown. Here, Pattern is used for data padding, Address represents the starting address of the HSM application software, Size represents the application software size, Version represents the HSM version number, and CMAC represents the integrity check code for the Header data. Note: The Header structure includes, but is not limited to, the above data content.

[0071] ④ The HSM-side Bootloader software performs CMAC verification. It processes the data in the Header structure other than CMAC using a predefined symmetric encryption algorithm (such as AES-128) and the Secret Key, generates a CMAC value, and compares this value with the CMAC in the Header. If they match, it proceeds to the next step; otherwise, it records the reason for the write failure and returns the result to the Host side.

[0072] ⑤ Check the information in the Header, including but not limited to the following: a) Whether the Pattern data conforms to the predefined value; b) Whether the Address is within the range managed by the Bootloader; c) Whether the Address + Size exceeds the range of the HSM-side Flash memory; d) Whether the Version is greater than the current software version. If the verification passes, proceed to the next step; otherwise, record the reason for the flash failure and return the result to the Host side.

[0073] ⑥ The HSM-side Bootloader software performs an erase operation on the Flash area where the HSM application software is located.

[0074] ⑦ Retrieve the encrypted HSM application software from the Host-side Flash memory, decrypt the encrypted data using a predefined Secret Key and a symmetric encryption algorithm (AES-128), and then flash the decrypted HSM application software into the HSM-side Flash memory area. Repeat this process until all HSM application software has been flashed.

[0075] ⑧ After the above process is completed, ensure the consistency of the software, perform CRC calculation on the data written to the Flash area, compare the result with the CRC in the upgrade file, and output the integrity verification result.

[0076] ⑨ If the verification results are consistent, write the application software valid flag bit to the specified position in the Flash area on the HSM side, and record that the flashing was successful. Otherwise, record the reason for the flashing failure and return the result to the Host side.

[0077] The hardware security module flashing method provided in this application can quickly repair any vulnerabilities or security flaws in the HSM application software within the ECU. The HSM upgrade file involved in this application is encrypted throughout the entire transmission process, effectively ensuring the confidentiality of the HSM software. To prevent the HSM application software from becoming unusable due to abnormal power loss during the HSM flashing process, this application provides a corresponding strategy: reserving a certain size Flash area on the host side to cache the received HSM upgrade file. Therefore, when an abnormal power loss occurs, the ECU can re-execute the HSM upgrade function after power-on. To effectively verify the legality and validity of the upgrade file, a signature verification mechanism is introduced. Signature verification is only successful when the Private Key and Public Key used to generate and verify the Signature match, indicating the legitimacy of the upgrade file source and allowing subsequent HSM flashing operations. This application embodiment... Figure 5 The HSM flashing process shown can effectively upgrade HSM application software in both the project development and mass production stages, while ensuring the security and integrity of the software.

[0078] Based on the above method embodiments, this application also provides a method for flashing a hardware security module, which is applied to a flashing tool; the flashing tool is communicatively connected to the host unit in the ECU; see [link to previous document]. Figure 7 As shown, the method includes the following steps:

[0079] Step S702: Send an erase memory command to the host to enable the host to check the erase address and length, and erase the first cache area used to temporarily store the HSM upgrade file;

[0080] Step S704: The HSM upgrade file is transmitted to the host by requesting download, transmitting download data, and requesting to exit service, so that the host temporarily stores the HSM upgrade file in the first cache area.

[0081] Step S706: Send a start flashing request to the host to enable the host to trigger the flashing process based on the target ciphertext and target signature extracted from the HSM upgrade file in the first cache.

[0082] Step S708: According to a preset cycle, send a flashing result acquisition command to the host to obtain the flashing result of the HSM application software from the host.

[0083] See Figure 8 As shown, the HSM upgrade file transfer process is as follows:

[0084] After receiving the upgrade file from the HSM application software, the flashing tool uses the UDS (Unified Diagnostic Services) standard service and process to transmit the upgrade file to the Host side in the ECU via the relevant communication protocol.

[0085] ① The flashing tool requests the ECU to initiate a programmable session, and the ECU software enters the bootloader on the host side.

[0086] ② The flashing tool securely accesses the ECU, which completes identity verification and prepares to enter the flashing stage.

[0087] ③ The flashing tool sends the memory erase routine control, and the host-side bootloader checks the address and length to be erased.

[0088] Erase the Flash area used to temporarily store HSM upgrade files.

[0089] ④ By requesting download, transmitting download data, and requesting to exit service, all data is transmitted to the Host side in the ECU. The Host-side Bootloader software temporarily stores the received data in the Flash area described above.

[0090] ⑤ After the data transmission is completed, in order to ensure data consistency, the flashing tool sends a routine control service to perform CRC (Cyclic Redundancy Check) integrity verification on the data transmitted to the ECU.

[0091] ⑥ The flashing tool sends a routine control service to initiate the HSM application software flashing process.

[0092] ⑦ The flashing tool periodically sends routine control services to obtain the final flashing result.

[0093] This application also provides a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the above-described method. For specific implementation details, please refer to the foregoing method embodiments, which will not be repeated here.

[0094] The computer program products of the methods, apparatus, and electronic devices provided in the embodiments of this application include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementations, please refer to the method embodiments, which will not be repeated here.

[0095] Unless otherwise specifically stated, the relative steps, numerical expressions, and values ​​of the components and steps described in these embodiments do not limit the scope of this application.

[0096] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0097] In the description of this application, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0098] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The protection scope of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the technical scope disclosed in this application. Such modifications, changes, 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 covered within the protection scope of this application. Therefore, the protection scope of this application should be determined by the protection scope of the claims.

Claims

1. A method for flashing a hardware security module, characterized in that, The method is applied to the host unit in an electronic control system (ECU); the host unit is communicatively connected to the flashing tool and the hardware security module (HSM) in the ECU. The first cache on the host computer stores the HSM upgrade file; the method includes: Upon receiving the start flashing request from the flashing tool, the target ciphertext and target signature are extracted from the HSM upgrade file in the first cache and sent to the HSM terminal, so that the HSM terminal can perform signature verification based on the target ciphertext and target signature; the target ciphertext includes: Header ciphertext and HSM application software ciphertext; Upon receiving the signature verification success message returned by the HSM terminal, an upgrade flashing request is sent to the HSM terminal to enable the HSM terminal to perform the upgrade flashing operation. This includes: after receiving the upgrade request from the host terminal, the HSM terminal will jump to the HSM terminal's bootloader software; if the HSM terminal's bootloader software detects the flashing request, it will start the upgrade process: the HSM terminal's bootloader software first loads the encrypted header from the host terminal's Flash area, decrypts the encrypted data using a pre-stored Secret Key and AES, and obtains the plaintext header data; it performs CMAC verification, processes the data in the header structure other than CMAC using a predefined symmetric encryption algorithm and Secret Key, generates a CMAC value, compares this value with the CMAC in the header, if they match, proceeds to the next step; otherwise, it records the reason for the flashing failure and returns the result to the host terminal; it checks the information in the header, including at least the following: whether the Pattern data conforms to the predefined value, whether the Address is within the Bootloader's management range, and whether the Address + If the size exceeds the HSM flash memory range and the version is greater than the current software version, proceed to the next step; otherwise, record the reason for the flashing failure and return the result to the host. Perform an erase operation on the flash area where the HSM application software is located. Retrieve the encrypted HSM application software from the host flash, decrypt the encrypted data using a predefined Secret Key and a symmetric encryption algorithm, and flash the decrypted HSM application software to the HSM flash area. Repeat the upgrade process until all HSM application software has been flashed. To ensure software consistency, perform CRC calculation on the data flashed to the flash area, compare the CRC calculation result with the CRC in the upgrade file, and output the integrity verification result. If the verification results match, write the application software valid flag bit to the specified position in the HSM flash area and record the flashing success; otherwise, record the reason for the flashing failure and return the result to the host.

2. The method according to claim 1, characterized in that, Before the step of extracting the target ciphertext and target signature from the HSM upgrade file in the first cache and sending them to the HSM terminal after receiving the start flashing request from the flashing tool, the method further includes: After receiving the HSM upgrade file transmitted by the flashing tool, the HSM upgrade file is stored in the first cache area.

3. The method according to claim 1, characterized in that, After the step of enabling the HSM terminal to perform signature verification based on the target ciphertext and the target signature, the method further includes: Upon receiving the signature verification failure message returned by the HSM terminal, the HSM upgrade file in the first cache area is erased, and the HSM upgrade failure message is sent to the flashing tool terminal.

4. The method according to claim 1, characterized in that, The method further includes: After receiving the flashing result corresponding to the upgrade flashing operation sent by the HSM terminal, the flashing result is sent to the flashing tool terminal.

5. A method for flashing a hardware security module, characterized in that, The method is applied to the HSM terminal in the ECU; The HSM terminal is communicatively connected to the host terminal in the ECU; the method includes: After receiving the target ciphertext and target signature sent by the host, a signature verification is performed based on the target ciphertext and target signature, and signature verification information is sent to the host so that the host can determine whether to trigger the HSM terminal to perform a flashing operation based on the signature verification information; the signature verification information includes: signature verification success information or signature verification failure information; the target ciphertext includes: header ciphertext and HSM application software ciphertext; Upon receiving the upgrade flashing request sent by the host, a preset check is performed based on the Header ciphertext; the preset check includes: CMAC verification and information verification of the Header ciphertext. If the verification is successful, the flashing operation will proceed, including: After receiving the upgrade request from the host, the HSM will redirect to the HSM's Bootloader software; if the HSM's Bootloader software detects the flashing request, it will begin the upgrade process: The HSM's Bootloader software first loads the encrypted Header from the host's Flash area, decrypts the encrypted data using a pre-stored Secret Key and AES, and obtains the plaintext Header; it performs CMAC verification, processes the data in the Header structure except for CMAC using a predefined symmetric encryption algorithm and the Secret Key, generates a CMAC value, compares this value with the CMAC in the Header, if they match, proceed to the next step; otherwise, it records the reason for the flashing failure and returns the result to the host; it checks the information in the Header, including at least the following: whether the Pattern data conforms to the predefined values, whether the Address is within the Bootloader's management range, and whether the Address + Check if the Size exceeds the HSM Flash memory range and if the Version is greater than the current software version; if the verification passes, proceed to the next step; otherwise, record the reason for the flashing failure and return the result to the host; perform an erase operation on the Flash area where the HSM application software is located; retrieve the encrypted HSM application software from the host Flash, decrypt the encrypted data using a predefined Secret Key and a symmetric encryption algorithm, and flash the decrypted HSM application software into the HSM Flash area; repeat the upgrade process until all HSM application software has been flashed; to ensure software consistency, perform CRC calculation on the data flashed into the Flash area, compare the CRC calculation result with the CRC in the upgrade file, and output the integrity verification result; if the verification results match, write the application software valid flag bit at the specified position in the HSM Flash area and record the flashing success; otherwise, record the reason for the flashing failure and return the result to the host; If the verification fails, record the reason for the flashing failure and return the HSM flashing failure information to the host.

6. The method according to claim 5, characterized in that, The steps of performing signature verification based on the target ciphertext and the target signature, and sending signature verification information to the host, include: The first hash value is obtained by calculating the Header ciphertext and HSM application software ciphertext in the target ciphertext using a preset secure hash algorithm. The target signature is decrypted using a preset asymmetric algorithm and a preset public key to obtain a second hash value; Determine whether the second hash value is consistent with the first hash value; If so, send a signature verification success message to the host. If not, send a signature verification failure message to the host.

7. The method according to claim 5, characterized in that, The steps for performing a preset check based on the Header ciphertext include: The Header ciphertext is decrypted using a preset symmetric encryption algorithm and a pre-stored private key to obtain the Header plaintext. The Header plaintext includes a first CMAC checksum and upgrade-related data. The upgrade-related data includes at least one of the following: data corresponding to the HSM application software, starting address, software size, and software version number. The upgrade-related data is calculated based on the private key and the preset symmetric encryption algorithm to obtain the second CMAC checksum; Determine whether the second CMAC checksum and the first CMAC checksum are consistent; If so, check whether the data contained in the Header plaintext meets the preset data requirements; If so, the test was successful.

8. A method for flashing a hardware security module, characterized in that, The method is applied to a flashing tool; the flashing tool is communicatively connected to the host unit in the ECU; the method includes: Send an erase memory command to the host to enable the host to check the erase address and length, and erase the first cache area used to temporarily store HSM upgrade files; The HSM upgrade file is transmitted to the host by requesting download, transmitting download data, and requesting to exit the service, so that the host temporarily stores the HSM upgrade file in the first cache area. Send a start flashing request to the host, so that the host triggers the flashing process based on the target ciphertext and target signature extracted from the HSM upgrade file in the first cache, including: After receiving the upgrade request from the host, the HSM terminal will redirect to its bootloader software. If the HSM bootloader software detects a flash request, it will begin the upgrade process: First, the HSM bootloader software loads the encrypted header from the host's Flash area. It then decrypts the encrypted data using a pre-stored Secret Key and AES to obtain the plaintext header. Next, it performs CMAC verification, processing all data in the header structure except for the CMAC using a predefined symmetric encryption algorithm and the Secret Key to generate a CMAC value. This value is compared with the CMAC in the header. If they match, the next step is performed; otherwise, the reason for the flash failure is recorded, and the result is returned to the host. Finally, the information in the header is checked, including at least the following: whether the Pattern data conforms to predefined values, whether the Address is within the bootloader's management range, and whether the Address + ... Check if the Size exceeds the HSM Flash memory range and if the Version is greater than the current software version; if the verification passes, proceed to the next step; otherwise, record the reason for the flashing failure and return the result to the host; perform an erase operation on the Flash area where the HSM application software is located; retrieve the encrypted HSM application software from the host Flash, decrypt the encrypted data using a predefined Secret Key and a symmetric encryption algorithm, and flash the decrypted HSM application software into the HSM Flash area; repeat the upgrade process until all HSM application software has been flashed; to ensure software consistency, perform CRC calculation on the data flashed into the Flash area, compare the CRC calculation result with the CRC in the upgrade file, and output the integrity verification result; if the verification results match, write the application software valid flag bit at the specified position in the HSM Flash area and record the flashing success; otherwise, record the reason for the flashing failure and return the result to the host; According to a preset cycle, a flashing result acquisition command is sent to the host to obtain the flashing result of the HSM application software from the host.

9. A flashing system for a hardware security module, characterized in that, The system includes: a flashing tool terminal, a host terminal in the electronic control system (ECU), and an HSM terminal; the host terminal is communicatively connected to the flashing tool terminal and the HSM terminal respectively; the host terminal is used to execute the method as described in any one of claims 1-4; the HSM terminal is used to execute the method as described in any one of claims 5-7; and the flashing tool terminal is used to execute the method as described in claim 8.

Citation Information

Patent Citations

  • Diagnosis joint update verification method and device of diagnosis device and diagnosis joint

    CN108124491A

  • KR20200020645A