Random number symmetric encryption algorithm applied to single-chip microcomputer message communication
By introducing a random number symmetric encryption algorithm into the microcontroller message communication and using random keys and redundant byte segments to form an encryption package, the problems of low encryption efficiency and poor security in the existing technology are solved, and efficient data encryption and decryption are achieved. , enhanced system security.
Patent Information
- Application Number
- CN202310905641.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-24
- Publication Date
- 2024-09-10
AI Technical Summary
Existing symmetric encryption algorithms have problems such as low encryption efficiency, high computing power requirements, and poor security in microcontroller message communication, and the pseudo-random number generation algorithm is vulnerable to attacks, leading to security issues.
Using a random number symmetric encryption algorithm, by introducing random numbers as key extensions, the generated encryption packet consists of a random key byte segment, an encrypted data byte segment, a random redundant byte segment and a random jump byte segment. Utilize XOR operations and jump byte segments to ensure the security of data encryption and decryption.
It improves the efficiency of data encryption and decryption, ensures randomness, is suitable for real-time communication scenarios, increases the difficulty of password cracking, avoids replay attacks, and improves system security.
Smart Images

Figure CN118631482A
Abstract
Description
Technical Field
[0001] The invention relates to a symmetric encryption algorithm, in particular to a random number symmetric encryption algorithm applied to single-chip computer message communication. Background Art
[0002] Historically, commonly used encryption algorithms can be divided into two categories: symmetric encryption algorithms and asymmetric encryption algorithms.
[0003] Commonly used symmetric encryption algorithms include symmetric encryption algorithms based on CTR mode and symmetric encryption algorithms based on CBC mode, but in practice these algorithms have defects such as low encryption efficiency, high computing power requirements, and poor security. At the same time, ordinary pseudo-random number generation algorithms are also vulnerable to attacks, and the quality of random numbers cannot be guaranteed. These technologies have security issues such as being vulnerable to replay attacks. Summary of the invention
[0004] The purpose of the present invention is to provide a random number symmetric encryption algorithm applied to single-chip microcomputer message communication, which introduces random numbers as key expansion to solve the security of the random number symmetric encryption algorithm. The specific scheme is as follows: A random number symmetric encryption algorithm applied to single-chip microcomputer message communication, wherein an encryption party encrypts plain text to generate an encrypted package, and then a decryption party decrypts the encrypted package to obtain decrypted data. During the encryption process of plain text, the plain text is treated as a byte stream of indefinite length, and each byte in the byte stream is encrypted to form an encrypted package; the encrypted package consists of four parts: a random key byte segment, an encrypted data byte segment, a random redundant byte segment, and a random jump byte segment.
[0005] The encrypted data byte segment is obtained by polling the encrypted plaintext byte by byte of the actual key byte segment.
[0006] The random key segment byte segment consists of three parts: a key length byte segment, an actual key byte segment, and an encrypted plaintext jump byte segment; the byte length of the actual key byte segment is determined according to the key length byte segment, the encrypted plaintext jump byte segment determines the position of the encrypted plaintext in the encrypted package, and then the ciphertexts are decrypted one by one according to the actual key byte segment.
[0007] The random jump byte segment is composed of a single byte or multiple bytes, and the random jump byte segment is used as an index to find the random key byte segment from the encrypted packet.
[0008] The algorithm used by the encryption party to encrypt data and generate an encrypted package is as follows: S101, determining the value range of the random jump value according to the plaintext length, comparing the generated XOR random number with all the numbers in the random jump value cache linked list, and if there is no identical number, the random jump value is available; S102, placing the random jump value into a predetermined position in the encrypted package; S103, randomly generate a key length, assuming that the plaintext length is N, the maximum key length P=N / 4, and generate the key length byte segment according to the same algorithm as the random jump value; S104, randomly generating a random key according to the key length; S105, randomly generate an actual jump value of the encrypted plaintext jump byte segment, assuming that the plaintext length is N, the maximum value of the actual jump value of the encrypted plaintext jump byte segment is Q=N / 4, and generate the key length byte segment according to the same algorithm as the random jump value; S106, performing XOR encryption on each bit of the random key byte segment and each bit of the plain text one by one to generate the encrypted data byte segment; S107. Add the random redundant byte segment after the encrypted data byte segment. To ensure that the maximum length of the encrypted packet is twice the length of the plaintext, the length of the redundant byte segment is a random value from 0 to the current available length.
[0009] The steps for processing the random jump byte segment during plaintext encryption are as follows: S201, determining the number of bits of the random jump byte segment according to the plaintext length, the random jump value is set to be within half the length of the plaintext to be encrypted, assuming that the plaintext length is N, then the maximum value of the random jump value is M=N / 2, thereby ensuring that the encrypted packet length after encryption is at most twice the length of the plaintext; S202, determine the number of bits of the random jump byte segment according to the random jump value (0~M), one byte has 8 bits, the jump bit only uses 5 bits as valid bits, and 4 bits are used as valid data bits, so the jump bit value range of 1 byte is 0~15. If the plaintext to be encrypted is long, a multi-byte jump word is used, and there is another bit as a judgment of whether the next byte is a jump word. The 2nd to 5th bits (0~7) in a byte are used as jump bits, and the 6th bit is used to judge whether the next byte is a jump byte. If it is 1, the next bit is still a jump byte, and other non-valid bits are first set to 0; S203, for a multi-byte jump byte segment, determine the jump value represented by each jump byte by using a random number (0-15), accumulate the values to be the real jump value, and count backwards from the last jump byte segment as an index for searching the random key byte segment; S204, parsing the jump bit only requires taking out 1 byte from the fixed jump byte and determining the value represented by the byte according to the 2nd to 5th bits, and then determining whether the next byte is a jump byte according to the 6th bit, parsing the jump value of each jump byte, and accumulating the index of the random key byte segment; S205. Generate an XOR random number for each byte of the jump byte segment, and perform bitwise OR processing on the non-valid bits (0, 1, 7) of each byte.
[0010] The random jump value cache linked list processing steps are as follows: S301, putting each of the random jump values into a linked list, the length of the linked list depends on the selection of the random jump value, for example, if the plaintext length is N, the maximum value of the random jump value is M=N / 2, and the length of the linked list is O=M / 2; S302, when the linked list buffer is full, remove the old jump bit at the head and insert a new random jump value at the tail; S303, when the system is shut down, storing the random jump value linked list in the buffer into a non-volatile memory; S304: When the system is turned on, the random jump value in the non-volatile memory is put back into the running memory linked list to ensure that the jump position is not repeated.
[0011] The algorithm used by the decryption party to decrypt the encrypted package is as follows: S401, finding the random jump byte segment according to the random jump value position agreed upon by both communicating parties, and decrypting the random jump byte segment according to the above encryption algorithm to obtain the random jump value; S402, compare the random jump value with the random jump value in the buffer one by one, if they do not exist, discard the oldest random jump value at the head of the queue and insert the currently parsed random jump value into the end of the queue. If they do exist, it is determined to be an abnormal encrypted packet and discarded; S403, searching for the random key byte segment from the last byte of the random jump byte segment located in the encrypted packet according to the random jump value; S404, parse the key length byte segment, the actual key byte segment, and the encrypted plaintext jump byte segment according to the random key byte segment to obtain the actual key, and find the encrypted data byte segment position backward according to the position of the last bit of the random key byte segment; S405: Decrypt by performing XOR analysis on each bit of the random key byte segment and each bit of the actual key byte segment one by one to obtain plain text.
[0012] The beneficial effects of the present invention are that each random number is subjected to random XOR encryption for data encryption, thereby ensuring the randomness of the random number; introducing jump words and redundant words for encryption, thereby achieving more efficient data encryption and decryption speeds, and being suitable for real-time communication scenarios; using variable-length keys for data encryption, and the key length and the key itself are randomly generated, thereby ensuring that different keys are used for each communication, thereby increasing the difficulty of password cracking and improving the security of the system; occupying a small amount of cache and computing power to encrypt the same plaintext data into different ciphertexts; using the same ciphertext to send to a recipient, the recipient will reject the ciphertext, thereby ensuring system security and avoiding replay attacks. Instruction Manual
[0013] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following introduction is made to the drawings of the embodiments of the present application or the related technical solutions in the prior art. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solutions of the present application. For technical personnel in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0014] Attached Figure 1 The flowchart of the algorithm for generating an encrypted package by encrypting data by the encryption party in a specific embodiment of the present invention; Attached Figure 2 This is a flow chart of a method for processing random jump byte segments during encryption according to a specific embodiment of the present invention; Attached Figure 3 It is a flow chart of a method for processing a random jump value cache linked list in an encryption process according to a specific embodiment of the present invention; Attached Figure 4 The figure is a flow chart of an algorithm for decrypting data in an encrypted package by a decryption party according to a specific embodiment of the present invention. Implementation
[0015] The present invention is further described in detail below.
[0016] The invention generates an encrypted package by encryption by an encryption party, and then decrypts the encrypted package by a decryption party to obtain decrypted data. The encryption of the randomly generated plain text is regarded as a byte stream of indefinite length, and each byte is encrypted. The algorithm of byte-by-byte encryption is conveniently applied to message communication, command communication, and data packet communication. In particular, for services that often use the same plain text to send commands, the algorithm can be used to obtain ciphertexts with different lengths and different bits for a long period of time.
[0017] The encrypted packet consists of four parts: random jump byte segment, random key byte segment, encrypted data byte segment, and redundant random bit. The random jump byte segment consists of a single or multiple bytes. The random jump byte segment is used as an index to find the random key byte segment and find the random key byte segment from the encrypted packet. The random key segment byte segment consists of three parts: key length byte segment, actual key byte segment, and encrypted plaintext jump byte segment. The byte length of the actual key byte segment is determined according to the key length byte segment, and the encrypted plaintext jump byte segment determines the position of the encrypted plaintext in the encrypted packet. Then, according to the actual key byte segment, the ciphertext is decrypted one by one. The encrypted data byte segment is obtained by polling the encrypted plaintext byte by byte in the actual key byte segment.
[0018] Generate a random value and compare it with the items in the historical cache table. If there is a coincidence in the comparison, regenerate it; otherwise, cache the new value and use it as the random key segment offset value. The purpose of caching is to ensure that historical values will not be used in a short period of time, reducing the chance of being cracked. The algorithm used by the encryption party to encrypt data and generate an encrypted package is as follows: S101, determining the value range of the random jump value according to the plaintext length, comparing the generated XOR random number with all the numbers in the random jump value cache linked list, and if there is no identical number, the random jump value is available; S102, placing the random jump value into the agreed position in the encrypted packet (the position is agreed upon by both parties in the communication); S103, randomly generate a key length, assuming that the plaintext length is N, the maximum key length P=N / 4, and generate a key length byte segment according to the same algorithm as the random jump value; S104, randomly generating a random key according to the key length; S105, randomly generate an actual jump value of the encrypted plaintext jump byte segment, set the plaintext length to N, the maximum value of the actual jump value of the encrypted plaintext jump byte segment to Q=N / 4, and generate a key length byte segment according to the same algorithm as the random jump value; S106, performing XOR encryption on each bit of the random key byte segment and each bit of the plaintext one by one to generate an encrypted data byte segment; S107. Add a redundant byte segment of random length after the encrypted data byte segment. To ensure that the maximum length of the encrypted packet is twice the length of the plaintext, the length of the redundant byte segment is a random value from 0 to the current available length.
[0019] The operations used by this encryption algorithm are only addition, subtraction, shift and XOR operations when implemented in the code, which is very convenient to use on microcontroller devices with low computing power.
[0020] The maximum memory occupied by this encryption algorithm is the random jump value cache linked list, which is very small. The random jump value cache linked list processing method is as follows: S201, put each random jump value into a linked list, the length of the linked list depends on the selection of the random jump value, for example, if the plaintext length is N, the maximum value of the random jump value is M=N / 2, and the length of the linked list O is O=M / 2; S202, when the linked list buffer is full, remove the old jump bit at the head and insert a new random jump value at the tail; S203, when the system is shut down, storing the random jump value linked list in the buffer into the non-volatile memory; S204: When the system is turned on, the random jump value in the non-volatile memory is put back into the running memory linked list to ensure that the jump position is not repeated.
[0021] The jump byte segment is processed as follows: S301, determine the number of random jump bits according to the plaintext length, the value of the random jump is set to be within half the length of the plaintext to be encrypted, assuming that the plaintext length is N, then the maximum value of the random jump value is M=N / 2, thereby ensuring that the length of the encrypted packet after encryption is at most twice the length of the plaintext; S302. Determine the number of bits in the jump byte segment according to the random jump value (0~M). A byte has 8 bits, and the jump bit only uses 5 of them as valid bits, of which 4 are valid data bits. Therefore, the value range of the jump bit of a byte is 0~15. If the plaintext to be encrypted is long, a multi-byte jump word is used, and there is another bit as a judgment of whether the next byte is a jump word. The 2nd to 5th bits in a byte (0~7) are used as jump bits, and the 6th bit is used to judge whether the next byte is a jump byte. If it is 1, the next bit is still a jump byte. Other non-valid bits are first set to 0; S303, for a multi-byte jump byte segment, determine the jump value represented by each jump byte by using a random number (0-15), add them up to get the real jump value, and count backwards from the last jump byte segment as an index for searching the random key byte segment; S304, parsing the jump bit only requires taking out 1 byte from the fixed jump byte and determining the value represented by the byte according to the 2nd to 5th bits, and then determining whether the next byte is a jump byte according to the 6th bit, parsing the jump value of each jump byte, and accumulating the index of the random key byte segment; S305. Generate an XOR random number for each byte of the jump byte segment, and perform bitwise OR processing on the non-valid bits (0, 1, 7 bits) of each byte to truly complete the byte processing of the jump byte segment. The purpose of using this method to process the jump byte segment is to introduce random dirty bits into each byte. Only part of a byte is a valid bit, which greatly increases the difficulty of brute force cracking.
[0022] The decryption algorithm used by the decryption party to decrypt the encrypted package: S401, find the random jump field according to the random jump value position agreed upon by the communicating parties, and decrypt the random jump field according to the above encryption algorithm to obtain the random jump value; S402, compare the random jump value with the random jump value in the buffer one by one, if the comparison does not exist, discard the oldest random jump value at the head of the queue and insert the currently parsed random jump value into the end of the queue. If the comparison does exist, it is determined to be an abnormal encrypted packet and discarded; S403, searching for a random key byte segment from the last byte of the random jump field located in the encrypted packet according to the random jump value; S404, parse the random key byte segment to obtain the key length byte segment, the actual key byte segment, and the encrypted plaintext jump byte segment, obtain the actual key, and find the encrypted data byte segment position backward according to the position of the last bit of the random key byte segment; S405: Decrypt by performing XOR analysis on each bit of the random key byte segment and each bit of the actual key byte segment one by one to obtain plain text.
[0023] Since the length of the final generated ciphertext is random, and the ciphertext contains a random number of redundant bytes, and the specific random jump bytes contain dirty bits, the random jump bytes can only be agreed upon by both communicating parties, which greatly reduces the possibility of brute force cracking the encryption algorithm.
[0024] Specific implementation methods are given above, but the present invention is not limited to the described implementation methods. The basic idea of the present invention lies in the above basic scheme. For ordinary technicians in this field, it does not take creative work to design various deformed models, formulas, and parameters according to the teachings of the present invention. Changes, modifications, substitutions, and variations of the implementation methods without departing from the principles and spirit of the present invention still fall within the scope of protection of the present invention.
Claims
1. A random number symmetric encryption algorithm applied to single-chip microcomputer message communication, wherein the encryption party encrypts the plain text to generate an encrypted package, and then the decryption party decrypts the encrypted package to obtain decrypted data, characterized in that: During the encryption process of randomly generated plaintext, the plaintext is treated as a byte stream of indefinite length, and each byte in the byte stream is encrypted to form an encrypted package; the encrypted package consists of four parts: a random key byte segment, an encrypted data byte segment, a random redundant byte segment, and a random jump byte segment.
2. The random number symmetric encryption algorithm applied to single-chip microcomputer message communication according to claim 1 is characterized in that: The encrypted data byte segment is obtained by polling the encrypted plaintext byte by byte of the actual key byte segment.
3. The random number symmetric encryption algorithm for single-chip microcomputer message communication according to claim 1 is characterized in that: The random key segment byte segment consists of three parts: a key length byte segment, an actual key byte segment, and an encrypted plaintext jump byte segment; the byte length of the actual key byte segment is determined according to the key length byte segment, the encrypted plaintext jump byte segment determines the position of the encrypted plaintext in the encrypted package, and then the ciphertexts are decrypted one by one according to the actual key byte segment.
4. The random number symmetric encryption algorithm applied to single-chip microcomputer message communication according to claim 3, characterized in that: The random jump byte segment is composed of a single byte or multiple bytes, and the random jump byte segment is used as an index to find the random key byte segment from the encrypted packet.
5. The random number symmetric encryption algorithm for single-chip microcomputer message communication according to claim 4, characterized in that: The algorithm used by the encryption party to encrypt data and generate an encrypted package is as follows: S101, determining the value range of the random jump value according to the plaintext length, comparing the generated XOR random number with all the numbers in the random jump value cache linked list, and if there is no identical number, the random jump value is available; S102, placing the random jump value into a predetermined position in the encrypted package; S103, randomly generate a key length, assuming that the plaintext length is N, the maximum key length P=N / 4, and generate the key length byte segment according to the same algorithm as the random jump value; S104, randomly generating a random key according to the key length; S105, randomly generate an actual jump value of the encrypted plaintext jump byte segment, assuming that the plaintext length is N, the maximum value of the actual jump value of the encrypted plaintext jump byte segment is Q=N / 4, and generate the key length byte segment according to the same algorithm as the random jump value; S106, performing XOR encryption on each bit of the random key byte segment and each bit of the plain text one by one to generate the encrypted data byte segment; S107. Add the random redundant byte segment after the encrypted data byte segment. To ensure that the maximum length of the encrypted packet is twice the length of the plaintext, the length of the redundant byte segment is a random value from 0 to the current available length.
6. The random number symmetric encryption algorithm for single-chip microcomputer message communication according to claim 5, characterized in that: The steps for processing the random jump byte segment during plaintext encryption are as follows: S201, determining the number of bits of the random jump byte segment according to the plaintext length, the random jump value is set to be within half the length of the plaintext to be encrypted, assuming that the plaintext length is N, then the maximum value of the random jump value is M=N / 2, thereby ensuring that the encrypted packet length after encryption is at most twice the length of the plaintext; S202, determine the number of bits of the random jump byte segment according to the random jump value (0~M), one byte has 8 bits, the jump bit only uses 5 bits as valid bits, and 4 bits are used as valid data bits, so the jump bit value range of 1 byte is 0~15. If the plaintext to be encrypted is long, a multi-byte jump word is used, and there is another bit as a judgment of whether the next byte is a jump word. The 2nd to 5th bits (0~7) in a byte are used as jump bits, and the 6th bit is used to judge whether the next byte is a jump byte. If it is 1, the next bit is still a jump byte, and other non-valid bits are first set to 0; S203, for a multi-byte jump byte segment, determine the jump value represented by each jump byte according to a random number (0-15), add them up to get the real jump value, and count backwards from the last jump byte segment as an index for searching the random key byte segment; S204, parsing the jump bit only requires taking out 1 byte from the fixed jump byte and determining the value represented by the byte according to the 2nd to 5th bits, and then determining whether the next byte is a jump byte according to the 6th bit, parsing the jump value of each jump byte, and accumulating the index of the random key byte segment; S205. Generate an XOR random number for each byte of the jump byte segment, and perform bitwise OR processing on the non-valid bits (0, 1, 7) of each byte.
7. The random number symmetric encryption algorithm for single-chip microcomputer message communication according to claim 6 is characterized in that: The random jump value cache linked list processing steps are as follows: S301, putting each of the random jump values into a linked list, where the length of the linked list depends on the selection of the random jump value; S302, when the linked list buffer is full, remove the old jump bit at the head and insert a new random jump value at the tail; S303, when the system is shut down, storing the random jump value linked list in the buffer into a non-volatile memory; S304: When the system is turned on, the random jump value in the non-volatile memory is put back into the running memory linked list to ensure that the jump position is not repeated.
8. The random number symmetric encryption algorithm for single-chip microcomputer message communication according to claim 7, characterized in that: The algorithm used by the decryption party to decrypt the encrypted package is as follows: S401, finding the random jump byte segment according to the random jump value position agreed upon by both communicating parties, and decrypting the random jump byte segment according to the above encryption algorithm to obtain the random jump value; S402, comparing the random jump value with the random jump value in the buffer one by one, if the random jump value does not exist, discarding the oldest random jump value at the head of the queue, inserting the currently parsed random jump value into the tail of the queue, if the random jump value does exist, determining that it is an abnormal encrypted packet and discarding it; S403, searching for the random key byte segment from the last byte of the random jump byte segment located in the encrypted packet according to the random jump value; S404, parse the key length byte segment, the actual key byte segment, and the encrypted plaintext jump byte segment according to the random key byte segment to obtain the actual key, and find the encrypted data byte segment position backward according to the position of the last bit of the random key byte segment; S405: Decrypt by performing XOR analysis on each bit of the random key byte segment and each bit of the actual key byte segment one by one to obtain plain text.
