A power distribution terminal message encryption transmission method based on a security chip
Patent Information
- Application Number
- CN202611445270.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-17
- Publication Date
- 2026-10-20
AI Technical Summary
[0005]因此,本发明提供了一种基于安全芯片的配电终端报文加密传输方法解决报文密码处理与业务承接关系关联不足以及异常通信条件下安全状态一致性难以保持的问题
[0016]本发明有益效果为:通过将配电通信规约中的业务承接关系、当前序号与链式安全状态共同关联至一次性报文密钥的形成过程,使报文密码处理与业务交互次序建立对应关系,增强报文在重组、错序传输情况下的识别与约束能力,提高业务报文传输的真实性和安全性;通过在接收侧设置主链与候选分支,并在跨越序号连续认证后提交共同确认状态,同时以共同确认状态进行失步恢复和密钥版本切换,使乱序、重复及通信异常情况下的链式安全状态保持受控推进,降低通信双方状态失配和密钥版本不同步的风险,提高配电终端报文加密传输的连续性、稳定性和可靠性。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This invention relates to the field of power communication security technology, and in particular to a method for encrypted transmission of power distribution terminal messages based on a security chip. Background Technology
[0002] With the development of distribution automation and the Internet of Things (IoT) in distribution, the continuous transmission of telemetry, telesignaling, remote control, and parameter configuration messages between distribution terminals and the master station places higher demands on the confidentiality, integrity, and reliability of communication data. Security chips, with their capabilities for secure key storage, cryptographic operations, and authentication, have been gradually applied to distribution terminals. They complete authentication, communication key management, and business message encryption through a hardware cryptographic environment, establishing a secure communication foundation between distribution terminals and the master station. As the frequency of business interactions increases and the network environment becomes more complex, distribution communication security also needs to consider message continuity, recovery from abnormal transmissions, and consistency of communication status during key updates.
[0003] Currently, the relevant message security transmission methods still have the following shortcomings: Message encryption and authentication are mainly implemented around communication keys, message sequence numbers, and message content. The cryptographic processing between different service messages is relatively independent, making it difficult to link the sequential relationship of services stipulated in the power distribution communication protocol with the security status of each message. This means that even after legitimate messages are reassembled or transmitted out of order, there may still be a lack of further constraints on the service interaction position. In addition, in the case of message out-of-order, duplicate, or communication anomalies, early-arriving messages may cause the security status of the receiving side to advance prematurely, while late-arriving messages may not be able to complete authentication according to the original state. At the same time, anomaly recovery and key version switching usually lack a unified mutual confirmation state as a processing boundary, which can easily cause the security status and key version of the communicating parties to be out of sync. Summary of the Invention
[0004] In view of the aforementioned existing problems, the present invention is proposed.
[0005] Therefore, this invention provides a method for encrypted transmission of power distribution terminal messages based on a security chip to solve the problems of insufficient correlation between message cryptography processing and service acceptance, as well as the difficulty in maintaining consistency of security status under abnormal communication conditions.
[0006] To solve the above-mentioned technical problems, the present invention provides the following technical solution: This invention provides a method for encrypted transmission of power distribution terminal messages based on a security chip, comprising: after bidirectional authentication between the power distribution terminal and the master station, the security chip forms a state root key and a chain of security states based on the authentication random number and the key corresponding to the current key version, and records the most recent consecutive acknowledgment sequence number; based on the protocol succession relationship of the message to be transmitted relative to the previous acknowledgment message and the current sequence number, message association information is formed, the chain of security states is advanced to the state corresponding to the current sequence number, a one-time message key is derived based on the state root key, the chain of security states, and the message association information, the service fields are encrypted and authentication information is generated, forming a state-associative encrypted message; the receiving side uses the chain of security states corresponding to the most recent consecutive acknowledgment sequence number as the main chain and the current sequence number as the receiving sequence number to receive the message. When sequence numbers are consecutive, authentication and decryption are performed along the main chain, and the main chain and the most recent consecutive confirmed sequence number are updated. When the received sequence number is ahead, a candidate branch is temporarily advanced from the main chain. After verification, only the chain security state at the end of the candidate branch and the authenticated sequence number are retained, while the main chain remains unchanged. When all sequences crossed by the received sequence number have been authenticated, the message corresponding to the received sequence number is decrypted, the chain security state at the end of the candidate branch is submitted as the common confirmation state, and the main chain and the most recent consecutive confirmed sequence number are updated. Duplicate messages maintain the common confirmation state. When communication is out of sync, the chain security state is restored from the common confirmation state. When the key is updated, the common confirmation state is used as the version switching position. After the new key version is confirmed, the new key version is determined as the current key version. When confirmation fails, the original key version is retained.
[0007] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the step of forming message association information based on the protocol succession relationship of the message to be transmitted relative to the previous acknowledgment message and the current sequence number includes: The protocol succession relationship refers to the sequential connection between the message to be transmitted and the previous confirmation message formed according to the business interaction process stipulated in the power distribution communication protocol. According to the power distribution communication protocol, determine the interaction position of the previous confirmation message and the message to be transmitted in the corresponding business interaction process. Based on the connection order of the corresponding interaction positions, determine the protocol inheritance relationship of the message to be transmitted relative to the previous confirmation message. Encode the protocol inheritance relationship with the current sequence number to form the message association information of the message to be transmitted.
[0008] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the step of advancing the chained security state to the state corresponding to the current sequence number and deriving a one-time message key based on the state root key, the chained security state, and message association information includes: The number of times to advance the chain security state is determined based on the sequence number interval between the current sequence number and the most recent consecutive confirmation sequence number. The chain security state corresponding to the most recent consecutive confirmation sequence number is used as the starting point for advancement. The chain security state is advanced step by step according to the sequence number progression order. Each time it is advanced, the next chain security state is formed based on the state root key, the previous chain security state and the sequence number reached in this advancement, until the current chain security state corresponding to the current sequence number is formed. Based on the root key, the current chain security state, and the message association information, key derivation data corresponding to the current sequence number is generated. The security chip performs key derivation operations on the key derivation data to obtain the one-time message key corresponding to the current sequence number.
[0009] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the step of temporarily advancing from the main chain to form a candidate branch when the received sequence number is ahead includes: The received sequence number is compared with the next sequence number of the most recent consecutive acknowledgment number. If the received sequence number is greater than the next sequence number of the most recent consecutive acknowledgment number, it is determined that the received sequence number is ahead. Keeping the main chain unchanged, the chain security state corresponding to the most recent consecutive confirmation sequence number is used as the starting point of the candidate branch. The chain security state is advanced step by step according to the progressive order from the most recent consecutive confirmation sequence number to the receiving sequence number. The chain security states obtained by each step are associated according to the progressive order of the corresponding sequence number to form a candidate branch. The chain security state corresponding to the receiving sequence number is determined as the chain security state at the end of the candidate branch. The one-time message key is recovered based on the state root key, the chain security state at the end of the candidate branch, and the message association information of the encrypted message associated with the state corresponding to the received sequence number. The authentication information of the corresponding state associated encrypted message is verified based on the recovered one-time message key. If the verification is successful, the received sequence number will be determined as the authenticated sequence number. If the verification fails, the one-time message key will be released and the candidate branch will be withdrawn, while keeping the main chain and the most recent consecutive confirmation sequence number unchanged.
[0010] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the step of authenticating and decrypting along the main chain and updating the main chain and the most recent consecutive confirmation sequence number when the received sequence number is continuous includes: When subsequent encrypted messages associated with the states of each sequence number that have been received arrive, the main chain remains unchanged. The main chain is used as the starting point for advancement. The chain security states are advanced in the order of sequence number progression. The one-time message key is restored in sequence according to the state root key, the chain security states corresponding to each sequence number, and the message association information. The authentication information of the corresponding state-associated encrypted message is verified. When the verification is successful, the corresponding business field is decrypted and the corresponding sequence number is determined as the authenticated sequence number. When all sequence numbers between the most recent consecutive confirmation sequence number and the received sequence number are determined to be authenticated sequence numbers, the one-time message key is recovered based on the state root key, the candidate branch end chain security state, and the message association information corresponding to the received sequence number. The business fields of the state association encrypted message corresponding to the received sequence number are decrypted, the candidate branch end chain security state is submitted as a common confirmation state, and the most recent consecutive confirmation sequence number is updated to the received sequence number.
[0011] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the step of retaining only the chain-like security state of the candidate branch end and the authenticated sequence number after successful verification while keeping the main chain unchanged includes: After the authentication information of the encrypted message associated with the received sequence number is verified, the one-time message key corresponding to the received sequence number is released, the chain security state corresponding to each sequence number after the starting point of the candidate branch and before the end of the candidate branch is cleared, and the chain security state at the end of the candidate branch is retained. Record the chain security state at the end of the candidate branch with the corresponding certified sequence number, maintain the main chain in the chain security state corresponding to the most recent consecutive confirmation sequence number, and keep the most recent consecutive confirmation sequence number unchanged.
[0012] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the step of submitting the candidate branch end chain security state as a common confirmation state includes: The receiving side forms a status confirmation information based on the receiving sequence number and the chain-like security status at the end of the candidate branch, and sends the status confirmation information to the sending side; The sending side determines the corresponding chain security state based on the received sequence number, forms the sending side status confirmation information based on the received sequence number and the corresponding chain security state, and performs consistency verification between the sending side status confirmation information and the received status confirmation information. When the consistency check passes, the sending side determines the chain security state corresponding to the received sequence number as the common confirmation state and returns the status confirmation result. The receiving side determines the chain security state at the end of the candidate branch as the common confirmation state based on the status confirmation result. The sending side and the receiving side update the most recent consecutive confirmation sequence number to the received sequence number. If the consistency check fails, the sending side returns a status confirmation failure result, and the sending side and the receiving side maintain the original joint confirmation status and the most recent consecutive confirmation sequence number.
[0013] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the recovery of the chained security state from the common confirmation state when communication is out of sync includes: When the chain of security states formed by the sending side and the receiving side for the same sequence number after the common confirmation state is inconsistent, communication is determined to be out of sync. Clear the chain of security states that have not yet been committed after the common confirmation state, and take the chain of security states corresponding to the common confirmation state as the recovery starting point, and start to advance the chain of security states again from the next sequence number of the most recent consecutive confirmation number; Based on the chain security state formed by the renewed push, the one-time message key is recovered and the authentication information of the encrypted message associated with the corresponding state is verified. The chain security state corresponding to the highest consecutively authenticated sequence number is determined as the common confirmation state after recovery, and the most recent consecutive confirmation sequence number is updated.
[0014] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the key update uses a common confirmation state as the version switching position, and after the new key version is confirmed, the new key version is determined as the current key version, including: The state root key corresponding to the original key version remains valid. The most recent consecutive confirmation sequence number corresponding to the common confirmation state is used as the version switching position. The security chip forms the state root key corresponding to the new key version based on the key corresponding to the new key version, and uses the chain security state corresponding to the common confirmation state as the starting point for the state advancement of the new key version. The chain security state corresponding to the new key version is advanced in the order of the sequence number following the most recent consecutive confirmation number. A one-time message key is derived based on the state root key, the corresponding chain security state and message association information corresponding to the new key version, and the authentication information of the encrypted message associated with the state corresponding to the new key version is verified. When the authentication information is verified and the corresponding chain security states of the sending and receiving sides are consistent, the new key version is determined as the current key version and the process continues along the corresponding chain security states. If the confirmation is not completed, the root key and common confirmation state corresponding to the original key version remain unchanged.
[0015] As a preferred embodiment of the power distribution terminal message encryption transmission method based on a security chip according to the present invention, the repeated messages maintain a common acknowledgment state, including: If an authenticated sequence number with the same received sequence number exists, the encrypted message associated with the corresponding status will be identified as a duplicate message. For duplicate messages, the chain security state will no longer be advanced, no candidate branch will be formed, and the corresponding authenticated sequence number, the most recent consecutive confirmation sequence number, and the common confirmation state will remain unchanged; The business fields corresponding to duplicate messages will no longer be processed. Subsequent state-associated encrypted messages will continue to be processed in a chain-like security state based on the common confirmation state and the most recent consecutive confirmation sequence number.
[0016] The beneficial effects of this invention are as follows: By associating the service acceptance relationship, current sequence number, and chain security state in the power distribution communication protocol with the formation process of the one-time message key, a correspondence is established between message cryptographic processing and the order of service interaction, enhancing the identification and constraint capabilities of messages in the case of reassembly and out-of-order transmission, and improving the authenticity and security of service message transmission; by setting up a main chain and candidate branches on the receiving side, and submitting a common confirmation state after continuous authentication across sequence numbers, and simultaneously using the common confirmation state for out-of-synchronization recovery and key version switching, the chain security state in the case of out-of-order, duplicate, and communication anomalies is kept under controlled progress, reducing the risk of state mismatch and key version asynchrony between the communicating parties, and improving the continuity, stability, and reliability of encrypted message transmission in power distribution terminals. Attached Figure Description
[0017] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a flowchart of a method for encrypted transmission of messages in a power distribution terminal based on a security chip.
[0019] Figure 2 This is a flowchart for two-way identity authentication and state association encryption.
[0020] Figure 3 Flowchart for receiving sequence number determination and chain-based security status processing.
[0021] Figure 4 A flowchart for jointly confirming status and handling exceptions. Detailed Implementation
[0022] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0023] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of the invention. Therefore, the invention is not limited to the specific embodiments disclosed below.
[0024] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in different places in this specification does not necessarily refer to the same embodiment, nor is it a single or selective embodiment that is mutually exclusive with other embodiments.
[0025] Reference Figures 1-4 This is one embodiment of the present invention, which provides a method for encrypted transmission of power distribution terminal messages based on a security chip, comprising the following steps: S1. After the power distribution terminal and the master station perform two-way identity authentication, the security chip forms a state root key and a chain of security states based on the authentication random number and the key corresponding to the current key version, and records the most recent consecutive confirmation sequence number.
[0026] It should be noted that before the power distribution terminal is put into communication, the protected storage area of the security chip is configured with the power distribution terminal identity identifier, power distribution terminal identity authentication certificate and private key, master station identity authentication certificate, current key version identifier and the key corresponding to the current key version; the master station is configured with the master station identity identifier, master station identity authentication certificate and private key, power distribution terminal identity authentication certificate and the mapping relationship between the key version identifier and the corresponding key; the identity authentication private key is responsible for authentication signature processing, and the key corresponding to the current key version is responsible for state root key derivation processing; the key corresponding to the current key version is a symmetric key that is pre-configured through the power distribution communication key management process and uniquely corresponds to the current key version identifier; the current key version information is transmitted through the key version identifier, and the corresponding key plaintext is not transmitted.
[0027] After the power distribution terminal establishes a communication connection with the master station, the master station calls the password random number generator to generate a master station random number and sends the master station identity identifier and the master station random number to the power distribution terminal. The security chip calls its internal password random number generator to generate a power distribution terminal random number. In this embodiment, both random numbers are 256-bit random data regenerated for each authentication. The power distribution terminal forms an authentication context according to a fixed field order of master station identity identifier, power distribution terminal identity identifier, master station random number, power distribution terminal random number, and current key version identifier. Each field in the authentication context is encoded sequentially with the field length value first and the field content second. The field length value is represented by a fixed byte width that is consistent with the configuration of the power distribution terminal and the master station, so that the boundaries of each field in the authentication context can be uniquely determined. The authentication context is subjected to SM3 digest operation, and the security chip calls the power distribution terminal identity authentication private key to perform SM2 signature to form power distribution terminal identity verification data. The power distribution terminal sends the power distribution terminal identity identifier, power distribution terminal random number, current key version identifier, identity authentication certificate, and identity verification data to the master station.
[0028] The master station confirms the identity of the power distribution terminal based on the power distribution terminal's identity authentication certificate, forms an authentication context according to the same field order, verifies the power distribution terminal's identity verification data using the public key in the certificate, and locates the corresponding key based on the current key version identifier. After the identity verification data is verified and the key version identifier is consistent, the master station calls the master station's identity authentication private key to perform SM2 signing on the digest result of the authentication context, forming the master station's identity verification data, and sends the master station's identity authentication certificate, master station's identity verification data, and current key version identifier to the power distribution terminal.
[0029] The power distribution terminal uses the public key in the master station's authentication certificate to verify the master station's identity verification data and performs a consistency check between the current key version identifier returned by the master station and the current key version identifier stored in the security chip. Both identity verification data cover two identity identifiers, two random numbers, and the current key version identifier. When the master station completes the power distribution terminal's identity verification, the power distribution terminal completes the master station's identity verification, and the key version identifiers match, the two-way identity verification is considered complete. The security chip performs fixed-length encoding on the two random numbers in the order of master station's random number first and power distribution terminal's random number last to form authentication random numbers. The master station forms the same authentication random numbers in the same order. The fixed-length encoding preserves the field boundaries of each random number.
[0030] After two-way authentication is completed, the security chip calls the key corresponding to the current key version to perform state root key derivation; this embodiment uses SM3-based keyed hash operation, and the security chip processes the authentication random number to obtain the state root key, represented as: ; in, Indicates the root key of the state; This indicates the key corresponding to the current key version identifier in the security chip; Indicates a random number for authentication; This represents a keyed hash operation based on SM3. The first term of the operation is the key used in the operation, and the second term is the data to be processed.
[0031] The operation outputs a 256-bit state root key, which is stored in the protected key area of the security chip. The master station uses the key corresponding to the current key version and the key value in the security chip, along with the same authentication random number, to perform the same derivation process to form a state root key consistent with the power distribution terminal.
[0032] After the state root key is formed, the distribution terminal and the master station configure the starting value of the service message sequence number according to the sequence number field format adopted by the distribution communication protocol. In this embodiment, the starting value of the service message sequence number is configured to 1, the previous sequence number 0 is determined as the initial sequence number of this communication, and the current sequence number of the first message to be transmitted is set to 1. The initial sequence number is denoted as... Security chip will The record is the most recent consecutive confirmation sequence number; the most recent consecutive confirmation sequence number represents the maximum sequence number reached when all state-associated encrypted messages corresponding to each sequence number have been continuously authenticated, starting from the initial value of the business message sequence number; at the initialization point when the business message has not yet started to be transmitted, the value 0 indicates that no state-associated encrypted message has completed consecutive confirmation.
[0033] The security chip generates a chain of security states corresponding to the initial sequence number based on the state root key, authentication random number, and initial sequence number, represented as follows: ; in, This indicates the chained security state corresponding to the initial sequence number; Indicates the initial sequence number of this communication; This indicates that the encoding is performed according to a fixed field order: authentication random number first, initial sequence number second.
[0034] The authentication random number uses the fixed-length encoding formed when the two-way authentication is completed. The initial sequence number is encoded using the byte length and byte order of the current sequence number field in the state-associative encrypted message. The byte length and byte order of the current sequence number field are determined according to the power distribution communication protocol. After the initial sequence number is encoded, it participates in the keyed hash operation together with the authentication random number. The operation output is 256 bits of data. The security chip determines the chain security state corresponding to the initial sequence number as the chain security state. The state root key is used as the key for the keyed hash operation. The authentication random number makes the chain security state corresponding to the initial sequence number correspond to this two-way authentication. The initial sequence number gives the chain security state a clear sequence number starting point.
[0035] The security chip associates and stores the current key version identifier, the state root key, the chain security state corresponding to the initial sequence number, and the most recent consecutive confirmation sequence number. The master station forms and stores corresponding records according to the same rules. The chain security state represents the fixed-length cryptographic state corresponding to a specific sequence number, and the chain security state corresponding to the initial sequence number corresponds to the most recent consecutive confirmation sequence number 0. The main chain represents the continuous state path maintained by the receiving side with the chain security state corresponding to the most recent consecutive confirmation sequence number as the starting point. After the record is completed, the state root key participates in the chain security state advancement and one-time message key derivation in subsequent message processing. The chain security state corresponding to the initial sequence number serves as the starting point for advancing the chain security state corresponding to the first business message, and also serves as the starting point of the main chain on the receiving side when no business message has been confirmed. The most recent consecutive confirmation sequence number is used to determine the position of the current sequence number relative to the already continuously confirmed range, and is used to calculate the number of times the chain security state has been advanced. As state-associated encrypted messages are continuously authenticated and the main chain is updated, the most recent consecutive confirmation sequence number and the corresponding chain security state are updated synchronously, so that the sequence number record always points to the chain security state at the end of the current continuous confirmation range.
[0036] S2. Based on the protocol succession relationship of the message to be transmitted relative to the previous confirmation message and the current sequence number, message association information is formed, the chain security state is advanced to the state corresponding to the current sequence number, a one-time message key is derived based on the state root key, chain security state and message association information, the business fields are encrypted and authentication information is generated, and a state-associated encrypted message is formed.
[0037] It should be noted that after two-way authentication is completed and a state root key, a chain of security states corresponding to the initial sequence number, and the most recent consecutive confirmation sequence number are formed, the power distribution terminal generates a message to be transmitted according to the power distribution communication protocol. The message to be transmitted includes a protocol control field and a service field. The protocol control field carries the message type identifier, transmission direction identifier, and service stage identifier, while the service field carries the service data to be transmitted in this service interaction. The power distribution terminal assigns a current sequence number to the message to be transmitted according to the message sending order under the current key version. The first message to be transmitted uses the already determined starting value of the service message sequence number. Subsequently, each time a new message to be transmitted is formed, the sequence number is incremented by 1 based on the previously assigned sequence number, so that different messages to be transmitted correspond to different current sequence numbers. The current sequence number is encoded using the sequence number field length and byte order specified in the power distribution communication protocol.
[0038] When the current sequence number reaches the maximum value that the sequence number field can represent, the next sequence number will not be assigned in the current communication state. The power distribution terminal and the master station will re-perform two-way identity authentication and re-form the authentication random number, the state root key, the chain security state corresponding to the initial sequence number, and the most recent consecutive confirmation sequence number according to the aforementioned rules. Subsequent messages will reset the current sequence number according to the aforementioned business message sequence number starting value configuration rules and continue to be processed based on the re-formed state root key and chain security state.
[0039] The power distribution terminal stores message records that have completed authentication and entered the continuous confirmation range. The message record includes the sequence number of the corresponding message, message type identifier, transmission direction identifier, and service stage identifier. The previous confirmation message represents a message that has been confirmed before the message to be transmitted, according to the service interaction process specified in the power distribution communication protocol. The power distribution terminal retrieves the corresponding previous confirmation message from the message record according to the service interaction process to which the message to be transmitted belongs, and determines the interaction position of the previous confirmation message and the message to be transmitted in the service interaction process.
[0040] The interaction position is determined jointly based on the message type, transmission direction, and service stage specified in the power distribution communication protocol. The message type determines the service action the message undertakes in the service interaction process; the transmission direction determines whether the corresponding service action is sent from the power distribution terminal to the master station or from the master station to the power distribution terminal; and the service stage determines the sequential position of the corresponding service action in the current service interaction process. The power distribution terminal, according to the sequential order of the service actions in the power distribution communication protocol, matches the interaction position of the previous acknowledgment message with the interaction position of the message to be transmitted in the order of the former first and the latter last, forming a protocol inheritance relationship between the message to be transmitted and the previous acknowledgment message. The protocol inheritance relationship includes the interaction position code of the previous acknowledgment message and the interaction position code of the message to be transmitted, which are used to characterize the confirmed service position and the service position that the message to be transmitted has received in the current service interaction process.
[0041] The distribution terminal encodes the protocol acceptance relationship and the current sequence number in a fixed field order to form message association information. During encoding, the interaction position encoding of the previous acknowledgment message is placed first, followed by the interaction position encoding of the message to be transmitted, and then the current sequence number. The field length of the interaction position encoding is determined according to the encoding length of the message type, transmission direction, and service stage in the distribution communication protocol. The field length and byte order of the current sequence number are consistent with the current sequence number field in the message to be transmitted. Each field is encoded sequentially with its length value first and its content last, enabling the receiving side to determine field boundaries according to the same rules. The formed message association information includes the protocol acceptance relationship and the current sequence number. The protocol acceptance relationship defines the service interaction position of the message to be transmitted, and the current sequence number defines the chained security state position corresponding to the message to be transmitted. The message association information is denoted as... ,in, This indicates the current sequence number of the message to be transmitted; the security chip retrieves the most recent consecutive acknowledgment number and its corresponding chained security state, and records the most recent consecutive acknowledgment number as... The sequence number interval between the current sequence number and the most recent consecutive confirmation sequence number represents the number of steps required for the security chip to advance from the chained security state corresponding to the most recent consecutive confirmation sequence number to the state corresponding to the current sequence number, expressed as: ; in, Indicates the number of times the chain of safety states has been advanced; Indicates the most recently confirmed sequence number, subscript This indicates that the corresponding sequence number is at the end of the current consecutive acknowledgment range; when the message to be transmitted is a newly formed service message, the current sequence number is greater than the most recent consecutive acknowledgment number, therefore... It is a positive integer.
[0042] When the current sequence number is the next sequence number after the most recently confirmed sequence number, the security chip performs a state advance; when there are multiple sequence numbers between the current sequence number and the most recently confirmed sequence number, the security chip executes the state advance sequentially in ascending order. Next state advancement.
[0043] The security chip uses the chained security state corresponding to the most recently confirmed sequence number as the starting state for this advancement, and advances sequentially starting from the next sequence number after the most recently confirmed sequence number. During each advancement, the security chip uses the state root key as the key for keyed hashing, encodes the previous chained security state and the sequence number reached in this advancement in a fixed order, and then performs an HMAC-SM3 operation to form the chained security state corresponding to the sequence number reached in this advancement, represented as: ; ; in, This indicates the sequence number reached in this state progression, and the value is determined according to... to The ascending order of the integers is determined; Indicates serial number The corresponding chain of safety states; Indicates serial number The corresponding previous chain of security states.
[0044] During encoding, the previous chain of secure states is listed first, followed by the sequence number reached in the current step. The previous chain of secure states uses the 256-bit length determined during the formation of the state root key, while the sequence number reached in the current step uses the byte length and byte order of the current sequence number field. The chain of secure states formed in each operation continue to participate in the state advancement of the next sequence number until the chain of secure states corresponding to the current sequence number is formed. The security chip associates the successively formed chain of security states with the corresponding sequence numbers, so that each sequence number under the same root key corresponds to a determined chain of security states.
[0045] After the chain of security states corresponding to the current sequence number is formed, the security chip generates key derivation data in the order of the chain of security states corresponding to the current sequence number first, followed by the message association information. The state root key determines the basis for the current communication and the derivation under the current key version. The chain of security states corresponding to the current sequence number determines the state advancement position corresponding to the one-time message key. The message association information determines the service acceptance relationship and the current sequence number corresponding to the one-time message key. The security chip performs a keyed hash operation on the key derivation data and extracts 128 bits of data starting from the high-order bits of the operation result to form the one-time message key corresponding to the current sequence number, represented as: ; in, Indicates the one-time message key corresponding to the current sequence number, subscript This indicates that the corresponding key is used for message cryptographic processing; This means extracting 128 bits of data sequentially starting from the most significant bit of the 256-bit hash result with the key.
[0046] The extraction length is determined based on the SM4 algorithm key length used in this embodiment. During encoding, the chain security state corresponding to the current sequence number is arranged first, followed by the message association information, and the length values and field boundaries of each field in the message association information are retained. The one-time message key is only associated with the corresponding current sequence number, the corresponding chain security state, and the corresponding message association information, and is not used for the cryptographic processing of messages corresponding to other sequence numbers.
[0047] The security chip generates an initial authentication encryption vector based on the current sequence number. When generating the initial authentication encryption vector, the current sequence number is encoded into the low-order field of the security chip's SM4-GCM operation interface according to the byte order specified in the power distribution communication protocol. The remaining high-order fields are padded with 0s, ensuring a one-to-one correspondence between the initial authentication encryption vector and the current sequence number. The power distribution terminal submits the service field to the security chip and encodes the protocol control field and message association information into additional authentication data in the SM4-GCM operation according to the message encapsulation order. The security chip calls the one-time message key and the initial authentication encryption vector to perform the SM4-GCM operation, encrypting the service field to obtain the encrypted service field. Simultaneously, it generates a 128-bit authentication tag based on the additional authentication data and the encrypted service field, and identifies the authentication tag as the authentication information. The length of the authentication information adopts the full SM4-GCM authentication tag length and is configured consistently by the power distribution terminal and the master station.
[0048] The power distribution terminal encapsulates the protocol control field, message association information, encrypted service field, and authentication information according to the message encapsulation order specified in the power distribution communication protocol, forming a state-associated encrypted message. The message association information is encapsulated as a plaintext field and participates in the generation of authentication information, enabling the receiving side to determine the protocol inheritance relationship and the current sequence number from the message association information. The encrypted service field carries the service data processed by the one-time message key. The authentication information is used by the receiving side to verify whether the protocol control field, message association information, and encrypted service field remain consistent during transmission. After the state-associated encrypted message is formed, the security chip associates and saves the chained security state corresponding to the current sequence number with the current sequence number, and the most recently confirmed sequence number remains unchanged until the corresponding message completes authentication and status confirmation.
[0049] After the state-associative encrypted message is sent to the receiving side, the current sequence number in the message association information is used to determine the receiving sequence number. The message association information participates in the one-time message key recovery and authentication information verification during the corresponding processing of consecutive receiving sequence numbers and ahead-of-time receiving sequence numbers. The protocol succession relationship, current sequence number and chain security state are thus used for the authentication and decryption of the state-associative encrypted message.
[0050] S3. The receiving side uses the chain security state corresponding to the most recent consecutive confirmation sequence number as the main chain and the current sequence number as the receiving sequence number. When the receiving sequence numbers are consecutive, the main chain is used for authentication and decryption, and the main chain and the most recent consecutive confirmation sequence number are updated. When the receiving sequence number is ahead, a candidate branch is temporarily advanced from the main chain. After verification, only the chain security state at the end of the candidate branch and the authenticated sequence number are retained, and the main chain remains unchanged. When all the sequences crossed by the received sequence number have been authenticated, the message corresponding to the receiving sequence number is decrypted, the chain security state at the end of the candidate branch is submitted as a common confirmation state, and the main chain and the most recent consecutive confirmation sequence number are updated.
[0051] It should be noted that after receiving the state-associated encrypted message, the receiving side determines the field boundaries of the protocol control field, message association information, encrypted service field, and authentication information according to the message encapsulation order specified in the power distribution communication protocol. The protocol control field includes the message type identifier, transmission direction identifier, and service stage identifier. The message association information includes the interaction position code of the previous acknowledgment message, the interaction position code of the current message, and the current sequence number. The receiving side extracts the current sequence number from the message association information and determines the current sequence number as the receiving sequence number. The message association information is kept in plaintext form during transmission and is used by the receiving side to recover the one-time message key and participate in the authentication information verification.
[0052] In this embodiment, the receiving side refers to the side of the encrypted message associated with the receiving state in the current message transmission direction; when the power distribution terminal is the receiving side, the security chip of the power distribution terminal completes the chain-like security state advancement, one-time message key recovery and authentication decryption; when the master station is the receiving side, the master station completes the corresponding processing according to the same state data, field encoding rules and cryptographic operation rules.
[0053] The receiving side stores the state root key, the most recent consecutive confirmation sequence number, and the chain security state corresponding to the most recent consecutive confirmation sequence number. The receiving side determines the chain security state corresponding to the most recent consecutive confirmation sequence number as the end chain security state of the main chain. The main chain represents the chain security state path that has continuously completed authentication and obtained confirmation. The receiving side compares the received sequence number with the most recent consecutive confirmation sequence number, and, considering whether there are candidate branches that have not yet completed continuous authentication, handles the following situations: (1) The received sequence number is continuous.
[0054] When there are no candidate branches that have not yet completed continuous authentication, and the received sequence number is equal to the most recent continuous acknowledgment sequence number plus 1, the receiving side determines that the received sequence number is continuous. The receiving side calls the main chain end chain security state, encodes the main chain end chain security state and the received sequence number according to the fixed field order used when advancing the chain security state, and calls the state root key to perform HMAC-SM3 operation to form the chain security state corresponding to the received sequence number. The chain security state corresponding to the received sequence number is temporarily stored in the temporary processing area of the receiving side before authentication is completed, and does not cover the main chain end chain security state.
[0055] The receiving side arranges the chained security states corresponding to the received sequence number first, and the message association information in the state-associative encrypted message last, according to the field order used by the sending side when deriving the one-time message key. The length value and field boundary of each field are encoded, and the state root key is called to perform HMAC-SM3 operation. The receiving side extracts data with the same key length as the SM4 algorithm key sequentially from the high-order bits of the operation result to recover the one-time message key corresponding to the received sequence number. The state root key limits the key derivation basis for this communication and the current key version, the chained security states corresponding to the received sequence number limit the state advancement position of the key, and the message association information limits the protocol inheritance relationship and received sequence number of the key.
[0056] The receiving side encodes the received sequence number into the low-order field of the authentication encryption initial vector according to the byte order specified in the power distribution communication protocol, and fills the remaining high-order field with 0, according to the rules adopted by the sending side when forming the authentication encryption initial vector. The receiving side combines the protocol control field and the message association information into additional authentication data according to the encapsulation order of the state-associated encrypted message, calls the recovered one-time message key and the authentication encryption initial vector to perform SM4-GCM authentication decryption, and compares the authentication tag formed by the operation with the authentication information in the state-associated encrypted message in byte order.
[0057] When the authentication tag and authentication information are completely consistent, the receiving side determines that the protocol control field, message association information, and encrypted service field remain consistent during transmission, and confirms the validity of the decrypted service field. The receiving side updates the chain security state corresponding to the received sequence number to the chain security state at the end of the main chain, updates the received sequence number to the most recent consecutive acknowledgment number, and forms an acknowledged message record based on the received sequence number, message type identifier, transmission direction identifier, and service stage identifier. The acknowledged message record is used to determine the previous acknowledged message and the corresponding protocol continuation relationship for subsequent messages to be transmitted. If any byte of the authentication tag and authentication information is inconsistent, the receiving side clears the chain security state and one-time message key corresponding to the received sequence number, does not output the decrypted service field, and the main chain and the most recent consecutive acknowledgment number remain unchanged.
[0058] (2) The received sequence number is ahead of the previous one and has not yet formed a continuous sequence of authenticated sequence numbers.
[0059] When the received sequence number is greater than the most recent consecutive acknowledgment number plus 1, the receiving side determines that the received sequence number is ahead, and determines the sequence number that has not yet been reached between the most recent consecutive acknowledgment number and the received sequence number as the sequence number that is crossed by the received sequence number; the receiving side keeps the chain safety state at the end of the main chain and the most recent consecutive acknowledgment number unchanged, and replicates the chain safety state at the end of the main chain in the temporary processing area of the receiving side, and uses the replicated chain safety state as the starting point for advancing the candidate branch.
[0060] The receiving side starts from the next sequence number after the most recent consecutive acknowledgment number and advances the chain security state sequentially in ascending order of sequence number. Each time it advances, the chain security state corresponding to the previous sequence number is placed first, followed by the sequence number reached in this advance. Encoding is completed according to a fixed field length and byte order, and HMAC-SM3 operation is performed using the state root key to form the chain security state corresponding to the sequence number reached in this advance. The chain security state formed in the previous advance continues to participate in the state advancement of the next sequence number until the chain security state corresponding to the received sequence number is formed. The chain security state corresponding to the received sequence number is determined as the candidate branch end chain security state, and the received sequence number is determined as the candidate branch end sequence number. The candidate branch end sequence number represents the sequence number corresponding to the candidate branch end chain security state. Each chain security state formed during the advancement process constitutes a candidate branch according to its corresponding sequence number.
[0061] The receiving side recovers the one-time message key based on the state root key, the candidate branch end chain security state, and the message association information in the state-associated encrypted message, according to the field order, encoding rules, and keyed hash operation used in the continuous reception scenario. It also verifies the authentication information according to the same authentication encryption initialization vector formation rules and additional authentication data encapsulation rules. At this time, only the integrity of the state-associated encrypted message and the correspondence between the message association information, the reception sequence number, and the candidate branch end chain security state are verified. Plaintext data corresponding to the encrypted service fields are not output to the service processing process.
[0062] When the authentication information is verified, the receiving side records the received sequence number as the authenticated sequence number, associates and saves the chain security state at the end of the candidate branch with the received sequence number, releases the one-time message key for this recovery, and clears the chain security state formed from the starting point of the candidate branch to the end of the candidate branch; the aforementioned "only retaining" means that only the chain security state at the end of the candidate branch is retained in the chain security state formed by the candidate branch; the receiving side still saves the state-associated encrypted message corresponding to the received sequence number so as to complete the decryption of the corresponding business field after forming a continuous chain of authenticated sequence numbers; the chain security state at the end of the main chain and the most recent continuous confirmation sequence number remain unchanged during the formation and authentication of the candidate branch.
[0063] When the authentication information verification fails, the receiving side does not record the receiving sequence number, clears the candidate branch formed this time, the chain security state at the end of the candidate branch and the one-time message key, and discards the encrypted message associated with the corresponding state. The main chain and the most recent consecutive confirmation sequence number remain unchanged.
[0064] (3) All serial numbers spanned by the received serial number have been authenticated and form a continuous sequence of authenticated serial numbers.
[0065] While the candidate branch has not yet been submitted, when the state-associated encrypted messages corresponding to the sequence numbers spanned by the received sequence number arrive subsequently, the receiving side determines the received sequence number from the message association information of the corresponding state-associated encrypted message, and determines whether the received sequence number is located between the next sequence number of the most recent consecutive acknowledgment sequence number and the previous sequence number of the candidate branch end sequence number. When the received sequence number is within the above sequence number range, the receiving side uses the chain security state at the end of the main chain as a fixed starting point, and temporarily advances to the chain security state corresponding to the received sequence number in ascending order of sequence number. Based on the state root key, the chain security state corresponding to the received sequence number, and the message association information, the one-time message key is recovered, and the authentication information of the corresponding state-associated encrypted message is verified.
[0066] When the authentication information is verified, the receiving side records the received sequence number as the authenticated sequence number and clears the chain security states and one-time message keys formed for this authentication. When the authentication information is verified, the receiving side does not record the received sequence number and clears the chain security states and one-time message keys formed for this authentication. The candidate branch end chain security state, the main chain end chain security state, and the most recent consecutive confirmation sequence number remain unchanged during the authentication process of each crossed sequence number.
[0067] After each addition of an authenticated sequence number, the receiving side checks each sequence number from the next sequence number of the most recently confirmed sequence number to the end sequence number of the candidate branch in ascending order. If no corresponding authenticated record is found for any sequence number within the above range, the receiving side determines that a continuous sequence of authenticated sequences has not yet been formed and continues to keep the candidate branch and main chain unchanged. When each sequence number within the above range has a corresponding authenticated record, the receiving side determines that all sequences spanned by the received sequence number have been authenticated and a continuous sequence of authenticated sequences extending from the next sequence number of the most recently confirmed sequence number to the end sequence number of the candidate branch is formed.
[0068] After consecutive authenticated sequence numbers are formed, the receiving side again uses the main chain end chain security state as the starting point and advances to the candidate branch end sequence number in ascending order to form a verification chain security state. The verification chain security state is then compared byte by byte with the saved candidate branch end chain security state. If the comparison results are inconsistent, the receiving side determines that the candidate branch cannot form the same state advancement result as the main chain, cancels the candidate branch, and clears the verification chain security state, the candidate branch end chain security state, the corresponding authenticated sequence number record, and the saved state-associated encrypted message. The main chain and the most recent consecutive acknowledgment sequence number remain unchanged.
[0069] If the comparison results are consistent, the receiving side recovers the one-time message key based on the state root key, the chain security state at the end of the candidate branch, and the message association information in the saved state-associated encrypted message. Following the aforementioned authentication encryption initialization vector formation rules and additional authentication data encapsulation rules, the receiving side performs SM4-GCM authentication and decryption on the state-associated encrypted message corresponding to the candidate branch end sequence number. If authentication is successful, the receiving side confirms the validity of the decrypted service fields and enters the joint confirmation state submission process. If authentication fails, the receiving side cancels the candidate branch, clears the review chain security state, the chain security state at the end of the candidate branch, the authenticated sequence number record, the saved state-associated encrypted message, and the one-time message key recovered this time. The main chain and the most recent consecutive confirmation sequence number remain unchanged.
[0070] After entering the joint confirmation state submission process, the receiving side encodes the received sequence number and the candidate branch end chain security state according to a fixed field order, calls the state root key to perform HMAC-SM3 operation to form a state confirmation value, and sends a state confirmation message including the received sequence number and the state confirmation value to the sending side; the state confirmation message does not carry the plaintext of the candidate branch end chain security state; the sending side determines the corresponding local chain security state according to the received sequence number, forms a local state confirmation value according to the same field order, encoding rules and keyed hash operation, and compares the local state confirmation value with the received state confirmation value byte by byte.
[0071] When the status confirmation values are consistent, the sending side determines the local chain security state corresponding to the received sequence number as the sending side's common confirmation state, determines the received sequence number as the sending side's most recent consecutive confirmation sequence number, and returns the status confirmation result. After receiving the status confirmation result, the receiving side determines the candidate branch end chain security state as the receiving side's common confirmation state and the main chain end chain security state, updates the received sequence number to the most recent consecutive confirmation sequence number, and outputs the business fields formed by authentication and decryption. When the status confirmation values are inconsistent, the sending side returns a status confirmation failure result. Both the sending and receiving sides maintain the original common confirmation state and the most recent consecutive confirmation sequence number. The receiving side cancels the candidate branch, clears the verification chain security state, the candidate branch end chain security state, the authenticated sequence number record, the saved status-associated encrypted message, and the one-time message key for this recovery. The main chain remains unchanged.
[0072] After the joint confirmation state is submitted, the receiving side clears the authenticated sequence number record, verifies the chain security state and the one-time message key for this recovery, and updates the confirmed message record according to the encrypted messages associated with the states that have been continuously authenticated. The updated joint confirmation state is used for the main chain advancement of subsequent state-associated encrypted messages, and serves as the state position when communication is out of sync and when the key version is switched.
[0073] S4. Repeated messages maintain the common confirmation state. When communication is out of sync, the chain security state is restored from the common confirmation state. When the key is updated, the common confirmation state is used as the version switching position. After the new key version is confirmed, the new key version is determined as the current key version. If the confirmation fails, the original key version is maintained.
[0074] It should be noted that after the distribution terminal and the master station complete two-way authentication and form the same chain security state, the chain security state jointly formed by both parties is determined as the first jointly confirmed state, and the initial sequence number and the current key version identifier are associated and saved with the first jointly confirmed state. After the candidate branch end chain security state is submitted, the distribution terminal and the master station update the submitted candidate branch end chain security state to the jointly confirmed state, and associate and save the most recent consecutive confirmation sequence number corresponding to the jointly confirmed state and the key version identifier used when forming the jointly confirmed state. The jointly confirmed state indicates that the distribution terminal and the master station have passed the state confirmation and have a consistent state value in the chain security state. The most recent consecutive confirmation sequence number corresponding to the jointly confirmed state indicates the position of the jointly confirmed state within the message sequence number range. The jointly confirmed state and associated information serve as an unchanged state benchmark during the process of repeated message processing, as the recovery starting point of the chain security state during the process of communication out-of-sync processing, and jointly determine the key version switching position during the key update process.
[0075] Based on the received sequence number, the most recent consecutive acknowledgment sequence number, the chain security status at the end of the main chain, the joint acknowledgment status, and the key update acknowledgment result, the distribution terminal and the master station shall handle the following situations: (1) Duplicate message processing.
[0076] After receiving a state-associated encrypted message, the receiving side extracts the current sequence number from the message association information and determines it as the received sequence number. The received sequence number is then compared with the most recent consecutive acknowledgment sequence number. If the received sequence number is not greater than the most recent consecutive acknowledgment sequence number, the receiving side determines that the sequence number corresponding to the state-associated encrypted message is already within the consecutive acknowledgment range and identifies the state-associated encrypted message as a duplicate message. If, during the period before a candidate branch is submitted, the received sequence number is greater than the most recent consecutive acknowledgment sequence number, but the received sequence number already exists in the authenticated sequence number record corresponding to the candidate branch, the receiving side also identifies the state-associated encrypted message as a duplicate message.
[0077] After the receiving side identifies a duplicate message, it does not advance the main chain based on the duplicate message, does not re-form candidate branches, does not use the duplicate message to update the authenticated sequence number record, and stops outputting the business fields corresponding to the duplicate message to the business processing process again. The receiving side retains the original common confirmation state, the chain-like security state at the end of the main chain, the most recent consecutive confirmation sequence number, and the current key version, so that the newly received state-associated encrypted messages continue to be processed according to the original main chain and sequence number range.
[0078] (2) Handling communication loss of synchronization.
[0079] After the receiving side recovers the one-time message key using the chain security state at the end of the main chain, if the authentication information of the state-associated encrypted message fails verification, the distribution terminal and the master station encode their respective most recent consecutive acknowledgment number and the corresponding chain security state according to a fixed field order, call the currently used state root key to perform HMAC-SM3 operation, form a state confirmation value, and exchange state confirmation information including the current key version identifier, the most recent consecutive acknowledgment number, and the state confirmation value. Outside of the key update confirmation process, if the current key version identifier is inconsistent, it is determined that the key version states of the two communicating parties are inconsistent; if the current key version identifier is consistent but the most recent consecutive acknowledgment number is inconsistent, it is determined that the chain security state advancement positions of the two communicating parties are inconsistent; if both the current key version identifier and the most recent consecutive acknowledgment number are consistent but the state confirmation value is inconsistent, it is determined that the chain security states saved by the two communicating parties at the same sequence number position are inconsistent; if any of the above states occur, it is determined that communication has lost synchronization.
[0080] After communication synchronization failure is confirmed, the distribution terminal and the master station stop advancing the chain security state based on the synchronization failure state. They clear the chain security states formed after the joint confirmation state but not yet submitted, the chain security states at the end of the candidate branches, the authenticated sequence number records, and the one-time message keys that have not yet been released. The distribution terminal and the master station call the associated and saved joint confirmation state, the most recent consecutive confirmation sequence number corresponding to the joint confirmation state, and the key version identifier used when the joint confirmation state was formed. They restore the key version identifier used when the joint confirmation state was formed to the current key version identifier and re-establish the starting point for advancing the chain security state based on the joint confirmation state. At the same time, the receiving side restores the joint confirmation state to the chain security state at the end of the main chain and restores the most recent consecutive confirmation sequence number corresponding to the joint confirmation state to the current most recent consecutive confirmation sequence number.
[0081] After the chain-based security state is restored, the sending side determines the next sequence number of the most recent consecutive confirmation sequence number corresponding to the common confirmation state as the sequence number of the first message to be sent after restoration, and determines the previous confirmation message based on the confirmed message record corresponding to the common confirmation state. The sending side re-forms the message association information according to the sequence number of the first message to be sent after restoration, and advances the chain-based security state from the common confirmation state under the current key version to form a state-associated encrypted message. The receiving side uses the same common confirmation state as the starting point for the main chain advancement, restores the one-time message key according to the received sequence number, and performs authentication and decryption. After successful authentication, the restored chain-based security state re-enters the main chain update process, and both communicating parties continue to process subsequent messages according to the restored sequence number range.
[0082] (3) New key version confirmation completed.
[0083] When the power distribution communication key management process generates a key update instruction, the instruction carries a new key version identifier but does not carry the plaintext of the key corresponding to the new key version. The side that sends the key update request between the power distribution terminal and the master station is determined as the key update initiating side, and the side that receives the request is determined as the key update receiving side. The power distribution terminal and the master station locate the key corresponding to the new key version pre-configured through the power distribution communication key management process based on the new key version identifier, and determine the version switching position based on the currently saved common confirmation state and the most recent consecutive confirmation sequence number corresponding to the common confirmation state. Before the new key version is confirmed, the current key version, the current state root key, the common confirmation state, the main chain end chain security state, and the most recent consecutive confirmation sequence number remain unchanged, and the key update confirmation information continues to be transmitted under the current key version.
[0084] The distribution terminal and the master station respectively call the key corresponding to the new key version and the authentication random number generated during the two-way authentication of this communication, and perform HMAC-SM3 operation according to the established derivation rules of the state root key to form the state root key to be switched. The distribution terminal and the master station use the jointly confirmed state as the chain security state corresponding to the version switching position, arrange the jointly confirmed state first, and arrange the next sequence number of the most recent consecutive confirmation sequence number corresponding to the jointly confirmed state last. They encode according to the fixed field order and byte order used for the chain security state advancement, and call the state root key to be switched to perform HMAC-SM3 operation to form the chain security state to be switched corresponding to the first sequence number under the new key version.
[0085] The distribution terminal and the master station encode the new key version identifier, the most recent consecutive confirmation sequence number corresponding to the common confirmation state, and the chain security state to be switched according to a fixed field order. They then call the root key of the state to be switched to perform HMAC-SM3 operation to form a new key version confirmation value. The key update initiating side sends key update confirmation information including the new key version identifier, the sequence number corresponding to the version switch position, and the new key version confirmation value. The key update receiving side locates the corresponding key based on the new key version identifier in the key update confirmation information, generates a local new key version confirmation value according to the same state root key derivation rule, chain security state advancement rule, and confirmation value formation rule, and compares the local new key version confirmation value with the received new key version confirmation value byte by byte.
[0086] When the new key version identifier, the corresponding sequence number of the version switch position, and the new key version confirmation value are consistent byte by byte, the key update receiving side encodes the new key version identifier, the corresponding sequence number of the version switch position, and the local new key version confirmation value according to a fixed field order, generates authentication information according to the authentication rules corresponding to the current key version, forms confirmation completion information, and sends it to the key update initiating side; the key update initiating side verifies the authentication information of the confirmation completion information, and compares the new key version identifier, the corresponding sequence number of the version switch position, and the locally stored new key version confirmation value in the confirmation completion information; when all the contents are consistent, the distribution terminal and the master station determine the new key version. Upon completion of this confirmation, the new key version identifier is updated to the current key version identifier, the root key of the state to be switched is updated to the state root key, and the common confirmation state is retained as the version switching position between the old and new key versions. The most recent consecutive confirmation sequence number corresponding to the common confirmation state remains unchanged. The first state-associated encrypted message under the new key version adopts the next sequence number of the most recent consecutive confirmation sequence number corresponding to the common confirmation state, and the already formed chain security state to be switched is determined as the corresponding chain security state. The receiving side restores the one-time message key according to the state root key corresponding to the new key version and the same version switching position. After successful authentication, the main chain and the most recent consecutive confirmation sequence number are updated.
[0087] (4) New key version verification failed.
[0088] If the distribution terminal and the master station cannot locate the key corresponding to the same new key version based on the new key version identifier, the new key version confirmation is deemed to have failed; if the sequence number corresponding to the version switch position in the key update confirmation information is inconsistent with the most recent consecutive confirmation sequence number corresponding to the local joint confirmation status, the new key version confirmation is deemed to have failed; if any byte of the local new key version confirmation value is inconsistent with the received new key version confirmation value, the new key version confirmation is also deemed to have failed; if the authentication information in the confirmation completion information fails verification, the new key version confirmation is deemed to have failed; if any of the new key version identifier, the sequence number corresponding to the version switch position, or the new key version confirmation value in the confirmation completion information is inconsistent with the locally stored content, the new key version confirmation is also deemed to have failed.
[0089] After the new key version confirmation fails, the distribution terminal and the master station do not update the current key version identifier, do not use the root key of the state to be switched to advance the main chain, and clear the root key of the state to be switched, the chain security state to be switched, and the confirmation value of the new key version formed this time; the distribution terminal and the master station continue to retain the key corresponding to the original key version, the original state root key, the common confirmation state, and the most recent consecutive confirmation sequence number corresponding to the common confirmation state; the receiving side continues to process the state-related encrypted messages with the original common confirmation state and the original chain security state at the end of the main chain, and the sending side continues to derive the one-time message key according to the original key version; subsequent state-related encrypted messages re-enter the encryption, authentication, decryption, and main chain update process under the original key version.
[0090] In summary, this invention achieves this by: associating the service acceptance relationship, current sequence number, and chain security state in the power distribution communication protocol with the formation process of the one-time message key, thus establishing a correspondence between message cryptographic processing and the order of service interactions, enhancing the identification and constraint capabilities of messages in cases of reassembly and out-of-order transmission, and improving the authenticity and security of service message transmission; by setting up a main chain and candidate branches on the receiving side, and submitting a common confirmation state after continuous authentication across sequence numbers, while using the common confirmation state for out-of-synchronization recovery and key version switching, the chain security state in cases of out-of-order, duplicate, and communication anomalies is kept under controlled progression, reducing the risk of state mismatch and key version asynchrony between the communicating parties, and improving the continuity, stability, and reliability of encrypted message transmission in power distribution terminals.
[0091] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A method for encrypted transmission of messages in a power distribution terminal based on a security chip, characterized in that, include: After the power distribution terminal and the master station perform two-way identity authentication, the security chip forms a state root key and a chain of security states based on the authentication random number and the key corresponding to the current key version, and records the most recent consecutive confirmation sequence number; Based on the protocol succession relationship of the message to be transmitted relative to the previous confirmation message and the current sequence number, message association information is formed, the chain security state is advanced to the state corresponding to the current sequence number, a one-time message key is derived based on the state root key, chain security state and message association information, the business fields are encrypted and authentication information is generated, and a state-associated encrypted message is formed. The receiving side uses the chain security state corresponding to the most recent consecutive confirmation sequence number as the main chain and the current sequence number as the receiving sequence number. When the receiving sequence numbers are consecutive, the main chain is used for authentication and decryption, and the main chain and the most recent consecutive confirmation sequence number are updated. When the receiving sequence number is ahead, a candidate branch is temporarily advanced from the main chain. After the verification is passed, only the chain security state at the end of the candidate branch and the authenticated sequence number are retained, and the main chain remains unchanged. When all the sequences crossed by the received sequence number have been authenticated, the message corresponding to the receiving sequence number is decrypted, the chain security state at the end of the candidate branch is submitted as a common confirmation state, and the main chain and the most recent consecutive confirmation sequence number are updated. Duplicate messages maintain the common confirmation state. When communication is out of sync, the chained security state is restored from the common confirmation state. When the key is updated, the common confirmation state is used as the version switching position. After the new key version is confirmed, the new key version is determined as the current key version. If the confirmation fails, the original key version is maintained.
2. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 1, characterized in that, The process of forming message association information based on the protocol succession relationship of the message to be transmitted relative to the previous acknowledgment message and the current sequence number includes: The protocol succession relationship refers to the sequential connection between the message to be transmitted and the previous confirmation message formed according to the business interaction process stipulated in the power distribution communication protocol. According to the power distribution communication protocol, determine the interaction position of the previous confirmation message and the message to be transmitted in the corresponding business interaction process. Based on the connection order of the corresponding interaction positions, determine the protocol inheritance relationship of the message to be transmitted relative to the previous confirmation message. Encode the protocol inheritance relationship with the current sequence number to form the message association information of the message to be transmitted.
3. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 2, characterized in that, The process of advancing the chained security state to the state corresponding to the current sequence number involves deriving a one-time message key based on the state root key, the chained security state, and message association information, including: The number of times to advance the chain security state is determined based on the sequence number interval between the current sequence number and the most recent consecutive confirmation sequence number. The chain security state corresponding to the most recent consecutive confirmation sequence number is used as the starting point for advancement. The chain security state is advanced step by step according to the sequence number progression order. Each time it is advanced, the next chain security state is formed based on the state root key, the previous chain security state and the sequence number reached in this advancement, until the current chain security state corresponding to the current sequence number is formed. Based on the root key, the current chain security state, and the message association information, key derivation data corresponding to the current sequence number is generated. The security chip performs key derivation operations on the key derivation data to obtain the one-time message key corresponding to the current sequence number.
4. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 1, characterized in that, When the received sequence number is ahead, a candidate branch is temporarily advanced from the main chain, including: The received sequence number is compared with the next sequence number of the most recent consecutive acknowledgment number. If the received sequence number is greater than the next sequence number of the most recent consecutive acknowledgment number, it is determined that the received sequence number is ahead. Keeping the main chain unchanged, the chain security state corresponding to the most recent consecutive confirmation sequence number is used as the starting point of the candidate branch. The chain security state is advanced step by step according to the progressive order from the most recent consecutive confirmation sequence number to the receiving sequence number. The chain security states obtained by each step are associated according to the progressive order of the corresponding sequence number to form a candidate branch. The chain security state corresponding to the receiving sequence number is determined as the chain security state at the end of the candidate branch. The one-time message key is recovered based on the state root key, the chain security state at the end of the candidate branch, and the message association information of the encrypted message associated with the state corresponding to the received sequence number. The authentication information of the corresponding state associated encrypted message is verified based on the recovered one-time message key. If the verification is successful, the received sequence number will be determined as the authenticated sequence number. If the verification fails, the one-time message key will be released and the candidate branch will be withdrawn, while keeping the main chain and the most recent consecutive confirmation sequence number unchanged.
5. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 1, characterized in that, The process of receiving consecutive sequence numbers, authenticating and decrypting along the main chain, and updating the main chain and the most recent consecutive confirmation sequence number, includes: When subsequent encrypted messages associated with the states of each sequence number that have been received arrive, the main chain remains unchanged. The main chain is used as the starting point for advancement. The chain security states are advanced in the order of sequence number progression. The one-time message key is restored in sequence according to the state root key, the chain security states corresponding to each sequence number, and the message association information. The authentication information of the corresponding state-associated encrypted message is verified. When the verification is successful, the corresponding business field is decrypted and the corresponding sequence number is determined as the authenticated sequence number. When all sequence numbers between the most recent consecutive confirmation sequence number and the received sequence number are determined to be authenticated sequence numbers, the one-time message key is recovered based on the state root key, the candidate branch end chain security state, and the message association information corresponding to the received sequence number. The business fields of the state association encrypted message corresponding to the received sequence number are decrypted, the candidate branch end chain security state is submitted as a common confirmation state, and the most recent consecutive confirmation sequence number is updated to the received sequence number.
6. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 1, characterized in that, After the verification is passed, only the chain-like security state of the candidate branch's end and the certified sequence number are retained, while the main chain remains unchanged, including: After the authentication information of the encrypted message associated with the received sequence number is verified, the one-time message key corresponding to the received sequence number is released, the chain security state corresponding to each sequence number after the starting point of the candidate branch and before the end of the candidate branch is cleared, and the chain security state at the end of the candidate branch is retained. Record the chain security state at the end of the candidate branch with the corresponding certified sequence number, maintain the main chain in the chain security state corresponding to the most recent consecutive confirmation sequence number, and keep the most recent consecutive confirmation sequence number unchanged.
7. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 5, characterized in that, The step of submitting the chained safety state at the end of the candidate branch as a jointly confirmed state includes: The receiving side forms a status confirmation information based on the receiving sequence number and the chain-like security status at the end of the candidate branch, and sends the status confirmation information to the sending side; The sending side determines the corresponding chain security state based on the received sequence number, forms the sending side status confirmation information based on the received sequence number and the corresponding chain security state, and performs consistency verification between the sending side status confirmation information and the received status confirmation information. When the consistency check passes, the sending side determines the chain security state corresponding to the received sequence number as the common confirmation state and returns the status confirmation result. The receiving side determines the chain security state at the end of the candidate branch as the common confirmation state based on the status confirmation result. The sending side and the receiving side update the most recent consecutive confirmation sequence number to the received sequence number. If the consistency check fails, the sending side returns a status confirmation failure result, and the sending side and the receiving side maintain the original joint confirmation status and the most recent consecutive confirmation sequence number.
8. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 1, characterized in that, The recovery from the common confirmation state to the chained security state when communication is out of sync includes: When the chain of security states formed by the sending side and the receiving side for the same sequence number after the common confirmation state is inconsistent, communication is determined to be out of sync. Clear the chain of security states that have not yet been committed after the common confirmation state, and take the chain of security states corresponding to the common confirmation state as the recovery starting point, and start to advance the chain of security states again from the next sequence number of the most recent consecutive confirmation number; Based on the chain security state formed by the renewed push, the one-time message key is recovered and the authentication information of the encrypted message associated with the corresponding state is verified. The chain security state corresponding to the highest consecutively authenticated sequence number is determined as the common confirmation state after recovery, and the most recent consecutive confirmation sequence number is updated.
9. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 1, characterized in that, The key update uses the shared confirmation state as the version switching position. After the new key version is confirmed, the new key version is determined as the current key version, including: The state root key corresponding to the original key version remains valid. The most recent consecutive confirmation sequence number corresponding to the common confirmation state is used as the version switching position. The security chip forms the state root key corresponding to the new key version based on the key corresponding to the new key version, and uses the chain security state corresponding to the common confirmation state as the starting point for the state advancement of the new key version. The chain security state corresponding to the new key version is advanced in the order of the sequence number following the most recent consecutive confirmation number. A one-time message key is derived based on the state root key, the corresponding chain security state and message association information corresponding to the new key version, and the authentication information of the encrypted message associated with the state corresponding to the new key version is verified. When the authentication information is verified and the corresponding chain security states of the sending and receiving sides are consistent, the new key version is determined as the current key version and the process continues along the corresponding chain security states. If the confirmation is not completed, the root key and common confirmation state corresponding to the original key version remain unchanged.
10. The method for encrypted transmission of power distribution terminal messages based on a security chip as described in claim 1, characterized in that, The repeated messages maintain a common acknowledgment state, including: If an authenticated sequence number with the same received sequence number exists, the encrypted message associated with the corresponding status will be identified as a duplicate message. For duplicate messages, the chain security state will no longer be advanced, no candidate branch will be formed, and the corresponding authenticated sequence number, the most recent consecutive confirmation sequence number, and the common confirmation state will remain unchanged; The business fields corresponding to duplicate messages will no longer be processed. Subsequent state-associated encrypted messages will continue to be processed in a chain-like security state based on the common confirmation state and the most recent consecutive confirmation sequence number.