CAN bus communication method, system and device based on dynamic key symmetric encryption and medium
By combining a fixed key seed and a real-time timestamp to generate a dynamic session key on the CAN bus, and using the XTEA algorithm to encrypt data, the security and real-time issues of traditional CAN bus communication are solved, achieving efficient security protection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-19
- Publication Date
- 2026-03-31
AI Technical Summary
Traditional CAN bus communication lacks security mechanisms and is vulnerable to eavesdropping and malicious attacks. Furthermore, existing encryption algorithms use fixed keys, which compromise security once cracked. In addition, complex encryption algorithms and frequent key updates can lead to communication delays.
A fixed key seed is combined with a real-time dynamic timestamp. A dynamic session key is generated using the SHA-256 hash algorithm, and the XTEA algorithm is used for data encryption and decryption to ensure that both communicating parties use the same dynamic session key.
While taking into account the real-time and low-bandwidth characteristics of the CAN bus, it provides strong security protection to prevent eavesdropping and malicious attacks, and ensure forward security and replay resistance of communication.
Smart Images

Figure CN121770831A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of commercial vehicle and in-vehicle network communication security technology, specifically to a communication method, system, device and medium based on dynamic key symmetric encryption of CAN bus. Background Technology
[0002] With the continuous development of vehicle intelligence and networking, the CAN bus, as the core network of the vehicle, carries all the control units in the vehicle, and its security has attracted much attention. Currently, external devices such as diagnostic tools can be connected to the CAN bus through standard OBD-II interfaces to communicate with various control units in the vehicle, enabling functions such as fault diagnosis, parameter configuration, data upgrades, and data monitoring. However, traditional CAN buses do not fully incorporate security mechanisms in their design phase. Their communication content is usually broadcast in plaintext, lacking effective data encryption and authentication. This makes traditional CAN buses vulnerable to security threats such as eavesdropping and malicious command injection. Attackers can easily intercept diagnostic commands and vehicle operating data, and even send illegal control commands to the vehicle by simulating external devices such as diagnostic tools, threatening vehicle safety.
[0003] Existing technologies generally employ traditional symmetric encryption algorithms (such as AES) or lightweight encryption algorithms to encrypt data. However, these schemes typically use fixed keys, and once the key is cracked, the security of the vehicle communication system is compromised. Furthermore, due to the bandwidth limitations of the CAN bus (typically 250kbps, 500kbps, or 1Mbps), overly complex encryption algorithms and frequent key updates can lead to communication delays. Summary of the Invention
[0004] The purpose of this invention is to provide a communication method, system, device, and medium for CAN bus based on dynamic key symmetric encryption, which can take into account both the real-time and low-bandwidth characteristics of CAN bus, and provide high-strength security protection for vehicles.
[0005] To achieve the above objectives, embodiments of the present invention provide a communication method for a CAN bus based on dynamic key symmetric encryption, comprising: The same fixed key seed is preset in the external device and the vehicle control unit, and heartbeat packets are periodically exchanged on the CAN bus. The heartbeat packets include the sender's current timestamp and verification information. Upon receiving a heartbeat packet, both communicating parties generate a dynamic session key using the SHA-256 hash algorithm based on the fixed key seed and the received timestamp. During the heartbeat cycle, the communicating party uses the dynamic session key and the XTEA algorithm to encrypt the non-heartbeat data to be sent, and encapsulates the encrypted data into a CAN data frame for transmission. The receiver uses the same locally generated dynamic session key to perform XTEA decryption on the received encrypted CAN data frame; The generation of the dynamic session key depends on the timestamp provided by the periodic interactive heartbeat packets, the encryption of the data depends on the dynamic session key generated in real time, and the decryption and encryption of the data use the same key generation mechanism and algorithm.
[0006] Optional, the heartbeat package includes: The first byte is the heartbeat identifier, the second to seventh bytes are timestamp information, and the eighth byte is the verification byte; wherein, the heartbeat identifier is a first preset value on the external device side and a second preset value on the vehicle control unit side; the verification byte is generated using CRC32 or cumulative checksum method.
[0007] Optionally, a dynamic session key is generated using the SHA-256 hash algorithm, including: The fixed key seed is concatenated with the received timestamp as a byte stream to obtain the concatenated data. Perform a SHA-256 hash operation on the concatenated data to obtain a 32-byte hash value; The first 16 bytes of the 32-byte hash value are extracted and used as the 128-bit dynamic session key required by the XTEA algorithm.
[0008] Optionally, perform a SHA-256 hash operation on the concatenated data to obtain a 32-byte hash value, including: According to the formula H shavalue = SHA-256(S||T) is used to calculate the SHA-256 hash value; According to the formula H final = Substr 1:16 ( H shavalue Extract the first 16 bytes; In the formula, H shavalue The result of hash value calculation, H final For the final output, Substr 1:16 ( ) represents a truncation operation, indicating that the first 16 bytes of the input byte stream are extracted, SHA-256( ) is the SHA-256 hash function, S is the fixed key seed, T is the timestamp information, and || is the byte stream concatenation operation.
[0009] Optionally, the XTEA algorithm is used to encrypt the non-heartbeat data to be sent, including: Split the 64-bit non-heartbeat plaintext data to be sent into two 32-bit integers; The 128-bit dynamic session key is split into four 32-bit integers; A 64-bit ciphertext is generated by performing 64 rounds of iterative operations with a fixed constant delta, combined with the dynamic session key.
[0010] Optionally, when decrypting a received encrypted CAN data frame, if decryption fails using the dynamic session key of the current heartbeat cycle, then the dynamic session key of the previous heartbeat cycle is used for decryption.
[0011] Optionally, the update cycle of the dynamic session key is the same as the interaction cycle of the heartbeat packet.
[0012] Secondly, the present invention also provides a communication system for a CAN bus based on dynamic key symmetric encryption, comprising: A key seed pre-setting module is used to pre-set the same fixed key seed in external devices and vehicle control units, and to periodically exchange heartbeat packets on the CAN bus, wherein the heartbeat packet includes the sender's current timestamp and verification information; The key generation module is used to generate a dynamic session key by both communicating parties based on the fixed key seed and the received timestamp after receiving the heartbeat packet, using the SHA-256 hash algorithm. The encryption module is used to encrypt the non-heartbeat data to be sent by the communicating party using the dynamic session key and the XTEA algorithm during the heartbeat cycle, and to encapsulate the encrypted data into a CAN data frame for transmission. The decryption module is used by the receiver to perform XTEA decryption on the received encrypted CAN data frame using the same locally generated dynamic session key. The generation of the dynamic session key depends on the timestamp provided by the periodic interactive heartbeat packets, the encryption of the data depends on the dynamic session key generated in real time, and the decryption and encryption of the data use the same key generation mechanism and algorithm.
[0013] Thirdly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the communication method based on dynamic key symmetric encryption of the CAN bus described above.
[0014] Fourthly, the present invention also provides a storage medium storing a computer program thereon, wherein the computer program, when executed by a processor, implements the steps of the communication method of the CAN bus based on dynamic key symmetric encryption described above.
[0015] The above technical solution generates a "digital fingerprint" on the CAN bus, which communicates with external devices such as diagnostic tools and vehicle control units, by combining a fixed key with a real-time dynamically changing timestamp. The data is then encrypted / decrypted using the XTEA algorithm. This approach balances the real-time nature and low bandwidth characteristics of the CAN bus while providing high-strength security protection for the vehicle.
[0016] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description
[0017] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of a communication method for a CAN bus based on dynamic key symmetric encryption, provided by an embodiment of the present invention. Figure 2 This is a detailed flowchart of a communication method for a CAN bus based on dynamic key symmetric encryption provided in an embodiment of the present invention; Figure 3 This is a timing diagram of a real-time communication process between an external device and a vehicle control unit provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of a communication system based on dynamic key symmetric encryption of a CAN bus provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0018] To better understand the technical solution of this application, the following explanations are provided for the technical terms used in this application: SHA-256 is a cryptographic hash algorithm specifically designed for encryption. Its core features include fixed-length output data, one-way irreversibility, and collision resistance. Based on these characteristics, SHA-256 excels in generating "digital fingerprints," but its lack of a key prevents its use in encryption / decryption. However, this invention relates to data encryption. The XTEA algorithm is a symmetric-key block encryption algorithm that not only boasts high computational efficiency and low resource consumption, but also enhances data encryption security by increasing the number of encryption rounds (typically 64 rounds) and employing more complex key scheduling and different mathematical methods, such as rearranging shift, XOR, and addition operations. This makes it particularly suitable for use in environments with limited computing power and resources, such as microcontrollers, where it can encrypt and protect data without consuming excessive resources.
[0019] Various embodiments of this disclosure will be described more fully in the following detailed description. This disclosure may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of this disclosure to the specific embodiments disclosed herein, but rather this disclosure should be understood to cover all adjustments, equivalents, and / or alternatives falling within the spirit and scope of the various embodiments of this disclosure.
[0020] In the following, the terms “comprising” or “may include”, which may be used in various embodiments of this disclosure, indicate the presence of the disclosed functions or operations and do not limit the addition of one or more functions or operations. Furthermore, as used in various embodiments of this disclosure, the terms “comprising,” “having,” and their cognates are intended only to indicate a specific feature, number, step, operation, or combination of the foregoing and should not be construed as primarily excluding the presence of one or more other features, numbers, steps, operations, or combinations of the foregoing, or the possibility of adding one or more features, numbers, steps, operations, or combinations of the foregoing.
[0021] In various embodiments of this disclosure, the expression "or" or "at least one of A and / or B" includes any combination or all combinations of the words listed simultaneously. For example, the expression "A or B" or "at least one of A and / or B" may include A, may include B, or may include both A and B.
[0022] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0023] See Figure 1 The diagram shows a flowchart of a communication method for a CAN bus based on dynamic key symmetric encryption in a specific embodiment, including the following execution steps: Step 100: The same fixed key seed is preset in the external device and the vehicle control unit, and heartbeat packets are periodically exchanged on the CAN bus, wherein the heartbeat packet includes the sender's current timestamp and verification information.
[0024] Specifically, the heartbeat packet includes: the first byte is the heartbeat identifier, the second to seventh bytes are timestamp information, and the eighth byte is the verification byte; wherein, the heartbeat identifier is a first preset value on the external device side and a second preset value on the vehicle control unit side; the verification byte is generated using CRC32 or a cumulative checksum method.
[0025] For example, an external device such as a diagnostic instrument.
[0026] In one specific embodiment, both the external device and the vehicle control unit are pre-set with the same fixed key seed (the string can be freely determined). The external device and the vehicle control unit exchange heartbeat packets on the CAN bus every 5 seconds. The heartbeat packet carries the sender's current timestamp. Because the heartbeat message is not encrypted, data verification can be performed using the last byte. The verification method can be CRC32 or a cumulative checksum. The heartbeat packet is specifically defined as follows: the first byte is the heartbeat byte: 3E; bytes 2-7 are timestamp information in milliseconds; and the eighth byte is the checksum byte.
[0027] The heartbeats of external devices are shown in Table 1, and the heartbeats of control units are shown in Table 2. Table 1 External Device Heartbeat
[0028] Table 2 Control Unit Heartbeat
[0029] Based on the same fixed key seed for external devices and vehicle control units, the two parties exchange heartbeat packets on the CAN bus every 5 seconds, which has data verification function and realizes periodic heartbeat and key synchronization.
[0030] Step 101: After receiving the heartbeat packet, the two communicating parties generate a dynamic session key based on the fixed key seed and the received timestamp using the SHA-256 hash algorithm.
[0031] Specifically, generating a dynamic session key using the SHA-256 hash algorithm includes the following steps: S1010: The fixed key seed and the received timestamp are concatenated into a byte stream to obtain the concatenated data.
[0032] S1011: Perform a SHA-256 hash operation on the concatenated data to obtain a 32-byte hash value.
[0033] Specifically, when executing step S1011, the following steps can be performed: According to the formula H shavalue = SHA-256(S||T) is used to calculate the SHA-256 hash value; According to the formula H final = Substr 1:16 ( H shavalue Extract the first 16 bytes; In the formula,H shavalue The result of hash value calculation, H final For the final output (the first 16 bytes of the SHA-256 hash value, i.e., 128 bits of data), Substr 1:16 ( ) represents a truncation operation, indicating that the first 16 bytes (or the first 128 bits) of the input byte stream are extracted, SHA-256( ) is the SHA-256 hash function (takes an arbitrary length byte stream as input and outputs a 32-byte fixed-length hash value), S is a fixed key seed, T is timestamp information, and || is a byte stream concatenation operation (concatenates the byte streams of S and T in order into a continuous byte stream).
[0034] It should be noted that the update cycle of the dynamic session key is the same as the interaction cycle of the heartbeat packet.
[0035] S1012: Extract the first 16 bytes of the 32-byte hash value as the 128-bit dynamic session key required by the XTEA algorithm.
[0036] Step 102: During the heartbeat cycle, the communicating party uses the dynamic session key and the XTEA algorithm to encrypt the non-heartbeat data to be sent, and encapsulates the encrypted data into a CAN data frame for transmission.
[0037] Specifically, the XTEA algorithm is used to encrypt the non-heartbeat data to be sent, including the following steps: S1020: Split the 64-bit non-heartbeat plaintext data to be sent into two 32-bit integers.
[0038] S1021: Split the 128-bit dynamic session key into four 32-bit integers.
[0039] S1022: Generate 64-bit ciphertext by performing 64 rounds of iterative operations containing a fixed constant delta, combined with the dynamic session key.
[0040] For example, within one heartbeat (5 seconds), all non-heartbeat diagnostic request and response data are encrypted using the XTEA algorithm and the current session key before being sent, and then encapsulated into standard CAN data frames for transmission.
[0041] In one specific embodiment, XTEA is a symmetric block cipher algorithm, the core of which is to split 64-bit data (plaintext message) into two 32-bit integers v0 / v1 and a 128-bit key ( H final(Decomposed into four 32-bit integers k0 / k1 / k2 / k3) Perform 64 rounds of repeated computation: Starting from the plaintext, accumulate sum using a fixed constant delta=0x9E3779B9. In each round, update v0 first, then update sum, and finally update v1. After 64 rounds, the ciphertext is obtained; the pseudocode execution is as follows: / / Input: 64-bit plaintext (split into v0, v1), 128-bit key (split into k[0]-k[3]) / / Output: 64-bit ciphertext (v0, v1) Function XTEA_Encrypt(v0, v1, k[0..3]): delta = 0x9E3779B9 / / Fixed constant sum = 0 / / The summation variable is initialized to 0 For i from 1 to 64: 64 iterations / / Step 1: Update v0 v0 = v0 + ( ((v1<<4) XOR (v1>>5)) + v1 ) XOR (sum + k[sum&3]) / / Step 2: Accumulate delta to sum sum = sum + delta Step 3: Update v1 v1 = v1 + ( ((v0<<4) XOR (v0>>5)) + v0 ) XOR (sum + k[(sum>>11)&3]) Return (v0, v1) / / Returns the ciphertext.
[0042] Step 103: The receiver uses the same locally generated dynamic session key to perform XTEA decryption on the received encrypted CAN data frame.
[0043] The generation of the dynamic session key depends on the timestamp provided by the periodic interactive heartbeat packets, the encryption of the data depends on the dynamic session key generated in real time, and the decryption and encryption of the data use the same key generation mechanism and algorithm.
[0044] It should be noted that an anti-slight network latency mechanism is introduced when decrypting the received encrypted CAN data frame using XTEA. If decryption fails using the dynamic session key of the current heartbeat cycle, the dynamic session key of the previous heartbeat cycle is used for decryption. This is to deal with the problem of misalignment between periodic heartbeat packets and encrypted data packets caused by network latency.
[0045] In one specific implementation, XTEA is a symmetric block cipher algorithm, the core of which is to split 64-bit data (ciphertext message) into two 32-bit integers v0 / v1 and a 128-bit key ( H final (Decomposed into four 32-bit integers k0 / k1 / k2 / k3) Perform 64 rounds of repeated operations: starting from the ciphertext, the sum is initially delta × 64, subtracting delta in reverse order. In each round, v1 is updated first, then the sum is updated, and finally v0 is updated (the operators are the opposite of the encryption). After 64 rounds, the plaintext is restored. The pseudocode execution is as follows: / / Input: 64-bit ciphertext (split into v0, v1), 128-bit key (split into k[0]-k[3]) / / Output: 64-bit plaintext (v0, v1) Function XTEA_Decrypt(v0, v1, k[0..3]): delta = 0x9E3779B9 / / Fixed constant sum = delta × 64 / / The initial summation variable is delta × 64 (0x63644D62). For i from 1 to 64: / / 64 rounds of reverse iteration / / Step 1: Update v1 (the reverse of the third step of encryption, + becomes -) v1 = v1 - ( ((v0<<4) XOR (v0>>5)) + v0 ) XOR (sum + k[(sum>>11)&3]) / / Step 2: Subtract delta from sum sum = sum - delta / / Step 3: Update v0 (the reverse operation of encryption step 1, + becomes -) v0 = v0 - ( ((v1<<4) XOR (v1>>5)) + v1 ) XOR (sum + k[sum&3]) Return (v0, v1) / / Returns plaintext.
[0046] In this embodiment, a "digital fingerprint" is generated on the CAN bus, which communicates with external devices such as diagnostic tools and vehicle control units, by combining a fixed key with a real-time dynamically changing timestamp. The data is then encrypted / decrypted using the XTEA algorithm. This approach balances the real-time nature and low bandwidth characteristics of the CAN bus while providing strong security protection for the vehicle.
[0047] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0048] In one embodiment, Figure 2 This is a detailed flowchart of a communication method for a CAN bus based on dynamic key symmetric encryption according to an embodiment of the present invention. This embodiment is further optimized and extended based on the above embodiments.
[0049] External Device Side Process: Key Generation: The external device has a built-in fixed key seed. It obtains the current time through the timestamp module, inputs the fixed key seed and timestamp into the SHA-256 hash algorithm to generate a "digital fingerprint" (hash value), and takes the first 128 bits (16 bytes) as the dynamic key for this session. Data Encryption: The plaintext message to be sent is input into the XTEA encryption module, encrypted using the dynamic key generated in the previous step, and outputs an encrypted message, which is sent to the CAN bus. The encrypted message is encapsulated into a CAN data frame through the CAN communication module and sent to the CAN bus. Control Unit Side Process: The control unit receives encrypted messages from the bus through the CAN communication module. The control unit also has the same pre-set fixed key seed, obtains the same timestamp as the external device from the heartbeat packet or synchronization mechanism, generates the same dynamic key using SHA-256, inputs the received encrypted message into the XTEA decryption module, decrypts it using the locally generated same dynamic key, and outputs a plaintext message for the control unit to parse and use.
[0050] By using the method of "fixed key seed + timestamp → SHA-256 → dynamic key → XTEA encryption / decryption", a lightweight secure communication system with forward security, replay resistance, and eavesdropping resistance is achieved without modifying the CAN hardware and underlying protocol.
[0051] In one embodiment, see Figure 3The diagram illustrates a real-time communication process between an external device and a vehicle control unit according to an embodiment of the present invention. The external device prepares and sends an encryption request (heartbeat 1), obtains a preset fixed key and current timestamp information 1, inputs both into the SHA-256 splicing module, and after calculation, generates a dynamic session key (referred to as key A) for encrypting this request. Encrypting the request data: The external device uses key A to perform XTEA encryption on the command or data to be sent (i.e., the plaintext of the external device's encryption request). Sending the request: The encrypted data is encapsulated into a CAN frame and sent to the control unit via the bus. The control unit receives and decrypts the request: Upon detecting the encryption request, the control unit's encryption scheduling module immediately synchronizes the key. Using the same fixed key and matching timestamp information 2 (Note: this information must be synchronized with "timestamp information 1," for example, from the same heartbeat cycle), it calculates using its own SHA-256 splicing module to independently generate an identical key A. The control unit uses key A to perform XTEA decryption on the received ciphertext, successfully restoring the original request command from the external device, and performs internal processing. The control unit prepares and sends an encrypted response: In response to the request, the control unit's encryption scheduling module restarts. Using a fixed key and timestamp information 1, it inputs another SHA-256 concatenation module to generate a new dynamic session key (called key B) for the encrypted response. The control unit uses key B to encrypt the processed result data (i.e., the plaintext of the control unit's encrypted response) using XTEA. The encrypted response data is encapsulated into a CAN frame and returned to the external device via the bus. The external device receives and decrypts the response: To process the response, the external device's encryption scheduling module initiates key synchronization. Using the fixed key and timestamp information 1 matching "timestamp information 1," it calculates using the SHA-256 concatenation module to independently generate an identical key B. The external device uses key B to decrypt the received ciphertext response using XTEA, ultimately obtaining the processing result returned by the control unit. Next round key pre-generation: The timestamp information 2 and the corresponding SHA-256 concatenation module at the bottom of the diagram represent preparations for subsequent communication cycles (such as new requests or heartbeat synchronization). The timestamp information 2 may be used for encryption of the next request initiated by the external device (generating key C) and for decryption of the request by the control unit (also generating key C). This ensures that the key is continuously and dynamically updated.
[0052] like Figure 4As shown, the following are embodiments of a communication system based on a CAN bus with dynamic key symmetric encryption provided in this disclosure. These embodiments belong to the same inventive concept as the communication methods based on a CAN bus with dynamic key symmetric encryption described above. For details not described in detail in the embodiments of the communication system based on a CAN bus with dynamic key symmetric encryption, please refer to the embodiments of the communication methods based on a CAN bus with dynamic key symmetric encryption described above.
[0053] A communication system based on dynamic key symmetric encryption for the CAN bus includes: A key seed pre-setting module is used to pre-set the same fixed key seed in external devices and vehicle control units, and to periodically exchange heartbeat packets on the CAN bus, wherein the heartbeat packet includes the sender's current timestamp and verification information; The key generation module is used to generate a dynamic session key by both communicating parties based on the fixed key seed and the received timestamp after receiving the heartbeat packet, using the SHA-256 hash algorithm. The encryption module is used to encrypt the non-heartbeat data to be sent by the communicating party using the dynamic session key and the XTEA algorithm during the heartbeat cycle, and to encapsulate the encrypted data into a CAN data frame for transmission. The decryption module is used by the receiver to perform XTEA decryption on the received encrypted CAN data frame using the same locally generated dynamic session key. The generation of the dynamic session key depends on the timestamp provided by the periodic interactive heartbeat packets, the encryption of the data depends on the dynamic session key generated in real time, and the decryption and encryption of the data use the same key generation mechanism and algorithm.
[0054] Figure 5 This is a schematic diagram of the hardware structure of an electronic device that implements various embodiments of the present invention.
[0055] The communication method based on dynamic key symmetric encryption for CAN bus provided in this application embodiment can be applied to electronic devices. Those skilled in the art will understand that the electronic device structure involved in the embodiments of this invention does not constitute a limitation on the electronic device. An electronic device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. In the embodiments of this invention, the electronic device includes, but is not limited to, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of this application described and / or claimed herein.
[0056] Electronic devices may include processors, external memory interfaces, internal memory, universal serial bus (USB) interfaces, charging management modules, power management modules, batteries, wireless communication modules, audio modules, speakers, microphones, sensor modules, buttons, cameras, displays, and SIM card interfaces, etc.
[0057] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device. In other embodiments of this application, the electronic device may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0058] A processor may include one or more processing units, such as: a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.
[0059] The processor can serve as the nerve center and command center of an electronic device. The controller can generate operation control signals based on the instruction opcode and timing signals to control the fetching and execution of instructions.
[0060] The processor may also include memory for storing instructions and data. In some embodiments, the memory in the processor is a cache memory. This memory can store instructions or data that the processor has just used or that are used repeatedly. If the processor needs to use the instruction or data again, it can retrieve it directly from this memory. This avoids repeated accesses, reduces processor latency, and thus improves system efficiency.
[0061] An external storage interface (ESI) can be used to connect external memory cards, such as microSD cards, to expand the storage capacity of electronic devices. The external memory card communicates with the processor through the ESI to perform data storage functions, such as saving music and video files on the external memory card.
[0062] Internal memory can be used to store computer executable program code, which includes instructions. The processor executes various functional applications and data processing of electronic devices by running the instructions stored in internal memory. Internal memory can include a program storage area and a data storage area. Internal memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0063] Wireless communication functionality in electronic devices can be achieved through antennas, wireless communication modules, modem processors, and baseband processors.
[0064] Wireless communication modules can provide solutions for wireless communication applications in electronic devices, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies.
[0065] Electronic devices can implement audio functions through audio modules, speakers, receivers, microphones, headphone jacks, and application processors.
[0066] Electronic devices can achieve shooting functions through ISPs, cameras, video codecs, GPUs, displays, and application processors.
[0067] Electronic devices can achieve display functions through GPUs, displays, and application processors.
[0068] A GPU is a microprocessor for image processing, connected to the display screen and application processor. GPUs are used to perform mathematical and geometric calculations for graphics rendering. A processor may include one or more GPUs, which execute program instructions to generate or modify display information.
[0069] A display screen is used to display images, videos, etc. A display screen includes a display panel.
[0070] The storage medium provided in this application stores a program product capable of implementing a communication method for a CAN bus based on dynamic key symmetric encryption.
[0071] The communication method of CAN bus based on dynamic key symmetric encryption includes: external devices and the vehicle control unit pre-set the same fixed key seed, and periodically exchange heartbeat packets on the CAN bus, wherein the heartbeat packet includes the sender's current timestamp and verification information; upon receiving the heartbeat packet, both communicating parties generate a dynamic session key based on the fixed key seed and the received timestamp using the SHA-256 hash algorithm; within the heartbeat cycle, the communicating party uses the dynamic session key and the XTEA algorithm to encrypt the non-heartbeat data to be sent, and encapsulates the encrypted data into a CAN data frame for transmission; the receiving party uses the locally generated same dynamic session key to perform XTEA decryption on the received encrypted CAN data frame; wherein the generation of the dynamic session key depends on the timestamp provided by the periodically exchanged heartbeat packets, the encryption of the data depends on the dynamically generated session key in real time, and the decryption and encryption of the data use the same key generation mechanism and algorithm.
[0072] In some possible implementations, the subject matter of this disclosure, namely, a communication method and system based on a dynamically keyed symmetric encrypted CAN bus, can be implemented as a program product comprising program code that, when run on a terminal device, causes the terminal device to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of this disclosure.
[0073] The storage medium disclosed herein may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.
[0074] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A communication method for a CAN bus based on dynamic key symmetric encryption, characterized in that, include: The same fixed key seed is preset in the external device and the vehicle control unit, and heartbeat packets are periodically exchanged on the CAN bus. The heartbeat packets include the sender's current timestamp and verification information. Upon receiving a heartbeat packet, both communicating parties generate a dynamic session key using the SHA-256 hash algorithm based on the fixed key seed and the received timestamp. During the heartbeat cycle, the communicating party uses the dynamic session key and the XTEA algorithm to encrypt the non-heartbeat data to be sent, and encapsulates the encrypted data into a CAN data frame for transmission. The receiver uses the same locally generated dynamic session key to perform XTEA decryption on the received encrypted CAN data frame; The generation of the dynamic session key depends on the timestamp provided by the periodic interactive heartbeat packets, the encryption of the data depends on the dynamic session key generated in real time, and the decryption and encryption of the data use the same key generation mechanism and algorithm.
2. The communication method for CAN bus based on dynamic key symmetric encryption according to claim 1, characterized in that, The heartbeat package includes: The first byte is the heartbeat identifier, the second to seventh bytes are timestamp information, and the eighth byte is the verification byte; wherein, the heartbeat identifier is a first preset value on the external device side and a second preset value on the vehicle control unit side; the verification byte is generated using CRC32 or cumulative checksum method.
3. The communication method for CAN bus based on dynamic key symmetric encryption according to claim 1, characterized in that, A dynamic session key is generated using the SHA-256 hash algorithm, including: The fixed key seed is concatenated with the received timestamp as a byte stream to obtain the concatenated data. Perform a SHA-256 hash operation on the concatenated data to obtain a 32-byte hash value; The first 16 bytes of the 32-byte hash value are extracted and used as the 128-bit dynamic session key required by the XTEA algorithm.
4. The communication method for CAN bus based on dynamic key symmetric encryption according to claim 3, characterized in that, Perform a SHA-256 hash operation on the concatenated data to obtain a 32-byte hash value, including: According to the formula H shavalue = SHA-256(S||T) is used to calculate the SHA-256 hash value; According to the formula H final = Substr 1:16 ( H shavalue Extract the first 16 bytes; In the formula, H shavalue The result of hash value calculation, H final For the final output, Substr 1:16 ( ) represents a truncation operation, indicating that the first 16 bytes of the input byte stream are extracted, SHA-256( ) is the SHA-256 hash function, S is the fixed key seed, T is the timestamp information, and || is the byte stream concatenation operation.
5. The communication method for CAN bus based on dynamic key symmetric encryption according to claim 3, characterized in that, The XTEA algorithm is used to encrypt the non-heartbeat data to be sent, including: Split the 64-bit non-heartbeat plaintext data to be sent into two 32-bit integers; The 128-bit dynamic session key is split into four 32-bit integers; A 64-bit ciphertext is generated by performing 64 rounds of iterative operations with a fixed constant delta, combined with the dynamic session key.
6. The communication method for CAN bus based on dynamic key symmetric encryption according to claim 1, characterized in that, When decrypting a received encrypted CAN data frame using XTEA, if decryption fails using the dynamic session key of the current heartbeat cycle, then the dynamic session key of the previous heartbeat cycle is used for decryption.
7. The communication method for CAN bus based on dynamic key symmetric encryption according to claim 1, characterized in that, The update cycle of the dynamic session key is the same as the interaction cycle of the heartbeat packet.
8. A communication system for a CAN bus based on dynamic key symmetric encryption, characterized in that, include: A key seed pre-setting module is used to pre-set the same fixed key seed in external devices and vehicle control units, and to periodically exchange heartbeat packets on the CAN bus, wherein the heartbeat packet includes the sender's current timestamp and verification information; The key generation module is used to generate a dynamic session key by both communicating parties based on the fixed key seed and the received timestamp after receiving the heartbeat packet, using the SHA-256 hash algorithm. The encryption module is used to encrypt the non-heartbeat data to be sent by the communicating party using the dynamic session key and the XTEA algorithm during the heartbeat cycle, and to encapsulate the encrypted data into a CAN data frame for transmission. The decryption module is used by the receiver to perform XTEA decryption on the received encrypted CAN data frame using the same locally generated dynamic session key. The generation of the dynamic session key depends on the timestamp provided by the periodic interactive heartbeat packets, the encryption of the data depends on the dynamic session key generated in real time, and the decryption and encryption of the data use the same key generation mechanism and algorithm.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the communication method based on dynamic key symmetric encryption of the CAN bus as described in any one of claims 1 to 7.
10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the communication method based on dynamic key symmetric encryption of the CAN bus as described in any one of claims 1 to 7.