An adaptive hardware encryption method, device, computer equipment and medium
By adaptively selecting encryption methods and preprocessing techniques, the problems of low efficiency and insufficient security in existing hardware encryption methods are solved, realizing an efficient encryption process optimized according to data characteristics, and adapting to encryption needs of different data volumes and types.
Patent Information
- Application Number
- CN202411034848.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-07-31
AI Technical Summary
Existing hardware encryption methods cannot adaptively select the appropriate encryption method based on the data to be encrypted, resulting in low encryption efficiency or insufficient security, especially when dealing with large amounts of data, making it difficult to guarantee processing time.
By initializing the microcontroller, loading a standardized encrypted communication protocol, obtaining the characteristics of the data to be encrypted, selecting an appropriate encryption method, preprocessing and filling it, generating metadata, optimizing the encryption process, and executing the encryption operation using the microcontroller's hardware configuration.
It improves the efficiency and security of encryption processing, reduces encryption time, adapts to encryption needs of different data volumes and types, and optimizes the performance of hardware encryption.
Smart Images

Figure CN118643517B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to an adaptive hardware encryption method, device, computer equipment and medium. Background Art
[0002] Existing hardware encryption methods usually perform encryption processing according to the encryption method specified by the customer. However, in many cases, customers do not specify which data encryption method to use to encrypt the data. If the randomly selected encryption method is more complicated, it usually takes a long time to process, affecting the efficiency of data encryption. On the contrary, if the randomly selected encryption algorithm is relatively simple, it will cause the data that originally requires high-level encryption to be cracked, reducing the security of encryption. At the same time, when the amount of data to be encrypted is huge, even hardware encryption can hardly guarantee the encryption processing time. There is an urgent need to automatically select the appropriate hardware encryption algorithm for various situations to improve the efficiency of hardware encryption. Summary of the invention
[0003] In view of this, an embodiment of the present invention provides an adaptive hardware encryption method to solve the technical problem in the prior art that a data encryption method cannot be adaptively selected according to the data to be encrypted. The method includes:
[0004] Initialize the microcontroller used for encryption, load the standardized encryption communication protocol, build a data transmission channel according to the standardized encryption communication protocol, obtain the data to be encrypted and the data characteristics of the data to be encrypted through the data transmission channel, and select a corresponding data encryption method according to the data characteristics, wherein the data characteristics include data sensitivity, data type and data volume;
[0005] Preprocess the data to be encrypted according to the data type and data volume of the data to be encrypted, and divide and fill the data to be encrypted according to the selected data encryption method to generate preprocessed encrypted data, and generate metadata required for encrypting the preprocessed encrypted data according to the selected data encryption method;
[0006] Check the correctness of the metadata. If the metadata is correct, store the metadata in a microcontroller, optimize the encryption process of the selected data encryption method according to the hardware configuration of the microcontroller, and execute the optimized encryption process of the selected data encryption method on the microcontroller according to the metadata to encrypt and / or decrypt the preprocessed encrypted data.
[0007] The embodiment of the present invention also provides an adaptive hardware encryption device to solve the technical problem in the prior art that a data encryption method cannot be adaptively selected according to the data to be encrypted. The device includes:
[0008] An adaptive encryption method selection module is used to initialize the microcontroller used for encryption, load the standardized encryption communication protocol, build a data transmission channel according to the standardized encryption communication protocol, obtain the data to be encrypted and the data characteristics of the data to be encrypted through the data transmission channel, and select a corresponding data encryption method according to the data characteristics, wherein the data characteristics include data sensitivity, data type and data volume;
[0009] A data preprocessing module is used to preprocess the data to be encrypted according to the data type and data volume of the data to be encrypted, and to segment and fill the data to be encrypted according to the selected data encryption method to generate preprocessed encrypted data, and to generate metadata required for encrypting the preprocessed encrypted data according to the selected data encryption method;
[0010] The hardware encryption and decryption module is used to check the correctness of the metadata. If the metadata is correct, the metadata is stored in the microcontroller, the encryption process of the selected data encryption method is optimized according to the hardware configuration of the microcontroller, and the optimized encryption process of the selected data encryption method is executed on the microcontroller according to the metadata to encrypt and / or decrypt the pre-processed encrypted data.
[0011] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned adaptive hardware encryption methods when executing the computer program, so as to solve the technical problem in the prior art that a data encryption method cannot be adaptively selected according to the data to be encrypted.
[0012] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program for executing any of the above-mentioned adaptive hardware encryption methods, so as to solve the technical problem in the prior art that a data encryption method cannot be adaptively selected according to the data to be encrypted.
[0013] Compared with the prior art, the beneficial effects that can be achieved by at least one of the above technical solutions adopted in the embodiments of this specification include at least:
[0014] Selecting different hardware encryption methods according to the data categories of the data to be encrypted is helpful to reduce encryption time and system running time and improve the efficiency of hardware encryption. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0016] Figure 1 is a flow chart of an adaptive hardware encryption method provided by an embodiment of the present invention;
[0017] Figure 2 is a structural block diagram of a computer device provided by an embodiment of the present invention;
[0018] Figure 3 It is a structural block diagram of an adaptive hardware encryption device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0019] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0020] The following describes the implementation methods of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that, in the absence of conflict, the following embodiments and the features in the embodiments can be combined with each other. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work belong to the scope of protection of the present application.
[0021] In an embodiment of the present invention, an adaptive hardware encryption method is provided, such as Figure 1 As shown, the method includes:
[0022] Step S101: Initialize the microcontroller used for encryption, load the standardized encryption communication protocol, build a data transmission channel according to the standardized encryption communication protocol, obtain the data to be encrypted and the data characteristics of the data to be encrypted through the data transmission channel, and select a corresponding data encryption method according to the data characteristics, wherein the data characteristics include data sensitivity, data type and data volume;
[0023] Step S102: preprocessing the data to be encrypted according to the data type and data volume of the data to be encrypted, segmenting and filling the data to be encrypted according to the selected data encryption method, generating preprocessed encrypted data, and generating metadata required for encrypting the preprocessed encrypted data according to the selected data encryption method;
[0024] Step S103: Check the correctness of the metadata. If the metadata is correct, store the metadata in the microcontroller, optimize the encryption process of the selected data encryption method according to the hardware configuration of the microcontroller, and execute the optimized encryption process of the selected data encryption method on the microcontroller according to the metadata to encrypt and / or decrypt the preprocessed encrypted data.
[0025] In the specific implementation, in order to reduce the amount of data processing, improve the efficiency of data encryption, and shorten the time of data encryption by removing invalid information and compressing the data to be encrypted, the following steps are implemented to pre-process the data to be encrypted according to the data type and amount of the data to be encrypted, and to segment and fill the data to be encrypted according to the selected data encryption method to generate pre-processed encrypted data:
[0026] Remove invalid information and information that does not need to be encrypted from the data to be encrypted to generate first processed data; if the data type is stream data, remove repeated or redundant subsets of stream data from the first processed data to generate second processed data; if the data type is text, database record or binary file, obtain the data load set by the microcontroller, if the data volume of the first processed data exceeds the data load, determine the compression algorithm and compression rate through the data load, use the compression algorithm to compress the first processed data according to the compression rate, and generate second processed data; if a cutting block size is set in the data encryption method, divide the second processed data into data encryption blocks of the cutting block size, if the size of the last data encryption block is smaller than the cutting block size, fill the last data encryption block with data until the size of the data encryption block is equal to the cutting block size.
[0027] Specifically, data cleaning removes invalid or irrelevant information from the data to ensure that only the data that needs to be protected is encrypted. Data cleaning reduces the size of the data to be encrypted, reduces the encryption burden, and improves efficiency. According to the requirements of different encryption algorithms, the data to be encrypted is converted into an appropriate format or structure. For example, for block encryption algorithms (such as AES (Advanced Encryption Standard)), the data to be encrypted needs to be divided into fixed-size data blocks.
[0028] If the amount of data to be encrypted is too large, it can be significantly reduced by compression. Evaluate the size and characteristics of the data to be encrypted, determine the potential effect of compression, and select a suitable compression algorithm based on the data type, such as DEFLATE (lossless data compression algorithm), LZ4 (dictionary compression algorithm), LZMA (Lempel-Ziv Markov chain Algorithm, a data compression algorithm, which is an improved and optimized compression algorithm of the LZ77 algorithm), etc. Use the selected compression algorithm to compress the data and generate a compressed data stream. If necessary, use MAC (message authentication code) or digital signature to ensure the integrity of the compressed data.
[0029] In specific implementation, in order to adaptively select a suitable data encryption method according to the data to be encrypted, the following steps are performed to select the corresponding data encryption method according to the data characteristics:
[0030] The data to be encrypted is divided into different sensitivity levels from low to high according to the sensitivity, wherein the sensitivity levels are public data, internal data, sensitive data and confidential data; if the sensitivity level is public data and / or internal data, a lightweight encryption algorithm is used as the corresponding data encryption method, wherein the key length of the lightweight encryption algorithm is less than or equal to 128 bits; if the sensitivity level is sensitive data and / or confidential data, the data type and data volume of the data to be encrypted are obtained, and the corresponding data encryption method is selected according to the data type and data volume of the data to be encrypted.
[0031] In specific implementation, in order to improve the efficiency of encryption without reducing the security of encryption by adaptively selecting the corresponding data encryption algorithm according to the data to be encrypted, the following steps are performed to select the corresponding data encryption method according to the data type and data volume of the data to be encrypted:
[0032] If the data type is text or binary file, compare the data volume with the preset data volume threshold. If the data volume is less than the data volume threshold, use the asymmetric encryption algorithm as the corresponding data encryption method. If the data volume is greater than or equal to the data volume threshold, use the symmetric encryption algorithm as the corresponding data encryption method. If the data type is stream data, compare the data volume with the data volume threshold. If the data volume is less than the data volume threshold, use the stream cipher encryption algorithm as the corresponding data encryption method. If the data volume is greater than or equal to the data volume threshold, use the block encryption algorithm as the corresponding data encryption method, wherein the block encryption algorithm includes the algorithm of the counter mode, the algorithm of the cipher block chaining mode and the algorithm of the Galois counter mode. If the data type is a database record, compare the data volume with the data volume threshold. If the data volume is less than the data volume threshold, use the block encryption algorithm of the authentication encryption mode and / or the symmetric encryption algorithm of the hash-based message authentication code as the corresponding data encryption method. If the data volume is greater than or equal to the data volume threshold, use the transparent data encryption algorithm and / or the attribute-level encryption algorithm as the corresponding data encryption method.
[0033] Specifically, the data to be encrypted is divided into different categories according to the sensitivity (from low to high: public data, internal data, sensitive data and confidential data). For high-risk sensitive data, such as various information related to personal identity information, choose a high-security hardware encryption method (such as AES-256 (256-bit Advanced Encryption Standard) or RSA (asymmetric encryption algorithm)). For low-risk non-sensitive data, use a lighter encryption method, such as AES-128 (128-bit Advanced Encryption Standard) or ChaCha20 (stream cipher encryption algorithm, a type of symmetric key encryption algorithm). In addition, according to the data type of the data to be encrypted (text, files, database records, etc.), choose the most appropriate encryption mode (such as ECB (Electronic Codebook mode), CBC (Cipher Block Chaining mode), CTR (CountTeR mode), GCM (Galois / Counter Mode mode), etc.). For text data, select AES encryption method or ChaCha20 encryption method; for binary data, you can select appropriate symmetric or asymmetric encryption methods as needed. For database records that need to consider data integrity, select an encryption mode for data integrity verification, such as GCM mode (authenticated encryption mode) or use HMAC (key-related hash operation message authentication code) in combination with encrypted data. For database records with large data volumes or that need to be frequently queried for encryption (real-time reading, writing, and real-time modification), use TDE (transparent data encryption method) or attribute-level encryption methods. Determine the size of the data to be encrypted. Asymmetric encryption algorithms can be used for small data volumes, but pay attention to the separation of key exchange and data encryption. Symmetric encryption algorithms can be used for large data volumes because they are generally faster. If high throughput is required, use fast symmetric encryption methods (such as AES-128 (128-bit Advanced Encryption Standard)). For streaming data or real-time communication data, use a stream encryption algorithm such as RC4 (RivestCipher4, a stream encryption algorithm with variable key length) or ChaCha20 (stream cipher encryption algorithm), or choose CTR (counter mode) or GCM (Galois / Counter Mode) mode in AES encryption suitable for streaming media or large blocks of data.
[0034] 1. AES (Advanced Encryption Standard) hardware encryption.
[0035] Divide the plaintext data to be encrypted into 64 / 128 / 192 / 256-byte encrypted data blocks according to the type of encrypted data. Initialize the AES encryption engine and set the parameters used for AES encryption. Set the AES encryption engine corresponding to ESP32 (a microcontroller with integrated WiFi function). Set the key length (128 bits, 192 bits, or 256 bits) and randomly generate the key through the random number generator based on the key length. Set the AES working mode (CBC or CTR). Set the initial vector (IV) required for encryption and transfer the encrypted data block to the encryption hardware (RISC-V architecture (an open source instruction set architecture based on the principle of reduced instruction sets)). Perform encryption or decryption on the encryption hardware and obtain the encrypted or decrypted data from the encryption hardware.
[0036] If the AES working mode is ECB (codebook mode), there is no need to define an initialization vector. Divide the data into fixed-size blocks (the block size of AES is 128 bits), and then encrypt each block independently. The same plaintext block will produce the same ciphertext block. Each data block is encrypted independently, using the formula C = E(k AES , P AES ), where C is the ciphertext, E is the encryption function, and k AES is the key, P AES is a plaintext block.
[0037] If the working mode of AES is CBC (Cipher Block Chaining Mode). CBC mode implements chain encryption by using the ciphertext of the previous block to perform an XOR operation with the plaintext of the current block, ensuring that even the same plaintext block will produce different ciphertext blocks. It is suitable for scenarios that require higher security, such as protecting sensitive data, financial transaction information, etc. A random initialization vector IV is XORed with the first plaintext block. If the data to be encrypted after block division is not an integer multiple of the block size, pad until the last data block is 128 bits in size. Encryption process: First, use the initialization vector IV to perform an XOR operation with the first plaintext block, and then encrypt the result; for each subsequent block, use the encryption result of the previous block to perform an XOR operation with the current plaintext block, and then encrypt it. Decryption process: First, decrypt the ciphertext block, and then XOR it with the ciphertext of the previous block to obtain the original plaintext; the decryption of the first block requires the use of the initialization vector IV.
[0038] If the AES working mode is CTR (Advanced Encryption Standard - Counter Mode), it is suitable for scenarios that require processing large amounts of data or parallel processing.
[0039] If the AES working mode is GCM (Advanced Encryption Standard - Galois / Counter Mode), it is suitable for scenarios that require processing large amounts of data or parallel processing.
[0040] 2. SHA (Secure Hash Algorithm) hardware encryption.
[0041] Initialize the SHA encryption engine. Pad the encrypted data block to a specific length to generate a fixed-size encrypted data block. Initialize the hash calculation to obtain the initialization vector (IV). Divide the data into fixed-size blocks (for example, in SHA-256, 64-byte blocks are processed at a time), and repeat the following steps for each data block: combine the current block with the current hash value, perform a series of logical operations, including bit operations and iterative processing, and update the hash value. Output the final hash value, usually in the form of a hexadecimal string. Hash values can be used to verify data integrity. Incorporate HMAC (hash with message authentication code) or digital signatures into the SHA encryption algorithm to ensure data security and integrity.
[0042] 3. RSA (asymmetric encryption algorithm) hardware encryption.
[0043] Generate a first key pair, a public key encryption exponent e and a private key decryption exponent d. The public key encryption exponent e is coprime with the Euler function φ(n), and the private key decryption exponent d is the modular inverse of the public key encryption exponent e with respect to the modulus φ(n). Convert the data to be encrypted into an integer m. Encrypt using the public key and the public key encryption exponent e. The recipient decrypts using the private key and the private key decryption exponent d. Convert the integer m back into the data to be encrypted. The message can be verified using a digital signature. Specifically, the sender signs the message M or the hash value of the message using the private key, and the sender sends the signature and the message to the recipient.
[0044] 4. ECC (Elliptic curve cryptography) hardware encryption.
[0045] Generate a random number as a private key and a public key (the public key (Q) is a multiple of the base point G and the private key (D)). The sender obtains the public key Q of the receiver. A random number k can be generated for encryption or signing. Key exchange is performed, and both parties calculate the shared key. The calculation method is: shared key shared_key = kQ (Q is the public key of the receiver) or shared_key = DP (D is the private key and P is the public key point of the sender). Combine ECC with a symmetric encryption algorithm to encrypt the message using the shared key. The sender signs the message or the hash value of the message with the private key. The receiver verifies the signature using the sender's public key. If the verification is successful, the message is considered valid. The sender sends the encrypted message and (optional) digital signature to the receiver. The receiver decrypts the message using the shared key and recovers the original data.
[0046] In specific implementation, in order to improve the encryption speed of hardware encryption and optimize the performance by utilizing the computing power, memory capacity, storage capacity and special encryption acceleration function of the microcontroller according to the properties of the microcontroller itself, the encryption process of the selected data encryption method is optimized according to the configuration of the microcontroller through the following steps:
[0047] If the central processing unit of the microcontroller is a multi-core processor, multi-core processing or distributed computing is used to simultaneously execute multiple encryption tasks in the data encryption method, wherein the encryption tasks correspond one-to-one to the divided data blocks in the data to be encrypted; if the central processing unit of the microcontroller supports multi-threading, multi-threading is called to simultaneously execute multiple encryption tasks in the data encryption method; if the microcontroller includes a hardware security module, the key used in the data encryption method is managed through the hardware security module; if the microcontroller supports an encryption instruction set, the corresponding encryption instruction is selected according to the data encryption method, and the encryption instruction is executed to call the data encryption method.
[0048] Specifically, multi-core processors, microcontrollers containing dedicated encryption coprocessors or hardware security modules, and fixed-model microcontrollers with built-in encryption instruction sets can all increase the speed of hardware encryption.
[0049] In some embodiments, the microcontroller selects an ESP32 series low-power microcontroller (the ESP32 series is a low-power microcontroller based on the RISC-V architecture (an open source instruction set architecture based on the principle of reduced instruction set), which has multiple features, including Wi-Fi and Bluetooth functions. A notable feature of the ESP32 series microcontroller is that it supports hardware-accelerated encryption algorithms). The data to be encrypted is connected to the ESP32 module through the high-speed serial port 1 of ESP32, and after the encryption is completed, the data is output through the serial port 2 of ESP32. At startup, it is necessary to initialize the hardware interface and resources (including GPIO (General-purpose input / output), UART1 (Universal Synchronous / Asynchronous Receiver / Transmitter1, the first universal synchronous / asynchronous serial receiver / transmitter), UART2 (Universal Synchronous / Asynchronous Receiver / Transmitter2, the second universal synchronous / asynchronous serial receiver / transmitter), RAM (Random Access Memory).
[0050] In other embodiments, other types of hardware encryption microcontroller modules may also be used, such as STM32H4 series microcontrollers, HC32FA series microcontrollers, etc.
[0051] In specific implementation, in order to improve the correctness of data encryption, the correctness of metadata is checked through the following steps:
[0052] Check whether the existence, format and length of the key meet the definition of the key in the corresponding data encryption method. If not, output the key error information; if the data encryption method needs to split the data block, check whether the size of the data block meets the definition in the data encryption method. If not, output the data block size error information; if the data encryption method includes a public key, determine whether the public key exponent of the public key meets the setting of the data encryption method. If not, output the public key exponent error information; if the data encryption method uses an initial vector, check the randomness and first use of the initial vector. If not, output the initial vector error information; if the data encryption method needs to fill the divided data blocks in the encrypted data, check whether the size of the filled data block meets the setting of the data encryption method. If not, output the filled data block error information.
[0053] In specific implementation, the following steps are performed to add a salt value to the key generated by the data encryption algorithm to increase the security of the key:
[0054] In the key generation process of the data encryption method, a corresponding salt value is randomly generated for each key; the salt value is combined with the key according to the combination rule to generate a key combination, and the key combination is hashed to generate a verification hash value, wherein the combination rule includes direct splicing and interleaved splicing; the verification hash value is saved in a microcontroller, and when executing the data encryption method, the verification hash value is parsed to obtain the key, and the key is used to encrypt the data, and if the key needs to be transmitted, the verification hash value is transmitted.
[0055] Specifically, using salt values in conjunction with keys increases the difficulty of cracking the keys. At the same time, even for the same key, different verification hash values will be generated under different salt values, ensuring the uniqueness of key storage. By using salt values, encryption hardware does not need to store plaintext keys, only salt values and verification hash values.
[0056] In this embodiment, a computer device is provided, such as Figure 2 As shown, it includes a memory 201, a processor 202, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any of the above-mentioned adaptive hardware encryption methods is implemented.
[0057] Specifically, the computer device may be a computer terminal, a server or a similar computing device.
[0058] In this embodiment, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program for executing any of the above-mentioned adaptive hardware encryption methods.
[0059] Specifically, computer-readable storage media include permanent and non-permanent, removable and non-removable media, and information storage can be achieved by any method or technology. Information can be computer-readable instructions, data structures, modules of programs or other data. Examples of computer-readable storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0060] Based on the same inventive concept, an adaptive hardware encryption device is also provided in the embodiment of the present invention, as described in the following embodiment. Since the principle of solving the problem by the adaptive hardware encryption device is similar to that of the adaptive hardware encryption method, the implementation of the adaptive hardware encryption device can refer to the implementation of the adaptive hardware encryption method, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0061] Figure 3 is a structural block diagram of an adaptive hardware encryption device according to an embodiment of the present invention, such as Figure 3 As shown, it includes: an adaptive encryption method selection module 301, a data preprocessing module 302 and a hardware encryption and decryption module 303. The structure is described below.
[0062] The module 301 for adaptively selecting encryption methods is used to initialize the microcontroller used for encryption, load the standardized encryption communication protocol, build a data transmission channel according to the standardized encryption communication protocol, obtain the data to be encrypted and the data characteristics of the data to be encrypted through the data transmission channel, and select the corresponding data encryption method according to the data characteristics, wherein the data characteristics include data sensitivity, data type and data volume;
[0063] The data preprocessing module 302 is used to preprocess the data to be encrypted according to the data type and data volume of the data to be encrypted, and to segment and fill the data to be encrypted according to the selected data encryption method to generate preprocessed encrypted data, and to generate metadata required for encrypting the preprocessed encrypted data according to the selected data encryption method;
[0064] The hardware encryption and decryption module 303 is used to check the correctness of the metadata. If the metadata is correct, the metadata is stored in the microcontroller, the encryption process of the selected data encryption method is optimized according to the hardware configuration of the microcontroller, and the optimized encryption process of the selected data encryption method is executed on the microcontroller according to the metadata to encrypt and / or decrypt the pre-processed encrypted data.
[0065] In one embodiment, the module for adaptively selecting an encryption method includes:
[0066] A sensitivity level acquisition unit, used to classify the data to be encrypted into different sensitivity levels from low to high according to the sensitivity, wherein the sensitivity levels are public data, internal data, sensitive data and confidential data in order;
[0067] A low-sensitivity encryption unit, used to use a lightweight encryption algorithm as a corresponding data encryption method if the sensitivity level is public data and / or internal data, wherein the key length of the lightweight encryption algorithm is less than or equal to 128 bits;
[0068] The second encryption method selection unit is used to obtain the data type and data volume of the data to be encrypted if the sensitivity level is sensitive data and / or confidential data, and select the corresponding data encryption method according to the data type and data volume of the data to be encrypted.
[0069] In one embodiment, the second encryption method selection unit is used to compare the data volume with a preset data volume threshold if the data type is text or binary file, and if the data volume is less than the data volume threshold, use an asymmetric encryption algorithm as the corresponding data encryption method; if the data volume is greater than or equal to the data volume threshold, use a symmetric encryption algorithm as the corresponding data encryption method; if the data type is stream data, compare the data volume with the data volume threshold, and if the data volume is less than the data volume threshold, use a stream cipher encryption algorithm as the corresponding data encryption method; if the data volume is greater than or equal to the data volume threshold, use a block encryption algorithm as the corresponding data encryption method, wherein the block encryption algorithm includes an algorithm in a counter mode, an algorithm in a cipher block chaining mode, and an algorithm in a Galois counter mode; if the data type is a database record, compare the data volume with the data volume threshold, and if the data volume is less than the data volume threshold, use a block encryption algorithm in an authenticated encryption mode and / or a symmetric encryption algorithm based on a hash-based message authentication code as the corresponding data encryption method; if the data volume is greater than or equal to the data volume threshold, use a transparent data encryption algorithm and / or an attribute-level encryption algorithm as the corresponding data encryption method.
[0070] In one embodiment, the data preprocessing module includes:
[0071] Removing invalid information units, used to remove invalid information and information that does not need to be encrypted in the data to be encrypted, and generate first processed data;
[0072] Removing redundant information units, used for removing repeated or redundant subsets of stream data in the first processed data to generate second processed data if the data type is stream data;
[0073] a data compression unit, configured to obtain a data load set by the microcontroller if the data type is text, database record or binary file, determine a compression algorithm and a compression rate by the data load if the data volume of the first processed data exceeds the data load, compress the first processed data by using the compression algorithm according to the compression rate, and generate second processed data;
[0074] A data cutting unit is used to divide the second processed data into data encryption blocks of the cutting block size if a cutting block size is set in the data encryption method, and if the size of the last data encryption block is smaller than the cutting block size, fill the last data encryption block with data until the size of the data encryption block is equal to the cutting block size.
[0075] In one embodiment, the hardware encryption and decryption module includes:
[0076] A multi-core processing unit, used for executing a plurality of encryption tasks in the data encryption method simultaneously by using multi-core processing or distributed computing if the central processing unit of the microcontroller is a multi-core processor, wherein the encryption tasks correspond one to one to the divided data blocks in the data to be encrypted;
[0077] A multi-thread processing unit, used for calling multi-threads to simultaneously execute multiple encryption tasks in the data encryption method if the central processing unit of the microcontroller supports multi-threading;
[0078] A key management unit, for managing keys used in a data encryption method through a hardware security module if the microcontroller includes a hardware security module;
[0079] The encryption instruction set using unit is used to select the corresponding encryption instruction according to the data encryption method if the microcontroller supports the encryption instruction set, and execute the encryption instruction to call the data encryption method.
[0080] In one embodiment, the hardware encryption and decryption module further includes:
[0081] A key checking unit is used to check whether the existence, format and length of the key meet the definition of the key in the corresponding data encryption method. If not, it outputs a key error message;
[0082] A data block checking unit, used for checking whether the size of the data block conforms to the definition in the data encryption method if the data block needs to be cut in the data encryption method, and outputting information that the size of the data block is wrong if it does not conform to the definition in the data encryption method;
[0083] A public key exponent checking unit, for judging whether the public key exponent of the public key satisfies the setting of the data encryption method if the data encryption method includes the public key, and outputting information that the public key exponent is wrong if it does not meet the setting of the data encryption method;
[0084] An initial vector checking unit, used for checking the randomness and first-time use of the initial vector if the initial vector is used in the data encryption method, and outputting information that the initial vector is wrong if the initial vector is not satisfied;
[0085] The data block padding checking unit is used to check whether the size of the data block after padding meets the setting of the data encryption method if the data encryption method needs to pad the divided data blocks in the encrypted data. If not, it outputs the information of padding data block error.
[0086] In one embodiment, the above device further includes: a salt value encryption module.
[0087] In one embodiment, the salt value encryption module includes:
[0088] A salt value generating unit, used to randomly generate a corresponding salt value for each key in the key generation process of the data encryption method;
[0089] A verification hash value generation unit, used for combining the salt value with the key according to a combination rule to generate a key combination, and performing hash processing on the key combination to generate a verification hash value, wherein the combination rule includes direct splicing and interleaved splicing;
[0090] The verification hash value storage unit is used to save the verification hash value in the microcontroller. When executing the data encryption method, the verification hash value is parsed to obtain the key, and the key is used to encrypt the data. If the key needs to be transmitted, the verification hash value is transmitted.
[0091] The embodiments of the present invention achieve the following technical effects:
[0092] Selecting different hardware encryption methods according to different data categories (text, database, binary, etc.) of the data to be encrypted is conducive to reducing encryption processing time and system running time, and improving the efficiency of hardware encryption; compressing the huge amount of data to be encrypted or partially encrypting it according to the actual situation of the data, reducing the number of data operations, improving the efficiency of data encryption, and shortening the time consumed by data encryption; using AES hardware acceleration, SHA hardware acceleration, RSA hardware acceleration, ECC hardware acceleration, and CPU clock speed, RAM execution, cache usage and other factors, the throughput can be optimized. Compared with executing software encryption, the throughput of AES encryption and decryption using hardware encryption accelerators is increased by 8 to 10 times. Improve data security and complete encryption within 10ms.
[0093] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present invention are not limited to any specific combination of hardware and software.
[0094] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An adaptive hardware encryption method, characterized in that: include: Initialize the microcontroller used for encryption, load the standardized encryption communication protocol, build a data transmission channel according to the standardized encryption communication protocol, obtain the data to be encrypted and the data characteristics of the data to be encrypted through the data transmission channel, and select a corresponding data encryption method according to the data characteristics, wherein the data characteristics include data sensitivity, data type and data volume, including: Classifying the data to be encrypted into different sensitivity levels from low to high according to the sensitivity, wherein the sensitivity levels are public data, internal data, sensitive data and confidential data in order; If the sensitivity level is the public data and / or the internal data, a lightweight encryption algorithm is used as the corresponding data encryption method, wherein the key length of the lightweight encryption algorithm is less than or equal to 128 bits; If the sensitivity level is the sensitive data and / or the confidential data, the data type and the data volume of the data to be encrypted are obtained, and a corresponding data encryption method is selected according to the data type and the data volume of the data to be encrypted, including: if the data type is a text or binary file, the data volume is compared with a preset data volume threshold, if the data volume is less than the data volume threshold, an asymmetric encryption algorithm is used as the corresponding data encryption method, if the data volume is greater than or equal to the data volume threshold, a symmetric encryption algorithm is used as the corresponding data encryption method; if the data type is stream data, the data volume is compared with the data volume threshold, if the data volume is less than the data volume threshold, A stream cipher encryption algorithm is used as the corresponding data encryption method. If the data volume is greater than or equal to the data volume threshold, a block encryption algorithm is used as the corresponding data encryption method, wherein the block encryption algorithm includes a counter mode algorithm, a cipher block chaining mode algorithm, and a Galois counter mode algorithm. If the data type is a database record, the data volume is compared with the data volume threshold. If the data volume is less than the data volume threshold, a block encryption algorithm in an authenticated encryption mode and / or a symmetric encryption algorithm based on a hash-based message authentication code is used as the corresponding data encryption method. If the data volume is greater than or equal to the data volume threshold, a transparent data encryption algorithm and / or an attribute-level encryption algorithm is used as the corresponding data encryption method. Preprocessing the data to be encrypted according to the data type and the data amount of the data to be encrypted, dividing and padding the data to be encrypted according to the selected data encryption method to generate preprocessed encrypted data, and generating metadata required for encrypting the preprocessed encrypted data according to the selected data encryption method; Check the correctness of the metadata. If the metadata is correct, store the metadata in the microcontroller. Improve the encryption speed and optimize the performance of the selected data encryption method according to the computing power, memory capacity, storage capacity and encryption acceleration function of the microcontroller. Execute the optimized encryption process of the selected data encryption method on the microcontroller according to the metadata to encrypt and / or decrypt the preprocessed encrypted data.
2. The adaptive hardware encryption method according to claim 1, characterized in that: Preprocessing the data to be encrypted according to the data type and the data amount of the data to be encrypted, and segmenting and padding the data to be encrypted according to the selected data encryption method to generate preprocessed encrypted data, including: Removing invalid information and information that does not need to be encrypted from the data to be encrypted to generate first processed data; If the data type is stream data, removing repeated or redundant stream data subsets in the first processed data to generate second processed data; If the data type is text, database record or binary file, obtaining a data load set by the microcontroller, and if the data volume of the first processed data exceeds the data load, determining a compression algorithm and a compression rate according to the data load, compressing the first processed data using the compression algorithm according to the compression rate to generate second processed data; If a cutting block size is set in the data encryption method, the second processed data is divided into data encryption blocks of the cutting block size. If the size of the last data encryption block is smaller than the cutting block size, data is filled in the last data encryption block until the size of the data encryption block is equal to the cutting block size.
3. The adaptive hardware encryption method according to claim 1, characterized in that: Optimizing the encryption process of the selected data encryption method according to the configuration of the microcontroller, including: If the central processing unit of the microcontroller is a multi-core processor, multiple encryption tasks in the data encryption method are simultaneously executed using multi-core processing or distributed computing, wherein the encryption tasks correspond one-to-one to the divided data blocks in the data to be encrypted; If the central processing unit of the microcontroller supports multi-threading, calling the multi-threading to simultaneously execute multiple encryption tasks in the data encryption method; If the microcontroller includes a hardware security module, the key used in the data encryption method is managed by the hardware security module; If the microcontroller supports an encryption instruction set, a corresponding encryption instruction is selected according to the data encryption method, and the encryption instruction is executed to call the data encryption method.
4. The adaptive hardware encryption method according to any one of claims 1 to 3, characterized in that: Check the correctness of the metadata, including: Check whether the existence, format and length of the key meet the definition of the key in the corresponding data encryption method. If not, output the key error information; If the data encryption method requires data block segmentation, check whether the size of the data block meets the definition in the data encryption method, and if not, output information that the data block size is incorrect; If the data encryption method includes a public key, determining whether a public key exponent of the public key satisfies the setting of the data encryption method, and if not, outputting information that the public key exponent is wrong; If an initial vector is used in the data encryption method, checking the randomness and first-time use of the initial vector, and if not satisfied, outputting information that the initial vector is wrong; If the data encryption method needs to fill the divided data blocks in the data to be encrypted, check whether the size of the filled data block meets the setting of the data encryption method. If not, output the information that the filled data block is wrong.
5. The adaptive hardware encryption method according to any one of claims 1 to 3, characterized in that: Also includes: In the key generation process of the data encryption method, a corresponding salt value is randomly generated for each key; Combining the salt value with the key according to a combination rule to generate a key combination, and performing hash processing on the key combination to generate a verification hash value, wherein the combination rule includes direct splicing and interleaved splicing; The verification hash value is saved in the microcontroller. When executing the data encryption method, the verification hash value is parsed to obtain the key, and the key is used to encrypt data. If the key needs to be transmitted, the verification hash value is transmitted.
6. An adaptive hardware encryption device, characterized in that: include: An adaptive encryption method selection module is used to initialize the microcontroller used for encryption, load the standardized encryption communication protocol, build a data transmission channel according to the standardized encryption communication protocol, obtain the data to be encrypted and the data characteristics of the data to be encrypted through the data transmission channel, and select a corresponding data encryption method according to the data characteristics, wherein the data characteristics include data sensitivity, data type and data volume; Adaptive encryption method selection module, including: A sensitivity level acquisition unit, used to classify the data to be encrypted into different sensitivity levels from low to high according to the sensitivity, wherein the sensitivity levels are public data, internal data, sensitive data and confidential data in order; A low-sensitivity encryption unit, used to use a lightweight encryption algorithm as a corresponding data encryption method if the sensitivity level is public data and / or internal data, wherein the key length of the lightweight encryption algorithm is less than or equal to 128 bits; The second encryption method selection unit is used to obtain the data type and data volume of the data to be encrypted if the sensitivity level is sensitive data and / or confidential data, and select a corresponding data encryption method according to the data type and data volume of the data to be encrypted; The second encryption method selection unit is used to compare the data volume with a preset data volume threshold if the data type is a text or binary file, and if the data volume is less than the data volume threshold, use an asymmetric encryption algorithm as the corresponding data encryption method; if the data volume is greater than or equal to the data volume threshold, use a symmetric encryption algorithm as the corresponding data encryption method; if the data type is stream data, compare the data volume with the data volume threshold, and if the data volume is less than the data volume threshold, use a stream cipher encryption algorithm as the corresponding data encryption method; if the data volume is greater than or equal to the data volume threshold, use a block encryption algorithm as the corresponding data encryption method, wherein the block encryption algorithm includes an algorithm in a counter mode, an algorithm in a cipher block chaining mode, and an algorithm in a Galois counter mode; if the data type is a database record, compare the data volume with the data volume threshold, and if the data volume is less than the data volume threshold, use a block encryption algorithm in an authenticated encryption mode and / or a symmetric encryption algorithm based on a hash-based message authentication code as the corresponding data encryption method; if the data volume is greater than or equal to the data volume threshold, use a transparent data encryption algorithm and / or an attribute-level encryption algorithm as the corresponding data encryption method; A data preprocessing module, used to preprocess the data to be encrypted according to the data type and the data volume of the data to be encrypted, and to segment and fill the data to be encrypted according to the selected data encryption method to generate preprocessed encrypted data, and to generate metadata required for encrypting the preprocessed encrypted data according to the selected data encryption method; A hardware encryption and decryption module is used to check the correctness of the metadata. If the metadata is correct, the metadata is stored in the microcontroller. The encryption speed of the selected data encryption method is improved and the performance is optimized according to the computing power, memory capacity, storage capacity and encryption acceleration function of the microcontroller. The optimized encryption process of the selected data encryption method is executed on the microcontroller according to the metadata to encrypt and / or decrypt the preprocessed encrypted data.
7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the adaptive hardware encryption method according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the adaptive hardware encryption method according to any one of claims 1 to 5.
