Anti-copy system and anti-copy method

By performing multiple verifications on the SN code of the microcontroller, the data legality and integrity are ensured, and the problem of insufficient copy protection in the existing technology is solved, and efficient data and system security is achieved.

CN118916048BActive Publication Date: 2024-12-27深圳市云希谷科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411414155.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2024-12-27
Estimated Expiration
2044-10-11

AI Technical Summary

Technical Problem

The prior art has risks in terms of copy protection, and fails to effectively prevent unauthorized copying of microcontroller programs, especially when cracking methods are popularized, resulting in system security impairment.

Method used

By obtaining the SN code of the burning program and microcontroller, multiple verifications are performed to ensure the legality and integrity of the data, including the first verification, the second verification and the third verification. If the verification is wrong, it will enter the safe mode , prevent unauthorized access.

Benefits of technology

It realizes efficient data security and system reliability, prevents unauthorized copying and tampering, and enters security mode in a timely manner to prevent potential security risks, improving the protection effect of data and system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916048B_ABST
    Figure CN118916048B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of single-chip microcomputer technology, and discloses an anti-copy system and an anti-copy method, the method comprising obtaining the SN code of the burning program and the SN code of the burned single-chip microcomputer, performing a first check, and obtaining a first check result; when the first check result is that the check is correct, the burning program writes data into the FLASH of the burned single-chip microcomputer for a second check and data preservation and backup, and obtains a second check result; if the second check result is that the check is correct, the copy is successful, otherwise it enters a safe mode; according to a preset time, a third check is performed on the data that has been successfully copied in the burned single-chip microcomputer, and a third check result is obtained; if the third check result is that the check is correct, the control program runs normally, and if an error occurs, the safe mode is entered. The anti-copy scheme provided by the present invention greatly improves the security of data and the reliability of the system, and realizes effective anti-copy protection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of single chip computers, and in particular to an anti-copying system and an anti-copying method. Background Art

[0002] At present, single-chip microcomputers are common core processor chips in embedded systems and are widely used in various fields of life and production. With the popularization of Internet technology, single-chip microcomputers can be remotely controlled through the Internet, automatically collect data and send the collected data to the host computer for data processing. In industrial production, by deploying a single-chip microcomputer network, the production process can be greatly simplified and production management can be facilitated. However, while providing great convenience to users, single-chip microcomputer programs can also be copied to other single-chip microcomputers by unauthorized personnel through the network, causing losses to the original factory.

[0003] In one prior art, a dedicated MCU burner with an integrated authorization module is used. This burner establishes an authentication connection with the MCU in a specific manner, and interacts with the MCU through an external encryption chip to authorize the internal program of the MCU to ensure that the program can run normally after obtaining a legal identity.

[0004] Existing technologies require additional hardware intervention, which has high risks when known cracking methods, resulting in the inability to provide effective copy protection. Summary of the invention

[0005] The present invention provides an anti-copying method, system, electronic equipment and storage medium to achieve effective anti-copying protection.

[0006] In a first aspect, in order to solve the above technical problem, the present invention provides an anti-copying method, comprising:

[0007] Get the SN code of the burning program and the SN code of the MCU being burned;

[0008] Perform a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result;

[0009] When the first verification result is that the verification is correct, the burning program writes the data into the FLASH of the burned single-chip computer according to the communication protocol;

[0010] Performing a second check on the data written in the FLASH and saving and backing up the data to obtain a second check result;

[0011] If the second verification result is correct, the copy is successful; if the verification is wrong, the safe mode is entered;

[0012] According to the preset time, a third verification is performed on the data that has been successfully copied in the burned single-chip computer to obtain a third verification result;

[0013] If the third verification result is a verification success, the control program runs normally; if the third verification result is a verification error, the control program enters a safe mode.

[0014] In an optional implementation manner, the step of obtaining the SN code of the burning program and the SN code of the burned single-chip computer includes:

[0015] Obtaining a unique identifier of an internal register of the burned single-chip computer;

[0016] Wherein, the unique identifier is generated during the production process of the burned single-chip microcomputer;

[0017] According to the unique identifier, a calculation transformation is performed to obtain a unique feature of the burned single chip microcomputer;

[0018] According to the unique characteristics of the burned single-chip microcomputer and the device information, a calculation transformation is performed to obtain the SN code of the burned single-chip microcomputer;

[0019] The SN code is saved in the burning program and the burned single-chip computer respectively, and the SN code of the burning program and the SN code of the burned single-chip computer are obtained.

[0020] In an optional implementation, performing calculation and transformation according to the unique identifier to obtain the unique feature of the burned single-chip computer includes:

[0021] The computational transformation is performed by hash mapping through a SHA-256 hash function;

[0022] According to the unique identifier, padding is performed by adding 1 and 0 at the end of the message to obtain a first padding message;

[0023] Wherein, the length of the first padding message is an integer multiple of 448 bits;

[0024] Adding a 64-bit representation at the end of the first padding message to obtain a second padding message;

[0025] Initialize a vector of eight 32-bit registers;

[0026] Splitting the second padding message into a plurality of 512-bit data blocks, and performing 64 loop iterations on each of the 512-bit data blocks;

[0027] Wherein, the loop iteration includes using logic functions and circular shift operations;

[0028] Updating the value of the register to obtain a final register value;

[0029] According to the final register value, a splicing operation is performed to obtain the unique feature of the burned single chip computer;

[0030] The unique feature of the burned single chip microcomputer is a 256-bit hash value.

[0031] In an optional implementation manner, the calculation and transformation are performed according to the unique characteristics of the burned single-chip computer and the device information to obtain the SN code of the burned single-chip computer, including:

[0032] The device information includes device serial number, production batch, device version, device ID, device serial number, software verification code, communication protocol version, and random seed;

[0033] According to the unique characteristics of the burned single chip computer and the device information, they are combined in order to obtain a combined string;

[0034] According to the combined character string, hash mapping is performed through the SHA-256 hash function to obtain the SN code of the burned single-chip microcomputer.

[0035] In an optional implementation, performing a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result includes:

[0036] Check whether the burned single-chip microcomputer includes an SN state machine, if so, compare the SN code of the burning program with the SN code of the burned single-chip microcomputer for consistency to obtain a first verification result; if not, determine that it is a verification error;

[0037] The SN state machine is a state machine for storing and verifying the SN code.

[0038] In an optional implementation manner, performing a second check on the data written in the FLASH and saving and backing up the data to obtain a second check result includes:

[0039] The written data includes the firmware code of the burned single-chip microcomputer, and the written data is divided into a plurality of data packets;

[0040] Get the packet number and first address of each data packet;

[0041] Perform a saving operation according to the first address of the data packet to obtain backup data of the data packet;

[0042] Writing the data packets into the FLASH according to the sequence of the packet numbers, performing a second check on the data packets, and obtaining a check result of the data packets;

[0043] When the verification result is a verification error, using the first address of the backup data to restore the last correctly written data packet;

[0044] When the verification result is that the verification is correct, repeating the step of dividing the written data into a plurality of data packets, wherein the written data includes the firmware code of the burned single-chip microcomputer, until all the data packets are successfully written and verified;

[0045] The second verification result includes the verification result of each data packet.

[0046] In an optional implementation, performing a second check on the data packet to obtain a check result of the data packet includes:

[0047] Calculating the content of the data packet according to a cyclic redundancy check algorithm to obtain a first check value of the data packet;

[0048] The first verification value is compared with a preset verification value for consistency to obtain a verification result of the data packet.

[0049] In an optional implementation manner, performing a third verification on the data that has been successfully copied in the burned single-chip computer according to the preset time to obtain a third verification result includes:

[0050] After the preset time, reading the written data from the FLASH of the burned single chip microcomputer;

[0051] Wherein, the written data includes a plurality of data packets;

[0052] Calculating the content of each data packet according to a cyclic redundancy check algorithm to obtain a second check value for each data packet;

[0053] Compare the second verification value with the first verification value to obtain a comparison result;

[0054] Determine whether the comparison results are consistent, if yes, the verification is correct; if no, the verification is wrong;

[0055] The third verification result includes the comparison result of each data packet.

[0056] In a second aspect, the present invention provides an anti-copy system, comprising:

[0057] SN code acquisition module, used to obtain the SN code of the burning program and the SN code of the burned microcontroller;

[0058] A first verification module, used for performing a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result;

[0059] FLASH write module, for when the first verification result is verified to be correct, the burning program writes the data to the burned microcontroller FLASH according to the communication protocol;

[0060] A data storage and backup module is used to perform segmented backup and storage of the data written in the FLASH;

[0061] A second verification module is used to perform a second verification on the data written in the FLASH to obtain a second verification result; if the second verification result is that the verification is correct, the copy is successful, and if the verification is wrong, the safe mode is entered;

[0062] The third verification module is used to perform a third verification on the data that has been successfully copied in the burned single-chip computer according to a preset time to obtain a third verification result; if the third verification result is a verification correct, the control program runs normally; if the third verification result is a verification error, the control program enters a safe mode.

[0063] In a third aspect, the present invention further provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements any one of the above-mentioned anti-copying methods when executing the computer program.

[0064] In a fourth aspect, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned anti-copying methods.

[0065] Compared with the prior art, the present invention has the following beneficial effects:

[0066] The present invention provides an anti-copying method, comprising obtaining an SN code of a burning program and an SN code of a burned single-chip computer; performing a first check according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first check result; when the first check result is that the check is correct, the burning program writes data into the FLASH of the burned single-chip computer according to a communication protocol; performing a second check on the data written in the FLASH and saving and backing up the data to obtain a second check result; if the second check result is that the check is correct, the copying is successful, and if the check is wrong, a safe mode is entered; according to a preset time, performing a third check on the data that has been successfully copied in the burned single-chip computer to obtain a third check result; if the third check result is that the check is correct, the control program runs normally, and if the third check result is that the check is wrong, the control program enters the safe mode.

[0067] In the present invention, the SN code acquisition module is first used to collect the SN codes of the burning program and the burned single-chip microcomputer in real time. Then, the first verification module matches and verifies the two SN codes to ensure the legitimacy of the burning program and the single-chip microcomputer. If the verification passes, the FLASH writing module will safely write the data into the FLASH memory of the single-chip microcomputer according to the communication protocol. Subsequently, the data storage backup module backs up the written data and verifies the data through the second verification module to prevent data loss or damage. If the second verification passes, the data copy is successful; if it fails, the security mode is triggered to protect the system from unauthorized access. In addition, the system will perform a third verification on the copied data according to the preset time to ensure the integrity and security of the data.

[0068] The present invention provides an anti-copy system and an anti-copy method, which ensure the integrity and security of data through multiple verifications. This method not only improves the security of data, but also prevents unauthorized copying and tampering. In addition, when data abnormalities are detected, the system can enter a safe mode in time to prevent potential security risks. Through this series of operations, the present invention provides users with an intelligent and automated anti-copy solution, which greatly improves the security of data and the reliability of the system and realizes effective anti-copy protection. BRIEF DESCRIPTION OF THE DRAWINGS

[0069] Figure 1 It is a flowchart of an anti-copying method provided by an embodiment of the present invention;

[0070] Figure 2 It is a structural schematic diagram of an anti-copy system provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0071] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0072] Reference Figure 1 The first embodiment of the present invention provides an anti-copying method, comprising the following steps:

[0073] S11, obtaining the SN code of the burning program and the SN code of the burned MCU;

[0074] S12, performing a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result;

[0075] S13, when the first verification result is that the verification is correct, the burning program writes the data into the FLASH of the burned single-chip computer according to the communication protocol;

[0076] S14, performing a second verification on the data written in the FLASH and saving and backing up the data to obtain a second verification result;

[0077] S15, if the second verification result is that the verification is correct, the copying is successful, and if the verification is wrong, the safe mode is entered;

[0078] S16, performing a third verification on the data that has been successfully copied in the burned single chip computer according to the preset time, and obtaining a third verification result;

[0079] S17, if the third verification result is a verification success, the control program runs normally; if the third verification result is a verification error, the control program enters a safe mode.

[0080] In step S11, the SN code of the burning program and the SN code of the burned microcontroller are obtained.

[0081] The SN code is a unique identification code of the product, usually composed of a string of numbers and letters, used to identify and track the production, sales, maintenance and other processes of the product. In the field of software, the SN code is used to verify the legitimacy of the software and ensure that the user is using genuine software.

[0082] It should be noted that the acquisition of the SN code first requires the acquisition of the unique identifier of the internal register of the burned single-chip microcomputer; wherein the unique identifier is generated during the production process of the burned single-chip microcomputer.

[0083] According to the unique identifier, a calculation transformation is performed to obtain the unique feature of the burned single-chip computer; the calculation transformation is hash mapping through the SHA-256 hash function; according to the unique identifier, a 1 and a sufficient number of 0s are added to the end of the message for padding to obtain a first padding message; wherein the length of the first padding message is an integer multiple of 448 bits; a 64-bit representation is added to the end of the first padding message to obtain a second padding message; a vector containing 8 32-bit registers is initialized, and these registers are used to store intermediate and final hash values; the initialization vector is a set of predefined constants, and these initialization values ​​are usually expressed as hexadecimal numbers, and are obtained by taking the first 32 bits of the decimal part of the square root of the first 8 prime numbers in natural numbers. The first 8 prime numbers in the natural numbers are 2, 3, 5, 11, 13, 17, and 19; for each prime number, its square root is calculated, and the first 32 bits of the decimal part of the calculation result are intercepted as the initial hash value. The second padding message is divided into multiple 512-bit data blocks, and 64 loop iterations are performed on each of the 512-bit data blocks.

[0084] For example, taking the first three registers as an example, assuming that the three registers are , , Each iteration includes the use of logic functions and circular shift operations. First, the messages in the message schedule are expanded using circular shift and non-circular shift operations. Perform a 7-bit circular right shift, an 18-bit circular right shift, and a 3-bit non-circular right shift, and perform an XOR operation on the results obtained by the three right shift operations to obtain a first operation result; Perform a 17-bit circular right shift, a 19-bit circular right shift, and a 10-bit non-circular right shift, and XOR the results to obtain the second operation result. Second, use the selection function and the majority function to combine the expanded message word, the register value of the current iteration, and an iteration constant to calculate a new T1 value; wherein the selection function is used to combine the values ​​of the three registers in each round of iteration to and to perform an AND operation; to calculate The negation result and Perform an AND operation; perform an XOR operation on the two operation results to obtain a third operation result. The functions are respectively calculated and , and , and The calculation formula of the T1 value is as follows:

[0085] ;

[0086] in, , , is the value of the register in the current iteration, is the first operation result, c is the second operation result, d is the fourth operation result, is a preset iteration constant for the current iteration. The iteration constant k is a series of predefined constants selected based on the first 32 bits of the decimal part of the cube roots of the first 64 prime numbers of natural numbers.

[0087] Third, use the circular right shift operation to register The value of 2, 13 and 22 bits are circularly shifted right, and then the three results are XORed to obtain the fifth operation result; Perform a 6-bit, 11-bit, and 25-bit circular right shift, and perform an XOR operation on the three results to obtain a sixth operation result; perform a sum operation on the third operation result, the fifth operation result, and the sixth operation result to obtain a new T2 value.

[0088] The T1 value and the T2 value are two temporary variables used to record the calculated hash value during the algorithm's loop iteration process.

[0089] Further, the register value is updated, and the T1 value and the T2 value are summed to obtain the final register value. The updated values ​​of the eight 32-bit registers are concatenated to obtain the unique feature of the burned microcontroller; wherein the unique feature of the burned microcontroller is a 256-bit hash value.

[0090] Furthermore, according to the unique characteristics of the burned single-chip computer and the device information, calculation transformation is performed to obtain the SN code of the burned single-chip computer; the device information includes device serial number, production batch, device version, device ID, device serial number, software verification code, communication protocol version, and random seed; according to the unique characteristics of the burned single-chip computer and the device information, they are merged in order to obtain a combined string; according to the combined string, hash mapping is performed through the SHA-256 hash function to obtain the SN code of the burned single-chip computer. The SN code is saved in the burning program and the burned single-chip computer respectively to obtain the SN code of the burning program and the SN code of the burned single-chip computer.

[0091] In step S12, a first verification is performed according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result.

[0092] Check whether the single-chip microcomputer to be burned contains an SN state machine, wherein the SN state machine is a built-in logic circuit for storing and verifying the SN code. If the single-chip microcomputer to be burned contains the SN state machine, the SN code of the burning program and the SN code of the single-chip microcomputer to be burned are compared for consistency to obtain a first verification result; if the single-chip microcomputer to be burned does not contain the SN state machine, it is determined to be a verification error.

[0093] The first verification result includes two situations. If the two SN codes are consistent with each other as a result of the first verification, the verification is correct and the subsequent burning process continues; if they are inconsistent, the verification is wrong and the copy operation is terminated immediately.

[0094] In step S13, when the first verification result is that the verification is correct, the burning program writes the data into the FLASH of the burned single-chip computer according to the communication protocol.

[0095] Wherein, the communication protocol is SPI (Serial Peripheral Interface).

[0096] It is worth noting that the burning program initializes the connection with the burned single-chip microcomputer through the SPI interface. Among them, the SPI interface initialization includes all necessary parameters for configuring the SPI interface, such as clock frequency, data bit width, clock polarity, clock phase, chip select signal CS, etc. SPI transmission is performed by byte. Before sending, the burning program decomposes the data sequence into a byte sequence. For data greater than 8 bits, such as 16-bit or 32-bit integers, they are decomposed into multiple bytes and transmitted in a big-endian manner. When the chip select signal CS changes from a high level to a low level, the burning program starts SPI transmission and sends the byte sequence to the burned single-chip microcomputer through the MOSI line. The burned single-chip microcomputer receives data through the MISO line and stores the received data in the internal FLASH memory according to the SPI protocol. When all data are successfully sent and received, the chip select signal CS changes from a low level to a high level, and the burning program stops SPI transmission.

[0097] In step S14, a second verification is performed on the data written in the FLASH and the data is saved and backed up to obtain a second verification result.

[0098] It should be noted that the written data includes the firmware code of the burned single-chip microcomputer, and the written data is divided into multiple data packets; the packet number and the first address of each data packet are obtained; and sufficient buffers are pre-allocated in the RAM to store the backup of each data packet. The size of the buffer should be determined according to the size and number of the data packets. According to the first address of the data packet, the corresponding data packet content is read from the FLASH, and a linked list structure is used to manage the backup of all data packets and their metadata. Each node in the linked list contains the backup data of the data packet, the packet number of the data packet, and the first address. The backup data of each data packet is written to the pre-allocated buffer in the RAM to ensure that the location of the backup data of each data packet in the RAM corresponds to its packet number and the first address.

[0099] Furthermore, according to the order of the packet numbers, the data packet is written into the FLASH, a second check is performed on the data packet, and a predefined polynomial is selected, where 0x04C11DB7 is selected. Before the data packet is written into the FLASH, the burning program performs a CRC check on the data packet, and performs a modulo-2 division operation on the content of the data packet according to the predefined polynomial to obtain a first check value, i.e., a CRC check code. The first check value is compared with a preset check value for consistency to obtain a check result of the data packet.

[0100] The preset check value is calculated using the predefined polynomial and data content when the data packet is generated, and the preset check value is attached to the end of the data packet and transmitted together.

[0101] When the verification result of the data packet is a verification error, the first address of the backup data is used to restore the last correctly written data packet; when the verification result is a verification correct, the above steps are repeated until all data packets are successfully written and verified;

[0102] It is worth noting that the second verification result includes the verification result of each data packet.

[0103] In step S15, if the second verification result is that the verification is correct, the copying is successful, and if the verification is wrong, the safe mode is entered.

[0104] It is worth noting that when entering the safe mode, the copied microcontroller locks all external communication interfaces, such as UART, SPI, I2C, etc., to prevent unauthorized access. The system shuts down all non-essential functions and only retains security-related functions, such as security logs and records and alarms. The copied microcontroller records events that fail verification, including timestamps and possible error codes. The system issues a security alarm through the LED indicator light and maintains the safe mode. The copied microcontroller will not continue to perform any operations and wait for further operations by the user or administrator, such as re-burning the program or performing a system check. If the system detects continued illegal access attempts during the activation of the safe mode, the copied microcontroller will take power-off measures to ensure that data is not leaked.

[0105] In step S16, according to a preset time, which is set to 10 minutes, a third verification is performed on the data that has been successfully copied in the burned single-chip computer to obtain a third verification result.

[0106] It should be noted that after the preset time, the written data is read from the FLASH of the burned microcontroller; the written data includes multiple data packets; according to the cyclic redundancy check algorithm and the predefined polynomial, the content of each data packet is calculated to obtain the second check value of each data packet.

[0107] Furthermore, the second check value is compared with the first check value to obtain a comparison result; and it is determined whether the comparison result is consistent, and the comparison result is intended to verify whether the data packet has not been tampered with or damaged since it was written. If the second check value is consistent with the first check value, the check is correct, indicating that the data packet has remained intact since it was written; if they are inconsistent, the check is wrong, indicating that the data packet may have been tampered with or an error occurred during the writing process. The third check result includes the comparison result of each data packet.

[0108] In step S17, if the third verification result is a verification success, the control program runs normally; if the third verification result is a verification error, the control program enters a safe mode.

[0109] It is worth noting that when entering the safe mode, the copied microcontroller locks all external communication interfaces, such as UART, SPI, I2C, etc., to prevent unauthorized access. The system shuts down all non-essential functions and only retains security-related functions, such as security logs and records and alarms. The copied microcontroller records events that fail verification, including timestamps and possible error codes. The system issues a security alarm through the LED indicator light and maintains the safe mode. The copied microcontroller will not continue to perform any operations and wait for further operations by the user or administrator, such as re-burning the program or performing a system check. If the system detects continued illegal access attempts during the activation of the safe mode, the copied microcontroller will take power-off measures to ensure that data is not leaked.

[0110] The following describes the working process of the present invention using a common scenario as an example. Figure 2 , which is Figure 1 Schematic diagram of the working scenario of the method.

[0111] Assuming that the microcontroller to be burned is an STM32 microcontroller, first obtain the 96-bit unique identifier (UID) of the microcontroller, which is an unchangeable serial number generated during the production process and used to identify the microcontroller. In this example, the UID is 0x123456789ABCDEF0123456789ABCDEF0. Input this UID into the SHA-256 hash function to obtain a 256-bit unique feature:

[0112] 0x9F2FCC4D3E7C20A8-BB9A2A49D08A3B6E1F5B0EA2C89B9C0BF9D4A3E1F5B0EA2C89. In order to generate the SN code, the device information also needs to be integrated. In this example, the device information only considers the production batch number and device version. It is known that the production batch number is Batch2024 and the device version is V1.0. Subsequently, the unique feature is combined with the device information, and the SHA-256 hash function is used again for hash mapping to obtain the SN code of 0x7B3EA2C89B9C0BF9D4A3E1F5B0EA2C89B9C0BF9D4A3E1F5B0EA2C-89B9C0BF9D4A3E1.

[0113] First check whether the burned single-chip microcomputer contains SN state machine, which is a built-in logic circuit for storing and verifying SN code. In this example, the inspection result is that the STM32 single-chip microcomputer includes SN state machine, and the SN code of the burning program and the SN code of the burned single-chip microcomputer are compared for consistency, and the comparison result is that the verification is correct. The burning program writes data segments into the FLASH of the single-chip microcomputer according to the SPI communication protocol. SPI is a synchronous serial data bus widely used in the communication between single-chip microcomputer and various peripheral devices. CRC check is performed on each data packet, and the check value is attached to the end of the data packet and written to FLASH together. At the same time, the backup of each data packet is stored in RAM so that data can be restored when an error occurs. When all data packets are written, the second verification result is obtained as a verification error, and the control program enters the safe mode. In safe mode, the STM32 microcontroller will take the following measures: lock all external communication interfaces, such as UART, SPI, I2C, etc., to prevent unauthorized access; turn off all non-essential functions and only retain security-related functions, such as security logs and records and alarms; record events of verification failures, including timestamps and possible error codes; issue a security alarm through the LED indicator to alert the user or administrator to the abnormal status of the system; maintain safe mode and wait for the user or administrator to perform further operations, such as re-burning the program or performing a system check; if continuous illegal access attempts are detected during the activation of safe mode, the STM32 microcontroller will take power-off measures to ensure that data is not leaked.

[0114] In summary, the present invention provides an anti-copying method, comprising obtaining an SN code of a burning program and an SN code of a burned single-chip computer; performing a first check according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first check result; when the first check result is that the check is correct, the burning program writes data into the FLASH of the burned single-chip computer according to a communication protocol; performing a second check on the data written in the FLASH and saving and backing up the data to obtain a second check result; if the second check result is that the check is correct, the copying is successful, and if the check is wrong, the safe mode is entered; according to a preset time, performing a third check on the data that has been successfully copied in the burned single-chip computer to obtain a third check result; if the third check result is that the check is correct, the control program runs normally, and if the third check result is that the check is wrong, the control program enters the safe mode.

[0115] In the present invention, the SN code acquisition module is first used to collect the SN codes of the burning program and the burned single-chip microcomputer in real time. Then, the first verification module matches and verifies the two SN codes to ensure the legitimacy of the burning program and the single-chip microcomputer. If the verification passes, the FLASH writing module will safely write the data into the FLASH memory of the single-chip microcomputer according to the communication protocol. Subsequently, the data preservation and backup module performs a second verification on the written data and creates a data backup to prevent data loss or damage. If the second verification passes, the data copy is successful; if it fails, the security mode is triggered to protect the system from unauthorized access. In addition, the system will perform a third verification on the copied data according to the preset time to ensure the integrity and security of the data.

[0116] The present invention provides an anti-copy system and an anti-copy method, which ensure the integrity and security of data through multiple verifications. This method not only improves the security of data, but also prevents unauthorized copying and tampering. In addition, when data abnormalities are detected, the system can enter a safe mode in time to prevent potential security risks. Through this series of operations, the present invention provides users with an intelligent and automated anti-copy solution, which greatly improves the security of data and the reliability of the system and realizes effective anti-copy protection.

[0117] Reference Figure 2 The second embodiment of the present invention provides an anti-copy system, comprising:

[0118] The SN code acquisition module 101 is used to acquire the SN code of the burning program and the SN code of the burned single chip microcomputer;

[0119] A first verification module 102, used for performing a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result;

[0120] A FLASH writing module 103, configured to write data into the FLASH of the burned single-chip computer according to the communication protocol when the first verification result is that the verification is correct;

[0121] The data storage and backup module 104 is used to perform segmented backup and storage of the data written in the FLASH;

[0122] The second verification module 105 is used to perform a second verification on the data written in the FLASH to obtain a second verification result; if the second verification result is that the verification is correct, the copy is successful, and if the verification is wrong, the safe mode is entered;

[0123] The third verification module 106 is used to perform a third verification on the data that has been successfully copied in the burned single-chip computer according to a preset time to obtain a third verification result; if the third verification result is a verification correct, the control program runs normally; if the third verification result is a verification error, the control program enters a safe mode.

[0124] Preferably, the SN code acquisition module includes:

[0125] A unique identification acquisition unit, used to acquire a unique identification of an internal register of the burned single-chip microcomputer; the unique identification is generated during the production process of the burned single-chip microcomputer;

[0126] A first padding unit, configured to obtain a first padding message by adding 1 and 0 to the end of the message according to the unique identifier; wherein the length of the first padding message is an integer multiple of 448 bits;

[0127] A second padding unit, used for adding a 64-bit representation at the end of the first padding message to obtain a second padding message;

[0128] A data block acquisition unit, used to divide the second padding message into a plurality of 512-bit data blocks;

[0129] A loop iteration unit, configured to perform 64 loop iterations on each of the 512-bit data blocks; the loop iterations comprising using a logic function and a circular shift operation;

[0130] A register updating unit, used for updating the value of the register to obtain a final register value;

[0131] A unique feature acquisition unit, used for performing a splicing operation according to the final register value to obtain the unique feature of the burned single-chip microcomputer; the unique feature of the burned single-chip microcomputer is a 256-bit hash value;

[0132] The SN code acquisition unit is used to combine the unique characteristics of the burned single-chip computer and the device information in order to obtain a combined string; the device information includes a device serial number, a production batch, a device version, a device ID, a device serial number, a software check code, a communication protocol version, and a random seed; according to the combined string, a hash mapping is performed through a SHA-256 hash function to obtain the SN code of the burned single-chip computer;

[0133] The SN code storage unit is used to store the SN code in the burning program and the burned single-chip computer respectively, so as to obtain the SN code of the burning program and the SN code of the burned single-chip computer.

[0134] Preferably, the data storage and backup module includes:

[0135] A metadata acquisition unit, used to obtain the packet number and the first address of each data packet;

[0136] A backup space allocation unit, used to pre-allocate a sufficient buffer in the RAM for storing a backup of each data packet; the size of the buffer should be determined according to the size and number of the data packets;

[0137] A backup data management unit, used to read the corresponding data packet content from the FLASH according to the first address of the data packet, and use a linked list structure to manage the backup of all data packets and their metadata; each node in the linked list contains the backup data of the data packet, the packet number of the data packet and the first address;

[0138] The backup storage unit is used to write the backup data of each data packet into a pre-allocated buffer in the RAM, ensuring that the location of the backup data of each data packet in the RAM corresponds to its packet number and first address.

[0139] Preferably, the second verification module includes:

[0140] A data packet acquisition unit, used for dividing the written data into a plurality of data packets;

[0141] A backup unit, used to perform a saving operation according to the first address of the data packet to obtain backup data of the data packet;

[0142] The second verification unit is used to calculate the content of the data packet according to a cyclic redundancy check algorithm to obtain a first verification value of the data packet; compare the first verification value with a preset verification value for consistency to obtain a verification result of the data packet; when the verification result is a verification error, use the first address of the backup data to restore the last correctly written data packet; when the verification result is a verification correct, repeat the steps of dividing the written data including the firmware code of the burned microcontroller into multiple data packets until all data packets are successfully written and verified; the second verification result includes the verification result of each data packet.

[0143] Preferably, the third verification module includes:

[0144] A data reading unit, used for reading the written data from the FLASH of the burned single-chip computer after the preset time; the written data includes a plurality of data packets;

[0145] The third verification unit is used to calculate the content of each data packet according to a cyclic redundancy check algorithm to obtain a second verification value for each data packet; compare the second verification value with the first verification value to obtain a comparison result; determine whether the comparison results are consistent, if so, the verification is correct; if not, the verification is incorrect; the third verification result includes the comparison result of each data packet.

[0146] It should be noted that an anti-copying system provided in an embodiment of the present invention is used to execute all process steps of an anti-copying method in the above embodiment, and the working principles and beneficial effects of the two correspond one to one, so they will not be described in detail.

[0147] The embodiment of the present invention further provides an electronic device. The electronic device includes: a processor, a memory, and a computer program stored in the memory and executable on the processor, such as a ... program. When the processor executes the computer program, the steps in the above-mentioned anti-copying method embodiment are implemented, such as Figure 1 Alternatively, when the processor executes the computer program, the functions of the modules / units in the above-mentioned device embodiments are realized, such as the data storage and backup module.

[0148] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the electronic device.

[0149] The electronic device may be a computing device such as a desktop computer, a notebook, a PDA, and a smart tablet. The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the above components are merely examples of electronic devices and do not constitute a limitation on the electronic device. The electronic device may include more or fewer components than the above components, or may combine certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.

[0150] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device.

[0151] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0152] Wherein, if the module / unit integrated in the electronic device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0153] It should be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.

[0154] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.

Claims

1. A copy protection method, characterized in that: include: Get the SN code of the burning program and the SN code of the MCU being burned; Perform a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result; When the first verification result is that the verification is correct, the burning program writes the data into the FLASH of the burned single-chip computer according to the communication protocol; Performing a second check on the data written in the FLASH and saving and backing up the data to obtain a second check result; If the second verification result is correct, the copy is successful; if the verification is wrong, the safe mode is entered; According to the preset time, a third verification is performed on the data that has been successfully copied in the burned single-chip computer to obtain a third verification result; If the third verification result is a verification error, the control program enters a safe mode; if the third verification result is a verification error, the control program enters a safe mode; Wherein, the step of obtaining the SN code of the burning program and the SN code of the burned single-chip microcomputer comprises: Obtaining a unique identifier of an internal register of the burned single-chip computer; Wherein, the unique identifier is generated during the production process of the burned single-chip microcomputer; According to the unique identifier, a calculation transformation is performed to obtain a unique feature of the burned single chip microcomputer; According to the unique characteristics of the burned single-chip microcomputer and the device information, a calculation transformation is performed to obtain the SN code of the burned single-chip microcomputer; The SN code is saved to the burning program and the burned single-chip microcomputer respectively, to obtain the SN code of the burning program and the SN code of the burned single-chip microcomputer; The method of performing calculation and transformation according to the unique identifier to obtain the unique feature of the burned single-chip computer includes: The computational transformation is performed by hash mapping through a SHA-256 hash function; According to the unique identifier, padding is performed by adding 1 and 0 at the end of the message to obtain a first padding message; Wherein, the length of the first padding message is an integer multiple of 448 bits; Adding a 64-bit representation at the end of the first padding message to obtain a second padding message; Initialize a vector of eight 32-bit registers; Splitting the second padding message into a plurality of 512-bit data blocks, and performing 64 loop iterations on each of the 512-bit data blocks; Wherein, the loop iteration includes using logic functions and circular shift operations; Updating the value of the register to obtain a final register value; According to the final register value, a splicing operation is performed to obtain the unique feature of the burned single chip computer; The unique feature of the burned single chip microcomputer is a 256-bit hash value.

2. The anti-copying method according to claim 1, characterized in that: The method of performing calculation and transformation according to the unique characteristics of the burned single-chip computer and the device information to obtain the SN code of the burned single-chip computer includes: The device information includes device serial number, production batch, device version, device ID, device serial number, software verification code, communication protocol version, and random seed; According to the unique characteristics of the burned single chip computer and the device information, they are combined in order to obtain a combined string; According to the combined character string, hash mapping is performed through the SHA-256 hash function to obtain the SN code of the burned single-chip microcomputer.

3. The anti-copying method according to claim 1, characterized in that: The step of performing a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result includes: Check whether the burned single-chip microcomputer includes an SN state machine, if so, compare the SN code of the burning program with the SN code of the burned single-chip microcomputer for consistency to obtain a first verification result; if not, determine that it is a verification error; The SN state machine is a state machine for storing and verifying the SN code.

4. The anti-copying method according to claim 1, characterized in that: The performing a second check on the data written in the FLASH and saving and backing up the data to obtain a second check result includes: The written data includes the firmware code of the burned single-chip microcomputer, and the written data is divided into a plurality of data packets; Get the packet number and first address of each data packet; Perform a saving operation according to the first address of the data packet to obtain backup data of the data packet; Writing the data packets into the FLASH according to the sequence of the packet numbers, performing a second check on the data packets, and obtaining a check result of the data packets; When the verification result is a verification error, using the first address of the backup data to restore the last correctly written data packet; When the verification result is that the verification is correct, repeating the step of dividing the written data into a plurality of data packets, wherein the written data includes the firmware code of the burned single-chip microcomputer, until all the data packets are successfully written and verified; The second verification result includes the verification result of each data packet.

5. The anti-copying method according to claim 4, characterized in that: The performing a second check on the data packet to obtain a check result of the data packet includes: Calculating the content of the data packet according to a cyclic redundancy check algorithm to obtain a first check value of the data packet; The first verification value is compared with a preset verification value for consistency to obtain a verification result of the data packet.

6. The anti-copying method according to claim 5, characterized in that: The method of performing a third verification on the data that has been successfully copied in the burned single chip microcomputer according to the preset time to obtain a third verification result includes: After the preset time, reading the written data from the FLASH of the burned single chip microcomputer; Wherein, the written data includes a plurality of data packets; Calculating the content of each data packet according to a cyclic redundancy check algorithm to obtain a second check value for each data packet; Compare the second verification value with the first verification value to obtain a comparison result; Determine whether the comparison results are consistent, if yes, the verification is correct; if no, the verification is wrong; The third verification result includes the comparison result of each data packet.

7. A copy protection system, characterized in that: Used to implement the anti-copying method according to any one of claims 1 to 6, comprising: SN code acquisition module, used to obtain the SN code of the burning program and the SN code of the burned microcontroller; A first verification module, used for performing a first verification according to the SN code of the burning program and the SN code of the burned single-chip computer to obtain a first verification result; FLASH write module, for when the first verification result is verified to be correct, the burning program writes the data to the burned microcontroller FLASH according to the communication protocol; A data storage and backup module is used to perform segmented backup and storage of the data written in the FLASH; A second verification module is used to perform a second verification on the data written in the FLASH to obtain a second verification result; if the second verification result is that the verification is correct, the copy is successful, and if the verification is wrong, the safe mode is entered; The third verification module is used to perform a third verification on the data that has been successfully copied in the burned single-chip computer according to a preset time to obtain a third verification result; if the third verification result is a verification correct, the control program runs normally; if the third verification result is a verification error, the control program enters a safe mode.

8. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the anti-copying method according to any one of claims 1 to 6 when executing the computer program.

Citation Information

Patent Citations

  • Firmware updating method and device

    CN106293621A

  • Dish-washing machine software burning method, device and equipment

    CN111522562A