A software tamper-proof encryption method for electric bicycles

By using software tamper-proof encryption method in the controller and instrument of the electric bicycle, and using communication keys and data keys for encrypted communication, the problem of communication being easily tampered with and chip data being read in the prior art is solved, and the security of data transmission and system reliability are achieved.

CN115134073BActive Publication Date: 2025-04-22JINHUA ZHUOYUAN IND
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210717531.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-17
Publication Date
2025-04-22
Estimated Expiration
2042-06-17

AI Technical Summary

Technical Problem

Communication between the existing electric bicycle controller and the instrument is easily read and tampered, and the chip's own data is easily read, which poses a safety hazard.

Method used

A software tamper-proof encryption method is adopted, by setting the first chip and the second chip in the controller and the instrument, including the Flash fixed address, the factory key and the UUID code, respectively, and encrypting the communication using the same communication key and the data key. The method includes steps such as detecting the chip legality, ciphertext communication handshake, UUID code encryption and decryption, and anti-UUID code encryption and decryption, to ensure the security of data transmission.

Benefits of technology

Effectively prevent the communication data between the controller and the instrument from being read and tampered, ensure the security of the chip's own data, and improve the safety and reliability of the electric bicycle system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115134073B_ABST
    Figure CN115134073B_ABST
Patent Text Reader

Abstract

The present invention discloses a software tamper-proof encryption method for electric bicycles, comprising the following steps: S1, judging whether a fixed address is empty, otherwise comparing the factory key, if not consistent, go to S2; if consistent, form encrypted data A to write; S2, detecting whether the fixed address is encrypted data A, if yes, jump to S3; S3, judging whether the controller and the meter are matched and jump to S4; S4, UUID code encryption is sent to the meter; S5, after the meter is decrypted, it is encrypted back to the controller through the data key and the communication key; S6, the controller decrypts back the encrypted data C, encrypts the UUID code to obtain the encrypted data E, if C and E are not equal, it is no longer executed; if they are equal, secondary encryption is performed; S7, obtaining the reverse UUID code, and repeating S4 to S6. The present invention can ensure that the communication data between the controller and the meter will not be read and tampered, and the chip's own data cannot be read, thereby ensuring the security of data transmission.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of communication encryption, and in particular to a software tamper-proof encryption method for an electric bicycle. Background Art

[0002] With the implementation of the new national and European standards, the safety of power-assisted bicycles has attracted more and more attention. However, in real life, some people still ignore safety for the sake of convenience and crack the original speed limit and other functions of the bicycle, which will bring great safety hazards.

[0003] At present, most controllers and instruments on the market use plain text communication. The advantage of this communication method is that it is concise and clear, but it also has the disadvantage of being easy to read and tamper with. Some products use ciphertext communication, but the communication data encryption method of all products is the same, which also has the risk of being tampered with.

[0004] In addition, because the encryption method and encryption key are stored in the chip, in addition to the risk of data being tampered with during the communication process, there is also a risk of the chip's own data being read, which requires further improvement. Summary of the invention

[0005] The present invention aims at the defects in the prior art that the communication between the controller and the instrument can be easily read and tampered, and the data of the chip itself can be easily read, and provides a new software tamper-proof encryption method for electric bicycles.

[0006] In order to solve the above technical problems, the present invention is implemented by the following technical solutions:

[0007] A software tamper-proof encryption method for an electric bicycle includes a controller and an instrument. The controller is provided with a first chip, the first chip is provided with a Flash fixed address, a factory key, and a UUID code, the Flash fixed address is provided with content, and the instrument is provided with a second chip, the first chip and the second chip are both provided with the same communication key and data key, and the method includes the following steps:

[0008] S1. After power-on, determine whether the content at the fixed address of the Flash of the first chip is empty. If it is empty, do not execute the subsequent steps. If it is not empty, compare the content at the fixed address of the Flash of the first chip with the factory key of the first chip. If they are inconsistent, jump to step S2. If they are consistent, it is determined that the current power-on is the first time, and the UUID code of the first chip is encrypted to form encrypted data A and written into the fixed address of the Flash of the first chip to overwrite the factory key of the first chip, and complete the key initialization.

[0009] S2, the first chip detects whether the data in the fixed address of the Flash is the encrypted data A. If so, the first chip is determined to be legal, and the process jumps to step S3; otherwise, the first chip is illegal, and the subsequent steps are not executed;

[0010] Steps S1-S2 are used to detect whether the first chip is legal. The detection purposes include whether the first chip is an original chip and whether the content at the Flash fixed address has been tampered with, thereby ensuring the security of the content at the Flash fixed address of the first chip.

[0011] S3, the controller sends a ciphertext communication handshake frame to the instrument. If the instrument receives the ciphertext communication handshake frame, it replies with a response frame to the controller. If the controller receives the response frame, it is determined that the controller and the instrument are compatible with each other and perform ciphertext communication, and jumps to step S4;

[0012] Step S3 is used to determine whether the controller matches the instrument, thereby providing the first line of defense for subsequent normal encryption and decryption.

[0013] S4, obtaining the UUID code of the first chip and encrypting it with the communication key to form encrypted data B and send it to the instrument;

[0014] The purpose of step S4 is to encrypt the sent plain text using the communication key, thereby preventing the outside world from obtaining the original data transmitted during the communication process.

[0015] S5. After receiving the encrypted data B, the meter first decrypts it back to the UUID code using the communication key. The meter then encrypts the decrypted UUID code using the data key to form encrypted data C. After the encryption is completed, it is encrypted again using the communication key to form encrypted data D and returned to the controller.

[0016] Step S5 encrypts the UUID code with the data key to prepare for the subsequent encryption of the UUID code data with the controller. Step S4 and step S5 use the communication key and the data key for encryption respectively, rather than using the same key, which can further improve the security of the data.

[0017] S6. When the controller receives the encrypted data D replied by the meter, it first decrypts the encrypted data D back to the encrypted data C through the communication key. At the same time, the controller encrypts the UUID code of the first chip through the data key to obtain the encrypted data E. If the encrypted data C is not equal to the encrypted data E, it is determined that the meter does not match or the data has been tampered with, and the subsequent steps are not executed; if the encrypted data C is equal to the encrypted data E, step S7 is executed;

[0018] Step S6 is used to compare whether the encrypted data C is consistent with the encrypted data E. If the data is consistent, it is determined that the communication key and data key of the first chip and the second chip are consistent, and the data communication process has not been tampered with, thereby ensuring the security of the data.

[0019] S7, obtaining the UUID code of the first chip and inverting the bytes to obtain the inverse UUID code, and repeating steps S4 to S6 according to the inverse UUID code, thereby completing the encryption process.

[0020] Step S7 repeats steps S4 to S6 again using the reverse UUID code, which can further ensure the security of the data.

[0021] Through the above steps, the present invention can ensure that the communication data between the controller and the instrument will not be read or tampered with, and the chip's own data cannot be read either, thereby ensuring the security of data transmission.

[0022] Preferably, in the above-mentioned method for encrypting software for electric bicycles to prevent tampering, the method of encrypting by communication key is:

[0023] A1. For input data encrypted by the communication key, take the first 4 bytes of the input data and define them as Data1, and take the last 4 bytes of the input data and define them as Data2;

[0024] A2, shift Data2 left by 5 bits to get intermediate data 1, add the communication key to Data2 bit by bit to get intermediate data 2, then perform bitwise XOR on intermediate data 1 and intermediate data 2, add them bit by bit to Data1, and assign them to Data1 again;

[0025] A3. Shift Data1 left by 5 bits to get intermediate data 3, and add the communication key to Data1 bit by bit to get intermediate data 4. Then perform bitwise XOR of intermediate data 3 and intermediate data 4, add them to Data2 bit by bit, and assign them to Data2 again.

[0026] A4. Repeat steps A2 to A3 for a total of 32 times, and then output the final Data1 and Data2 as the data obtained after the communication key encryption.

[0027] The above communication key encryption method, i.e., bit left shift and bit XOR operation, has a faster operation speed and is more suitable for the operating environment and processing requirements of the single-chip microcomputer. 32 rounds of operation are used during encryption, which makes the obtained data more different from the original data, making it more difficult to find patterns and crack.

[0028] Preferably, in the above-mentioned software tamper-proof encryption method for electric bicycles, the method of decrypting by communication key is:

[0029] B1, obtain the data Data1 and Data2 that need to be decrypted;

[0030] B2, shift Data2 left by 5 bits to get the intermediate data 5, add the communication key to Data2 bit by bit to get the intermediate data 6, then perform bitwise XOR on the intermediate data 5 and the intermediate data 6 to get the intermediate data 7, then subtract Data1 from the intermediate data 7 and assign it to Data1 again;

[0031] B3. Shift Data1 left by 5 bits to get the intermediate data eight, add the communication key to Data1 bit by bit to get the intermediate data nine, then perform bitwise XOR on the intermediate data eight and the intermediate data nine to get the intermediate data ten, then subtract Data2 from the intermediate data ten bit by bit and assign the result to Data2 again;

[0032] B4. Repeat steps B2 to B3 for a total of 32 times, and then output the final Data1 and Data2 as the data obtained after decryption of the communication key.

[0033] The above communication key decryption method, that is, through bit left shift and bit XOR operation, has a faster operation speed and is more suitable for the operating environment and processing requirements of the single-chip microcomputer. 32 rounds of operation are used during encryption, which makes the obtained data more different from the original data, making it more difficult to find patterns and crack. Decryption is the reverse process of encryption. In the 32 rounds of operation, encryption is through the sum of the original data and the encrypted data, while the decryption process is to find the difference. Even if the encryption result overflows, it does not affect the original data obtained by decryption. The data in the encryption and decryption process is more robust.

[0034] Preferably, in the above-mentioned method for tamper-proof encryption of software for electric bicycles, the method of encrypting by data key is:

[0035] C1. For input data encrypted by the data key, take the first 4 bytes of the input data and define them as Data3, and take the last 4 bytes of the input data and define them as Data4;

[0036] C2, shift Data4 left by 5 bits to get the intermediate data 11, and add the data key to Data4 bit by bit to get the intermediate data 12, then perform bitwise XOR on the intermediate data 11 and the intermediate data 12, add them to Data3 bit by bit, and assign them to Data3 again;

[0037] C3, shift Data3 left by 5 bits to get the intermediate data 13, and add the data key to Data3 bit by bit to get the intermediate data 14, then perform bitwise XOR on the intermediate data 13 and the intermediate data 14, add them to Data4 bit by bit, and assign them to Data4 again;

[0038] C4. Repeat steps C2 to C3 for a total of 32 times, and then output the final Data3 and Data4 as the data obtained after data key encryption.

[0039] The above data key encryption method, i.e., bit left shift and bit XOR operation, has a faster operation speed and is more suitable for the operating environment and processing requirements of the single-chip microcomputer. 32 rounds of operation are used during encryption, which makes the obtained data more different from the original data, making it more difficult to find patterns and crack. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a flow chart of steps S1 and S2 in the present invention;

[0041] Figure 2 Flow chart of steps S4 to S7 in the present invention. DETAILED DESCRIPTION

[0042] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments, but they are not intended to limit the present invention:

[0043] Example 1

[0044] A software tamper-proof encryption method for an electric bicycle includes a controller and an instrument. The controller is provided with a first chip, the first chip is provided with a Flash fixed address, a factory key, and a UUID code, the Flash fixed address is provided with content, and the instrument is provided with a second chip, the first chip and the second chip are both provided with the same communication key and data key, and the method includes the following steps:

[0045] S1. After power-on, determine whether the content at the fixed address of the Flash of the first chip is empty. If it is empty, do not execute the subsequent steps. If it is not empty, compare the content at the fixed address of the Flash of the first chip with the factory key of the first chip. If they are inconsistent, jump to step S2. If they are consistent, it is determined that the current power-on is the first time, and the UUID code of the first chip is encrypted to form encrypted data A and written into the fixed address of the Flash of the first chip to overwrite the factory key of the first chip, and complete the key initialization.

[0046] S2, the first chip detects whether the data in the fixed address of the Flash is the encrypted data A. If so, the first chip is determined to be legal, and the process jumps to step S3; otherwise, the first chip is illegal, and the subsequent steps are not executed;

[0047] S3, the controller sends a ciphertext communication handshake frame to the instrument. If the instrument receives the ciphertext communication handshake frame, it replies with a response frame to the controller. If the controller receives the response frame, it is determined that the controller and the instrument are compatible with each other and perform ciphertext communication, and jumps to step S4;

[0048] S4, obtaining the UUID code of the first chip and encrypting it with the communication key to form encrypted data B and send it to the instrument;

[0049] S5. After receiving the encrypted data B, the meter first decrypts it back to the UUID code using the communication key. The meter then encrypts the decrypted UUID code using the data key to form encrypted data C. After the encryption is completed, it is encrypted again using the communication key to form encrypted data D and returned to the controller.

[0050] S6. When the controller receives the encrypted data D replied by the meter, it first decrypts the encrypted data D back to the encrypted data C through the communication key. At the same time, the controller encrypts the UUID code of the first chip through the data key to obtain the encrypted data E. If the encrypted data C is not equal to the encrypted data E, it is determined that the meter does not match or the data has been tampered with, and the subsequent steps are not executed; if the encrypted data C is equal to the encrypted data E, step S7 is executed;

[0051] S7, obtaining the UUID code of the first chip and inverting the bytes to obtain the inverse UUID code, and repeating steps S4 to S6 according to the inverse UUID code, thereby completing the encryption process.

[0052] Preferably, the method of encrypting by communication key is:

[0053] A1. For input data encrypted by the communication key, take the first 4 bytes of the input data and define them as Data1, and take the last 4 bytes of the input data and define them as Data2;

[0054] A2, shift Data2 left by 5 bits to get intermediate data 1, add the communication key to Data2 bit by bit to get intermediate data 2, then perform bitwise XOR on intermediate data 1 and intermediate data 2, add them bit by bit to Data1, and assign them to Data1 again;

[0055] A3. Shift Data1 left by 5 bits to get intermediate data 3, and add the communication key to Data1 bit by bit to get intermediate data 4. Then perform bitwise XOR of intermediate data 3 and intermediate data 4, add them to Data2 bit by bit, and assign them to Data2 again.

[0056] A4. Repeat steps A2 to A3 for a total of 32 times, and then output the final Data1 and Data2 as the data obtained after the communication key encryption.

[0057] Preferably, the method of decrypting by communication key is:

[0058] B1, obtain the data Data1 and Data2 that need to be decrypted;

[0059] B2, shift Data2 left by 5 bits to get the intermediate data 5, add the communication key to Data2 bit by bit to get the intermediate data 6, then perform bitwise XOR on the intermediate data 5 and the intermediate data 6 to get the intermediate data 7, then subtract Data1 from the intermediate data 7 and assign it to Data1 again;

[0060] B3. Shift Data1 left by 5 bits to get the intermediate data eight, add the communication key to Data1 bit by bit to get the intermediate data nine, then perform bitwise XOR on the intermediate data eight and the intermediate data nine to get the intermediate data ten, then subtract Data2 from the intermediate data ten bit by bit and assign the result to Data2 again;

[0061] B4. Repeat steps B2 to B3 for a total of 32 times, and then output the final Data1 and Data2 as the data obtained after decryption of the communication key.

[0062] Preferably, the method of encrypting by data key is:

[0063] C1. For input data encrypted by the data key, take the first 4 bytes of the input data and define them as Data3, and take the last 4 bytes of the input data and define them as Data4;

[0064] C2, shift Data4 left by 5 bits to get the intermediate data 11, and add the data key to Data4 bit by bit to get the intermediate data 12, then perform bitwise XOR on the intermediate data 11 and the intermediate data 12, add them to Data3 bit by bit, and assign them to Data3 again;

[0065] C3, shift Data3 left by 5 bits to get the intermediate data 13, and add the data key to Data3 bit by bit to get the intermediate data 14, then perform bitwise XOR on the intermediate data 13 and the intermediate data 14, add them to Data4 bit by bit, and assign them to Data4 again;

[0066] C4. Repeat steps C2 to C3 for a total of 32 times, and then output the final Data3 and Data4 as the data obtained after data key encryption.

[0067] In conclusion, the above is only a preferred embodiment of the present invention, and all equivalent changes and modifications made within the scope of the patent application of the present invention should fall within the scope of the present invention.

Claims

1. A software tamper-proof encryption method for an electric bicycle, comprising a controller and an instrument, wherein a first chip is provided in the controller, and characterized in that: The first chip is provided with a Flash fixed address, a factory key, and a UUID code, the Flash fixed address is provided with content, the meter is provided with a second chip, the first chip and the second chip are both provided with the same communication key and data key, and the following steps are included: S1. After power-on, determine whether the content at the fixed address of the Flash of the first chip is empty. If it is empty, do not execute the subsequent steps. If it is not empty, compare the content at the fixed address of the Flash of the first chip with the factory key of the first chip. If they are inconsistent, jump to step S2. If they are consistent, it is determined that the current power-on is the first time, and the UUID code of the first chip is encrypted to form encrypted data A and written into the fixed address of the Flash of the first chip to overwrite the factory key of the first chip, and complete the key initialization. S2, the first chip detects whether the data in the fixed address of the Flash is the encrypted data A. If so, the first chip is determined to be legal, and the process jumps to step S3; otherwise, the first chip is illegal, and the subsequent steps are not executed; S3, the controller sends a ciphertext communication handshake frame to the instrument. If the instrument receives the ciphertext communication handshake frame, it replies with a response frame to the controller. If the controller receives the response frame, it is determined that the controller and the instrument are compatible with each other and perform ciphertext communication, and jumps to step S4; S4, obtaining the UUID code of the first chip and encrypting it with the communication key to form encrypted data B and send it to the instrument; S5. After receiving the encrypted data B, the meter first decrypts it back to the UUID code using the communication key. The meter then encrypts the decrypted UUID code using the data key to form encrypted data C. After the encryption is completed, it is encrypted again using the communication key to form encrypted data D and returned to the controller. S6. When the controller receives the encrypted data D replied by the meter, it first decrypts the encrypted data D back to the encrypted data C through the communication key. At the same time, the controller encrypts the UUID code of the first chip through the data key to obtain the encrypted data E. If the encrypted data C is not equal to the encrypted data E, it is determined that the meter does not match or the data has been tampered with, and the subsequent steps are not executed; if the encrypted data C is equal to the encrypted data E, step S7 is executed; S7, obtaining the UUID code of the first chip and inverting the bytes to obtain the inverse UUID code, and repeating steps S4 to S6 according to the inverse UUID code, thereby completing the encryption process.

2. The software tamper-proof encryption method for electric bicycles according to claim 1, characterized in that: The method of encrypting by communication key is: A1. For input data encrypted by the communication key, take the first 4 bytes of the input data and define them as Data1, and take the last 4 bytes of the input data and define them as Data2; A2, shift Data2 left by 5 bits to get intermediate data 1, add the communication key to Data2 bit by bit to get intermediate data 2, then perform bitwise XOR on intermediate data 1 and intermediate data 2, add them bit by bit to Data1, and assign them to Data1 again; A3. Shift Data1 left by 5 bits to get intermediate data 3, and add the communication key to Data1 bit by bit to get intermediate data 4. Then perform bitwise XOR of intermediate data 3 and intermediate data 4, add them to Data2 bit by bit, and assign them to Data2 again. A4. Repeat steps A2 to A3 for a total of 32 times, and then output the final Data1 and Data2 as the data obtained after the communication key encryption.

3. The software tamper-proof encryption method for electric bicycles according to claim 2, characterized in that: The method of decrypting by communication key is: B1, obtain the data Data1 and Data2 that need to be decrypted; B2, shift Data2 left by 5 bits to get the intermediate data 5, add the communication key to Data2 bit by bit to get the intermediate data 6, then perform bitwise XOR on the intermediate data 5 and the intermediate data 6 to get the intermediate data 7, then subtract Data1 from the intermediate data 7 and assign it to Data1 again; B3. Shift Data1 left by 5 bits to get the intermediate data eight, add the communication key to Data1 bit by bit to get the intermediate data nine, then perform bitwise XOR on the intermediate data eight and the intermediate data nine to get the intermediate data ten, then subtract Data2 from the intermediate data ten bit by bit and assign the result to Data2 again; B4. Repeat steps B2 to B3 for a total of 32 times, and then output the final Data1 and Data2 as the data obtained after decryption of the communication key.

4. The software tamper-proof encryption method for electric bicycles according to claim 1, characterized in that: The method of encrypting by data key is: C1. For input data encrypted by the data key, take the first 4 bytes of the input data and define them as Data3, and take the last 4 bytes of the input data and define them as Data4; C2, shift Data4 left by 5 bits to get the intermediate data 11, and add the data key to Data4 bit by bit to get the intermediate data 12, then perform bitwise XOR on the intermediate data 11 and the intermediate data 12, add them to Data3 bit by bit, and assign them to Data3 again; C3, shift Data3 left by 5 bits to get the intermediate data 13, and add the data key to Data3 bit by bit to get the intermediate data 14, then perform bitwise XOR on the intermediate data 13 and the intermediate data 14, add them to Data4 bit by bit, and assign them to Data4 again; C4. Repeat steps C2 to C3 for a total of 32 times, and then output the final Data3 and Data4 as the data obtained after data key encryption.

Citation Information

Patent Citations

  • Related method for encrypting and storing files in trusted execution environment based on encryption chip

    CN110110548A

  • Inter-device encryption communication method and data communication method using the same

    JP2015128230A