Encryption and decryption data processing methods, cryptographic engine units, and microprocessor architecture

By setting up a storage unit in the cryptographic engine unit to cache the stream cipher initialization state data, the problem of excessively long stream cipher initialization operation time is solved, improving the encryption and decryption efficiency of small data packets and the utilization rate of hardware resources.

CN123122802APending Publication Date: 2026-11-17PHYTIUM TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611168723.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In microprocessor architectures, stream cipher initialization operations consume excessive time during small data packet encryption and decryption, resulting in low hardware resource utilization and low encryption and decryption efficiency.

Method used

A storage unit is set up in the cryptographic engine unit to cache the stream cryptographic initialization state data, and the stored initialization state data is queried and loaded by the instruction identifier to skip repeated initialization operations and generate the key stream.

Benefits of technology

It significantly improves the encryption and decryption efficiency and real-time performance of small data packets, increases hardware resource utilization, and reduces unnecessary power consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123122802A_ABST
    Figure CN123122802A_ABST
Patent Text Reader

Abstract

This application provides an encryption / decryption data processing method, a cryptographic engine unit, and a microprocessor architecture. The method is applied to a cryptographic engine unit, which includes a storage unit for storing stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The method includes: receiving a target encryption / decryption request instruction for first data; querying the storage unit to see if stored target stream cipher initialization state data is associated with the target instruction identifier carried in the target encryption / decryption request instruction; if target stream cipher initialization state data is found, reading the first data, directly loading the target stream cipher initialization state data into the cryptographic engine unit, generating a keystream matching the length of the first data, performing stream cipher operations corresponding to the target encryption / decryption request instruction, and outputting the operation result. This method can improve the encryption / decryption efficiency of small data packets.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to an encryption and decryption data processing method, a cryptographic engine unit, and a microprocessor architecture. Background Technology

[0002] Microprocessor architectures typically integrate dedicated cryptographic engine units to handle data security operations, such as implementing stream cipher data encryption and decryption operations.

[0003] In the process of stream cipher data encryption and decryption, the stream cipher initialization operation is a necessary step before data encryption and decryption. That is, before encrypting or decrypting the data, the stream cipher initialization operation is performed to obtain the stream cipher initialization state data, and then the data encryption and decryption operation is performed using the stream cipher initialization state data.

[0004] For encryption and decryption of small data packets, the stream cipher initialization operation accounts for an extremely high proportion of the total encryption and decryption time. For example, in the hardware implementation of the ChaCha20 stream cipher, the initialization process requires approximately 200 clock cycles, while encrypting a 16-byte small data packet only requires 4 clock cycles, with the initialization overhead accounting for over 98%. This excessively high initialization time will cause the computational units in the early initialization stage of the entire encryption and decryption process for small data packets to be fully loaded, while the computational units in the later encryption and decryption stages will be idle for a long time, resulting in low utilization of hardware resources and affecting the encryption and decryption efficiency of small data packets. Summary of the Invention

[0005] Based on the above-mentioned technical problems, this application provides an encryption / decryption data processing method, apparatus, cryptographic engine unit, and microprocessor architecture, which can improve the encryption / decryption efficiency of small data packets.

[0006] The first aspect of this application provides an encryption / decryption data processing method applied to a cryptographic engine unit. The cryptographic engine unit includes a storage unit for storing stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The stream cipher initialization state data includes basic parameters used to initiate keystream generation after the cryptographic engine unit performs stream cipher initialization operations. The method includes: receiving a target encryption / decryption request instruction for first data; querying the storage unit to see if stored target stream cipher initialization state data is associated with a target instruction identifier carried in the target encryption / decryption request instruction; if the target stream cipher initialization state data is found, reading the first data based on the storage address of the first data carried in the target encryption / decryption request instruction, directly loading the target stream cipher initialization state data into the cryptographic engine unit, generating a keystream matching the length of the first data, performing stream cipher operations corresponding to the target encryption / decryption request instruction based on the keystream, and outputting the operation result.

[0007] A second aspect of this application provides a cryptographic engine unit, which includes a storage unit for storing stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The stream cipher initialization state data includes basic parameters used to initiate key stream generation after the cryptographic engine unit performs stream cipher initialization operations. The cryptographic engine unit is configured to execute the above-described encryption and decryption data processing method.

[0008] A third aspect of this application provides a microprocessor architecture including a cryptographic engine unit. The cryptographic engine unit includes a storage unit for storing stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The stream cipher initialization state data includes basic parameters used to initiate key stream generation after the cryptographic engine unit performs stream cipher initialization operations. The cryptographic engine unit is configured to execute the above-described encryption and decryption data processing method.

[0009] The encryption / decryption data processing method provided in this application stores pre-generated stream cipher initialization state data for specific instruction identifiers within a cryptographic engine unit. Upon receiving a target encryption / decryption request instruction, the method queries the storage unit to check for associated stored target stream cipher initialization state data based on the target instruction identifier. If the target stream cipher initialization state data is found, it is directly loaded into the cryptographic engine unit to generate a key stream, thereby skipping repetitive stream cipher initialization operations. This significantly reduces the total time required for encryption and decryption of small data volumes and substantially improves the real-time performance of encryption and decryption processing. Furthermore, the process of pre-generating and caching the stream cipher initialization state data can be performed when the cryptographic engine unit is idle, avoiding frequent start-stop cycles and idle waste of hardware resources, improving the hardware resource utilization of the cryptographic engine unit, and reducing unnecessary power consumption.

[0010] In some implementations, the basic parameters include a complete intermediate state snapshot of the general-purpose registers, linear shift registers, and / or nonlinear shift registers within the cryptographic engine unit, as well as the internal variables of the feedback stream cryptographic algorithm's operational logic. By capturing the complete internal runtime environment rather than just saving the key, it ensures that the cached state data can support the cryptographic engine unit in accurately resuming operations from any specified point in time, enabling functions such as resuming operations from breakpoints, state backtracking, and fault location.

[0011] In some implementations, the method further includes: upon first receiving an encryption / decryption request instruction carrying the target instruction identifier, generating target stream cipher initialization state data based on the encryption / decryption operation parameters carried in the encryption / decryption request instruction; and associating and storing the target instruction identifier and the target stream cipher initialization state data in the storage unit. Although this initial generation process consumes the time overhead of initialization operations, its result will be cached for subsequent reuse, allowing subsequent encryption / decryption requests carrying the same instruction identifier to skip the initialization operation, thus improving the efficiency of subsequent encryption / decryption processing.

[0012] In some implementations, upon first receiving an encryption / decryption request instruction carrying the target instruction identifier, before generating the target stream cipher initialization state data based on the target instruction identifier, the method further includes: determining whether the preprocessing flag in the encryption / decryption request instruction is valid, and determining whether the computing core of the cryptographic engine unit is idle; if it is determined that the preprocessing flag in the encryption / decryption request instruction is valid, and the computing core of the cryptographic engine unit is idle, generating the target stream cipher initialization state data based on the target instruction identifier. This dual-judgment logic ensures that the stream cipher initialization preprocessing process is not triggered at inappropriate times: it is not triggered when the preprocessing flag is invalid, avoiding unnecessary preprocessing operations; it is not triggered when the computing core is busy, avoiding competition for computing resources between preprocessing and ongoing encryption / decryption operations, ensuring the priority and real-time performance of normal encryption / decryption services.

[0013] In some implementations, the method further includes: recording the number of times the target stream cipher initialization state data is used; when the number of times the target stream cipher initialization state data is used reaches a set number, clearing the target stream cipher initialization state data from the storage unit and regenerating the target stream cipher initialization state data for the target instruction identifier; associating the target instruction identifier and the regenerated target stream cipher initialization state data in the storage unit, and resetting the number of times the target stream cipher initialization state data is used to zero. By setting an upper limit on the number of uses and forcibly regenerating the stream cipher initialization state data when the upper limit is reached, the stream cipher initialization state data can be refreshed periodically, reducing security risks caused by excessive reuse and achieving a balance between reuse efficiency and encryption security.

[0014] In some implementations, the storage unit stores multiple sets of stream cipher initialization state data. These multiple sets of stream cipher initialization state data are generated based on different encryption / decryption request instructions, each carrying a different instruction identifier and encryption / decryption operation parameters. Storing multiple different sets of stream cipher initialization state data in the storage unit can satisfy more stream cipher initialization state data queries, thereby further improving data encryption and decryption efficiency.

[0015] In some implementations, the method further includes: if the idle time of any set of stream cipher initialization state data in the storage unit exceeds a set time, then clearing that set of stream cipher initialization state data from the storage unit. By setting an idle time threshold and automatically clearing expired data, storage space occupied by invalid data in the storage unit can be released in a timely manner, freeing up cache resources for new encryption and decryption tasks, preventing the storage unit from exhausting its capacity due to long-term accumulation of expired data, and ensuring the effective utilization rate of the storage unit.

[0016] In some implementations, the method further includes: if the target stream cipher initialization state data is not found, performing a stream cipher initialization operation based on the encryption / decryption operation parameters carried in the target encryption / decryption request instruction to obtain the target stream cipher initialization state data; loading the obtained target stream cipher initialization state data into the cryptographic engine unit to generate a key stream matching the length of the first data, and performing stream cipher operations corresponding to the target encryption / decryption request instruction based on the key stream, and outputting the operation result. When the storage unit does not contain stream cipher initialization state data associated with the target instruction identifier (e.g., the instruction identifier is being used for the first time, or the corresponding cached data has been cleared due to idle timeout or usage limit), the cryptographic engine unit reverts to the standard stream cipher initialization operation process, generating stream cipher initialization state data in real time based on the encryption / decryption operation parameters, ensuring that the encryption / decryption request will not fail due to cache miss, and guaranteeing the robustness of the system. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0018] Figure 1a This is a schematic diagram of a microprocessor architecture provided in an embodiment of this application.

[0019] Figure 1b This is a schematic diagram of the structure of a cryptographic engine unit provided in an embodiment of this application.

[0020] Figure 2 This is a flowchart illustrating an encryption / decryption data processing method provided in an embodiment of this application.

[0021] Figure 3 This is a schematic diagram of another cryptographic engine unit provided in an embodiment of this application. Detailed Implementation

[0022] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0023] In the field of stream cipher data processing hardware implementation, to achieve high-throughput encryption and decryption processing, the commonly adopted technical solution is a stream cipher engine based on a pipelined architecture or a combinational logic architecture. Specifically, this solution uses a hardware description language to solidify the steps of the stream cipher algorithm, such as key loading, initialization vector loading, pseudo-random number generator internal state initialization, and key stream generation, into independent hardware logic modules, namely, the cryptographic engine unit. Its basic working principle is that upon receiving a new encryption / decryption task, the cryptographic engine unit starts from the initial state and sequentially executes all the above processes to generate a key stream of the same length as the data to be processed, and then completes the encryption and decryption operations through XOR logic.

[0024] However, when this solution is applied to encryption and decryption scenarios primarily involving short data packets, such as IoT short messages and network control signaling, its performance is less than ideal. The main reason is that, in pursuit of processing efficiency for large, continuous data blocks, the solution's design mandates that each independent encryption / decryption transaction undergo a complete initialization process with a fixed number of clock cycles. When the data packets to be processed are small, the time cost of this initialization process far exceeds the time cost of the actual data transformation, leading to a sharp drop in the hardware's effective encryption / decryption throughput.

[0025] The root cause of the above problems is that the cryptographic engine unit in the relevant technology treats the initialization operation and the data transformation operation as an inseparable atomic transaction, and does not decouple and reuse the output of the initialization operation.

[0026] To better understand the above issues, let's first explain the differences between stream ciphers and block ciphers in their encryption and decryption processes. Block ciphers divide plaintext into fixed-length blocks and perform encryption operations on each block independently. Stream ciphers, on the other hand, continuously generate a keystream using a pseudo-random number generator (PRNG), and then XOR the keystream with the plaintext bit by bit to complete the encryption. Their internal state dynamically evolves with each bit output. It's also important to distinguish between the concepts of key and keystream: the key is a pre-agreed, fixed-length secret parameter used as input to the stream cipher algorithm; the keystream is a pseudo-random bit sequence dynamically generated by the cryptographic engine unit using the PRNG based on the key, the initialization vector (IV), and the initialized internal state. Its length matches the length of the data to be encrypted or decrypted. In other words, the key is a static input parameter, while the keystream is a dynamically generated output sequence. Because the internal state of a stream cipher is highly coupled with dynamic parameters (such as the initialization vector), the initialization state of a stream cipher depends not only on the key, but also on the initialization vector and all intermediate states generated during the initialization iteration. This means that a stream cipher needs to undergo a complete initialization process before each encryption or decryption operation.

[0027] For example, the stream cipher algorithm can be a mainstream stream cipher algorithm such as the ChaCha20 algorithm or the ZUC-128 algorithm. Taking the ZUC-128 algorithm as an example, its initialization process requires loading the initial key and initial vector into the register cell variable of the Linear Feedback Shift Register (LFSR) as the initial state, and repeatedly executing an iterative process (e.g., 32 iterations) including bit reconstruction, nonlinear function operation, and LFSR initialization mode update to obtain the PRNG state data after initialization. Taking the ZUC-128 algorithm as an example, its initialization process requires about 32 clock cycles, while encrypting a small packet of 16 bytes only requires about 4 clock cycles, and the initialization overhead accounts for more than 89%. In the case of even smaller data packets, this proportion can even exceed 98%.

[0028] In stream cipher algorithms, the internal operating environment of the pseudo-random number generator used to drive key stream generation is established through a series of complex nonlinear iterations using the key and initialization vector. This establishment process is the main time-consuming step. In scenarios involving frequent processing of small packets from the same source, reconstructing the exact same internal operating environment each time results in redundant consumption of computational resources and time. It can be seen that in small data volume encryption and decryption scenarios, the time consumed by stream cipher initialization operations is the core bottleneck restricting the real-time performance of encryption and decryption.

[0029] To address the aforementioned technical problems, this application proposes a novel cryptographic engine unit and a data processing method for encryption and decryption based on this cryptographic engine unit. The core inventive concept of this application lies in: by adding a storage unit to the cryptographic engine unit and employing a mechanism for caching and reusing stream cipher initialization state data, the initialization bottleneck in the encryption and decryption process is improved. This effectively avoids the time overhead caused by repeatedly performing initialization operations when processing short packets from the same source, without modifying the core algorithm logic of the stream cipher or sacrificing encryption security. This solves the problem of poor real-time performance caused by the high proportion of initialization time in stream cipher hardware when processing small data packets, achieving the technical effect of improving the encryption and decryption performance of short packets while ensuring security.

[0030] Figure 1a This is a schematic diagram of a microprocessor architecture provided in an embodiment of this application. The microprocessor architecture includes a processor core, a system bus, a cryptographic engine unit, and external memory. The processor core is connected to the cryptographic engine unit and external memory via the system bus, and is responsible for issuing encryption / decryption request instructions to the cryptographic engine unit and receiving processing results. The external memory stores the data packets to be encrypted / decrypted, as well as the ciphertext or plaintext data output after the computation is completed.

[0031] A cryptographic engine unit is a hardware acceleration unit used to execute stream cipher algorithms, such as... Figure 1b As shown, it integrates a computing core, storage unit, instruction parser, and data interface. The instruction parser decodes encryption / decryption requests from the processor core, extracting the instruction identifier, data storage address, and computation parameters. The data interface reads the data to be processed via the system bus and writes the computation results back to the specified location.

[0032] The computational core is the main component of the cryptographic engine unit responsible for stream cipher operations. Internally, it includes a pseudo-random number generator, a shift register set, feedback logic, and a keystream generation circuit. During stream cipher encryption and decryption, the computational core generates a keystream of equal length to the data to be processed according to a specific algorithm and performs data transformation through XOR logic.

[0033] The storage unit is located within the cryptographic engine unit and can be implemented using a high-speed register set or on-chip random access memory (RAM). Its storage capacity is adapted to the maximum initialization state data volume of the stream cipher algorithms supported by the cryptographic engine unit, and it possesses fast query and read / write capabilities. This storage unit stores internal state parameters generated or needing to be restored during the computational core's operation. These parameters relate to the values ​​of various registers and internal variables after the cryptographic engine completes the initialization phase but before the actual key stream generation, reflecting the complete operational state of the computational core at that time. The storage unit has independent read / write paths with the computational core, supporting fast access during instruction execution.

[0034] In this implementation environment, after the processor core generates an encryption / decryption request instruction, it is sent to the cryptographic engine unit via the system bus. The instruction parser in the cryptographic engine unit parses the instruction, determines the target address, and then initiates a read from external memory via the data interface to retrieve the first data to be encrypted / decrypted. Simultaneously, the computing core accesses internal memory based on the identification information carried in the instruction, determining whether a status parameter associated with that identifier exists. If it exists, the computing core loads these parameters, skips some computational steps, directly generates the required keystream based on these parameters, completes the encryption / decryption operation, and writes the result back to external memory. If it does not exist, the computing core executes the complete initialization and keystream generation process before outputting the result. Data transfer between external memory and the cryptographic engine unit can be coordinated with a direct memory access controller to reduce processor core involvement and improve system throughput.

[0035] Figure 2 The diagram shown is a schematic flowchart of an encryption / decryption data processing method provided in an embodiment of this application. This method is executed by a cryptographic engine unit. (Combined with...) Figure 1a and Figure 1b In the implementation environment shown, the cryptographic engine unit can be connected to the processor core, system bus, and external memory.

[0036] In this embodiment of the application, the storage unit inside the cryptographic engine unit is used to store the stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The stream cipher initialization state data includes the basic parameters used to start key stream generation after the cryptographic engine unit performs the stream cipher initialization operation.

[0037] The aforementioned specific instruction identifier is used to uniquely identify a combination of encryption and decryption operation parameters. For example, encryption and decryption operation parameters may include parameters such as a key and an initialization vector, and a corresponding association is established between the specific instruction identifier and the key and initialization vector. Through the association between the instruction identifier and the encryption and decryption operation parameters, the cryptographic engine unit can quickly index the corresponding stream cipher initialization state data based on the instruction identifier, without having to compare the complete encryption and decryption operation parameters one by one, thus improving query efficiency.

[0038] Stream cipher initialization state data is the result data obtained by the cryptographic engine unit after performing stream cipher initialization operations according to the initialization process specified by the stream cipher algorithm. This initialization process may include steps such as key loading, initialization vector loading, PRNG internal state initialization, and initial keystream generation. The stream cipher initialization state data completely records the internal state of the cryptographic engine unit after performing the stream cipher initialization operation, allowing subsequent encryption / decryption requests to directly recover from this state and start keystream generation without re-executing all the above initialization steps. This transforms the one-time overhead of the initialization operation into a reusable cache resource. It should be noted that the logic of the stream cipher initialization operation is completely consistent with the initialization logic of the core stream cipher algorithm, without modifying the core encryption logic. Thus, the initialization operation in the preprocessing stage is consistent with the initialization process of the standard stream cipher algorithm, ensuring that the pre-generated stream cipher initialization state data is cryptographically equivalent to the result of real-time initialization, without introducing additional security risks and guaranteeing encryption security.

[0039] See Figure 2 The encryption / decryption data processing method provided in this application embodiment may include: S101, Receive the target encryption / decryption request instruction for the first data.

[0040] The target encryption / decryption request instruction can be issued by the processor core and input to the cryptographic engine unit via the system bus. The target encryption / decryption request instruction may carry a target instruction identifier, the storage address of the first data, and encryption / decryption operation parameters. These encryption / decryption operation parameters may include at least one of the following: key, initialization vector, data length, algorithm type, operation direction, and preprocessing control information. By simultaneously carrying identification information and operation information in a single request instruction, it is possible to determine whether a corresponding cache state exists and, in the event of a cache miss, to fall back to the normal initialization path, ensuring the continuity of the operation process.

[0041] The aforementioned first data can be, for example, small packet data with a short data length, including but not limited to IoT short messages, network packets, etc. Specifically, it can be plaintext data to be encrypted or ciphertext data to be decrypted. The length of the first data is less than a set number of bytes, thus reflecting its "small packet data" characteristic. For example, the data length of the first data can be less than 128 bytes; in some embodiments, it can also be adjusted to 64 bytes, 256 bytes, or other adaptable ranges according to bus width, cache capacity, or business model. The small data volume of the small packet data results in the stream cipher initialization operation accounting for a relatively high proportion of the total encryption and decryption time, which is the core scenario addressed by the embodiments of this application.

[0042] In this embodiment, the term "target instruction identifier" refers to identifier information that can characterize a set of target encryption / decryption semantics or state index relationships. Specifically, it can be a command number pre-assigned by the software, an index value encoded from information such as the key, initialization vector, algorithm type, session identifier, and context number, or a combined identifier formed by the above information.

[0043] S102. Based on the target instruction identifier carried in the target encryption / decryption request instruction, query the storage unit to see if there is any stored target stream cipher initialization status data associated with it.

[0044] As a specific implementation, after obtaining the target instruction identifier, the computational core in the cryptographic engine unit can send an index query request to the storage unit. The storage unit then returns the existence of an available entry and the corresponding state data address. More generally, the query can be implemented in various ways. For example, the target instruction identifier can be used directly as the address index; a table lookup can be performed by comparing the target instruction identifier with a tag bit; or matching can be done using hash mapping, content addressing, or a multi-level directory table. All of these methods can achieve the function of locating the target stream cryptographic initialization state data based on the target instruction identifier.

[0045] In some embodiments, the storage unit can be implemented using on-chip random access memory, or using a high-speed register set, dual-port RAM, or a cache structure composed of a hybrid of registers and RAM. To support fast lookup and read / write operations, an independent read / write path can be established between the storage unit and the computing core. In addition to storing the state data itself, each cache entry can also store management information such as the valid bit, hit count, last access time, state length, and algorithm identifier. Through this structural design, the computing core can prioritize state retrieval upon receiving a request, thereby determining whether the initialization process can be skipped.

[0046] In this application, the stream cipher initialization state data refers to a set of basic parameters that can be used to initiate key stream generation after the cryptographic engine unit performs stream cipher initialization operations. These basic parameters do not refer solely to the key itself, nor solely to the initialization vector, but rather to the set of internal states that enable the computational core to continue operating from a previously initialized running node. Specifically, this set can originate from key loading, initialization vector loading, pseudo-random number generator internal state initialization, and the values ​​of registers, shift registers, and internal variables after the initial key stream generation. This definition extends the cached object from static input parameters to a dynamic internal running environment, which is beneficial for accurately restoring the computational core's state upon initialization completion.

[0047] As an explanation, when using public stream cipher algorithms, the initialization process itself can have a defined internal state evolution. For example, for a ZUC-type implementation, the initialization phase may include loading the initial key and initial vector into a linear feedback shift register group, setting the memory unit variables to zero, and performing multiple rounds of iterative updates before entering the working state; for a ChaCha20-type implementation, the internal state can also be established first using the key, counter, and nonce, and then the key stream is output after block function evolution. Thus, stream cipher initialization is not simply loading the key, but rather forming an internal state context that can continue to drive key stream generation. Step S102 establishes conditions for subsequent direct loading and key stream generation by querying whether this context has been pre-stored.

[0048] S103. If the target stream cipher initialization status data is found, the first data is read based on the storage address of the first data carried in the target encryption / decryption request instruction. The target stream cipher initialization status data is directly loaded into the cryptographic engine unit to generate a key stream that matches the length of the first data. The stream cipher operation corresponding to the target encryption / decryption request instruction is performed based on the key stream, and the operation result is output.

[0049] As a specific implementation, the computing core can read the first data from the external memory according to the storage address and send the first data into the XOR operation path. At the same time, the computing core obtains the target stream cryptographic initialization state data from the storage unit and loads it into the internal register group, shift register group, and feedback operation logic. After loading, the computing core does not need to go through the complete initialization stage again, but directly generates a key stream with the same length as the first data from the restored state. Then, the XOR operation path performs encryption or decryption processing on the first data based on the key stream, and finally writes the operation result back to the external memory.

[0050] In some embodiments, the reading of the first data and the loading of the target stream cipher initialization state data can be performed serially or at least partially in parallel. For example, in some embodiments, the computing core can prefetch the first data while initiating a state query; in other embodiments, the state loading can be completed first, and then data can be read on demand to adapt to different bus timings. The generation of a keystream matching the length of the first data can refer to generation byte-by-byte, word-by-word, step-by-step, or block-by-block concatenation, as long as the final output length covers the effective length of the first data. For tail data that is less than one word or one block width, truncation or masking can be used for processing.

[0051] In this application, the terms "key" and "keystream" are clearly distinguished. The key is typically an externally input confidential parameter used in initialization operations; the keystream, on the other hand, is a pseudo-random sequence generated in real-time by the computational core based on the key, initialization vector, and internal state, used to perform an XOR operation with the first data. In other words, the key is one of the input conditions, and the keystream is one of the outputs; they differ in origin, purpose, and timing. The target stream cryptographic initialization state data stores the set of internal conditions required to initiate keystream generation, not just the original key itself. Therefore, when the target stream cryptographic initialization state data is directly loaded into the cryptographic engine unit in step S103, what is actually restored is the runtime environment that allows the computational core to continue generating the keystream, rather than re-importing the static key and recalculating from scratch.

[0052] As described above, the encryption / decryption data processing method provided in this application provides a storage unit within the cryptographic engine unit to store pre-generated stream cipher initialization state data for a specific instruction identifier. Upon receiving a target encryption / decryption request instruction, the method queries the storage unit to determine if stored target stream cipher initialization state data is associated with the target instruction identifier. If target stream cipher initialization state data is found, it is directly loaded into the computational core of the cryptographic engine unit to generate a key stream, thereby skipping repetitive stream cipher initialization operations, significantly reducing the total time consumption for encryption and decryption of small data volumes, and significantly improving the real-time performance of encryption and decryption processing. Furthermore, the process of pre-generating and caching stream cipher initialization state data can be executed when the cryptographic engine unit is idle, avoiding frequent start-stop and idle waste of hardware resources, improving the hardware resource utilization of the cryptographic engine unit, and reducing ineffective power consumption.

[0053] In some embodiments, the basic parameters for initiating key stream generation stored in the storage unit may include a complete intermediate state snapshot of general-purpose registers, linear shift registers, and / or nonlinear shift registers within the cryptographic engine unit, as well as internal variables of the feedback stream cryptographic algorithm operation logic.

[0054] It is important to emphasize that the aforementioned complete intermediate state snapshot is not a simple saving of a single input parameter, nor is it just saving the key itself. Rather, it is formed by completely capturing the state of the internal core storage and computing components at a specified time point during the operation of the cryptographic engine unit. It completely replicates the internal operating environment of the cryptographic engine unit at that time point, including the states of all registers, the bit states of shift registers, and all temporary variables in the computing logic.

[0055] Specifically, the snapshot can include the current stored values ​​of general-purpose registers, the real-time bit state data of linear and non-linear shift registers, and the values ​​of temporary variables formed during the execution of the feedback stream cryptographic algorithm's internal operational logic. By saving the combination of the above, the operating environment of the cryptographic engine unit at the moment of capture can be completely replicated during subsequent loading.

[0056] The above process can be understood as follows: Unlike block cipher algorithms, stream cipher algorithms rely solely on the key itself for key expansion, so preprocessing only requires saving the key or its expansion result. However, the internal state of a stream cipher is highly coupled with dynamic parameters (such as the initialization vector), and simply saving the key cannot restore the complete internal state after initialization. By capturing the complete internal runtime environment instead of just saving the key, the cached state data ensures that the cryptographic engine unit can accurately recover the operation from any specified point in time, enabling functions such as resuming interrupted operations, state backtracking, and fault location. This is the key difference between stream cipher initialization preprocessing and block cipher key expansion preprocessing.

[0057] In other embodiments, a general-purpose register is disclosed to store intermediate data and control information during the operation of the cryptographic engine unit. Its current stored value is included in a snapshot to ensure that the intermediate operation data in the general-purpose register is not lost when the cryptographic engine unit recovers from the cache state, thereby avoiding errors in the subsequent key stream generation results due to the lack of register state.

[0058] Linear shift registers can correspond to LFSR structures, while nonlinear shift registers can correspond to state-keeping units in nonlinear update links. The internal variables of the feedback stream cryptographic algorithm's operational logic can include addition, XOR, substitution, bit reconstruction, and intermediate results temporarily stored during the feedback calculation process.

[0059] In some embodiments, if the computational core adopts a ZUC-type structure, the complete intermediate state snapshot may include multiple LFSR register states and memory cell states; if a ChaCha20-type structure is adopted, the complete intermediate state snapshot may include several working words, counter words, and nonce-related words in the state matrix. The state layout corresponding to different algorithms may be different, but as long as it can represent the internal state that can continue to generate the key stream after initialization, it can be included in the above-mentioned basic parameter range.

[0060] By employing complete intermediate state snapshots, subsequent recovery not only supports direct keystream generation but also allows for continuation of interrupted operations, state backtracking, and debugging. For example, if an abnormal interruption occurs during encryption / decryption, a complete intermediate state snapshot at the current moment can be preserved, and the remaining operations can continue after recovery. Similarly, when verifying the cause of an abnormal keystream output, the internal state at the corresponding time point can be traced back to analyze whether there are deviations in registers and feedback variables. This capability stems from the snapshot's overall preservation of the internal operational context, rather than from the separate recording of static keys. Therefore, this preferred approach helps avoid recovery deviations caused by incomplete state preservation, thereby improving the reliability of cached state reuse.

[0061] In other embodiments, it is also disclosed that, upon first receiving an encryption / decryption request instruction carrying the aforementioned target instruction identifier, target stream cipher initialization state data is generated based on the encryption / decryption operation parameters carried in the encryption / decryption request instruction. Then, the target instruction identifier and the target stream cipher initialization state data are associated and stored in a storage unit.

[0062] Specifically, when the computing core determines that there is no corresponding cached entry for a certain target instruction identifier in the storage unit, it can perform a complete stream cipher initialization operation. This stream cipher initialization operation can include key loading, initialization vector loading, pseudo-random number generator internal state initialization, and state evolution before and after initial key stream generation. Upon reaching a predetermined capture node, it outputs the target stream cipher initialization state data. Subsequently, the computing core can use the target instruction identifier as an index key, writing it along with the obtained stream cipher initialization state data into a new entry in the storage unit, and marking this entry as available. This on-demand generation method allows the system to complete cache table creation upon the first request, thus facilitating direct matching for subsequent requests with the same target instruction identifier.

[0063] In other embodiments, the first receipt of an encryption / decryption request instruction carrying the target instruction identifier can refer to the first reception after the system powers on, or it can refer to the second reception of the encryption / decryption request instruction carrying the target instruction identifier after the cache has been cleared, or it can refer to the first reception of the encryption / decryption request instruction carrying the target instruction identifier within a certain session period. The encryption / decryption operation parameters can come directly from the request instruction, or they can come from the configuration table, context table, or session descriptor pointed to by the request instruction.

[0064] The associated storage can be implemented through a one-to-one mapping method (for example, establishing a corresponding mapping relationship between the target instruction identifier and the target stream cipher initialization state data after storing the target instruction identifier and the target stream cipher initialization state data in the storage unit), or it can be implemented by having one target instruction identifier correspond to multiple state versions, such as corresponding to different algorithm modes, different length ranges, or different priority queues. All of the above alternative forms can achieve the purpose of establishing state cache entries based on identifiers.

[0065] It should be noted that the method of creating cache entries on demand described above works in conjunction with the aforementioned method of querying the cache based on target instruction identifiers. On the one hand, if an entry already exists, the state can be reused directly; on the other hand, if no entry exists yet, it can be generated and written promptly driven by the first request. This avoids exhaustively generating all potential parameter combinations in advance and improves the targeting of cache space allocation. When a series of small packet requests with the same parameter combinations arrive consecutively, subsequent requests can continuously reuse the initially created state entries, thereby shortening the average response time and improving throughput.

[0066] In other embodiments, upon first receiving an encryption / decryption request instruction carrying a target instruction identifier, before generating target stream cipher initialization state data based on the target instruction identifier, the method first determines whether the preprocessing flag in the encryption / decryption request instruction is valid and whether the computational core of the cryptographic engine unit is in an idle state. If it is determined that the preprocessing flag is valid and the computational core is in an idle state, target stream cipher initialization state data is generated based on the target instruction identifier.

[0067] In this embodiment, the preprocessing flag can be set in the control field of the target encryption / decryption request instruction to indicate whether the request allows or is expected to trigger state pre-generation. "Valid" can mean the flag is set, the flag matches a predefined control code, or the triggering condition is met after combining permission configuration, session type, or service level judgment. Whether the computing core is idle can be detected by the state management module within the cryptographic engine unit. The state management module can monitor whether the computing core is executing encryption / decryption tasks, whether there are queued tasks, whether bus access is busy, and whether the cache read / write port is available, and output an idle judgment result accordingly.

[0068] As a specific implementation, the state management module can be connected to both the computing core and the storage unit to arbitrate the preprocessing and normal computation processes. When the preprocessing flag is valid and the computing core is idle, the computing core's resources can be called to generate the target stream password initialization state data. If either condition is not met, the generation process is postponed, or the current request is processed directly according to the real-time initialization path. By introducing the preprocessing flag and idle judgment, preprocessing can be performed at a clearly permitted and resource-schedulable time, reducing the possibility of competing for computing resources with real-time services.

[0069] In some embodiments, the preprocessing flag is not limited to a single bit representation; it can be a multi-bit field used to distinguish different strategies such as immediate preprocessing, background preprocessing, table creation without immediate use, and prohibition of table creation. The idle state is not limited to a state with no tasks running at all; it can also be a state where low-priority tasks are preemptible, a partially pipelined idle state, or a time slot idle state. Any initialization operation that can be scheduled without significantly affecting the timing of existing encryption / decryption services can be included within the scope of this embodiment. Those skilled in the art can also combine this scheme with the aforementioned on-demand table creation scheme to make state generation more adaptable to different service loads.

[0070] By adopting the above control method, preprocessing is no longer unconditionally triggered, but a controlled operation based on two conditions: flag permission and resource idleness. This allows for the preparation of stream cipher initialization state data in advance while avoiding additional delays caused by resource contention in the foreground encryption and decryption tasks. For systems with alternating periods of high-concurrency small packet requests and intermittent idle periods, this scheme can make fuller use of idle time to complete state preparation and maintain stable overall throughput.

[0071] To further optimize security and state freshness in long-term reuse scenarios, some embodiments also disclose recording the number of times the target stream cipher initialization state data is used. When the number of times the target stream cipher initialization state data is used reaches a set number, the target stream cipher initialization state data is cleared from the storage unit, and new target stream cipher initialization state data is generated for the target instruction identifier. Then, the target instruction identifier and the regenerated target stream cipher initialization state data are associated and stored in the storage unit, and the number of times the target stream cipher initialization state data is used is reset to zero.

[0072] In this embodiment, an independent usage counter can be set for each cached entry in the storage unit. Whenever a state entry corresponding to a target instruction identifier is successfully hit and participates in an encryption / decryption process, the state management module increments the usage counter. The number of times can be a fixed threshold, such as 16, 32, 64, or 256 times, or a dynamic threshold associated with the algorithm type, business level, or data sensitivity level. When the usage count reaches the threshold, the state management module can mark the corresponding entry as invalid, triggering the computing core to reinitialize and generate new state data, which is then rewritten back to the storage unit with the same target instruction identifier.

[0073] In some embodiments, the regeneration can be completed synchronously when the next request arrives, or it can be completed in advance during background idle periods. The zeroing can be performed after a new entry is successfully written back, or it can be performed after an old entry becomes invalid, followed by waiting for a new entry to be loaded. In addition to the number of uses, the system can also record the most recent generation time, the most recent usage time, and the number of consecutive hits to support a more granular update strategy. All of the above designs help avoid the risks that may arise from the long-term, unlimited reuse of single-state data and maintain the cached content in a controlled update state.

[0074] It's important to note that the usage count recording and state clearing / reconstruction mechanism does not alter the encryption / decryption logic of the stream cipher algorithm itself; rather, it operates on the management layer of the state cache. By introducing a usage cap in the management layer, the performance advantages of state reuse can be maintained while constraining the potential problems caused by long-term state persistence. When combined with the aforementioned complete intermediate state snapshot scheme, this approach ensures that a new, accurately reconstructable state is obtained after each refresh, thus balancing recovery accuracy and long-term operational security.

[0075] In some embodiments, the storage unit can store multiple sets of stream cipher initialization state data. These multiple sets of initialization state data are generated based on different encryption / decryption request instructions, each carrying a different instruction identifier and encryption / decryption operation parameters. Parallel caching of multiple sets of stream cipher initialization state data is supported, enabling the cryptographic engine unit to simultaneously serve multiple encryption / decryption tasks with different key and initialization vector combinations. Each task can independently hit its own cached data and skip the initialization operation. In high-concurrency small packet encryption / decryption scenarios (such as 5G base stations, routers, and other network encryption scenarios), multiple caches can be reused by multiple concurrent small packet encryption / decryption requests. The hardware throughput increases linearly with the concurrency, solving the throughput saturation problem in related technologies when adapting large packet architectures to high-concurrency small packets.

[0076] In scenarios that support parallel caching of multiple sets of different target instruction identifiers and different parameter combinations, in order to avoid idle entries continuously occupying storage resources, some embodiments also disclose that if the idle time of any set of stream cipher initialization state data in the storage unit exceeds a set time, the set of stream cipher initialization state data is cleared from the storage unit.

[0077] As a specific implementation, each cached entry in the storage unit can correspond to a timestamp field to record the time of its most recent access, loading, or update. The state management module can periodically scan each entry, or trigger a partial scan before inserting a new entry, to determine the idle time of each entry. The idle time can refer to the time interval since the most recent successful hit, or the time interval since the most recent write without further access. The set duration can be set to milliseconds, seconds, or longer time scales based on storage capacity, concurrency scale, algorithm state length, and business cycle. If an entry exceeds the threshold, it is cleared to free up storage space for subsequent new state writes.

[0078] In this embodiment, the clearing mechanism can be simple deletion, or it can take the form of clearing the valid bits to zero, overwriting the data area with a zero value, or marking the data area as awaiting reclamation. As long as the group of states no longer participates in subsequent hits and releases manageable resources, it can be considered as clearing.

[0079] By employing idle time monitoring and automatic cleanup, unused state entries can be promptly reclaimed, reducing the occupation of storage unit capacity by invalid data and improving storage utilization. This embodiment, in conjunction with the aforementioned initial table creation and usage count refresh mechanism, forms a complete state lifecycle management chain for multi-session environments. From initial generation, hit reuse, count refresh to idle eviction, all are completed internally by the cryptographic engine unit, reducing the management burden on external processors.

[0080] To ensure that encryption and decryption can still be completed even when the required stream cipher initialization state data for encryption and decryption is not found in the storage unit, another embodiment discloses that, in the case where the target stream cipher initialization state data is not found in the storage unit, a stream cipher initialization operation is performed based on the encryption and decryption operation parameters carried in the target encryption / decryption request instruction to obtain the target stream cipher initialization state data. Then, the obtained target stream cipher initialization state data is loaded into the computation core of the cryptographic engine unit to generate a keystream matching the first data length. The stream cipher operation corresponding to the target encryption / decryption request instruction is then performed based on this keystream, and the operation result is output.

[0081] Specifically, when the storage unit does not contain target stream cipher initialization state data matching the target instruction identifier, the computation core enters the real-time initialization path. At this time, the computation core performs operations based on the key, initialization vector, and other parameters carried in the target encryption / decryption request instruction, following the initialization process specified by the corresponding stream cipher algorithm. For example, it can complete operations such as key loading, initialization vector loading, clearing internal registers, initializing shift registers, multi-round feedback updates, and preparation for initial keystream generation to obtain the target stream cipher initialization state data. Subsequently, the state loading path can directly use this state for the current request's keystream generation without waiting for the next request.

[0082] In some embodiments, the target stream cipher initialization state data obtained by performing stream cipher initialization operations based on the encryption / decryption parameters carried in the target encryption / decryption request instruction can be used only for the current request, or it can be further written to the storage unit after the current request is completed, as a reusable entry for subsequent requests. Whether to write the generated target stream cipher initialization state data back to the storage unit can be determined by the preprocessing flag, system load, state length, or cache space. If the system is in large packet processing mode or the cache space is tight, only the real-time initialization required for the current request can be performed without writing it to the database. In this way, the system can continuously provide encryption and decryption services in different states.

[0083] It should be noted that the real-time initialization path when the required stream cipher initialization state data for encryption / decryption is not found in the storage unit, and the direct loading path when the required stream cipher initialization state data is found in the storage unit, together constitute a complete data encryption / decryption processing loop. The former ensures functional integrity, ensuring that any request can still be processed even when there is no readily available stream cipher initialization state data; the latter ensures performance optimization, reducing initialization wait when reusable stream cipher initialization state data exists. The parallel existence of these two ensures that the cryptographic engine unit is backward compatible with conventional stream cipher processing flows, while also achieving shorter processing latency in small-packet, high-frequency scenarios.

[0084] Another embodiment of this application also provides a cryptographic engine unit, in Figure 1b Based on the cryptographic engine unit shown, this application proposes a simplified cryptographic engine unit, see [link to relevant documentation]. Figure 3 As shown, the cryptographic engine unit includes a communication interface, a computing core, and a storage unit. For example, the communication interface can be a system bus as described in the above embodiments. Generally, the communication interface enables communication between the cryptographic engine unit and other microprocessor architecture components; for example, the communication interface can be connected to the processor core, allowing the cryptographic engine unit to receive instructions from the processor core through the communication interface.

[0085] The storage unit is used to store the stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The stream cipher initialization state data includes the basic parameters used to start key stream generation after the cryptographic engine unit performs the stream cipher initialization operation. In this embodiment: The communication interface is used to receive a target encryption / decryption request instruction for the first data; The computing core is used to query the storage unit to see if there is any associated stored target stream cipher initialization state data based on the target instruction identifier carried in the target encryption / decryption request instruction; if the target stream cipher initialization state data is found, the first data is read based on the storage address of the first data carried in the target encryption / decryption request instruction, and the target stream cipher initialization state data is directly loaded into the cryptographic engine unit to generate a key stream with a length matching the first data, so as to perform stream cipher operations corresponding to the target encryption / decryption request instruction based on the key stream and output the operation result.

[0086] In some embodiments, the basic parameters include a complete intermediate state snapshot of the general-purpose registers, linear shift registers, and / or nonlinear shift registers within the cryptographic engine unit, as well as the internal variables of the feedback stream cryptographic algorithm operation logic.

[0087] In some embodiments, the computing core is further configured to: Upon first receiving an encryption / decryption request instruction carrying the target instruction identifier, the target stream cipher initialization state data is generated based on the encryption / decryption operation parameters carried in the encryption / decryption request instruction; The target instruction identifier and the target stream cipher initialization status data are associated and stored in the storage unit.

[0088] In some embodiments, upon first receiving an encryption / decryption request instruction carrying the target instruction identifier, before generating the target stream cipher initialization state data based on the target instruction identifier, the computing core is further configured to: Determine whether the preprocessing flag in the encryption / decryption request instruction is valid, and determine whether the computing core of the cryptographic engine unit is in an idle state; If the preprocessing flag in the encryption / decryption request instruction is found to be valid and the computational core of the cryptographic engine unit is in an idle state, the target stream cipher initialization state data is generated based on the target instruction identifier.

[0089] In some embodiments, the computing core is further configured to: The number of times the target stream cipher initialization state data is used is recorded; If the target stream cipher initialization state data is used a set number of times, the target stream cipher initialization state data is cleared from the storage unit, and the target stream cipher initialization state data is regenerated for the target instruction identifier. The target instruction identifier and the regenerated target stream cipher initialization state data are associated and stored in the storage unit, and the usage count of the target stream cipher initialization state data is cleared to zero.

[0090] In some embodiments, the storage unit stores multiple sets of stream cipher initialization state data, which are generated based on different encryption / decryption request instructions, each carrying a different instruction identifier and encryption / decryption operation parameters. In some embodiments, if the idle time of any set of stream cipher initialization state data in the storage unit exceeds a set time, the computing core will clear the set of stream cipher initialization state data from the storage unit.

[0091] In some embodiments, the computing core is further configured to: If the target stream cipher initialization status data is not found, a stream cipher initialization operation is performed based on the encryption and decryption operation parameters carried in the target encryption and decryption request instruction to obtain the target stream cipher initialization status data; The obtained target stream cipher initialization state data is loaded into the cryptographic engine unit to generate a key stream that matches the length of the first data. The stream cipher operation corresponding to the target encryption / decryption request instruction is then performed based on the key stream, and the operation result is output.

[0092] The cryptographic engine unit provided in this embodiment belongs to the same concept as the encryption / decryption data processing method provided in the above embodiments of this application. It can execute the encryption / decryption data processing method provided in any of the above embodiments of this application and has the corresponding functional modules and beneficial effects of the execution method. Technical details not described in detail in this embodiment can be found in the specific processing content of the encryption / decryption data processing method provided in the above embodiments of this application, and will not be repeated here.

[0093] In some embodiments, the cryptographic engine unit can be housed within the chip as an independent cryptographic coprocessor, or as a security acceleration module within a system-on-a-chip, or as a peripheral connected to the processor core. Its computational core is compatible with ZUC-128, ChaCha20, or other stream cipher algorithms. Adaptation does not require changing the algorithm definition itself; instead, state reuse is achieved by adjusting the initialization execution timing, state capture timing, and state loading method. Therefore, this structure is compatible with the standard execution chain of existing publicly available stream cipher algorithms.

[0094] Another embodiment of this application provides a microprocessor architecture, the structure of which is shown in Figure 1. This microprocessor architecture may include a processor core, a system interconnect bus, an external memory controller, and a cryptographic engine unit. The cryptographic engine unit includes a storage unit for storing pre-generated stream cipher initialization state data for a specific instruction identifier. This stream cipher initialization state data includes basic parameters used to initiate keystream generation after the cryptographic engine unit performs stream cipher initialization operations. The cryptographic engine unit is configured to execute the encryption / decryption data processing method described in any of the foregoing embodiments.

[0095] In this microprocessor architecture, the processor core is responsible for generating target encryption / decryption request instructions, the cryptographic engine unit is responsible for performing state queries, loading, and encryption / decryption calculations, and the external memory controller is responsible for coordinating data reads and writes with external memory. By integrating the aforementioned cryptographic engine unit at the microprocessor architecture level, low-latency optimizations for small packet stream cryptography can be achieved at the system level.

[0096] In addition to the methods and devices described above, embodiments of this application may also be computer program products, which include computer program instructions that, when executed by a processor, cause the processor to perform the steps of the encryption / decryption data processing methods described in any of the above embodiments of this specification.

[0097] The computer program product can be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of this application. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0098] Furthermore, embodiments of this application may also be storage media storing a computer program, which is executed by a processor using the steps of the encryption / decryption data processing method described in any of the above embodiments of this specification.

[0099] For the foregoing method embodiments, in order to simplify the description, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0100] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0101] The steps in the methods of the various embodiments of this application can be adjusted, merged, or deleted in order according to actual needs, and the technical features described in each embodiment can be replaced or combined.

[0102] The modules and sub-modules in the various embodiments of the present application's devices and terminals can be merged, divided, and deleted according to actual needs.

[0103] It should be understood that the disclosed terminals, devices, and methods can be implemented in other ways, given the several embodiments provided in this application. For example, the terminal embodiments described above are merely illustrative. For instance, the division of modules or sub-modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple sub-modules or modules may be combined or integrated into another module, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms.

[0104] The modules or submodules described as separate components may or may not be physically separate. The components that constitute a module or submodule may or may not be physical modules or submodules; that is, they may be located in one place or distributed across multiple network modules or submodules. Some or all of the modules or submodules can be selected to achieve the purpose of this embodiment's solution, depending on actual needs.

[0105] Furthermore, the functional modules or sub-modules in the various embodiments of this application can be integrated into one processing module, or each module or sub-module can exist physically separately, or two or more modules or sub-modules can be integrated into one module. The integrated modules or sub-modules described above can be implemented in hardware or in the form of software functional modules or sub-modules.

[0106] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0107] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software unit executed by a processor, or a combination of both. The software unit can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0108] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0109] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for encrypting and decrypting data, characterized in that, Applied to a cryptographic engine unit, the cryptographic engine unit is provided with a storage unit, the storage unit is used to store the stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier, the stream cipher initialization state data includes the basic parameters used to start key stream generation after the cryptographic engine unit performs the stream cipher initialization operation; The method includes: Receive a target encryption / decryption request instruction for the first data; Based on the target instruction identifier carried in the target encryption / decryption request instruction, query the storage unit to see if there is any stored target stream cipher initialization status data associated with it; If the target stream cipher initialization status data is found, the first data is read based on the storage address of the first data carried in the target encryption / decryption request instruction. The target stream cipher initialization status data is directly loaded into the cryptographic engine unit to generate a key stream that matches the length of the first data. The stream cipher operation corresponding to the target encryption / decryption request instruction is then performed based on the key stream, and the operation result is output.

2. The method according to claim 1, characterized in that, The basic parameters include a complete snapshot of the intermediate states of the general-purpose registers, linear shift registers, and / or nonlinear shift registers within the cryptographic engine unit, as well as the variables within the feedback stream cryptographic algorithm's operational logic.

3. The method according to claim 1, characterized in that, The method further includes: Upon first receiving an encryption / decryption request instruction carrying the target instruction identifier, the target stream cipher initialization state data is generated based on the encryption / decryption operation parameters carried in the encryption / decryption request instruction; The target instruction identifier and the target stream cipher initialization status data are associated and stored in the storage unit.

4. The method according to claim 3, characterized in that, Upon first receiving an encryption / decryption request instruction carrying the target instruction identifier, before generating the target stream cipher initialization state data based on the target instruction identifier, the method further includes: Determine whether the preprocessing flag in the encryption / decryption request instruction is valid, and determine whether the computing core of the cryptographic engine unit is in an idle state; If the preprocessing flag in the encryption / decryption request instruction is found to be valid and the computational core of the cryptographic engine unit is in an idle state, the target stream cipher initialization state data is generated based on the target instruction identifier.

5. The method according to claim 1, characterized in that, The method further includes: The number of times the target stream cipher initialization state data is used is recorded; If the target stream cipher initialization state data is used a set number of times, the target stream cipher initialization state data is cleared from the storage unit, and the target stream cipher initialization state data is regenerated for the target instruction identifier. The target instruction identifier and the regenerated target stream cipher initialization state data are associated and stored in the storage unit, and the usage count of the target stream cipher initialization state data is cleared to zero.

6. The method according to any one of claims 1 to 5, characterized in that, The storage unit stores multiple sets of stream cipher initialization state data, which are generated based on different encryption / decryption request instructions. Each encryption / decryption request instruction carries a different instruction identifier and encryption / decryption operation parameters.

7. The method according to claim 6, characterized in that, The method further includes: If the idle time of any set of stream cipher initialization state data in the storage unit exceeds a set time, the set of stream cipher initialization state data will be cleared from the storage unit.

8. The method according to any one of claims 1 to 5, characterized in that, The method further includes: If the target stream cipher initialization status data is not found, a stream cipher initialization operation is performed based on the encryption and decryption operation parameters carried in the target encryption and decryption request instruction to obtain the target stream cipher initialization status data; The obtained target stream cipher initialization state data is loaded into the cryptographic engine unit to generate a key stream that matches the length of the first data. The stream cipher operation corresponding to the target encryption / decryption request instruction is then performed based on the key stream, and the operation result is output.

9. A cryptographic engine unit, characterized in that, The cryptographic engine unit is provided with a storage unit, which is used to store the stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The stream cipher initialization state data includes the basic parameters used to start key stream generation after the cryptographic engine unit performs the stream cipher initialization operation. The cryptographic engine unit is configured to perform the encryption and decryption data processing method as described in any one of claims 1 to 7.

10. A microprocessor architecture, characterized in that, It includes a cryptographic engine unit, which is provided with a storage unit. The storage unit is used to store the stream cipher initialization state data pre-generated by the cryptographic engine unit for a specific instruction identifier. The stream cipher initialization state data includes the basic parameters used to start key stream generation after the cryptographic engine unit performs the stream cipher initialization operation. The cryptographic engine unit is configured to perform the encryption and decryption data processing method as described in any one of claims 1 to 7.