Encryption method, decryption method and system for firmware upgrade file

CN121664434BActive Publication Date: 2026-09-22ZHEJIANG LEAPENERGY TECH CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202511896149.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-16
Publication Date
2026-09-22
Estimated Expiration
2045-12-16

AI Technical Summary

Technical Problem

[0003]本申请提供一种固件升级文件的加密方法、解密方法及系统,其解决了相关技术无法兼顾高强度加密与低资源开销的技术问题,达到了低成本构建端到端的保护闭环的技术效果

Benefits of technology

[0007]通过对随机数和用户密钥执行确定性的逻辑运算,生成格式规整的中间值,为加解密同步提供了可靠的基础,无需专用加密引擎,具有极佳的平台兼容性。通过对中间值进行非线性变换,有效打破了输入与输出之间可能存在的线性或可预测关系,从而提升了最终生成的加密种子对抗线性密码分析及差分密码分析等攻击的鲁棒性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121664434B_ABST
    Figure CN121664434B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of automobile firmware upgrading, and discloses an encryption method, a decryption method and a system for a firmware upgrading file, wherein the encryption method comprises the following steps: obtaining an original program file to be encrypted; generating signature data according to the original program file; generating a random number, and generating an encryption seed based on the random number and a preset user key; determining an encryption variable based on the encryption seed, and respectively performing encryption transformation on the signature data and the original program file based on the encryption variable to obtain an encrypted signature and encrypted program data, wherein the encryption variable is iteratively updated according to a preset rule in the encryption transformation process; and generating an encrypted file for firmware upgrading based on the random number, the encrypted signature and the encrypted program data, so that the technical effect of constructing an end-to-end protection closed loop at a low cost is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automotive firmware upgrade technology, and in particular to a method for encrypting, decrypting and encrypting firmware upgrade files. Background Technology

[0002] With the rapid development of automotive electronics and intelligence, in-vehicle electronic control units (ECUs) have become core components of modern automobiles. The online upgrade function of their internal software (firmware) is a key technology for ensuring vehicle performance, fixing vulnerabilities, and adding new features. Firmware upgrade files are typically released in binary format and distributed to the ECU via diagnostic interfaces or wireless networks. However, this process faces severe information security challenges: if upgrade files are released and circulated in plaintext, attackers can easily intercept data packets and use disassembly, reverse engineering, and other methods to analyze core algorithms and logic. This directly leads to the illegal cracking of software functions, copyright piracy, and even the implantation of malicious code to tamper with the firmware. This not only seriously infringes upon the manufacturer's intellectual property rights and commercial interests but may also cause abnormal vehicle control logic, posing a direct threat to driving safety. Summary of the Invention

[0003] This application provides a method for encrypting and decrypting firmware upgrade files, as well as a system that solves the technical problem that related technologies cannot simultaneously achieve high-strength encryption and low resource consumption, thus achieving the technical effect of building an end-to-end protection closed loop at low cost.

[0004] To achieve the above objectives, the main technical solutions adopted in this application include: In a first aspect, embodiments of this application provide a method for encrypting firmware upgrade files. The encryption method includes: obtaining an original program file to be encrypted; generating signature data based on the original program file; generating a random number and generating an encryption seed based on the random number and a preset user key; determining encryption variables based on the encryption seed and performing encryption transformations on the signature data and the original program file based on the encryption variables to obtain an encrypted signature and encrypted program data, wherein, during the encryption transformation process, the encryption variables are iteratively updated according to preset rules; and generating an encrypted file for firmware upgrade based on the random number, the encrypted signature, and the encrypted program data.

[0005] The firmware upgrade file encryption method provided in this application ensures one-time encryption by introducing random numbers and generates iteratively updatable encryption variables based on an encryption seed. This allows for segmented data processing and enables streaming segmented encryption of firmware files, making the method suitable for embedded environments with limited storage and computing resources, such as automotive ECUs. Simultaneously, the encryption variables are iteratively updated according to preset rules after each encryption operation, ensuring that the same plaintext generates different ciphertexts in different contexts. This achieves non-fixed mapping encryption, effectively enhancing resistance to cryptanalysis. By integrating signature data, random numbers, and encryption program data into a single encrypted file, the encrypted file itself possesses both integrity verification and source authentication capabilities, constructing an end-to-end protection loop for firmware upgrades while ensuring the confidentiality of the encrypted program file.

[0006] Optionally, generating an encryption seed based on the random number and a preset user key includes: performing logical operations on the random number and the user key to obtain an intermediate value, wherein the logical operations include at least one of bitwise XOR, bitwise AND, addition, and multiplication; and performing a nonlinear transformation on the intermediate value to generate the encryption seed.

[0007] By performing deterministic logical operations on random numbers and user keys, a well-formatted intermediate value is generated, providing a reliable foundation for encryption and decryption synchronization. This eliminates the need for a dedicated encryption engine and offers excellent platform compatibility. Furthermore, by applying a non-linear transformation to the intermediate value, the potential linear or predictable relationship between input and output is broken, thereby enhancing the robustness of the final generated encryption seed against attacks such as linear cryptanalysis and differential cryptanalysis.

[0008] Optionally, performing a nonlinear transformation on the intermediate value includes multiplying the intermediate value by a preset first prime number.

[0009] By using multiplication, a fundamental arithmetic operation, the linear or affine relationship between input and output that could previously be formed by linear logical operations (such as XOR and addition) is broken. This allows for the introduction of mathematical nonlinearity and diffusion properties necessary for cryptanalysis resistance into the resource-constrained encryption seed generation process, at the cost of extremely low computational overhead.

[0010] Optionally, the random number is generated as follows: obtain the current system time; generate the random number based on the current system time.

[0011] By utilizing the system clock, which is widely present in all microcontrollers, as an entropy source, the uniqueness of the ciphertext output by the same firmware is effectively guaranteed when it is encrypted multiple times. At the same time, it ensures that this encryption scheme can run on any embedded hardware platform without relying on a dedicated random number generator, thus enhancing the versatility and ease of deployment of the scheme.

[0012] Optionally, encryption variables are determined based on the encryption seed, and the signature data and the original program file are encrypted based on the encryption variables to obtain an encrypted signature and encrypted program data. During the encryption transformation process, the encryption variables are iteratively updated according to preset rules, including: determining the current encryption variable based on the encryption seed; for any current data unit to be encrypted in the signature data or the original program file, performing an encryption operation on the current data unit based on the current encryption variable to obtain an encrypted data unit, and iterating the current encryption variable according to the preset rules; obtaining the encrypted signature based on each encrypted data unit of the signature data; and obtaining the encrypted program data based on each encrypted data unit of the original program file.

[0013] By encrypting data units one by one using encrypted variables, this becomes possible on microcontrollers with limited memory, solving the resource constraints problem in embedded environments. After each data unit is encrypted, the encrypted variables are iteratively updated according to preset rules. Even if the plaintext data units are the same, the generated encrypted data units are completely different because their encrypted variables are different, thus achieving non-fixed mapping encryption.

[0014] Optionally, the encryption operation includes at least one of bitwise XOR operation and bitwise NOT operation.

[0015] By concentrating limited computing resources on generating high-quality, dynamic encrypted variables, while encrypting the data itself using the simplest operation with almost zero overhead, a level of security that traditionally required dedicated hardware or complex algorithms can be achieved on a resource-constrained platform (vehicle ECU).

[0016] Optionally, iterating the current encrypted variable according to the preset rules includes at least one of the following methods: multiplying the current encrypted variable by a preset second prime number to obtain a product, and using the product as the iterated current encrypted variable; or querying a preset nonlinear permutation table based on the current encrypted variable to obtain a query result, and using the query result as the iterated current encrypted variable.

[0017] Efficient nonlinear perturbation is achieved by multiplying the current encrypted variable by a preset large prime number or by querying a preset nonlinear permutation table. These two mechanisms can be used independently or in combination, making the iterative update of the encrypted variable no longer a simple linear recursion, but effectively resisting professional cryptanalysis attacks based on linear relationships or differential features, achieving ideal security performance within the limited computing power of the embedded platform.

[0018] Secondly, embodiments of this application provide an encryption system for firmware upgrade files. The system includes: a file acquisition module for acquiring an original program file to be encrypted; a signature generation module for generating signature data based on the original program file; an encryption seed generation module for generating a random number and generating an encryption seed based on the random number and a preset user key; an encryption transformation module for determining encryption variables based on the encryption seed and performing encryption transformations on the signature data and the original program file based on the encryption variables to obtain an encrypted signature and encrypted program data, wherein, during the encryption transformation process, the encryption variables are iteratively updated according to preset rules; and an encrypted file generation module for generating an encrypted file for firmware upgrade based on the random number, the encrypted signature, and the encrypted program data.

[0019] Thirdly, embodiments of this application provide a method for decrypting firmware upgrade files, used to decrypt encrypted files generated by the above-mentioned encryption method. The decryption method includes: extracting a random number, an encryption signature, and encryption program data from the encrypted file; generating a decryption seed based on the extracted random number and a user key identical to that of the encryptor; determining decryption variables based on the decryption seed, and performing decryption transformations on the encryption signature and the encryption program based on the decryption variables to obtain signature data and an original program file, wherein, during the decryption transformation process, the decryption variables are iteratively updated according to the same preset rules as those of the encryptor; generating verification signature data based on the original program file; and determining that decryption is successful if the verification signature data matches the signature data obtained from the decryption transformation.

[0020] Fourthly, embodiments of this application provide a firmware upgrade file decryption system for decrypting encrypted files generated by the aforementioned encryption method. The system includes: a data extraction module for extracting random numbers, encryption signatures, and encryption program data from the encrypted file; a decryption seed generation module for generating a decryption seed based on the extracted random numbers and a user key identical to that of the encryptor; a decryption transformation module for determining decryption variables based on the decryption seed and performing decryption transformations on the encryption signature and the encryption program data based on the decryption variables to obtain signature data and an original program file, wherein, during the decryption transformation process, the decryption variables are iteratively updated according to the same preset rules as those of the encryptor; a verification signature generation module for generating verification signature data based on the original program file; and a determination module for determining successful decryption if the verification signature data matches the signature data obtained from the decryption transformation.

[0021] Fifthly, embodiments of this application provide a computer device, including: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the above-mentioned encryption and / or decryption methods for firmware upgrade files.

[0022] Sixthly, embodiments of this application provide a computer-readable storage medium storing computer instructions, which are used to cause a computer to execute the above-described encryption and / or decryption methods for firmware upgrade files.

[0023] In a seventh aspect, embodiments of this application provide a computer program product, including computer instructions, which are used to cause a computer to execute the above-described encryption and / or decryption methods for firmware upgrade files. Attached Figure Description

[0024] 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.

[0025] Figure 1 A flowchart illustrating a firmware upgrade file encryption method provided in this application embodiment; Figure 2 A schematic diagram of an encryption system for firmware upgrade files provided in this application embodiment; Figure 3 A flowchart illustrating a method for decrypting firmware upgrade files provided in this application embodiment; Figure 4 A schematic diagram of a firmware upgrade file decryption system provided in this application embodiment; Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. 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.

[0027] Electronic Control Units (ECUs) are core control components in modern vehicles and various industrial equipment. The security of their embedded software (firmware) directly affects the reliable operation and functional safety of the equipment. Throughout the product's lifecycle, ECU firmware often needs to be upgraded to fix defects, improve performance, or add new features. The typical upgrade process involves developers compiling the source code into an executable binary program file, then using in-application programming (IAP) technology to send this file to the target ECU via a communication network (such as CAN or UART). The ECU's internal bootloader then writes the file into its storage area, completing the update. However, this upgrade process carries significant information security risks. Directly releasing or transmitting unprotected raw firmware files exposes the following threats. First, there is the risk of intellectual property leakage and piracy: attackers can easily obtain the complete binary image, and after disassembly analysis, directly clone the hardware controller, seriously infringing on the rights and interests of developers. Second, there is the risk of function tampering and malicious implantation: attackers can reverse engineer the program logic, illegally modify key control functions (such as removing power limits and bypassing security checks), and even implant malicious code, endangering equipment and personal safety. Third, there is the risk of eavesdropping during transmission: even if the file is processed at the publishing end, if it is transmitted in plaintext on the transmission link, attackers can record the upgrade data stream through bus monitoring and other means, thereby restoring the original firmware.

[0028] To address these challenges, several technical solutions exist, each with its own limitations. The first solution is plaintext distribution and upgrades, meaning no encryption measures are taken. While simple to implement and requiring no additional ECU resources, this solution is completely defenseless against any of the aforementioned security attacks and fails to meet basic confidentiality and integrity requirements. The second solution relies on compiler-side encryption and decryption using high-strength encryption algorithms. This solution encrypts the firmware on the host machine using algorithms such as Advanced Encryption Standard (AES), but during upgrades, the host computer software performs decryption and sends the decrypted plaintext data stream to the ECU. Its limitations are as follows: First, complex encryption and decryption algorithms such as AES have high computational resource requirements, making it difficult to run efficiently on resource-constrained microcontroller units (MCUs). Therefore, the decryption process is forced to be completed on the host side. Second, this results in data being in plaintext during transmission from the host computer to the ECU, allowing attackers to obtain the original firmware completely through eavesdropping, rendering end-side encryption meaningless. Third, such algorithms typically require decryption of entire blocks of data, demanding sufficient buffer storage space from the ECU, placing a significant burden on resource-constrained MCUs. The third approach is based on digital signature-based legitimacy verification. This approach focuses on verifying the authenticity and integrity of the firmware source, rather than encrypting the content itself. It typically uses a hash algorithm to generate a firmware digest and uses an asymmetric encryption algorithm to sign the digest to generate a certificate. During upgrades, the ECU uses a pre-set public key to verify the certificate and check the signature. The advantage of this approach is that it effectively prevents unauthorized firmware from being flashed. However, its core drawback is that the firmware program itself is always stored and transmitted in plaintext. Although attackers cannot pass the verification, they can still legally obtain, analyze, and copy the plaintext program. This cannot prevent technical theft and secondary development through disassembly, indicating a vulnerability in intellectual property protection.

[0029] In summary, existing technical solutions often struggle to balance high security, low resource consumption, and practicality when implementing secure ECU firmware upgrades. They may lack sufficient security strength, place excessive demands on the terminal MCU's performance (making local decryption impossible), or only provide source authentication without protecting the code itself from leakage and analysis. Therefore, there is an urgent need for an innovative technical solution that can achieve end-to-end firmware content confidentiality in resource-constrained microcontroller environments and support efficient and secure decryption and verification at the device terminal.

[0030] The firmware upgrade file encryption method provided in this application, through a lightweight streaming encryption / decryption design and a dynamic seed update mechanism, can run efficiently on microcontrollers (MCUs) with limited storage and computing resources and no dedicated hardware encryption engine, thus achieving secure firmware upgrades on embedded terminals such as vehicle control modules. It should be noted that the steps shown in the flowcharts in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be executed in a different order than that presented here.

[0031] Please refer to Figure 1 , Figure 1 A flowchart illustrating a firmware upgrade file encryption method provided in this application embodiment is shown below. Figure 1 As shown, the process includes the following steps: Step S1: Obtain the original program file to be encrypted.

[0032] The original program file refers to the executable program image file that exists in binary format, is not encrypted, and can be directly burned to the microcontroller, generated by compiling and linking the embedded software source code. It is the core data object to be encrypted.

[0033] Step S3: Generate signature data based on the original program file.

[0034] The signature data is a digital fingerprint generated from the original program file using a cryptographic hash function (such as SHA-256), possessing uniqueness and tamper-proof properties. The signature data is encrypted and protected along with the original program file. At the decryption end, the decrypted signature data is compared with the digital fingerprint recalculated from the decrypted program file to achieve dual verification of data integrity and source authenticity. If they match, verification passes; otherwise, the upgrade process terminates, thus establishing an end-to-end trusted and secure channel.

[0035] Step S5: Generate a random number, and based on the random number and the preset user key, generate an encryption seed.

[0036] A random number is a non-predictable value generated on the fly during each encryption process, used to ensure that the ciphertext produced by encrypting the same program file is different each time. A user key is a fixed key shared in advance by the encryptor and decryptor. Combining the user key with the random number used in this encryption generates a seed that is used only for this encryption, thereby improving resistance to cryptanalysis.

[0037] Step S7: Determine encryption variables based on the encryption seed, and perform encryption transformations on the signature data and the original program file based on the encryption variables to obtain encrypted signature and encrypted program data. During the encryption transformation process, the encryption variables are iteratively updated according to preset rules.

[0038] The encryption seed is used to initialize the encryption variables. Encryption transformation refers to performing reversible cryptographic operations, such as bitwise XOR, on each data unit of the signature data or original program file based on the encryption variables. Iterative update of encryption variables means that after each data unit's encryption transformation is completed, the encryption variables are iteratively updated according to preset rules and used for the encryption of the next data unit. This iterative update ensures that the encryption variables change continuously and discretely during the encryption process, guaranteeing that the same plaintext unit will be encrypted with different encryption variables at different positions in the file. This results in highly discrete ciphertext, breaking the fixed correspondence between plaintext and ciphertext. Furthermore, since each encryption session uses a different random number to generate the encryption seed, combined with the iterative update mechanism of the encryption variables during the encryption process, even for the exact same original program file, the complete ciphertext output from two independent encryption processes will be completely different. This further enhances the system's overall resistance to cryptanalysis.

[0039] Step S9: Based on the random number, the cryptographic signature, and the cryptographic program data, generate an encrypted file for firmware upgrade.

[0040] The independent encryption signatures and encryption program data generated during the encryption process, along with random numbers, are integrated into a single encrypted file based on preset combination rules, thereby improving the firmware's ability to prevent tampering.

[0041] The firmware upgrade file encryption method provided in this application ensures one-time encryption by introducing random numbers and generates iteratively updatable encryption variables based on an encryption seed. This allows for segmented data processing and enables streaming segmented encryption of firmware files, making the method suitable for embedded environments with limited storage and computing resources, such as automotive ECUs. Simultaneously, the encryption variables are iteratively updated according to preset rules after each encryption operation, ensuring that the same plaintext generates different ciphertexts in different contexts. This achieves non-fixed mapping encryption, effectively enhancing resistance to cryptanalysis. By integrating signature data, random numbers, and encryption program data into a single encrypted file, the encrypted file itself possesses both integrity verification and source authentication capabilities, constructing an end-to-end protection loop for firmware upgrades while ensuring the confidentiality of the encrypted program file.

[0042] In some specific embodiments, generating an encryption seed based on the random number and a preset user key includes: performing logical operations on the random number and the user key to obtain an intermediate value, wherein the logical operations include at least one of bitwise XOR operation, bitwise AND operation, addition operation, and multiplication operation; and performing a nonlinear transformation on the intermediate value to generate the encryption seed.

[0043] In the process of generating the encryption seed, deterministic logical operations are first performed on random numbers and the user key to generate a well-formatted intermediate value, providing a reliable foundation for encryption and decryption synchronization. This eliminates the need for a dedicated encryption engine and offers excellent platform compatibility. By applying a non-linear transformation to the intermediate value, the potentially linear or predictable relationship between input and output is effectively broken, thereby improving the robustness of the final encryption seed against attacks such as linear cryptanalysis and differential cryptanalysis.

[0044] In some specific embodiments, performing a nonlinear transformation on the intermediate value includes multiplying the intermediate value by a preset first prime number.

[0045] By using multiplication, a fundamental arithmetic operation, the linear or affine relationship between input and output that could previously be formed by linear logical operations (such as XOR and addition) is broken. This allows for the introduction of mathematical nonlinearity and diffusion properties necessary for cryptanalysis resistance into the resource-constrained encryption seed generation process, at the cost of extremely low computational overhead.

[0046] In some specific embodiments, the random number is generated as follows: the current system time is obtained; the random number is generated based on the current system time.

[0047] By utilizing the system clock, which is widely present in all microcontrollers, as an entropy source, the uniqueness of the ciphertext output by the same firmware is effectively guaranteed when it is encrypted multiple times. At the same time, it ensures that this encryption scheme can run on any embedded hardware platform without relying on a dedicated random number generator, thus enhancing the versatility and ease of deployment of the scheme.

[0048] In some specific embodiments, encryption variables are determined based on the encryption seed, and the signature data and the original program file are encrypted using the encryption variables to obtain an encrypted signature and encrypted program data. During the encryption transformation process, the encryption variables are iteratively updated according to preset rules, including: determining the current encryption variable based on the encryption seed; for any current data unit to be encrypted in the signature data or the original program file, performing an encryption operation on the current data unit based on the current encryption variable to obtain an encrypted data unit, and iterating the current encryption variable according to the preset rules; obtaining the encrypted signature based on each encrypted data unit of the signature data; and obtaining the encrypted program data based on each encrypted data unit of the original program file.

[0049] By encrypting data units one by one using encrypted variables, this becomes possible on microcontrollers with limited memory, solving the resource constraints of embedded environments. After each data unit is encrypted, the encrypted variables are iteratively updated according to preset rules. Even if the plaintext data units are the same, the generated encrypted data units are completely different because the encrypted variables are different, thus achieving non-fixed mapping encryption. In this way, with near-minimum computational and storage overhead that embedded environments can tolerate, a highly dynamic and analysis-resistant level of encryption security is achieved, which would otherwise require complex algorithms and powerful hardware.

[0050] In some specific embodiments, the encryption operation includes at least one of bitwise XOR operation and bitwise NOT operation.

[0051] Bitwise XOR and bitwise NOT are among the most basic and fastest operations in CPU instruction sets, typically completed within a single clock cycle. This allows for encryption of each data unit with virtually no perceptible computational latency or additional power consumption. By concentrating limited computing resources on generating high-quality, dynamic encrypted variables, while encrypting the data itself using minimal-overhead operations, a level of security traditionally requiring dedicated hardware or complex algorithms can be achieved on resource-constrained platforms (vehicle ECUs).

[0052] In some specific embodiments, iterating the current encrypted variable according to the preset rules includes at least one of the following methods: multiplying the current encrypted variable by a preset second prime number to obtain a product, and using the product as the iterated current encrypted variable; based on the current encrypted variable, querying a preset nonlinear permutation table to obtain a query result, and using the query result as the iterated current encrypted variable.

[0053] Efficient nonlinear perturbation is achieved by multiplying the current encrypted variable by a preset large prime number or by querying a preset nonlinear permutation table. These two mechanisms can be used independently or in combination, making the iterative update of the encrypted variable no longer a simple linear recursion, but effectively resisting professional cryptanalysis attacks based on linear relationships or differential features, achieving ideal security performance within the limited computing power of the embedded platform.

[0054] In some specific implementations, a SHA-256 hash operation is performed on the original program file to obtain a fixed-length signature data of 256 bits (32 bytes). By reading the timer value of the high-precision system, a SHA-256 operation is performed on that value, and the first 4 bytes of the result are used as the random number for this encryption. The encryptor and decryptor share a 32-byte user key beforehand. The 4-byte random number is extended to 32 bytes by padding with zeros at the high bits, and then a bitwise AND operation is performed with the 32-byte user key to obtain a 32-byte intermediate value. This intermediate value is then multiplied by a preset large prime number, and the lower 32 bytes of the product are used as the encryption seed. This encryption seed is set as the current encryption variable. By sequentially dividing the data to be encrypted (signature data or original program file) into multiple 32-byte data units, when the last data unit is less than 32 bytes long, its original length is retained without padding. For the current data unit to be encrypted, the encryption steps are as follows: The current encryption variable and the current data unit are bitwise NOTed to generate an encrypted data unit. The current encryption variable is multiplied by a preset large prime number, and the lower 32 bits of the product are used as the updated encryption variable to encrypt the next data unit. This encryption process is repeated until all data units have been processed. For the signature data, a 32-byte encrypted signature is obtained. For the original program file (data length L bytes), encrypted program data of length L bytes is obtained. The random number (Rand), the encryption signature (EncryptSignature), and the encrypted program data (EncryptData) are combined in a predefined order to generate the final encrypted output file. In a specific implementation, the first 4 bytes of the encrypted file are a random number, the following 32 bytes are the encryption signature, and the remaining part is all encrypted program data. The final output encrypted file will be used for network transmission or stored on physical media for subsequent burning to the ECU.

[0055] In some specific implementations, based on the current encrypted variable, a preset nonlinear permutation table is queried to obtain a query result, and the query result is used as the current encrypted variable after iteration, including: A 256-byte non-linear permutation table (S-Box) is pre-stored in the firmware of both the encryption and decryption ends. This table contains a non-linear random permutation of the value 0-255. When the current encrypted variable needs updating, the 32 bytes of the current encrypted variable are treated as 32 independent indices (one per byte). The non-linear permutation table is queried sequentially, and the lookup result replaces the original byte. After replacing all 32 bytes sequentially, the result is used as the updated current encrypted variable (New_Seed).

[0056] Accordingly, please refer to Figure 2 , Figure 2 This is a schematic diagram of an encryption system for firmware upgrade files provided in an embodiment of this application, such as... Figure 2 As shown, the system includes: a file acquisition module for acquiring the original program file to be encrypted; a signature generation module for generating signature data based on the original program file; an encryption seed generation module for generating a random number and generating an encryption seed based on the random number and a preset user key; an encryption transformation module for determining encryption variables based on the encryption seed and performing encryption transformations on the signature data and the original program file based on the encryption variables to obtain an encrypted signature and encrypted program data, wherein, during the encryption transformation process, the encryption variables are iteratively updated according to preset rules; and an encrypted file generation module for generating an encrypted file for firmware upgrade based on the random number, the encrypted signature, and the encrypted program data.

[0057] Accordingly, please refer to Figure 3 , Figure 3 The flowchart illustrates a method for decrypting firmware upgrade files provided in this application embodiment, used to decrypt encrypted files generated by the aforementioned encryption method, such as... Figure 3 As shown, the decryption method includes: extracting a random number, an encrypted signature, and encrypted program data from the encrypted file; generating a decryption seed based on the extracted random number and a user key identical to that of the encryptor; determining decryption variables based on the decryption seed, and performing decryption transformations on the encrypted signature and the encrypted program data based on the decryption variables to obtain signature data and the original program file, wherein, during the decryption transformation process, the decryption variables are iteratively updated according to the same preset rules as those of the encryptor; generating verification signature data based on the original program file; and determining that decryption is successful if the verification signature data matches the signature data obtained from the decryption transformation.

[0058] The decryption method provided in this application, as a strict inverse of the encryption method described above, can deterministically and precisely reconstruct the dynamic decryption state that is completely synchronized with the encryption process by reusing the same user key as the encryptor, the same random number extracted from the encrypted file, and the same iteration rules. This decryption process inherits the streaming processing architecture of the encryption method, processes data units one by one, and does not require a large buffer. This makes it possible to execute the complete decryption and verification process on a terminal microcontroller (MCU) with extremely limited resources, achieving a perfect match between security capabilities and terminal resource constraints.

[0059] Accordingly, please refer to Figure 4 , Figure 4 This application provides a schematic diagram of a firmware upgrade file decryption system, used to decrypt encrypted files generated by the aforementioned encryption method. Figure 4 As shown, the system includes: a data extraction module for extracting random numbers, encryption signatures, and encryption program data from the encrypted file; a decryption seed generation module for generating a decryption seed based on the extracted random numbers and a user key identical to that of the encryptor; a decryption transformation module for determining decryption variables based on the decryption seed and performing decryption transformations on the encryption signature and the encryption program data based on the decryption variables to obtain signature data and the original program file, wherein, during the decryption transformation process, the decryption variables are iteratively updated according to the same preset rules as those of the encryptor; a verification signature generation module for generating verification signature data based on the original program file; and a judgment module for determining successful decryption if the verification signature data matches the signature data obtained from the decryption transformation.

[0060] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.

[0061] In this embodiment, the encryption and decryption systems for firmware upgrade files are presented in the form of functional units. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.

[0062] Please see Figure 5 , Figure 5 This application provides a schematic diagram of the structure of a computer device, as shown in the embodiment of the present application. Figure 5As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 5 Take a processor 10 as an example.

[0063] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.

[0064] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.

[0065] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0066] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.

[0067] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.

[0068] This application also provides a computer-readable storage medium. The methods described in this application can be implemented in hardware or firmware, or implemented as recordable on a storage medium, or implemented as computer code downloaded over a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and subsequently stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the methods shown in the above embodiments are implemented.

[0069] This application provides a computer program product including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method of any embodiment of this application.

[0070] The systems and modules described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.

[0071] For ease of description, the above devices are described separately by function as various units. Of course, in implementing this application, the functions of each unit can be implemented in one or more software and / or hardware.

[0072] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0073] This application is described with reference to flowchart illustrations and / or block diagrams of methods, systems, and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0074] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0075] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0076] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0077] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on its differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0078] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

[0079] Although embodiments of this application have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of this application, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A method for encrypting firmware upgrade files, characterized in that, The encryption method includes: Obtain the original program file to be encrypted; Generate signature data based on the original program file; Generate random numbers; Logical operations are performed on the random number and the user key to obtain an intermediate value, wherein the logical operations include at least one of bitwise XOR, bitwise AND, addition, and multiplication. The intermediate value is subjected to a nonlinear transformation to generate an encryption seed; Based on the encryption seed, encryption variables are determined, and based on the encryption variables, at least one data unit obtained by dividing the signature data and at least one data unit obtained by dividing the original program file are encrypted to obtain an encrypted signature and encrypted program data. During the encryption transformation of different data units, the encryption variables are iteratively updated according to preset rules. Based on the random number, the cryptographic signature, and the cryptographic program data, an encrypted file for firmware upgrade is generated; The iteration of the current encrypted variable according to the preset rules includes at least one of the following methods: The current encrypted variable is multiplied by a preset second prime number to obtain a product, and the product is used as the current encrypted variable after iteration; Based on the current encrypted variable, a preset nonlinear permutation table is queried to obtain the query result, and the query result is used as the current encrypted variable after iteration.

2. The method according to claim 1, characterized in that, Performing a nonlinear transformation on the intermediate value includes multiplying the intermediate value by a preset first prime number.

3. The method according to claim 1, characterized in that, The random number is generated in the following manner: Get the current system time; The random number is generated based on the current system time.

4. The method according to claim 1, characterized in that, Based on the encryption seed, encryption variables are determined, and based on the encryption variables, the signature data and the original program file are respectively encrypted to obtain an encrypted signature and encrypted program data. During the encryption transformation process, the encryption variables are iteratively updated according to preset rules, including: Based on the encryption seed, determine the current encryption variable; For any current data unit to be encrypted in the signature data or the original program file, the current data unit is encrypted based on the current encryption variable to obtain an encrypted data unit, and the current encryption variable is iterated according to the preset rule. The encrypted signature is obtained based on each encrypted data unit of the signature data; The encrypted program data is obtained based on each encrypted data unit of the original program file.

5. The method according to claim 4, characterized in that, The encryption operation includes at least one of bitwise XOR operation and bitwise NOT operation.

6. An encryption system for firmware upgrade files, characterized in that, The system includes: The file acquisition module is used to acquire the original program file to be encrypted; A signature generation module is used to generate signature data based on the original program file; An encryption seed generation module is used to generate random numbers, perform logical operations on the random numbers and user keys to obtain intermediate values, wherein the logical operations include at least one of bitwise XOR, bitwise AND, addition, and multiplication; and perform a nonlinear transformation on the intermediate values ​​to generate an encryption seed. An encryption transformation module is used to determine encryption variables based on the encryption seed, and to perform encryption transformation on at least one data unit obtained by dividing the signature data and at least one data unit obtained by dividing the original program file based on the encryption variables, respectively, to obtain an encrypted signature and encrypted program data. In the process of performing the encryption transformation on different data units, the encryption variables are iteratively updated according to preset rules. An encrypted file generation module is used to generate an encrypted file for firmware upgrade based on the random number, the encryption signature, and the encryption program data. The iteration of the current encrypted variable according to the preset rules includes at least one of the following methods: The current encrypted variable is multiplied by a preset second prime number to obtain a product, and the product is used as the current encrypted variable after iteration; Based on the current encrypted variable, a preset nonlinear permutation table is queried to obtain the query result, and the query result is used as the current encrypted variable after iteration.

7. A method for decrypting firmware upgrade files, used to decrypt encrypted files generated by the encryption method as described in any one of claims 1-5, characterized in that, The decryption method includes: Extract the random number, encryption signature, and encryption program data from the encrypted file; Based on the extracted random number and the same user key as the encryptor, a decryption seed is generated; Based on the decryption seed, a decryption variable is determined, and based on the decryption variable, the encrypted signature and the encrypted program are decrypted and transformed to obtain signature data and the original program file. During the decryption transformation process, the decryption variable is iteratively updated according to the same preset rules as the encryptor. Generate verification signature data based on the original program file; If the verification signature data matches the signature data obtained from the decryption transformation, then the decryption is considered successful.

8. A firmware upgrade file decryption system, used to decrypt encrypted files generated by the encryption method as described in any one of claims 1-5, characterized in that, The system includes: The data extraction module is used to extract random numbers, encryption signatures, and encryption program data from the encrypted file; The decryption seed generation module is used to generate a decryption seed based on the extracted random number and the same user key as the encryptor; The decryption transformation module is used to determine decryption variables based on the decryption seed, and to perform decryption transformation on the encrypted signature and the encrypted program based on the decryption variables to obtain signature data and original program files. In the process of decryption transformation, the decryption variables are iteratively updated according to the same preset rules as the encryptor. The signature generation module is used to generate signature data based on the original program file. The determination module is used to determine that decryption is successful if the verification signature data matches the signature data obtained by decryption transformation.

Citation Information

Patent Citations

  • Firmware upgrading method and device, electronic equipment and storage medium

    CN112015455A

  • Key encryption method, key decryption method, data encryption method and data decryption method

    CN112953707A

  • Encryption method and device suitable for large file, computer equipment and storage medium

    CN120358101A