Data processing method, password service module, chip and electronic device

In the public key cryptography algorithm, the modulus is used to perform modulus calculation on the to-process cipher and determine the modulus results based on the calculation results, the problem of low modulus calculation efficiency when the modulus is even is solved, and more efficient encryption algorithm performance is achieved.

CN119906544BActive Publication Date: 2025-06-13OPEN SECURITY RES INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510328025.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-19
Publication Date
2025-06-13
Estimated Expiration
2045-03-19

AI Technical Summary

Technical Problem

In the case where the processing modulus is even, the modulus calculation efficiency is low, especially in public key cryptography algorithms. Since the operands are all large numbers and the calculation amount is large, the processing efficiency is low.

Method used

When the bit length of the to-process password is less than or equal to a certain length, the odd module is determined based on the to-process module, and the to-process password is used to perform modulo calculation on the to-process password, obtain the quotient and the module, and then determine the modulo result according to the quotient and the module; when the bit length is greater than the length, the to-process password is split into integers, and the calculation process is performed based on these integers and odd modules to obtain the modulo result.

Benefits of technology

Through the above method, the modulus calculation efficiency can be effectively improved when the modulus is even, and the existing hardware accelerator that supports odd modulus is fully utilized, thereby improving the performance of the encryption algorithm.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119906544B_ABST
    Figure CN119906544B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a data processing method, a password service module, a chip, and an electronic device. The password service module receives a password service request instruction. The password service request instruction includes a password to be processed and a modulus to be processed. When the bit length of the password to be processed is less than or equal to a first length, an odd modulus is determined according to the modulus to be processed, and the password to be processed is subjected to a modulo operation using the odd modulus to obtain a first quotient and a first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1. A modulo result is determined according to the first quotient and the first modulus. Wherein, the modulo result represents the result of taking the modulo of the password to be processed using the modulus to be processed. When the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer. A first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain a modulo result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cryptography technology, and in particular, to a data processing method, a cryptographic service module, a chip, and an electronic device. Background Art

[0002] Currently, public-key cryptography algorithms have been gradually widely applied, and many data processing devices or related equipment will set up hardware accelerators to support the modulo-related operations in these cryptographic algorithms; however, these hardware accelerators only support operations with an odd modulus. Therefore, in the face of the situation where the modulus is even, a software method is usually used to calculate the large number division to complete the modulo operation; but since the operands in the public-key cryptography algorithms are all large numbers and the calculation amount is large, the current processing efficiency of the modulo operation with an even modulus is low. Summary of the Invention

[0003] Embodiments of the present application provide a data processing method, a cryptographic service module, a chip, and an electronic device, which can effectively improve the efficiency of the modulo operation when the modulus is even.

[0004] The technical solution of the embodiments of the present application is implemented as follows:

[0005] In a first aspect, an embodiment of the present application provides a data processing method, and the method includes:

[0006] Receiving a cryptographic service request instruction; the cryptographic service request instruction includes a password to be processed and a modulus to be processed;

[0007] When the bit length of the password to be processed is less than or equal to a first length, determining an odd modulus according to the modulus to be processed, and performing a modulo operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus; wherein, the modulus to be processed is even; the odd modulus is equal to the modulus to be processed plus 1;

[0008] Determining a modulo result according to the first quotient and the first modulus; wherein, the modulo result represents the result of taking the modulus of the password to be processed using the modulus to be processed;

[0009] When the bit length of the password to be processed is greater than the first length, splitting the password to be processed into a first integer and a second integer;

[0010] Performing a first operation process based on the first integer, the second integer, and the odd modulus to obtain a modulo result.

[0011] In a second aspect, an embodiment of the present application provides a cryptographic service module, and the cryptographic service module includes a receiving unit, a first determining unit, a splitting unit, and a second determining unit;

[0012] The receiving unit is configured to receive a cryptographic service request instruction; the cryptographic service request instruction includes a password to be processed and a modulus to be processed;

[0013] A first determination unit, configured to, when the bit length of the password to be processed is less than or equal to a first length, determine an odd modulus according to the modulus to be processed, and perform a modulo operation on the password to be processed by using the odd modulus to obtain a first quotient and a first modulus; and determine a modulo result according to the first quotient and the first modulus; wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; the modulo result represents the result of taking the modulo of the password to be processed by using the modulus to be processed.

[0014] A splitting unit, configured to, when the bit length of the password to be processed is greater than the first length, split the password to be processed into a first integer and a second integer.

[0015] A second determination unit, configured to determine a modulo result based on the first integer, the second integer, and the odd modulus.

[0016] In a third aspect, an embodiment of the present application provides a cryptographic chip, including a cryptographic service module and a storage module.

[0017] The cryptographic service module is configured to receive a cryptographic service request instruction; the cryptographic service request instruction includes a password to be processed and a modulus to be processed; and when the bit length of the password to be processed is less than or equal to the first length, determine an odd modulus according to the modulus to be processed, and perform a modulo operation on the password to be processed by using the odd modulus to obtain a first quotient and a first modulus; wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; and determine a modulo result according to the first quotient and the first modulus; wherein, the modulo result represents the result of taking the modulo of the password to be processed by using the modulus to be processed; and when the bit length of the password to be processed is greater than the first length, split the password to be processed into a first integer and a second integer; and perform a first operation process based on the first integer, the second integer, and the odd modulus to obtain a modulo result.

[0018] The storage module is configured to store data written by the cryptographic service module.

[0019] In a fourth aspect, an embodiment of the present application provides an electronic device, including a cryptographic chip and a software logic module.

[0020] A cryptographic chip is used to receive a cryptographic service request instruction through a cryptographic service module. The cryptographic service request instruction includes a password to be processed and a modulus to be processed. And when the bit length of the password to be processed is less than or equal to a first length, an odd modulus is determined according to the modulus to be processed, and the odd modulus is used to perform a modulo operation on the password to be processed to obtain a first quotient and a first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; and a modulo result is determined according to the first quotient and the first modulus. Wherein, the modulo result represents the result of taking the modulo of the password to be processed by the modulus to be processed. And when the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer. And a first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain a modulo result.

[0021] A software logic module is used to send a cryptographic service request instruction to the cryptographic service module in response to cryptographic processing.

[0022] Embodiments of the present application provide a data processing method, a cryptographic service module, a chip, and an electronic device. The cryptographic service module receives a cryptographic service request instruction. The cryptographic service request instruction includes a password to be processed and a modulus to be processed. When the bit length of the password to be processed is less than or equal to a first length, an odd modulus is determined according to the modulus to be processed, and the odd modulus is used to perform a modulo operation on the password to be processed to obtain a first quotient and a first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; a modulo result is determined according to the first quotient and the first modulus. Wherein, the modulo result represents the result of taking the modulo of the password to be processed by the modulus to be processed. When the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer. A first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain a modulo result. Thus, when the cryptographic service module solves the modulo operation with an even modulus for the password to be processed, if it is determined that the bit length of the password to be processed is less than or equal to the first length, the even modulus to be processed can be incremented by 1 to obtain an odd modulus, and the odd modulus is used to perform a modulo operation on the password to be processed to obtain a first quotient and a first modulus, and then the modulo result corresponding to the originally even modulus to be processed is determined according to the first quotient and the first modulus. And if it is determined that the bit length of the password to be processed is greater than the first length, the password to be processed can be first split, and then a first arithmetic process is performed on the split first integer and second integer to determine the modulo result in the case of an even modulus. Through the above method, the existing hardware accelerator conditions that support an odd modulus can be fully utilized to complete the modulo operation with an even modulus for the password to be processed with any bit length, greatly improving the efficiency of the modulo operation in the case of an even modulus. Description of the Drawings

[0023] Figure 1Schematic diagram of the electronic device proposed in the embodiments of the present application;

[0024] Figure 2 Implementation process schematic of the data processing method proposed in the embodiments of the present application Figure 1 ;

[0025] Figure 3 Implementation process schematic of the data processing method proposed in the embodiments of the present application Figure 2 ;

[0026] Figure 4 Schematic diagram of the composition structure of the password service module proposed in the embodiments of the present application. Detailed implementation manners

[0027] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. It can be understood that the specific embodiments described herein are only used to explain the related application, rather than limiting the application. In addition, it should be noted that, for the sake of description, only parts related to the related application are shown in the drawings.

[0028] Cryptographic algorithms, especially public-key cryptographic algorithms, such as the traditional encryption algorithm RSA, the Elliptic Curve Digital Signature Algorithm (ECDSA), and the SM2 elliptic curve public-key cryptographic algorithm, etc., have been more and more widely used; in order to obtain better performance to meet actual applications, hardware accelerators for these algorithms, or called coprocessors, computing engines, etc., are designed on many data processing devices or equipment. Since modular multiplication is used in these algorithms, these accelerators can all support related modular multiplication operations; however, the moduli of the modular multiplication operations in these algorithms are all odd numbers, while in some cryptographic algorithms, there will be cases where the modulus is an even number, such as user signature private key generation, signature generation, signature verification, key exchange, key encapsulation, and decryption in the SM9 elliptic curve public-key cryptographic algorithm; currently, mainly a pure software method is used to calculate the case where the modulus is an even number. However, since the core operations of these public-key cryptographic algorithms are usually large numbers and the calculation amount is large, the calculation rate is low, resulting in low performance of the encryption algorithm.

[0029] To solve the problems existing in the current related methods of password processing, the embodiments of the present application provide a data processing method, a password service module, a chip and an electronic device. The password service module in the present application can receive a password service request instruction; the password service request instruction includes a password to be processed and a modulus to be processed; when the bit length of the password to be processed is less than or equal to the first length, an odd modulus is determined according to the modulus to be processed, and the odd modulus is used to perform a modulo operation on the password to be processed to obtain a first quotient and a first modulus; wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; a modulo result is determined according to the first quotient and the first modulus; wherein, the modulo result represents the result of taking the modulus of the password to be processed by the modulus to be processed; when the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer; a first arithmetic process is performed based on the first integer, the second integer and the odd modulus to obtain a modulo result; it can greatly improve the operation efficiency of taking the modulus of a large number when the modulus is an even number, thereby improving the performance of the encryption algorithm.

[0030] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application.

[0031] An embodiment of the present application provides a data processing method, which is applied to a password service module in a password chip; as Figure 1 shown, the password chip 0 may include a password service module 1 and a storage module 3; the password service module 1 may be used to receive a password service request from an external software logic module 2 and perform a corresponding modulo operation in response to the password service request to obtain a modulo result; during this process, the password service module 1 may write the data participating in the operation and the result of the operation into the storage module 3.

[0032] Figure 2 is a schematic implementation flow of the data processing method proposed in the embodiments of the present application Figure 1 As Figure 2 shown, in the embodiments of the present application, the data processing method of the password service module may include the following steps:

[0033] Step 101, receive a password service request instruction; the password service request instruction includes a password to be processed and a modulus to be processed.

[0034] In the embodiments of the present application, the password service module may receive a password service request instruction; the password service request instruction includes a password to be processed and a modulus to be processed.

[0035] In an embodiment of the present application, the password to be processed is the password that needs to be modulo-calculated using the modulus to be processed currently, and the password to be processed can be an integer; correspondingly, the modulus to be processed is the modulus for modulo-calculating the password to be processed; for example, when calculating A mod B, A represents the password to be processed, and B represents the modulus to be processed, where B is an even number.

[0036] Step 102: When the bit length of the password to be processed is less than or equal to the first length, determine an odd modulus according to the modulus to be processed, and perform a modulo operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus; wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1.

[0037] In an embodiment of the present application, the password service module can, when the bit length of the password to be processed is less than or equal to the first length, determine an odd modulus according to the modulus to be processed, and perform a modulo operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus; wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1.

[0038] In an embodiment of the present application, "mod" represents a modulo operation, and the modulo operation can be understood as an operation for finding the remainder; for example, 0 mod 5 = 0, 7 mod 5 = 2, 3 mod 5 = 3, and the moduli of these three modulo operations are all 5.

[0039] In an embodiment of the present application, the first length can be determined according to the bit length of the modulus to be processed.

[0040] In some embodiments of the present application, the first product can be determined according to a first preset value and the bit length of the modulus to be processed, and then a subtraction operation is performed on the first product and a second preset value to obtain the first length.

[0041] Exemplarily, the bit length of the modulus to be processed is nbitlen, and the first length can be expressed as 2nbitlen - 2, where both the first preset value and the second preset value are 2.

[0042] Exemplarily, if the modulus to be processed is b, then the odd modulus can be expressed as n = b + 1.

[0043] In some embodiments of the present application, when the password service module performs a modulo operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus, it can split the password to be processed according to the bit length of the odd modulus to obtain a sixth integer and a seventh integer; then determine the first modulus based on the sixth integer and the seventh integer; determine the first quotient based on the first modulus and the password to be processed.

[0044] It can be understood that in an embodiment of the present application, the sixth integer and the seventh integer are concatenated to obtain the password to be processed.

[0045] In an embodiment of the present application, when the password service module splits the password to be processed according to the bit length of the odd modulus to obtain the sixth integer and the seventh integer, it may use the bits corresponding to the bit length of the odd modulus at the lower positions in the password to be processed as the seventh integer, that is, starting from the first bit on the right side of the password to be processed, count to the left until the number of bits equal to the bit length of the odd modulus, and use these bits as the seventh integer; then use the remaining higher - order bits as the sixth integer.

[0046] Exemplarily, the bit length of the odd modulus is nbitlen, and the password to be processed is a. Split a into a1 (the sixth integer) and a2 (the seventh integer), a = a1||a2, that is, a can be represented as the concatenation of a1 and a2; assuming a is 0x1234, a can be split into 0x12 and 0x34, that is, 0x12×0x100 + 0x34, where the bit length of 0x34 is nbitlen.

[0047] In some embodiments of the present application, when the password service module determines the first modulus based on the sixth integer and the seventh integer, it may determine the operation parameters according to the sixth integer, the seventh integer, and the odd modulus; perform a modulo operation on the operation parameters using the odd modulus to obtain the first modulus.

[0048] In some embodiments of the present application, the operation parameters may include a first parameter and a second parameter.

[0049] In some embodiments of the present application, when the password service module determines the operation parameters according to the sixth integer, the seventh integer, and the odd modulus, it may perform a modular multiplication operation according to the sixth integer, the first value, and the odd modulus to obtain the first parameter; then perform a modulo operation on the seventh integer using the odd modulus to obtain the second parameter.

[0050] In an embodiment of the present application, modular multiplication means that given a modulus m, perform a multiplication operation on two integers a and b, and then take the remainder of the result with respect to the modulus m; the operation rule of modular multiplication can be expressed as (a × b) mod m = [(a mod m) × (b mod m)] mod m.

[0051] In an embodiment of the present application, the first value can be determined according to the odd modulus; for example, the odd modulus is represented as n, the bit length of n is nbitlen, and the first value can be represented as t = 2 nbitlen mod n.

[0052] Exemplarily, the method by which the password service module performs a modular multiplication operation according to the sixth integer, the first value, and the odd modulus to obtain the first parameter can be expressed as a' 1 =a 1×t mod n, that is, the first parameter can be the result of taking the modulus of the product of the sixth integer and the first value using an odd modulus.

[0053] In some embodiments of the present application, when determining the first parameter, Montgomery modular multiplication can also be performed according to the first value and a preset parameter to obtain a second operation result; then, Montgomery modular multiplication is performed according to the second operation result and the sixth integer to obtain the first parameter.

[0054] It should be noted that in the embodiments of the present application, the cryptographic service module may include a modular multiplication accelerator and / or a Montgomery modular multiplier; when a modular multiplication accelerator is provided in the cryptographic service module, the cryptographic service module can determine the first parameter by performing modular multiplication according to the sixth integer, the first value, and the odd modulus. If there is no modular multiplication accelerator in the cryptographic service module but a Montgomery modular multiplier is provided, the first parameter can be obtained by performing the above two Montgomery modular multiplications based on the Montgomery modular multiplier.

[0055] In the embodiments of the present application, the preset parameter is a parameter for Montgomery modular multiplication.

[0056] Exemplarily, the Montgomery modular multiplication is defined as mont(x, y, n)=x×y×R ﹣1 mod n; performing Montgomery modular multiplication according to the first value and the preset parameter can be expressed as mont(t, R 2 , n)=t×R 2 ×R ﹣1 mod n, where t is the first value, R is the preset parameter, n is the odd modulus, and the second operation result obtained by this operation is expressed as tR; then, Montgomery modular multiplication is performed according to the second operation result and the sixth integer, and this method can be expressed as mont(a 1 , tR, n)=a 1 ×tR×R ﹣1 mod n, and the result obtained thereby is the first parameter a' 1 .

[0057] In some embodiments of the present application, when the cryptographic service module determines the first quotient based on the first modulus and the password to be processed, it can perform a subtraction operation on the password to be processed and the first modulus to obtain a first operation result; then, the first quotient is determined based on the preset odd number and the first operation result.

[0058] In the embodiments of the present application, the preset odd number is greater than the odd modulus.

[0059] It can be understood that by performing a subtraction operation on the password to be processed and the first modulus, the first operation result obtained is the product of the odd modulus and the first quotient.

[0060] Exemplarily, the preset odd number can be a number p greater than the product of the odd modulus and the first quotient. Then the method for determining the first quotient based on the preset odd number and the first operation result can be expressed as k 1 =C×n ﹣1 mod p, where C represents the first operation result, that is, C = k 1 n.

[0061] Exemplarily, the preset odd number can be a number p greater than the odd modulus and having the same bit length as the odd modulus. Then the process of determining the first quotient based on the preset odd number p and the first operation result C can be to first calculate t = C mod p, and then calculate the result of t×n ﹣1 mod p, and the result is the first quotient k 1 .

[0062] Step 103: Determine the modulo result according to the first quotient and the first modulus; where the modulo result represents the result of taking the modulo of the password to be processed using the modulus to be processed.

[0063] In the embodiments of the present application, when the bit length of the password to be processed is less than or equal to the first length, the password service module can determine the odd modulus according to the modulus to be processed, and perform a modulo operation on the password to be processed using the odd modulus. After obtaining the first quotient and the first modulus, determine the modulo result according to the first quotient and the first modulus; where the modulo result represents the result of taking the modulo of the password to be processed using the modulus to be processed.

[0064] In the embodiments of the present application, when performing a modulo operation on the password to be processed with an even modulus, it does not directly perform the modulo operation using the even modulus to be processed, but first determines an odd number, that is, the odd modulus, according to the modulus to be processed, and then performs a modulo operation on the password to be processed using this odd modulus to obtain the results of the quotient and the modulus, that is, the first quotient and the first modulus. Subsequently, use the first quotient and the first modulus, as well as the mathematical relationship between the result of taking the modulo with the odd modulus and the result of taking the modulo with the even modulus to obtain the result of taking the modulo corresponding to the even modulus to be processed; thus, it can first make full use of the existing hardware resources to perform the modulo operation with the odd modulus, and then directly use the result of taking the modulo with the odd modulus to determine the result of taking the modulo corresponding to the modulus to be processed. Compared with the pure software method of taking the modulo with an even modulus, it can greatly improve the speed of the modulo calculation, thereby improving the performance of the encryption algorithm.

[0065] In some embodiments of the present application, when determining the modulo result according to the first quotient and the first modulus, the sum value of the first quotient and the first modulus can be determined first; then perform a modulo operation on the sum value using the modulus to be processed to obtain the modulo result.

[0066] It can be understood that the sum value is the value obtained by adding the first quotient and the first modulus.

[0067] Exemplarily, the method of obtaining the modulo result by taking the modulo operation on the sum value using the modulo to be processed can be expressed by the following formula:

[0068] c 2 =(c 1 +k 1 ) mod (n﹣1) (1)

[0069] Wherein, c 1 represents the first modulus, k 1 represents the first quotient, n represents the odd modulus, then n﹣1 represents the modulo to be processed that is 1 less than the odd modulus.

[0070] It should be noted that the method of determining the modulo result through formula (1) above requires at most two subtractions to obtain the result. If the first quotient k 1 is less than the modulo to be processed, then at most only one subtraction is required to complete the calculation, which can reduce the time consumption of the modulo operation. Especially for the modulo operation of large numbers, it can greatly improve the efficiency of the modulo operation.

[0071] Step 104: When the bit length of the password to be processed is greater than the first length, split the password to be processed into a first integer and a second integer.

[0072] In the embodiment of the present application, the password service module can also split the password to be processed into a first integer and a second integer when the bit length of the password to be processed is greater than the first length.

[0073] In the embodiment of the present application, when the password service module splits the password to be processed into a first integer and a second integer, it can determine the first length of the high-order bits in the password to be processed as the first integer, that is, starting from the first bit on the left of the password to be processed, count to the right until the number of bits equal to the first length, and use this part of the bits as the first integer; use the remaining low-order bits as the second integer.

[0074] Exemplarily, the first length is 2nbitlen﹣2, and the bit length of the password to be processed a is greater than 2nbitlen﹣2. Then a can be split into a 3 and a 4 , where a 3 is the high 2nbitlen﹣2 bits of a, and the remaining bits can be used as a 4 .

[0075] It should be noted that in the embodiment of the present application, the execution order of step 101 and step 103 is not limited in the present application.

[0076] Step 105: Perform a first arithmetic process based on the first integer, the second integer, and the odd modulus to obtain a modulo result.

[0077] In an embodiment of the present application, when the bit length of the password to be processed is greater than the first length, after splitting the password to be processed into a first integer and a second integer, the password service module may perform a first arithmetic process based on the first integer, the second integer, and an odd modulus to obtain a modulo result.

[0078] In an embodiment of the present application, the first arithmetic process means that for the two split integers, the integer with a bit length equal to the first length is subjected to a modulo operation with an odd modulus, and after the obtained modulus is concatenated with the other integer, relevant judgments are made on the concatenated integer to determine whether the modulo result has been obtained, or whether the concatenated integer needs to be further split to perform the above modulo operation again to determine the modulo result.

[0079] In some embodiments of the present application, as Figure 3 shown, the method by which the password service module performs a first arithmetic process based on the first integer, the second integer, and an odd modulus to obtain a modulo result, that is, the method of step 105, may include the following steps:

[0080] Step 105a: Perform a modulo operation on the first integer based on the odd modulus to obtain a second modulus; where the second modulus represents the result of taking the modulo of the first integer using the modulus to be processed.

[0081] In an embodiment of the present application, when the password service module performs a first arithmetic process based on the first integer, the second integer, and an odd modulus to obtain a modulo result, it may first perform a modulo operation on the first integer based on the odd modulus to obtain a second modulus; where the second modulus represents the result of taking the modulo of the first integer using the modulus to be processed.

[0082] It should be noted that in an embodiment of the present application, performing a modulo operation on the first integer based on the odd modulus to obtain a second modulus is the same as the method of taking the modulo of the password to be processed using the odd modulus to obtain a first quotient and a first modulus, and determining the modulo result based on the first quotient and the first modulus, that is, still first performing a modulo operation on the first integer using the odd modulus, and after obtaining the quotient and the modulo result, determining the second modulus in combination with the method of formula (1) above.

[0083] Exemplarily, the password a to be processed is split into a first integer a 3 and a second integer a 4 , and the odd modulus is n, then a 1 mod n may be calculated first to obtain the second modulus.

[0084] Step 105b: Determine a third integer according to the second modulus and the second integer.

[0085] In an embodiment of the present application, after the password service module performs a modulo operation on a first integer based on an odd modulus to obtain a second modulus, it may determine a third integer according to the second modulus and a second integer.

[0086] Exemplarily, if the second modulus is represented as d, the third integer may be the concatenation of d and the second integer a 4 and the third integer may be represented as a 5 = d || a 2 .

[0087] It should be noted that, in an embodiment of the present application, according to the property of modulo operation, a mod b = a 5 mod b, where b represents the modulus to be processed; that is to say, the property of modulo operation can be used to perform a modulo operation on the dividend split from the password to be processed to obtain the modulo result. During this splitting process, the bit length of the dividend will continuously decrease, which can further improve the efficiency of the modulo operation.

[0088] Step 105c: When the third integer is less than the modulus to be processed, determine the third integer as the modulo result.

[0089] In an embodiment of the present application, after the password service module determines the third integer according to the second modulus and the second integer, when the third integer is less than the modulus to be processed, it may determine the third integer as the modulo result.

[0090] In an embodiment of the present application, when the concatenated dividend is less than the modulus to be processed, it may be determined to stop the loop process of the above splitting and modulo operation, and the modulo result has been obtained currently.

[0091] Exemplarily, when a 3 is less than the modulus to be processed b, a 3 may be determined as the modulo result of a mod b.

[0092] Step 105d: When the third integer is greater than or equal to the modulus to be processed, split the third integer into a fourth integer and a fifth integer, and perform a first arithmetic process based on the fourth integer, the fifth integer, and the odd modulus to obtain the modulo result.

[0093] In an embodiment of the present application, after the password service module determines the third integer according to the second modulus and the second integer, when the third integer is greater than or equal to the modulus to be processed, it may split the third integer into a fourth integer and a fifth integer, and perform a first arithmetic process based on the fourth integer, the fifth integer, and the odd modulus to obtain the modulo result.

[0094] It can be understood that in the embodiments of the present application, if the third integer is greater than or equal to the modulus to be processed, it means that the third integer needs to be continuously split and the subsequent modulo operation is required to obtain the modulo result.

[0095] In some embodiments of the present application, when the bit length of the fourth integer is less than the first length, the password service module can pad the fourth integer with zero bits to obtain the padded fourth integer with a bit length equal to the first length; that is, if the bit length of the split fourth integer is less than the first length, zero bits can be used for padding, so that the bit length of the dividend in each loop calculation is consistent.

[0096] It can be understood that in the embodiments of the present application, if the bit length of the split fourth integer is less than the first length, the fifth integer is empty.

[0097] In summary, in the embodiments of the present application, if the bit length of the password to be processed is less than or equal to the first length, the mathematical relationship between the modulo even reduction and the modulo odd reduction can be directly determined, so that the existing hardware resources can be used to perform the modulo odd reduction to obtain the quotient and the modulus, and then the result of the modulo even reduction can be determined in combination with the mathematical relationship; if the bit length of the password to be processed is greater than the first length, the length of the input large number can be continuously shortened, that is, the password to be processed is split, and the modulo operation is performed on the split integer in the foregoing manner of the modulo odd reduction, and finally the result is obtained; based on the above method, efficient modulo operation can be achieved for large numbers of any length, the hardware resources that support the modulo odd reduction can be fully utilized, and the efficiency of the modulo even reduction is greatly improved.

[0098] An embodiment of the present application provides a data processing method. The password service module receives a password service request instruction, which includes a password to be processed and a modulus to be processed. Then, when the bit length of the password to be processed is less than or equal to the first length, an odd modulus is determined according to the modulus to be processed, and the odd modulus is used to perform a modulo operation on the password to be processed to obtain a first quotient and a first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; the modulo result is determined according to the first quotient and the first modulus. Wherein, the modulo result represents the result of taking the modulus of the password to be processed using the modulus to be processed. When the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer; a first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain the modulo result. It can be seen that when the password service module solves the modulo operation with an even modulus for the password to be processed, if it is determined that the bit length of the password to be processed is less than or equal to the first length, the even modulus to be processed can be incremented by 1 to obtain an odd modulus, and the odd modulus is used to perform a modulo operation on the password to be processed to obtain a first quotient and a first modulus, and then the modulo result corresponding to the originally even modulus to be processed is determined according to the first quotient and the first modulus; if it is determined that the bit length of the password to be processed is greater than the first length, the password to be processed can be split first, and then a first arithmetic process is performed on the split first integer and second integer to determine the modulo result in the case of an even modulus; through the above method, the existing hardware accelerator conditions that support odd moduli can be fully utilized to complete the modulo operation with an even modulus for passwords to be processed with any bit length, greatly improving the modulo operation efficiency in the case of an even modulus.

[0099] Based on the above embodiment, in another embodiment of the present application, a method for deriving the mathematical relationship between the above-mentioned modulo reduction with an even modulus and modulo reduction with an odd modulus is provided, that is, a method for deriving the above formula (1).

[0100] Exemplarily, c = a mod b, where b is a positive even number and a is a positive integer greater than b; let n be an odd number greater than b, that is, b = n - 1; if c 1 = a mod n, then there exists a positive integer k 1 , such that a = k 1 n + c 1 , where 0 ≤ c 1 < n.

[0101] Exemplarily, c 2 = a mod (n - 1), that is, c 2 = c = a mod b, then there exists an integer k 2 , such that a = k 2 (n - 1) + c 2 = k 2 n + (c2 -k 2 ), where 0 ≤ c 2 < n - 1; thus a = k 1 n + c 1 = k 2 n + (c 2 -k 2 ).

[0102] It should be noted that if k 1 and k 2 are both less than n, then there must be k 1 = k 2 or k 1 = k 2 -1. The following is the proof of this conclusion:

[0103] If c 2 ≥ k 2 , then 0 ≤ (c 2 -k 2 ) < (n - 1) < n. Thus, (c 2 -k 2 ) = a mod n, and c 1 = a mod n, so c 1 = (c 2 -k 2 ), and thus k 1 = k 2 .

[0104] If c 2 < k 2 , then -n < (c 2 -k 2 ) < 0. Thus, 0 < n + (c 2 -k 2 ) < n. So, a = k 1 n + c 1 = (k 2 -1)n + n + c 2 -k 2 , then k 1 = k 2 -1, c 1 = n + c 2 -k 2 .

[0105] Thus, it can be seen that the relationship among k 1 , c 1 , k 2 , c 2 can be divided into two cases: k 1 = k 2 , then c 2 = c1 + k 1 ; k 1 = k 2 −1, then c 2 = c 1 + k 2 −n = c 1 + k 1 −(n − 1).

[0106] Based on the summary of the above two cases, it can be concluded that after calculating k 1 and c 1 , c 2 can be obtained by calculating the aforementioned formula (1); among them, since c 1 can be at most n − 1, and k 1 is also at most n − 1, therefore, this calculation only requires at most two subtractions, and the calculation time consumption is small.

[0107] In some embodiments of the present application, for the method of calculating k 1 and c 1 , for a chip or device provided with a general large number division accelerator, k 1 and c 1 can be easily calculated, but usually there are fewer such devices, and more commonly there are chips provided with hardware cryptographic operation accelerators; for example, in order to support the implementation of public key algorithms such as RSA, ECDSA, and SM2, hardware accelerators for large number addition and subtraction, modular multiplication operation, or Montgomery modular multiplication are designed on the chip, and k 1 and c 1 can be calculated by using these accelerators on such devices.

[0108] In some embodiments of the present application, first c 1 can be calculated, and c 1 can be obtained by the method of finding the remainder with an odd modulus; assume that the bit length of the odd modulus n is nbitlen, and a is split into a 1 and a 2 , where the bit length of a 2 is , that is, the same as the bit length of the odd modulus n; since k 1 < n, and c 1 < n, then a = k 1 n + c 1 ≤(n - 1)n + c 1 = n 2 −n + c 1 < n 2 , and the bit length of n 2 is less than 2nbitlen, so a1 has a bit length less than nbitlen; calculate c as follows 1 The method can allow a 1 to have a bit length equal to nbitlen; c 1 The calculation method can be expressed by the following formula:

[0109] c 1 = a mod n = (a 1 || a 2 ) mod n = (a 1 × 2 nbitlen + a 2 ) mod n = (a 1 × t + a 2 ) mod n

[0110] = ((a 1 × t mod n) + (a 2 mod n)) mod n = (a' 1 + a' 2 ) mod n (2)

[0111] where t = 2 nbitlen mod n, and this operation only requires one subtraction; a' 1 = a 1 × t mod n, and this operation is a typical modular multiplication operation that can be completed by a modular multiplication accelerator; a' 2 = a 2 mod n, and this operation also requires at most one subtraction.

[0112] If there is no modular multiplication accelerator but there is a Montgomery modular multiplier, the Montgomery modular multiplier can also be used to implement the calculation of a' 1 ; for example, define the Montgomery modular multiplication operation as mont(x, y, n) = x × y × R ﹣1 mod n; then the second operation result tR = mont(t, R 2 , n) = t × R 2 × R ﹣1 mod n, then a' 1 = a 1 × t mod n = mont(a 1 , tR, n) = a 1 × tR × R ﹣1 mod n; where R is a parameter of the Montgomery modular multiplication operation, and usually the Montgomery accelerator will provide the function of calculating R 2 mod n. Given the odd modulus n, since R is known, R 2mod n, thereby saving computation time when performing Montgomery modular multiplication operations.

[0113] In some embodiments of the present application, when c is calculated, 1 Later, based on c 1 Calculate k 1 ; First, k 1 n=a﹣c 1 , so we can use the obtained c 1 Subtract it from a first, and get k 1 n, then calculate k 1 There are two methods to do this; one of them is to take a ratio k 1 n is a large odd number p, calculate k 1 n×n ﹣1 mod p to get k 1 , n ﹣1 mod p can be pre-calculated; another way is to take an odd number p that is larger than n and has the same bit length as n, and first calculate t=k 1 n mod p, then calculate t×n ﹣1 mod p to get k 1 , similarly, n ﹣1 mod p can be precomputed.

[0114] It is understandable that after obtaining c 1 and k 1 Later, you can use c 1 and k 1 And the above formula (1) gives the modulo result c 2 .

[0115] For example, the cryptographic function H is used in the user signature private key generation, signature generation, signature verification, key exchange, key encapsulation and decryption processes in the SM9 algorithm. 1 and H 2 , both functions involve the operation Ha mod (n-1), where Ha is a large number that can be up to 320 bits, the modulus n of an odd number is a 256-bit prime number, and the modulus n-1 is an even number of 256 bits; obviously, the integer part of Ha / n and Ha / (n-1) is only 320-256=64 bits at most, which is much smaller than 256 bits, thus satisfying the above k 1 and k 2 If all are less than n, the above method can be used to calculate the modulo result c 2 ; Assume a=Ha, b=(n-1), then c 2The result of =a mod b is the modulo result to be obtained; considering that the curve parameters of the SM9 algorithm are fixed, some data can be pre-computed during the calculation to improve the calculation performance; for example, the even modulus n−1 can be: 0xB6400000 02A3A6F1 D603AB4F F58EC744 49F2934B 18EA8BEE E56EE19C D69ECF24; calculate c 1 It takes 2 256 mod n, then c can be pre-computed 1 and stored, for example c 1 can be: 0x49BFFFFF FD5C590E29FC54B0 0A7138BB B60D6CB4 E7157411 1A911E63 296130DC; when using the first of the two aforementioned methods to calculate k 1 calculate k 1 When calculating k, an odd number p larger than k 1 n can be preset first. Considering that a = Ha in the SM9 algorithm is 320 bits, a 321-bit p can be preset. For example, p can be: 0x01 283E3080 5A596C47 6D1CFCF74F747031 B8FA9B83 957A94BD F52285F5 68C985F2 434ED486 A732F1C7; n ﹣ 1 mod p can be calculated as: 0x00 015C0136 540E907E ABE64F2F 8AFC5E04 BE89694F 0B7006FF 11BCCE93952D7A05 DCE2A985 5CF46F88, and then k ﹣1 can be calculated based on n 1 mod p; for the other method of calculating k 1 An odd number p with the same bit length as n but larger than n can be preset. For example, p can be 0xF61C44AEB5B89C3A F56C7EA8 B2C82BC2 E4226F23 0B85FC40 9FFB9643 5716F3CB; n ﹣ 1 mod p can be calculated as: 0x25D2FF7D 030650D3 958EA0ED 7221E006 E6C6E254 163469EF A609B952E92EAE9E, and then k ﹣1 can be calculated based on n 1 .

[0116] The above method of calculating a mod (n-1), where n-1 is an even number, has a constraint condition, namely k 1 =a / n and k 2 =a / n-1 must be less than n; in fact, for any positive integer a, the method for calculating a mod (n-1) is as follows:

[0117] Assuming that the bit length of n is nbitlen, the bit length of the even modulus b=(n-1) is also nbitlen; if the bit length of a is less than or equal to 2nbitlen-2, the above method can be used directly for calculation, because: a<2 2nbitlen-2 , and 2 2nbitlen-1 <n<2 2nbitlen ,but , , , so we can get ,Right now ; similarly, there are ,but , , , so we can get ,Right now , which can satisfy the aforementioned conditions, can be directly calculated using the aforementioned method.

[0118] For example, if the bit length of a is greater than 2nbitlen-2, a may be split, and the high 2nbitlen-2 bits of a are split into a 3 , the remaining bits are split into a 4 , and then use the above method to calculate a' 3 =a 3 mod (n-1), and then let a'= a' 3 || a 2 , that is, a' is a' 3 and a 2 According to the properties of modular arithmetic, a mod (n-1) = a' mod(n-1), but since a' is at least 2 bits, therefore, by continuing this process, the bit length of the modulus will continue to decrease, and eventually the result of a mod (n-1) can be obtained; in this process, if the length of the high-order bit part of a split is less than 2nbitlen-2, the high-order bit part of the split integer can be padded with zero bits to make the bit length reach 2nbitlen-2, so that the bit length of the modulus calculated each time can be consistent to improve the calculation efficiency.

[0119] Exemplarily, the password service module includes a Field Programmable Gate Array (FPGA) with a modular multiplication hardware accelerator, which calculates the even modulus reduction a mod (n - 1). Here, n is selected as the curve order of the SM9 algorithm, which is a 256-bit large prime number. There are three cases for the value of a. The first case is a 320-bit large number, which is consistent with the actual calculation length in the SM9 algorithm. The second case is a 209-bit large number. Both of these two cases can meet the usage conditions of the calculation method where the bit length of a is less than or equal to 2nbitlen - 2. The third case is that a is 1200 bits. In this case, it meets the usage conditions of the calculation method where the bit length of a is greater than 2nbitlen - 2.

[0120] Exemplarily, the even modulus reduction is calculated respectively by the current pure software method and the method proposed in the embodiments of the present application. For the first case where a is a 320-bit large number, if the even modulus reduction is calculated by the current pure software method, the number of calculations that can be performed in one second is 412 times. However, if the method proposed in the embodiments of the present application is used, 2304 calculations can be performed in one second. For the second case where a is a 209-bit large number, if the even modulus reduction is calculated by the current pure software method, the number of calculations that can be performed in one second is 105 times. However, if the method proposed in the embodiments of the present application is used, 2304 calculations can be performed in one second. For the third case where a is a 1200-bit large number, if the even modulus reduction is calculated by the current pure software method, the number of calculations that can be performed in one second is 29.3 times. However, if the method proposed in the embodiments of the present application is used, 201.7 calculations can be performed in one second. Thus, it can be seen that for the first case of the value of a, that is, when a is 64 bits more than the modulus (n - 1), compared with the pure software implementation, the method of the embodiments of the present application can improve the calculation performance of the even modulus reduction by 459%. For the second case, that is, when the bit length of a is approximately equal to twice the bit length of the modulus, compared with the current software method, using the method of the embodiments of the present application can improve the calculation performance by more than 20 times. For the third case, that is, when the bit length of a is approximately equal to four times the bit length of the modulus, compared with the current software method, using the method of the embodiments of the present application can improve the calculation performance by nearly 20 times.

[0121] In the embodiments of the present application, if the chip of the password service module already has hardware accelerators such as large number reduction and modular multiplication operations, due to factors such as the chip area and cost, it is not possible to make major changes to the chip, and it is not convenient to directly design a hardware accelerator for modular even number reduction. Then, based on the existing hardware accelerator, the method in the embodiments of the present application can be implemented in a hardware manner, with less modification to the hardware accelerator. In this way, software operations can be further reduced to continuously improve the performance of modular even number reduction, thereby improving the performance of related password processing algorithms.

[0122] In summary, in the embodiments of the present application, through derivation, regardless of the bit length of the large number a that needs to perform modular even number reduction, it can be classified into two cases. One is when the bit length of the large number a is less than or equal to 2nbitlen - 2, then the modular result can be directly determined by using the mathematical relationship between modular even number reduction and modular odd number reduction. That is, after calculating the quotient k1 and modulus c1 of modular odd number reduction, the modular result of modular even number reduction can be determined by using the quotient k1, modulus c1, and the mathematical relationship between modular even number reduction and modular odd number reduction shown in the foregoing formula (1). If the bit length of the large number a is greater than 2nbitlen - 2, then a can be split to continuously shorten the length of the input large number, and the modular operation is performed on the split integers in the manner of the foregoing modular odd number reduction, and finally the result is obtained. Based on the above method, efficient modular operations can be achieved for large numbers of any length. The hardware resources that support modular odd number reduction can be fully utilized to perform the calculation of modular odd number reduction. Then, based on the calculation result of modular odd number reduction, the modular result can be quickly determined by using the foregoing formula (1). This process requires at most only two subtractions to complete the calculation. Even when implemented in software, the calculation time can be greatly shortened, effectively improving the efficiency of modular even number reduction or modular operation of modular even numbers, thereby improving the performance of the password algorithm.

[0123] An embodiment of the present application provides a data processing method. The password service module receives a password service request instruction. The password service request instruction includes a password to be processed and a modulus to be processed. When the bit length of the password to be processed is less than or equal to the first length, an odd modulus is determined according to the modulus to be processed, and the odd modulus is used to perform a modulo operation on the password to be processed, obtaining a first quotient and a first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1. A modulo result is determined according to the first quotient and the first modulus. Wherein, the modulo result represents the result of taking the modulo of the password to be processed using the modulus to be processed. When the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer. A first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain a modulo result. Thus, when the password service module solves the modulo operation with an even modulus for the password to be processed, if it is determined that the bit length of the password to be processed is less than or equal to the first length, the even modulus to be processed can be incremented by 1 to obtain an odd modulus, and the odd modulus is used to perform a modulo operation on the password to be processed, obtaining a first quotient and a first modulus, and then the modulo result corresponding to the originally even modulus to be processed is determined according to the first quotient and the first modulus. If it is determined that the bit length of the password to be processed is greater than the first length, the password to be processed can be split first, and then a first arithmetic process is performed on the split first integer and second integer to determine the modulo result in the case of an even modulus. Through the above method, the existing hardware accelerator conditions that support odd moduli can be fully utilized to complete the modulo operation of an even modulus for a password to be processed with any bit length, greatly improving the efficiency of the modulo operation in the case of an even modulus.

[0124] Based on the above embodiment, in another embodiment of the present application, Figure 4 is a schematic structural diagram of the password service module proposed in the embodiment of the present application, as Figure 4 shown, the password service module 1 proposed in the embodiment of the present application may include: a receiving unit 11, a first determining unit 12, a splitting unit 13, and a second determining unit 14.

[0125] The receiving unit 11 is configured to receive a password service request instruction. The password service request instruction includes a password to be processed and a modulus to be processed.

[0126] The first determining unit 12 is configured to, when the bit length of the password to be processed is less than or equal to the first length, determine an odd modulus according to the modulus to be processed, and use the odd modulus to perform a modulo operation on the password to be processed, obtaining a first quotient and a first modulus; and determine a modulo result according to the first quotient and the first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; the modulo result represents the result of taking the modulo of the password to be processed using the modulus to be processed.

[0127] The splitting unit 13 is used to split the password to be processed into a first integer and a second integer when the bit length of the password to be processed is greater than the first length.

[0128] The second determination unit 14 is used to perform a first operation process based on the first integer, the second integer, and the odd modulus to obtain a modulo result.

[0129] In some embodiments of the present application, the second determination unit 14 is further used to perform a modulo operation on the first integer based on the odd modulus to obtain a second modulus; wherein the second modulus represents the result of performing a modulo operation on the first integer using the modulus to be processed; and determine a third integer according to the second modulus and the second integer; and when the third integer is less than the modulus to be processed, determine the third integer as the modulo result; and when the third integer is greater than or equal to the modulus to be processed, split the third integer into a fourth integer and a fifth integer, and perform a first operation process based on the fourth integer, the fifth integer, and the odd modulus to obtain a modulo result.

[0130] In some embodiments of the present application, the first determination unit 12 is further used to determine the sum value of the first quotient and the first modulus; and perform a modulo operation on the sum value using the modulus to be processed to obtain a modulo result.

[0131] In some embodiments of the present application, the first determination unit 12 is further used to split the password to be processed according to the bit length of the odd modulus to obtain a sixth integer and a seventh integer; and determine a first modulus based on the sixth integer and the seventh integer; and determine a first quotient based on the first modulus and the password to be processed.

[0132] In some embodiments of the present application, the first determination unit 12 is further used to determine operation parameters according to the sixth integer, the seventh integer, and the odd modulus; and perform a modulo operation on the operation parameters using the odd modulus to obtain a first modulus.

[0133] In some embodiments of the present application, the operation parameters include a first parameter and a second parameter; the first determination unit 12 is further used to perform a modular multiplication operation according to the sixth integer, the first value, and the odd modulus to obtain a first parameter; and perform a modulo operation on the seventh integer using the odd modulus to obtain a second parameter.

[0134] In some embodiments of the present application, the first determination unit 12 is further used to perform a Montgomery modular multiplication operation according to the first value and a preset parameter to obtain a second operation result; and perform a Montgomery modular multiplication operation according to the second operation result and the sixth integer to obtain a first parameter.

[0135] In some embodiments of the present application, the first determination unit 12 is further used to perform a subtraction operation on the password to be processed and the first modulus to obtain a first operation result; and determine a first quotient based on a preset odd number and the first operation result.

[0136] An embodiment of the present application provides a password service module. The password service module receives a password service request instruction. The password service request instruction includes a password to be processed and a modulus to be processed. When the bit length of the password to be processed is less than or equal to a first length, an odd modulus is determined according to the modulus to be processed, and the password to be processed is subjected to a modulo operation using the odd modulus to obtain a first quotient and a first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1. A modulo result is determined according to the first quotient and the first modulus. Wherein, the modulo result represents the result of taking the modulus of the password to be processed using the modulus to be processed. When the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer. A first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain a modulo result. Thus, when the password service module solves the modulo operation with an even modulus for the password to be processed, if it is determined that the bit length of the password to be processed is less than or equal to the first length, the even modulus to be processed can be incremented by 1 to obtain an odd modulus, and the password to be processed is subjected to a modulo operation using the odd modulus to obtain a first quotient and a first modulus, and then the modulo result corresponding to the originally even modulus to be processed is determined according to the first quotient and the first modulus. If it is determined that the bit length of the password to be processed is greater than the first length, the password to be processed can be split first, and then a first arithmetic process is performed on the split first integer and second integer to determine the modulo result in the case of an even modulus. Through the above method, the existing hardware accelerator conditions supporting an odd modulus can be fully utilized to complete the modulo operation of an even modulus for a password to be processed with any bit length, greatly improving the efficiency of the modulo operation in the case of an even modulus.

[0137] Based on the above embodiment, in another embodiment of the present application, further, an electronic device is proposed in an embodiment of the present application, as Figure 1 shown. The electronic device may include a password chip 0 and a software logic module 2. Wherein, the software logic module 2 may be in the form of a processor or the like.

[0138] The password chip 0 can be used to receive a password service request instruction through the password service module 1. The password service request instruction includes a password to be processed and a modulus to be processed. And when the bit length of the password to be processed is less than or equal to a first length, an odd modulus is determined according to the modulus to be processed, and the password to be processed is subjected to a modulo operation using the odd modulus to obtain a first quotient and a first modulus. Wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1. And a modulo result is determined according to the first quotient and the first modulus. Wherein, the modulo result represents the result of taking the modulus of the password to be processed using the modulus to be processed. And when the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer. And a first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain a modulo result.

[0139] The software logic module 2 can be used to send a password service request instruction to the password service module in response to password processing.

[0140] The software logic module 2 can also be used to control the password service module 1 in the password chip 0 to obtain data from the storage module 3 to execute the data processing method provided by the embodiments of the present application.

[0141] Furthermore, an embodiment of the present application proposes a password chip. As Figure 1 shown, the password chip 0 may include a password service module 1 and a storage module 3.

[0142] The password service module 1 can be used to receive a password service request instruction; the password service request instruction includes a password to be processed and a modulus to be processed; and when the bit length of the password to be processed is less than or equal to the first length, an odd modulus is determined according to the modulus to be processed, and the odd modulus is used to perform a modulo operation on the password to be processed to obtain a first quotient and a first modulus; wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; and a modulo result is determined according to the first quotient and the first modulus; wherein, the modulo result represents the result of taking the modulus of the password to be processed using the modulus to be processed; and when the bit length of the password to be processed is greater than the first length, the password to be processed is split into a first integer and a second integer; and a first arithmetic process is performed based on the first integer, the second integer, and the odd modulus to obtain the modulo result.

[0143] The storage module 3 can be used to store the data written by the password service module.

[0144] In some embodiments of the present application, the storage module 3 can be used to store at least one of the password to be processed, the modulus to be processed, the odd modulus, the first quotient, the first modulus, and the modulo result written by the password service module during the execution of the data processing method.

[0145] In an embodiment of the present application, the above-mentioned processor may be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), an FPGA, a Central Processing Unit (CPU), a controller, a microcontroller, and a microprocessor. It can be understood that for different devices, the electronic devices for implementing the functions of the above-mentioned processor may also be others, and the embodiments of the present application do not make specific limitations.

[0146] In an embodiment of the present application, the electronic device may further include a bus for connecting software logic modules, a cryptographic chip, and for mutual communication between these devices.

[0147] In practical applications, the above-mentioned storage module may be a volatile memory, such as a Random-Access Memory (RAM); or a non-volatile memory, such as a Read-Only Memory (ROM), a flash memory, a Hard Disk Drive (HDD), or a Solid-State Drive (SSD); or a combination of the above types of memories.

[0148] In addition, in this embodiment, each functional module may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional module.

[0149] When an integrated unit is implemented in the form of a software functional module and is not 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 embodiment, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the method of this embodiment. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks, or optical discs that can store program codes.

[0150] Specifically, the program instructions corresponding to a data processing method in this embodiment can be stored on storage media such as optical discs, hard disks, and USB flash drives. When the program instructions corresponding to a data processing method in the storage medium are read or executed by an electronic device, the following steps are included:

[0151] Receive a password service request instruction; the password service request instruction includes a password to be processed and a modulus to be processed.

[0152] In the case where the bit length of the password to be processed is less than or equal to the first length, determine an odd modulus according to the modulus to be processed, and perform a modulo operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus; wherein, the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1.

[0153] Determine a modulo result according to the first quotient and the first modulus; wherein, the modulo result represents the result of taking the modulus of the password to be processed using the modulus to be processed.

[0154] In the case where the bit length of the password to be processed is greater than the first length, split the password to be processed into a first integer and a second integer.

[0155] Perform a first arithmetic process based on the first integer, the second integer, and the odd modulus to obtain a modulo result.

[0156] The embodiment of the present application provides a computer program product, including a computer program or instructions. When the computer program or instructions are executed by a processor, the computer is caused to execute the steps in the method provided by the above method embodiment.

[0157] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories and optical memories, etc.) that contain computer-usable program code.

[0158] The present application is described with reference to the schematic flow diagrams and / or block diagrams of the implementation processes of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the schematic flow diagrams and / or block diagrams, as well as the combination of processes and / or blocks in the schematic flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to generate a machine, such that the instructions executed by the processors of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0159] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0160] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0161] The above is only the preferred embodiment of the present application and is not used to limit the protection scope of the present application.

Claims

1. A data processing method, characterized in that: Applied to a cryptographic service module, the method comprises: Receiving a cryptographic service request instruction; the cryptographic service request instruction includes a password to be processed and a modulus to be processed; In the case where the bit length of the password to be processed is less than or equal to the first length, determining an odd modulus according to the modulus to be processed, and performing a modulus operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus; wherein the modulus to be processed is an even number; and the odd modulus is equal to the modulus to be processed plus 1; Determine a modulus result according to the first quotient and the first modulus; wherein the modulus result represents a result of taking a modulus of the password to be processed using the modulus to be processed; When the bit length of the password to be processed is greater than the first length, splitting the password to be processed into a first integer and a second integer; A first operation is performed based on the first integer, the second integer, and the odd modulus to obtain the modulus result.

2. The data processing method according to claim 1, characterized in that: The performing a first operation based on the first integer, the second integer, and the odd modulus to obtain the modulus result includes: Performing a modulo operation on the first integer based on the odd modulus to obtain a second modulus; wherein the second modulus represents a result of performing a modulo operation on the first integer using the modulus to be processed; determining a third integer according to the second modulus and the second integer; In a case where the third integer is smaller than the modulus to be processed, determining the third integer as the modulus result; When the third integer is greater than or equal to the modulus to be processed, the third integer is split into a fourth integer and a fifth integer, and the first operation is performed based on the fourth integer, the fifth integer and the odd modulus to obtain the modulus result.

3. The data processing method according to claim 2, characterized in that: The determining a module result according to the first quotient and the first module includes: determining a sum of the first quotient and the first modulus; The modulus to be processed is used to perform a modulo operation on the sum value to obtain the modulo result.

4. The data processing method according to any one of claims 1 to 3, characterized in that: The step of performing a modulus operation on the password to be processed by using the odd modulus to obtain a first quotient and a first modulus includes: Splitting the password to be processed according to the bit length of the odd modulus to obtain a sixth integer and a seventh integer; determining the first modulus based on the sixth integer and the seventh integer; The first quotient is determined based on the first modulus and the password to be processed.

5. The data processing method according to claim 4, characterized in that: The determining the first modulus based on the sixth integer and the seventh integer comprises: Determine an operation parameter according to the sixth integer, the seventh integer and the odd modulus; The odd modulus is used to perform a modulo operation on the operation parameter to obtain the first modulus.

6. The data processing method according to claim 5, characterized in that: The operation parameters include a first parameter and a second parameter; and determining the operation parameters according to the sixth integer, the seventh integer and the odd modulus includes: Perform a modular multiplication operation according to the sixth integer, the first value, and the odd modulus to obtain the first parameter; A modulo operation is performed on the seventh integer using the odd modulus to obtain the second parameter.

7. The data processing method according to claim 4, characterized in that: The determining the first quotient based on the first modulus and the password to be processed includes: Performing a subtraction operation on the password to be processed and the first module to obtain a first operation result; The first quotient is determined based on a preset odd number and the first operation result.

8. A cryptographic service module, characterized in that: The cryptographic service module includes a receiving unit, a first determining unit, a splitting unit, and a second determining unit; The receiving unit is used to receive a cryptographic service request instruction; the cryptographic service request instruction includes a password to be processed and a modulus to be processed; The first determining unit is used to determine an odd modulus according to the modulus to be processed, and perform a modulus operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus, and determine a modulus result according to the first quotient and the first modulus, when the bit length of the password to be processed is less than or equal to the first length; wherein the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; and the modulus result represents a result of performing a modulus operation on the password to be processed using the modulus to be processed; The splitting unit is used to split the password to be processed into a first integer and a second integer when the bit length of the password to be processed is greater than the first length; The second determining unit is used to perform a first operation based on the first integer, the second integer and the odd modulus to obtain the modulus result.

9. A cryptographic chip, characterized in that: It includes a cryptographic service module and a storage module; The cryptographic service module is configured to receive a cryptographic service request instruction; the cryptographic service request instruction includes a password to be processed and a modulus to be processed; and when the bit length of the password to be processed is less than or equal to a first length, determine an odd modulus according to the modulus to be processed, and use the odd modulus to perform a modulus operation on the password to be processed to obtain a first quotient and a first modulus; wherein the modulus to be processed is an even number; the odd modulus is equal to the modulus to be processed plus 1; and determine a modulus result according to the first quotient and the first modulus; wherein the modulus result represents a result of performing a modulus operation on the password to be processed using the modulus to be processed; and when the bit length of the password to be processed is greater than the first length, split the password to be processed into a first integer and a second integer; and perform a first operation based on the first integer, the second integer and the odd modulus to obtain the modulus result; The storage module is used to store the data written by the cryptographic service module.

10. An electronic device, characterized in that: Including cryptographic chip and software logic module; The cryptographic chip is used to receive a cryptographic service request instruction through a cryptographic service module; the cryptographic service request instruction includes a to-be-processed cryptographic code and a to-be-processed modulus; and when the bit length of the to-be-processed cryptographic code is less than or equal to a first length, determine an odd modulus according to the to-be-processed modulus, and use the odd modulus to perform a modulus operation on the to-be-processed cryptographic code to obtain a first quotient and a first modulus; wherein the to-be-processed modulus is an even number; the odd modulus is equal to the to-be-processed modulus plus 1; and determine a modulus result according to the first quotient and the first modulus; wherein the modulus result represents a result of performing a modulus operation on the to-be-processed cryptographic code using the to-be-processed modulus; and when the bit length of the to-be-processed cryptographic code is greater than the first length, split the to-be-processed cryptographic code into a first integer and a second integer; and perform a first operation based on the first integer, the second integer and the odd modulus to obtain the modulus result; The software logic module is used to send the cryptographic service request instruction to the cryptographic service module in response to cryptographic processing.

Citation Information

Patent Citations

  • Unsigned processing method of modular inversion algorithm and modular inversion accelerator

    CN105577372A

  • FFT hardware accelerator and data processing method

    CN115525244A