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

By receiving the password service request instruction in the password service module, determining the odd modulus and performing modulus calculations, the problem of low modulus calculation efficiency when the modulus is even in the prior art is solved, and efficient modulus calculations for any bit-length cryptographic codes are realized, and the performance of the public key cryptographic algorithm is improved.

CN119906544AActive Publication Date: 2025-04-29OPEN SECURITY RES INC

Patent Information

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

AI Technical Summary

Technical Problem

In the case where the modulus is even, the modulus calculation efficiency is low, resulting in poor performance of the public key cryptography algorithm.

Method used

By receiving the password service request instruction, the odd module is determined based on the to-process module, and the to-process password is performed using the odd module to perform modulo calculation, the first quotient and the first modulo are obtained, and the modulo result is determined. If the bit length of the to-process password is greater than a certain length, it is divided into an integer part and a remainder part, and the corresponding calculation process is performed.

Benefits of technology

It effectively improves the modulus calculation efficiency when the modulus is even, makes full use of hardware accelerators that support odd modulus, and improves the performance of the public key cryptography algorithm.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119906544A_ABST
    Figure CN119906544A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses 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 comprises a to-be-processed password and a to-be-processed modulus; under the condition that the bit length of the to-be-processed password is smaller than or equal to the first length, determining an odd modulus according to the to-be-processed modulus, and performing modulo operation on the to-be-processed password 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 to-be-processed modulus plus 1; determining a model result according to the first quotient and the first model; wherein the modulo result represents a result of performing modulo operation on the to-be-processed password by using the to-be-processed modulus; under the condition that the bit length of the to-be-processed password is greater than the first length, splitting the to-be-processed password into a first integer and a second integer; and performing first operation processing based on the first integer, the second integer and the odd modulus to obtain a modulus result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] At present, public key cryptographic algorithms are gradually being widely used, and many data processing devices or related equipment will be equipped with hardware accelerators to support the modulus-related operations in these cryptographic algorithms; however, these hardware accelerators only support operations where the modulus is an odd number. Therefore, when faced with the situation where the modulus is an even number, software methods are usually used to perform large number division calculations to complete the modulus; but since the operands in the public key cryptographic algorithms are all large numbers and the amount of calculation is large, the current processing efficiency of modulus operations for even modulus is low. Summary of the invention

[0003] The 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 modulus operations when the modulus is an even number.

[0004] The technical solution of the embodiment of the present application is implemented as follows: In a first aspect, an embodiment of the present application provides a data processing method, the method comprising: Receiving 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 the first length, determine the 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; and the odd modulus is equal to the modulus to be processed plus 1; Determine a modulo result according to the first quotient and the first modulus; wherein the modulo result represents the result of taking a 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, 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 a modulus result.

[0005] In a second aspect, an embodiment of the present application provides a cryptographic service module, the cryptographic service module comprising a receiving unit, a first determining unit, a splitting unit, and a second determining unit; A receiving unit, 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; A first determining unit is used to determine an odd modulus according to the modulus to be processed when the bit length of the password to be processed is less than or equal to the first length, and to perform a modulus operation on the password to be processed using the odd modulus to obtain a first quotient and a first modulus; and to determine a modulus 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; and the modulus result represents a result of performing a modulus operation on the password to be processed using the modulus to be processed; a splitting unit, configured 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 determine a modulus result based on the first integer, the second integer and the odd modulus.

[0006] In a third aspect, an embodiment of the present application provides a cryptographic chip, including a cryptographic service module and a storage module; A cryptographic service module is used to receive a cryptographic service request instruction; the cryptographic service request instruction includes a to-be-processed password and a to-be-processed modulus; and when the bit length of the to-be-processed password 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 password 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 taking a modulus of the to-be-processed password using the to-be-processed modulus; and when the bit length of the to-be-processed password is greater than the first length, split the to-be-processed password 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 a modulus result; The storage module is used to store the data written by the password service module.

[0007] In a fourth aspect, an embodiment of the present application provides an electronic device, including a cryptographic chip and a software logic module; A cryptographic chip, used for receiving 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, determining an odd modulus according to the to-be-processed modulus, and performing a modulus operation on the to-be-processed cryptographic code using the odd modulus 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 determining 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, splitting the to-be-processed cryptographic code into a first integer and a second integer; and performing a first operation based on the first integer, the second integer and the odd modulus to obtain a modulus result; The software logic module is used to send a cryptographic service request instruction to the cryptographic service module in response to the cryptographic processing.

[0008] The embodiments of the present application provide a data processing method, a cryptographic service module, a chip and an electronic device, wherein 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 a modulus operation is performed 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; a modulus result is determined according to the first quotient and the first modulus; wherein the modulus result represents a result of modulo operation on 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 operation is performed based on the first integer, the second integer and the odd modulus to obtain a modulus result. It can be seen that when the cryptographic service module solves the modulus operation of the password to be processed with an even modulus, if it is determined that the bit length of the password to be processed is less than or equal to the first length, 1 can be added to the modulus to be processed, which is an even number, to obtain an odd modulus, and the odd modulus is used to perform a modulus operation on the password to be processed to obtain a first quotient and a first modulus, and then the modulus result corresponding to the modulus to be processed, which was originally an even number, is determined based on 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 split first, and then the first integer and the second integer after the split can be subjected to the first operation to determine the modulus result when the modulus is an even number; through the above method, the existing hardware accelerator conditions that support odd modulus can be fully utilized to complete the modulus operation of even modulus of the password to be processed with any bit length, greatly improving the efficiency of the modulus operation when the modulus is an even number. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] Figure 1 A schematic diagram of an electronic device proposed in an embodiment of the present application; Figure 2 Schematic diagram of the implementation process of the data processing method proposed in this application embodiment Figure 1 ; Figure 3 Schematic diagram of the implementation process of the data processing method proposed in this application embodiment Figure 2 ; Figure 4 A schematic diagram of the composition structure of the cryptographic service module proposed in the embodiment of the present application. DETAILED DESCRIPTION

[0010] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. It is understood that the specific embodiments described herein are only used to explain the related applications, rather than to limit the applications. It should also be noted that, for ease of description, only the parts related to the related applications are shown in the drawings.

[0011] 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, have been increasingly widely used. In order to obtain better performance to meet practical applications, hardware accelerators, or coprocessors, computing engines, etc., for these algorithms are designed on many data processing devices or equipment. Since modular multiplication is used in these algorithms, these accelerators can support related modular multiplication operations. However, the modulus of modular multiplication operations in these algorithms is an odd number, while some cryptographic algorithms may encounter the situation 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, the calculation of the case where the modulus is an even number is mainly performed through pure software methods. However, since the core operations of these public key cryptographic algorithms are usually large numbers and the amount of calculation is large, the calculation rate is low, which leads to poor performance of the encryption algorithm.

[0012] In order to solve the problems existing in the relevant methods of current cryptographic processing, the embodiments of the present application provide a data processing method, a cryptographic service module, a chip and an electronic device. The cryptographic service module in the present application can receive 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 a modulus operation is performed 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; a modulus result is determined according to the first quotient and the first modulus; wherein the modulus result represents the result of modulo operation 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 operation is performed based on the first integer, the second integer and the odd modulus to obtain a modulus result; the operation efficiency of modulo operation on large numbers when the modulus is an even number can be greatly improved, thereby improving the performance of the encryption algorithm.

[0013] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

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

[0015] Figure 2 Schematic diagram of the implementation process of the data processing method proposed in this application embodiment Figure 1 ,like Figure 2 As shown, in an embodiment of the present application, the data processing method of the cryptographic service module may include the following steps: Step 101: Receive a cryptographic service request instruction; the cryptographic service request instruction includes a password to be processed and a modulus to be processed.

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

[0017] In an embodiment of the present application, the password to be processed is the password that currently needs to be moduloed with the modulus to be processed, and the password to be processed can be an integer; accordingly, the modulus to be processed is the modulus with which the password to be processed is moduloed; for example, when calculating AmodB, A represents the password to be processed, and B represents the modulus to be processed, where B is an even number.

[0018] Step 102: When the bit length of the password to be processed is less than or equal to the first length, determine the 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; and the odd modulus is equal to the modulus to be processed plus 1.

[0019] In an embodiment of the present application, the cryptographic service module can determine the odd modulus based on the modulus to be processed when the bit length of the password to be processed is less than or equal to the first length, 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; and the odd modulus is equal to the modulus to be processed plus 1.

[0020] In the embodiments of the present application, mod represents a modulo operation, which can be understood as an operation of finding a 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.

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

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

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

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

[0025] In some embodiments of the present application, when the cryptographic service module uses an odd modulus to perform a modulus operation on the password to be processed to obtain a first quotient and a first modulus, the password to be processed can be split according to the bit length of the odd modulus to obtain a sixth integer and a seventh integer; then the first modulus is determined based on the sixth integer and the seventh integer; and the first quotient is determined based on the first modulus and the password to be processed.

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

[0027] In an embodiment of the present application, when the cryptographic 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, the bits corresponding to the bit length of the low-order odd modulus in the password to be processed can be used 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 to the bits equal to the bit length of the odd modulus, and take this part of the bits as the seventh integer; then the remaining high-order bits are used as the sixth integer.

[0028] Exemplarily, the bit length of the odd modulus is nbitlen, the password to be processed is a, a is split into a1 (the sixth integer) and a2 (the seventh integer), a= a1|| a2, that is, a can be expressed 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.

[0029] In some embodiments of the present application, when the cryptographic service module determines the first modulus based on the sixth integer and the seventh integer, it can determine the operation parameters according to the sixth integer, the seventh integer and the odd modulus; and use the odd modulus to perform a modulus operation on the operation parameters to obtain the first modulus.

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

[0031] In some embodiments of the present application, when the cryptographic service module determines the operation parameters based on the sixth integer, the seventh integer and the odd modulus, it can perform a modular multiplication operation based on the sixth integer, the first value and the odd modulus to obtain a first parameter; and then use the odd modulus to perform a modular operation on the seventh integer to obtain a second parameter.

[0032] In the embodiments of the present application, modular multiplication refers to multiplying two integers a and b given a modulus m, and then taking the remainder of the result with respect to the modulus m; the modular multiplication operation rule can be expressed as (a × b) mod m = [(a mod m) × (b mod m)] mod m.

[0033] 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 by n, the bit length of n is nbitlen, and the first value can be represented by t=2 nbitlen mod n.

[0034] Exemplarily, the cryptographic service module performs modular multiplication on the sixth integer, the first value and the odd modulus to obtain the first parameter, which can be expressed as a'1=a1×t mod n, that is, the first parameter can be the result of performing a modular operation on the product of the sixth integer and the first value using the odd modulus.

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

[0036] It should be noted that, in an embodiment 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 may determine the first parameter by performing a modular multiplication operation based on the sixth integer, the first numerical value and an odd modulus; if there is no modular multiplication accelerator in the cryptographic service module but a Montgomery modular multiplier is provided, the first parameter may be obtained by performing the above-mentioned two Montgomery modular multiplication operations based on the Montgomery modular multiplier.

[0037] In the embodiment of the present application, the preset parameters are parameters of the Montgomery modular multiplication operation.

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

[0039] 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; and then determine the first quotient based on a preset odd number and the first operation result.

[0040] In an embodiment of the present application, the preset odd number is greater than the odd modulus.

[0041] It can be understood that, when a subtraction operation is performed 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.

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

[0043] Exemplarily, the preset odd number can be a number p that is greater than the odd modulus and whose bit length is consistent with the bit length of 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 t×n ﹣1 The result of mod p is the first quotient k1.

[0044] Step 103, determining 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.

[0045] In an embodiment of the present application, the cryptographic service module can determine an odd modulus based on the modulus to be processed when the bit length of the password to be processed is less than or equal to the first length, and use the odd modulus to perform a modulus operation on the password to be processed, and after obtaining a first quotient and a first modulus, determine a modulus result based on the first quotient and the first modulus; wherein the modulus result represents the result of taking the modulus of the password to be processed using the modulus to be processed.

[0046] In an embodiment of the present application, when performing a modulo operation on an even modulus of a password to be processed, the modulo operation is not performed directly using the even modulus to be processed, but an odd number, i.e., an odd modulus, is first determined based on the modulus to be processed, and then the modulo operation is performed using the odd modulus to obtain a quotient and a modulus result, i.e., a first quotient and a first modulus, and then the first quotient and the first modulus, as well as the mathematical relationship between the result of the modulo operation of the odd modulus and the result of the modulo operation of the even modulus are used to obtain the modulo result corresponding to the modulus to be processed of the even number; thereby, the existing hardware resources can be fully utilized to perform the modulo operation of the odd modulus, and then the result of the modulo operation of the odd modulus is directly used to determine the modulo result corresponding to the modulus to be processed, which can greatly improve the speed of the modulo calculation compared to the pure software method for performing modulo operation on even modulus numbers, thereby improving the performance of the encryption algorithm.

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

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

[0049] Exemplarily, a method of performing a modulo operation on the sum value using the modulus to be processed to obtain a modulo result can be expressed as the following formula: c2=(c1+k1) mod (n-1) (1) Wherein, c1 represents the first modulus, k1 represents the first quotient, n represents an odd modulus, and n-1 represents a modulus to be processed that is 1 less than the odd modulus.

[0050] It should be noted that the above method of determining the modulus result through formula (1) only requires two subtractions at most to obtain the result. If the first quotient k1 is smaller than the modulus to be processed, only one subtraction is required at most to complete the calculation, which can reduce the time consumption of the modulus operation, especially for the modulus operation of large numbers, and can greatly improve the efficiency of the modulus operation.

[0051] 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.

[0052] In an embodiment of the present application, the password service module may further 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.

[0053] In an embodiment of the present application, when the password service module splits the password to be processed into a first integer and a second integer, the high-order bits of the first length in the password to be processed can be determined as the first integer, that is, starting from the first bit on the left side of the password to be processed, count to the right to the bits with a bit length equal to the first length, and take this part of the bits as the first integer; and take the remaining low-order bits as the second integer.

[0054] Exemplarily, the first length is 2nbitlen-2, and the bit length of the password a to be processed is greater than 2nbitlen-2. a can be split into a3 and a4, where a3 is the high 2nbitlen-2 bits of a, and the remaining bits can be used as a4.

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

[0056] Step 105: Perform a first operation based on the first integer, the second integer, and the odd modulus to obtain a modulus result.

[0057] In an embodiment of the present application, when the bit length of the password to be processed is greater than the first length, the cryptographic service module splits the password to be processed into a first integer and a second integer, and then performs a first operation based on the first integer, the second integer and the odd modulus to obtain a modulus result.

[0058] In an embodiment of the present application, the first operation processing represents a processing method of performing a modulus operation of an odd modulus on the integer whose bit length is equal to the first length among the two split integers, and after concatenating the obtained modulus with another integer, performing relevant judgment on the concatenated integer to determine whether the modulus result has been obtained, or continuing to split the concatenated integer to perform the above-mentioned modulus operation again to determine the modulus result.

[0059] In some embodiments of the present application, Figure 3 As shown, the cryptographic service module performs a first operation based on the first integer, the second integer and the odd modulus to obtain a modulus result, that is, the method of step 105 may include the following steps: Step 105a: perform 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.

[0060] In an embodiment of the present application, when the cryptographic service module performs a first operation based on a first integer, a second integer and an odd modulus to obtain a modulus result, it can first perform a modulus 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 modulus operation on the first integer using the modulus to be processed.

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

[0062] Exemplarily, the password a to be processed is split into a first integer a3 and a second integer a4, and the odd modulus is n, then a1 mod n can be calculated first to obtain the second modulus.

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

[0064] In an embodiment of the present application, after the cryptographic service module performs a modulo operation on the first integer based on the odd modulus to obtain the second modulus, the third integer can be determined according to the second modulus and the second integer.

[0065] Exemplarily, the second modulus is expressed as d, and the third integer may be a concatenation of d and the second integer a4, and the third integer may be expressed as a5=d||a2.

[0066] It should be noted that, in the embodiments of the present application, according to the properties of the modular operation, a mod b = a5mod b, where b represents the modulus to be processed; that is, the properties of the modular operation can be used to perform a modular operation on the modulus split from the password to be processed to obtain a modular result. During this splitting process, the bit length of the modulus will continue to decrease, which can further improve the efficiency of the modular operation.

[0067] Step 105c: when the third integer is smaller than the modulus to be processed, determine the third integer as the modulus result.

[0068] In an embodiment of the present application, after determining the third integer according to the second modulus and the second integer, the cryptographic service module may determine the third integer as the modulus result if the third integer is smaller than the modulus to be processed.

[0069] In an embodiment of the present application, when the modulus after splicing is smaller than the modulus to be processed, it can be determined to stop the above splitting and modulo operation cycle, and the modulo result has been obtained.

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

[0071] 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, perform a first operation based on the fourth integer, the fifth integer and the odd modulus, and obtain a modulus result.

[0072] In an embodiment of the present application, after the cryptographic service module determines the third integer based on the second modulus and the second integer, if the third integer is greater than or equal to the modulus to be processed, the third integer can be split into a fourth integer and a fifth integer, and a first operation can be performed based on the fourth integer, the fifth integer and the odd modulus to obtain a modulus result.

[0073] It can be understood that, in the embodiment 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 further split and subsequently modulo operations need to be performed to obtain the modulo result.

[0074] In some embodiments of the present application, the cryptographic service module may, when the bit length of the fourth integer is less than the first length, pad the fourth integer with zero bits to obtain a padded fourth integer having 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, it may be padded with zero bits, so that the bit length of the modulus calculated in each cycle can be made consistent.

[0075] It can be understood that, in the embodiment of the present application, if the bit length of the fourth integer obtained by splitting is less than the first length, the fifth integer is empty.

[0076] To summarize, in an embodiment 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 modulo odd reduction can be performed using existing hardware resources to obtain the quotient and the modulus, and then the result of the modulo even reduction is determined based on the mathematical relationship; and 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 integers in accordance with the aforementioned modulo odd reduction method to finally obtain the result; based on the above method, efficient modulo operation can be achieved for large numbers of any length, and hardware resources that can support modulo odd reduction can be fully utilized, greatly improving the efficiency of modulo even reduction.

[0077] 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 processing 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 processing 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 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.

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

[0079] 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 c1 = a mod n, then there exists a positive integer k1 such that a = k1n + c1, where 0 ≤ c1 < n.

[0080] Exemplarily, c2 = a mod (n - 1), that is, c2 = c = a mod b, then there exists an integer k2 such that a = k2(n - 1) + c2 = k2n + (c2 - k2), where 0 ≤ c2 < n - 1; thus, a = k1n + c1 = k2n + (c2 - k2).

[0081] It should be noted that if both k1 and k2 are less than n, then necessarily k1 = k2 or k1 = k2 - 1. The following is the proof of this conclusion: If \(c2\geq k2\), then \(0\leq(c2 - k2)<(n - 1)<n\). So, \((c2 - k2)=a\bmod n\). Since \(c1 = a\bmod n\), we have \(c1=(c2 - k2)\), and thus \(k1 = k2\).

[0082] If \(c2<k2\), then \(-n<(c2 - k2)<0\), so \(0<n+(c2 - k2)<n\). Then, \(a = k1n + c1=(k2 - 1)n + n + c2 - k2\), which gives \(k1 = k2 - 1\) and \(c1=n + c2 - k2\).

[0083] It can be seen that the relationship between \(k1\), \(c1\), \(k2\), and \(c2\) can be divided into two cases: when \(k1 = k2\), \(c2 = c1 + k1\); when \(k1 = k2 - 1\), \(c2 = c1 + k2 - n = c1 + k1-(n - 1)\).

[0084] Based on the summary of the above two cases, it can be concluded that after calculating \(k1\) and \(c1\), \(c2\) can be obtained by calculating the aforementioned formula (1). Since \(c1\) can be at most \(n - 1\) and \(k1\) can also be at most \(n - 1\), this calculation requires at most two subtractions, and the calculation time is relatively small.

[0085] In some embodiments of the present application, for the method of calculating \(k1\) and \(c1\), for a chip or device equipped with a general large-number division accelerator, it is easy to calculate \(k1\) and \(c1\). However, such devices are usually few, and more commonly, there are chips equipped with hardware cryptographic operation accelerators. For example, to support the implementation of public-key algorithms such as RSA, ECDSA, and SM2, hardware accelerators for large-number addition, subtraction, modular multiplication, or Montgomery modular multiplication are designed on the chip, and these accelerators can be used to complete the calculation of \(k1\) and \(c1\) on such devices.

[0086] In some embodiments of the present application, first, \(c1\) can be calculated. \(c1\) can be obtained by the method of finding the remainder of an odd modulus. Assume that the bit length of the odd modulus \(n\) is \(nbitlen\). Split \(a\) into \(a1\) and \(a2\), where the bit length of \(a2\) is , that is, the same as the bit length of the odd modulus \(n\). Since \(k1 < n\) and \(c1 < n\), then \(a = k1n + c1\leq(n - 1)n + c1=n 2 -n + c1 < n 2 , and the bit length of \(n 2 is less than \(2nbitlen\), so the bit length of \(a1\) is less than \(nbitlen\). The following method for calculating \(c1\) allows the bit length of \(a1\) to be equal to \(nbitlen\). The calculation method of \(c1\) can be expressed by the following formula: c1=a mod n=( a1|| a2) mod n=( a1×2 nbitlen +a2) mod n=(a1×t+ a2) mod n =(( a1×t mod n)+( a2mod n)) mod n=(a'1+a'2) mod n (2) Where t=2 nbitlen mod n, this operation only requires one subtraction; a'1= a1×t mod n, this operation is a typical modular multiplication operation and can be completed by a modular multiplication accelerator; a'2= a2mod n, this operation also only requires one subtraction at most.

[0087] 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, the Montgomery modular multiplication operation is defined 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=a1×t mod n= mont(a1,tR,n)=a1×tR×R ﹣1 mod n; where R is the parameter of the Montgomery modular multiplication operation. Usually the Montgomery accelerator will provide the calculation R 2 mod n function, when an odd modulus n is determined, R can be calculated in advance because R is known 2 mod n, thereby saving computation time when performing Montgomery modular multiplication operations.

[0088] In some embodiments of the present application, after c1 is calculated, k1 can be calculated based on c1. First, k1n=a-c1, so c1 and a can be used to perform a subtraction to obtain k1n. Next, there are two methods for calculating k1. One method is to take an odd number p greater than k1n and calculate k1n×n. ﹣1 mod p we can get k1,n ﹣1 mod p can be precomputed; another way is to take an odd number p that is larger than n and has the same bit length as n, first calculate t=k1n mod p, and then calculate t×n ﹣1 mod p we can get k1, similarly, n ﹣1 mod p can be precomputed.

[0089] It can be understood that after obtaining c1 and k1, the modulo result c2 can be obtained by using c1 and k1 and the above formula (1).

[0090] Exemplarily, the user signature private key generation, signature generation, signature verification, key exchange, key encapsulation and decryption processes in the SM9 algorithm all use cryptographic functions H1 and H2. Both functions involve the operation Ha mod (n-1), where Ha is a large number that can be up to 320 bits, the odd modulus n is a prime number of 256 bits, 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 aforementioned condition that both k1 and k2 are less than n, and the above method can be used to calculate the modulus result c2; assuming a=Ha, b=(n-1), then the result of c2=a mod b is the modulus result to be obtained; considering that the curve parameters of the SM9 algorithm are fixed, some data can be pre-calculated during the calculation process to improve the calculation performance; for example, the even modulus n-1 can be: 0xB6400000 02A3A6F1 D603AB4F F58EC744 49F2934B 18EA8BEE E56EE19C D69ECF24; Calculation of c1 requires 2 256 mod n, c1 can be calculated in advance and stored, for example, c1 can be: 0x49BFFFFF FD5C590E29FC54B0 0A7138BB B60D6CB4 E7157411 1A911E63 296130DC; when calculating k1 using the first of the two methods for calculating k1, an odd number p larger than k1n 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 can be calculated first ﹣ 1 mod p is: 0x00 015C0136 540E907E ABE64F2F 8AFC5E04 BE89694F 0B7006FF 11BCCE93952D7A05 DCE2A985 5CF46F88, which can be based on n ﹣1mod p calculates k1; for another method of calculating k1, an odd number p that is the same as the bit length of n but larger than n can be preset, for example, p can be 0xF61C44AEB5B89C3A F56C7EA8 B2C82BC2 E4226F23 0B85FC40 9FFB9643 5716F3CB; n can be calculated first ﹣ 1 mod p is: 0x25D2FF7D 030650D3 958EA0ED 7221E006 E6C6E254 163469EF A609B952E92EAE9E, which can be based on n ﹣1 k1 is calculated mod p.

[0091] The above method of calculating a mod (n-1) when n-1 is an even number has a constraint condition, that is, k1=a / n and k2=a / n-1 must be less than n; in fact, for any positive integer a, the method of calculating a mod (n-1) is as follows: 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.

[0092] For example, if the bit length of a is greater than 2nbitlen-2, a can be split into a3 with the high 2nbitlen-2 bits of a and a4 with the remaining bits. Then, a'3=a3mod (n-1) is calculated using the above method. Then, let a'= a'3|| a2, that is, a' is the concatenation of a'3 and a2. According to the properties of modular operation, a mod (n-1)= a' mod(n-1). However, since a' is at least 1 / 2 smaller than the bit length of a, 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.

[0093] Exemplarily, the cryptographic service module includes a field programmable gate array (FPGA) with a modular multiplication hardware accelerator, which calculates the reduction of an even modulus a mod (n-1), where n is selected using the curve order of the SM9 algorithm, which is a large prime number of 256 bits, and there are three cases for the value of a. The first is a large number of 320 bits, which is consistent with the actual calculation length in the SM9 algorithm, and the second is a large number of 209 bits. Both cases can meet the use conditions of the aforementioned calculation method that the bit length of a is less than or equal to 2nbitlen-2; the third case is that a is 1200 bits, in which case the use conditions of the calculation method that the bit length of a is greater than 2nbitlen-2 are met.

[0094] Exemplarily, the even modulus reduction is calculated by the current pure software method and the method proposed in the embodiment of the present application respectively; for the first value case where a is a large number of 320 bits, if the current pure software method is used to calculate the even modulus reduction, the number of calculations that can be made in one second is 412 times, and if the method proposed in the embodiment of the present application is used for calculation, the number of calculations that can be made in one second is 2304 times; for the second value case where a is a large number of 209 bits, if the current pure software method is used to calculate the even modulus reduction, the number of calculations that can be made in one second is 105 times, and if the method proposed in the embodiment of the present application is used for calculation, the number of calculations that can be made in one second is 2304 times; for the third value case where a is a large number of 1200 bits, if the current pure software method is used to calculate the even modulus reduction, The number of calculations that can be made in one second is 29.3 times, while if the method proposed in the embodiment of the present application is used for calculation, the number of calculations that can be made in one second is 201.7 times; thus, for the first value of a, that is, when a is 64 bits more than the modulus (n-1), compared with pure software implementation, the method in the embodiment of the present application can improve the calculation performance of 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, the method in the embodiment 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, the method in the embodiment of the present application can improve the calculation performance by nearly 20 times.

[0095] In an embodiment of the present application, if the chip of the cryptographic service module already has hardware accelerators such as large number reduction and modular multiplication operations, it is not possible to make major changes to the chip due to factors such as chip area and cost, and it is not convenient to directly design a hardware accelerator for modular even number reduction. In this case, the method in the embodiment of the present application can be implemented in hardware based on the existing hardware accelerator, with relatively small changes to the hardware accelerator. This can further reduce software actions to continue to improve the performance of modular even number reduction, thereby improving the performance of related cryptographic processing algorithms.

[0096] In summary, in the embodiments of the present application, after deduction, no matter what the bit length of the large number a to be subjected to even modulus reduction is, it can be classified into two cases. One is that when the bit length of the large number a is less than or equal to 2nbitlen-2, the modulus result can be directly determined by using the mathematical relationship between the modulus even number reduction and the modulus odd number reduction, that is, after calculating the quotient k1 and modulus c1 of the odd modulus reduction, the modulus result of the even modulus reduction is determined by using the quotient k1 and modulus c1 and the mathematical relationship between the modulus even number reduction and the modulus odd number reduction shown in the above formula (1); and if the bit length of the large number a is greater than 2nbitlen-2, the modulus result of the even modulus reduction can be determined by using a is split to continuously shorten the length of the input large number, and the split integers are modulo-operated in accordance with the aforementioned modulo-odd number reduction method to finally obtain the result; based on the above method, efficient modulo-operation can be achieved for large numbers of any length, and hardware resources that can support modulo-odd number reduction can be fully utilized to perform modulo-odd number reduction calculations, and then based on the calculation results of the modulo-odd number reduction, the aforementioned formula (1) can be used to quickly determine the modulo result. This process only requires two subtractions at most to complete the calculation. Even if it is implemented in software, it can greatly shorten the calculation time and effectively improve the efficiency of even modulo reduction or modulo-operation of even modulos, thereby improving the performance of the cryptographic algorithm.

[0097] An embodiment of the present application provides a data processing method, in which a 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 a modulus operation is performed 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; a modulus result is determined according to the first quotient and the first modulus; wherein the modulus result represents a result of modulo operation 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 operation is performed based on the first integer, the second integer and the odd modulus to obtain a modulus result. It can be seen that when the cryptographic service module solves the modulus operation of the password to be processed with an even modulus, if it is determined that the bit length of the password to be processed is less than or equal to the first length, 1 can be added to the modulus to be processed, which is an even number, to obtain an odd modulus, and the odd modulus is used to perform a modulus operation on the password to be processed to obtain a first quotient and a first modulus, and then the modulus result corresponding to the modulus to be processed, which was originally an even number, is determined based on 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 split first, and then the first integer and the second integer after the split can be subjected to the first operation to determine the modulus result when the modulus is an even number; through the above method, the existing hardware accelerator conditions that support odd modulus can be fully utilized to complete the modulus operation of even modulus of the password to be processed with any bit length, greatly improving the efficiency of the modulus operation when the modulus is an even number.

[0098] Based on the above embodiment, in another embodiment of the present application, Figure 4 This is a schematic diagram of the composition structure of the cryptographic service module proposed in the embodiment of the present application, such as Figure 4 As shown, the cryptographic 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.

[0099] The receiving unit 11 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.

[0100] The first determination unit 12 is used to determine the odd modulus according to the modulus to be processed when the bit length of the password to be processed is less than or equal to the first length, 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; and determine a modulus 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; and the modulus result represents the result of taking the modulus of the password to be processed using the modulus to be processed.

[0101] 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.

[0102] The second determining unit 14 is configured to perform a first operation based on the first integer, the second integer and the odd modulus to obtain a modulus result.

[0103] 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 a result of performing a modulo operation on the first integer using the modulus to be processed; and determining a third integer based on the second modulus and the second integer; and when the third integer is less than the modulus to be processed, determining the third integer as the modulo result; and when the third integer is greater than or equal to the modulus to be processed, splitting the third integer into a fourth integer and a fifth integer, and performing a first operation based on the fourth integer, the fifth integer and the odd modulus to obtain a modulo result.

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

[0105] 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 the first modulus based on the sixth integer and the seventh integer; and determine the first quotient based on the first modulus and the password to be processed.

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

[0107] 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 based on the sixth integer, the first numerical value and the odd modulus to obtain the first parameter; and use the odd modulus to perform a modular operation on the seventh integer to obtain the second parameter.

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

[0109] In some embodiments of the present application, the first determination unit 12 is further configured 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.

[0110] An embodiment of the present application provides a cryptographic service module, which 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 a modulus operation is performed 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; a modulus result is determined according to the first quotient and the first modulus; wherein the modulus result represents a result of modulo operation 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 operation is performed based on the first integer, the second integer and the odd modulus to obtain a modulus result. It can be seen that when the cryptographic service module solves the modulus operation of the password to be processed with an even modulus, if it is determined that the bit length of the password to be processed is less than or equal to the first length, 1 can be added to the modulus to be processed, which is an even number, to obtain an odd modulus, and the odd modulus is used to perform a modulus operation on the password to be processed to obtain a first quotient and a first modulus, and then the modulus result corresponding to the modulus to be processed, which was originally an even number, is determined based on 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 split first, and then the first integer and the second integer after the split can be subjected to the first operation to determine the modulus result when the modulus is an even number; through the above method, the existing hardware accelerator conditions that support odd modulus can be fully utilized to complete the modulus operation of even modulus of the password to be processed with any bit length, greatly improving the efficiency of the modulus operation when the modulus is an even number.

[0111] Based on the above embodiment, in another embodiment of the present application, further, the present application embodiment proposes an electronic device, such as Figure 1 As shown, the electronic device may include a cryptographic 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.

[0112] The cryptographic chip 0 can be used to receive a cryptographic service request instruction through the cryptographic service module 1; 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, determining an odd modulus according to the to-be-processed modulus, and performing a modulus operation on the to-be-processed cryptographic code using the odd modulus 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 determining 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, splitting the to-be-processed cryptographic code into a first integer and a second integer; and performing a first operation based on the first integer, the second integer and the odd modulus to obtain a modulus result.

[0113] The software logic module 2 may be configured to send a cryptographic service request instruction to the cryptographic service module in response to the cryptographic processing.

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

[0115] Furthermore, the present application embodiment provides a cryptographic chip, such as Figure 1 As shown, the cryptographic chip 0 may include a cryptographic service module 1 and a storage module 3 .

[0116] A cryptographic service module 1 can be 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; and 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 using 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 determining a modulus result according to the first quotient and the first modulus; wherein the modulus 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, splitting the password to be processed into a first integer and a second integer; and performing a first operation based on the first integer, the second integer and the odd modulus to obtain a modulus result.

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

[0118] 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 modulus result written by the cryptographic service module during the execution of the data processing method.

[0119] In the embodiments of the present application, the 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 is understandable that for different devices, the electronic device used to implement the functions of the processor may also be other, and the embodiments of the present application do not specifically limit this.

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

[0121] In practical applications, the above-mentioned storage module can be a volatile memory (volatile memory), such as a random access memory (Random-Access Memory, RAM); or a non-volatile memory (non-volatile memory), such as a read-only memory (Read-Only Memory, ROM), a flash memory (flash memory), a hard disk drive (Hard Disk Drive, HDD) or a solid-state drive (SSD); or a combination of the above-mentioned types of memory.

[0122] In addition, each functional module in this embodiment can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or software functional modules.

[0123] If the integrated unit is implemented in the form of a software function 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 is essentially or the part that contributes to the prior art or the whole or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor to perform all or part of the steps of the method of this embodiment. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.

[0124] Specifically, the program instructions corresponding to a data processing method in this embodiment may be stored on a storage medium such as a CD, a hard disk, or a USB flash drive. 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: Receiving 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 the first length, determine the 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; and the odd modulus is equal to the modulus to be processed plus 1; Determine a modulo result according to the first quotient and the first modulus; wherein the modulo result represents the result of taking a 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, 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 a modulus result.

[0125] An 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 executes the steps in the method provided in the above method embodiment.

[0126] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Moreover, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program codes.

[0127] The present application is described with reference to the implementation flowcharts and / or block diagrams 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 box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0128] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which is implemented in the implementation flow diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0129] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process described in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0130] The above are only preferred embodiments of the present application and are not intended 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

  • Acceleration device and method for fully homomorphic encryption operation

    CN119148980A

  • System, Apparatus And Method For Performing A Plurality Of Cryptographic Operations

    US20190044718A1

  • Method and apparatus for accelerating preliminary operations for cryptographic processing

    US7187770B1

Cited By

  • Data sequence out-of-order processing method and device, chip, storage medium and product

    CN121309151A