A data encryption method, device and readable storage medium

CN116305197BActive Publication Date: 2026-09-08CHENGDU GUOKE MICROELECTRONICS CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202310127449.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-17
Publication Date
2026-09-08
Estimated Expiration
2043-02-17

AI Technical Summary

Technical Problem

[0003]现有技术中,数据加密过程中容易受到旁路攻击,目前常用的抗旁路攻击的数据加密方法为在传输的通道中加入随机掩码,来消除密钥和功耗之间的相关性,但该方法仅在密码算法级别进行防护,且攻击者仅需攻击该类方案一条路线上的多点,即可破解信息,因此安全性较低

Benefits of technology

[0051] The data encryption device and computer-readable storage medium provided in this application correspond to the data encryption method described above and have the same beneficial effects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116305197B_ABST
    Figure CN116305197B_ABST
Patent Text Reader

Abstract

The application discloses a data encryption method and device and a readable storage medium, and relates to the field of information security. The data encryption method provided by the application generates multiple selection possibilities through multiple paths, prevents bypass attacks, and obtains input data of the next round of the first path through mask operation of output data of each round of the first path, output data of each round of the second path, and corresponding random plaintext mask and random key mask of the next round. The first path is always protected by a mask during the operation process, and different random masks are introduced in each operation to resist high-order side channel attacks. Attackers cannot crack the key by attacking the value of the intermediate point in the operation, and the correct output result is obtained by exclusive OR of the output results of the two paths. Even if the attacker obtains the output result of one path, the information in the password operation cannot be cracked, and the security of the data is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information security, and in particular to a data encryption method, apparatus and readable storage medium. Background Technology

[0002] With the development of information technology, information security is receiving increasing attention, and the requirements for the security of data storage and transmission are becoming increasingly stringent.

[0003] In existing technologies, data encryption is vulnerable to side-channel attacks. Currently, the commonly used data encryption method to resist side-channel attacks is to add a random mask to the transmission channel to eliminate the correlation between the key and power consumption. However, this method only provides protection at the cryptographic algorithm level, and attackers only need to attack multiple points on one route of this type of scheme to crack the information, so the security is low.

[0004] Given the above-mentioned technologies, finding a highly secure data encryption method is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0005] The purpose of this application is to provide a data encryption method, apparatus, and readable storage medium to address the problem that commonly used data encryption methods for resisting side-channel attacks involve adding a random mask to the transmission channel to eliminate the correlation between the key and power consumption. However, this method only provides protection at the cryptographic algorithm level, and attackers only need to attack multiple points on one route of this type of scheme to crack the information, thus resulting in low security.

[0006] To address the aforementioned technical problems, this application provides a data encryption method applied to a data encryption device. The data encryption device includes at least three block cipher algorithm paths. The block cipher algorithm is a multi-round iterative encryption algorithm, including:

[0007] Obtain the random plaintext mask and random key mask for each round;

[0008] The first mask plaintext is obtained by XORing the original plaintext with the first round of random plaintext mask, and the first mask key is obtained by XORing the original key with the first round of random key mask.

[0009] Randomly select a path as the first path, and use the first mask plaintext and the first mask key as the input data of the first path to perform the first round of encryption operation;

[0010] Choose any path other than the first path as the second path, and use the random plaintext mask and random key mask of each round as the input data of each round of the second path for encryption operation.

[0011] The output data of each round of the second path and the corresponding random plaintext mask and random key mask for the next round are used to perform a masking operation on the output data of each round of the first path. The result of the masking operation is used as the input data of the first path for the next round.

[0012] The first ciphertext and the first key output by the first channel are XORed with the second ciphertext and the second key output by the second channel to obtain the plaintext encryption result and the key encryption result.

[0013] As a preferred embodiment, in the above data encryption method, the output data of each round of the second path and the corresponding random plaintext mask and random key mask of the next round are used to perform a masking operation on the output data of each round of the first path. The masking operation result is used as the input data of the next round of the first path, including:

[0014] The output of each round of the first path is XORed with the random plaintext mask and random key mask of the next round to obtain the first XOR result.

[0015] Perform an XOR operation between the first XOR result and the corresponding output of the second path to obtain the second XOR result. Use the second XOR result as the input data for the next round of the first path.

[0016] As a preferred embodiment, in the above data encryption method, after the first channel outputs the first ciphertext and the first key, and the second channel outputs the second ciphertext and the second key, the method further includes:

[0017] Choose any two paths other than the first and second paths as the third and fourth paths. Use the first ciphertext and the first key as input data for the third path to perform decryption operations, and use the second ciphertext and the second key as input data for the fourth path to perform decryption operations.

[0018] The decryption result of the third path is XORed with the decryption result of the fourth path to obtain the plaintext and the key for verification.

[0019] Determine whether the plaintext matches the original plaintext;

[0020] If they match, it is determined that there is no error injection;

[0021] If there is a discrepancy, it is determined that there is an error injection.

[0022] As a preferred embodiment, the above data encryption method further includes, before performing the first round of encryption operations using the first mask plaintext and the first mask key as input data for the first path:

[0023] Obtain the first random data set as input data for the first path and perform pseudo-operations;

[0024] After the first path finishes its pseudo-operation, it proceeds to the step of performing the first round of encryption operation using the first mask plaintext and the first mask key as input data for the first path.

[0025] As a preferred embodiment, in the above data encryption method, before using the random plaintext mask and random key mask of each round as the input data of each round of the second path for the corresponding round of encryption operation, the method further includes:

[0026] Obtain the second random data set as input data for the second path and perform pseudo-operations;

[0027] After the second path finishes its pseudo-operation, it proceeds to the step of using the random plaintext mask and random key mask of each round as the input data for each round of the second path to perform the corresponding round of encryption operation.

[0028] As a preferred embodiment, the above data encryption method involves obtaining the random plaintext mask and random key mask for each round, including:

[0029] Obtain the first initial mask, the second initial mask, the first preset random number generation algorithm, and the second preset random number generation algorithm;

[0030] Each round of random plaintext mask is obtained based on the first preset random number generation algorithm and the first initial mask;

[0031] The random key mask for each round is obtained based on the second preset random number generation algorithm and the second initial mask.

[0032] As a preferred embodiment, the above data encryption method further includes, before obtaining the random plaintext mask and random key mask for each round:

[0033] Determine if the current operation state is in safe mode;

[0034] If so, proceed to the step of obtaining the random plaintext mask and random key mask for each round;

[0035] If not, then any idle path is selected to perform encryption operations on the original plaintext and the original key as input data, and the corresponding output result is obtained.

[0036] As a preferred option, the above data encryption method also includes:

[0037] Determine whether the first round of encryption operations for both the first and second paths has ended;

[0038] If so, the first and second paths will proceed to the next round of encryption operations;

[0039] If not, save the output of the first round of encryption operation of the path that has completed the first round of encryption operation, and perform a random pseudo-operation until the first round of encryption operation of the other path is completed.

[0040] To address the aforementioned technical problems, this application also provides a data encryption device applied to a data encryption equipment. The data encryption equipment includes at least three block cipher algorithm paths, and the block cipher algorithm is a multi-round iterative encryption algorithm, including:

[0041] The random mask acquisition module is used to obtain the random plaintext mask and random key mask for each round;

[0042] The original data XOR module is used to obtain the first mask plaintext by XORing the original plaintext with the random plaintext mask, and to obtain the first mask key by XORing the original key with the random key mask;

[0043] The first processing module is used to randomly select a path as the first path and use the first mask plaintext and the first mask key as input data of the first path to perform the first round of encryption operation.

[0044] The second operation module is used to select any path other than the first path as the second path, and to use the random plaintext mask and random key mask of each round as the input data of each round of the second path for encryption operation of the corresponding round.

[0045] The third operation module is used to perform a mask operation on the output data of each round of the second path and the corresponding random plaintext mask and random key mask of the next round on the output data of each round of the first path. The result of the mask operation is used as the input data of the first path in the next round.

[0046] The output module is used to perform XOR operations on the first ciphertext and the first key finally output by the first channel with the second ciphertext and the second key finally output by the second channel to obtain the plaintext encryption result and the key encryption result.

[0047] To address the aforementioned technical problems, this application also provides a data encryption device, including a memory for storing computer programs;

[0048] A processor is used to implement the above-described data encryption method when executing a computer program.

[0049] To address the aforementioned technical problems, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the aforementioned data encryption method.

[0050] The data encryption method provided in this application is applied to a data encryption device. The data encryption device includes at least three block cipher algorithm paths. The block cipher algorithm is a multi-round iterative encryption algorithm, including: obtaining a random plaintext mask and a random key mask for each round; XORing the original plaintext with the first round random plaintext mask to obtain a first mask plaintext, and XORing the original key with the first round random key mask to obtain a first mask key; randomly selecting a path as the first path, and using the first mask plaintext and the first mask key as input data for the first path to perform a first round of encryption operation; selecting any path other than the first path as the second path, and using the random plaintext mask and random key mask for each round as corresponding input data for each round of the second path to perform encryption operation; performing a mask operation on the output data of each round of the second path and the corresponding random plaintext mask and random key mask for the next round on the output data of each round of the first path, and using the mask operation result as the input data for the next round of the first path; and performing an XOR operation on the first ciphertext and the first key finally output by the first path with the second ciphertext and the second key finally output by the second path to obtain the plaintext encryption result and the key encryption result. By setting up multiple pathways and creating various possible choices, the attack difficulty is increased from the attack chain, making it impossible for attackers to accurately locate the specific channel through which information is transmitted, thus preventing side-channel attacks and enhancing data security. Furthermore, different random masks are introduced in each round of operation to resist high-order side-channel attacks. The correct output result is obtained by XORing the output results of the two pathways; even if an attacker obtains the output result of one pathway, they cannot crack the information in the cryptographic operation.

[0051] The data encryption device and computer-readable storage medium provided in this application correspond to the data encryption method described above and have the same beneficial effects. Attached Figure Description

[0052] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0053] Figure 1 A flowchart illustrating a data encryption method provided in this application embodiment;

[0054] Figure 2 This is a schematic diagram illustrating the application of a 4-channel data encryption method provided in an embodiment of this application.

[0055] Figure 3 A schematic diagram of a data encryption device provided in an embodiment of this application;

[0056] Figure 4This is a structural diagram of a data encryption device provided in another embodiment of this application. Detailed Implementation

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

[0058] The core of this application is to provide a data encryption method, apparatus, and readable storage medium to solve the problem that current encryption algorithms, which only provide protection at the cryptographic algorithm level, are inherently insecure because attackers only need to attack multiple points along a single path to crack the information.

[0059] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0060] Figure 1 This application provides a flowchart of a data encryption method, applied to a data encryption device. The data encryption device includes at least three block cipher algorithm paths. The block cipher algorithm is a multi-round iterative encryption algorithm, such as... Figure 1 As shown, it includes:

[0061] S11: Obtain the random plaintext mask and random key mask for each round;

[0062] This embodiment is based on a multi-round iterative encryption algorithm. If it is a 32-round encryption algorithm, then 32 sets of random plaintext masks and random key masks are required. If it is a 64-round encryption algorithm, then 64 sets of random plaintext masks and random key masks are required. The settings can be adjusted according to actual needs.

[0063] Furthermore, this embodiment does not limit the generation method of the random plaintext mask and the random key mask. They can be generated by a random number generator or generated according to preset rules. In addition, this embodiment does not limit the specific number of bits and data types of the random plaintext mask and the random key mask. They can be set according to actual needs.

[0064] This embodiment does not limit the specific block cipher algorithm, such as the Advanced Encryption Standard (AES) algorithm, the Data Encryption Standard (DES) algorithm, the SM4 block cipher algorithm, etc. The SM4 algorithm is a commercial cryptographic standard in my country, and its predecessor was the SMS4 algorithm. The SM4 algorithm is a block cipher algorithm with a block length and key length of 128 bits. The SM4 algorithm uses a 32-round non-linear iterative structure. After the last round of non-linear iteration, SM4 adds a reversal transformation; therefore, in SM4, as long as the decryption key is the reverse of the encryption key, its decryption algorithm can be consistent with the encryption algorithm.

[0065] S12: Obtain the first mask plaintext by XORing the original plaintext with the first round of random plaintext mask, and obtain the first mask key by XORing the original key with the first round of random key mask;

[0066] S13: Randomly select a path as the first path, and use the first mask plaintext and the first mask key as the input data of the first path to perform the first round of encryption operation;

[0067] In this embodiment, the original plaintext and original key are used as raw data. They are XORed with the first round of random plaintext mask and random key mask, respectively, and then used as the input data of the first path for the first round of encryption operation.

[0068] In this embodiment, there are at least 3 block encryption algorithm paths. One path is randomly selected as the first path, and any path other than the first path is selected as the second path. This includes at least 3 possible choices. The more paths included, the more choices are generated, which increases the difficulty of the attacker's attack from the attack chain.

[0069] S14: Select any path other than the first path as the second path, and use the random plaintext mask and random key mask of each round as the input data of each round of the second path for encryption operation of the corresponding round.

[0070] Each round of random plaintext mask and random key mask is used as the input data for each round of the second path for encryption operations. That is, each set of random plaintext mask and random key mask is used as the input data for each round of the second path for encryption operations.

[0071] S15: Perform a masking operation on the output data of each round of the second path and the corresponding random plaintext mask and random key mask of the next round on the output data of each round of the first path. The result of the masking operation is used as the input data of the next round of the first path.

[0072] Unlike the second-path operation, the first path, except for the first round of encryption which uses the first mask plaintext and the first mask key as input data, requires further masking operations on the input data of each subsequent round of encryption. Specifically, the output data of each round of the first path is further masked using the corresponding random plaintext mask and random key mask for the next round, along with the output data of each round of the second path. The result of this masking operation is then used as the input data for the next round of the first path. Through these masking operations, different random masks are introduced in each round to resist high-order side-channel attacks. The first path is always protected by a mask during the operation, preventing attackers from cracking the key by attacking values ​​at intermediate points in the operation.

[0073] In a specific embodiment, the output data of each round of the second path, along with the corresponding random plaintext mask and random key mask for the next round, are used to perform a masking operation on the output data of each round of the first path. The result of the masking operation is used as the input data for the next round of the first path, including:

[0074] The output of each round of the first path is XORed with the random plaintext mask and random key mask of the next round to obtain the first XOR result.

[0075] The first XOR result is XORed with the corresponding output of the second path to obtain the second XOR result, which is then used as the input data for the next round of the first path.

[0076] In this embodiment, the output of the first path in each round is first XORed with the random plaintext mask and random key mask of the next round, and then XORed with the corresponding output of the second path. The result is then used as the input data for the next round of the first path. For example, the output of the first path in the first round is first XORed with the second set of random plaintext masks and random key masks, and then XORed with the output data of the second path respectively. The result is used as the input data for the second round of the first path. Each round of the first path introduces random plaintext masks, random key masks, and the output data of the second path as masks to resist high-order side-channel attacks.

[0077] S16: The first ciphertext and the first key output by the first channel are XORed with the second ciphertext and the second key output by the second channel to obtain the plaintext encryption result and the key encryption result.

[0078] The output data of the first and second channels are XORed accordingly to obtain the final plaintext encryption result and the key encryption result.

[0079] The data encryption method provided in this application is applied to a data encryption device. The data encryption device includes at least three block cipher algorithm paths. The block cipher algorithm is a multi-round iterative encryption algorithm, including: obtaining a random plaintext mask and a random key mask for each round; XORing the original plaintext with the first round random plaintext mask to obtain a first mask plaintext, and XORing the original key with the first round random key mask to obtain a first mask key; randomly selecting a path as a first path, and using the first mask plaintext and the first mask key as input data for the first path to perform a first round of encryption operation; selecting any path other than the first path as a second path, and using the random plaintext mask and random key mask for each round as corresponding input data for each round of the second path to perform encryption operation; performing a mask operation on the output data of each round of the second path and the corresponding random plaintext mask and random key mask for the next round on the output data of each round of the first path, and using the mask operation result as the input data for the next round of the first path; and performing an XOR operation on the first ciphertext and the first key finally output by the first path with the second ciphertext and the second key finally output by the second path to obtain a plaintext encryption result and a key encryption result. By setting up multiple pathways and creating various possible choices, the attack difficulty is increased from the attack chain, making it impossible for attackers to accurately locate the specific channel through which information is transmitted, thus preventing side-channel attacks and enhancing data security. Furthermore, different random masks are introduced in each round of operation to resist high-order side-channel attacks. The correct output result is obtained by XORing the output results of the two pathways; even if an attacker obtains the output result of one pathway, they cannot crack the information in the cryptographic operation.

[0080] According to the above embodiments, in order to verify whether the cryptographic algorithm is susceptible to error injection, this embodiment provides a preferred solution: after the first channel outputs the first ciphertext and the first key, and the second channel outputs the second ciphertext and the second key, the following further step is taken:

[0081] Choose any two paths other than the first and second paths as the third and fourth paths. Use the first ciphertext and the first key as input data for the third path to perform decryption operations, and use the second ciphertext and the second key as input data for the fourth path to perform decryption operations.

[0082] The decryption result of the third path is XORed with the decryption result of the fourth path to obtain the plaintext and the key for verification.

[0083] Determine whether the plaintext matches the original plaintext;

[0084] If they match, it is determined that there is no error injection;

[0085] If there is a discrepancy, it is determined that there is an error injection.

[0086] In this embodiment, at least four paths are included. Any two paths other than the first and second paths are selected as the third and fourth paths. After the first path outputs the first ciphertext and the first key, and the second path outputs the second ciphertext and the second key, the first ciphertext and the first key are used as input data for the third path for decryption. The second ciphertext and the second key are used as input data for the fourth path for decryption. The decryption results of the third and fourth paths are XORed to obtain the verification plaintext and the verification key. If the verification plaintext matches the original plaintext, there is no error injection; otherwise, there is error injection. The scheme provided in this embodiment can verify whether the cryptographic algorithm has error injection. In addition, for attackers, the operation steps of operation three and operation four are the same as those of operation one and operation two, and their input data are incorrect plaintext and key (no masking is involved in the operation). These two paths can obfuscate the correct output, increasing the difficulty of the attack.

[0087] To resist timing attacks, this embodiment provides a preferred solution, which further includes the following step before performing the first round of encryption operations on the first mask plaintext and the first mask key as input data for the first path:

[0088] Obtain the first random data set as input data for the first path and perform pseudo-operations;

[0089] After the first path finishes the pseudo-operation, the first step is to use the first mask plaintext and the first mask key as input data for the first path to perform the first round of encryption operation.

[0090] In addition, before using the random plaintext mask and random key mask of each round as the input data for each round of the second path for the corresponding round of encryption operation, the following steps are also included:

[0091] Obtain the second random data set as input data for the second path and perform pseudo-operations;

[0092] After the second path finishes its pseudo-operation, it proceeds to the step of using the random plaintext mask and random key mask of each round as the input data for each round of the second path to perform the corresponding round of encryption operation.

[0093] In this embodiment, before the first round of operations in the first and second paths, a random data set is obtained and pseudo-operations are performed to make the output time of the cryptographic algorithm random, thus resisting timing attacks. It should be noted that the first and second random data sets can be the same or different, and the output results of the pseudo-operations are not saved.

[0094] According to the above embodiments, the random plaintext mask and random key mask for each round can be generated by a random number generator. To reduce the resource consumption of the random number generator, this embodiment provides a preferred solution for obtaining the random plaintext mask and random key mask for each round, including:

[0095] Obtain the first initial mask, the second initial mask, the first preset random number generation algorithm, and the second preset random number generation algorithm;

[0096] Each round of random plaintext mask is obtained based on the first preset random number generation algorithm and the first initial mask;

[0097] The random key mask for each round is obtained based on the second preset random number generation algorithm and the second initial mask.

[0098] It should be noted that the first initial mask and the second initial mask can be the same or different. The operation rules of the first preset random number generation algorithm and the second preset random number generation algorithm can be the same or different, but they cannot be the same at the same time.

[0099] Each round of random plaintext mask is obtained according to the first preset random number generation algorithm and the first initial mask. The operation rules of the first preset random number generation algorithm can be used to operate on the first initial mask according to the current round number to generate each round of random plaintext mask. Similarly, each round of random key mask is obtained according to the second preset random number generation algorithm and the second initial mask, which can also be related to the current round number to generate the corresponding random key mask.

[0100] This embodiment generates a random plaintext mask and a random key mask using a random number generation algorithm, which avoids the need for a random number generator module in cryptographic operations and reduces resource consumption.

[0101] This embodiment provides a specific example of random number generation:

[0102] (1) Given a 128-bit random mask value X; (In this embodiment, the first initial mask and the second initial mask are the same, both being X)

[0103] (2) Set the random plaintext mask to Y i Taking the first round of random plaintext mask Y1 as an example, the calculation steps are as follows:

[0104] a) Represent X⊕(X<<1) as A;

[0105] b) Represent A⊕(A<<2) as B;

[0106] c) Represent B⊕(B<<3) as C;

[0107] d) Represent C mod 512 as D;

[0108] e) representing D⊕B[15:0] as Y1;

[0109] (3) The generation method of random plaintext masks for other rounds of the cryptographic algorithm is similar to that in step (2), except that the number of bits for the cyclic left shift is different. The number of bits for the cyclic left shift is related to the current round number. If the current round is the i-th round, step (2) can be replaced with:

[0110] a) representing X⊕(X<<i) as A;

[0111] b) representing A⊕(A<<2i) as B;

[0112] c) representing B⊕(B<<3i) as C;

[0113] d) representing C mod 512 as D;

[0114] e) representing D⊕B[15:0] as Y i ;

[0115] (4) setting the random plaintext mask as Z i , which differs from Y i as follows:

[0116] representing X⊕(X>>(1+i)) as a;

[0117] representing a⊕(a>>(2+i)) as b;

[0118] representing b⊕(b>>(3+i)) as c;

[0119] representing c mod 512 as d;

[0120] representing d⊕b[127:112] as Zi;

[0121] According to the above embodiment, this embodiment provides a preferred solution, before acquiring the random plaintext mask and random key mask of each round, the method further comprises:

[0122] determining whether the current operation state is a security mode;

[0123] if yes, proceeding to the step of acquiring the random plaintext mask and random key mask of each round;

[0124] if not, arbitrarily selecting an idle path to perform encryption operation with the original plaintext and original key as input data, and obtaining a corresponding output result.

[0125] Users can set the operation status according to their actual needs. The operation status includes secure mode and non-secure mode. In secure mode, the data security requirements are higher, so a more secure encryption operation method needs to be selected. In non-secure mode, the data security requirements are lower, so a less secure encryption operation method can be selected. The specific choice can be made according to the actual needs.

[0126] If set to secure mode, the process proceeds to obtain the random plaintext mask and random key mask for each round, and then executes steps S11-S16 for encryption. If set to insecure mode, an idle path is arbitrarily selected, and the original plaintext and original key are used as input data for encryption. All paths operate in parallel, greatly improving the processing speed.

[0127] According to the above embodiments, since a pseudo-operation is added before the encryption operation, the number of pseudo-operation rounds may be different, resulting in different times for the first round output result. Furthermore, the method of this embodiment also includes:

[0128] Determine whether the first round of encryption operations for both the first and second paths has ended;

[0129] If so, the first and second paths will proceed to the next round of encryption operations;

[0130] If not, save the output of the first round of encryption operation of the path that has completed the first round of encryption operation, and perform a random pseudo-operation until the first round of encryption operation of the other path is completed.

[0131] In a specific embodiment, an output flag bit can be configured for each channel. After the first round of encryption operations of the first channel and the second channel are completed, the corresponding output flag bit is pulled high. Determining whether the first round of encryption operations of the first channel and the second channel are both completed includes: determining whether the first round output flag bits of the first channel and the second channel are both pulled high.

[0132] Specifically, after the first or second path completes its first round of computation, it raises the corresponding output flag. If the corresponding output flag of the other path is not raised, the output result of the first round of computation for this path is saved, and a random pseudo-operation round is performed after the first round of computation for this path until the output flag of the other path is raised. The output result of the random pseudo-operation round is not saved.

[0133] To enable those skilled in the art to better understand this solution, a specific application embodiment is provided below. Figure 2 This is a schematic diagram illustrating the application of a 4-channel data encryption method provided in an embodiment of this application, such as... Figure 2As shown, a selector is set to choose the cryptographic operation state as Mode0 or Mode1. Mode0 represents the secure mode, and Mode1 represents the insecure mode. Plaintext 0, plaintext m, and plaintext n represent the original plaintext; key 0, key m, and key n represent the original key; mask represents the random plaintext mask; MASK represents the random key mask; ciphertext 1 represents the first ciphertext; key 1 represents the first key; ciphertext 2 represents the second ciphertext; and key 2 represents the second key.

[0134] If Mode1 is selected, any path can be directly selected to start the first round of operation with the original plaintext and the original key. Taking the third path as an example, plaintext m and key m are directly input as the original plaintext and the original key. All four paths can be selected for encryption operation. The operation process can be parallelized, and the operation efficiency is improved.

[0135] If Mode0 is selected, the first path begins pseudo-operation with the first random data group, and the second path begins pseudo-operation with the second random data group. After the pseudo-operation, plaintext 0 is XORed with mask0 as the plaintext input data for the first round of the first path, and key 0 is ORed with mask0 as the key input data for the first round of the first path, thus starting the first round of operation for the first path. Mask0 is used as the plaintext input data for the first round of the second path, and key 0 is used as the key input data for the first round of the second path, thus starting the first round of operation for the second path. After the first round of operation for the first path is completed, the output flag 1 is pulled high. After the first round of operation for the second path is completed, the output flag 2 is pulled high. If Flag2 is high and Flag1 is low, it indicates that operation two has completed the first round of operation one. The output result of the first round of operation two is then saved, and a random pseudo-operation round is added after the first round of operation for the second path. It continuously checks whether Flag1 is high. If it is, the next operation is performed; otherwise, the operation of the random pseudo-operation round continues until Flag1 is also high. The output result of the random pseudo-operation round is not saved.

[0136] After the first round of cryptographic operations, mask1 and MASK1 are first XORed with the first round output of the first channel, and then XORed with the first round output of the second channel. The final data is used as the input data for the second round of operations of the first channel; random masks mask1 and MASK1 are used as the input data for the second round of operations of the second channel.

[0137] After multiple rounds of iterative operations on the first and second paths are completed, the outputs of the first and second paths are XORed to obtain the plaintext encryption result and the key encryption result.

[0138] The ciphertext 1 and key 1 output from the first path are used as inputs to the third path; the ciphertext 2 and key 2 output from the second path are used as inputs to the fourth path. The corresponding decryption operations are performed on the third and fourth paths respectively. The decryption results from the third and fourth paths are XORed, and the XOR result is compared with the plaintext 0 of operation 1. If they match, it proves that there is no error injection in the cryptographic operation; if they do not match, it indicates that there is error injection in the cryptographic operation.

[0139] In the above embodiments, the data encryption method has been described in detail. This application also provides embodiments corresponding to the data encryption device. It should be noted that this application describes the embodiments of the device part from two perspectives: one is based on the functional module, and the other is based on the hardware.

[0140] From the perspective of functional modules Figure 3 This application provides a schematic diagram of a data encryption device, which includes:

[0141] The random mask acquisition module 31 is used to acquire the random plaintext mask and random key mask for each round;

[0142] The original data XOR module 32 is used to obtain the first mask plaintext by XORing the original plaintext with the random plaintext mask, and to obtain the first mask key by XORing the original key with the random key mask;

[0143] The first operation module 33 is used to randomly select a path as the first path and use the first mask plaintext and the first mask key as input data of the first path to perform the first round of encryption operation.

[0144] The second operation module 34 is used to select any path other than the first path as the second path, and to use the random plaintext mask and random key mask of each round as the input data of each round of the second path for encryption operation of the corresponding round.

[0145] The third operation module 35 is used to perform a mask operation on the output data of each round of the second path and the random plaintext mask and random key mask corresponding to the next round on the output data of each round of the first path, and the mask operation result is used as the input data of the next round of the first path.

[0146] The output module 36 is used to perform XOR operations on the first ciphertext and the first key finally output by the first channel with the second ciphertext and the second key finally output by the second channel to obtain the plaintext encryption result and the key encryption result.

[0147] The data encryption device provided in this application increases the difficulty for attackers by setting up multiple channels for encryption operations, generating various possible choices and making it impossible to accurately locate the specific encryption operation channel. This prevents side-channel attacks and enhances the security of encrypted data transmission. Furthermore, different random masks are introduced in each round of operation to resist high-order side-channel attacks. The correct output result is obtained by XORing the output results of the two channels; even if an attacker obtains the output result of one channel, they cannot crack the information in the cryptographic operation.

[0148] In addition, the device also includes:

[0149] The third operation module 35 includes a first XOR subunit, which is used to perform an XOR operation on the output result of each round of the first path with the random plaintext mask and the random key mask corresponding to the next round to obtain the first XOR result.

[0150] The second XOR subunit is used to perform an XOR operation between the first XOR result and the corresponding output result of the second path to obtain the second XOR result, and use the second XOR result as the input data for the next round of the first path.

[0151] The random selection module is used to select any two paths other than the first and second paths as the third and fourth paths, and to perform decryption operations by using the first ciphertext and the first key as input data for the third path, and to perform decryption operations by using the second ciphertext and the second key as input data for the fourth path.

[0152] The verification operation module is used to perform an XOR operation on the decryption result of the third channel and the decryption result of the fourth channel to obtain the verification plaintext and the verification key.

[0153] The first judgment module is used to determine whether the plaintext being checked is consistent with the original plaintext.

[0154] If they match, the correct module is triggered to determine if there is no error injection.

[0155] If there is a discrepancy, an error module is triggered to determine if there is an error injection.

[0156] The first pseudo-operation module is used to obtain the first random data group as input data for the first path and perform pseudo-operations.

[0157] After the first path finishes its pseudo-operation, the first operation module is triggered;

[0158] The first pseudo-operation module is used to obtain the second random data set as input data for the second path and perform pseudo-operations.

[0159] When the second path finishes the pseudo-operation, the second operation module is triggered.

[0160] The random mask acquisition module includes: a raw data acquisition subunit, used to acquire a first initial mask, a second initial mask, a first preset random number generation algorithm, and a second preset random number generation algorithm;

[0161] The plaintext mask generation subunit is used to obtain a random plaintext mask for each round based on the first preset random number generation algorithm and the first initial mask;

[0162] The key mask generation subunit is used to obtain a random key mask for each round based on the second preset random number generation algorithm and the second initial mask.

[0163] The second judgment module is used to determine whether the current operation state is in safe mode;

[0164] If so, trigger the random mask acquisition module;

[0165] If not, the insecure encryption module is triggered, which arbitrarily selects an idle path to perform encryption operations on the original plaintext and the original key as input data, and obtains the corresponding output result.

[0166] The third judgment module is used to determine whether the first round of encryption operations for the first and second paths have both ended;

[0167] If so, the second and third operation modules are triggered, and the first and second paths enter the next round of encryption operation;

[0168] If not, the random operation module is triggered to save the output of the first round of encryption operation of the path that has completed the first round of encryption operation, and to perform random pseudo-operations until the first round of encryption operation of the other path is completed.

[0169] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.

[0170] Figure 4 A structural diagram of a data encryption device provided in another embodiment of this application is shown below. Figure 4 As shown, the data encryption device includes: a memory 40 for storing computer programs;

[0171] The processor 41 is used to implement the steps of the data encryption method mentioned in the above embodiments when executing a computer program.

[0172] The data encryption device provided in this embodiment may include, but is not limited to, smartphones, tablets, laptops, or desktop computers.

[0173] The processor 41 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 41 may be implemented using at least one hardware form selected from Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor 41 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 41 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 41 may also include an Artificial Intelligence (AI) processor, which handles computational operations related to machine learning.

[0174] The memory 40 may include one or more computer-readable storage media, which may be non-transitory. The memory 40 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 40 is used to store at least the following computer program 401, which, after being loaded and executed by the processor 41, is capable of implementing the relevant steps of the data encryption method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 40 may also include an operating system 402 and data 403, and the storage method may be temporary or permanent storage. The operating system 402 may include Windows, Unix, Linux, etc. The data 403 may include, but is not limited to, the data involved in the data encryption method.

[0175] In some embodiments, the data encryption device may further include a display screen 42, an input / output interface 43, a communication interface 44, a power supply 45, and a communication bus 46.

[0176] Those skilled in the art will understand that Figure 4 The structure shown does not constitute a limitation on the data encryption device and may include more or fewer components than illustrated.

[0177] The data encryption device provided in this application includes a memory and a processor. When the processor executes a program stored in the memory, it can implement the following method: a data encryption method applied to a data encryption device. The data encryption device includes at least three block cipher algorithm paths. The block cipher algorithm is a multi-round iterative encryption algorithm, including: obtaining a random plaintext mask and a random key mask for each round; XORing the original plaintext with the first round random plaintext mask to obtain a first mask plaintext, and XORing the original key with the first round random key mask to obtain a first mask key; randomly selecting a path as a first path, and using the first mask plaintext and the first mask key as the first path. The input data undergoes a first round of encryption. Then, any path other than the first path is selected as the second path. Each round's random plaintext mask and random key mask are used as the input data for each round of encryption in the second path. The output data of each round in the second path, along with the corresponding random plaintext mask and random key mask for the next round, are used to perform a masking operation on the output data of each round in the first path. The result of this masking operation is used as the input data for the next round in the first path. Finally, the first ciphertext and first key output by the first path are XORed with the second ciphertext and second key output by the second path to obtain the plaintext encryption result and the key encryption result. By setting multiple paths, various possible choices are generated, increasing the difficulty for attackers in the attack chain and making it impossible to accurately locate the specific channel through which information is transmitted, thus preventing side-channel attacks and enhancing data security. Furthermore, different random masks are introduced in each round of operation to resist high-order side-channel attacks. The correct output result is obtained by XORing the output results of two paths; even if an attacker obtains the output result of one path, they cannot crack the information in the cryptographic operation.

[0178] Finally, this application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, performs the steps described in the above method embodiments, achieving the technical effects of the data encryption method described above.

[0179] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0180] The computer-readable storage medium provided in this embodiment stores a computer program. When the processor executes the program, it can implement the following method: a data encryption method applied to a data encryption device. The data encryption device includes at least three block cipher algorithm paths. The block cipher algorithm is a multi-round iterative encryption algorithm, including: obtaining a random plaintext mask and a random key mask for each round; XORing the original plaintext with the first round random plaintext mask to obtain a first mask plaintext, and XORing the original key with the first round random key mask to obtain a first mask key; randomly selecting a path as the first path, and using the first mask plaintext and the first mask key as inputs to the first path. The data undergoes a first round of encryption. Then, any path other than the first path is selected as the second path. Each round's random plaintext mask and random key mask are used as input data for each round of encryption in the second path. The output data of each round in the second path, along with the corresponding random plaintext mask and random key mask for the next round, are used to perform a masking operation on the output data of each round in the first path. The result of this masking operation is used as input data for the next round in the first path. Finally, the first ciphertext and first key output by the first path are XORed with the second ciphertext and second key output by the second path to obtain the plaintext encryption result and the key encryption result. By setting multiple paths, various possible choices are generated, increasing the difficulty for attackers in the attack chain and making it impossible to accurately locate the specific channel through which information is transmitted, thus preventing side-channel attacks and enhancing data security. Furthermore, different random masks are introduced in each round of operation to resist high-order side-channel attacks. The correct output result is obtained by XORing the output results of two paths; even if an attacker obtains the output result of one path, they cannot crack the information in the cryptographic operation.

[0181] The foregoing provides a detailed description of a data encryption method, apparatus, and computer-readable storage medium provided in this application. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

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

Claims

1. A data encryption method, characterized in that, Applied to a data encryption device, the data encryption device includes at least three block cipher algorithm paths, the block cipher algorithm being a multi-round iterative encryption algorithm, including: Obtain the random plaintext mask and random key mask for each round; The first mask plaintext is obtained by XORing the original plaintext with the first round of random plaintext mask, and the first mask key is obtained by XORing the original key with the first round of random key mask. Randomly select a path as the first path, and use the first mask plaintext and the first mask key as the input data of the first path to perform the first round of encryption operation; Select any path other than the first path as the second path, and use the random plaintext mask and the random key mask of each round as the input data of each round of the second path for encryption operation of the corresponding round. The output data of each round of the second path and the random plaintext mask and random key mask corresponding to the next round are used to perform a masking operation on the output data of each round of the first path. The result of the masking operation is used as the input data of the next round of the first path. The first ciphertext and the first key output by the first channel are XORed with the second ciphertext and the second key output by the second channel to obtain the plaintext encryption result and the key encryption result. The step of performing a masking operation on the output data of each round of the second path and the corresponding random plaintext mask and random key mask for the next round on the output data of each round of the first path, and using the masking operation result as the input data of the first path for the next round, includes: The output of each round of the first path is XORed with the random plaintext mask and the random key mask corresponding to the next round to obtain the first XOR result. Perform an XOR operation between the first XOR result and the corresponding output result of the second path to obtain a second XOR result, and use the second XOR result as the input data for the next round of the first path.

2. The data encryption method according to claim 1, characterized in that, After the first channel outputs the first ciphertext and the first key, and the second channel outputs the second ciphertext and the second key, the method further includes: Select any two paths other than the first and second paths as the third and fourth paths, use the first ciphertext and the first key as input data for the third path to perform decryption operation, and use the second ciphertext and the second key as input data for the fourth path to perform decryption operation. The decryption result of the third path is XORed with the decryption result of the fourth path to obtain the plaintext and the key for verification. Determine whether the test plaintext is consistent with the original plaintext; If they match, it is determined that there is no error injection; If there is a discrepancy, it is determined that there is an error injection.

3. The data encryption method according to claim 1, characterized in that, Before performing the first round of encryption operation using the first mask plaintext and the first mask key as input data for the first path, the method further includes: Obtain the first random data set as input data for the first path and perform pseudo-operations; After the first path finishes the pseudo-operation, the step of performing the first round of encryption operation by using the first mask plaintext and the first mask key as input data for the first path is entered. In addition, before performing the encryption operation on each round of the corresponding round by using the random plaintext mask and the random key mask as input data for each round of the second path, the method further includes: Obtain the second random data set as input data for the second path and perform pseudo-operations; After the second path finishes the pseudo-operation, the process proceeds to the step of using the random plaintext mask and the random key mask of each round as the input data of each round of the second path for the corresponding round of encryption operation.

4. The data encryption method according to claim 1, characterized in that, The process of obtaining the random plaintext mask and random key mask for each round includes: Obtain the first initial mask, the second initial mask, the first preset random number generation algorithm, and the second preset random number generation algorithm; Each round of random plaintext mask is obtained based on the first preset random number generation algorithm and the first initial mask; The random key mask for each round is obtained based on the second preset random number generation algorithm and the second initial mask.

5. The data encryption method according to claim 1, characterized in that, Before obtaining the random plaintext mask and random key mask for each round, the process also includes: Determine if the current operation state is in safe mode; If so, proceed to the step of obtaining the random plaintext mask and random key mask for each round; If not, then any idle path is selected to perform encryption operations on the original plaintext and the original key as input data, and the corresponding output result is obtained.

6. The data encryption method according to claim 3, characterized in that, Also includes: Determine whether the first round of encryption operations for both the first and second paths has ended; If so, the first path and the second path will proceed to the next round of encryption operation; If not, save the output of the first round of encryption operation of the path that has completed the first round of encryption operation, and perform a random pseudo-operation until the first round of encryption operation of the other path is completed.

7. A data encryption device, characterized in that, An application for a data encryption device, the data encryption device including at least three block cipher algorithm paths, the block cipher algorithm being a multi-round iterative encryption algorithm, the device comprising: The random mask acquisition module is used to obtain the random plaintext mask and random key mask for each round; The original data XOR module is used to obtain the first mask plaintext by XORing the original plaintext with the random plaintext mask, and to obtain the first mask key by XORing the original key with the random key mask; The first processing module is used to randomly select a path as the first path and use the first mask plaintext and the first mask key as input data of the first path to perform the first round of encryption operation. The second operation module is used to select any path other than the first path as the second path, and to use the random plaintext mask and the random key mask of each round as the input data of each round of the second path for encryption operation of the corresponding round. The third calculation module is used to perform a masking operation on the output data of each round of the second path and the random plaintext mask and random key mask corresponding to the next round on the output data of each round of the first path, and the masking operation result is used as the input data of the first path in the next round. The output module is used to perform XOR operations on the first ciphertext and the first key finally output by the first channel with the second ciphertext and the second key finally output by the second channel to obtain the plaintext encryption result and the key encryption result. The step of performing a masking operation on the output data of each round of the second path and the corresponding random plaintext mask and random key mask for the next round on the output data of each round of the first path, and using the masking operation result as the input data of the first path for the next round, includes: The output of each round of the first path is XORed with the random plaintext mask and the random key mask corresponding to the next round to obtain the first XOR result. Perform an XOR operation between the first XOR result and the corresponding output result of the second path to obtain a second XOR result, and use the second XOR result as the input data for the next round of the first path.

8. A data encryption device, characterized in that, Includes memory used to store computer programs; A processor, configured to implement the steps of the data encryption method as described in any one of claims 1 to 6 when executing the computer program.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the data encryption method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Anti-attack mask method and device of block encryption algorithm

    CN106161005A

  • AES mask method, electronic device and storage medium

    CN109165531A

  • Injection attack prevention method for data encryption standard coprocessor

    CN110321737A

  • AES algorithm module anti-attack system and method

    CN114785479A