An adaptive smart meter full-frame dynamic implicit derived streaming encryption method, system and medium
By employing a four-level obfuscation iterative algorithm and a four-layer single-byte streaming encryption technology, the security and real-time issues in UART communication of smart meters are resolved, enabling module identity authentication and secure data transmission for split-type meters, thereby improving the security and reliability of communication.
Patent Information
- Application Number
- CN202611256654.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-19
- Publication Date
- 2026-11-20
AI Technical Summary
Existing UART communication for smart meters suffers from risks such as plaintext frame feature leakage, weak security of key derivation mechanism, plaintext exposure of baud rate negotiation process, insufficient real-time adaptation, and lack of device identity verification. It cannot be adapted to the hardware architecture of split-type meters, resulting in insufficient communication security and reliability.
A four-level obfuscation iterative algorithm is used to generate the session master key. Four layers of single-byte streaming encryption are used to encrypt all fields of the communication frame. Combined with adaptive frame synchronization and out-of-sync resynchronization mechanisms, secure communication is achieved between the base table and the replaceable communication module, realizing strong authentication of module identity and high-security data transmission.
Without altering the native communication frame format or adding extra protocol fields, it effectively resists traffic sniffing, data tampering, and fake frame attacks, adapts to the hardware architecture of split-type electricity meters, improves communication security and reliability, and prevents the leakage of sensitive metering data and unauthorized module access.
Smart Images

Figure CN123144997A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of UART serial communication security for smart split-type electricity meters, embedded dynamic key implicit derivation, UART byte-by-byte streaming encryption and decryption, full-frame obfuscation anti-feature analysis, and serial port baud rate adaptive matching. Specifically, it relates to a method, system, and medium for full-frame dynamic implicit derivation streaming encryption adapted to smart meters. Background Technology
[0002] Currently, smart meters generally adopt a split hardware architecture of "fixed base meter + replaceable communication module". The base meter and the module communicate with each other via UART serial port. The industry mostly uses custom communication protocols, each with its own native frame format.
[0003] In existing technical solutions, the encryption of UART communication between the smart energy meter base and the communication module has the following core technical defects: First, the risk of plaintext frame feature leakage is high. Most schemes transmit key fields such as frame identifiers and synchronization words in plaintext. Attackers can accurately segment the frame structure, identify the communication timing, and capture data by listening to serial port traffic, and then carry out attacks such as traffic analysis, frame replay, and pseudo-frame injection.
[0004] Secondly, the key derivation mechanism has weak security. Some dynamic key schemes use simple XOR or concatenation to generate session keys, which have high linearity and poor diffusion. Attackers can fit the complete key after obtaining partial information. Furthermore, the key negotiation process requires the transmission of random factors in plaintext, further increasing the risk of leakage.
[0005] Third, the baud rate negotiation process exposes plaintext characteristics. After the communication module is powered on, it needs to match the baud rate through plaintext polling frames, switch candidate baud rates one by one, and send plaintext probe frames. This interaction process completely exposes the protocol frame format and communication parameters, providing convenience for attackers to reverse analyze the protocol.
[0006] Fourth, there are defects in real-time adaptation. Some solutions require batch decryption after full frame buffering, which disrupts the business logic of the meter's native UART interrupt for byte-by-byte reception, byte-by-byte storage, and unified parsing after frame completion. This can easily lead to problems such as packet loss, communication delay, and abnormal metering data, making it unsuitable for the real-time operation requirements of the meter.
[0007] Fifth, the lack of a device identity verification mechanism allows for the unauthorized access and data theft of counterfeit modules. Existing solutions do not authenticate the communication modules, allowing any third-party module to initiate interaction, posing a risk of sensitive data leakage. It is particularly important to note that the split-type smart meter addressed in this invention employs a hardware architecture of "fixed base meter + hot-swappable communication module." The base meter and communication module are two physically independent and separable units, and the communication module can be freely disassembled and replaced on-site by users or maintenance personnel. In a fixed connection architecture, the identities of the communicating parties are relatively fixed, typically eliminating the need for frequent identity verification. However, in a split, replaceable architecture, the base meter cannot predict whether the accessed module is a legitimate, compliant unit or a counterfeit third-party module. Without a strict identity authentication mechanism, unauthorized modules can easily impersonate legitimate devices to access the system, thereby stealing sensitive metering data or injecting malicious control commands. Therefore, this solution introduces a factory-pre-set pair of public and private keys for two-way authentication, precisely to fill the identity trust gap in the split architecture and achieve physical layer interception of illegal counterfeit module access. This security requirement and the corresponding hardware architecture constraints do not exist in the existing fixed connection meter communication solutions.
[0008] In summary, existing technologies are mostly designed for fixed-connection communication links and cannot be adapted to the "base meter-hot-swappable module" architecture of split-type electricity meters. There is an urgent need for a solution that can achieve strong module identity authentication and high-security data transmission under conditions of unknown baud rate, no additional protocol overhead, and low computing power. Summary of the Invention
[0009] The purpose of this invention is to address the aforementioned problems by proposing a method, system, and medium for full-frame dynamic implicit derived streaming encryption adapted to smart meters. It generates a session master key through a four-level obfuscation iterative algorithm, employs four layers of single-byte streaming encryption to achieve full-field encryption of communication frames, and includes an adaptive frame synchronization and resynchronization mechanism. Without altering the original communication frame format or adding extra protocol fields, it achieves secure communication between the base meter and replaceable communication modules, effectively resisting traffic sniffing, data tampering, pseudo-frame and replay attacks, and is compatible with the hardware architecture of split-type meters.
[0010] The technical solution of this invention is: In a first aspect, the present invention provides a full-frame dynamic implicit derived streaming encryption method adapted to smart meters, applied to UART communication scenarios between a base meter and a replaceable communication module, comprising the following steps: S1. Factory preset and power-on initialization steps: Preset a public key cryptographic algorithm key pair between the base table and the communication module. The base table stores its own private key and the module's public key. The module stores its own private key and the base table's public key. After power-on, the base table operates at the default baud rate and generates its own unique power-on random seed Seed_b. The module completes serial port parameter initialization and generates its own unique power-on random seed Seed_m. S2, Module-side encrypted baud rate adaptive polling steps: The module initiates polling according to the candidate baud rate list, constructs a baud rate polling plaintext frame based on its own random seed Seed_m and native frame format, and encapsulates the baud rate polling plaintext frame with ciphertext based on the base table public key to obtain a baud rate polling ciphertext frame, and sends the baud rate polling ciphertext frame to the base table with the current candidate baud rate; S3. Base table side decryption verification and encryption response steps: The base table continuously listens to serial port data at a fixed baud rate. After receiving a data frame, it uses its own private key to decapsulate it. If the decapsulated data conforms to the original frame format specification and is a baud rate polling frame, it extracts and saves the module random seed Seed_m, fills its own random seed Seed_b into the reserved area of the original frame format, assembles it into a baud rate response plaintext frame, and performs ciphertext encapsulation based on the module public key to obtain a baud rate response ciphertext frame to reply to the module. S4. Implicit Derivation Steps for Dynamic Session Master Key: After receiving the ciphertext frame of the response, the module uses its own private key to decapsulate it. If the verification is successful, the current candidate baud rate is confirmed to be the matching baud rate and locked as the baud rate for subsequent business communication. The module and base table synchronization is performed based on the base table random seed Seed_b and the module random seed Seed_m. A consistent session master key MasterKey is obtained by using a dual-seed four-level confusion hybrid iterative algorithm for business communication. S5. Four-layer single-byte full-frame streaming encryption steps: During the business communication phase, the session master key MasterKey is used as the working key and as the module or base table of the sending end to perform four-layer progressive encryption operations of S-box obfuscation, bit diffusion, key mixing and byte linkage perturbation on the entire content of the business communication frame to obtain the ciphertext bytes of the business communication frame; no additional protocol fields are introduced into the original frame or the payload length is changed throughout the process; S6. Byte-by-byte real-time decryption steps: As the base table or module of the receiving end, each time a ciphertext byte of a service communication frame is received, the reverse linkage perturbation, reverse key mixing, reverse diffusion, and reverse S-box obfuscation operations are performed synchronously to restore the plaintext byte of the service communication frame in real time and store it in the buffer area of the original frame.
[0011] Furthermore, in S1, the public key cryptography algorithm key pair is only used for baud rate negotiation and random seed ciphertext encapsulation in the first frame, and is not used to directly encrypt business data; its algorithm specifications are adapted to low-computing-power embedded operating environments, and elliptic curve cryptography, RSA algorithm, or lightweight public key encryption algorithm suitable for embedded environments are selected.
[0012] Furthermore, S2 includes: S21. The module selects the current candidate baud rate configuration communication interface according to the candidate baud rate list, carries its own random seed Seed_m in the reserved field of the native frame format, and assembles it into a baud rate polling plaintext frame. S22. Encapsulate the baud rate polling plaintext frame with ciphertext based on the base table public key to obtain the baud rate polling ciphertext frame. S23. Send the baud rate polling ciphertext frame to the base table at the current candidate baud rate and start the timeout countdown; S24. If no baud rate polling ciphertext response frame is received within the timeout period, switch to the next candidate baud rate and return to S21 to re-execute the framing, encapsulation, and transmission process.
[0013] Furthermore, the dual-seed four-level confusion hybrid iterative algorithm described in S4 is specifically as follows: S41, Bit-width extension concatenation: Concatenate the 8-bit module random seed Seed_m and the 8-bit base table random seed Seed_b into a 16-bit intermediate variable, with the high 8 bits being Seed_m and the low 8 bits being Seed_b; S42, Cyclic Shift Diffusion: Perform a fixed-number left cyclic shift on a 16-bit intermediate variable to achieve full-bit diffusion; S43, High and Low Byte Interleaving Compression: Perform modulo addition and XOR interleaving operations on the high 8 bits and low 8 bits of the shifted 16-bit data to compress it into an 8-bit intermediate result; S44. Constant whitening output: Perform an XOR operation between the 8-bit intermediate result and the fixed whitening constant to obtain the final session master key.
[0014] Furthermore, the mathematical expression for the four-level confusion-mixing iterative algorithm is: ; in, Represents 16-bit data Circular left shift Bit, This is the whitening constant for the master key.
[0015] Furthermore, the four-layer progressive encryption operation described in S5 is specifically as follows: The first layer performs S-box obfuscation: a single byte is split into the high 4 bits and the low 4 bits, and then reassembled after being independently permuted by two sets of fixed read-only bijective nonlinear S-boxes. The second layer performs bit diffusion: after the S-box is confused, the bytes are first left circularly shifted to scatter the bit positions, and then the high and low nibbles are swapped to achieve diffusion across nibbles; The third layer executes key mixing: the lower 3 bits of the session master key MasterKey dynamically control the number of cyclic shifts, splitting the high and low nibbles to perform modulo addition and XOR differential operations respectively, and finally cross-merging the output; The fourth layer performs byte perturbation: the low-order feature value of the previous ciphertext byte in the business communication frame is superimposed as the dynamic offset. The perturbation factor of the first byte of each frame is fixed at 0, and the dynamic offset is updated bit by bit starting from the second byte.
[0016] Furthermore, it also includes the S7 resynchronization step, specifically: If multiple consecutive frames fail to verify, the iteration state mismatches, the module is plugged in or unplugged, or the base table is reset, communication is considered out of sync. When the base table detects a communication loss of synchronization, it disconnects the module power supply and then turns the power supply back on and performs a hardware reset of the module, and then performs a soft clear of the session master key status. When the module detects a communication failure, it automatically resets. Subsequently, the base table detects the module reset and performs a soft reset of the session master key (MasterKey) status. In both cases, the module re-initiates the module-side encryption baud rate adaptive polling process. Both parties regenerate a random seed and complete a new round of negotiation using a public-key cryptography key pair to restore normal communication.
[0017] Furthermore, it also includes an adaptive step for S8 module replacement, specifically: If a faulty module is removed and a brand-new, compatible module is powered on and inserted, the module will automatically perform a handshake process to regenerate a random seed and generate a new session master key (MasterKey). A third-party forged module without a matching public and private key cannot pass identity verification after being plugged in or removed, and an encrypted communication link cannot be established.
[0018] Secondly, the present invention provides a full-frame dynamic implicit derived streaming encryption system adapted to smart meters for implementing the method described above.
[0019] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed, implements the method described thereon.
[0020] The beneficial effects of this invention are: This invention utilizes a factory-preset public-key cryptography algorithm key pair to complete the first frame ciphertext negotiation and random seed exchange between the two parties. The four-level confusion hybrid iterative algorithm causes a change in a single input bit to induce multi-bit nonlinear diffusion in the output key. When any one bit in Seed_m or Seed_b is flipped, the final MasterKey will change by an average of about 4.25 bits, which fully meets the strict avalanche criterion requirement. The four-layer single-byte streaming encryption achieves high nonlinearity resistance to cracking through 4-bit nonlinear S-box permutation, bit diffusion, key-controlled shift dual-domain cross-mixing, and adjacent byte linkage perturbation. The key is not transmitted through the channel throughout the process, resulting in good security and high reliability.
[0021] In this invention, the byte-by-byte real-time decryption fully retains the native UART interrupt byte-by-byte reception logic, eliminating the need for full-frame buffering and communication delay, thus adapting to the real-time operation requirements of the electricity meter. The out-of-synchronization mechanism achieves automatic recovery without manual intervention by automatically detecting communication anomalies, triggering module hard reset or autonomous reset, and re-executing the encryption baud rate polling process. The module replacement adaptive mechanism generates an independent key after each module replacement, rendering all historically stored communication ciphertexts invalid and completely avoiding the risk of replaying historical data streams.
[0022] The solution of this invention does not require modification of the original communication frame or the addition of extra protocol fields. It operates purely in software with a lightweight design and does not require dedicated encryption hardware. This significantly improves the communication security and reliability of split-type smart meters, prevents the leakage of sensitive metering data and unauthorized module access, and ensures the integrity and confidentiality of smart grid communication.
[0023] Other features and advantages of the present invention will be described in detail in the following detailed description section. Attached Figure Description
[0024] The above and other objects, features and advantages of the present invention will become more apparent from the more detailed description of exemplary embodiments of the invention in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the invention.
[0025] Figure 1 A flowchart of a full-frame dynamic implicit derived streaming encryption method for smart meters according to an embodiment of the present invention is shown. Detailed Implementation
[0026] Preferred embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While preferred embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be limited to the embodiments set forth herein.
[0027] Figure 1 A flowchart of a full-frame dynamic implicit derived streaming encryption method for smart meters according to an embodiment of the present invention is shown.
[0028] like Figure 1 As shown, this invention provides a full-frame dynamic implicit derived streaming encryption method adapted to smart meters, applied to UART communication scenarios between the base meter and replaceable communication modules. This embodiment is adapted to split-type smart meters, compatible with all types of replaceable external communication modules, and can adapt to various native communication frame formats. All method logic is implemented purely in software and can be directly run on embedded systems, including the following steps: 1. Definition of Prerequisite Parameters Protocol common parameters: polling timeout threshold 200ms, master key whitening constant 0xA5; Candidate baud rate list: {9600bps, 19200bps, 38400bps, ...}; The default baud rate for the base table is 19200bps. Cryptographic system parameters: A factory-preset fixed public-key cryptographic algorithm key pair (base table private key / public key, module private key / public key) is used only for baud rate negotiation and seed ciphertext encapsulation in the first frame, and does not directly encrypt business data. After encapsulation, no additional protocol fields are introduced into the original communication frame or the payload length is changed, ensuring full compatibility with the original protocol and adaptability to low-computing-power embedded operating environments. The public-key cryptographic algorithm can be an elliptic curve cryptography algorithm, RSA algorithm, or a lightweight public-key encryption algorithm suitable for embedded environments, only needing to meet the security requirements of random seed ciphertext encapsulation.
[0029] Fixed S-box parameters: The high 4 bits of the positive S box: S_hi
[16] = {0x06,0x0A,0x03,0x0F,0x02,0x0C,0x05,0x09,0x01,0x07,0x0B,0x0D,0x04,0x00,0x08,0x0E}; The lower 4 bits of the positive S box: S_lo
[16] = {0x09,0x02,0x0C,0x06,0x0A,0x01,0x0F,0x07,0x03,0x0D,0x05,0x00,0x0E,0x04,0x08,0x0B}; The high 4 bits of the inverse S-box: Inv_S_hi
[16] = {0x0D,0x08,0x04,0x02,0x0C,0x06,0x00,0x09,0x0E,0x07,0x01,0x0A,0x05,0x0B,0x0F,0x03}; The lower 4 bits of the inverse S-box: Inv_S_lo
[16] = {0x0B,0x05,0x01,0x08,0x0D,0x0A,0x03,0x07,0x0E,0x00,0x04,0x0F,0x02,0x09,0x0C,0x06}; The aforementioned S-box is a pre-designed bijective nonlinear permutation box, whose differential uniformity and linear approximation advantages are superior to random permutations, making it suitable for lightweight encryption requirements in low-computing-power embedded scenarios.
[0030] Example of random seed: Module random seed Seed_m=0x3C, base table random seed Seed_b=0x5A.
[0031] 2. Baud Rate Adaptive Polling and Implicit Key Negotiation Process (1) Power-on initialization: After power-on, the base table is configured with UART set to 19200bps, continuously listens to the serial port, and generates its own random seed Seed_b=0x5A; after power-on, the module loads the candidate baud rate list, generates its own random seed Seed_m=0x3C, and initializes the algorithm state variables. The factory-preset fixed public key cryptographic algorithm key pair is stored in the device storage and is only called during the negotiation phase.
[0032] (2) First round of baud rate polling of the module (9600bps): The module is configured with UART at 9600bps, and Seed_m=0x3C is assembled with the native frame format into a plaintext polling frame; the frame data containing the random seed is encapsulated based on the base table public key, and the effective payload length after encapsulation is completely consistent with the native format; the ciphertext frame is sent and a 200ms timeout is started; the base table is working at 19200bps and cannot correctly receive and parse 9600bps data, and there is no response output; the module does not receive a response after a 200ms timeout, and it is determined that 9600bps does not match, and the next candidate baud rate is switched.
[0033] (3) Second round of baud rate polling of the module (19200bps): The module is configured with UART at 19200bps, reassembles the same plaintext polling frame and completes ciphertext encapsulation based on the base table public key; sends the ciphertext frame and starts the timeout countdown; the base table correctly receives the data at 19200bps, decapsulates it using its own factory private key, verifies the legal plaintext polling frame, and extracts and saves Seed_m=0x3C; the base table assembles a response plaintext frame containing Seed_b=0x5A, completes ciphertext encapsulation based on the module public key and replies at 19200bps.
[0034] (4) Dual-seed implicit derived session master key: When the module receives the ciphertext response frame within the timeout period, it uses its own factory private key to decapsulate and obtain a valid plaintext response frame, and the verification passes; it confirms that 19200bps is the matching baud rate and locks this baud rate as the baud rate for subsequent business communication; it extracts the base table seed Seed_b=0x5A and executes the dual-seed four-level obfuscation hybrid iterative algorithm to generate a dynamic session master key. The specific calculation process is as follows: Step 1: Width Expansion and Splicing: Temp1 = (uint16_t)Seed_m << 8 | Seed_b = (0x3C << 8) | 0x5A = 0x3C5A; Step 2: Left circular shift of 16 bits by 5 bits for expansion: Temp2 = ROL16(Temp1, 5) = 0x8B47; Operation description: 16-bit data is left-circularly shifted by 5 bits, with the high 5 bits shifted to the low bits, (0x3C5A << 5) & 0xFFFF | (0x3C5A >> 11) = 0x8B40 | 0x0007 = 0x8B47; Step 3: High and low byte interleaving compression: High 8 bits 0x8B, Low 8 bits 0x47; Temp3 = ((0x8B + 0x47) & 0xFF) ^ 0x8B = 0xD2 ^ 0x8B = 0x59; Step 4: Constant whitening output: MasterKey=Temp3^0xA5=0x59^0xA5=0xFC.
[0035] The base table performs identical four-level operations synchronously to obtain the same master key 0xFC. After negotiation, the factory-issued public key cryptographic algorithm key pair no longer participates in business communication. In the business phase, MasterKey=0xFC is directly used as the working key for a single frame.
[0036] This obfuscation algorithm can cause a single input bit change to cause multiple nonlinear diffusions in the output key, significantly enhancing key sensitivity. Tests have verified that when any one bit in Seed_m or Seed_b is flipped, the final MasterKey will have an average of about 4.25 bits changed. The bit flipping probability is close to that of an ideal random function, which fully meets the requirements of the strict avalanche criterion.
[0037] 3. Business encryption process Single-byte encryption is the smallest unit of operation in stream encryption. It is executed byte by byte, with only 8 bits of native operations throughout, resulting in extremely low computational overhead. It is suitable for encrypting any byte within a communication frame.
[0038] First layer: Dual 4-bit nonlinear S-box replacement; the 8-bit plaintext is split into high 4 bits and low 4 bits, and each bit is independently permuted by two sets of fixed read-only bijective S-boxes, completely breaking the linear characteristics of the original data.
[0039] C uint8_t hi = (PlainByte >> 4) & 0x0F; uint8_t lo = PlainByte & 0x0F; uint8_t s_byte = (S_hi[hi] << 4) | S_lo[lo]; Second layer: Circular shift + half-byte swap diffusion; Perform bit diffusion on the S-box obfuscated bytes to scatter bit positions and enhance the diffusion effect across half-bytes.
[0040] C / / 8 bits left circular shift by 1 bit uint8_t rol1 = ((s_byte << 1) | (s_byte >> 7)) & 0xFF; / / Swap high and low 4 bits uint8_t diff_byte = ((rol1 & 0x0F) << 4) | ((rol1 & 0xF0) >> 4); The third layer: key-controlled shift + dual-domain cross-hybrid; using the session master key as the operation key, the lower 3 bits of the key dynamically control the number of cyclic shifts, splitting the high and low nibbles to perform modulo addition and XOR differential operations respectively, and cross-merging the output to achieve deep non-linear coupling between the key and plaintext.
[0041] C / / The lower 3 bits of the key control the number of bits for the circular left shift uint8_t shift = MasterKey & 0x07; uint8_t rol_key = ((diff_byte << shift) | (diff_byte >> (8 - shift)))& 0xFF; / / Split the high and low nibbles and perform differential operations uint8_t data_hi = (rol_key >> 4) & 0x0F; uint8_t data_lo = rol_key & 0x0F; uint8_t key_hi = (MasterKey >> 4) & 0x0F; uint8_t key_lo = MasterKey & 0x0F; uint8_t mix_hi = (data_hi + key_hi) & 0x0F; / / High-order modulo-16 addition uint8_t mix_lo = data_lo ^ key_lo; / / XOR the least significant bits / / Cross merge uint8_t keyed_byte = (mix_lo << 4) | mix_hi; Fourth layer: Adjacent byte linkage perturbation correction; superimposed with the lower 4 bits of the previous ciphertext byte as a perturbation factor; the first byte of each frame has no preceding ciphertext, Delta is fixed at 0, and is updated bit by bit starting from the second byte.
[0042] C / / Frame initialization: delta = 0x00 / / Starting from byte 2: delta = previous ciphertext & 0x0F uint8_t CipherByte = (keyed_byte + Delta) & 0xFF; Byte-by-byte decryption reverse process: Decryption is the strict inverse operation of encryption, executed byte-by-byte in real time, with the same computational cost as encryption. Since both the S-box and its inverse S-box are strict bijective permutations, the first-layer encryption operation has global reversibility, ensuring lossless recovery in subsequent decryption processes. Simultaneously, because the high-order bits use modulo-16 addition and the low-order bits use XOR operations, and both have closed value ranges, the third-layer cross-merging operation is a bijective transformation, possessing a unique inverse operation. This includes: Inverse linkage perturbation: uint8_t keyed_byte = (CipherByte - Delta) & 0xFF; Inverse key mixing: Inverse cross-merging → Inverse half-byte double-field operation → Inverse dynamic cyclic shift, restoring to diff_byte; Inverse diffusion: Inverse high-low 4-bit swap → Right cyclic shift by 1 bit, restoring to s_byte; Inverse S-box replacement: Restoring the plaintext byte by looking up the table using the inverse S-box.
[0043] 4. Example of a single-byte encryption / decryption process (1) First byte encryption example: Input conditions: plaintext byte 0x7E, session master key MasterKey=0xFC, first byte Delta=0x00; 1. S-box replacement: hi=0x7→0x09, lo=0xE→0x08 → s_byte = 0x98; 2. Diffusion layer: left loop 1 bit to get 0x31, high and low 4 bits swap → diff_byte = 0x13; 3. Key mixing: shift = 0xFC& 0x07 = 4; 0x13 left loop 4 bits → rol_key = 0x31; data_hi=0x3, data_lo=0x1; key_hi=0xF, key_lo=0xC; mix_hi = (0x3+0xF) & 0x0F = 0x02; mix_lo = 0x1^0xC = 0xD; 4. Cross-merge → keyed_byte = 0xD2; 5. Linked perturbation: Delta = 0, final ciphertext → 0xD2; 6. Perturbation update: next byte Delta = 0xD2 & 0x0F = 0x02 (2) First byte decryption verification: 1. Inverse perturbation: 0xD2 - 0x00 = 0xD2; 2. Inverse key mixing: mix_lo=0xD, mix_hi=0x02; data_hi = (0x02 - 0xF) & 0x0F = 0x3; data_lo = 0xD ^ 0xC = 0x1 → rol_key=0x31; shift=4, right loop 4 bits → diff_byte=0x13; 3. Inverse diffusion: swap high and low 4 bits to get 0x31, right loop 1 bit → s_byte=0x98; 4. Inverse S-box: hi=0x9→0x07, lo=0x8→0x0E → restore plaintext byte 0x7E All bytes within the communication frame are iteratively encrypted / decrypted byte by byte according to the above rules to complete the transmission of the entire frame.
[0044] 5. Synchronization and Module Replacement Process for Missed Phases If issues such as byte loss, device reset, module insertion / removal, or decryption failure occur, it will cause the encryption / decryption iteration state to become out of sync. Once communication out of sync is determined, the receiving end automatically clears the session master key (MasterKey) and all temporary dynamic states of the algorithm, triggering a complete handshake renegotiation mechanism. The module will restart the encrypted baud rate polling process with private key signature from the first baud rate in the candidate baud rate list. The base table and the module will respectively regenerate the random seeds Seed_b and Seed_m specific to this power-on. Based on the factory-paired public key cryptographic algorithm key pair, identity verification, baud rate matching, and implicit derivation of the session master key will be completed again. After two complete and valid business data frames are verified consecutively, the system will automatically resume normal encrypted communication without any manual intervention.
[0045] The legitimate business data frame refers to a complete communication frame whose decrypted message conforms to the original protocol's header identifier, whose length field is within the protocol's allowed range, and whose frame tail checksum is correct. The system determines communication synchronization failure under the following triggering conditions: multiple consecutive frames with invalid field structures, abnormal frame format verification, encryption / decryption iteration state mismatch, physical removal / re-insertion of the module, power-on reset of the base table, and power-on reset of the module.
[0046] The following logic is provided for handling out-of-sync issues detected on different device sides: If communication synchronization failure is detected by the base table: the base table first issues a control command to perform a module hard reset operation, and then locally clears all key states; If the module itself identifies the communication out-of-sync issue: the module autonomously completes a local device reset. After the reset, the base table detects the module's offline reset event and synchronously clears the local key state. After the above two types of out-of-sync handling are completed, the module automatically restarts the signed encrypted baud rate polling process. The base table and the module re-exchange random seeds, rely on the paired public key cryptographic key pair to complete identity authentication and key derivation, and establish a new power-on encrypted communication link. The entire resynchronization process runs automatically without the need for maintenance personnel to manually restart any device.
[0047] Meanwhile, for on-site module replacement scenarios: after a faulty module is removed and a brand-new, compatible module is powered on and inserted, the module automatically executes a complete signature authentication handshake process, regenerates a random seed, synchronizes the frame count benchmark, and generates a brand-new MasterKey; third-party forged modules without paired public and private keys cannot pass identity verification after being plugged in or out, and can never establish an encrypted communication link, continuously intercepting illegal access and replay attacks from the hardware plugging and unplugging scenario; each time a module is replaced, an independent key is generated, and all historically stored communication ciphertexts become invalid, completely avoiding the risk of historical data stream replay.
[0048] This invention also provides a full-frame dynamic implicit derived streaming encryption system adapted to smart meters. The system includes modules that correspond one-to-one with the steps of the above method and are used to implement all or part of the process of the method. Each module can be implemented by hardware, software or a combination of both.
[0049] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed, implements all or part of the process of the method.
[0050] The various embodiments of the present invention have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments.
Claims
1. A full-frame dynamic implicit derived streaming encryption method adapted for smart meters, applied to UART communication scenarios between the base meter and replaceable communication modules, characterized in that... Includes the following steps: S1. Factory preset and power-on initialization steps: Preset a public key cryptographic algorithm key pair between the base table and the communication module. The base table stores its own private key and the module's public key. The module stores its own private key and the base table's public key. After power-on, the base table operates at the default baud rate and generates its own unique power-on random seed Seed_b. The module completes serial port parameter initialization and generates its own unique power-on random seed Seed_m. S2, Module-side encrypted baud rate adaptive polling steps: The module initiates polling according to the candidate baud rate list, constructs a baud rate polling plaintext frame based on its own random seed Seed_m and native frame format, and encapsulates the baud rate polling plaintext frame with ciphertext based on the base table public key to obtain a baud rate polling ciphertext frame, and sends the baud rate polling ciphertext frame to the base table with the current candidate baud rate; S3. Base table side decryption verification and encryption response steps: The base table continuously listens to serial port data at a fixed baud rate. After receiving a data frame, it uses its own private key to decapsulate it. If the decapsulated data conforms to the original frame format specification and is a baud rate polling frame, it extracts and saves the module random seed Seed_m, fills its own random seed Seed_b into the reserved area of the original frame format, assembles it into a baud rate response plaintext frame, and performs ciphertext encapsulation based on the module public key to obtain a baud rate response ciphertext frame to reply to the module. S4. Implicit Derivation Steps for Dynamic Session Master Key: After receiving the ciphertext frame of the response, the module uses its own private key to decapsulate it. If the verification is successful, the current candidate baud rate is confirmed to be the matching baud rate and locked as the baud rate for subsequent business communication. The module and base table synchronization is performed based on the base table random seed Seed_b and the module random seed Seed_m. A consistent session master key MasterKey is obtained by using a dual-seed four-level confusion hybrid iterative algorithm for business communication. S5. Four-layer single-byte full-frame streaming encryption steps: During the business communication phase, the session master key MasterKey is used as the working key. As the module or base table of the sending end, the entire content of the business communication frame is subjected to four-layer progressive encryption operations of S-box obfuscation, bit diffusion, key mixing and byte linkage perturbation byte by byte to obtain the ciphertext bytes of the business communication frame. No additional protocol fields are introduced into the native frames or the payload length is changed throughout the entire process; S6. Byte-by-byte real-time decryption steps: As the base table or module of the receiving end, each time a ciphertext byte of a service communication frame is received, the reverse linkage perturbation, reverse key mixing, reverse diffusion, and reverse S-box obfuscation operations are performed synchronously to restore the plaintext byte of the service communication frame in real time and store it in the buffer area of the original frame.
2. The full-frame dynamic implicit derived streaming encryption method for smart meters as described in claim 1, characterized in that... In S1, the public key cryptography algorithm key pair is only used for baud rate negotiation and random seed ciphertext encapsulation in the first frame, and is not used to directly encrypt business data; Its algorithm specifications are adapted to low-computing-power embedded operating environments, and it selects elliptic curve cryptography, RSA algorithm, or lightweight public-key encryption algorithm suitable for embedded environments.
3. The full-frame dynamic implicit derived streaming encryption method for smart meters as described in claim 1, characterized in that S2 include: S21. The module selects the current candidate baud rate configuration communication interface according to the candidate baud rate list, carries its own random seed Seed_m in the reserved field of the native frame format, and assembles it into a baud rate polling plaintext frame. S22. Encapsulate the baud rate polling plaintext frame with ciphertext based on the base table public key to obtain the baud rate polling ciphertext frame. S23. Send the baud rate polling ciphertext frame to the base table at the current candidate baud rate and start the timeout countdown; S24. If no baud rate polling ciphertext response frame is received within the timeout period, switch to the next candidate baud rate and return to S21 to re-execute the framing, encapsulation, and transmission process.
4. The full-frame dynamic implicit derived streaming encryption method for smart meters as described in claim 1, characterized in that, The dual-seed, four-level confusion-mixed iterative algorithm described in S4 is as follows: S41, Bit-width extension concatenation: Concatenate the 8-bit module random seed Seed_m and the 8-bit base table random seed Seed_b into a 16-bit intermediate variable, with the high 8 bits being Seed_m and the low 8 bits being Seed_b; S42, Cyclic Shift Diffusion: Perform a fixed-number left cyclic shift on a 16-bit intermediate variable to achieve full-bit diffusion; S43, High and Low Byte Interleaving Compression: Perform modulo addition and XOR interleaving operations on the high 8 bits and low 8 bits of the shifted 16-bit data to compress it into an 8-bit intermediate result; S44. Constant whitening output: Perform an XOR operation between the 8-bit intermediate result and the fixed whitening constant to obtain the final session master key.
5. The full-frame dynamic implicit derived streaming encryption method for smart meters as described in claim 4, characterized in that... The mathematical expression for the four-level confusion-mixing iterative algorithm is: ; in, Represents 16-bit data Circular left shift Bit, This is the whitening constant for the master key.
6. The full-frame dynamic implicit derived streaming encryption method for smart meters as described in claim 1, characterized in that, The four-layer progressive encryption operation described in S5 is as follows: The first layer performs S-box obfuscation: a single byte is split into the high 4 bits and the low 4 bits, and then reassembled after being independently permuted by two sets of fixed read-only bijective non-linear S-boxes. The second layer performs bit diffusion: after the S-box is confused, the bytes are first left circularly shifted to scatter the bit positions, and then the high and low nibbles are swapped to achieve diffusion across nibbles; The third layer executes key mixing: the lower 3 bits of the session master key MasterKey dynamically control the number of cyclic shifts, splitting the high and low nibbles to perform modulo addition and XOR differential operations respectively, and finally cross-merging the output; The fourth layer performs byte perturbation: the low-order feature value of the previous ciphertext byte in the business communication frame is superimposed as the dynamic offset. The perturbation factor of the first byte of each frame is fixed at 0, and the dynamic offset is updated bit by bit starting from the second byte.
7. The full-frame dynamic implicit derived streaming encryption method for smart meters as described in claim 1, characterized in that... It also includes the S7 out-of-synchronization resynchronization steps, specifically: If multiple consecutive frames fail to verify, the iteration state mismatches, the module is plugged in or unplugged, or the base table is reset, communication is considered out of sync. When the base table detects a communication loss of synchronization, it disconnects the module power supply and then turns the power supply back on and performs a hardware reset of the module, and then performs a soft clear of the session master key status. When the module detects a communication failure, it automatically resets. Subsequently, the base table detects the module reset and performs a soft reset of the session master key (MasterKey) status. In both cases, the module re-initiates the module-side encryption baud rate adaptive polling process. Both parties regenerate a random seed and complete a new round of negotiation using a public-key cryptography key pair to restore normal communication.
8. The full-frame dynamic implicit derived streaming encryption method for smart meters as described in claim 1, characterized in that... It also includes an adaptive step for S8 module replacement, specifically: If a faulty module is removed and a brand-new, compatible module is powered on and inserted, the module will automatically perform a handshake process to regenerate a random seed and generate a new session master key (MasterKey). A third-party forged module without a matching public and private key cannot pass identity verification after being plugged in or removed, and an encrypted communication link cannot be established.
9. A full-frame dynamic implicit derived streaming encryption system adapted for smart meters, used to implement the method as described in any one of claims 1-8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that... When the program is executed, the method as described in any one of claims 1-8 is implemented.
