A data encryption working mode detection method and device in CPA mode
Patent Information
- Application Number
- CN202511633562.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2045-11-10
AI Technical Summary
(1)本发明通过选择明文进行工作模式识别,促进检测技术演进,为构建自主可控的密码安全生态提供技术保障。
Smart Images

Figure CN121441601B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer encryption technology, and specifically to a method and apparatus for detecting data encryption working mode under CPA mode. Background Technology
[0002] In December 2001, NIST published five working modes of AES for security, adopting ECB, CBC, OFB, and CFB used by DES, and adding CTR. To date, international organizations have released numerous standards for block cipher working modes with different functions. To further promote the localization and independent control of cryptographic technologies in key areas, the national standard GB / T17964-2021 was released in 2021, defining nine data encryption working modes (ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF). Their correct application is directly related to the security of information systems.
[0003] The detection and identification of encryption modes are not only compliance requirements but also a crucial line of defense against cryptographic attacks. Domestic commercial cryptographic testing is a key link in ensuring network information security. Its scope extends beyond the compliance verification of cryptographic algorithms; it requires in-depth evaluation of the security of data encryption modes. Encryption mode detection is an important component of encryption technology implementation. Summary of the Invention
[0004] In view of this, the present invention provides a method and apparatus for detecting data encryption working mode under CPA mode, which can solve the above-mentioned technical problems.
[0005] To solve the above-mentioned technical problems, the present invention is implemented as follows.
[0006] A method for detecting data encryption working mode under CPA mode, comprising: Step S1: Based on the purpose of detecting and verifying the encryption mode used by the party to be detected, the detection center selects the encryption mode to be detected as the encryption mode to be detected; four different plaintexts are sent to the party to be detected, and the party to be detected encrypts the plaintexts respectively using the encryption mode to be detected, generating a ciphertext for each plaintext; the encryption mode to be detected is one of ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF; Step S2: Divide the plaintext into a header plaintext block, a middle plaintext block that reflects the encryption behavior, and a tail plaintext block that reflects the padding and truncation logic; divide the ciphertext corresponding to the plaintext into a header ciphertext block, a middle ciphertext block, and a tail ciphertext block, respectively corresponding to the header plaintext block, the middle plaintext block, and the tail plaintext block. Step S3: Determine the encryption working mode to be detected based on the segmentation results of the plaintext and the corresponding ciphertext.
[0007] Preferably, in step S2, the plaintext is divided into a header plaintext block, a middle plaintext block representing encryption behavior, and a tail plaintext block representing padding and truncation logic, including: The first complete block in the plaintext is taken as the header plaintext block; the complete blocks in the remaining plaintext after removing the header plaintext block are taken as the middle plaintext block; and the incomplete blocks in the remaining plaintext are taken as the tail plaintext block.
[0008] Preferably, in step S3, determining the encryption mode to be detected based on the segmentation results of the plaintext and the corresponding ciphertext includes: Step S31: Obtain the header plaintext block P of the first plaintext. 11 Middle section plaintext block P 12 and the end plaintext block P 13 In the first ciphertext corresponding to the first plaintext, and the header plaintext block P 11 The corresponding header ciphertext block is denoted as C. 11 , with the middle plaintext block P 12 The corresponding middle-section ciphertext block is denoted as C. 12 , with the plaintext block P at the end 13 The corresponding end-of-line ciphertext block is denoted as C. 13 ; where the first plaintext block P 11 Middle section plaintext block P 12 and the end plaintext block P 13 satisfy: P 11 =P 12 , and |P 11 |=|P 12 |=n,|P 13 |=t, where t is a prime number less than n, and | | represents the length of the bit string *, n is the block length, and t is the length of the plaintext at the end; Obtain the tag corresponding to the user's initial input information from the party to be tested. When the encryption system of the party to be tested prompts the party to be tested to input an initial vector, the tag corresponding to the user's initial input information is 1; when the encryption system of the party to be tested does not prompt the party to be tested to input an initial vector, the tag corresponding to the user's initial input information is 0. Make the first judgment: If the label is 1, and C 11 ≠C 12 The encryption mode of the data to be detected is CBC or BC. If the label is 0, and C 11 =C 12 If so, the encryption mode of the data to be detected is ECB; If the label is 0, and C 11 ≠C12 ≠C 13 If the length of the first ciphertext is the same as the length of the first plaintext, then the encryption mode of the data to be detected is CTR. If the label is 0, and C 11 ≠C 12 ≠C 13 If the length of the first ciphertext is an integer multiple of n, and the length of the first ciphertext is different from the length of the first plaintext, then the encryption mode of the data to be detected is OFBNLF. If none of the four conditions in the first judgment are met, proceed to step S32; Step S32: Obtain the header plaintext block P of the second plaintext. 21 Middle section plaintext block P 22 and the end plaintext block P 23 In the second ciphertext corresponding to the second plaintext, the header plaintext block P... 21 The corresponding header ciphertext block is denoted as C. 21 , with the middle plaintext block P 22 The corresponding middle-section ciphertext block is denoted as C. 22 , with the plaintext block P at the end 23 The corresponding end-of-line ciphertext block is denoted as C. 23 ; where the first plaintext block P 21 Middle section plaintext block P 22 and the end plaintext block P 23 satisfy: P 21 ⊕P 11 =00…01, i.e., P 21 With P 11 The last bit of the XOR value is 1, and the remaining bits are all 0; and P 22 =P 12 , ⊕ represents the XOR operation; Make a second judgment: If C 11 ⊕C 21 =P 11 ⊕P 21 And C 12 ⊕C 22 =P 12 ⊕P 22 C 13 ⊕C 23 =P 13 ⊕P 23 The encryption mode for the data to be detected is OFB. If C 11 ⊕C 21 =P 11 ⊕P 21 And C 12 ⊕C 22 ≠P12 ⊕P 22 C 13 ⊕C 23 ≠P 13 ⊕P 23 The encryption mode for the data to be detected is CFB. If neither of the two conditions in the second judgment is true, proceed to step S33; Step S33: Obtain the header plaintext block P of the third plaintext. 31 Middle section plaintext block P 32 and the end plaintext block P 33 In the third ciphertext corresponding to the third plaintext, the first plaintext block P... 31 The corresponding header ciphertext block is denoted as C. 31 , with the middle plaintext block P 32 The corresponding middle-section ciphertext block is denoted as C. 32 , with the plaintext block P at the end 33 The corresponding end-of-line ciphertext block is denoted as C. 33 ; where the first plaintext block P 31 Middle section plaintext block P 32 and the end plaintext block P 33 satisfy: P 31 =P 11 P 32 =P 12 P 33 ≠P 13 ; Make a third judgment: If C 11 ⊕C 31 =C 13 ⊕C 33 =0, and C 12 ⊕C 32 If ≠0, then the encryption mode of the data to be tested is XTS; If C 11 ⊕C 31 ≠C 13 ⊕C 33 ≠C 12 ⊕C 32 And C 11 ⊕C 31 C 13 ⊕C 33 C 12 ⊕C 32 If none of them are zero, then the encryption mode of the data to be tested is HCTR; If neither of the two conditions in the third judgment is met, the encryption mode of the data to be tested cannot be determined.
[0009] Preferably, step S3 further includes step S34: Obtain the header plaintext block P of the fourth plaintext. 41 Middle section plaintext block P 42 and the end plaintext block P 43 In the fourth ciphertext corresponding to the fourth plaintext, the plaintext block P in the header is... 41 The corresponding header ciphertext block is denoted as C. 41 , with the middle plaintext block P 42 The corresponding middle-section ciphertext block is denoted as C. 42 , with the plaintext block P at the end 43 The corresponding end-of-line ciphertext block is denoted as C. 43 ; where the first plaintext block P 41 Middle section plaintext block P 42 and the end plaintext block P 43 satisfy: P 41 IV2=P 11 IV1; Wherein, IV1 is the initial vector, and IV2 is the second vector required by the encryption system of the party to be detected to be input by the party to be detected. The second vector is the input information of the party to be detected when the encryption system of the party to be detected determines whether the initial vector is transmitted to the detection center synchronously with the generated ciphertext. Perform the fourth judgment: like The encryption mode for the data to be detected is CBC. If C 11 =C 41 However, C 12 ≠C 42 C 13 ≠C 43 The encryption mode for the data to be detected is BC.
[0010] Preferably, step S3 further includes step S34: Obtain the header plaintext block P of the fourth plaintext. 41 Middle section plaintext block P 42 and the end plaintext block P 43 In the fourth ciphertext corresponding to the fourth plaintext, the plaintext block P in the header is... 41 The corresponding header ciphertext block is denoted as C. 41 , with the middle plaintext block P 42 The corresponding middle-section ciphertext block is denoted as C. 42 , with the plaintext block P at the end 43 The corresponding end-of-line ciphertext block is denoted as C. 43 ; where the first plaintext block P 41 Middle section plaintext block P 42and the end plaintext block P 43 satisfy: P 41 IV2=P 11 IV1; Wherein, IV1 is the initial vector, and IV2 is the second vector required by the encryption system of the party to be detected to be input by the party to be detected. The second vector is the input information of the party to be detected when the encryption system of the party to be detected determines whether the initial vector is transmitted to the detection center synchronously with the generated ciphertext. Perform the fourth judgment: like The encryption mode for the data to be detected is CBC. If C 11 =C 41 However, C 12 ≠C 42 C 13 ≠C 43 The encryption mode for the data to be detected is BC.
[0011] Preferably, the encryption mode of the data to be detected is CBC, which means that the initial vector input by the party to be detected when encrypting the plaintext is transmitted along with the ciphertext; the encryption mode of the data to be detected is BC, which means that the initial vector input by the party to be detected when encrypting the plaintext is transmitted along with the ciphertext.
[0012] This invention provides a data encryption working mode detection device under CPA mode, comprising: Encryption module: Configured for the detection center to use the encryption mode used by the party under test as the encryption mode to be tested for the purpose of detection and verification; send four different plaintexts to the party under test, and the party under test encrypts the plaintexts respectively using the encryption mode to be tested, generating a ciphertext for each plaintext; the encryption mode to be tested is one of ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF; Segmentation module: Configured to segment plaintext into a header plaintext block, a middle plaintext block that reflects encryption behavior, and a tail plaintext block that reflects padding and truncation logic; segment the ciphertext corresponding to the plaintext into a header ciphertext block, a middle ciphertext block, and a tail ciphertext block, respectively corresponding to the header plaintext block, the middle plaintext block, and the tail plaintext block. Working mode determination module: configured to determine the working mode of the encryption to be detected based on the segmentation results of the plaintext and the corresponding ciphertext.
[0013] The present invention provides a computer-readable storage medium storing a plurality of instructions; the plurality of instructions are used by a processor to load and execute the method as described above.
[0014] The present invention provides an electronic device, characterized in that the electronic device comprises: A processor is used to execute multiple instructions; Memory, used to store multiple instructions; The plurality of instructions are to be stored in the memory and loaded and executed by the processor as described above.
[0015] Beneficial effects: (1) This invention promotes the evolution of detection technology by selecting plaintext for working mode recognition, and provides technical support for building an independent and controllable cryptographic security ecosystem.
[0016] (2) Based on the analysis of the ciphertext characteristics generated by the data encryption working mode, the present invention distinguishes the ciphertext of 9 encryption working modes (ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF) under the plaintext attack mode.
[0017] (3) Through the encryption working mode identified by the present invention, normal encrypted communication and malicious encrypted traffic (such as ransomware communication and covert tunnels) can be distinguished, and early interception of the attack chain can be achieved.
[0018] (4) The encryption working mode identified by the present invention helps to dynamically allocate computing resources, adopt a strong encryption working mode (such as HCTR) for highly sensitive data, and a traditional encryption working mode (such as CBC) for low-risk data, thus achieving a balance between security and performance. Attached Figure Description
[0019] Figure 1 This is a schematic diagram of the data encryption working mode detection method under the CPA mode of the present invention. Detailed Implementation
[0020] The present invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0021] like Figure 1 As shown, this invention proposes a method for detecting data encryption working mode under Chosen Plaintext Attack (CPA) mode, the method comprising: Step S1: Based on the purpose of detecting and verifying the encryption mode used by the party to be detected, the detection center selects the encryption mode to be detected as the encryption mode to be detected; four different plaintexts are sent to the party to be detected, and the party to be detected encrypts the plaintexts respectively using the encryption mode to be detected, generating a ciphertext for each plaintext; the encryption mode to be detected is one of ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF; Step S2: Divide the plaintext into a header plaintext block, a middle plaintext block that reflects the encryption behavior, and a tail plaintext block that reflects the padding and truncation logic; divide the ciphertext corresponding to the plaintext into a header ciphertext block, a middle ciphertext block, and a tail ciphertext block, respectively corresponding to the header plaintext block, the middle plaintext block, and the tail plaintext block. Step S3: Determine the encryption working mode to be detected based on the segmentation results of the plaintext and the corresponding ciphertext.
[0022] Further, in step S2, the plaintext is divided into a header plaintext block, a middle plaintext block reflecting encryption behavior, and a tail plaintext block reflecting padding and truncation logic, including: The first complete block in the plaintext is taken as the header plaintext block; the complete blocks in the remaining plaintext after removing the header plaintext block are taken as the middle plaintext block; and the incomplete blocks in the remaining plaintext are taken as the tail plaintext block.
[0023] In step S3, the encryption mode to be detected is determined based on the segmentation results of the plaintext and the corresponding ciphertext, including: Step S31: Obtain the header plaintext block P of the first plaintext. 11 Middle section plaintext block P 12 and the end plaintext block P 13 In the first ciphertext corresponding to the first plaintext, and the header plaintext block P 11 The corresponding header ciphertext block is denoted as C. 11 , with the middle plaintext block P 12 The corresponding middle-section ciphertext block is denoted as C. 12 , with the plaintext block P at the end 13 The corresponding end-of-line ciphertext block is denoted as C. 13 ; where the first plaintext block P 11 Middle section plaintext block P 12 and the end plaintext block P 13 satisfy: P 11 =P 12 , and |P 11 |=|P 12 |=n,|P 13 |=t, where t is a prime number less than n, and | | represents the length of the bit string *, n is the block length, and t is the length of the plaintext at the end; Obtain the tag corresponding to the user's initial input information from the party to be tested. When the encryption system of the party to be tested prompts the party to be tested to input an initial vector, the tag corresponding to the user's initial input information is 1; when the encryption system of the party to be tested does not prompt the party to be tested to input an initial vector, the tag corresponding to the user's initial input information is 0. Make the first judgment: If the label is 1, and C 11 ≠C 12 The encryption mode of the data to be detected is CBC or BC. If the label is 0, and C 11 =C 12 If so, the encryption mode of the data to be detected is ECB; If the label is 0, and C 11 ≠C 12 ≠C 13 If the length of the first ciphertext is the same as the length of the first plaintext, then the encryption mode of the data to be detected is CTR. If the label is 0, and C 11 ≠C 12 ≠C 13 If the length of the first ciphertext is an integer multiple of n, and the length of the first ciphertext is different from the length of the first plaintext, then the encryption mode of the data to be detected is OFBNLF. If none of the four conditions in the first judgment are met, proceed to step S32; Step S32: Obtain the header plaintext block P of the second plaintext. 21 Middle section plaintext block P 22 and the end plaintext block P 23 In the second ciphertext corresponding to the second plaintext, the header plaintext block P... 21 The corresponding header ciphertext block is denoted as C. 21 , with the middle plaintext block P 22 The corresponding middle-section ciphertext block is denoted as C. 22 , with the plaintext block P at the end 23 The corresponding end-of-line ciphertext block is denoted as C. 23 ; where the first plaintext block P 21 Middle section plaintext block P 22 and the end plaintext block P 23 satisfy: P 21 ⊕P 11 =00…01, i.e., P 21 With P 11 The last bit of the XOR value is 1, and the remaining bits are all 0; and P 22 =P 12 , ⊕ represents the XOR operation; Make a second judgment: If C 11 ⊕C 21 =P 11 ⊕P 21 And C 12 ⊕C 22 =P 12 ⊕P 22 C 13 ⊕C 23 =P 13 ⊕P 23 The encryption mode for the data to be detected is OFB. If C 11 ⊕C 21 =P 11 ⊕P 21 And C 12 ⊕C 22 ≠P 12 ⊕P 22 C 13 ⊕C 23 ≠P 13 ⊕P 23 The encryption mode for the data to be detected is CFB. If neither of the two conditions in the second judgment is true, proceed to step S33; Step S33: Obtain the header plaintext block P of the third plaintext. 31 Middle section plaintext block P 32 and the end plaintext block P 33 In the third ciphertext corresponding to the third plaintext, the first plaintext block P... 31 The corresponding header ciphertext block is denoted as C. 31 , with the middle plaintext block P 32 The corresponding middle-section ciphertext block is denoted as C. 32 , with the plaintext block P at the end 33 The corresponding end-of-line ciphertext block is denoted as C. 33 ; where the first plaintext block P 31 Middle section plaintext block P 32 and the end plaintext block P 33 satisfy: P 31 =P 11 P 32 =P 12 P 33 ≠P 13 ; Make a third judgment: If C 11 ⊕C 31 =C 13 ⊕C 33 =0, and C 12 ⊕C32 If ≠0, then the encryption mode of the data to be tested is XTS; If C 11 ⊕C 31 ≠C 13 ⊕C 33 ≠C 12 ⊕C 32 And C 11 ⊕C 31 C 13 ⊕C 33 C 12 ⊕C 32 If none of them are zero, then the encryption mode of the data to be tested is HCTR; If neither of the two conditions in the third judgment is met, the encryption mode of the data to be tested cannot be determined.
[0024] In this invention, the initialization vector (IV) input by the party to be detected when encrypting plaintext is obtained, the tag corresponding to the IV value is determined, and the header plaintext block is calculated based on the tag. The header plaintext block is the first encryption unit strongly correlated with the IV. The middle plaintext block is a complete block in the middle, reflecting the core behavior of the encryption mode. The tail plaintext block is the last block and is an incomplete block, reflecting the padding and truncation logic.
[0025] In step S31 of this invention, the encryption system prompts the party to be detected to input an initial vector, for example, through a pop-up window or command line. Alternatively, the encryption system may not prompt the party to be detected to input an initial vector, for example, the initial vector may be automatically generated by the encryption system or no initial vector may be required.
[0026] Furthermore, step S3 also includes step S34: Obtain the header plaintext block P of the fourth plaintext. 41 Middle section plaintext block P 42 and the end plaintext block P 43 In the fourth ciphertext corresponding to the fourth plaintext, the plaintext block P in the header is... 41 The corresponding header ciphertext block is denoted as C. 41 , with the middle plaintext block P 42 The corresponding middle-section ciphertext block is denoted as C. 42 , with the plaintext block P at the end 43 The corresponding end-of-line ciphertext block is denoted as C. 43 ; where the first plaintext block P 41 Middle section plaintext block P 42 and the end plaintext block P 43 satisfy: P 41 IV2=P 11 IV1; Wherein, IV1 is the initial vector, and IV2 is the second vector required by the encryption system of the party to be detected to be input by the party to be detected. The second vector is the input information of the party to be detected when the encryption system of the party to be detected determines whether the initial vector is transmitted to the detection center synchronously with the generated ciphertext. Perform the fourth judgment: like The encryption mode for the data to be detected is CBC. If C 11 =C 41 However, C 12 ≠C 42 C 13 ≠C 43 The encryption mode for the data to be detected is BC.
[0027] In this invention, any of the nine data encryption modes in the standard can be identified. However, if the mode is modified or these nine modes are not used, it cannot be identified.
[0028] Furthermore, the encrypted working mode of the data to be detected is CBC, which means that the initial vector input by the party to be detected when encrypting the plaintext is transmitted along with the ciphertext; the encrypted working mode of the data to be detected is BC, which means that the initial vector input by the party to be detected when encrypting the plaintext is transmitted along with the ciphertext.
[0029] The data encryption working mode is BC, which means that the initial vector input by the party to be detected when encrypting plaintext is transmitted along with the ciphertext.
[0030] ECB, CFB, OFB, CTR, XTS, HCTR, and OFBNLF all refer to ECB, CFB, OFB, CTR, XTS, HCTR, and OFBNLF, where the IV value or TW value participated in the key generation.
[0031] The present invention also provides a data encryption working mode detection device under CPA mode, the device comprising: Encryption module: Configured for the detection center to use the encryption mode used by the party under test as the encryption mode to be tested for the purpose of detection and verification; send four different plaintexts to the party under test, and the party under test encrypts the plaintexts respectively using the encryption mode to be tested, generating a ciphertext for each plaintext; the encryption mode to be tested is one of ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF; Segmentation module: Configured to segment plaintext into a header plaintext block, a middle plaintext block that reflects encryption behavior, and a tail plaintext block that reflects padding and truncation logic; segment the ciphertext corresponding to the plaintext into a header ciphertext block, a middle ciphertext block, and a tail ciphertext block, respectively corresponding to the header plaintext block, the middle plaintext block, and the tail plaintext block. Working mode determination module: configured to determine the working mode of the encryption to be detected based on the segmentation results of the plaintext and the corresponding ciphertext.
[0032] The specific embodiments described above only illustrate the design principles of the present invention. The shapes and names of the components in this description may differ and are not limited. Therefore, those skilled in the art can modify or make equivalent substitutions to the technical solutions described in the foregoing embodiments; and these modifications and substitutions do not depart from the inventive spirit and technical solutions of the present invention, and should all fall within the protection scope of the present invention.
Claims
1. A method for detecting data encryption working mode under CPA mode, characterized in that, include: Step S1: The testing center, based on the purpose of testing and confirming the encryption working mode used by the party to be tested, designates the encryption working mode as the encryption working mode to be tested. Four different plaintexts are sent to the party to be detected. The party to be detected encrypts the plaintexts respectively using the encryption mode to be detected, generating a ciphertext for each plaintext. The encryption mode to be detected is one of ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF. Step S2: Divide the plaintext into a header plaintext block, a middle plaintext block that reflects the encryption behavior, and a tail plaintext block that reflects the padding and truncation logic; divide the ciphertext corresponding to the plaintext into a header ciphertext block, a middle ciphertext block, and a tail ciphertext block, respectively corresponding to the header plaintext block, the middle plaintext block, and the tail plaintext block. Step S3: Determine the encryption working mode to be detected based on the segmentation results of the plaintext and the corresponding ciphertext; In step S2, the plaintext is divided into a header plaintext block, a middle plaintext block reflecting encryption behavior, and a tail plaintext block reflecting padding and truncation logic, including: The first complete block in the plaintext is taken as the header plaintext block; the complete blocks in the remaining plaintext after removing the header plaintext block are taken as the middle plaintext block; and the incomplete blocks in the remaining plaintext are taken as the tail plaintext block. In step S3, the encryption mode to be detected is determined based on the segmentation results of the plaintext and the corresponding ciphertext, including: Step S31: Obtain the header plaintext block of the first plaintext. Middle section plaintext block and the end plaintext block In the first ciphertext corresponding to the first plaintext, the first plaintext block... The corresponding header ciphertext block is denoted as , with the middle plaintext block The corresponding middle-section ciphertext block is denoted as , and the plaintext block at the end The corresponding end-of-segment ciphertext block is denoted as ;The first plaintext block Middle section plaintext block and the end plaintext block satisfy: ,and t is a prime number less than n, where This represents the length of the bit string *, where n is the block length and t is the length of the trailing plaintext; Obtain the tag corresponding to the user's initial input information from the party to be tested. When the encryption system of the party to be tested prompts the party to be tested to input an initial vector, the tag corresponding to the user's initial input information is 1; when the encryption system of the party to be tested does not prompt the party to be tested to input an initial vector, the tag corresponding to the user's initial input information is 0. Make the first judgment: If the mark is 1, and The encryption mode of the data to be detected is CBC or BC. If the mark is 0, and If so, the encryption mode of the data to be detected is ECB; If the mark is 0, and If the length of the first ciphertext is the same as the length of the first plaintext, then the encryption mode of the data to be detected is CTR. If the mark is 0, and If the length of the first ciphertext is an integer multiple of n, and the length of the first ciphertext is different from the length of the first plaintext, then the encryption mode of the data to be detected is OFBNLF. If none of the four conditions in the first judgment are met, proceed to step S32; Step S32: Obtain the header plaintext block of the second plaintext. Middle section plaintext block and the end plaintext block In the second ciphertext corresponding to the second plaintext, the first plaintext block... The corresponding header ciphertext block is denoted as , with the middle plaintext block The corresponding middle-section ciphertext block is denoted as , and the plaintext block at the end The corresponding end-of-segment ciphertext block is denoted as ;The first plaintext block Middle section plaintext block and the end plaintext block satisfy: ,Right now and The last bit of the XOR value is 1, and the remaining bits are all 0; and... , For XOR operation; Make a second judgment: like ,and , The encryption mode for the data to be detected is OFB. like ,and , The encryption mode for the data to be detected is CFB. If neither of the two conditions in the second judgment is true, proceed to step S33; Step S33: Obtain the header plaintext block of the third plaintext. Middle section plaintext block and the end plaintext block In the third ciphertext corresponding to the third plaintext, the first plaintext block... The corresponding header ciphertext block is denoted as , with the middle plaintext block The corresponding middle-section ciphertext block is denoted as , and the plaintext block at the end The corresponding end-of-segment ciphertext block is denoted as ;The first plaintext block Middle section plaintext block and the end plaintext block satisfy: , , ; Make a third judgment: like ,and The encryption mode for the data to be detected is XTS. like ,and , , If none of them are zero, then the encryption mode of the data to be tested is HCTR; If neither of the two conditions in the third judgment is met, the encryption mode of the data to be tested cannot be determined.
2. The method as described in claim 1, characterized in that, Step S3 further includes step S34: Obtain the header plaintext block of the fourth plaintext Middle section plaintext block and the end plaintext block In the fourth ciphertext corresponding to the fourth plaintext, the first plaintext block... The corresponding header ciphertext block is denoted as , with the middle plaintext block The corresponding middle-section ciphertext block is denoted as , and the plaintext block at the end The corresponding end-of-segment ciphertext block is denoted as ; The first section plaintext block Middle section plaintext block and the end plaintext block satisfy: = ; in, Let the initial vector be... The second vector is the input information of the encryption system of the party to be detected, which requires the party to be detected to input the initial vector when the encryption system of the party to be detected determines whether the initial vector is transmitted to the detection center synchronously with the generated ciphertext. Perform the fourth judgment: like The encryption mode for the data to be detected is CBC. like ,but , The encryption mode for the data to be detected is BC.
3. The method as described in claim 1 or 2, characterized in that, The encrypted working mode of the data to be detected is CBC, which means that the initial vector input by the party to be detected when encrypting the plaintext is transmitted along with the ciphertext; the encrypted working mode of the data to be detected is BC, which means that the initial vector input by the party to be detected when encrypting the plaintext is transmitted along with the ciphertext.
4. A data encryption working mode detection device under CPA mode applying the method of any one of claims 1-3, characterized in that, include: Encryption module: Configured for the testing center to use the encryption mode used by the party being tested as the encryption mode to be tested for the purpose of testing and verification. Four different plaintexts are sent to the party to be detected. The party to be detected encrypts the plaintexts respectively using the encryption mode to be detected, generating a ciphertext for each plaintext. The encryption mode to be detected is one of ECB, CBC, CFB, OFB, CTR, XTS, HCTR, BC, OFBNLF. Segmentation module: Configured to segment plaintext into a header plaintext block, a middle plaintext block that reflects encryption behavior, and a tail plaintext block that reflects padding and truncation logic; segment the ciphertext corresponding to the plaintext into a header ciphertext block, a middle ciphertext block, and a tail ciphertext block, respectively corresponding to the header plaintext block, the middle plaintext block, and the tail plaintext block. Working mode determination module: configured to determine the working mode of the encryption to be detected based on the segmentation results of the plaintext and the corresponding ciphertext.
5. A computer-readable storage medium, characterized in that, The storage medium stores a plurality of instructions; the plurality of instructions are loaded by a processor and executed as described in any one of claims 1-3.
6. An electronic device, characterized in that, The electronic device includes: A processor is used to execute multiple instructions; Memory, used to store multiple instructions; The plurality of instructions are to be stored in the memory and loaded by the processor and executed as described in any one of claims 1-3.
Citation Information
Patent Citations
Method and device for switching multiple encryption and decryption modes based on software definition
CN118523902A