Terminal-side dltcp session state fast recovery method, device, electronic equipment and storage medium

By saving encrypted session state snapshots in a secure chip, the problem of repeated handshakes after low-power terminal devices are woken up is solved, enabling rapid recovery of session state and reducing energy consumption and security risks.

CN123164435APending Publication Date: 2026-11-24SICHUAN PLANNING TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611670347.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-27
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

In low-power terminal devices, the session state of the DTLCP protocol stack is easily lost, which requires a complete handshake to be re-executed after wake-up, increasing communication waiting time and energy consumption. Furthermore, existing session recovery schemes have security risks and state discontinuity issues.

Method used

An encrypted snapshot of the session state, including the session master key and working key, is saved through a security chip. Encryption and authentication are performed using the snapshot encryption key and authentication key. Upon wake-up, the validity of the snapshot is verified and the session state is restored, avoiding repeated handshakes.

Benefits of technology

It reduces the latency and energy consumption of repeated handshakes after wake-up, ensures the continuity and security of session state, and reduces the risk of session key exposure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123164435A_ABST
    Figure CN123164435A_ABST
Patent Text Reader

Abstract

This invention provides a method, apparatus, electronic device, and storage medium for fast recovery of DTLCP session state on the terminal side, relating to the field of IoT secure communication technology. The method includes the following steps: before the terminal goes into sleep mode, a fast message structure including session state data and snapshot metadata is constructed; a snapshot encryption key and a snapshot authentication key are derived and persistently stored using the chip master key within the security chip; a snapshot authentication code is calculated; the session state data is authenticated and encrypted; and the resulting session state snapshot is stored in the power-off retention snapshot storage slot of the security chip. After the terminal wakes up, available snapshots are decrypted and verified; if verification is successful, the session state data is written to the DTLCP protocol stack to restore the session state; if no available snapshot is available or verification fails, a full handshake is performed. This invention can reduce repeated handshakes after the terminal wakes up from sleep mode, reduce session state recovery latency, and improve the security of session state persistence, making it highly practical.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of IoT secure communication technology, specifically to a method, apparatus, electronic device, and storage medium for fast recovery of DTLCP session state on the terminal side. Background Technology

[0002] IoT terminals typically upload sensor data or receive control commands through a security gateway. For battery-powered devices such as water level monitoring terminals and industrial telemetry terminals, to reduce energy consumption, the terminal generally enters sleep mode after completing a data communication and wakes up before the next data collection or communication. DTLCP (GM / T 0128-2023) is a transport layer cryptographic protocol based on UDP (User Datagram Protocol) defined in the national cryptographic standard system. It can use national cryptographic algorithms to protect datagram communication between the terminal and the gateway. The two communicating parties negotiate the cipher suite through a handshake, generate a session master key and a working key, and maintain the record layer state through record layer generation value and sequence number.

[0003] In some low-power terminals, the runtime state of the DTLCP protocol stack is stored in volatile memory. When the terminal enters deep sleep, the memory loses power, and the session master key, working key, record layer generation value, and transmission sequence number are lost. After the terminal wakes up, if it cannot regain the above states, even if the gateway retains the original session, it is necessary to re-execute the full handshake to continue communication. The full handshake involves multiple message exchanges, certificate processing, and asymmetric cryptographic operations, which increases the communication waiting time and energy consumption after wake-up, especially in scenarios with frequent sleep or requiring fast response.

[0004] Storing session state in external non-volatile memory can reduce state loss caused by memory power failure. However, if session keys and related states are stored in plaintext in memory lacking physical protection, there is a risk of direct reading and misuse. If only part of the key is stored and the record layer generation value, transmission sequence number, and cipher suite are not stored, it is difficult to accurately restore the original record layer running state. In addition, the persisted old state may become unsuitable for continued use due to expiration, changes in peer certificates, or the gateway discarding the session. The lack of verification and invalidation processing can easily lead to recovery failure or the reuse of old state.

[0005] Some session recovery schemes require both communicating parties to add dedicated recovery messages or rely on the server to manage recovery credentials. For terminals that have already deployed DTLCP gateways, how to combine the terminal's own security chip to save and verify session state, reduce repeated handshakes, and maintain the continuity of the record layer state after recovery is a technical problem that needs to be solved. Summary of the Invention

[0006] To address the shortcomings of the aforementioned existing technologies, this application provides a method, apparatus, electronic device, and storage medium for fast recovery of DTLCP session state on the terminal side. The method uses a security chip to encrypt and protect the session state and retain it even after power failure. The method verifies and restores the session state after the terminal is woken up, thereby reducing the latency and energy consumption caused by repeatedly performing the complete handshake.

[0007] To achieve the above objectives, the present invention employs the following techniques: A method for fast recovery of DTLCP session state on the terminal side, applied to a terminal equipped with a security chip, includes performing the following steps before the terminal enters sleep mode: S100. Construct a snapshot metadata structure that includes session state data and snapshot metadata; the session state data includes at least the hash value of the peer certificate extracted from the current DTLCP session, the record layer generation value, the transmission sequence number, the negotiated cipher suite, the session master key and the working key derived from the negotiated cipher suite; the snapshot metadata includes the snapshot generation time and the preset snapshot format version number and snapshot validity period. S200: Derive snapshot encryption key and snapshot authentication key from the chip master key stored in the security chip, and store them in the power-off retention key slot built into the security chip. S300: Using the snapshot authentication key, with the snapshot text structure as the data to be authenticated, calculate the snapshot authentication code; using the snapshot encryption key, with a random number pre-generated in the security chip as the initialization parameter, session state data as the data to be encrypted, and snapshot metadata as the associated authentication data, use the authentication encryption algorithm to calculate the encrypted session state data and authentication tag. S400 constructs a session state snapshot including snapshot metadata, encrypted session state data, authentication tag, snapshot authentication code and random number, and stores it in the power-off snapshot storage slot built into the security chip; After the terminal wakes up, perform the following steps: S500: Determine if the snapshot storage slot is empty or has been marked as invalid. If so, then perform the full DTLCP handshake procedure to establish a DTLCP session; If not, the encrypted session state data will be decrypted and the session state snapshot will be verified using the preset snapshot verification rules. If the verification is successful, the decrypted session state data will be written to the terminal's DTLCP protocol stack to restore the DTLCP session state. If the verification fails, the snapshot storage slot will be marked as invalid, and the complete DTLCP handshake process will be executed to establish a DTLCP session.

[0008] A terminal-side DTLCP session state fast recovery device is applied to a terminal equipped with a security chip, including a plaintext construction module, a key derivation module, an authentication encryption module, a snapshot construction module, and a snapshot verification module; The plaintext construction module is used to build a plaintext structure that includes session state data and snapshot metadata before the terminal is about to enter sleep mode. The session state data includes at least the hash value of the peer certificate extracted from the current DTLCP session, the record layer generation value, the transmission sequence number, the negotiated cipher suite, the session master key and the working key derived from the negotiated cipher suite; the snapshot metadata includes the snapshot generation time and the preset snapshot format version number and snapshot validity period. The key derivation module is used to derive snapshot encryption keys and snapshot authentication keys from the chip master key stored in the security chip, and store them in the power-off retention key slot built into the security chip. The authentication encryption module is used to calculate the snapshot authentication code using the snapshot authentication key and the snapshot text structure as the data to be authenticated; and to calculate the encrypted session state data and authentication tag using the snapshot encryption key, the pre-generated random number in the security chip as the initialization parameter, the session state data as the data to be encrypted, and the snapshot metadata as the associated authentication data, using the authentication encryption algorithm. The snapshot building module is used to build a session state snapshot that includes snapshot metadata, encrypted session state data, authentication tags, snapshot authentication codes, and random numbers, and stores it in the power-down retainable snapshot storage slot built into the security chip; The snapshot verification module is used to determine whether the snapshot storage slot is empty or marked as invalid after the terminal wakes up: If so, then perform the full DTLCP handshake procedure to establish a DTLCP session; If not, the encrypted session state data is decrypted and the session state snapshot is verified using the preset snapshot verification rules. If the verification is successful, the decrypted session state data is written to the terminal's DTLCP protocol stack to restore the DTLCP session state. If the verification fails, the snapshot storage slot is marked as invalid, and the complete DTLCP handshake process is executed to establish a DTLCP session.

[0009] An electronic device includes: at least one processor and a memory; wherein the memory stores computer-executable instructions; the at least one processor executes the computer-executable instructions stored in the memory, causing the at least one processor to execute the aforementioned terminal-side DTLCP session state fast recovery method.

[0010] A computer-readable storage medium storing a computer program that, when executed by a processor, controls the device containing the computer-readable storage medium to perform the aforementioned terminal-side DTLCP session state fast recovery method.

[0011] The beneficial effects of this invention are as follows: 1. The session state, including the session master key, working key, record layer generation value, and transmission sequence number, is included in the protection scope of the security chip. By retaining the stored state during hibernation when the power is off, the state loss caused by power failure of volatile memory is reduced, and the risk of exposing the session key in external storage is also reduced. 2. The snapshot encryption key and snapshot authentication key are derived and persistently stored within the security chip. After waking up, the key slot can be directly called to perform decryption and verification, avoiding the circular dependency that occurs because the record layer generation value and the sending sequence number required for derivation are already encrypted, which would lead to the need to obtain the key before decryption and decryption before key derivation. 3. Snapshots are protected by authentication tags using authentication encryption algorithms and snapshot authentication codes calculated based on plaintext structures, and snapshot metadata is included in the authentication scope. Combined with validity period, certificate hash and optional incremental version verification, it is helpful to detect anomalies such as snapshot tampering, expiration and rollback, and restrict the use of unsuitable snapshots. 4. After successful verification, the original record layer state is written back to the protocol stack to keep the sending sequence number and record layer generation value continuous. Under the condition that the gateway still retains the corresponding session state, the terminal can continue to send data protected by the original session, reducing message interaction and asymmetric cryptographic operations in repeated handshakes, thereby reducing local recovery latency and related energy consumption after wake-up. 5. The lifecycle of snapshots and snapshot keys is managed through strategies such as snapshot expiration after use, snapshot update after use, and abnormal cleanup. Combined with the on-demand write strategy, it can balance recovery availability, old snapshot usage restrictions, and the write burden of the secure storage area; local persistence and recovery of session state does not require changing the DTLCP record format. Attached Figure Description

[0012] Figure 1 This is a flowchart illustrating the fast recovery method for DTLCP session state on the terminal side according to an embodiment of this application.

[0013] Figure 2 This is a schematic diagram illustrating the snapshot encryption key and snapshot authentication key generation process in an embodiment of this application.

[0014] Figure 3 This is a schematic diagram of the snapshot authentication code calculation process in an embodiment of this application.

[0015] Figure 4 This is a schematic diagram of the session state snapshot verification process according to an embodiment of this application.

[0016] Figure 5 This is a flowchart illustrating the process of preventing rollback attacks according to an embodiment of this application.

[0017] Figure 6 This is a schematic diagram of the structure of the terminal-side DTLCP session state fast recovery device according to an embodiment of this application. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the implementation methods of the present invention will be described in detail below with reference to the accompanying drawings. However, the embodiments described in this invention are only some embodiments of the present invention, and not all embodiments.

[0019] The terminal in this embodiment includes a main control processor, runtime memory running the DTLCP protocol stack, a communication module, and a security chip. The main control processor coordinates the protocol stack and the security chip through a secure communication subsystem. The communication module is used to send and receive data packets between the terminal and the gateway. The security chip provides an internal storage area for the chip master key, a cryptographic operation unit, a power-off key retention slot, and a power-off snapshot retention storage slot. For terminals where memory loses power after hibernation, the runtime memory may lose data during hibernation, while the snapshot and derived key in the security chip are still retained.

[0020] In this embodiment, the terminal can use a domestically produced microcontroller as the main controller, run the FreeRTOS real-time operating system, and the security chip supports SM2 (elliptic curve public key cryptography), SM3 (cryptographic hashing), and SM4 (block symmetric cryptography) cryptographic algorithms. The communication module can be a fourth-generation mobile communication module. The above hardware configuration is used to illustrate the specific deployment environment and does not limit the terminal's processor model, operating system, or wireless access method.

[0021] The chip master key is a root key that is preset at the factory or injected during initialization and stored in the hardware security area of ​​the security chip, such as a one-time programmable storage area. The chip master key does not leave the security chip and the main control processor cannot read its plaintext. The snapshot encryption key and the snapshot authentication key are derived from the chip master key and are used for the authentication encryption of the snapshot and the message authentication of the snapshot text structure, respectively. They have different uses from the working key of the DTLCP session itself.

[0022] The key slots and snapshot storage areas of the security chip are physically isolated from each other in terms of access permissions. The main control processor can only initiate derivation, encryption, decryption, and authentication code operations through the interface and key slot index provided by the internal firmware of the security chip. It cannot directly read the plaintext of the chip master key or snapshot derivation key through the external bus, nor can it directly access the physical address space of the snapshot storage area. The address and capacity of the snapshot storage slot are pre-configured, and its capacity is determined according to the actual field encoding length and authentication data length to accommodate a complete snapshot.

[0023] Preferably, the secure storage area has power-loss retention, access control, and physical tamper protection functions, and supports at least 100,000 erase / write cycles; in deployments with corresponding security level requirements, a security chip with the corresponding certification level can be selected; the physical tamper protection function is used to trigger the erasure of sensitive data when a physical attack is detected; the above protection capabilities are implemented by the selected chip and are not replaced by the terminal main control software directly accessing the secure storage area.

[0024] In this embodiment, the complete DTLCP handshake process includes 6 rounds of message exchange: the client sends ClientHello, the server replies with HelloVerifyRequest (including cookies, anti-DoS), the client resends ClientHello with cookies, the server replies with ServerHello + Certificate + ServerKeyExchange + ServerHelloDone, the client sends Certificate + ClientKeyExchange + CertificateVerify + ChangeCipherSpec + Finished, and the server replies with ChangeCipherSpec + Finished.

[0025] like Figure 1 As shown, one aspect of this application provides a method for fast recovery of DTLCP session state on the terminal side, including steps S100 to S500; wherein, steps S100 to S400 are executed before the terminal is about to enter sleep mode, and step S500 is executed after the terminal wakes up and completes the initialization of the operating environment, and before continuing to send service data using the original session.

[0026] S100. Construct a snapshot metadata structure that includes session state data and snapshot metadata. The session state data includes at least the hash value of the peer certificate extracted from the current DTLCP session, the record layer generation value, the transmission sequence number, the negotiated cipher suite, the session master key and the working key derived from the negotiated cipher suite. The snapshot metadata includes the snapshot generation time and the preset snapshot format version number and snapshot validity period.

[0027] In this embodiment, session state data is extracted from the runtime state area of ​​the DTLCP protocol stack; the record layer generation value is used to identify the generation to which the current cryptographic state belongs, and increments accordingly when the cryptographic specification changes; the transmission sequence number is used to identify the transmission record within that generation; the session master key and working key provide the key materials required for record layer data protection, and the negotiated cryptographic suite is used to determine the applicable cryptographic algorithm, key length, and record processing method; saving the above information is beneficial for restoring the protocol running state to the state before sleep after wake-up.

[0028] The hash value of the peer certificate is used to verify whether it is consistent with the certificate in the gateway if necessary. It is derived from the peer certificate corresponding to the session established before the snapshot was generated.

[0029] Preferably, the session state data also includes the protocol version and compression method; the protocol version is used to restore the protocol stack's interpretation of records and messages, and the compression method is used to restore the corresponding record processing parameters; when the terminal only supports a fixed protocol version and a fixed uncompressed method, the protocol stack can restore these parameters according to its fixed configuration; in implementations that support multiple configurations, they are saved along with the session state to avoid restoring according to the incorrect default configuration.

[0030] In one field encoding method, the protocol version is represented by 2 bytes, the record layer generation value is represented by 2 bytes of unsigned integer, the sending sequence number is represented by 6 bytes of unsigned integer, the session master key is represented by 48 bytes, the cipher suite identifier is represented by 2 bytes, and the compression method is represented by 1 byte, where a compression method of 0 indicates no compression; the hash value of the peer certificate is calculated using the SM3 algorithm and has a length of 32 bytes.

[0031] The working key is stored separately for the terminal sending and receiving directions, including the client-written key, the server-written key, and the corresponding initialization vector. When the cipher suite requires an independent message authentication key, it also includes the client-written message authentication key and the server-written message authentication key. The client-written key is used to protect the records sent by the client, and the server obtains the corresponding key for verification and decryption in the same direction. The server-written key is used to protect the records in the opposite direction. For the SM4 algorithm, the encryption key length is 16 bytes. The initialization vector can be 12 bytes or 16 bytes depending on the cipher suite, and the message authentication key length is also configured according to the cipher suite. The scope of the working key storage mentioned in this application includes the relevant initialization parameters required to restore the operation of the cipher suite. Unused independent message authentication keys do not participate in the record operation of the cipher suite.

[0032] The snapshot generation time can be represented by an 8-byte unsigned integer, recording the millisecond timestamp calculated from the unified time base; the snapshot validity period can be represented by a 4-byte unsigned integer, in seconds, for example, set to 86400 seconds; the snapshot format version number is used to identify the snapshot's data structure and field encoding rules, and can be represented by 2 bytes, for example, the initial format version is 1; when reading a snapshot, the terminal selects a pre-supported parsing rule according to the snapshot format version number. Formats that cannot be recognized or parsed are not used for recovery and are treated as if no snapshot is available.

[0033] The snapshot format version number has a different meaning from the snapshot version number used for rollback prevention: the former is used to select the parsing rules of the data structure, while the latter is used to determine the relationship between the old and new snapshots; when the rollback prevention scheme is adopted, the snapshot metadata further includes the snapshot version number, which can be represented by a 4-byte unsigned integer and incremented when a new snapshot is generated.

[0034] The Quick Illumination text structure logically includes snapshot metadata and session state data; each field is encoded into a byte string according to a preset field order, length, and byte order; the same encoding rules are used for generating snapshot authentication codes, performing associated authentication, and reconstructing the data to be authenticated during recovery; different byte representations must not be used for the same logical field during the generation and verification stages; the Quick Illumination text structure is a temporary data structure used by the chip to perform cryptographic operations, and what is persistently saved is the session state snapshot formed later.

[0035] S200 derives a snapshot encryption key and a snapshot authentication key from the chip master key stored in the security chip and stores them in the power-off retention key slot built into the security chip.

[0036] Preferred, such as Figure 2 As shown, step S200 is implemented using steps S210 and S211: S210 The security chip uses a pseudo-random function specified in GB / T 38636—2020 inside the chip. It uses the chip master key as the key, the preset DTLCP session snapshot purpose identifier as the tag, and the data string formed by concatenating the snapshot generation time, record layer generation value and sending sequence number as the derived parameters to generate snapshot key material.

[0037] S211. Take the first 16 bytes of the snapshot key material as the snapshot encryption key, and take the 32 bytes immediately following the first 16 bytes as the snapshot authentication key.

[0038] In this embodiment, the output length of the pseudo-random function is set to provide the aforementioned 48-byte key material; the snapshot purpose identifier uses a pre-fixed tag byte string to distinguish key derivation for other purposes; the purpose expressed by the tag is a DTLCP session snapshot, and its encoding remains fixed in the same implementation; the time, generation value, and transmission sequence number in the derivation parameters use encoding consistent with their field definitions, and variable format display text is not directly used as a replacement for binary fields.

[0039] R = pseudo-random function (K, L, t‖e‖s) Where R is the snapshot key material, K is the chip master key, L is the snapshot purpose identifier, t is the snapshot generation time, e is the record layer generation value, and s is the transmission sequence number; "‖" indicates that the byte string is concatenated according to the preset rules; the above formula is used to represent the relationship between the inputs, and the specific pseudo-random function operation is implemented according to the aforementioned standard.

[0040] The security chip writes the 16-byte snapshot encryption key and the 32-byte snapshot authentication key into different power-off retention key slots. After writing, the main control program calls the cryptographic operation through the slot index without obtaining the plaintext of the derived key. Each time a new snapshot is generated according to the updated snapshot generation time and session state, the snapshot key can be re-derived and the old key can be overwritten to make the key correspond to the current snapshot.

[0041] This design is primarily based on parameter dependencies during the recovery phase: the record layer generation value and the transmission sequence number are contained in encrypted session state data, and these derived parameters cannot be directly obtained after wake-up without decryption. If only the chip master key is retained and not the derived keys, a circular dependency will occur during recovery, where decryption is required to obtain the derived parameters, and the derived key is required to decrypt. Therefore, this embodiment retains the derived keys even after power loss. After wake-up, the key stored in the key slot is used directly to complete decryption and authentication, without needing to re-execute the key derivation for this snapshot.

[0042] S300: Using the snapshot authentication key, with the snapshot text structure as the data to be authenticated, calculate the snapshot authentication code; using the snapshot encryption key, with a random number pre-generated in the security chip as the initialization parameter, session state data as the data to be encrypted, and snapshot metadata as the associated authentication data, use the authentication encryption algorithm to calculate the encrypted session state data and authentication tag.

[0043] Preferred, such as Figure 3 As shown, the snapshot authentication code is calculated using steps S310 and S311: S310. Concatenate the snapshot format version number, snapshot generation time, snapshot validity period and session status data in the snapshot text structure to obtain the data to be authenticated.

[0044] S311. Using the snapshot authentication key as the key, the hash message authentication code algorithm based on SM3 is used to process the data to be authenticated to obtain the snapshot authentication code.

[0045] In this embodiment, the hash message authentication code algorithm based on SM3 outputs a 32-byte snapshot authentication code. The snapshot authentication code is used to verify whether the reconstructed snapshot message structure after decryption is consistent with that at the time of generation. When using an extended format containing a snapshot version number, the snapshot version number is included in the encoding of the snapshot metadata and is included in the calculation scope of the snapshot authentication code.

[0046] A = Message Authentication Code (K) a M‖P) Where A is the snapshot authentication code, K a M is the snapshot authentication key, P is the snapshot metadata encoded in the current format, and P is the session state data. The message authentication code in the formula is calculated using the aforementioned hash message authentication code algorithm based on SM3.

[0047] In a further preferred embodiment, the authentication encryption algorithm employs a Galois counter mode based on the SM4 block cipher algorithm. The security chip internally generates a 96-bit random number, which is used to perform authentication encryption with a 16-byte snapshot encryption key, outputting session state ciphertext and a 128-bit authentication tag. The random number is saved with the snapshot and serves as an initialization parameter during the recovery phase. When encrypting different data using the same snapshot encryption key, the mode's requirement for non-repetition of initialization parameters must be met.

[0048] (C, T) = Authentication Encryption (K) e (N, P, M) Where C is the encrypted session state data, T is the authentication tag, and K is the authentication tag. e The snapshot encryption key is N, where N is a random number, P is the session state data, and M is the snapshot metadata.

[0049] Snapshot metadata is used as associated authentication data for authentication, but it is not encrypted along with session state data. Therefore, before decrypting the session state, the terminal can obtain information such as the snapshot format version number, snapshot generation time, and validity period, and can check whether this metadata is consistent with the snapshot generation time through the authentication tag. The implementation method with snapshot version number uses the extended complete metadata as associated authentication data to avoid the version field being outside the authentication protection.

[0050] The snapshot authentication code and the authentication tag are two independently stored verification results, calculated using keys for different purposes. The snapshot authentication code is generated based on the snapshot plaintext structure, and the session state plaintext must be obtained before it can be recalculated during recovery. The authentication tag is generated according to the authentication encryption mode and is used to verify the ciphertext and associate authentication data. During recovery, the calculation methods corresponding to the generation stage are called respectively, and the snapshot authentication code is not used as the authentication tag in the authentication encryption output.

[0051] S400 constructs a session state snapshot including snapshot metadata, encrypted session state data, authentication tag, snapshot authentication code, and random number, and stores it in the power-off retainable snapshot storage slot built into the security chip.

[0052] The final persistent snapshot includes the snapshot format version number, snapshot generation time, snapshot validity period, random number, encrypted session state data, authentication tag, and snapshot authentication code; when using an anti-rollback scheme, it also includes the snapshot version number located in the snapshot metadata; the session master key and working key are included in the encrypted session state data and are not saved as plaintext fields of the snapshot; the actual serialization length may differ depending on the snapshot format or cipher suite, and the storage slot capacity is configured according to the final encoding result and cannot be estimated solely based on the number of logical fields.

[0053] During the writing process, the snapshot remains consistent with its two corresponding derived keys; after the security chip completes the persistence of this snapshot and the corresponding key, it uses the slot as a usable snapshot slot; empty slots, slots marked as invalid, and slots that have not formed complete usable data do not enter the state recovery branch; after the terminal completes the necessary snapshot persistence operation, it enters hibernation.

[0054] S500: After the terminal wakes up, determine whether the snapshot storage slot is empty or has been marked as invalid; if so, execute the complete DTLCP handshake process to establish a DTLCP session; if not, decrypt the encrypted session state data and verify the session state snapshot using the preset snapshot verification rules; if the verification is successful, write the decrypted session state data into the terminal's DTLCP protocol stack to restore the DTLCP session state; if the verification fails, mark the snapshot storage slot as invalid and execute the complete DTLCP handshake process to establish a DTLCP session.

[0055] "Marked as invalid" means that the slot will no longer be used as a usable snapshot in the recovery process. Even if there are still historical ciphertext bytes in the slot, it will not be considered as a valid snapshot. The complete handshake after the verification fails is used to establish a new session, and the state that has not yet passed all verifications will not be written into the valid running state area of ​​the current DTLCP protocol stack.

[0056] After restoring the DTLCP session state, without re-performing the DTLCP handshake, DTLCP application data records are sent to the gateway based on the restored session state. The record layer generation value of the application data records is the same as the record layer generation value before hibernation, and the transmission sequence number is incremented based on the sequence number used before hibernation, so as to keep the DTLCP record layer state on the gateway side continuous.

[0057] Preferred, such as Figure 4 As shown, the decryption and snapshot verification in S500 are implemented using steps S501 to S505; when the anti-rollback scheme is adopted, step S506 is further executed; if any step fails, the process will proceed to the snapshot invalidation and complete handshake branch, and the session state will only be restored after all applicable verifications are passed.

[0058] S501. Call the snapshot encryption key in the key slot, calculate the verification authentication tag based on the random number in the session state snapshot, the encrypted session state data, and the snapshot metadata as associated authentication data, and compare it with the authentication tag in the session state snapshot; if the comparison is consistent, determine whether the difference between the snapshot generation time and the current time is greater than the snapshot validity period; if the comparison is inconsistent, determine that the verification fails.

[0059] In this embodiment, the calculation of the authentication tag uses the same SM4 Galois counter mode parameters as the encryption phase, with the input being the snapshot encryption key, random number, ciphertext, and snapshot metadata encoded according to the same rules. The authentication tag in this mode can be calculated and verified based on the above inputs, without being conditional on the pre-output of the session state plaintext. Therefore, the authentication tag verification can be completed first, followed by checking the validity period and performing plaintext recovery. For security chips that encapsulate decryption and authentication tag verification into a single interface, the interface should ensure that plaintext available for recovery is only provided externally after the tag verification is successful, and the internal calculation order remains unchanged, with plaintext not used when verification fails.

[0060] S502. Determine whether the difference between the snapshot generation time and the current time is greater than the snapshot validity period in the session state snapshot; if yes, the verification fails; if no, proceed with subsequent decryption.

[0061] In this embodiment, the time difference specifically refers to the duration of the snapshot obtained by subtracting the snapshot generation time from the current time; the current time and the snapshot generation time use the same time base, both measured in milliseconds; the snapshot validity period is measured in seconds, and the snapshot validity period is multiplied by 1000 to convert it to milliseconds before comparison; for example, if the current time and the snapshot generation time differ by 900,000 milliseconds, and the validity period is 86,400 seconds, 900,000 and 86,400,000 should be compared. If the former does not exceed the latter, it is determined that the snapshot has not expired; if they are equal, it does not belong to the case of "greater than the validity period".

[0062] Duration of existence = Current time - Snapshot generation time Snapshot expiration condition: Existing duration > Snapshot validity period × 1000 The current time can be obtained from the terminal's real-time clock, and the terminal maintains the corresponding time measurement capability during sleep. If the system cannot obtain a current time comparable to the snapshot generation time, it will not accept the snapshot based on an invalid time value. By arranging the validity period check before decryption, expired snapshots can be excluded in advance, provided that the authentication tag has passed, thereby reducing the subsequent decryption and plaintext authentication operations of invalid snapshots.

[0063] S503. When decrypting session state data, the snapshot encryption key in the key slot is called, the random number in the session state snapshot is used as the initialization parameter, the snapshot metadata is used as the associated authentication data, and the authentication encryption algorithm corresponding to the generation stage is used to decrypt the encrypted session state data to obtain the decrypted session state data.

[0064] In this embodiment, decryption is completed inside the security chip, and the recovery process directly uses the persistent derived key. If the chip uses an authentication decryption interface, the stored authentication tag is provided to the interface at the same time, and only the plaintext output after the interface is successfully verified is accepted. At this time, the interface-level verification of the tag is consistent with the pre-verification in S501, and does not change the relationship that each verification stage jointly determines whether the snapshot can be used for recovery.

[0065] S504. Call the snapshot authentication key in the key slot, reconstruct the snapshot text structure using the decrypted session state data and the snapshot metadata in the session state snapshot, use the snapshot text structure as the data to be authenticated, calculate the verification authentication code according to the calculation method used when generating the snapshot authentication code, and compare it with the snapshot authentication code in the session state snapshot; if the comparison is consistent, the verification is deemed successful; if the comparison is inconsistent, the verification is deemed unsuccessful.

[0066] Specifically, in this embodiment, the snapshot authentication key is used as the key, and the hash message authentication code algorithm based on SM3 is used for recalculation. The field order, field length, and byte order of the data to be authenticated are consistent with step S310. If an extended format containing the snapshot version number is used, the reconstructed plaintext structure also includes the version number. If the authentication code is inconsistent, the decrypted session state is not used to continue recovery.

[0067] Further preferred, such as Figure 5 As shown, after the verification code in S504 matches the snapshot authentication code in the session state snapshot and before the final verification is determined, step S505 is executed: determine whether the snapshot version number in the session state snapshot is greater than the current base snapshot version number; if yes, the verification is determined to be successful and the base snapshot version number is set to the snapshot version number; if no, the verification is determined to be unsuccessful.

[0068] In this embodiment, the baseline snapshot version number is stored in the power-down retention area inside the security chip, which cannot be arbitrarily rewritten by external programs. During initialization, the baseline snapshot version number can be set to 0, and the version number of the first snapshot to be saved can be set to 1. During the normal generation, hibernation, and recovery cycle, the next snapshot version number is generated incrementally based on the current baseline. After the snapshot is generated, the baseline is not immediately updated to the version number of the snapshot to be recovered, so as to avoid rejecting the current valid snapshot due to the two being equal during recovery comparison.

[0069] When the authentication label, validity period, snapshot authentication code, and snapshot version comparison all pass, the security chip accepts the snapshot for recovery, and then updates the baseline to the current snapshot version number. For example, if the baseline is 0 and the snapshot version is 1, the version comparison passes and the baseline is updated to 1. When a snapshot with version 1 is submitted again, it is rejected because it is not greater than the current baseline. The next normal cycle generates a snapshot with version 2, which is compared with baseline 1 during recovery. In this way, the snapshot version number and the accepted version baseline form a clear update relationship.

[0070] During a normal recovery cycle, this embodiment retains only one current snapshot for the next wake-up. If the deployment environment allows for multiple generation of alternative snapshots before accepting the previous snapshot, the security chip should also maintain the management rule of incremental version generation for each generation, and should not repeatedly assign the same version to different generation orders simply because the recovery baseline has not been updated. Snapshot version counting and baseline maintenance are both completed internally within the security chip.

[0071] When the snapshot version number is less than or equal to the current baseline, the terminal marks the snapshot slot as invalid and performs a full handshake; in implementations with auditing functionality configured, the security chip also writes rollback exception events to its audit log; the initial baseline and subsequent baselines will not be reset due to normal sleep wake-up, thus maintaining the version comparison basis across sleep cycles.

[0072] After all applicable verifications are passed, the secure communication subsystem writes the session state field into the runtime state area of ​​the DTLCP protocol stack, restoring the record layer generation value, transmission sequence number, cipher suite, session master key, transmission and reception working keys, and other saved protocol parameters; the record layer generation value retains the snapshot value, and the transmission sequence number is not reset to 0; during actual transmission, the sequence number of the next record is generated according to the protocol stack's recording caliber for sequence numbers.

[0073] In this embodiment, the sending sequence number in the snapshot represents the last sent sequence number used before saving; for example, if the snapshot saves a generation value of 1 and a sending sequence number of 5, the next application data record after restoration will use a generation value of 1 and a sending sequence number of 6; by preserving this continuity, the original session is prevented from being restored to a state of resending from the initial sequence number; if the protocol stack stores the next to be sent sequence number, the extraction and restoration should be consistent with this standard, and the two standards should not be mixed.

[0074] The restoration of the terminal's local state and whether the gateway continues to accept the original session are two interrelated steps. When the gateway still holds the corresponding session key and record layer state, it can verify the data sent by the terminal according to the original DTLCP record processing procedure. If the gateway has been restarted, the session has timed out, or the session has been discarded, the terminal may still be unable to continue using the original session after successful local verification. It should roll back to a full handshake according to the exception handling described later. The original DTLCP record format and cipher suite rules remain unchanged, and the terminal's local state is not restored by sending the snapshot content to the gateway.

[0075] If no snapshot is available or verification fails, the terminal performs a complete DTLCP handshake. Taking the handshake process used in this embodiment as an example, the terminal first sends a client greeting, and the gateway returns a verification request with anti-denial-of-service verification information. The terminal sends the client greeting again with the verification information. The gateway sends a server greeting, certificate, key exchange and greeting end messages. The terminal sends the required certificate, client key exchange, certificate verification, password specification switching and completion messages. The gateway returns password specification switching and completion messages. After the handshake is completed, the two parties establish a new session and form a new runtime state. Before the terminal goes to sleep again, it saves a snapshot according to steps S100 to S400.

[0076] For handling the process after a successful snapshot recovery, this embodiment supports the following two strategies.

[0077] The first strategy is the use-and-expires policy: after a snapshot is successfully restored, the security chip immediately marks the snapshot storage slot as invalid, so that the same snapshot is no longer usable data for subsequent restoration; when hibernation is required again, a new snapshot is generated based on the current session state; this strategy is suitable for scenarios where there are high requirements for the single use of snapshots.

[0078] The second strategy is the post-use update strategy: After the snapshot is restored and used for communication, the sending sequence number has been incremented. The terminal re-derives the snapshot key based on the new snapshot generation time, record layer generation value and sending sequence number, and generates a new session state snapshot to overwrite the old snapshot. When the anti-rollback scheme is adopted, the new snapshot version number is incremented. After the new snapshot and new key are persisted, they are used for the next sleep wake-up. This strategy is suitable for scenarios with periodic collection and continuous reporting.

[0079] During the key lifecycle, the generation phase is completed internally by the security chip, including key derivation and key slot writing; the sleep retention phase is maintained by the power-off retention area, which saves the key and snapshots; the recovery phase directly calls the key internally; the update phase overwrites the old key with the new key corresponding to the new snapshot; and the destruction phase makes the old snapshot key unusable through hardware-level key slot clearing operations and marks the corresponding snapshot slot as invalid. Key slot clearing and snapshot invalidation are for different storage objects, and it cannot be assumed that the data in the key slot has been physically erased simply because the snapshot is marked as invalid.

[0080] Preferably, when a DTLCP session is closed normally, either when the terminal receives a session closure notification message from the peer, or when the terminal sends a session closure notification message to the peer, the security chip will mark the snapshot storage slot as invalid and clear the corresponding snapshot encryption key and snapshot authentication key according to the key destruction policy. Sessions that have been normally closed will not be re-entered into use through historical snapshots.

[0081] Preferably, if the terminal uses a snapshot to restore the session state and sends data to the gateway a preset number of times, and receives a handshake request from the gateway each time, the original session is considered no longer suitable for continued use, the snapshot is marked as invalid, and a complete DTLCP handshake is performed. The preset number of times can be 3. In another communication anomaly handling configuration, if the expected response is not received after continuous sending, the corresponding session reconstruction process can also be triggered. The judgment criteria and the situation of receiving an explicit handshake request are recorded separately.

[0082] Preferably, when the terminal receives the "Clear Security Session" command issued by the administrator via the serial port, it calls the security chip interface to clear the corresponding snapshot key and marks the snapshot storage slot as invalid; when the security chip detects a physical attack, it automatically erases all sensitive data stored inside the chip, including session state snapshots and corresponding keys, to avoid simply changing the availability flag while retaining sensitive materials that can be exploited by attacks.

[0083] Snapshot key destruction can be triggered by snapshot expiration, continuous recovery failure, administrator clearing and rollback failure; if the snapshot authentication tag or snapshot authentication code fails to be verified, the terminal will not accept the snapshot, mark it as invalid and enter a full handshake; the new session snapshot is regenerated from the new session state and the snapshot data that failed to be verified will not be reused.

[0084] Further preferably, to reduce the write burden on the secure storage area, a cumulative write strategy can be adopted; when the record layer generation value remains unchanged, the daily changes in the transmission sequence number are temporarily stored in the runtime memory; when the cumulative change in the transmission sequence number reaches a preset threshold compared to the last complete write, such as increasing by 100, or when the record layer generation value changes, the generation and writing of a complete snapshot are triggered; regardless of whether the above threshold is reached, before the terminal is about to enter a hibernation state that would cause the runtime memory to lose power, the current state is still written along with the snapshot to avoid restoring to an earlier transmission position after waking up.

[0085] In incremental update configuration, when only the transmission sequence number changes within the same record layer generation, the transmission sequence number can be regarded as the changed logical field, and the corresponding state content is updated according to its 6-byte field length. When performing persistence, the consistency of the corresponding encryption state, authentication tag, and snapshot authentication code should be maintained synchronously. For the session state overall authentication encryption structure adopted in this embodiment, after changing the transmission sequence number, the affected encryption and authentication processes need to be re-executed. The new 6-byte plaintext cannot be directly overwritten to an offset position in the original ciphertext, nor can the old authentication result that does not correspond to the new state be retained. Whether the physical write volume can be reduced is determined by the storage organization and cryptographic interface of the security chip.

[0086] For example, a terminal that reports and goes into hibernation every 15 minutes corresponds to about 96 persistent operations before hibernation per day, and about 35,000 per year. When selecting a memory that supports at least 100,000 erase / write cycles, the lifespan should be estimated by combining the actual erase / write granularity, hibernation frequency, and additional runtime snapshot update times. The cumulative write strategy mainly reduces unnecessary additional full writes during operation, but it cannot eliminate the need to save the latest session state before each power outage and hibernation.

[0087] The following example illustrates the complete operation process using a water level monitoring terminal deployed at a reservoir site. The terminal is battery powered and collects water level data every 15 minutes. The data is then reported to the IoT security gateway via a DTLCP encrypted channel through the mobile communication network. After completing the reporting, the terminal enters deep sleep mode and is woken up by a real-time clock for the next reporting cycle.

[0088] Upon initial power-up, the snapshot slot is empty. The terminal and gateway perform a full handshake, negotiating a cryptographic suite using SM4 Galois counter mode and SM3 related algorithms to obtain the session master key and corresponding working key. After completing this water level data transmission, the terminal prepares to hibernate. At this point, the record layer generation value of the example session is 1, and the last used transmission sequence number is 5.

[0089] The terminal extracts the session state, including the aforementioned generation value, serial number, cipher suite, session master key, working key, and gateway certificate hash, records the current millisecond timestamp, and sets the validity period to 86400 seconds. The security chip derives and persists the snapshot encryption key and snapshot authentication key, completes the snapshot authentication code calculation and authentication encryption, and writes the final snapshot to the power-off retention slot. When the anti-rollback scheme is adopted, the first snapshot version is 1 and the base version is 0. The terminal then enters deep sleep, and the runtime memory loses power, while the security chip's key slot and snapshot storage area retain the data.

[0090] Fifteen minutes later, the terminal is woken up, initializes the runtime environment and reads the snapshot; the security chip completes the authentication tag verification, the current time minus the snapshot generation time is 900,000 milliseconds, which is less than 86,400,000 milliseconds, so the timeliness verification is passed; then the session state is decrypted, the snapshot authentication code is recalculated and compared; when version verification is used, the snapshot version 1 is greater than the baseline 0, the verification is passed and the baseline is updated to 1.

[0091] The terminal writes the session state back to the protocol stack. The next application data record uses the record layer generation value 1, the sending sequence number is 6, and is encrypted using the working key and initialization parameters corresponding to the client's sending direction. The additional authentication data is constructed according to the selected cipher suite and DTLCP record rules. If the gateway still retains the original session, it processes this record using the receiving key corresponding to the sending direction and delivers the decrypted water level data to the business system. The terminal can then generate the next snapshot according to the post-use update policy, incrementing the version to 2, and then enters sleep mode again.

[0092] In one application example of the above hardware and software configuration, the complete handshake takes about 800 milliseconds, and the snapshot local decryption and verification takes about 5 milliseconds, which reflects the reduction of local recovery overhead caused by the complete handshake; these durations are used to illustrate the operation under this application configuration and do not limit the implementation performance of other devices; the local decryption and verification time is not equal to the total end-to-end communication time including network waiting and service reporting.

[0093] If the terminal fails to complete normal recovery for 3 consecutive days after the snapshot is generated, the existing duration is approximately 259,200,000 milliseconds, which exceeds the validity period corresponding to 86,400 seconds. In this case, the snapshot will not be used, it will be marked as invalid, the corresponding snapshot key will be cleared, and the session will be re-established through a complete handshake. If the gateway restarts and discards the session during the hibernation period, even if the snapshot is still valid and the certificate hash has not changed, the gateway may not be able to process the old session records issued after recovery. The terminal invalidates the old snapshot and rebuilds the session according to the preset abnormal number criteria.

[0094] In this embodiment, the generation, storage, and verification of snapshots are completed on the terminal side, without the need to transmit snapshots to the gateway through a new DTLCP session recovery message. The gateway still processes business data according to the existing DTLCP record layer rules. Thus, the terminal's local snapshot mechanism and the gateway's regular session processing work together to continue the original session when the peer's state conditions are met, and to fall back to a complete handshake when the conditions are not met.

[0095] like Figure 6 As shown, another aspect of the embodiments of this application provides a terminal-side DTLCP session state fast recovery device, including a plaintext construction module, a key derivation module, an authentication encryption module, a snapshot construction module, and a snapshot verification module.

[0096] The plaintext construction module is used to build a plaintext structure that includes session state data and snapshot metadata before the terminal is about to enter sleep mode. The session state data includes at least the hash value of the peer certificate extracted from the current DTLCP session, the record layer generation value, the transmission sequence number, the negotiated cipher suite, the session master key and the working key derived from the negotiated cipher suite; the snapshot metadata includes the snapshot generation time and the preset snapshot format version number and snapshot validity period.

[0097] The key derivation module is used to derive snapshot encryption keys and snapshot authentication keys from the chip master key stored in the security chip, and store them in the power-off retention key slot built into the security chip.

[0098] The authentication encryption module is used to calculate the snapshot authentication code using the snapshot authentication key and the snapshot text structure as the data to be authenticated; and to calculate the encrypted session state data and authentication tag using the snapshot encryption key, the pre-generated random number in the security chip as the initialization parameter, the session state data as the data to be encrypted, and the snapshot metadata as the associated authentication data, using the authentication encryption algorithm.

[0099] The snapshot building module is used to build a session state snapshot that includes snapshot metadata, encrypted session state data, authentication tags, snapshot authentication codes, and random numbers, and stores it in the power-down retainable snapshot storage slot built into the security chip.

[0100] The snapshot verification module is used to determine whether the snapshot storage slot is empty or marked as invalid after the terminal wakes up: If so, the complete DTLCP handshake process is executed to establish a DTLCP session.

[0101] If not, the encrypted session state data is decrypted and the session state snapshot is verified using the preset snapshot verification rules. If the verification is successful, the decrypted session state data is written to the terminal's DTLCP protocol stack to restore the DTLCP session state. If the verification fails, the snapshot storage slot is marked as invalid, and the complete DTLCP handshake process is executed to establish a DTLCP session.

[0102] In this embodiment, the aforementioned modules can be implemented collaboratively by the terminal secure communication subsystem and the firmware within the security chip. The snapshot verification module can further include functional components such as snapshot reading, integrity verification, state recovery, and anomaly handling; their functions correspond to snapshot reading, password verification, runtime state write-back, and anomaly clearing, respectively. The logical division of modules does not require each module to correspond to independent hardware; calculations involving the chip master key and derived keys are still completed within the security chip.

[0103] In another aspect of this application, an electronic device is provided, comprising: at least one processor and a memory; wherein the memory stores computer execution instructions; the at least one processor executes the computer execution instructions stored in the memory, causing the at least one processor to perform the terminal-side DTLCP session state fast recovery method described in the embodiment.

[0104] In another aspect of the embodiments of this application, a computer-readable storage medium is provided, on which a computer program is stored, wherein the computer program, when executed by a processor, controls the device where the computer-readable storage medium is located to perform the terminal-side DTLCP session state fast recovery method described in the embodiments.

[0105] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for fast recovery of DTLCP session state on the terminal side, applied to a terminal equipped with a security chip, characterized in that, This includes performing steps before the terminal enters sleep mode: S100. Construct a snapshot metadata structure that includes session state data and snapshot metadata; the session state data includes the hash value of the peer certificate extracted from the current DTLCP session, the record layer generation value, the transmission sequence number, the negotiated cipher suite, the session master key and the working key derived from the negotiated cipher suite; the snapshot metadata includes the snapshot generation time and the preset snapshot format version number and snapshot validity period. S200: Derive snapshot encryption key and snapshot authentication key from the chip master key stored in the security chip, and store them in the power-off retention key slot built into the security chip. S300. Using the snapshot authentication key, and with the snapshot text structure as the data to be authenticated, calculate the snapshot authentication code. Using the snapshot encryption key, with a pre-generated random number in the security chip as the initialization parameter, session state data as the data to be encrypted, and snapshot metadata as the associated authentication data, the encrypted session state data and authentication tag are calculated using an authentication encryption algorithm. S400 constructs a session state snapshot including snapshot metadata, encrypted session state data, authentication tag, snapshot authentication code and random number, and stores it in the power-off snapshot storage slot built into the security chip; After the terminal wakes up, perform the following steps: S500: Determine if the snapshot storage slot is empty or has been marked as invalid. If so, then perform the full DTLCP handshake procedure to establish a DTLCP session; If not, the encrypted session state data will be decrypted and the session state snapshot will be verified using the preset snapshot verification rules. If the verification is successful, the decrypted session state data will be written to the terminal's DTLCP protocol stack to restore the DTLCP session state. If the verification fails, the snapshot storage slot will be marked as invalid, and the complete DTLCP handshake process will be executed to establish a DTLCP session.

2. The DTLCP session state fast recovery method according to claim 1, characterized in that, In S200, the snapshot encryption key and snapshot authentication key are derived from the chip master key stored in the security chip, including the following steps: S210. The security chip uses a pseudo-random function specified in GB / T 38636—2020 inside the chip. It uses the chip master key as the key, the preset DTLCP session snapshot purpose identifier as the tag, and the data string formed by concatenating the snapshot generation time, record layer generation value and sending sequence number as the derived parameters to generate snapshot key material. S211. Take the first 16 bytes of the snapshot key material as the snapshot encryption key, and the 32 bytes after the first 16 bytes as the snapshot authentication key.

3. The DTLCP session state fast recovery method according to claim 1, characterized in that, In S300, the snapshot authentication key is used to calculate the snapshot authentication code using the snapshot text structure as the data to be authenticated. The steps include: S310. Concatenate the snapshot format version number, snapshot generation time, snapshot validity period and session status data in the snapshot text structure to obtain the data to be authenticated. S311. Using the snapshot authentication key as the key, the hash message authentication code algorithm based on SM3 is used to process the data to be authenticated to obtain the snapshot authentication code.

4. The DTLCP session state fast recovery method according to claim 1, characterized in that, The authentication encryption algorithm in S300 uses the Galois counter mode based on the SM4 block cipher algorithm.

5. The DTLCP session state fast recovery method according to claim 2, characterized in that, The S500 process involves decrypting the encrypted session state data and verifying the session state snapshot using preset snapshot verification rules, including the following steps: S501. The snapshot encryption key in the key slot is invoked. Based on the random number in the session state snapshot, the encrypted session state data, and the snapshot metadata used as associated authentication data, an authentication encryption algorithm is employed to calculate the verification authentication tag, which is then compared with the authentication tag in the session state snapshot. If the comparison is consistent, determine whether the difference between the snapshot generation time and the current time is greater than the snapshot validity period in the session state snapshot; If the comparison is inconsistent, the verification is deemed unsuccessful. S502. Determine whether the difference between the snapshot generation time and the current time is greater than the snapshot validity period in the session state snapshot: If so, the verification is deemed unsuccessful; If not, then decrypt the session state data; S503. When decrypting session state data: the snapshot encryption key in the key slot is called, the random number in the session state snapshot is used as the initialization parameter and the snapshot metadata is used as the associated authentication data, and the authentication encryption algorithm is used to decrypt the encrypted session state data to obtain the decrypted session state data. S504. Call the snapshot authentication key in the key slot, reconstruct the snapshot text structure using the decrypted session state data and the snapshot metadata in the session state snapshot, and use the snapshot text structure as the data to be authenticated. Calculate the verification authentication code using the calculation method used when generating the snapshot authentication code in the session state snapshot, and compare it with the snapshot authentication code in the session state snapshot: If the comparison matches, the verification is considered successful. If the comparison is inconsistent, the verification is deemed unsuccessful.

6. The DTLCP session state fast recovery method according to claim 5, characterized in that, The security chip stores a baseline snapshot version number; the snapshot metadata also includes a snapshot version number generated by incrementing the current baseline snapshot version number; in step S504, before determining that the verification is successful after comparing the verification code with the snapshot authentication code in the session state snapshot, the following steps are executed: S505. Determine whether the snapshot version number in the session state snapshot is greater than the current baseline snapshot version number: If so, the judgment result is determined to be successful, and the baseline snapshot version number is set to be equal to the snapshot version number in the session state snapshot; If not, the verification fails, the snapshot storage slot is immediately marked as invalid, and the complete DTLCP handshake process is executed to establish a DTLCP session.

7. The DTLCP session state fast recovery method according to claim 1, characterized in that, When a DTLCP session is closed normally, or when the terminal uses a preset number of session state snapshots to restore the DTLCP state and receives a handshake request each time, or when the terminal receives a "clear secure session" command, the snapshot storage slot is marked as invalid. When the security chip detects a physical attack, it will erase all sensitive data, including at least a snapshot of the session state.

8. A terminal-side DTLCP session state fast recovery device, applied to a terminal equipped with a security chip, characterized in that, It includes a plaintext construction module, a key derivation module, an authentication encryption module, a snapshot construction module, and a snapshot verification module; The plaintext construction module is used to build a plaintext structure that includes session state data and snapshot metadata before the terminal is about to enter sleep mode. The session state data includes the hash value of the peer certificate extracted from the current DTLCP session, the record layer generation value, the transmission sequence number, the negotiated cipher suite, the session master key and the working key derived from the negotiated cipher suite; the snapshot metadata includes the snapshot generation time and the preset snapshot format version number and snapshot validity period. The key derivation module is used to derive snapshot encryption keys and snapshot authentication keys from the chip master key stored in the security chip, and store them in the power-off retention key slot built into the security chip. The authentication encryption module is used to calculate the snapshot authentication code using the snapshot authentication key and the snapshot text structure as the data to be authenticated. Using the snapshot encryption key, with a pre-generated random number in the security chip as the initialization parameter, session state data as the data to be encrypted, and snapshot metadata as the associated authentication data, the encrypted session state data and authentication tag are calculated using an authentication encryption algorithm. The snapshot building module is used to build a session state snapshot that includes snapshot metadata, encrypted session state data, authentication tags, snapshot authentication codes, and random numbers, and stores it in the power-down retainable snapshot storage slot built into the security chip; The snapshot verification module is used to determine whether the snapshot storage slot is empty or marked as invalid after the terminal wakes up: If so, then perform the full DTLCP handshake procedure to establish a DTLCP session; If not, the encrypted session state data will be decrypted and the session state snapshot will be verified using the preset snapshot verification rules. If the verification is successful, the decrypted session state data will be written to the terminal's DTLCP protocol stack to restore the DTLCP session state. If the verification fails, the snapshot storage slot will be marked as invalid, and the complete DTLCP handshake process will be executed to establish a DTLCP session.

9. An electronic device, comprising: At least one processor and a memory; wherein the memory stores computer-executable instructions; characterized in that, when the at least one processor executes the computer-executable instructions stored in the memory, the at least one processor performs the terminal-side DTLCP session state fast recovery method as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it controls the device containing the computer-readable storage medium to perform the terminal-side DTLCP session state fast recovery method as described in any one of claims 1 to 7.