Encryption method and device based on hidden code protection, electronic equipment and storage medium

By introducing a random entropy source seed and multiple rounds of shift operations and nonlinear transformations into the SM4 algorithm, the nonlinear characteristics of the SM4 algorithm are enhanced, the problem of side-channel defense under limited hardware resources is solved, and a more complex encryption process and higher security are achieved.

CN121690637APending Publication Date: 2026-03-17ALLWINNER TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

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

Smart Images

  • Figure CN121690637A_ABST
    Figure CN121690637A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an encryption method and device based on hidden code protection, electronic equipment and a storage medium, and the method comprises the steps: obtaining text information, an entropy source seed and a plurality of round keys, decomposing the text information, and determining a first text and a second text; performing encryption processing on the first text through the entropy source seed to obtain an intermediate ciphertext, and performing encryption processing on the second text through the entropy source seed and the round key to obtain a first entropy ciphertext; alternately performing shift operation and nonlinear transformation processing on the first entropy ciphertext to obtain a second entropy ciphertext; determining a new first text and a new second text according to the first text and the second entropy ciphertext, and encrypting the new first text and the new second text again; performing inverse transformation on the first text and the second text which are most encrypted to obtain a target ciphertext; according to the method, the nonlinear characteristic of the encryption algorithm can be enhanced on the premise that the algorithm performance is not increased, so that the encryption process is more complex, and the security of the ciphertext is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of encryption algorithms, and particularly relates to an encryption method and device based on hidden code protection, electronic equipment and a storage medium. BACKGROUND

[0002] The SM4 cryptographic algorithm is a block symmetric cryptographic algorithm independently developed by China, which is used to realize data encryption / decryption operations to ensure the confidentiality of data and information. Many chip application scenarios in China require to meet the national cryptographic authentication standards, and the national cryptographic authentication security level two requires that the chip has the protection of energy analysis attacks (anti-side channel attacks) to meet the protection ability of the chip itself. To cope with the future market that must be reached in more and more scenarios of national cryptographic authentication, it is inevitable to realize the SM4 hardware circuit with anti-side channel attack, and how to realize the chip with low cost and security protection ability under the condition of limited hardware resources becomes an effective means to provide industry competitiveness.

[0003] The SM4 algorithm and other variations in the prior art only simply realize the encryption and decryption functions of the algorithm without considering any side channel defense performance. SUMMARY

[0004] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.

[0005] The encryption method and device based on hidden code protection, electronic equipment and storage medium provided by the embodiments of the present application can enhance the nonlinear characteristics of the encryption algorithm without increasing the algorithm performance, improve the side channel defense performance, and make the encryption process more complex.

[0006] To achieve the above-mentioned purpose, a first aspect of the embodiments of the present application provides an encryption method based on hidden code protection, comprising: obtaining text information, a random entropy source seed and a round key of a plurality of encryption rounds, decomposing the text information to determine a first text and a second text; encrypting the first text through the entropy source seed to obtain intermediate ciphertext, and encrypting the second text through the entropy source seed and the round key of the current encryption round to obtain first entropy ciphertext; performing shift operation and nonlinear transformation processing alternately on the first entropy ciphertext with a preset number of shifts and a preset number of nonlinear transformations to obtain second entropy ciphertext; determining new first text and new second text according to the intermediate ciphertext and the second entropy ciphertext, and encrypting the first text and the second text determined currently again until the number of encryption rounds is equal to a preset number threshold; and performing reverse sequence transformation on the first text and the second text after encryption to obtain target ciphertext.

[0007] In some embodiments, the second text includes a plurality of first sub-ciphertexts, the first text is encrypted by the entropy source seed to obtain an intermediate ciphertext, and the second text is encrypted by the entropy source seed and the round key of the current encryption round to obtain a first entropy ciphertext, including: generating a plurality of masks with the same length as the first sub-ciphertexts by the entropy source seed, performing XOR processing on each of the first sub-ciphertexts by the masks to obtain a plurality of second sub-ciphertexts, and merging all the second sub-ciphertexts by XOR processing to determine a third sub-ciphertext; performing XOR processing on the third sub-ciphertext by the round key generated according to the current encryption round to determine the first entropy ciphertext.

[0008] In some embodiments, the number of shifts is twice, and the number of nonlinear transformations is once, and the first entropy ciphertext is alternately subjected to shift operation and nonlinear transformation processing with a preset number of shifts and a preset number of nonlinear transformations to obtain a second entropy ciphertext, including: decomposing the first entropy ciphertext to obtain a plurality of fourth sub-ciphertexts, performing cyclic shift operation on each of the fourth sub-ciphertexts to determine a fifth sub-ciphertext; obtaining a nonlinear transformation hidden code box, the number of nonlinear transformation hidden code boxes being equal to the number of fifth sub-ciphertexts, performing nonlinear transformation processing on each of the fifth sub-ciphertexts by the nonlinear transformation hidden code box to obtain a sixth sub-ciphertext; and performing cyclic shift operation and merging processing on each of the sixth sub-ciphertexts to obtain a second entropy ciphertext.

[0009] In some embodiments, the cyclic shift operation on each of the fourth sub-ciphertexts to determine a fifth sub-ciphertext includes: determining a first shift starting point in each of the fourth sub-ciphertexts by the entropy source seed, and performing left cyclic shift operation on the corresponding fourth sub-ciphertext according to the first shift starting point to determine a fifth sub-ciphertext.

[0010] In some embodiments, the cyclic shift operation and merging processing on each of the sixth sub-ciphertexts to obtain a second entropy ciphertext includes: determining a second shift starting point on each of the sixth sub-ciphertexts by the entropy source seed, and performing right cyclic shift operation on the corresponding sixth sub-ciphertext according to the second shift starting point to obtain a plurality of seventh sub-ciphertexts; and merging the seventh sub-ciphertexts to obtain a second entropy ciphertext.

[0011] In some embodiments, before the first entropy ciphertext is alternately subjected to shift operation and nonlinear transformation processing with a preset number of shifts and a preset number of nonlinear transformations, the method further includes: generating a random number sequence by the entropy source seed, and expanding the first entropy ciphertext using the random number sequence.

[0012] In some embodiments, the determining the new first text and the new second text according to the intermediate ciphertext and the second entropy ciphertext comprises: performing a preset bitwise XOR operation on the second entropy ciphertext to obtain an eighth sub-ciphertext, and performing an XOR operation on the eighth sub-ciphertext and the first text; taking a part of the second text as the new first text, and taking the remaining part of the second text and the eighth sub-ciphertext as the new second text.

[0013] In addition, to achieve the above object, a second aspect of the embodiments of the present application provides an improved sm4 encryption device, comprising: an acquisition module configured to acquire text information, a random entropy source seed, and a plurality of round keys of encryption rounds, decompose the text information, and determine a first text and a second text; a first encryption module configured to encrypt the first text by using the entropy source seed to obtain an intermediate ciphertext, and encrypt the second text by using the entropy source seed and the round key of the current encryption round to obtain a first entropy ciphertext; a second encryption module configured to perform a shift operation and a nonlinear transformation on the first entropy ciphertext alternately for a preset number of times of shifting and a preset number of times of nonlinear transformation to obtain a second entropy ciphertext; an iteration module configured to determine a new first text and a new second text according to the intermediate ciphertext and the second entropy ciphertext, and encrypt the new first text and the new second text again until the number of encryption rounds is equal to a preset number threshold; and a third encryption module configured to perform reverse sequence transformation on the encrypted first text and the encrypted second text to obtain a target ciphertext.

[0014] To achieve the above object, a third aspect of the embodiments of the present application provides an electronic device, which comprises a memory and a processor, the memory stores a computer program, and the processor implements the encryption method based on hidden code protection according to the first aspect when executing the computer program.

[0015] To achieve the above object, a fourth aspect of the embodiments of the present application provides a storage medium, which is a computer readable storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the encryption method based on hidden code protection according to the first aspect.

[0016] The embodiments of the present application at least have the following beneficial effects: after inputting the text information to be encrypted, the text information is decomposed to obtain a first text and a second text, different encryption processing is performed on the first text and the second text respectively, multi-level encryption of the text information is realized, and the confusion degree of the text information can be improved; by obtaining a random entropy source seed, the first text and the second text are first encrypted according to the entropy source seed, so that randomness is introduced into the encryption of the text information; in one encryption round, the first entropy ciphertext is alternately subjected to shift processing and nonlinear transformation processing, so that the nonlinear characteristics of the encryption algorithm are enhanced without increasing the algorithm performance, the consumption of hardware resources is reduced, and the encryption process is more complex and difficult to be cracked by linear or differential analysis.

[0017] Other features and advantages of the present application will be set forth in the following description, and in part will become apparent from the description, or can be learned by practice of the present application. The objects and other advantages of the present application will be realized and attained by means of the instrumentalities particularly pointed out in the description and claims, and the appended drawings. BRIEF DESCRIPTION OF DRAWINGS

[0018] The accompanying drawings, which are incorporated herein and form a part of the specification, illustrate the present application and, together with the description, further serve to explain the principles of the present application and to enable a person skilled in the pertinent art to make and use the present application.

[0019] Figure 1 An optional flow diagram of the encryption method based on the hidden code protection provided by the embodiments of the present application; Figure 2 An optional flow diagram of the encryption of the first entropy ciphertext provided by the embodiments of the present application; Figure 3 An optional flow diagram of the encryption of the second entropy ciphertext provided by the embodiments of the present application; Figure 4 An optional flow diagram of the iteration processing provided by the embodiments of the present application; Figure 5 An optional framework diagram of the round key generator provided by the embodiments of the present application; Figure 6 An optional framework diagram of the encryption of the first entropy ciphertext provided by the embodiments of the present application; Figure 7 An optional framework diagram of the extension processing provided by the embodiments of the present application; Figure 8 An optional framework diagram of the pseudo-random number generator provided by the embodiments of the present application; Figure 9A schematic diagram of an optional framework for obtaining second entropy ciphertext through encryption, as provided in an embodiment of this application; Figure 10 A schematic diagram of an optional framework for the iterative processing provided in an embodiment of this application; Figure 11 A schematic diagram of an optional framework for reverse processing provided in an embodiment of this application; Figure 12 This is a schematic diagram of an optional structure of the encryption device based on hidden code protection provided in this embodiment; Figure 13 This is a schematic diagram of an optional hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0021] In the description of this application, "several" means one or more, "multiple" means two or more, "greater than", "less than", "exceeding" etc. are understood to exclude the number itself, and "above", "below", "within" etc. are understood to include the number itself.

[0022] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, or the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.

[0023] Existing SM4 algorithms and their variations simply implement the encryption and decryption functions of the algorithm without considering any side-channel defense capabilities.

[0024] Based on this, embodiments of this application provide an encryption method, apparatus, electronic device, and storage medium based on covert protection, which can enhance the nonlinear characteristics of the encryption algorithm without increasing the algorithm performance, making the encryption process more complex.

[0025] The encryption method, apparatus, electronic device and storage medium based on covert protection provided in this application are specifically described through the following embodiments. First, the encryption method based on covert protection in the embodiments of this application is described.

[0026] The encryption method based on covert protection provided in this application relates to the field of computer technology. This covert protection encryption method can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the covert protection encryption method, but is not limited to the above forms.

[0027] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0028] The embodiments of this application will be further described below with reference to the accompanying drawings.

[0029] like Figure 1 As shown, Figure 1 This is a schematic diagram of an optional flowchart of an encryption method based on covert protection provided in an embodiment of this application. The encryption method based on covert protection can be executed by a server, or by a terminal, or by a server in cooperation with a terminal. The encryption method based on covert protection includes, but is not limited to, the following steps S110 to S140: Step S110: Obtain text information, a random entropy source seed, and round keys for multiple encryption rounds; decompose the text information to determine the first text and the second text. Step S120: Encrypt the first text using the entropy source seed to obtain the intermediate ciphertext; then encrypt the second text using the entropy source seed and the round key of the current encryption round to obtain the first entropy ciphertext. Step S130: The first entropy ciphertext is alternately subjected to shift operations and nonlinear transformations with a preset number of shifts and nonlinear transformations to obtain the second entropy ciphertext; Step S140: Determine a new first text and a new second text based on the intermediate ciphertext and the second entropy ciphertext, and encrypt the currently determined first text and second text again until the number of encryption rounds is equal to the preset number threshold. Step S150: Reverse the order of the first and second encrypted texts to obtain the target ciphertext.

[0030] Understandably, after receiving the text information to be encrypted, the text information is decomposed into a first text and a second text. Different encryption processes are then applied to the first and second texts respectively, achieving multi-level encryption of the text information and increasing the obfuscation level. By obtaining a random entropy source seed, the first and second texts are first encrypted according to the entropy source seed, thus introducing randomness into the encryption of the text information. In one encryption round, by alternately shifting and nonlinearly transforming the first entropy ciphertext, the nonlinear characteristics of the encryption algorithm are enhanced without increasing the algorithm performance, reducing the consumption of hardware resources, and making the encryption process more complex and difficult to crack by linear or differential analysis.

[0031] Specifically, the initial input text information is converted to binary, resulting in text information consisting of four first sub-ciphertexts (X0, X1, X2, X3), where X0, X1, X2, and X3 are all 32-bit binary texts, making the total text information 128-bit binary text. This binary text information is then divided into X0, X1, X2, and X3. In the first encryption round, the first text includes X0, and the second text includes X1, X2, and X3. The system generates a random entropy source seed using a random number generator. The mask generator uses the randomly generated entropy source seed to determine four 32-bit masks. One of these masks is used to XOR X0 in the first text. The mask generator and random number generator can be true random number generators. Simultaneously, a round key generator... The generator generates dedicated round keys for each encryption round based on the initial input key. In the first encryption round, X1, X2, and X3 in the second text are encrypted using the other three masks and the generated first round key to obtain the first entropy ciphertext. Then, the system presets the number of shift operations and the number of nonlinear transformations. The shift operation can be a combination of left circular shift and right circular shift. The nonlinear transformation can be an 8-bit binary sbox replacement box or a finite field GF(2)-based nonlinear transformation. 2 )2 The byte substitution is performed, and after alternating shift operations and nonlinear transformations on the first entropy ciphertext, the second entropy ciphertext is obtained. Then, the first and second texts in the next encryption round are determined based on the intermediate ciphertext and the second entropy ciphertext. The above steps are performed again on the new first and second texts until the preset number of encryption rounds is completed.

[0032] The encryption algorithm consists of 32 encryption rounds. In the first encryption round, the first and second texts are X0, X1, X2, and X3, respectively. Through the encryption steps in the first encryption round, the first text X1 and the second texts X2, X3, and X5 in the second encryption round are obtained. These new first and second texts are then re-encrypted to obtain new first and second texts again. In summary, in the i-th encryption round (i=0, 1, 2…31), the first text before encryption is Xi, and the second texts include Xi+1, Xi+2, and Xi+3. Through the encryption steps in the first encryption round… The first text and the second text are processed to obtain Xi+4. Therefore, the first text obtained after encryption is Xi+1, and the second text includes Xi+2, Xi+3 and Xi+4. After completing the 32nd encryption round, the ciphertext (X32, X33, X34, X35) is obtained. In step S150, the ciphertext (X32, X33, X34, X35) is reversed to obtain the target ciphertext (Y0, Y1, Y2, Y3) = R(X32, X33, X34, X35) = (X35, X34, X33, X32).

[0033] Additionally, refer to Figure 2 As shown, one embodiment of this application, Figure 1 Step 110 includes, but is not limited to, the following steps S210 to S230: Step S210: Generate multiple masks with the same length as the first sub-ciphertext using the entropy source seed; perform XOR processing on each first sub-ciphertext using the mask to obtain multiple second sub-ciphertexts; merge all second sub-ciphertexts using the XOR processing method to determine the third sub-ciphertext. Step S220: Perform XOR processing on the third sub-ciphertext based on the round key generated in the current encryption round to determine the first entropy ciphertext.

[0034] like Figure 5As shown, the system generates a 128-bit initial key MK, denoted as MK=(MK0, MK1, MK2, MK3), where MK0, MK1, MK2, and MK3 are all 32 bits long. The system stores 128-bit system parameters FK=(FK0, FK1, FK2, FK3). XORing (MK0, MK1, MK2, MK3) with the system parameters (FK0, FK1, FK2, FK3) yields (K0, K1, K2, K3). In the first round of key generation, K1, K2, and K3 are XORed... After XORing K1, K2, and K3 to obtain a 32-bit ciphertext, the ciphertext obtained by combining K1, K2, and K3 is XORed using a fixed parameter CTi in each round. The ciphertext XORed by CTi is then divided into four 8-bit first subkeys. These four first subkeys are then subjected to a non-linear transformation using a preset s-box and combined to obtain a 32-bit second subkey. The second subkey is then subjected to 13-bit and 23-bit circular left shift operations, and the result of the left shift operation is XORed with itself to obtain the third subkey. The specific formula is as follows: In this formula, B is the third subkey, and A is the second subkey. The expression represents an XOR operation. B<<<13 represents a 13-bit circular left shift operation, and B<<<23 represents a 23-bit circular left shift operation. The third subkey is XORed with K0 to obtain the round key rk0 in the first encryption round. Here, K4=rk0, resulting in (K1, K2, K3, K4). (K1, K2, K3, K4) is used to enter the second generation round of the round key. This process is repeated. In the i-th generation round (i=0, 1…31), (Ki, Ki+1, Ki+2, Ki+3) obtained from the previous encryption round is used to process and obtain the round key rki of the current generation round. Ki+4=rki, resulting in (Ki+1, Ki+2, Ki+3, Ki+4) to enter the (i+1)-th encryption round, until 32 round keys are generated.

[0035] Specifically, such as Figure 6As shown, the random number generator generates a first mask, a second mask, and a third mask using an entropy source seed. The length of each mask is 32 bits. In the first encryption round, the three first sub-ciphertexts X1, X2, and X3 in the second text are XORed using the first, second, and third masks respectively, resulting in three 32-bit second sub-ciphertexts. These three masked second sub-ciphertexts are then XORed and merged to obtain a single 32-bit third sub-ciphertext. Finally, the third sub-ciphertext is XORed using the round key rk0 to obtain the current... The first entropy ciphertext of the encryption step; in the i-th encryption round, the random number generator generates the first mask, the second mask, and the third mask again using the entropy source seed. The first mask, the second mask, and the third mask are used to XOR the three first sub-ciphertexts Xi, Xi+1, and Xi+2 in the second text in the current encryption round to obtain three second sub-ciphertexts. The masked second sub-ciphertexts are XORed and merged to obtain the third sub-ciphertext. The third sub-ciphertext is XORed using the round key rki corresponding to the current encryption round to obtain the first entropy ciphertext of the current encryption step.

[0036] In another embodiment of this application, the number of shifts is two, and the number of nonlinear transformations is one, as shown in the reference. Figure 3 As shown, Figure 1 Step S130 includes, but is not limited to, steps S310 to S330: Step S310: Decompose the first entropy ciphertext to obtain multiple fourth sub-ciphertexts, and perform a cyclic shift operation on each fourth sub-ciphertext to determine the fifth sub-ciphertext; Step S320: Obtain nonlinear transformation hidden boxes. The number of nonlinear transformation hidden boxes is equal to the number of fifth sub-ciphertexts. Perform nonlinear transformation processing on each fifth sub-ciphertext using the nonlinear transformation hidden boxes to obtain the sixth sub-ciphertext. Step S330: Perform cyclic shift and merge operations on each sixth sub-ciphertext to obtain the second entropy ciphertext.

[0037] In passing Figure 6 After obtaining the first entropy ciphertext, it is decomposed into multiple 8-bit fourth sub-ciphertexts. A cyclic shift operation is performed on each fourth sub-ciphertext to determine the fifth sub-ciphertext. A nonlinear transformation hidden box is obtained, which is similar to the S-box in the SM4 encryption algorithm. The 8-bit fifth sub-ciphertext is nonlinearly replaced by the nonlinear transformation hidden box to obtain a sixth sub-ciphertext, which is also 8 bits. The sixth sub-ciphertext is then cyclically shifted again. The sixth sub-ciphertexts after cyclic shifting are then merged back to obtain the second entropy ciphertext.

[0038] In one specific implementation, such as Figure 7As shown, after obtaining the 32-bit first entropy ciphertext from encryption step 1, the random number generator generates a 96-bit random number sequence through the entropy source seed. The first entropy ciphertext is then expanded to 128 bits using the random number sequence. The expansion process can be done by directly adding a random number sequence to the left side of the first entropy ciphertext, or directly adding a random number sequence to the right side of the first entropy ciphertext, or inserting a random number sequence at a specific position within the first entropy ciphertext. No restrictions will be placed here.

[0039] like Figure 8 As shown, Figure 8 This is a schematic diagram of an optional framework for the pseudo-random number generator proposed in this application. The pseudo-random number generator includes a nonlinear feedback shift register (NLFSR) and 16 constant memories. Each constant memory stores a 96-bit constant. The entropy source seed has a length of 4 bits. A multiplexer (usually abbreviated as MUX) selects a constant from one of the constant memories based on the entropy source seed and performs an XOR operation on the output of the nonlinear feedback shift register using this constant, thereby generating a 98-bit random number sequence.

[0040] like Figure 9 As shown, after expanding the first entropy ciphertext to a length of 128 bits using a random number sequence, the first entropy ciphertext is decomposed into 16 fourth sub-ciphertexts, each 8 bits long. The first shift start point in each fourth sub-ciphertext is determined using the entropy source seed. Based on the first shift start point, a left circular shift operation is performed on the corresponding fourth sub-ciphertext to obtain the fifth sub-ciphertext. Sixteen nonlinear transformation hidden boxes sbox0, sbox1…sbox15 are obtained. The fifth sub-ciphertext is then subjected to a nonlinear transformation using these boxes. The value of the fifth sub-ciphertext is replaced with the corresponding value in the nonlinear transformation hidden box to obtain the sixth sub-ciphertext. The second shift start point on each sixth sub-ciphertext is determined using the entropy source seed. Based on the second shift start point, a right circular shift operation is performed on the corresponding sixth sub-ciphertext to obtain 16 seventh sub-ciphertexts, each 8 bits long. The 16 seventh sub-ciphertexts are then merged again to obtain the 128-bit second entropy ciphertext.

[0041] The replacement table within the nonlinear transformation hidden box is stored in memory. According to the order in which the first entropy ciphertext is segmented, the fifth sub-ciphertext corresponds one-to-one with the nonlinear transformation hidden box. When the number of hardware structures that can simultaneously perform nonlinear transformation based on the nonlinear transformation hidden box is less than the number of fifth sub-ciphertexts that need to be nonlinearly transformed at the same time, the order of nonlinear transformation of the fifth sub-ciphertext is determined by the entropy source seed. According to the order, a linear lookup table is used to sequentially perform nonlinear transformation on the fifth sub-ciphertext.

[0042] Additionally, refer to Figure 4 As shown, Figure 1 Step S140 includes, but is not limited to, steps S410 to S420: Step S410: Perform a preset bitwise XOR operation on the second entropy ciphertext to obtain the eighth sub-ciphertext, and then perform an XOR operation on the eighth sub-ciphertext and the first text. Step S420: Take a portion of the second text as the new first text, and take the remaining portion of the second text and the eighth sub-ciphertext as the new second text.

[0043] like Figure 10 As shown, specifically, the 128-bit second entropy ciphertext is compressed to 32 bits. The compressed second entropy ciphertext is then subjected to a preset bitwise XOR operation to obtain a 32-bit eighth sub-ciphertext. Let the compressed second entropy ciphertext be C, and the bitwise XOR operation formula is as follows: .

[0044] The eighth ciphertext is XORed with Xi-1 in the 32-bit first text to obtain Xi+4, thus completing the i-th encryption round and obtaining Xi, Xi+1, Xi+2 and Xi+3. Xi is used as the new first text, and Xi+1, Xi+2 and Xi+3 are used as the new first ciphertext in the second text. The (i+1)-th encryption round is then performed based on the new first text and the second text.

[0045] like Figure 11 As shown in encryption step 5, after completing a total of 32 encryption rounds, X32, X33, X34 and X35 are obtained. The (X32, X33, X34, X34) are reversed according to the overall order of X32, X33, X34 and X35 to obtain the 128-bit target ciphertext (X35, X34, X33, X32).

[0046] Additionally, refer to Figure 12 This application also provides an encryption device 1200 based on covert protection, comprising: The acquisition module 1201 is used to acquire text information, a random entropy source seed, and round keys for multiple encryption rounds, decompose the text information, and determine the first text and the second text. The first encryption module 1202 is used to encrypt the first text using the entropy source seed to obtain the intermediate ciphertext, and to encrypt the second text using the entropy source seed and the round key of the current encryption round to obtain the first entropy ciphertext. The second encryption module 1203 is used to alternately perform shift operations and nonlinear transformations on the first entropy ciphertext with a preset number of shifts and nonlinear transformations to obtain the second entropy ciphertext. The iteration module 1204 is used to determine the new first text and second text based on the intermediate ciphertext and the second entropy ciphertext, and to encrypt the new first text and second text again until the number of encryption rounds is equal to the preset number threshold. The third encryption module 1205 is used to reverse the order of the first and second texts after encryption to obtain the target ciphertext.

[0047] The aforementioned encryption device 1200 based on hidden code protection and the encryption method based on hidden code protection are based on the same inventive concept, and will not be described again here.

[0048] Additionally, refer to Figure 13 , Figure 13 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 1301 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 1302 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 1302 can store the operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1302 and is called and executed by the processor 1301 using the encryption method based on hidden code protection according to the embodiments of this application, for example, executing the above-described... Figure 1 Method steps S110 to S150 Figure 2 Method steps S210 to S220, Figure 3Method steps S310 to S330, Figure 4 Method steps S410 to S420; The input / output interface 1303 is used to implement information input and output; The communication interface 1304 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 1305 transmits information between various components of the device (e.g., processor 1301, memory 1302, input / output interface 1303, and communication interface 1304); The processor 1301, memory 1302, input / output interface 1303 and communication interface 1304 are connected to each other within the device via bus 1305.

[0049] This application embodiment also provides a storage medium, which is a computer-readable storage medium for computer-readable storage. The storage medium stores one or more programs, which can be executed by one or more processors to implement the above-described encryption method based on covert protection. For example, it executes the above-described encryption method. Figure 1 Method steps S110 to S150 Figure 2 Method steps S210 to S220, Figure 3 Method steps S310 to S330, Figure 4 Method steps S410 to S420.

[0050] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0051] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0052] It will be understood by those skilled in the art thatFigures 1 to 4 The technical solutions shown do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0053] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0054] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0055] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0056] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0057] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0058] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0059] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0060] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it 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 includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0061] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A method for encryption based on covert code protection, characterized in that, The method comprises the following steps: obtaining text information, a random entropy source seed and a plurality of round keys of encryption rounds, decomposing the text information to determine a first text and a second text; encrypting the first text by using the entropy source seed to obtain intermediate ciphertext, and encrypting the second text by using the entropy source seed and the round key of the current encryption round to obtain first entropy ciphertext; alternately performing shift operation and nonlinear transformation processing on the first entropy ciphertext according to a preset number of shifts and a preset number of nonlinear transformations to obtain second entropy ciphertext; determining new first text and new second text according to the intermediate ciphertext and the second entropy ciphertext, and encrypting the first text and the second text again until the number of encryption rounds is equal to a preset threshold value; performing reverse sequence transformation on the encrypted first text and second text to obtain target ciphertext.

2. The encryption method based on the concealment code protection according to claim 1, characterized in that, The second text comprises a plurality of first sub-ciphertexts, the encryption of the first text by using the entropy source seed to obtain intermediate ciphertext, and the encryption of the second text by using the entropy source seed and the round key of the current encryption round to obtain first entropy ciphertext comprises the following steps: generating a plurality of masks with the same length as the first sub-ciphertexts by using the entropy source seed, performing XOR processing on each first sub-ciphertext by using the masks to obtain a plurality of second sub-ciphertexts, and merging all the second sub-ciphertexts by using XOR processing method to determine third sub-ciphertext; performing XOR processing on the third sub-ciphertext by using the round key generated according to the current encryption round to determine first entropy ciphertext.

3. The encryption method based on the concealment code protection according to claim 1, characterized in that, The number of shifts is twice, the number of nonlinear transformations is once, and the alternately performing shift operation and nonlinear transformation processing on the first entropy ciphertext according to a preset number of shifts and a preset number of nonlinear transformations to obtain second entropy ciphertext comprises the following steps: decomposing the first entropy ciphertext to obtain a plurality of fourth sub-ciphertexts, performing cyclic shift operation on each fourth sub-ciphertext to determine fifth sub-ciphertext; obtaining a plurality of nonlinear transformation code boxes, the number of nonlinear transformation code boxes being equal to the number of fifth sub-ciphertexts, performing nonlinear transformation processing on each fifth sub-ciphertext by using the nonlinear transformation code boxes to obtain sixth sub-ciphertext, and performing cyclic shift operation and merging processing on each sixth sub-ciphertext to obtain second entropy ciphertext. The performing cyclic shift operation on each fourth sub-ciphertext to determine fifth sub-ciphertext comprises the following steps:

4. The encryption method based on the concealment code protection according to claim 3, characterized in that, determining a first shift starting point in each fourth sub-ciphertext by using the entropy source seed, and performing left cyclic shift operation on the corresponding fourth sub-ciphertext according to the first shift starting point to determine fifth sub-ciphertext. The performing cyclic shift operation and merging processing on each sixth sub-ciphertext to obtain second entropy ciphertext comprises the following steps:

5. The encryption method based on the hidden code protection according to claim 3, characterized in that, determining a second shift starting point on each sixth sub-ciphertext by using the entropy source seed, and performing right cyclic shift operation on the corresponding sixth sub-ciphertext according to the second shift starting point to obtain a plurality of seventh sub-ciphertexts; merging the seventh sub-ciphertexts to obtain second entropy ciphertext. ​ 6. The encryption method based on the concealment code protection according to claim 1, characterized in that, Before the first entropy ciphertext is alternately subjected to the preset number of times of shifting operation and the preset number of times of nonlinear transformation, the method further comprises: The random number sequence is generated by the entropy source seed, and the first entropy ciphertext is expanded by using the random number sequence.

7. The encryption method based on the concealment code protection according to claim 1, characterized in that, The new first text and the new second text are determined according to the intermediate ciphertext and the second entropy ciphertext, and the method comprises: The second entropy ciphertext is subjected to preset bit-by-bit XOR processing to obtain an eighth sub-ciphertext, and the eighth sub-ciphertext is subjected to XOR processing with the first text; One part of the second text is taken as the new first text, and the remaining part of the second text and the eighth sub-ciphertext are taken as the new second text.

8. An improved sm4 encryption apparatus, characterized by, The method comprises: An acquisition module is configured to acquire text information, a random entropy source seed, and a plurality of round keys of encryption rounds, decompose the text information, and determine a first text and a second text; A first encryption module is configured to encrypt the first text by using the entropy source seed to obtain an intermediate ciphertext, and encrypt the second text by using the entropy source seed and the round key of the current encryption round to obtain a first entropy ciphertext; A second encryption module is configured to alternately subject the first entropy ciphertext to a preset number of times of shifting operation and a preset number of times of nonlinear transformation to obtain a second entropy ciphertext; An iteration module is configured to determine a new first text and a new second text according to the intermediate ciphertext and the second entropy ciphertext, and encrypt the new first text and the new second text again until the number of encryption rounds is equal to a preset number threshold. A third encryption module is configured to perform reverse sequence transformation on the encrypted first text and the encrypted second text to obtain a target ciphertext.

9. An electronic device, comprising: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the encryption method based on hidden code protection in any one of claims 1 to 7 when executing the computer program.

10. A storage medium storing a computer program, characterized by The computer program is executed by the processor to implement the encryption method based on hidden code protection in any one of claims 1 to 7.