Data encryption method and system of national password TLS based on security chip
By integrating a hardware-based national cryptographic algorithm module into embedded devices, the problem of low efficiency of national cryptographic algorithms in embedded devices is solved, achieving efficient data encryption and identity authentication, and reducing hardware costs and power consumption.
Patent Information
- Application Number
- CN202510961008.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-12
- Publication Date
- 2025-11-14
AI Technical Summary
In existing technologies, embedded devices are inefficient when using national cryptographic algorithms, consuming a large amount of CPU resources and affecting the overall performance of the GMTLS protocol.
The method adopts the national cryptographic TLS data encryption method based on a security chip. It obtains the TLS open source protocol library through the processor, extracts and removes the encryption algorithm module, integrates the hardware national cryptographic algorithm module, defines the national cryptographic suite, and performs identity authentication and data encryption in the handshake protocol.
It improves the implementation efficiency of GMTLS in embedded devices, optimizes system resource utilization, ensures the authenticity of the identities of both communicating parties and data security, and reduces hardware costs and power consumption.
Smart Images

Figure CN120956447A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data encryption, and in particular to a data encryption method and system based on the national standard TLS (Security Tokenization) based on a security chip. Background Technology
[0002] As my country's information security requirements become more stringent, an increasing number of embedded devices need to support the national cryptographic algorithm standard. When these devices connect to the network, they need to use the TLS protocol based on the national cryptographic algorithm (GMTLS) to ensure communication security.
[0003] In related technologies, the current mainstream implementation method is to run a complete TLS protocol stack on a general-purpose MCU, implement various encryption algorithms in software, use standard international encryption algorithm libraries, and implement the operation of algorithms such as RSA and AES through program code. However, this pure software implementation is inefficient when performing Chinese cryptographic algorithms, because the computational complexity of Chinese cryptographic algorithms (such as SM2, SM3, SM4, etc.) is high. Implementing them in software will consume a lot of CPU resources and affect the overall performance of the GMTLS protocol. Summary of the Invention
[0004] This application provides a data encryption method and system based on a security chip using the national standard TLS, which can improve the implementation efficiency of GMTLS in embedded devices.
[0005] Firstly, this application provides a data encryption method for national cryptographic TLS based on a security chip, applied to a data encryption system for national cryptographic TLS based on a security chip. The data encryption system includes a processor and a security chip. The method includes: the processor acquiring a TLS open-source protocol library, extracting and retaining the protocol framework module and certificate processing module from the TLS open-source protocol library, and deleting the encryption algorithm library module from the TLS open-source protocol library to obtain a basic protocol framework; the processor integrating the hardware national cryptographic algorithm module of the security chip with the basic protocol framework to obtain a national cryptographic algorithm protocol framework, wherein the hardware national cryptographic algorithm module is used to replace the encryption algorithm library module; the processor defining a national cryptographic cipher suite based on the hardware national cryptographic algorithm module, and writing the national cryptographic cipher suite into the cipher suite list of the protocol framework module, wherein the national cryptographic cipher suite is used for key exchange; when the national cryptographic algorithm protocol framework executes a handshake protocol, the processor calls the certificate processing module for authentication and performs data encryption according to the hardware national cryptographic algorithm module.
[0006] By adopting the above technical solution, the processor obtains the TLS open-source protocol library and performs module extraction and deletion operations to obtain the basic protocol framework. Key functional modules are retained, and the hardware national cryptographic algorithm module of the security chip is integrated to replace the encryption algorithm library module. This fully leverages the hardware acceleration advantage and improves the computational efficiency of the national cryptographic algorithm. During the execution of the handshake protocol, the certificate processing module is used for identity authentication to ensure the authenticity of the identities of both communicating parties. Then, data encryption is performed according to the hardware national cryptographic algorithm module to ensure data security, thereby improving the implementation efficiency of GMTLS in embedded devices.
[0007] In conjunction with some embodiments of the first aspect, in some embodiments, the step of integrating the hardware national cryptographic algorithm module of the security chip with the basic protocol framework to obtain the national cryptographic algorithm protocol framework specifically includes: the processor dividing the memory space of the security chip into a standard storage area and an array storage area according to the memory requirement data required for the operation of the hardware national cryptographic algorithm module; the standard storage area is used to store small-capacity data with memory less than a preset memory threshold, and the array storage area is used to store large-capacity data with memory not less than the preset memory threshold; the security chip accesses the small-capacity data in the standard storage area using a program code call method, the small-capacity data including handshake parameters and temporary calculation data; the security chip accesses the large-capacity data in the array storage area using a predefined array method, the large-capacity data including protocol framework data and algorithm running data, the predefined array method storing data through a fixed-size array structure; the processor interfaces the program interface of the hardware national cryptographic algorithm module with the program interface of the basic protocol framework to obtain the national cryptographic algorithm protocol framework.
[0008] By adopting the above technical solution, the processor divides the memory space of the security chip into a standard storage area and an array storage area according to the memory requirements of the hardware national cryptographic algorithm module. This makes data storage management more reasonable and efficient. In the standard storage area, small-capacity data is accessed by program code calls, which utilizes its flexibility to handle frequently used small data and avoid memory fragmentation. In the array storage area, large-capacity data is accessed by predefined arrays. Static arrays improve access efficiency and reduce memory allocation and release operations. Finally, the interface between the hardware national cryptographic algorithm module and the basic protocol framework is connected to realize the integration of module functions. The various steps work together to optimize the utilization of system resources.
[0009] In conjunction with some embodiments of the first aspect, in some embodiments, the step of defining a national cryptographic suite based on the hardware national cryptographic algorithm module specifically includes: the processor configuring a first preset algorithm in the hardware national cryptographic algorithm module as a key exchange algorithm; the processor configuring a second preset algorithm in the hardware national cryptographic algorithm module as an integrity verification algorithm; the processor configuring a third preset algorithm in the hardware national cryptographic algorithm module as a data encryption algorithm; the processor calling a hardware true random number generator in the hardware national cryptographic algorithm module to generate random numbers required for the operation of the national cryptographic suite; and the processor generating a national cryptographic suite according to a preset cryptographic suite format based on the first preset algorithm, the third preset algorithm, and the hardware true random number generator.
[0010] By adopting the above technical solution, the processor is configured with different algorithms in the hardware national cryptographic algorithm module as key exchange, integrity verification, and data encryption algorithms, respectively. This specifically meets the needs of the national cryptographic suite in different functions. The hardware true random number generator is called to provide high-quality random numbers to enhance the security of the cryptographic suite. The national cryptographic suite is generated according to a preset format and written into the cryptographic suite list to ensure that the communicating parties can negotiate and select appropriate algorithm combinations. This makes the national cryptographic suite definition accurate and functionally complete, effectively ensuring the security and reliability of the key exchange process.
[0011] In conjunction with some embodiments of the first aspect, in some embodiments, before the steps of calling the certificate processing module for identity authentication and encrypting data according to the hardware national cryptographic algorithm module when executing the handshake protocol within the national cryptographic algorithm protocol framework, the method further includes: the security chip creating a key management table, the key management table containing a key type field, a key purpose field, a key length field, and a key content field; the security chip generating a single key verification value for each key record in the key management table, the single key verification value being used to verify the integrity of a single key; the security chip generating a key area verification value for all fields in the key management table, the key area verification value being used to verify the integrity of the entire key management table; when using a key during the handshake protocol process, the security chip performing permission verification based on the key type field and the key purpose field, the permission verification condition being that only keys meeting the usage conditions are allowed to participate in encryption operations.
[0012] By adopting the above technical solution, the security chip creates a key management table with multiple fields, providing a structured framework for key management. A single key verification value is generated for each key record, which can accurately verify the integrity of a single key and prevent key tampering. Key area verification values are generated for all fields, ensuring the overall security of the key management table. When using keys in the handshake protocol, permission verification is performed based on the key type and purpose fields, strictly limiting the key usage scenarios and enhancing the security and standardization of key management.
[0013] In conjunction with some embodiments of the first aspect, in some embodiments, after the steps of calling the certificate processing module for identity authentication and encrypting data according to the hardware national cryptographic algorithm module when executing the handshake protocol within the national cryptographic algorithm protocol framework, the method further includes: the processor sending a client handshake request message to the server, the client handshake request message containing information on the national cryptographic suites supported by the hardware national cryptographic algorithm module; upon receiving a server handshake message returned by the server, the processor verifying the server certificate information in the server handshake message through the certificate processing module; if the server certificate information is verified successfully, the security chip generates a pre-master key based on the SM2 algorithm, and generates a session key based on the pre-master key and a random number generated during the handshake process; the processor establishes an encrypted communication connection based on the session key.
[0014] By employing the above technical solution, the processor sends a client handshake request message to the server containing information on the national cryptographic suites supported by the hardware national cryptographic algorithm module, thus informing the server of the client's available cryptographic suites. Upon receiving the server handshake message, the certificate processing module verifies the server's certificate information to ensure the server's authenticity. If the verification is successful, the security chip generates a pre-master key based on the SM2 algorithm and combines it with a random number to generate a session key, providing a secure symmetric key for communication. This achieves a secure and reliable communication connection establishment process, ensuring accurate identification of both communicating parties. In conjunction with some embodiments of the first aspect, in some embodiments, the step of establishing an encrypted communication connection based on the session key specifically includes: the processor grouping application layer data into multiple data blocks according to a preset length; the security chip using a third preset algorithm to encrypt the data blocks to obtain encrypted data, and using a second preset algorithm to calculate the integrity check value of the encrypted data; and the processor packaging the encrypted data and the integrity check value into a data packet for transmission.
[0015] By adopting the above technical solution, the processor groups application layer data into multiple data blocks of a preset length, facilitating subsequent encryption processing. The security chip uses a third preset algorithm to encrypt the data blocks, ensuring data confidentiality, and then uses a second preset algorithm to calculate the integrity check value of the encrypted data, guaranteeing data integrity. The processor packages the encrypted data and the integrity check value into a data packet for transmission, adhering to protocol specifications to ensure accurate data transmission.
[0016] In conjunction with some embodiments of the first aspect, in some embodiments, before the step of integrating the hardware cryptographic algorithm module of the security chip with the basic protocol framework, the method further includes: the processor configuring the operating parameters of the security chip, the operating parameters including the working mode and storage space allocation of the hardware cryptographic algorithm module; the security chip detecting the operating status of the hardware cryptographic algorithm module; and when the operating status of the hardware cryptographic algorithm module is normal, the processor performing the integration operation of the hardware cryptographic algorithm module with the basic protocol framework.
[0017] By adopting the above technical solution, the processor configures the operating parameters of the security chip, including the working mode and storage space allocation of the hardware national cryptographic algorithm module. The security chip detects the operating status of the hardware national cryptographic algorithm module to ensure its normal operation and avoid system errors caused by module failure. The processor only performs subsequent integration operations when the module is operating normally, thus ensuring the stability and reliability of the entire system construction process.
[0018] In a second aspect, embodiments of this application provide a data encryption system, which includes: one or more processors and a memory; the memory is coupled to the one or more processors, and the memory is used to store computer program code, which includes computer instructions, and the one or more processors call the computer instructions to cause the data encryption system to perform the method described in the first aspect and any possible implementation thereof.
[0019] Thirdly, embodiments of this application provide a computer program product containing instructions that, when the computer program product is run on a data encryption system, cause the data encryption system to perform the method described in the first aspect and any possible implementation thereof.
[0020] Fourthly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a data encryption system, cause the data encryption system to perform the method described in the first aspect and any possible implementation thereof.
[0021] Understandably, the data encryption system provided in the second aspect, the computer program product provided in the third aspect, and the computer storage medium provided in the fourth aspect are all used to execute the methods provided in the embodiments of this application. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here.
[0022] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. This application obtains the TLS open-source protocol library through the processor and performs module extraction and deletion operations to obtain the basic protocol framework. Key functional modules are retained, and the hardware national cryptographic algorithm module of the security chip is integrated to replace the encryption algorithm library module. This fully leverages the hardware acceleration advantage and improves the computational efficiency of the national cryptographic algorithm. During the execution of the handshake protocol, the certificate processing module is used for identity authentication to ensure the authenticity of the identities of both communicating parties. Then, data encryption is performed according to the hardware national cryptographic algorithm module to ensure data security and improve the implementation efficiency of GMTLS in embedded devices.
[0023] 2. This application divides the memory space of the security chip into a standard storage area and an array storage area based on the memory requirements of the hardware national cryptographic algorithm module, making data storage management more reasonable and efficient. In the standard storage area, small-capacity data is accessed by program code calls, which utilizes its flexibility to handle frequently used small data and avoid memory fragmentation. In the array storage area, large-capacity data is accessed by predefined arrays, which improves access efficiency and reduces memory allocation and release operations through static arrays. Finally, the interface between the hardware national cryptographic algorithm module and the basic protocol framework is connected to realize the integration of module functions. The various steps work together to optimize the utilization of system resources.
[0024] 3. This application configures different algorithms in the hardware national cryptographic algorithm module through the processor as key exchange, integrity verification, and data encryption algorithms, respectively, to specifically meet the needs of the national cryptographic suite in different functions. It calls the hardware true random number generator to provide high-quality random numbers, enhances the security of the cryptographic suite, generates national cryptographic suites according to a preset format and writes them into the cryptographic suite list, ensuring that the communicating parties can negotiate and select appropriate algorithm combinations, making the national cryptographic suite definition accurate and functionally complete, and effectively ensuring the security and reliability of the key exchange process. Attached Figure Description
[0025] Figure 1 This is a flowchart illustrating a data encryption method based on a security chip using the national standard TLS in an embodiment of this application. Figure 2 This is another flowchart illustrating the national standard TLS data encryption method based on a security chip in this application embodiment; Figure 3 This is a schematic diagram of the physical device structure of a data encryption system in the embodiments of this application. Detailed Implementation
[0026] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification of this application, the singular expressions “a,” “an,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to any or all possible combinations including one or more of the listed items.
[0027] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0028] To facilitate understanding, the application scenarios of the embodiments of this application are described below.
[0029] In a smart manufacturing environment within an industrial park, a large number of embedded devices require real-time access to a cloud management platform for data transmission and remote control. These devices, including sensors, actuators, and controllers on the production line, number in the thousands. Because they involve core production data and control commands, communication must employ encryption schemes compliant with the requirements of the State Cryptography Administration. Furthermore, these devices primarily utilize low-power MCUs with limited computing resources and require 24 / 7 uninterrupted operation. Traditional software encryption schemes consume significant CPU resources, leading to slow device response and excessive power consumption. In addition, cost control is extremely stringent, necessitating both enhanced security and reduced hardware costs.
[0030] A factory uses a traditional solution for secure device access. Each device is equipped with a high-performance MCU with a 1GHz clock speed and a security chip, running a Linux operating system and implementing the GMTLS protocol in software. In actual operation, when 100 devices on the production line are transmitting data simultaneously, the CPU utilization of each device reaches over 85%, the devices overheat severely, and multiple crashes occur. Moreover, the hardware cost of a single device exceeds 200 yuan, the use of a large number of pins in the MCU complicates the PCB design, and reduces production yield. Furthermore, the Linux system boot time exceeds 30 seconds, affecting rapid device deployment, and system maintenance requires professional development support, resulting in high operation and maintenance costs.
[0031] After adopting this solution, the factory's embedded devices use only a single security chip integrating hardware acceleration of the national cryptographic algorithm, running the GMTLS protocol directly on the chip. When 100 devices are communicating encrypted simultaneously, the CPU utilization of each device is only about 20%, and the device operating temperature remains normal. Since no additional high-performance MCU and operating system are required, the hardware cost per device is reduced to below 50 yuan. The security chip has fewer pins, simplifying the PCB design and increasing the production yield to 99%. Device startup time is reduced to within 3 seconds, enabling rapid deployment. Maintenance personnel can complete daily operation and maintenance tasks with simple training.
[0032] To facilitate understanding, the method provided in this implementation will be described in detail below, using the above scenario as an example. Please refer to [link / reference]. Figure 1 This is a flowchart illustrating a data encryption method based on a security chip using the national cryptographic standard TLS in an embodiment of this application.
[0033] S101. The processor obtains the TLS open-source protocol library, extracts and retains the protocol framework module and certificate processing module from the TLS open-source protocol library, deletes the encryption algorithm library module from the TLS open-source protocol library, and obtains the basic protocol framework.
[0034] The TLS open-source protocol library refers to a collection of open-source software code that implements transport layer security protocols, such as the mbedtls library. The protocol framework module represents the program modules that implement the basic flow control, message format definition, and state management of the TLS protocol. The certificate processing module refers to the functional unit responsible for parsing and verifying X.509 digital certificates. The encryption algorithm library module represents the specific code collection that implements international encryption algorithms such as RSA and AES. The basic protocol framework refers to the core framework of the TLS protocol after removing the encryption algorithm implementations.
[0035] During the GMTLS system initialization phase, the processor needs to build a basic protocol framework. Specifically, the processor first obtains a complete open-source TLS protocol library, such as mbedtls version 1.2, from the network or storage medium; then it analyzes its code structure, locates and extracts the core code of the protocol framework modules, including functions such as protocol state machines, message encapsulation, and session management; at the same time, it retains the code of the certificate processing module, including functions such as certificate parsing and certificate chain verification; finally, it removes all encryption algorithm implementation code, including the specific implementations of symmetric encryption, asymmetric encryption, hash algorithms, etc., thus obtaining a clean basic protocol framework.
[0036] In some embodiments, the TLS open-source protocol library can be obtained and processed in several ways: Optionally, the source code can be cloned from the official code repository, a version control tool can be used to check out a specified version, and the encryption algorithm module can be disabled by compiling and configuring, while retaining the protocol framework and certificate processing module; alternatively, the TLS open-source protocol library source code can be divided into functional modules, encryption algorithm-related source files can be manually deleted, relevant header files and configuration files can be modified, and the remaining code can be reorganized and compiled. It is understood that other methods can also be used to process the TLS open-source protocol library to obtain the basic protocol framework, which are not limited here.
[0037] S102. The processor integrates the hardware national cryptographic algorithm module of the security chip with the basic protocol framework to obtain the national cryptographic algorithm protocol framework. The hardware national cryptographic algorithm module is used to replace the encryption algorithm library module.
[0038] Here, "hardware cryptographic algorithm module" refers to a dedicated hardware unit in the security chip that implements national cryptographic algorithms such as SM2 / SM3 / SM4. "Integration" refers to the process of combining the functions and adapting the interfaces of two independent modules. "National Cryptographic Algorithm Protocol Framework" represents a complete GMTLS protocol implementation that integrates hardware cryptographic algorithms. "Replacement" refers to completely replacing the functionality of the original module with a new one.
[0039] After obtaining the basic protocol framework, the hardware national cryptographic algorithm needs to be integrated with the protocol framework. Specifically, the processor first identifies the calling interface of the original encryption algorithm in the basic protocol framework; then it encapsulates the functional interface of the hardware national cryptographic algorithm module, including algorithm initialization, key setting, encryption and decryption operations, etc.; next, it implements an interface adaptation layer to convert the algorithm calls of the protocol framework into corresponding hardware national cryptographic algorithm operations; finally, it completes functional verification and testing to ensure that the integrated national cryptographic algorithm protocol framework can work normally.
[0040] In some embodiments, the integration of hardware-based national cryptographic algorithms can be achieved in several ways: Optionally, a function encapsulation approach can be used, where a wrapper function is written for each hardware-based national cryptographic algorithm, implementing parameter conversion and interface adaptation within the wrapper function, and replacing the original algorithm call with a function pointer; alternatively, an object-oriented approach can be used, encapsulating the hardware-based national cryptographic algorithm into a class, implementing the same interface as the original encryption algorithm, and achieving algorithm replacement through polymorphism. It is understood that other methods can also be used to integrate hardware-based national cryptographic algorithms with the basic protocol framework, which are not limited here.
[0041] S103. The processor defines a national cryptographic suite based on the hardware national cryptographic algorithm module, and writes the national cryptographic suite into the cryptographic suite list of the protocol framework module. The national cryptographic suite is used for key exchange.
[0042] Among them, the national cryptographic suite refers to a set of cryptographic algorithms composed of national cryptographic algorithms, such as SM2_SM4_SM3, represented by a two-byte value {0xe0, 0x13}. The cryptographic suite list represents a data structure storing all available cryptographic suites. Key exchange represents the process of securely establishing a shared key between communicating parties. The hardware national cryptographic algorithm module refers to a dedicated hardware unit in the security chip that implements algorithms such as SM2 / SM3 / SM4. The protocol framework module represents the program module that implements the basic flow control and state management of the TLS protocol.
[0043] After integrating the hardware-based national cryptographic algorithms with the protocol framework, the supported cipher suites need to be defined. Specifically, the processor first configures the SM2 algorithm as the key exchange algorithm, the SM3 algorithm as the integrity verification algorithm, and the SM4 algorithm as the data encryption algorithm; then, it calls the hardware true random number generator to provide random numbers for the cipher suite operation; next, it combines these algorithms according to a preset format to generate standard national cryptographic suites, such as SM2_SM4_SM3; finally, it writes the generated cipher suite information into the cipher suite list of the protocol framework so that it can be selected in subsequent handshake protocols.
[0044] In some embodiments, the definition and configuration of national cryptographic suites can be implemented in several ways: Optionally, through a configuration file, the constituent algorithms, identifier values, and parameter settings of the cryptographic suite are defined in the configuration file, and the configuration file is read and the cryptographic suite is initialized when the program starts; alternatively, through program code, the cryptographic suite structure is defined directly in the code, the algorithm combination and parameters are set, and the cryptographic suite is added to the list through function calls. It is understood that other methods can also be used to define and configure national cryptographic suites, which are not limited here.
[0045] S104. When executing the handshake protocol within the framework of the national cryptographic algorithm protocol, the processor calls the certificate processing module for identity authentication and encrypts the data according to the hardware national cryptographic algorithm module.
[0046] The handshake protocol represents the process of establishing a secure connection, including steps such as authentication and key negotiation. The certificate processing module is the functional unit responsible for parsing and verifying X.509 digital certificates. Authentication represents the process of verifying the authenticity of the communicating party's identity. Data encryption refers to the process of protecting communication data using cryptographic algorithms. The national cryptographic algorithm protocol framework represents a complete GMTLS protocol implementation integrating hardware-based national cryptographic algorithms.
[0047] When two communicating parties establish a connection, a handshake protocol is required to achieve secure authentication. Specifically, the processor first initiates the GMTLS handshake process; then it calls the certificate processing module to parse the digital certificate sent by the other party and verify the certificate's signature, validity period, and purpose; after successful authentication, the SM2 algorithm is used to complete key exchange and generate a session key; finally, the SM4 algorithm is used to encrypt subsequent communication data, and the SM3 algorithm is used to ensure data integrity.
[0048] In some embodiments, authentication and data encryption in the handshake protocol can be implemented in several ways: Optionally, a synchronous processing approach can be adopted, executing certificate verification, key exchange, and data encryption sequentially according to the state machine order of the handshake protocol, proceeding to the next step only after each step is completed; alternatively, an asynchronous processing approach can be adopted, creating independent processing threads to handle certificate verification and data encryption separately, coordinating the various processing procedures through message queues or callback mechanisms. It is understood that other methods can also be used to implement authentication and data encryption in the handshake protocol, which are not limited here.
[0049] The following provides a more detailed description of the process of the method provided in this implementation. Please refer to [link / reference]. Figure 2 This is another flowchart illustrating the national cryptographic TLS data encryption method based on a security chip in this application embodiment.
[0050] S201. The processor obtains the TLS open-source protocol library, extracts and retains the protocol framework module and certificate processing module from the TLS open-source protocol library, deletes the encryption algorithm library module from the TLS open-source protocol library, and obtains the basic protocol framework.
[0051] The TLS open-source protocol library is a collection of software code that implements transport layer security protocols, such as the mbedtls library. It includes a protocol framework module, a certificate processing module, and a cryptographic algorithm library module. The protocol framework module is responsible for implementing the basic flow control, message format definition, and state management of the TLS protocol. The certificate processing module is responsible for handling the parsing, verification, and management of X.509 digital certificates. The cryptographic algorithm library module contains the specific implementation code for international cryptographic algorithms such as RSA and AES. The basic protocol framework is the core framework of the TLS protocol after removing the cryptographic algorithm implementations.
[0052] In this step, the processor first acquires a complete open-source TLS protocol library, such as mbedtls version 1.2. By analyzing the library's code structure, the processor extracts and retains the complete code for the protocol framework modules (such as the protocol state machine and message encapsulation) and certificate processing modules (such as certificate parsing and certificate chain verification). Simultaneously, the processor removes the encryption algorithm implementation code from the protocol library, including the specific implementations of symmetric encryption, asymmetric encryption, and hash algorithms. This results in a basic protocol framework that retains the core functionality of the TLS protocol, preparing for subsequent integration of hardware-based national cryptographic algorithm modules.
[0053] S202. The processor configures the operating parameters of the security chip, including the working mode and storage space allocation of the hardware cryptographic algorithm module.
[0054] Operating parameters are configuration data that control the working state of the security chip, including the operating mode of the hardware national cryptographic algorithm module (such as encryption / decryption mode, key length, etc.) and the storage space allocation scheme (such as key storage area, data buffer area, etc.). The hardware national cryptographic algorithm module is a dedicated hardware unit in the security chip that implements national cryptographic algorithms such as SM2 / SM3 / SM4. The operating mode defines the specific way the algorithm runs, and the storage space allocation determines the storage location and size of various types of data.
[0055] The processor writes predefined operating parameters to the security chip through a dedicated configuration interface. For operating modes, the operating mode for each algorithm needs to be set, such as the signature / verification mode for the SM2 algorithm and the ECB / CBC encryption mode for the SM4 algorithm. For storage space, different functional areas need to be divided according to algorithm requirements, such as allocating a dedicated storage area for SM2 key pairs and temporary storage space for SM4 session keys. These configurations ensure the correct operation of the hardware-based national cryptographic algorithm module.
[0056] S203. The security chip detects the operating status of the hardware cryptographic algorithm module.
[0057] Operational status refers to the working condition of the hardware cryptographic algorithm module, including whether it has been initialized correctly, whether each functional unit is functioning properly, and whether the internal registers are set correctly. Testing involves the security chip verifying the availability of the hardware cryptographic algorithm module through its internal self-test mechanism.
[0058] In this step, the security chip performs a self-test program, sequentially checking each component of the hardware cryptographic algorithm module. Specifically, this includes: checking the functional integrity of the SM2 / SM3 / SM4 algorithm units, verifying the output characteristics of the random number generator, testing the read / write capabilities of the internal RAM and registers, and confirming the security of the key storage area. These checks ensure that the hardware cryptographic algorithm module can securely and reliably execute subsequent cryptographic operations.
[0059] S204. When the hardware cryptographic algorithm module is running normally, the processor divides the memory space of the security chip into a standard storage area and an array storage area according to the memory requirement data required for the operation of the hardware cryptographic algorithm module. The standard storage area is used to store small-capacity data with memory less than a preset memory threshold, and the array storage area is used to store large-capacity data with memory not less than the preset memory threshold.
[0060] Memory requirement data refers to the specific storage space requirements of the hardware cryptographic algorithm module during operation, including the size and frequency of use of various types of data. The standard storage area is a memory region used to store small amounts of data, managed using standard memory allocation methods. The array storage area is a memory region used to store large amounts of data, managed using a fixed-size array structure. The preset memory threshold is the boundary value distinguishing between small and large amounts of data, typically set to 2KB. Small data refers to data for which a single memory allocation is less than 2KB. Large data refers to data for which a single memory allocation is at least 2KB.
[0061] After confirming that the hardware cryptographic algorithm module is operating normally, the processor allocates the memory space of the security chip based on the statistical memory usage. Frequently used but small data, such as handshake parameters and temporary variables, are allocated to the standard storage area; larger data, such as protocol message caches and algorithm calculation results, are allocated to the array storage area. In practice, the processor uses the memory management unit to set up a memory mapping table, mapping the physical memory address space to two logical regions, and records the starting address and size of each region in the memory allocation table.
[0062] S205. The security chip accesses the small amount of data in the standard storage area using a program code call method. The small amount of data includes handshake parameters and temporary calculation data.
[0063] The program code calling method refers to the method of allocating and freeing memory using the standard malloc / free functions. Small amounts of data include handshake parameters (such as random numbers, protocol version numbers, etc.) and temporary computation data (such as intermediate results, status flags, etc.). Handshake parameters are various configuration information exchanged during the TLS handshake process. Temporary computation data is temporary data generated during algorithm execution.
[0064] When processing small amounts of data, the security chip uses memory management functions provided by the standard C library. When handshake parameters need to be stored, it allocates the required memory space using the `malloc` function, writes the parameters into memory, and releases the memory using the `free` function after use. For temporary computational data, dynamic allocation is also used to ensure flexible memory usage. This approach is suitable for processing large amounts of small datasets and avoids memory fragmentation.
[0065] S206. The security chip uses a predefined array method to access the large-capacity data in the array storage area. The large-capacity data includes protocol framework data and algorithm running data. The predefined array method stores the data through a fixed-size array structure.
[0066] Predefined arrays refer to the method of pre-allocating a fixed-size array space to store data. Large-capacity data includes protocol framework data (such as message buffers, certificate information, etc.) and algorithm execution data (such as encrypted input / output, key information, etc.). Protocol framework data comprises the various data structures required to implement the TLS protocol. Algorithm execution data is the data used during the execution of cryptographic algorithms. Fixed-size array structures refer to data structures whose array size is determined at compile time.
[0067] When processing large amounts of data, security chips use static arrays for storage. During program initialization, a fixed-size array is predefined and allocated, such as a 4KB array for protocol message buffers and a 3KB array for SM2 calculation results. Data access is performed directly via array indices, avoiding frequent memory allocation and deallocation operations. This approach is suitable for handling large blocks of data, improving access efficiency and reducing memory fragmentation.
[0068] S207. The processor interfaces the program interface of the hardware national cryptographic algorithm module with the program interface of the basic protocol framework to obtain the national cryptographic algorithm protocol framework. The hardware national cryptographic algorithm module is used to replace the encryption algorithm library module.
[0069] A program interface refers to the standardized interface definition for data exchange and function calls between software modules. The program interface for the hardware national cryptographic algorithm module includes the calling methods, parameter formats, and return value definitions for algorithms such as SM2 / SM3 / SM4. The program interface for the basic protocol framework includes the encryption algorithm calling interfaces defined in the original TLS protocol. The national cryptographic algorithm protocol framework is a complete protocol implementation formed by integrating national cryptographic algorithms into the TLS protocol framework. The encryption algorithm library module is the program module in the original TLS protocol that implements international encryption algorithms such as RSA and AES.
[0070] In this step, the processor implements interface conversion between the hardware-based national cryptographic algorithm and the protocol framework by writing adaptation layer code. Specifically, this includes: defining an interface mapping table to map the encryption algorithm call interfaces in the TLS protocol to the corresponding national cryptographic algorithm interfaces; writing wrapper functions to handle parameter format conversion, such as converting RSA key format to SM2 key format; and implementing call flow adaptation to ensure the protocol framework can correctly call the hardware-based national cryptographic algorithm to complete encryption operations. In this way, the hardware-based national cryptographic algorithm module completely replaces the original encryption algorithm library, providing cryptographic services for the GMTLS protocol.
[0071] S208. The processor is configured with the first preset algorithm in the hardware national cryptographic algorithm module as the key exchange algorithm.
[0072] A key exchange algorithm is an algorithm that securely establishes a shared key between communicating parties. The first pre-defined algorithm specifically refers to the SM2 algorithm, a public-key cryptography algorithm based on elliptic curve cryptography, used to replace the RSA or ECDSA algorithms in international TLS. The SM2 algorithm has functions such as key generation, key negotiation, and digital signature, and its security strength is comparable to RSA-2048.
[0073] The processor configures the SM2 algorithm in the hardware cryptographic algorithm module as the key exchange algorithm for the GMTLS protocol by configuring registers or sending configuration commands. The configuration process includes: setting the SM2 algorithm key length (256 bits), selecting the elliptic curve parameters (the recommended SM2 curve), and configuring the key negotiation mode. After configuration, during the GMTLS handshake, the protocol framework will invoke the SM2 algorithm to complete the key exchange operation, including generating temporary key pairs and calculating the shared key.
[0074] S209. The processor is configured with the second preset algorithm in the hardware cryptographic algorithm module as the integrity verification algorithm.
[0075] Integrity verification algorithms are used to verify whether communication data has been tampered with during transmission. The second preset algorithm specifically refers to the SM3 algorithm, a cryptographic hash algorithm with a 256-bit output length, used to replace the SHA-1 or SHA-256 algorithms used in international TLS. The SM3 algorithm has cryptographic properties such as one-wayness and collision resistance, making it suitable for digital signatures and message authentication.
[0076] The processor configures the hardware cryptographic algorithm module to set the SM3 algorithm as the integrity verification algorithm for the GMTLS protocol. The configuration process includes: setting the SM3 algorithm's operating mode, configuring the data padding method, and initializing the algorithm state. After configuration, during GMTLS communication, all data requiring integrity protection will use the SM3 algorithm to calculate the message authentication code, ensuring the integrity and authenticity of data transmission.
[0077] S210, The processor is configured with the third preset algorithm in the hardware national cryptographic algorithm module as the data encryption algorithm.
[0078] Data encryption algorithms are symmetric cryptographic algorithms used to encrypt and protect communication data. The third preset algorithm specifically refers to the SM4 algorithm, a block cipher algorithm with a block size and key length of 128 bits, used to replace the AES or 3DES algorithms in international TLS. The SM4 algorithm employs a 32-round non-linear iterative structure, offering high security and implementation efficiency, making it suitable for encrypted data transmission.
[0079] The processor configures the hardware cryptographic algorithm module to set the SM4 algorithm as the data encryption algorithm for the GMTLS protocol. The specific configuration process includes: setting the SM4 algorithm's operating mode (ECB / CBC), configuring the key length (128 bits), setting the initialization vector IV, and configuring the data padding method. After configuration, during GMTLS communication, all application data requiring encrypted transmission will be encrypted and decrypted using the SM4 algorithm.
[0080] S211. The processor calls the hardware true random number generator in the hardware national cryptographic algorithm module to generate random numbers required for the operation of the national cryptographic suite.
[0081] A hardware true random number generator is a physical device within the hardware national cryptographic algorithm module specifically designed to generate high-quality random numbers. It generates truly random sequences based on physical noise sources (such as thermal noise, photon quantum noise, etc.), and after post-processing, obtains random numbers that meet cryptographic requirements. These random numbers are used to generate cryptographic parameters such as session keys and initialization vectors.
[0082] The processor invokes a hardware true random number generator through a dedicated interface to provide random numbers for the operation of the national cryptographic suite. The invocation process includes: initializing the random number generator, setting sampling parameters, collecting random source data, and performing statistical checks. Each time random numbers are needed, the processor obtains a random sequence of a specified length from the hardware true random number generator. These random numbers will be used to generate key materials, construct protocol messages, etc.
[0083] S212. The processor generates a national cryptographic suite according to a preset cryptographic suite format based on the first preset algorithm, the third preset algorithm, and the hardware true random number generator, and writes the national cryptographic suite into the cryptographic suite list of the protocol framework module. The national cryptographic suite is used for key exchange.
[0084] Chinese national cryptographic suites are combinations of cryptographic algorithms defined in the GMTLS protocol. The default suite format specifies the suite's identifier value and structure; for example, {0xe0, 0x13} represents the SM2_SM4_SM3 algorithm combination. The suite list is a data structure within the protocol framework that stores all supported suites.
[0085] In this step, the processor combines the configured SM2 (key exchange), SM3 (integrity check), and SM4 (data encryption) algorithms with a hardware true random number generator into a complete national cryptographic suite. The specific process includes: generating a cryptographic suite identifier value according to a preset format, forming a combination of {algorithm identifier, key length, and operating mode}; constructing a cryptographic suite description structure, including algorithm interface pointers and parameter configurations; and adding the generated national cryptographic suite to the protocol framework's cryptographic suite list. Thus, during the subsequent GMTLS handshake, the communicating parties negotiate and select a suitable cryptographic suite to establish secure communication.
[0086] S213. The security chip creates a key management table, which includes a key type field, a key purpose field, a key length field, and a key content field.
[0087] The key management table is a structured data table used to uniformly manage all key information used in the GMTLS protocol. The key type field identifies the algorithm type of the key, such as SM2 public key, SM4 session key, etc. The key purpose field specifies the use case of the key, such as signature verification, data encryption, etc. The key length field records the actual bit length of the key, such as 256 bits for SM2 keys and 128 bits for SM4 keys. The key content field stores the actual key data in a secure storage format.
[0088] During the initialization phase, the security chip creates a key management table, assigning corresponding entries to each type of key. The specific implementation includes: allocating a fixed-size tablespace in the secure storage area; defining the table structure, including header information (total number of records, table size, etc.) and an array of entries; creating four fields for each entry to store the key type (1 byte), key purpose (1 byte), key length (2 bytes), and key content (variable length); and initializing entry status flags to indicate whether the entry is in use.
[0089] S214. The security chip generates a key area verification value for all fields in the key management table. This key area verification value is used to verify the integrity of the entire key management table.
[0090] The key area checksum is a total checksum calculated for the entire key management table, used to verify the integrity of the entire key storage area. All fields refer to all data in the key management table, including header information, all key records, and their individual key checksums. Integrity verification of the key management table is a mechanism to ensure that the entire key storage area has not been illegally modified.
[0091] After generating all individual key checksums, the security chip calculates the key area checksum for the entire key management table. This is implemented by: collecting all data in the table in a predefined order, including header information, all fields of each key record, and all individual key checksums; calculating the hash value of the collected data using the SM3 algorithm to obtain a 32-byte key area checksum; and storing the key area checksum in a dedicated area at the end of the key management table. Each time the key management table is accessed, the key area checksum is verified first to ensure the integrity of the entire key storage area.
[0092] S215. When using a key during the handshake protocol, the security chip performs permission verification based on the key type field and the key purpose field. The permission verification condition is that only keys that meet the usage conditions are allowed to participate in encryption operations.
[0093] The handshake protocol is the process used in GMTLS to establish a secure connection, including steps such as authentication and key negotiation. Permission verification is a mechanism for checking the permissions to use keys, ensuring that keys are used only for their designated purposes. Usage conditions are key usage rules defined by the key type field and the key purpose field; for example, an SM2 signing key can only be used for digital signature operations, and an SM4 session key can only be used for data encryption and decryption. Encryption operations include cryptographic operations such as encryption, decryption, signing, and signature verification.
[0094] The security chip performs strict authorization verification before executing cryptographic operations. Specifically, this includes: reading the type field of the key to be used to confirm whether it matches the algorithm type required for the requested operation (e.g., SM2 / SM3 / SM4); checking the key purpose field to verify whether the requested operation type (e.g., signing / encryption) is permitted; comparing the operation request with the key attributes (e.g., a signing operation can only use an SM2 key marked for signing purposes); and only allowing cryptographic operations using the key if both the type and purpose match, otherwise returning an error code to prevent the operation from executing.
[0095] S216. When executing the handshake protocol within the framework of the national cryptographic algorithm protocol, the processor calls the certificate processing module for identity authentication and encrypts the data according to the hardware national cryptographic algorithm module.
[0096] The certificate processing module is the functional unit that processes X.509 digital certificates, responsible for certificate parsing, verification, and management. Identity authentication is the process of verifying the authenticity of the communicating party's identity, achieved through digital certificate verification. Data encryption is the process of encrypting and protecting communication data using a negotiated key. The hardware-based national cryptographic algorithm module provides hardware implementations of algorithms such as SM2 / SM3 / SM4.
[0097] During the GMTLS handshake protocol execution, the processor first invokes the certificate processing module to complete identity authentication. Specific steps include: parsing the digital certificate sent by the other party to extract the public key and identity information; verifying the certificate signature to confirm whether the certificate was issued by a trusted certificate authority; and checking the certificate's validity period and purpose to confirm that the certificate is valid and suitable for GMTLS authentication. After successful authentication, the processor invokes the hardware cryptographic algorithm module for data encryption, including: using the SM2 algorithm for key exchange and generating a session key; using the SM4 algorithm to encrypt communication data; and using the SM3 algorithm to ensure data integrity. The entire process strictly adheres to the GMTLS protocol specification to ensure communication security.
[0098] In some embodiments, step S216 may be followed by the following steps: The processor sends a client handshake request message to the server, which contains information about the national cryptographic suites supported by the hardware national cryptographic algorithm module.
[0099] Specifically, the client handshake request message is the first message sent by the client when initiating a connection in the GMTLS protocol, used to indicate to the server the intention to establish a secure connection. The national cryptographic suite information is a list of cryptographic algorithm combinations supported by the client, such as SM2_SM4_SM3, identified by a two-byte value {0xe0, 0x13}. The cryptographic suites supported by the hardware national cryptographic algorithm module refer to the combinations of national cryptographic algorithms implemented in the security chip. The processor constructs a ClientHello message and sends it to the server. The specific implementation includes: filling in the protocol version number (value 0x0101); calling the hardware true random number generator to generate a 32-byte client random number; collecting supported cryptographic suite information, encoding the identifier values of suites such as SM2_SM4_SM3 according to the TLS specification format; assembling the above information into a ClientHello message, encapsulating it according to the message format specified by the protocol; and sending it to the server through the network interface.
[0100] Upon receiving a server handshake message returned by the server, the processor verifies the server certificate information in the handshake message through the certificate processing module.
[0101] Specifically, the server handshake message is a set of messages sent by the server in response to the client's handshake request, including messages such as ServerHello and Certificate. The server certificate information is the server's identity credential, containing its public key and identity data. The certificate processing module is the functional unit responsible for parsing and verifying X.509 format certificates. After receiving the handshake message returned by the server, the processor uses the certificate processing module to verify the server certificate. The specific steps include: parsing the ServerHello message to confirm the cipher suite selected by the server; extracting the certificate chain information and verifying it level by level according to the certificate chain order; checking the certificate validity period, purpose, and signature algorithm; verifying the legality of the certificate signature; and extracting the server's SM2 public key to prepare for subsequent key exchange.
[0102] If the server certificate information is verified, the security chip generates a pre-master key based on the SM2 algorithm, and generates a session key based on the pre-master key and the random number generated during the handshake process.
[0103] Specifically, the pre-master key is the intermediate key material used to generate the final session key. The SM2 algorithm is a Chinese national standard asymmetric cryptographic algorithm used to securely generate and transmit the pre-master key. The session key is a symmetric key used to encrypt communication data. The random number is a random value exchanged between the client and server during the handshake process, used to increase the randomness of key generation. After the server certificate verification is successful, the security chip executes the key generation process. The specific implementation includes: generating a 48-byte pre-master key using the SM2 algorithm; combining the pre-master key with the client's random number and the server's random number; performing derivation calculations on the combined data using the SM3 algorithm to generate the session key material; extracting the encryption key and MAC key from the key material; writing the generated key material into the key management table and setting appropriate type and purpose identifiers.
[0104] The processor establishes an encrypted communication connection based on the session key.
[0105] Specifically, the session key is a symmetric key used to encrypt communication data after the GMTLS handshake protocol is completed. The encrypted communication connection is a secure data transmission channel established based on the session key, ensuring the confidentiality and integrity of data transmission. Establishing a connection includes initializing encryption parameters, configuring the communication state, and preparing a data buffer. The processor uses the negotiated session key to initialize the secure communication environment. The specific implementation includes: configuring the operating parameters of the SM4 encryption algorithm, including the key, initialization vector, and operating mode; initializing the SM3 integrity protection algorithm; establishing send and receive data buffers; setting connection status flags to indicate that the secure channel has been established; and preparing a sequence number counter for preventing replay attacks.
[0106] The processor groups application layer data into multiple data blocks according to a preset length.
[0107] Specifically, application layer data is the raw data content that needs to be transmitted encrypted. The preset length is the data block size specified by the SM4 block cipher algorithm, which is fixed at 16 bytes. A data block is a unit of application layer data divided into 16-byte blocks. If the last data block is less than 16 bytes, it needs to be padded. The processor processes the application layer data into blocks. The specific implementation includes: calculating the total data length; dividing the data into blocks according to 16-byte boundaries; performing PKCS7 padding on the last incomplete data block; adding a sequence number to each data block; and passing the grouped data blocks to the security chip for encryption.
[0108] The security chip uses a third preset algorithm to encrypt the data block to obtain encrypted data, and uses a second preset algorithm to calculate the integrity check value of the encrypted data.
[0109] Specifically, the third preset algorithm refers to the SM4 symmetric encryption algorithm, used for data encryption. The second preset algorithm refers to the SM3 hash algorithm, used to calculate the data integrity check value. The integrity check value is a 32-byte hash value calculated using the SM3 algorithm on the encrypted data, used to verify data integrity. The security chip performs encryption and integrity protection on data blocks. The specific implementation includes: encrypting each data block using the SM4 algorithm, employing CBC mode to ensure the security of the ciphertext; calculating the hash value of all encrypted data blocks using the SM3 algorithm to obtain a 32-byte integrity check value; combining the encrypted data and the integrity check value into the final transmission data packet; and sending the data packet to the communication partner through a secure channel. After receiving the data, the communication partner uses the same process for decryption and integrity verification.
[0110] The processor packages the encrypted data and the integrity check value into a data packet for transmission.
[0111] Specifically, the encrypted data is ciphertext data encrypted using the SM4 algorithm, stored in 16-byte blocks. The integrity check value is a 32-byte hash value calculated using the SM3 algorithm, used to verify data integrity. A data packet is a communication data unit conforming to the GMTLS protocol specification, containing a protocol header and payload data. Transmission is the process of sending data packets to the communication partner through the network interface; the processor performs data packaging and transmission operations. The specific implementation includes: constructing the GMTLS record layer protocol header, filling in the protocol type (value 0x17 indicates application data), protocol version (value 0x0101), and data length; using the encrypted data as the payload of the record layer protocol; appending a 32-byte SM3 integrity check value to the end of the payload; calculating the length of the complete data packet to ensure it does not exceed the Maximum Transmission Unit (MTU) limit; transmitting the data packet to the partner through the network interface's send buffer; and updating the sequence number counter after transmission to prepare for the next data packet. Upon receiving the data packet, the receiver unpacks it in reverse order: first verifying the integrity check value, then decrypting the data content, and finally submitting the plaintext data to the application layer for processing.
[0112] The data encryption system in the embodiments of this invention is described below from the perspective of hardware processing. Please refer to [link / reference]. Figure 3 This is a schematic diagram of the physical device structure of a data encryption system in an embodiment of this application.
[0113] It should be noted that, Figure 3 The structure of the data encryption system shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0114] like Figure 3 As shown, the data encryption system includes a Central Processing Unit (CPU) 301, which can perform various appropriate actions and processes based on a program stored in Read-Only Memory (ROM) 302 or a program loaded from storage section 308 into Random Access Memory (RAM) 303, such as performing the methods described in the above embodiments. The RAM 303 also stores various programs and data required for system operation. The CPU 301, ROM 302, and RAM 303 are interconnected via a bus 304. An Input / Output (I / O) interface 305 is also connected to the bus 304.
[0115] The following components are connected to I / O interface 305: input section 306 including audio input devices, push-button switches, etc.; output section 307 including a liquid crystal display (LCD) and audio output devices, indicator lights, etc.; storage section 308 including a hard disk, etc.; and communication section 309 including a network interface card such as a LAN (Local Area Network) card, modem, etc. Communication section 309 performs communication processing via a network such as the Internet. Drive 310 is also connected to I / O interface 305 as needed. Removable media 311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 310 as needed so that computer programs read from them can be installed into storage section 308 as needed.
[0116] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing computer programs for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 309, and / or installed from removable medium 311. When the computer program is executed by central processing unit (CPU) 301, it performs the various functions defined in the present invention.
[0117] It should be noted that specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0118] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. Each block in a flowchart or block diagram may represent a module, program segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those shown in the drawings.
[0119] Specifically, the data encryption system of this embodiment includes a processor and a memory. The memory stores a computer program. When the computer program is executed by the processor, it implements the national cryptographic TLS data encryption method based on a security chip provided in the above embodiment.
[0120] In another aspect, the present invention also provides a computer-readable storage medium, which may be included in the data encryption system described in the above embodiments; or it may exist independently and not assembled into the data encryption system. The storage medium carries one or more computer programs, which, when executed by a processor of the data encryption system, cause the data encryption system to implement the national standard TLS data encryption method based on a security chip provided in the above embodiments.
[0121] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0122] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as meaning "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as meaning "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".
[0123] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A data encryption method based on a secure chip using the national standard TLS, characterized in that, A data encryption system based on a national standard TLS (Third-Level Secrecy) security chip, the data encryption system comprising a processor and a security chip, the method comprising: The processor obtains the TLS open-source protocol library, extracts and retains the protocol framework module and certificate processing module in the TLS open-source protocol library, deletes the encryption algorithm library module in the TLS open-source protocol library, and obtains the basic protocol framework. The processor integrates the hardware national cryptographic algorithm module of the security chip with the basic protocol framework to obtain the national cryptographic algorithm protocol framework. The hardware national cryptographic algorithm module is used to replace the encryption algorithm library module. The processor defines a national cryptographic suite based on the hardware national cryptographic algorithm module, and writes the national cryptographic suite into the cryptographic suite list of the protocol framework module. The national cryptographic suite is used for key exchange. When the handshake protocol is executed within the framework of the national cryptographic algorithm protocol, the processor calls the certificate processing module to perform identity authentication and encrypts the data according to the hardware national cryptographic algorithm module.
2. The method according to claim 1, characterized in that, The step of integrating the hardware national cryptographic algorithm module of the security chip with the basic protocol framework to obtain the national cryptographic algorithm protocol framework specifically includes: The processor divides the memory space of the security chip into a standard storage area and an array storage area according to the memory requirement data required for the operation of the hardware national cryptographic algorithm module. The standard storage area is used to store small-capacity data with memory less than a preset memory threshold, and the array storage area is used to store large-capacity data with memory not less than the preset memory threshold. The security chip accesses the small-capacity data in the standard storage area using a program code call method. The small-capacity data includes handshake parameters and temporary calculation data. The security chip accesses the large-capacity data in the array storage area using a predefined array method. The large-capacity data includes protocol framework data and algorithm execution data. The predefined array method stores the data using a fixed-size array structure. The processor interfaces the program interface of the hardware national cryptographic algorithm module with the program interface of the basic protocol framework to obtain the national cryptographic algorithm protocol framework.
3. The method according to claim 1, characterized in that, The step of defining a national cryptographic suite based on the hardware national cryptographic algorithm module specifically includes: The processor is configured with the first preset algorithm in the hardware national cryptographic algorithm module as the key exchange algorithm; The processor is configured with the second preset algorithm in the hardware cryptographic algorithm module as the integrity verification algorithm; The processor is configured with the third preset algorithm in the hardware national cryptographic algorithm module as the data encryption algorithm; The processor calls the hardware true random number generator in the hardware national cryptographic algorithm module to generate random numbers required for the operation of the national cryptographic suite; The processor generates a national cryptographic suite according to a preset cryptographic suite format based on the first preset algorithm, the third preset algorithm, and the hardware true random number generator.
4. The method according to claim 1, characterized in that, Before the steps of calling the certificate processing module for identity authentication and encrypting data according to the hardware national cryptographic algorithm module when executing the handshake protocol within the national cryptographic algorithm protocol framework, the method further includes: The security chip creates a key management table, which includes a key type field, a key purpose field, a key length field, and a key content field. The security chip generates a single key verification value for each key record in the key management table. The single key verification value is used to verify the integrity of a single key. The security chip generates a key area verification value for all fields in the key management table, and the key area verification value is used to verify the integrity of the entire key management table; When using a key during the handshake protocol, the security chip performs permission verification based on the key type field and the key purpose field. The permission verification condition is that only keys that meet the usage conditions are allowed to participate in encryption operations.
5. The method according to claim 1, characterized in that, After the steps of calling the certificate processing module for identity authentication and encrypting data according to the hardware national cryptographic algorithm module during the handshake protocol execution within the national cryptographic algorithm protocol framework, the method further includes: The processor sends a client handshake request message to the server, and the client handshake request message contains information on the national cryptographic suites supported by the hardware national cryptographic algorithm module; When the processor receives a server handshake message returned by the server, it verifies the server certificate information in the server handshake message through the certificate processing module. If the server certificate information is verified, the security chip generates a pre-master key based on the SM2 algorithm, and generates a session key based on the pre-master key and the random number generated during the handshake process. The processor establishes an encrypted communication connection based on the session key.
6. The method according to claim 1, characterized in that, The step of establishing an encrypted communication connection based on the session key specifically includes: The processor groups the application layer data into multiple data blocks according to a preset length; The security chip uses the third preset algorithm to encrypt the data block to obtain encrypted data, and uses the second preset algorithm to calculate the integrity check value of the encrypted data; The processor packages the encrypted data and the integrity verification value into a data packet for transmission.
7. The method according to claim 1, characterized in that, Prior to the step of integrating the hardware cryptographic algorithm module of the security chip with the basic protocol framework, the method further includes: The processor configures the operating parameters of the security chip, including the working mode and storage space allocation of the hardware cryptographic algorithm module; The security chip detects the operating status of the hardware cryptographic algorithm module; When the hardware cryptographic algorithm module is operating normally, the processor performs the integration operation between the hardware cryptographic algorithm module and the basic protocol framework.
8. A data encryption system, characterized in that, The data encryption system includes: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the data encryption system to perform the method as described in any one of claims 1-7.
9. A computer-readable storage medium comprising instructions, characterized in that, When the instructions are executed on the data encryption system, the data encryption system performs the method as described in any one of claims 1-7.
10. A computer program product, characterized in that, When the computer program product is run on the data encryption system, the data encryption system performs the method as described in any one of claims 1-7.