Embedded program encryption method and device

Through the embedded program encryption method designed by software, monitoring software is used to encrypt and decrypt in embedded products, which solves the problems of high hardware encryption cost and low efficiency in embedded product systems, and achieves effective protection and high-efficiency reliability of firmware. Portability.

CN118171308BActive Publication Date: 2024-09-03贵州航天控制技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410606242.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-16
Publication Date
2024-09-03
Estimated Expiration
2044-05-16

AI Technical Summary

Technical Problem

Hardware encryption in existing embedded product systems has the problems of high cost, low efficiency and poor portability. It cannot effectively protect firmware and is difficult to maintain and improve.

Method used

Embedded programs are encrypted using software design, monitoring software is used to encrypt and decrypt when loaded from FLASH and run, data is protected through the XOR encryption algorithm, hardware requirements are reduced, and portability and efficiency are improved.

Benefits of technology

It achieves effective protection of embedded firmware, reduces costs, improves operability and reliability, solves the problems of high cost and low efficiency of hardware encryption, and has the characteristics of small changes, fast cycle, high reliability and portability. Strong advantages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118171308B
    Figure CN118171308B
Patent Text Reader

Abstract

The present specification discloses an encryption method and device for an embedded program, and relates to the field of information encryption technology, including initializing internal registers and parameters and reading a key from FLASH; sending an inquiry instruction to a host computer to receive first sub-verification data and second sub-verification data of the host computer, and judging whether a data upload condition is met based on the first verification data; determining the type of target data based on the second sub-verification data and sending a corresponding communication instruction; responding to an erase instruction from the host computer, erasing a target address area of ​​FLASH and receiving target data; judging whether the target data needs to be encrypted based on the type of the target data; if so, encrypting the target data based on a key using an XOR encryption algorithm and writing it to a target address area of ​​FLASH; directly transmitting the target data written to the target address area of ​​FLASH back or transmitting it back to the host computer after decryption, so as to solve the problems of high cost, low efficiency and poor portability of hardware encryption in the current embedded product system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of information encryption, and in particular relates to an encryption method and device for an embedded program. Background Art

[0002] With the development of science and technology, various hardware / software products enrich people's lives, which are inseparable from embedded software products (hereinafter referred to as firmware). The important data such as personal data or software codes for development will be disastrous if the software is cracked or damaged. However, in the existing embedded software field, there is a lack of effective encryption protection measures for firmware.

[0003] In a certain type of embedded product, its digital processor is loaded with important embedded software and data. If the program and data are cracked or leaked, the product will be at risk of being copied, which will cause economic and security losses to the project and even the company. In order to effectively protect the firmware loaded in the processor, this encryption scheme has the characteristics of low cost, high reliability, novel ideas, strong portability, and wide application, which can protect embedded firmware.

[0004] Encryption and decryption have long been a contradiction. The current decryption methods can be roughly divided into four types: recovery encryption method, logic analysis method, simulation software tracking analysis method, and chip uncovering analysis method. For existing embedded firmware products, due to the high cost, difficulty, and long cycle of recovery encryption and chip uncovering methods, they can be cracked mainly through logic analysis and simulation software tracking analysis methods. These two methods can be easily implemented through the embedded product's data bus, address bus, and JTAG simulation interface with the help of oscilloscopes, logic analyzers, MDU decryption instruments and other analysis tools. Even if the firmware product has some encryption measures in hardware, it can be cracked by first obtaining the source code and then performing simulation analysis.

[0005] Existing embedded firmware protection solutions are generally implemented in hardware or software. Hardware implementation generally uses a dedicated digital signal processor (DSP) or field programmable logic device (FPGA) to implement the core encryption and decryption module, and uses the traditional DES encryption algorithm to use an external key to encrypt the firmware. These traditional encryption methods are complex and require high data processing efficiency. At the same time, they must have dedicated signal processing circuits and corresponding peripheral circuits to implement. For data encryption, the method of logical XOR with the key is generally used.

[0006] The above existing technologies must rely on dedicated digital signal processing circuits and corresponding clock circuits, storage circuits, control logic circuits and other auxiliary circuits, and the core components of these circuits, the data processing units, must have the characteristics of high computing efficiency, small size, low cost, and good confidentiality. These solutions have very high hardware requirements, and are difficult to implement, have a long cycle, and have poor portability. Even if they are considered before the product finalization stage, they often face major adjustments and changes to the product hardware solutions, which is not conducive to the miniaturization and integrated design of the product. The most critical thing is that they cannot effectively solve the effective protection of the firmware, nor are they conducive to the maintenance and improvement of the firmware.

[0007] Therefore, currently in embedded product systems, hardware encryption has the problems of high cost, low efficiency and poor portability. Summary of the invention

[0008] The purpose of the present invention is to provide an embedded program encryption method and device to solve the problems of high cost, low efficiency and poor portability in hardware encryption in embedded product systems.

[0009] To achieve the above object, the present invention adopts the following technical solution:

[0010] On the one hand, this specification provides an encryption method for an embedded program, comprising:

[0011] Step 102, initialize internal registers and parameters and read the key from FLASH;

[0012] Step 104, sending a query command to the host computer and receiving first verification data sent back by the host computer, and judging whether the data upload condition is met based on the first verification data;

[0013] Step 106, receiving second verification data sent by the host computer, determining the type of target data based on the second verification data and sending a communication instruction corresponding to the type of target data to the host computer, wherein the second verification data is sent by the host computer after the data upload condition is met;

[0014] Step 108, in response to the erase instruction sent by the host computer, erase the target address area of ​​the FLASH and receive the target data sent by the host computer, wherein the erase instruction is sent by the host computer in response to the communication instruction;

[0015] Step 110, based on the type of the target data, determine whether the target data needs to be encrypted; if so, encrypt the target data using an XOR encryption algorithm based on the key and write it into the target address area of ​​the FLASH;

[0016] Step 112, directly transmit the target data written into the target address area of ​​the FLASH back to the host computer or transmit it back after decryption.

[0017] On the other hand, the present specification provides an encryption device for an embedded program, comprising:

[0018] Initialization module, used to initialize internal registers and parameters and read keys from FLASH;

[0019] A first verification module, used to send a query command to the host computer and receive first verification data sent back by the host computer, and determine whether the data upload condition is met based on the first verification data;

[0020] A second verification module is used to receive second sub-verification data sent by the host computer, determine the type of target data based on the second sub-verification data, and send a communication instruction corresponding to the type of the target data to the host computer, wherein the second sub-verification data is sent by the host computer after the data upload condition is met;

[0021] A data erasing module, configured to respond to an erasing instruction sent by the host computer, erase the target address area of ​​the FLASH and receive target data sent by the host computer, wherein the erasing instruction is sent by the host computer in response to the communication instruction;

[0022] A data upload module, used to determine whether the target data needs to be encrypted based on the type of the target data; if so, encrypt the target data using an XOR encryption algorithm based on the key and write it into the target address area of ​​the FLASH;

[0023] The data transmission module is used to directly transmit the target data written into the target address area of ​​the FLASH back to the host computer or transmit it back after decryption.

[0024] Based on the above technical solution, this specification can achieve the following technical effects:

[0025] The method encrypts the embedded program and the key by means of software design, that is, when the embedded software is uploaded, the monitoring software has the function of encrypting the embedded software data, and when it is loaded and run from FLASH, the monitoring software has the function of decrypting the embedded software. The encryption and decryption are both performed by the encryption and decryption algorithms running in the monitoring software, and the embedded hardware platform is effectively utilized. The firmware is protected by software design, and the problem that the firmware of the existing embedded products is easy to be cracked is effectively solved. In addition, the method has the advantages of strong operability, small changes, low cost, fast cycle, high reliability, strong portability, wide application, etc., thereby solving the problems of high cost, low efficiency and poor portability in hardware encryption in the current embedded product system. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 The figure is a flow chart of an encryption method for an embedded program in one embodiment of the present invention.

[0027] Figure 2 FIG. 4 is a schematic diagram of the structure of FLASH in one embodiment of the present invention.

[0028] Figure 3 The figure is a schematic diagram of a process of generating a key in an embodiment of the present invention.

[0029] Figure 4 Schematic diagram of the structure of a key sector in one embodiment of the present invention.

[0030] Figure 5 The figure is a schematic diagram of the process of encrypting the flight control software in one embodiment of the present invention.

[0031] Figure 6 The figure is a schematic diagram of the process of decrypting the flight control software in one embodiment of the present invention.

[0032] Figure 7 The figure is a schematic diagram of the execution flow of monitoring software tasks in one embodiment of the present invention.

[0033] Figure 8 1 is a functional composition diagram of monitoring software in one embodiment of the present invention.

[0034] Fig. 9 The figure is a schematic diagram of the structure of an encryption device for an embedded program in one embodiment of the present invention.

[0035] Fig.10 The figure is a schematic diagram of an electronic device according to the present invention. DETAILED DESCRIPTION

[0036] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. The advantages and features of the present invention will become more apparent from the following description and claims. It should be noted that the drawings are all in very simplified form and are not in precise proportions, and are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention.

[0037] It should be noted that, in order to clearly explain the content of the present invention, the present invention specifically cites multiple embodiments to further illustrate different implementations of the present invention, wherein the multiple embodiments are enumerated rather than exhaustive. In addition, for the sake of brevity of explanation, the contents mentioned in the previous embodiments are often omitted in the subsequent embodiments. Therefore, the contents not mentioned in the subsequent embodiments can refer to the previous embodiments accordingly. Embodiment 1

[0038] Please refer to Figure 1 , Figure 1The following is a method for encrypting an embedded program provided by this embodiment. In this embodiment, the method includes:

[0039] Step 102, initialize internal registers and parameters and read the key from FLASH;

[0040] Step 104, sending a query command to the host computer and receiving first verification data sent back by the host computer, and judging whether the data upload condition is met based on the first verification data;

[0041] In this embodiment, the first verification data includes first sub-verification data and second sub-verification data;

[0042] In this embodiment, the first verification data returned by the receiving host computer includes:

[0043] After sending the query command, query the FIFO depth of the elastic ground port after a specified delay, where the elastic ground port refers to the data interface between the monitoring software and the host computer;

[0044] If the FIFO depth is the third expected value, it is determined that the first sub-check data returned by the host computer is received.

[0045] In this embodiment, the step of determining whether the data upload condition is met based on the first verification data includes:

[0046] Step 202, judging whether the monitoring software and the host computer have successfully established communication based on the first sub-verification data;

[0047] In this embodiment, one implementation of step 202 is:

[0048] Step 2022, determining the frame header data and the remaining data in the first sub-check data;

[0049] Step 2024: if the frame header data is the first expected value, superimpose the frame header data and the remaining data to obtain superimposed data;

[0050] Step 2026, determining whether the superimposed data is communication data, and if so, determining that communication is successfully established.

[0051] Step 204: If yes, determine whether the data upload condition is met based on the first sub-verification data and the second sub-verification data.

[0052] In this embodiment, one implementation of step 204 is:

[0053] Step 2042, determining whether the data of the specified byte in the first sub-check data is the second expected value, and if so, performing frame header determination on the second sub-check data sent by the host computer, the second sub-check data being sent by the host computer in response to a successful communication instruction from the monitoring software;

[0054] Step 2044: If the frame header is correct, it is determined that the data upload condition is met.

[0055] In this embodiment, if the frame header data is not the first expected value, or the superimposed data is non-communication data, or the data of the specified byte in the first sub-check data is not the second expected value, or the FIFO depth is not the third expected value, a jump flight control software instruction is sent to the host computer and the flight control software is jumped to execute.

[0056] Step 106, receiving second sub-verification data sent by the host computer, determining the type of target data based on the second sub-verification data and sending a communication instruction corresponding to the type of target data to the host computer, wherein the second sub-verification data is sent by the host computer after the data upload condition is met;

[0057] In this embodiment, the type of the target data is determined based on the instruction corresponding to the specified byte of the second verification data;

[0058] The communication instruction corresponding to the type of the target data sent to the host computer includes:

[0059] If the instruction corresponding to the specified byte is the first instruction, a jump measurement and control instruction is sent to the upper computer and the measurement and control software is executed;

[0060] If the instruction corresponding to the specified byte is the second instruction, an upload monitoring instruction is sent to the upper computer and the target data is determined to be monitoring software;

[0061] If the instruction corresponding to the designated byte is the third instruction, an upload measurement and control instruction is sent to the upper computer and the target data is determined to be the measurement and control software;

[0062] If the instruction corresponding to the specified byte is the fourth instruction, an upload flight control instruction is sent to the host computer and the target data is determined to be the flight control software;

[0063] If the instruction corresponding to the designated byte is the fifth instruction, an instruction to upload the first coefficient is sent to the host computer and the target data is determined to be the first coefficient;

[0064] If the instruction corresponding to the designated byte is the sixth instruction, an instruction to upload the second coefficient is sent to the upper computer and the target data is determined to be the second coefficient; the first coefficient and the second coefficient are inertial compensation coefficients related to flight control;

[0065] If the instruction corresponding to the designated byte is the seventh instruction, an upload key instruction is sent to the host computer and the target data is determined to be the key.

[0066] Step 108, in response to the erase instruction sent by the host computer, erase the target address area of ​​the FLASH and receive the target data sent by the host computer, wherein the erase instruction is sent by the host computer in response to the communication instruction;

[0067] Step 110, based on the type of the target data, determine whether the target data needs to be encrypted; if so, encrypt the target data using an XOR encryption algorithm based on the key and write it into the target address area of ​​the FLASH;

[0068] In this embodiment, the types that need to be encrypted include: measurement and control software and the flight control software;

[0069] refer to Figure 2 , the step of encrypting the target data based on the key using an XOR encryption algorithm and writing the target data into the target address area of ​​the FLASH comprises:

[0070] Using an XOR encryption algorithm to XOR every 16 bytes of the target data with the key to obtain encrypted target data;

[0071] If the target data is flight control software, the encrypted target data is written into the flight control sector of FLASH;

[0072] If the target data is measurement and control software, the encrypted target data will be flown into the measurement and control sector of FLASH;

[0073] The key is composed of an intermediate key and a pseudo key for encryption or decryption, and the intermediate key is obtained by encrypting the target product number by the host computer through the AES-128 algorithm.

[0074] In this embodiment, the types that do not need to be encrypted include: monitoring software, the first coefficient, the second coefficient, and the key;

[0075] The method also includes:

[0076] If the target data is monitoring software, the target data is written into the monitoring sector of FLASH;

[0077] If the target data is the first coefficient and the second coefficient, the target data is written into the coefficient sector of the FLASH;

[0078] If the target data is a key, the target data is written into the key sector of the FLASH.

[0079] Step 112, directly transmit the target data written into the target address area of ​​the FLASH back to the host computer or transmit it back after decryption.

[0080] Specifically, refer to Figure 3 , which is a flowchart of key generation. Figure 4 A schematic diagram of the structure of the key sector.

[0081] Based on this, reference Figure 3 In this method, the product number is encrypted for the first time by the upper computer software through the AES-128 algorithm, that is, the original product number is overwritten to obtain a new product number; then an encryption and decryption intermediate key (secondary encryption) is generated according to the new product number, and finally it is packaged with the pseudo key and uploaded to FLASH. Therefore, this method can make the key, pseudo key, and encrypted program of each set of products inconsistent after the key is encrypted twice, thereby improving the security of the product.

[0082] refer to Figure 5 , Figure 6 Schematic diagram of the encryption and decryption process of the flight control software.

[0083] refer to Figure 7 This is a diagram of the monitoring software task execution process.

[0084] The specific steps are as follows:

[0085] S1. After the monitoring software enters the data upload process, it initializes the internal registers and parameters, clears the receiving FIFO address, and the FK switch is low level. Then the monitoring software reads the key from the key sector of FLASH.

[0086] S2, the monitoring software sends a query command (0x aa 55 01 dd) to the host computer, and after a delay of 30ms, queries the depth of the FIFO of the bounce interface (the data interface between the monitoring software and the host computer), and determines whether the depth of the FIFO is 24 (the third expected value) at this time ("24" indicates that the FIFO has received 24 bytes of data (the first sub-check data) at this time, and this 24 bytes of data is the communication data used to indicate the successful establishment of communication in the communication protocol previously agreed upon by the monitoring software and the host computer); if not, execute S21; if yes, execute S22;

[0087] S21, send the jump flight control software command (0x52) to the host computer (external device) and jump to execute the flight control software;

[0088] S22, take 2 bytes of frame header data and determine whether the frame header data is 0x dd dd (first expected value); if the frame header is incorrect, execute S21; if the frame header is correct, execute S3;

[0089] S3, superimpose the 2-byte frame header and the remaining 22-byte data and check whether the content of the superimposed 24-byte data is communication data, if not, execute S21; if yes, execute S4;

[0090] S4, send a communication success command (0x50) to the host computer and determine whether the values ​​of bit5 and bit4 of the 20th byte are 10 (the second expected value). If not, execute S21; if yes, execute S5;

[0091] S5, the monitoring software enters the upload judgment process, the monitoring software receives the second 24-byte data (the second sub-check data) sent by the host computer and performs frame header judgment again. If the frame header is correct, the data type of the 20th byte of the second 24-byte data is analyzed;

[0092] S51, if the data type of the 20th byte of the second 24-byte data is 0x01 (the first instruction), the monitoring software sends a jump measurement and control instruction (0x51) to the host computer and jumps to execute the measurement and control software;

[0093] S52, if the data type of the 20th byte of the second 24-byte data is 0x02 (second instruction), the monitoring software sends an upload monitoring instruction (0x53) to the host computer and enters the upload monitoring software process (upload monitoring cannot be XOR encrypted);

[0094] S53, if the data type of the 20th byte of the second 24-byte data is 0x03 (the third instruction), the monitoring software sends the upload measurement and control instruction (0x54) to the host computer and enters the upload measurement and control software process (upload measurement and control needs to be XOR encrypted);

[0095] S54, if the data type of the 20th byte of the second 24-byte data is 0x04 (the fourth instruction), the monitoring software sends the upload flight control instruction (0x55) to the host computer and enters the upload flight control software process (uploading flight control needs to be XOR encrypted);

[0096] S55, if the data type of the 20th byte of the second 24-byte data is 0x05 (the fifth instruction), the monitoring software sends the first coefficient upload instruction (0x56) to the host computer and enters the coefficient upload process (the uploaded coefficient does not need to be XOR encrypted);

[0097] S56. If the data type of the 20th byte of the second 24-byte data is 0x06 (the sixth instruction), the monitoring software sends an upload second coefficient instruction (0x57) to the host computer and enters the coefficient upload process (the uploaded coefficient does not need to be XOR encrypted);

[0098] S57, if the data type of the 20th byte of the second 24-byte data is 0x07 (the seventh instruction), the monitoring software sends an upload key instruction (0x58) to the host computer and enters the key upload process (the upload key does not need to be XOR encrypted);

[0099] S6, the monitoring software determines whether the first target instruction sent by the host computer is 4 bytes. If so, it continues to determine whether the first target instruction is the start upload instruction (0x aa 55 01 dd). If not, it re-receives the first target instruction; if so, it sends the start upload instruction received instruction (0x60) to the host computer and erases the corresponding FLASH address area;

[0100] S7, the monitoring software determines whether the erasure is completed. If it is completed, it sends an erase completion command (0x61) to the host computer; if not, it erases again;

[0101] S8, the monitoring software determines whether the second target instruction sent by the host computer is 4 bytes. If so, it continues to determine whether the second target instruction is a continue upload instruction (0x aa 55 02 dd). If so, it executes S81; if not, it executes S82;

[0102] S81, send the received continue upload instruction (0x62) to the host computer and execute S9;

[0103] S82, determine whether the second target instruction is an upload completion instruction (0x aa 55 03 dd), if so, send a data upload completion instruction (0x63) to the host computer and end the upload; if not, continue to determine whether the second target instruction is an upload failure instruction (0x aa 55 04 dd); if so, send a data upload failure instruction (0x64) to the host computer and end the upload, if not, execute S81;

[0104] S9, the monitoring software determines whether the target data received from the host computer is 131 bytes (131 bytes is the length of the target data agreed by the protocol). If so, it continues to determine whether the 2-byte frame header of the target data is correct. If so, it executes S10; if not, it receives the target data again;

[0105] S10, when the monitoring software uploads monitoring, first coefficient, second coefficient, and key, the data is directly written into the target address area of ​​FLASH; when uploading measurement and control and flight control, the data is XOR encrypted and written into the target address area of ​​FLASH;

[0106] S11. When the monitoring software downloads the monitoring, first coefficient, second coefficient, and key, the data is directly read from the target address area of ​​FLASH and sent to the host computer through the ground port for verification; when the measurement and control and flight control are downloaded, the data is read from the target address area of ​​FLASH, XOR decrypted, and sent to the host computer through the ground port for verification; after the host computer verifies the received data, it issues a continue upload instruction (0x aa 55 02 dd, indicating that the currently uploaded data is correct but not all uploaded), a complete upload instruction (0x aa 55 03 dd, indicating that the currently uploaded data is all correct), and an upload failure instruction (0xaa 55 04 dd, indicating that the currently uploaded data is inconsistent with the original data sent by the host computer, the chip is faulty, and the upload needs to be stopped immediately)

[0107] S12, the address is accumulated to 128, and a data upload is completed.

[0108] refer to Figure 8 , which is the functional composition diagram of the monitoring software.

[0109] In summary, the method encrypts the embedded program and the key through software design implementation, that is, when the embedded software is uploaded, the monitoring software has the function of encrypting the embedded software data, and when it is loaded and run from FLASH, the monitoring software has the function of decrypting the embedded software. The encryption and decryption are performed by the encryption and decryption algorithms running in the monitoring software. The embedded hardware platform is effectively utilized, and the firmware is protected by software design. The problem that the firmware of existing embedded products is easy to be cracked is effectively solved. Moreover, the implementation of the method has the advantages of strong operability, small changes, low cost, fast cycle, high reliability, strong portability, and wide application, thereby solving the problems of high cost, low efficiency and poor portability of hardware encryption in the current embedded product system. Embodiment 2

[0110] Please refer to Fig. 9 , Fig. 9 The figure shows an embedded program encryption device provided by this embodiment. In this embodiment, the device includes:

[0111] Initialization module, used to initialize internal registers and parameters and read keys from FLASH;

[0112] A first verification module, used to send a query command to the host computer and receive first verification data sent back by the host computer, and determine whether the data upload condition is met based on the first verification data;

[0113] A second verification module is used to receive second sub-verification data sent by the host computer, determine the type of target data based on the second sub-verification data, and send a communication instruction corresponding to the type of the target data to the host computer, wherein the second sub-verification data is sent by the host computer after the data upload condition is met;

[0114] A data erasing module, configured to respond to an erasing instruction sent by the host computer, erase the target address area of ​​the FLASH and receive target data sent by the host computer, wherein the erasing instruction is sent by the host computer in response to the communication instruction;

[0115] A data upload module, used to determine whether the target data needs to be encrypted based on the type of the target data; if so, encrypt the target data using an XOR encryption algorithm based on the key and write it into the target address area of ​​the FLASH;

[0116] The data transmission module is used to directly transmit the target data written into the target address area of ​​the FLASH back to the host computer or transmit it back after decryption.

[0117] Optionally, the first verification data includes first sub-verification data and second sub-verification data;

[0118] Optionally, the first verification module includes:

[0119] A communication establishment submodule, used for judging whether the monitoring software and the host computer have successfully established communication based on the first sub-verification data;

[0120] The upload judgment submodule is used to judge whether the data upload condition is met based on the first sub-verification data and the second sub-verification data.

[0121] Optionally, the communication establishment submodule includes:

[0122] A first sub-check data acquisition unit, used to determine the frame header data and the remaining data in the first sub-check data;

[0123] a first frame header data determining unit, configured to superimpose the frame header data and the remaining data to obtain superimposed data if the frame header data is a first expected value;

[0124] The communication establishment judgment unit is used to judge whether the superimposed data is communication data, and if so, determine that the communication is successfully established.

[0125] Optionally, the upload judgment submodule includes:

[0126] A first byte determination unit is used to determine whether the data of a specified byte in the first sub-check data is a second expected value, and if so, to perform a frame header determination on the second sub-check data sent by the host computer, the second sub-check data being sent by the host computer in response to a successful communication instruction from the monitoring software;

[0127] The upload determination unit is used to determine that the data upload condition is met if the frame header is correct.

[0128] Optionally, the first verification module includes:

[0129] The interface data query submodule is used to query the FIFO depth of the elastic ground port after a specified delay after sending the query instruction. The elastic ground port refers to the data interface between the monitoring software and the host computer;

[0130] The FIFO depth judgment submodule is used to determine that the first sub-check data returned by the host computer is received if the FIFO depth is a third expected value.

[0131] Optionally, if the frame header data is not the first expected value, or the superimposed data is non-communication data, or the data of the specified byte in the first sub-check data is not the second expected value, or the FIFO depth is not the third expected value, a jump flight control software instruction is sent to the host computer and the flight control software is jumped to execute.

[0132] Optionally, the type of the target data is determined based on an instruction corresponding to a specified byte of the second verification data;

[0133] The communication instruction corresponding to the type of the target data sent to the host computer includes:

[0134] If the instruction corresponding to the specified byte is the first instruction, a jump measurement and control instruction is sent to the upper computer and the measurement and control software is executed;

[0135] If the instruction corresponding to the specified byte is the second instruction, an upload monitoring instruction is sent to the upper computer and the target data is determined to be monitoring software;

[0136] If the instruction corresponding to the designated byte is the third instruction, an upload measurement and control instruction is sent to the upper computer and the target data is determined to be the measurement and control software;

[0137] If the instruction corresponding to the specified byte is the fourth instruction, an upload flight control instruction is sent to the host computer and the target data is determined to be the flight control software;

[0138] If the instruction corresponding to the designated byte is the fifth instruction, an instruction to upload the first coefficient is sent to the host computer and the target data is determined to be the first coefficient;

[0139] If the instruction corresponding to the designated byte is the sixth instruction, an instruction to upload the second coefficient is sent to the upper computer and the target data is determined to be the second coefficient; the first coefficient and the second coefficient are inertial compensation coefficients related to flight control;

[0140] If the instruction corresponding to the designated byte is the seventh instruction, an upload key instruction is sent to the host computer and the target data is determined to be the key.

[0141] Optionally, the types that need to be encrypted include: measurement and control software and the flight control software;

[0142] The method of encrypting the target data by using an XOR encryption algorithm based on the key and writing the target data into the target address area of ​​the FLASH comprises:

[0143] Using an XOR encryption algorithm to XOR every 16 bytes of the target data with the key to obtain encrypted target data;

[0144] If the target data is flight control software, the encrypted target data is written into the flight control sector of FLASH;

[0145] If the target data is measurement and control software, the encrypted target data will be flown into the measurement and control sector of FLASH;

[0146] The key is composed of an intermediate key and a pseudo key for encryption or decryption, and the intermediate key is obtained by encrypting the target product number by the host computer through the AES-128 algorithm.

[0147] Optionally, the types that need to be encrypted include: monitoring software, the first coefficient, the second coefficient, and the key;

[0148] Also includes:

[0149] If the target data is monitoring software, the target data is written into the monitoring sector of FLASH;

[0150] If the target data is the first coefficient and the second coefficient, the target data is written into the coefficient sector of the FLASH;

[0151] If the target data is a key, the target data is written into the key sector of the FLASH.

[0152] Based on this, the device encrypts the embedded program and the key through the software design implementation, that is, when the embedded software is uploaded, the monitoring software has the function of encrypting the embedded software data, and when it is loaded and run from FLASH, the monitoring software has the function of decrypting the embedded software. The encryption and decryption are performed by the encryption and decryption algorithms running in the monitoring software, which effectively utilizes the embedded hardware platform and adopts the software design method to realize the protection of the firmware, effectively solving the problem that the firmware of the existing embedded products is easy to be cracked. Moreover, the implementation of this method has the advantages of strong operability, small changes, low cost, fast cycle, high reliability, strong portability and wide application, thereby solving the problems of high cost, low efficiency and poor portability of hardware encryption in the current embedded product system. Embodiment 3

[0153] Please refer to Fig.10 , this embodiment provides an electronic device, which includes a processor, an internal bus, a network interface, a memory and a non-volatile memory, and of course may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming an encryption method for embedded programs at the logical level. Of course, in addition to software implementation methods, this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0154] The network interface, processor and memory can be connected to each other through a bus system. The above bus can be divided into an address bus, a data bus, a control bus, etc.

[0155] The memory is used to store programs. Specifically, the program may include program code, and the program code includes computer operation instructions. The memory may include a read-only memory and a random access memory, and provides instructions and data to the processor.

[0156] The processor is used to execute the program stored in the above memory, and specifically perform:

[0157] Step 102, initialize internal registers and parameters and read the key from FLASH;

[0158] Step 104, sending a query command to the host computer and receiving first verification data sent back by the host computer, and judging whether the data upload condition is met based on the first verification data;

[0159] Step 106, receiving second sub-verification data sent by the host computer, determining the type of target data based on the second sub-verification data and sending a communication instruction corresponding to the type of target data to the host computer, wherein the second sub-verification data is sent by the host computer after the data upload condition is met;

[0160] Step 108, in response to the erase instruction sent by the host computer, erase the target address area of ​​the FLASH and receive the target data sent by the host computer, wherein the erase instruction is sent by the host computer in response to the communication instruction;

[0161] Step 110, based on the type of the target data, determine whether the target data needs to be encrypted; if so, encrypt the target data using an XOR encryption algorithm based on the key and write it into the target address area of ​​the FLASH;

[0162] Step 112, directly transmit the target data written into the target address area of ​​the FLASH back to the host computer or transmit it back after decryption.

[0163] The processor may be an integrated circuit chip with signal processing capability. In the implementation process, each step of the above method may be completed by an integrated logic circuit of the processor hardware or by instructions in the form of software.

[0164] Based on the same invention, the embodiment of this specification also provides a computer-readable storage medium, which stores one or more programs. When the one or more programs are executed by an electronic device including multiple application programs, the electronic device executes Figure 1-Figure 8 A corresponding embodiment provides an encryption method for an embedded program.

[0165] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-readable storage media containing computer-usable program code.

[0166] In addition, for the above-mentioned specific implementation of the system, since it is basically similar to the method implementation, the description is relatively simple, and the relevant parts can be referred to the partial description of the method implementation. Moreover, it should be noted that in each module of the system of the present application, the components therein are logically divided according to the functions to be implemented, but the present application is not limited thereto, and the components can be re-divided or combined as needed.

[0167] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences between it and other embodiments.

[0168] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the specific order or sequential order shown in the process depicted in the drawings is not necessarily required to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0169] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims

1. An encryption method for an embedded program, characterized in that: include: Initialize internal registers and parameters and read the key from FLASH; Sending a query command to the host computer and receiving first verification data sent back by the host computer, and judging whether the data uploading condition is met based on the first verification data; The first verification data includes first sub-verification data and second sub-verification data; The determining whether the data upload condition is met based on the first verification data includes: Determine whether the monitoring software and the host computer have successfully established communication based on the first sub-verification data; If yes, determining whether the data upload condition is met based on the first sub-verification data and the second sub-verification data; The determining whether the monitoring software and the host computer have successfully established communication based on the first sub-verification data includes: Determine the frame header data and the remaining data in the first sub-check data; If the frame header data is a first expected value, superimposing the frame header data and the remaining data to obtain superimposed data; Determining whether the superimposed data is communication data, and if so, determining that communication is successfully established; The determining whether the data upload condition is met based on the first sub-verification data and the second sub-verification data includes: Determine whether the data of the specified byte in the first sub-check data is a second expected value, and if so, perform frame header judgment on the second sub-check data sent by the host computer, where the second sub-check data is sent by the host computer in response to a successful communication instruction from the monitoring software; If the frame header is correct, it is determined that the data upload conditions are met; receiving second sub-verification data sent by the host computer, determining the type of target data based on the second sub-verification data and sending a communication instruction corresponding to the type of target data to the host computer, wherein the second sub-verification data is sent by the host computer after the data upload condition is met; In response to the erase instruction sent by the host computer, erase the target address area of ​​the FLASH and receive the target data sent by the host computer, wherein the erase instruction is sent by the host computer in response to the communication instruction; Based on the type of the target data, determine whether the target data needs to be encrypted; if so, encrypt the target data using an XOR encryption algorithm based on the key and write it into the target address area of ​​the FLASH; The target data written into the target address area of ​​the FLASH is directly transmitted back or decrypted and then transmitted back to the host computer.

2. The method according to claim 1, characterized in that: The first verification data returned by the receiving host computer includes: After sending the query command, query the FIFO depth of the elastic ground port after a specified delay, where the elastic ground port refers to the data interface between the monitoring software and the host computer; If the FIFO depth is the third expected value, it is determined that the first sub-check data returned by the host computer is received.

3. The method according to claim 2, characterized in that If the frame header data is not the first expected value, or the superimposed data is non-communication data, or the data of the specified byte in the first sub-check data is not the second expected value, or the FIFO depth is not the third expected value, then a jump flight control software instruction is sent to the host computer and the flight control software is jumped to execute.

4. The method according to claim 3, characterized in that The type of the target data is determined based on the instruction corresponding to the specified byte of the second sub-check data; The communication instruction corresponding to the type of the target data sent to the host computer includes: If the instruction corresponding to the designated byte is the first instruction, a jump measurement and control instruction is sent to the upper computer and the measurement and control software is executed; If the instruction corresponding to the designated byte is the second instruction, an upload monitoring instruction is sent to the upper computer and the target data is determined to be monitoring software; If the instruction corresponding to the designated byte is the third instruction, an upload measurement and control instruction is sent to the upper computer and the target data is determined to be measurement and control software; If the instruction corresponding to the specified byte is the fourth instruction, an upload flight control instruction is sent to the host computer and the target data is determined to be the flight control software; If the instruction corresponding to the designated byte is the fifth instruction, an instruction to upload the first coefficient is sent to the host computer and the target data is determined to be the first coefficient; If the instruction corresponding to the designated byte is the sixth instruction, an instruction to upload the second coefficient is sent to the upper computer and the target data is determined to be the second coefficient; the first coefficient and the second coefficient are inertial compensation coefficients related to flight control; If the instruction corresponding to the designated byte is the seventh instruction, an upload key instruction is sent to the host computer and the target data is determined to be the key.

5. The method according to claim 4, characterized in that The types that need to be encrypted include: measurement and control software and the flight control software; The method of encrypting the target data by using an XOR encryption algorithm based on the key and writing the target data into the target address area of ​​the FLASH comprises: Using an XOR encryption algorithm to XOR every 16 bytes of the target data with the key to obtain encrypted target data; If the target data is flight control software, the encrypted target data is written into the flight control sector of FLASH; If the target data is measurement and control software, the encrypted target data will be flown into the measurement and control sector of FLASH; The key is composed of an intermediate key and a pseudo key for encryption or decryption, and the intermediate key is obtained by encrypting the target product number by the host computer through the AES-128 algorithm.

6. The method according to claim 4, characterized in that The types that do not require encryption include: monitoring software, the first coefficient, the second coefficient, and the key; The method also includes: If the target data is monitoring software, the target data is written into the monitoring sector of FLASH; If the target data is the first coefficient and the second coefficient, the target data is written into the coefficient sector of the FLASH; If the target data is a key, the target data is written into the key sector of the FLASH.

7. An encryption device for an embedded program, characterized in that: include: Initialization module, used to initialize internal registers and parameters and read keys from FLASH; A first verification module, used to send a query command to the host computer and receive first verification data sent back by the host computer, and determine whether the data upload condition is met based on the first verification data; The first verification data includes first sub-verification data and second sub-verification data; The first verification module includes: A communication establishment submodule, used to determine whether the monitoring software and the host computer have successfully established communication based on the first sub-verification data; an upload judgment submodule, configured to judge whether a data upload condition is met based on the first sub-verification data and the second sub-verification data if yes; The communication establishment submodule includes: A first sub-check data acquisition unit, used to determine the frame header data and the remaining data in the first sub-check data; a first frame header data determining unit, configured to superimpose the frame header data and the remaining data to obtain superimposed data if the frame header data is a first expected value; a communication establishment determination unit, configured to determine whether the superimposed data is communication data, and if so, determine that the communication is successfully established; The upload judgment submodule includes: A first byte determination unit is used to determine whether the data of a specified byte in the first sub-check data is a second expected value, and if so, to perform a frame header determination on the second sub-check data sent by the host computer, the second sub-check data being sent by the host computer in response to a successful communication instruction from the monitoring software; An upload determination unit is used to determine that the data upload condition is met if the frame header is correct; A second verification module is used to receive second sub-verification data sent by the host computer, determine the type of target data based on the second sub-verification data, and send a communication instruction corresponding to the type of the target data to the host computer, wherein the second sub-verification data is sent by the host computer after the data upload condition is met; A data erasing module, configured to respond to an erasing instruction sent by the host computer, erase the target address area of ​​the FLASH and receive target data sent by the host computer, wherein the erasing instruction is sent by the host computer in response to the communication instruction; A data upload module, used to determine whether the target data needs to be encrypted based on the type of the target data; if so, encrypt the target data using an XOR encryption algorithm based on the key and write it into the target address area of ​​the FLASH; The data transmission module is used to directly transmit the target data written into the target address area of ​​the FLASH back to the host computer or transmit it back after decryption.