Communication method and device, electronic device and storage medium
By hashing and truncating messages on the communication end of the industrial control system, communication data packets are generated, and the problem of message authentication code occupies network resources is solved, and the effect of reducing network resource consumption is achieved while ensuring transmission reliability. .
Patent Information
- Application Number
- CN202211731296.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2042-12-30
AI Technical Summary
In industrial control systems with limited resources, message authentication codes occupy a large amount of network resources, resulting in excessive consumption of network resources.
By obtaining the current message and historical message on the first communication end, filtering out the target message, hashing, generating the first hash verification code, and truncating the processing according to the verification code length, the second hash verification code is obtained. Then, based on the subscript information of the current message, the second hash verification code, and the target message, a communication data packet is generated and sent.
It reduces the transmission bandwidth occupied by message verification code, reduces the consumption of network resources, and retains part of the verification information that has been sent normally in history, enhancing the reliability of data transmission.
Smart Images

Figure CN116132059B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of industrial control technology, and in particular to a communication method and device, an electronic device, and a storage medium. Background Art
[0002] The message authentication code (MAC code) in the network is used by the message receiver to verify the source of the message. It is an indispensable part of the message sending and receiving during the communication process. Therefore, the message authentication code attached to each message to be sent will take up space, making the data packet that needs to be transmitted on the link larger. And usually, for a single message, its message authentication code usually needs to reach 128 bits to achieve the minimum security level, which means that each message to be sent needs an additional 16 bytes of MAC code. In a resource-constrained environment, for example, some messages in an industrial control system are as small as a single byte, so a large part of the packet load will be occupied by the message authentication code, which greatly increases the consumption of network resources. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to provide a communication method and device, an electronic device and a storage medium, which can reduce the consumption of network resources while ensuring the reliability of network transmission.
[0004] To achieve the above object, a first aspect of an embodiment of the present application provides a communication method, the method comprising:
[0005] Get the current message and sent historical messages for which the hash verification code is to be generated;
[0006] Filtering target messages from the historical messages;
[0007] Performing hash processing on the current message and the target message to obtain a first hash verification code;
[0008] Obtain the length of the first hash verification code to obtain the verification code length;
[0009] According to the length of the verification code, the first hash verification code is shortened to obtain a second hash verification code;
[0010] Generate a communication data packet according to the current message, the second hash verification code and the subscript information of the target message;
[0011] The communication data packet is sent to the second communication end.
[0012] In some embodiments of the first aspect, the filtering out the target message from the historical messages includes:
[0013] If the number of the historical messages is within a preset first threshold range, each of the historical messages is used as the target message;
[0014] If the number of messages is within a preset second threshold range, a preset number of messages are selected from the historical messages and are all used as the target messages.
[0015] In some embodiments of the first aspect, the truncating the first hash verification code according to the verification code length to obtain the second hash verification code includes:
[0016] When the length of the verification code is greater than a preset truncation length, bits of the truncation length are continuously truncated from the first hash verification code to obtain a second hash verification code.
[0017] In some embodiments of the first aspect, the method further comprises:
[0018] Get the current message to be resent;
[0019] Obtaining a third hash verification code according to the current message to be resent;
[0020] Generate a retransmission data packet according to the third hash verification code and the current message to be retransmitted;
[0021] The retransmitted data packet is sent to the second communication end.
[0022] According to some embodiments of the second aspect of the present application, a communication method is provided, which is applied to a second communication terminal. The method includes:
[0023] Receiving a communication data packet sent from the first communication terminal; wherein the communication data packet is generated by the method described in the first aspect;
[0024] Parsing the communication data packet to obtain the current message, the second hash verification code and the subscript information;
[0025] The communication data packet is verified according to the index information, the second hash verification code and the current message.
[0026] In some embodiments of the second aspect, the verifying the communication data packet according to the index information, the second hash verification code and the current message includes:
[0027] According to the index information, the target information is read from the history cache;
[0028] Obtaining a first verification hash verification code according to the current message and the target information;
[0029] Matching the first verification hash verification code with the second hash verification code;
[0030] When the first verification hash verification code and the second hash verification code do not match, a resending process is entered.
[0031] In some embodiments of the second aspect, the retransmission process includes:
[0032] Storing the current message in a suspicious message buffer;
[0033] When the target message exists in the suspicious message buffer area, request the first communication end to resend the current message.
[0034] To achieve the above-mentioned purpose, a third aspect of an embodiment of the present application provides a communication device, the communication device comprising:
[0035] An acquisition module, the acquisition module is used to acquire the current message for which a hash verification code is to be generated and the sent historical messages;
[0036] A selection module, the selection module is used to filter out target messages from the historical messages;
[0037] A hash processing module, the hash processing module is used to perform hash processing on the current message and the target message to obtain a first hash verification code;
[0038] A truncation module, the truncation module is used to obtain the length of the first hash verification code to obtain the verification code length; and obtain a second hash verification code according to the verification code length and the first hash verification code;
[0039] A generation module, the generation module is used to generate a communication data packet according to the current message, the second hash verification code and the subscript information of the target message;
[0040] An interaction module, wherein the interaction module is used to send the communication data packet to the second communication end.
[0041] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the communication method described in the first aspect when executing the computer program.
[0042] To achieve the above-mentioned purpose, the fifth aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium and stores a computer program. When the computer program is executed by a processor, the method described in the first aspect is implemented.
[0043] The communication method and device, electronic device and storage medium proposed in the present application generate a first hash verification code by jointly generating the current message and target information of the verification code to be generated at the first communication end, and the first hash verification code contains the verification information of the message that has been sent normally in the past. When the first hash verification code is truncated to obtain the second hash verification code, the transmission bandwidth occupied by the message verification code can be reduced to reduce the loss of network resources and at the same time retain part of the verification information of the message that has been sent normally in the past. Therefore, when the second communication end receives the communication data packet, it can judge whether the current message is received normally based on the target message that has been received in the past and the current message that is currently received, thereby enhancing the reliability of data transmission. Compared with the related art, the embodiment of the present application can reduce the consumption of network resources while ensuring the reliability of network transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 is a flow chart of the communication method provided in the embodiment of the present application applied to the first communication terminal;
[0045] Figure 2 It is a flowchart of a specific embodiment of message authentication performed by the first communication terminal in the communication method provided in the embodiment of the present application;
[0046] Figure 3 It is a schematic diagram of judging message processing of the first communication terminal in the communication method provided in an embodiment of the present application;
[0047] Figure 4 It is a flowchart of a specific embodiment of the retransmission process of the first communication end in the communication method provided in the embodiment of the present application;
[0048] Figure 5 is a flow chart of the communication method provided in the embodiment of the present application applied to the second communication terminal;
[0049] Figure 6 It is a flowchart of a specific embodiment of the second communication end performing parsing verification in the communication method provided in the embodiment of the present application;
[0050] Figure 7 It is a schematic diagram of a verification process of a specific embodiment of a retransmission process performed by a second communication terminal in a communication method provided in an embodiment of the present application;
[0051] Figure 8 It is a schematic diagram of the overall flow of a specific embodiment of the communication method provided in the embodiment of the present application;
[0052] Fig. 9 is a module schematic diagram of a communication method provided in an embodiment of the present application applied to a communication device corresponding to a first communication terminal;
[0053] Fig.10is a module schematic diagram of the communication method provided in an embodiment of the present application applied to a communication device corresponding to a second communication terminal;
[0054] Fig.11 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0058] The message authentication code (MAC code) in the network is used by the message receiver to verify the source of the message, so the message authentication code attached to each message to be sent will take up space, making the data packet that needs to be transmitted on the link larger. And usually, for a single message, its message authentication code usually needs to reach 128 bits to achieve the minimum security level, that is, each message to be sent needs to add an additional 16 bytes of MAC code. In a resource-constrained environment, for example, some messages in an industrial control system are as small as a single byte, so a large part of the load of the packet will be occupied by the message authentication code, which greatly increases the consumption of network resources. However, the message authentication code is one of the indispensable means to ensure the reliability of network transmission in network communication. Therefore, there is an urgent need for a method that can reduce the consumption of network resources while ensuring the reliability of network transmission. Based on this, the present application provides a communication method and device, an electronic device and a storage medium, which can reduce the consumption of network resources while ensuring the reliability of network transmission.
[0059] The communication method and device, electronic device and storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the communication method in the embodiments of the present application is described.
[0060] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0061] It should be noted that the principle of the message authentication code is that the sender and receiver of the message share a key k. Assuming that the sender wants to send a message m to the receiver, the sender calculates: mac_code = hash(m,k).
[0062] Where hash is a hash function, and hash(m,k) means taking m and k as inputs and calculating the hash value. Then mac_code is sent to the receiver together with the MAC code of message m. After receiving it, the receiver also calculates the value of hash(m,k) and compares the calculation result with the received mac_code. If they are consistent, it is considered that message m does come from the expected sender and has not been tampered with, so message m can be received. Otherwise, it is considered that the message does not come from the expected sender, or the message has been tampered with during transmission, and message m should be discarded.
[0063] It should be noted that the process of hash authentication usually includes two parts: pre-setting the key and verifying the sending and receiving of messages. The pre-setting of the key must be completed before the device is deployed on the network. After the pre-setting of the key, each pair of devices that need to communicate will share the pre-setting key to calculate the MAC code for communication between the two devices. The present application mainly focuses on the part of verifying the sending and receiving of messages, and no further details will be given on the pre-setting of the key.
[0064] Figure 1 is an optional flow chart of the communication method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to the following steps:
[0065] Reference Figure 1 As shown, according to the communication method applied to the first communication terminal provided by the present application, the method includes:
[0066] Step S110: Obtain the current message for which a hash verification code is to be generated and the sent historical messages.
[0067] It should be noted that historical messages can be read from the cache, and the number of historical messages read each time is less than or equal to the message threshold. When the number of sent messages is less than the message threshold, the historical messages are a collection of all sent messages. When the number of sent messages exceeds or equals the message threshold, the number of historical messages is the message threshold. For example, if the message threshold is set to 9, when the current message is the 10th message, 9 sent messages will be taken as historical messages.
[0068] It should be noted that, in some embodiments, the historical message is a collection of multiple messages sent continuously before the current message. Assuming that the current message is the Kth message and the number of historical messages is N, the historical messages include the K-1th, K-2th, ..., KNth messages. It should be noted that the current message is not a message requested to be resent by the second communication terminal.
[0069] It should be noted that, in some embodiments, each current message needs to generate a verification code. In other embodiments, the current message only needs to generate a hash verification code at intervals.
[0070] Step S120: Filter out target messages from historical messages.
[0071] It should be noted that there is at least one target message, and illustratively, in some embodiments, the number of target messages is set to 3. In this regard, those skilled in the art may selectively set it according to actual needs.
[0072] Step S130: Perform hash processing on the current message and the target message to obtain a first hash verification code.
[0073] It should be noted that, refer to Figure 2 As shown, assuming that there are multiple target messages, namely m a ,m b ,m c , then the first hash verification code is mac_code=hash(m i ,m a ,m b ,m c ), where m i For the current message.
[0074] Step S140: Obtain the length of the first hash verification code to obtain the verification code length.
[0075] Step S150: shorten the first Hash verification code according to the length of the verification code to obtain a second Hash verification code.
[0076] It should be noted that the truncation process is used to ensure that the length of the second hash verification code is the truncated length, so that when the length of the first hash verification code is very long, the length of the second hash verification code is shorter, thereby reducing network energy consumption.
[0077] It should be noted that the truncation process includes truncating the truncation length bits of the first hash verification code when the verification code length exceeds the truncation length to obtain the second hash verification code. For example, in some embodiments, the truncation length bits are continuously truncated from the first byte of the first hash verification code as the second hash verification code. In other embodiments, the truncation length bits are continuously truncated from the last byte of the first hash verification code as the second hash verification code. The truncation length can be selected based on experience, such as 64.
[0078] It should be noted that, in some embodiments, the truncation process includes filling the bits of the first hash verification code that are shorter than the truncation length with a fixed value to obtain a second hash verification code when the length of the verification code does not meet the truncation length.
[0079] For example, refer to Figure 2 As shown, when the length of the first hash verification code mac_code exceeds 64 bits, the first 64 bits of mac_code are intercepted as the new mac_code. When the length of mac_code is less than 64 bits, the bit "0" is filled behind the mac_code until the mac_code reaches 64 bits.
[0080] Step S160: Generate a communication data packet according to the current message, the second hash verification code and the subscript information of the target message.
[0081] It should be noted that, by sending the index information to the second communication end, the second communication end can verify the general data packet by extracting the target information from the normal messages that have been received and passed verification in the past based on the index information.
[0082] It should be noted that the subscript information is used to identify the target message.
[0083] Step S170: Send the communication data packet to the second communication end.
[0084] Therefore, the first hash verification code is generated by combining the current message and the target information for which the verification code is to be generated at the first communication terminal. At this time, the first hash verification code contains the verification information of the message that has been normally sent in the past. When the first hash verification code is truncated to obtain the second hash verification code, the transmission bandwidth occupied by the message verification code can be reduced to reduce the loss of network resources and at the same time retain part of the verification information of the message that has been normally sent in the past. Therefore, when the second communication terminal receives the communication data packet, it can judge whether the current message is received normally based on the target message that has been received in the past and the current message that is currently received, thereby enhancing the reliability of data transmission. Compared with the related art, the embodiment of the present application can reduce the consumption of network resources while ensuring the reliability of network transmission.
[0085] The principles of the embodiments of the present application that can reduce network resource consumption while ensuring network transmission reliability are as follows: (1) Reliability is improved by sharing MAC codes by multiple messages to reduce the number of retransmissions and thereby reduce the number of MAC codes; (2) The data volume of a single MAC code is reduced by truncating the MAC code; and (3) Security is not reduced while using the above-mentioned data volume reduction measures by associating one message with multiple MAC codes.
[0086] It should be noted that in wireless industrial control networks, a large number of messages are often sent one-way (from the control unit to the receiving unit), so the receiving unit can accumulate multiple messages for verification. Therefore, the embodiments of the present application can reduce bandwidth usage without affecting actual use when bandwidth resources are limited, especially in industrial control networks.
[0087] It is understandable that step S120, filtering out the target message from the historical messages, includes:
[0088] If the number of historical messages is within a preset first threshold range, each message in the historical messages is used as a target message;
[0089] If the number of messages is within a preset second threshold range, a preset number of messages are selected from the historical messages and are all used as target messages.
[0090] It should be noted that the preset number is less than the lower limit of the second threshold range. The first threshold range is 0 to the preset number.
[0091] For example, taking the preset number as 3 and the message threshold as 9, the current message m is read. i The subscript i of the message is 9, when i>9, the number of historical messages is 9, within the second threshold range, the historical messages include: m i-9 、m i-8 、m i-7 ,...,m i-1 ; At this time, from mi-9 、m i-8 、m i-7 ,...,m i-1 Randomly select 3 as the target messages, which are m a 、m b 、m c ; When i>4 and i≤9, the number of historical messages is still within the second threshold, then randomly select m a 、m b 、m c In this way, the target message selected each time is the target message with the largest preset number associated with the current message being sent, thereby further improving reliability.
[0092] It should be noted that random selection can be implemented using an existing random algorithm, and the embodiments of the present application will not be described in detail here.
[0093] It is understandable that step S140, truncating the first hash verification code according to the verification code length to obtain the second hash verification code, includes:
[0094] When the length of the verification code is greater than a preset truncation length, bits of the truncation length are continuously truncated from the first hash verification code to obtain a second hash verification code.
[0095] It should be noted that the continuous interception may start from the first byte of the first hash verification code. In other embodiments, the continuous interception may also start from the last byte of the first hash verification code.
[0096] It is understood that the method further comprises:
[0097] Get the current message to be resent;
[0098] Obtain a third hash verification code according to the current message to be resent;
[0099] Generate a retransmission data packet according to the third hash verification code and the current message to be retransmitted;
[0100] The retransmission data packet is sent to the second communication end.
[0101] It should be noted that the processing process of the current message to be resent is the message resending process of the first communication end, and the processing process of the current message is the normal message sending process. For the first communication end, including the message resending process and the normal message sending process, before each current message is sent, refer to Figure 3 As shown, it is determined at the beginning whether it is a normal message sending process or a message resending process. If it is a normal message sending process, it enters the normal message sending process and executes steps S110 to S170. If it is determined to be a message resending process, it enters the message resending process.
[0102] It should be noted that, in some embodiments, the first communication end is provided with a cache for caching the current message that has been sent. The second communication end gives the subscript of the retransmitted second message to the first communication end. The first communication end takes out the message with the same subscript from the cache based on the subscript as the current message to be retransmitted, and enters the message retransmission process.
[0103] It should be noted that the third hash verification code is only related to the current message to be resent, so the second communication end can directly perform verification when receiving the resent data packet, thereby simplifying the verification process. At this time, compared with each current message to be resent generating a hash verification code only related to it, when there is no link failure, the solution of the present application can reduce the transmission bandwidth occupied by the hash verification code, thereby reducing network energy consumption.
[0104] For example, refer to Figure 4 As shown, according to the index i of the resent message fed back by the message receiver (ie, the second communication end), the message m is taken out from the sent message queue. i , calculate the MAC code mac_code = hash (m i ). At this time, according to the MAC code and the message m is taken out i The generated data packet is resent to the second communication end.
[0105] Understandably, referring to Figure 5 As shown, in some embodiments, according to the communication method applied to the second communication terminal according to the present application, the method includes:
[0106] Step S210: receiving a communication data packet sent from a first communication terminal, where the communication data packet is generated by the communication method of the first communication terminal.
[0107] Step S220: parse the communication data packet to obtain the current message, the second hash verification code and the index information.
[0108] Step S230: verify the communication data packet according to the index information, the second hash verification code and the current message.
[0109] Therefore, the first hash verification code is generated by combining the current message and the target information for which the verification code is to be generated at the first communication terminal. At this time, the first hash verification code contains the verification information of the message that has been normally sent in the past. When the first hash verification code is truncated to obtain the second hash verification code, the transmission bandwidth occupied by the message verification code can be reduced to reduce the loss of network resources and at the same time retain part of the verification information of the message that has been normally sent in the past. Therefore, when the second communication terminal receives the communication data packet, it can judge whether the current message is received normally based on the target message that has been received in the past and the current message that is currently received, thereby enhancing the reliability of data transmission. Compared with the related art, the embodiment of the present application can reduce the consumption of network resources while ensuring the reliability of network transmission.
[0110] It should be noted that, when the verification fails in step S230 and the retransmission condition is met, the second communication end requests the first communication end to retransmit the current message to ensure the reliability of the transmission.
[0111] It is understandable that, in some embodiments, step S230, verifying the communication data packet according to the index information, the second hash verification code and the current message, includes:
[0112] According to the index information, the target information is read from the history cache;
[0113] According to the current message and the target information, a first verification hash verification code is obtained;
[0114] Matching the first verification hash verification code with the second hash verification code;
[0115] When the first verification hash verification code and the second hash verification code do not match, the resending process is entered.
[0116] It should be noted that the history cache is used to cache the current message that has passed the verification. When the first verification hash verification code and the second hash verification code match, the current message is stored in the history cache. The first verification hash verification code and the second hash verification code match, indicating that the second verification hash verification code obtained by performing the same truncation process on the first verification hash verification code is consistent with the second hash verification code.
[0117] It should be noted that as more verified current messages are stored in the history cache, the messages stored earlier will lose their verification function and need to be removed from the history cache to ensure that there is enough space in the history cache to store new verified current messages. Figure 6 As shown, assuming that the maximum consecutive subscript in the current history buffer is i, all messages with subscript i-9 are removed.
[0118] Exemplarily, taking the target message quantity set to 3 and randomly obtained from the first 9 messages of the current message as an example, the parsing process of the second communication end is as follows Figure 6 as shown:
[0119] The recipient (i.e., the second communication end) receives the message m i and the MAC code mac_code and the message subscripts a, b, c associated with the MAC code, and determines whether 9 ≤ a < b < c ≤ i holds (i.e., verifies whether the subscripts are legal). When the subscript verification is legal, read m a , m b , m c from the message buffer to be verified (i.e., the historical buffer), and calculate h = hash(m i , m a , m b , m c )(i.e., the first verification hash verification code), and determines whether h = hash(m i , m a , m b , m c ) holds (i.e., whether the truncated result of h = hash(m i , m a , m b , m c ) with the same truncation rule as the first hash verification code is the same as the second hash verification code. If they are the same, the verification is successful; if they are different, the verification fails). When the verification is successful, store m i in the message buffer to be verified. In some other embodiments, as shown in Figure 6 , also remove all messages in the message buffer to be verified with subscripts less than i - 9 to remove messages that cannot assist in verification.
[0120] It can be understood that in some embodiments, the retransmission process includes:
[0121] Store the current message in the suspicious message buffer;
[0122] When there is a target message in the suspicious message buffer, request the first communication end to retransmit the current message.
[0123] Exemplarily, as shown in Figure 6 , when storing m i (i.e., the current message) in the suspicious message buffer, verify whether there is any message in m a , m b , m c . If so, request the sender (i.e., the first communication end) to retransmit the message (i.e., m i ).
[0124] It should be noted that after the second communication end receives the retransmitted data packet and parses it, the message in the suspicious message buffer area will be removed.
[0125] It should be noted that when there are multiple target messages, at least one of them means that there are two possibilities for the current message to cause an exception, and it needs to be resent.
[0126] It should be noted that, refer to Figure 7 As shown, after receiving the retransmitted current message, the second communication end will perform a hash check on it. If the check fails, it will continue to request retransmission until the current message is successfully verified. i And MAC code mac_code, calculate h = hash (m i ), judge h=hash(m i ) is legal, if legal, receive message m i If it is illegal, request the sender to resend m i information.
[0127] It should be noted that the above method describes the operations when the first communication end is the sender and the second communication end is the receiver. In some embodiments, the first communication end can also perform the operations of the second communication end as the receiver, and the second communication end can also perform the operations of the sender in the first communication end as the sender. Figure 8 shown.
[0128] For example, the first communication end is the sender and the second communication end is the receiver. Figure 8 As shown, the sender calculates the MAC code (i.e., the second hash verification code) before sending the message, and the first communication end and the second communication end send and receive the message and MAC code respectively; the receiver verifies the MAC code, and if the receiver believes that a message has not passed the MAC code verification, it notifies the sender to resend the message.
[0129] Understandably, referring to Fig. 9 As shown, a communication device provided according to an embodiment of the present application includes:
[0130] The acquisition module 110 is used to acquire the current message for which the hash verification code is to be generated and the sent historical messages;
[0131] A selection module 120, the selection module 120 is used to filter out a target message from historical messages;
[0132] A hash processing module 130, the hash processing module 130 performs hash processing on the current message and the target message to obtain a first hash verification code;
[0133] The truncation module 140 is used to obtain the length of the first hash verification code to obtain the verification code length; and obtain the second hash verification code according to the verification code length and the first hash verification code;
[0134] A generating module 150, the generating module 150 is used to generate a communication data packet according to the current message, the second hash verification code and the subscript information of the target message;
[0135] The interaction module 160 is used to send the communication data packet to the second communication end.
[0136] It should be noted that, in some embodiments, referring to Fig.10 As shown, the embodiment of the present application also provides a communication device including:
[0137] The receiving module 210 is used to receive a general data packet sent from the first communication end, and the general data packet is processed by the first communication end through the acquisition module 110, the selection module 120, the hash processing module 130, the truncation module 140 and the generation module 150 respectively.
[0138] The parsing module 220 is used to parse the communication data packet to obtain the current message, the second hash verification code and the subscript information.
[0139] Verification module 230, verification module 230 is used to verify the communication data packet according to the index information, the second hash verification code and the current message.
[0140] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above communication method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0141] See also Fig.11 , Fig.11 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0142] The processor 301 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0143] The memory 302 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 302 can store an operating system and other applications. When the technical solution provided in the embodiments of this specification is implemented by software or firmware, the relevant program code is stored in the memory 302, and the processor 301 calls and executes the communication method of the embodiments of this application;
[0144] Input / output interface 303, used to implement information input and output;
[0145] The communication interface 304 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0146] A bus 305 that transmits information between the various components of the device (e.g., the processor 301, the memory 302, the input / output interface 303, and the communication interface 304);
[0147] The processor 301 , the memory 302 , the input / output interface 303 and the communication interface 304 are connected to each other in communication within the device via the bus 305 .
[0148] An embodiment of the present application further provides a storage medium, which is a computer-readable storage medium and stores a computer program. When the computer program is executed by a processor, the above-mentioned communication method is implemented.
[0149] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0150] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0151] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0152] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0153] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0154] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0155] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0156] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0157] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0158] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0159] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0160] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A communication method, characterized in that: Applied to the first communication terminal, the method includes: Get the current message and sent historical messages for which the hash verification code is to be generated; Filtering target messages from the historical messages; Performing hash processing on the current message and the target message to obtain a first hash verification code; Obtain the length of the first hash verification code to obtain the verification code length; According to the length of the verification code, the first hash verification code is shortened to obtain a second hash verification code; Generate a communication data packet according to the current message, the second hash verification code and the subscript information of the target message; The communication data packet is sent to the second communication terminal; wherein the index information is used to enable the second communication terminal to read out the target information from the message buffer area based on the index information to verify the general data packet; when the communication data packet is successfully verified, the second communication terminal stores the current message in the message buffer area to be verified.
2. The communication method according to claim 1, characterized in that: The step of filtering out the target message from the historical messages includes: If the number of the historical messages is within a preset first threshold range, each of the historical messages is used as the target message; If the number of messages is within a preset second threshold range, a preset number of messages are selected from the historical messages and are all used as the target messages.
3. The communication method according to claim 1, characterized in that: The step of truncating the first hash verification code according to the verification code length to obtain a second hash verification code includes: When the length of the verification code is greater than a preset truncation length, bits of the truncation length are continuously truncated from the first hash verification code to obtain a second hash verification code.
4. The communication method according to claim 1, characterized in that: The method further comprises: Get the current message to be resent; Obtaining a third hash verification code according to the current message to be resent; Generate a retransmission data packet according to the third hash verification code and the current message to be retransmitted; The retransmitted data packet is sent to the second communication end.
5. A communication method, characterized in that: Applied to the second communication terminal, the method includes: Receiving a communication data packet sent from a first communication terminal; wherein the communication data packet is generated by the method according to any one of claims 1 to 4; Parsing the communication data packet to obtain the current message, the second hash verification code and the subscript information; Verifying the communication data packet according to the subscript information, the second hash verification code and the current message; the subscript information is used to enable the second communication end to read the target information from the message buffer area based on the subscript information to verify the general data packet; When the communication data packet is successfully verified, the current message is stored in a message buffer area to be verified.
6. The communication method according to claim 5, characterized in that: The verifying the communication data packet according to the index information, the second hash verification code and the current message includes: According to the index information, the target information is read from the history cache; Obtaining a first verification hash verification code according to the current message and the target information; Matching the first verification hash verification code with the second hash verification code; When the first verification hash verification code and the second hash verification code do not match, a resending process is entered.
7. The communication method according to claim 6, characterized in that: The resending process includes: Storing the current message in a suspicious message buffer; When the target message exists in the suspicious message buffer area, request the first communication end to resend the current message.
8. A communication device, characterized in that: The device comprises: An acquisition module, the acquisition module is used to acquire the current message for which a hash verification code is to be generated and the sent historical messages; A selection module, the selection module is used to filter out target messages from the historical messages; A hash processing module, the hash processing module is used to perform hash processing on the current message and the target message to obtain a first hash verification code; A truncation module, the truncation module is used to obtain the length of the first hash verification code to obtain the verification code length; and truncate the first hash verification code according to the verification code length to obtain a second hash verification code; A generation module, the generation module is used to generate a communication data packet according to the current message, the second hash verification code and the subscript information of the target message; An interaction module, wherein the interaction module is used to send the communication data packet to the second communication terminal, wherein the index information is used to enable the second communication terminal to read out the target information from the message buffer area based on the index information to verify the general data packet; when the communication data packet is successfully verified, the second communication terminal stores the current message in the message buffer area to be verified.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the communication method described in any one of claims 1 to 4 and / or any one of claims 5 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the communication method according to any one of claims 1 to 4 and / or the communication method according to any one of claims 5 to 7 is implemented.
Citation Information
Patent Citations
Block chain evidence storage method
CN112954039A
Log storage method and device and log verification method and device suitable for privacy calculation
CN115118507A