Hardware implementation method and system for dual-domain modular inversion and encryption method
By constructing a state machine and a computation unit, and combining mode selection and preset modular inverse strategy, the modular inverse operation of prime number field and binary field is simplified, solving the problem of high complexity of modular inverse operation in the existing technology, and achieving faster computing speed and lower resource consumption.
Patent Information
- Application Number
- CN202410972626.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2024-11-26
AI Technical Summary
Existing technologies have complex hardware implementation schemes for modular inverse operations, slow calculation speed, and high resource consumption, making it difficult to perform modular inverse operations on prime number fields and binary fields efficiently.
A state machine and a computation unit are constructed. The prime field or binary field state machine is selected by the mode selection bit. The modular inverse operation is performed by using a preset modular inverse strategy. Combined with shift, addition and subtraction operations, the computation process is simplified and resource consumption is reduced.
It improves the speed and efficiency of modular inverse operations, reduces the resource consumption of hardware implementation, is suitable for various application scenarios, and enhances computing speed and resource utilization.
Smart Images

Figure CN119030701A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information security technology, and in particular to a hardware implementation method, system and encryption method of dual-domain modular inversion. Background Art
[0002] Modular inversion is one of the most critical and complex operations in public key cryptography algorithms. Its computational efficiency determines the speed of the entire encryption and decryption module. For the modular inversion function implemented in hardware, related technologies usually implement it through solutions such as Fermat's Little Theorem, extended Euclidean algorithm, and Stein algorithm. However, these solutions require complex modular exponentiation, modular division, or modular multiplication operations, with complex states, difficult hardware implementation, and slow calculation speed. It consumes a lot of resources. Summary of the invention
[0003] The purpose of the present invention is to solve one of the technical problems existing in the prior art to at least a certain extent.
[0004] To this end, the purpose of the present invention is to provide an efficient hardware implementation method, system and encryption method for dual-domain modular inversion.
[0005] In order to achieve the above technical objectives, one aspect of an embodiment of the present invention provides a hardware implementation method for dual-domain modular inversion, including the following steps: constructing a state machine and an operation unit; according to the mode selection bit, selecting to jump to the prime domain state machine, or, jumping to the binary domain state machine; based on the current state machine, calling the operation unit through a preset modular inversion strategy, performing modular inversion operation, and determining the target result; the preset modular inversion strategy includes: determining the initial values of the first parameter, the second parameter, the third parameter, and the fourth parameter; according to the parity of the second parameter and the fourth parameter, updating the first parameter, the second parameter, the third parameter, and the fourth parameter; according to the updated first parameter, the second parameter, the third parameter, and the fourth parameter, determining the target result. The embodiment of the present application constructs a state machine and an operation unit, wherein the state machine can be used in the prime domain or in the binary domain, and can perform hardware implementation of modular inversion operations in the prime domain and the binary domain; the embodiment of the present application implements modular inversion operations through a preset modular inversion strategy, and performs shift, addition, and subtraction operations according to the parity of the relevant parameters to determine the target result. The computing process of the embodiment of the present application is simple and can be easily implemented through hardware, which is beneficial to improving computing speed and reducing resource consumption.
[0006] In some embodiments, in the hardware implementation method of the dual-domain modular inversion of the embodiment of the present invention, the determining of the initial values of the first parameter, the second parameter, the third parameter and the fourth parameter includes:
[0007] Determine that the initial value of the first parameter is 1, the initial value of the third parameter is 0, and the second parameter is a given positive integer;
[0008] If the current state machine is the prime number domain state machine, the initial value of the fourth parameter is determined to be the modulus of the prime number domain; or, if the current state machine is the binary number domain state machine, the initial value of the fourth parameter is determined to be an irreducible polynomial of the binary number domain.
[0009] In some embodiments, in one embodiment of the present invention, updating the first parameter, the second parameter, the third parameter and the fourth parameter according to the parity of the second parameter and the fourth parameter includes:
[0010] If the second parameter is an even number, update the first parameter and the second parameter;
[0011] Alternatively, if the fourth parameter is an even number, updating the third parameter and the fourth parameter;
[0012] Alternatively, if the second parameter is an odd number, the fourth parameter is an odd number, and both the second parameter and the fourth parameter are not 1, the first parameter, the second parameter, the third parameter and the fourth parameter are updated according to the sizes of the second parameter and the fourth parameter.
[0013] In some embodiments, in an embodiment of the present invention, if the second parameter is an even number, updating the first parameter and the second parameter includes:
[0014] If the second parameter is an even number, the parameter after the current second parameter is processed by the shift operation unit is used as a new second parameter;
[0015] If the first parameter is an even number, the parameter after the current first parameter is processed by the shift operation unit is used as the new first parameter; or, if the first parameter is an odd number, the new first parameter is determined by the operation unit according to the current first parameter and the first initial value; the first initial value is the initial value of the fourth parameter.
[0016] In some embodiments, in an embodiment of the present invention, updating the first parameter, the second parameter, the third parameter and the fourth parameter according to the size of the second parameter and the fourth parameter includes:
[0017] If the second parameter is greater than the fourth parameter, the difference between the current second parameter and the current fourth parameter is determined as a new second parameter by the modular subtraction operation unit; and the difference between the current first parameter and the current third parameter is determined as a new first parameter by the modular subtraction operation unit;
[0018] Alternatively, if the second parameter is less than or equal to the fourth parameter, the difference between the current fourth parameter and the current second parameter is determined as the new second parameter through the modular subtraction operation unit; and the difference between the current third parameter and the current first parameter is determined as the new first parameter through the modular subtraction operation unit.
[0019] In some embodiments, in one embodiment of the present invention, determining the target result according to the updated first parameter, the second parameter, the third parameter and the fourth parameter includes:
[0020] If the updated second parameter and the updated fourth parameter are both odd numbers, and the updated second parameter is 1, determining that the updated first parameter is the target result;
[0021] Alternatively, if the updated second parameter and the updated fourth parameter are both odd numbers, and the updated fourth parameter is 1, the updated third parameter is determined to be the target result;
[0022] Alternatively, returning the parity of the second parameter and the fourth parameter, and updating the first parameter, the second parameter, the third parameter and the fourth parameter.
[0023] On the other hand, an embodiment of the present application provides a public key encryption method, including:
[0024] Obtaining a fifth parameter and a sixth parameter, and determining the product of the fifth parameter and the sixth parameter as a first modulus;
[0025] Determine a seventh parameter according to the fifth parameter and the sixth parameter by using the Euler function; and select an eighth parameter according to the seventh parameter; wherein the seventh parameter and the eighth parameter are mutually prime;
[0026] Using the eighth parameter as the initial value of the second parameter and the seventh parameter as the initial value of the fourth parameter, and determining a ninth parameter for performing a modular inverse operation on the eighth parameter by the hardware implementation method of the dual-domain modular inversion as described above;
[0027] Encrypting the plaintext according to the eighth parameter and the first modulus to obtain a ciphertext;
[0028] The ciphertext is decrypted according to the ninth parameter and the first modulus to obtain plaintext.
[0029] On the other hand, an embodiment of the present invention provides a hardware implementation system for dual-domain modular inversion, including:
[0030] The first module is used to build a state machine and an operation unit;
[0031] The second module is used to select to jump to the prime domain state machine or the binary domain state machine according to the mode selection bit;
[0032] The third module is used to call the operation unit based on the current state machine and perform modular inverse operation through a preset modular inverse strategy to determine the target result;
[0033] The preset modular inversion strategy includes: a fourth module, used to determine the initial values of the first parameter, the second parameter, the third parameter and the fourth parameter;
[0034] updating the first parameter, the second parameter, the third parameter and the fourth parameter according to the parity of the second parameter and the fourth parameter;
[0035] The target result is determined according to the updated first parameter, the second parameter, the third parameter and the fourth parameter.
[0036] On the other hand, an embodiment of the present invention provides a hardware implementation device of dual-domain modular inversion, including:
[0037] at least one processor;
[0038] at least one memory for storing at least one program;
[0039] When the at least one program is executed by the at least one processor, the at least one processor implements the above-mentioned hardware implementation method of dual-domain modular inversion.
[0040] On the other hand, an embodiment of the present invention provides a storage medium storing a program executable by a processor, wherein the program executable by the processor is used to implement the hardware implementation method of the above-mentioned dual-domain modular inversion when executed by the processor.
[0041] The method provided by the embodiment of the present application includes: constructing a state machine and an operation unit; according to the mode selection bit, selecting to jump to the prime number domain state machine, or, jumping to the binary domain state machine; based on the current state machine, through the preset modular inverse strategy, calling the operation unit, performing modular inverse operation, and determining the target result; the preset modular inverse strategy includes: determining the initial values of the first parameter, the second parameter, the third parameter, and the fourth parameter; according to the parity of the second parameter and the fourth parameter, updating the first parameter, the second parameter, the third parameter, and the fourth parameter; according to the updated first parameter, the second parameter, the third parameter, and the fourth parameter, determining the target result. The embodiment of the present application constructs a state machine and an operation unit, wherein the state machine can be used in the prime number domain or the binary domain, and can implement the modular inverse operation of the prime number domain and the binary domain in hardware; the embodiment of the present application implements the modular inverse operation by the preset modular inverse strategy, and performs shift, addition and subtraction operations according to the parity of the relevant parameters to determine the target result. The operation process of the embodiment of the present application is simple and easy to implement through hardware, which is conducive to improving the operation speed and reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the embodiments of the present invention or the drawings of related technical solutions in the prior art are introduced below. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0043] Figure 1 A schematic flow chart of an embodiment of a method for hardware implementation of dual-domain modular inversion provided by the present invention;
[0044] Figure 2 A schematic diagram of the structure of an embodiment of a dual-domain model inversion module provided by the present invention;
[0045] Figure 3 A schematic diagram of a flow chart of an embodiment of a dual-domain modular inverse state machine provided by the present invention;
[0046] Figure 4 A schematic diagram of a flow chart of an embodiment of a prime field modular inverse operation provided by the present invention;
[0047] Figure 5 A schematic diagram of a flow chart of an embodiment of a binary domain modular inversion module provided by the present invention;
[0048] Figure 6 A schematic diagram of the structure of an embodiment of a hardware implementation system for dual-domain modular inversion provided by the present invention;
[0049] Figure 7 A schematic diagram of the structure of an embodiment of a hardware implementation device for dual-domain modular inversion provided by the present invention. DETAILED DESCRIPTION
[0050] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and are not to be construed as limitations of the present invention. For the step numbers in the following embodiments, they are only provided for the convenience of explanation, and the order between the steps is not limited in any way, and the execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.
[0051] Modular inversion is one of the most critical and complex operations in public key cryptography algorithms. Its computational efficiency determines the speed of the entire encryption and decryption module. Among the modular inversion functions implemented in hardware, the most commonly used algorithms are Fermat's Little Theorem inversion, Extended Euclidean Algorithm inversion, and Stein Algorithm inversion.
[0052] Fermat's Little Theorem states that if p is a prime number, a is an integer, and p and a are relatively prime, then a p-1 ≡1modp always holds. If you want to find a -1 modp, substituting into the equation, we know that a -1 modp≡a p-2 modp, that is, Fermat's little theorem is used to transform the modular inverse operation into a modular exponentiation operation, and the modular inverse calculation can be realized by reusing the modular exponentiation module in the algorithm. However, p in this algorithm must be a prime number, which is only applicable to the inversion of prime domains, not to the binary domain, and the modular exponentiation operation itself is also relatively complicated.
[0053] The principle of expanding the Euclidean algorithm to find the inverse is to solve the equation ax+by=gcd(a,b). From number theory, we know that this equation must have a solution. When a and b are relatively prime, the solution x of ax+by=1 is a. -1 The value of modb. In an application, if the bit width of the data being sought is very large, the division and modulo operations in the solution process will reduce the efficiency of the entire inversion.
[0054] The Stein algorithm expands the division in the Euclidean algorithm and replaces it with shift and subtraction operations, making it more suitable for hardware implementation. However, for large numbers, the algorithm has more loops. The related patent mentioned at the end of the article is also based on this algorithm, but the state is more complicated, and after the calculation is completed, additional modules are still required for modular multiplication to convert the intermediate results into the final results.
[0055] It can be seen that the above scheme requires complex modular exponentiation, modular division or modular multiplication operations, with complex states, difficult hardware implementation, and slow calculation speed. It consumes a lot of resources. In this regard, the present application eliminates the intermediate variables x2 and y2 in the original Stein algorithm, and combines the inversion calculations of the prime field and the binary field together, and proposes a hardware implementation algorithm suitable for modular inversion of dual fields.
[0056] The core of this application is that the function of dual-domain modular inversion can be realized with only one Verilog file, and no additional module is required for result conversion. The state control logic is simple. The module can choose which domain to perform modular inversion operation through a mode selection control signal. It has more application scenarios and a high reuse rate. It avoids complex modular exponentiation, large number division and modular operations, and uses XOR and shift to complete the same function. The calculation speed is faster, it is more suitable for hardware implementation, and the resource consumption is lower.
[0057] The following describes in detail the hardware implementation method and system of dual-domain modular inversion proposed in an embodiment of the present invention with reference to the accompanying drawings. First, the hardware implementation method of dual-domain modular inversion proposed in an embodiment of the present invention will be described with reference to the accompanying drawings.
[0058] Reference Figure 1 In an embodiment of the present invention, a hardware implementation method of dual-domain modular inversion is provided. The hardware implementation method of dual-domain modular inversion in an embodiment of the present invention can be applied to a terminal, or to a server, or can be software running in a terminal or a server, etc. The terminal can be a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The server can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The hardware implementation method of dual-domain modular inversion in an embodiment of the present invention mainly includes the following steps:
[0059] S100: construct a state machine and an operation unit; the operation unit includes a shift operation unit, a modular subtraction operation unit and a modular addition operation unit;
[0060] S200: According to the mode selection bit, select to jump to the prime domain state machine, or jump to the binary domain state machine;
[0061] S300: Based on the current state machine, the operation unit is called through a preset modular inverse strategy to perform modular inverse operation and determine the target result;
[0062] The preset modular inversion strategy determines the target result through the following steps:
[0063] Determining initial values of the first parameter, the second parameter, the third parameter, and the fourth parameter;
[0064] According to the parity of the second parameter and the fourth parameter, the first parameter, the second parameter, the third parameter and the fourth parameter are updated by the operation unit;
[0065] A target result is determined according to the updated first parameter, second parameter, third parameter and fourth parameter.
[0066] In some possible implementations, the state machine and the operation unit can be constructed by a hardware description language. In some embodiments, the mode selection bit is used to indicate that a prime domain state machine needs to be selected for modular inverse operation, or that a binary domain state machine needs to be selected for modular inverse operation. Specifically, the mode selection bit can be distinguished by 1 or 0 to perform modular inverse operation through a prime domain state machine or a binary domain state machine. Exemplarily, if the mode selection bit is 0, jump to the prime domain state machine; if the mode selection bit is 1, jump to the binary domain state machine. For the above two state machines, through a pre-set preset modular inverse strategy, through the operation unit, in a hardware environment, a modular inverse operation is implemented to determine the target result of the modular inverse operation.
[0067] Specifically, the initial values of the first parameter and the third parameter in the embodiment of the present application can be set as fixed values according to actual needs. According to the parity of the second parameter and the fourth parameter, the subsequent update logic is determined to update the first parameter, update the second parameter, update the third parameter, and update the fourth parameter; and the cycle is repeated to determine the target result according to the updated first parameter, the updated second parameter, the updated third parameter, and the updated fourth parameter.
[0068] Optionally, in one embodiment of the present invention, determining initial values of the first parameter, the second parameter, the third parameter, and the fourth parameter includes:
[0069] Determine that the initial value of the first parameter is 1, the initial value of the third parameter is 0, and the second parameter is a given positive integer;
[0070] If the current state machine is a prime number domain state machine, the initial value of the fourth parameter is determined to be the modulus of the prime number domain; or, if the current state machine is a binary number domain state machine, the initial value of the fourth parameter is determined to be an irreducible polynomial of the binary number domain.
[0071] In some possible implementations, the initial value of the second parameter may be any given positive integer of the modular inverse operation, and the fourth parameter is the modulus of the modular inverse operation. It is understandable that the initial values of the first parameter and the third parameter may be adjusted, and the initial value of the first parameter being 1 and the initial value of the third parameter being 0 are illustrative examples, and the present application does not specifically limit the determination of the initial value of the first parameter, the initial value of the second parameter, the initial value of the third parameter, and the initial value of the fourth parameter.
[0072] Optionally, in one embodiment of the present invention, updating the first parameter, the second parameter, the third parameter and the fourth parameter according to the parity of the second parameter and the fourth parameter includes:
[0073] If the second parameter is an even number, update the first parameter and the second parameter;
[0074] Or, if the fourth parameter is an even number, update the third parameter and the fourth parameter;
[0075] Alternatively, if the second parameter is an odd number, the fourth parameter is an odd number, and both the second parameter and the fourth parameter are not 1, the first parameter, the second parameter, the third parameter, and the fourth parameter are updated according to the sizes of the second parameter and the fourth parameter.
[0076] In some possible implementations, the first parameter and the second parameter may be considered as a first combination, and the third parameter and the fourth parameter may be considered as a second combination. If the second parameter in the first combination is an even number, the first parameter and the second parameter are updated, and the update direction of the second parameter is to reduce the value. Similarly, if the fourth parameter in the second combination is an even number, the third parameter and the fourth parameter are updated, and the update direction of the fourth parameter is to reduce the value. If both the second parameter and the fourth parameter are odd numbers, and neither is 1, it is determined to update the parameters in the first combination, or to update the parameters in the second combination, according to the size relationship between the second parameter and the fourth parameter.
[0077] Optionally, in one embodiment of the present invention, if the second parameter is an even number, updating the first parameter and the second parameter includes:
[0078] If the second parameter is an even number, the parameter after the current second parameter is processed by the shift operation unit is used as the new second parameter;
[0079] If the first parameter is an even number, the parameter after the current first parameter is processed by the shift operation unit is used as the new first parameter; or, if the first parameter is an odd number, the new first parameter is determined by the operation unit according to the current first parameter and the first initial value; the first initial value is the initial value of the fourth parameter.
[0080] In some possible implementations, if the second parameter is an even number, the quotient of the current second parameter and 2 is used as the new second parameter, and in hardware, the operation of dividing by 2 can be implemented by a shift operation. Similarly, when the first parameter is an even number, the update logic of the first parameter is the same as the second parameter. If the first parameter is an odd number, the new first parameter can be determined based on the current first parameter and the initial value of the fourth parameter. In some embodiments, if the first parameter is an odd number, the new first parameter is determined by a modulo addition operation unit and a shift operation unit based on the current first parameter and the first initial value. Specifically, the first sum of the current first parameter and the first initial value can be determined first, and then the quotient of the first sum and 2 is determined as the new first parameter. It is understandable that it can also be updated by the difference between the first parameter and the first initial value. Alternatively, by determining the specific numerical value of the operation in each step, it does not affect the final result. The embodiment of the present application does not limit the specific logic of the first parameter update.
[0081] It can be understood that for the parameters in the second combination, the same update logic as that of the first combination is adopted, specifically:
[0082] If the fourth parameter is an even number, the parameter after the current fourth parameter is processed by the shift operation unit is used as the new second parameter;
[0083] If the third parameter is an even number, the parameter after the current third parameter is processed by the shift operation unit is used as the new third parameter; or, if the third parameter is an odd number, the new third parameter is determined according to the current third parameter and the first initial value; the first initial value is the initial value of the fourth parameter.
[0084] Optionally, in one embodiment of the present invention, updating the first parameter, the second parameter, the third parameter and the fourth parameter according to the magnitudes of the second parameter and the fourth parameter includes:
[0085] If the second parameter is greater than the fourth parameter, the difference between the current second parameter and the current fourth parameter is determined as a new second parameter through a modular subtraction operation unit; and the difference between the current first parameter and the current third parameter is determined as a new first parameter through a modular subtraction operation unit;
[0086] Alternatively, if the second parameter is less than or equal to the fourth parameter, the difference between the current fourth parameter and the current second parameter is determined as the new second parameter through the modular subtraction operation unit; and the difference between the current third parameter and the current first parameter is determined as the new first parameter through the modular subtraction operation unit.
[0087] In some possible implementations, if the second parameter is greater than the fourth parameter, the first parameter and the second parameter in the first combination are updated. If the fourth parameter is greater than or equal to the second parameter, the third parameter and the fourth parameter in the second combination are updated. The update logic of the parameter can be adjusted, and the direction of the update is to reduce the value of the parameter. It should be noted that the difference between the current second parameter and the current fourth parameter is the current second parameter minus the current fourth parameter; the difference between the current fourth parameter and the current second parameter is the current fourth parameter minus the current second parameter. Similarly, the difference between the current first parameter and the current third parameter is the current first parameter minus the current third parameter; the difference between the current third parameter and the current first parameter is the current third parameter minus the current first parameter.
[0088] Optionally, in one embodiment of the present invention, determining the target result according to the updated first parameter, second parameter, third parameter and fourth parameter includes:
[0089] If the updated second parameter and the updated fourth parameter are both odd numbers, and the updated second parameter is 1, the updated first parameter is determined to be the target result;
[0090] Alternatively, if the updated second parameter and the updated fourth parameter are both odd numbers, and the updated fourth parameter is 1, the updated third parameter is determined to be the target result;
[0091] Alternatively, return and update the first parameter, the second parameter, the third parameter and the fourth parameter according to the parity of the second parameter and the fourth parameter.
[0092] In some possible implementations, if the updated second parameter and the updated fourth parameter are both odd numbers, and any one of the updated second parameter and the updated fourth parameter is 1, the result of the modular inverse operation can be determined. If the above conditions are not met, it is necessary to use the updated first parameter as the new first parameter, the updated second parameter as the new second parameter, the updated third parameter as the new third parameter, and the updated fourth parameter as the new fourth parameter, return to update the first parameter, update the second parameter, update the third parameter, and update the fourth parameter according to the parity of the second parameter and the fourth parameter, repeat the update of the parameters, and then determine whether the result of the modular inverse operation is obtained. Through multiple cycles, until the new second parameter and the fourth parameter are both odd numbers, and at least one of them is 1, the target result is obtained.
[0093] Optionally, in one embodiment of the present invention, the method further comprises:
[0094] If the current state machine is a prime number domain state machine, determine that the addition and subtraction operations of the operation unit perform modular operations;
[0095] If the current state machine is a binary domain state machine, the addition and subtraction operations of the operation unit are determined to perform modulo 2 addition operations.
[0096] It is understandable that the present application implements modular inverse operations only through modular addition, modular subtraction and shift operations. Specifically, for the operation process of the prime field, modular addition and modular subtraction operations are modular operations; for the operation process of the binary field, modular addition and modular subtraction operations are modular 2 addition.
[0097] The hardware implementation method provided by this application is described below through a specific embodiment:
[0098] Before introducing the algorithm principle, we first introduce the addition and subtraction operations in the binary domain. In the binary domain, addition is equivalent to subtraction, and both use the form of modulo 2 addition.
[0099] The steps to find the modular inverse are as follows, where p refers to the modulus of the prime field, fz refers to the irreducible polynomial of the binary field, and all additions and subtractions represent modular operations:
[0100] Step S21, set x1=1, y1=0, x3=e, y3=p (fz for binary domain calculation).
[0101] Step S22, determine whether x3 is an even number, if it is an even number, divide x3 by 2, and then determine whether x1 is an even number. When x1 is an even number, divide x1 by 2. If x1 is an odd number, add p / fz to x1 and then divide by 2. When x3 is an odd number, do not perform any operation on x1 and x3.
[0102] Step S23, determine whether y3 is an even number, if it is an even number, divide y3 by 2, and then determine whether y1 is an even number. When y1 is an even number, divide y1 by 2. If y1 is an odd number, add p / fz to y1 and then divide it by 2. When y3 is an odd number, do not perform any operation on y1 and y3.
[0103] Step S24, when x3 and y3 are both odd numbers, determine the values of x3 and y3. If x3=1 or y3=1, the calculation ends. At this time, if x3=1, the value of x1 is the result of modular inversion. If not, the value of y1 is the result of modular inversion. If neither x3 nor y3 is 1, determine the size of x3 and y3. When x3 is greater than y3, set x3=x3-y3, x1=x1-y1; when y3 is greater than x3, set y3=y3-x3, y1=y1-x1.
[0104] Step S25: If the calculation in step S24 is not completed, return to step S22 and step S23 to repeat the operation until one of x3 and y1 is equal to 1, then the calculation is completed and the result is output.
[0105] In some embodiments, the structure of the dual-domain module of the present application is as follows: Figure 2As shown, the corresponding module state transition diagram is as follows Figure 3 The algorithm shown in step S21 to step S25 is implemented using a state machine in the design, and is controlled by the mode selection bit mode. When mode = 0, it jumps to the prime domain state machine, and when mode = 1, it jumps to the binary domain state machine. The state jump is shown in 3, IDLE: idle state. When the start signal of the module is pulled high, the module starts working, and the state machine jumps to step S31:
[0106] State S1, judge mode selection bit mode. When mode = 1, jump to S2 state, and when mode = 0, jump to S4 state.
[0107] State S2, execute calculation steps S22 and S23, in which the binary domain modulo addition and subtraction function is called. When there is an even number between x3 and y3, the state S2 is maintained, otherwise the state S3 is jumped to.
[0108] State S3, execute calculation step S24, after the calculation is completed, determine the values of x3 and y3, if both are not 1, jump to S2 state, if one is equal to 1, jump to finish state.
[0109] State S4, execute calculation steps S22 and S23, in which the prime field modulo addition and subtraction function is called. When there is an even number between x3 and y3, the state S2 is maintained, otherwise the state S3 is jumped to.
[0110] State S5, execute calculation step S24. After the calculation is completed, determine the values of x3 and y3. If neither of them is 1, jump to state S2. If one of them is equal to 1, jump to state finish.
[0111] Finish: Determine which of x3 and y3 is equal to 1. If x3=1, then x1 is the result of modular inversion; if y3=1, then y1 is the result of modular inversion. Output the result and pull the done signal high to complete a modular inversion operation.
[0112] The following example illustrates the correctness of the prime number domain modulo inversion algorithm as well as the detailed calculation process and intermediate values. Figure 4 For example, use this module to find 19 -1 The value of mod47 is calculated according to the algorithm principle shown in step S21 to step S25. The calculated value of each step is as follows Figure 4 As shown in the figure, the addition and subtraction in the figure are prime field modulo operations. As can be seen from the figure, the final modular inverse answer is 5, 5*19mod47=95mod47=1, so 19 -1 mod47=5 is the correct answer. And in the algorithm implementation, there are only modular addition, subtraction and shift operations (division by 2 can be directly implemented by shifting right one bit in hardware).
[0113] The following example will illustrate the correctness of the binary domain modular inversion algorithm as well as the detailed calculation process and intermediate values. For example, choose the irreducible polynomial fz = z 4 +z+1(5'b10011), find z 3 +z 2 +z(4'b1110), according to the algorithm principle shown in step S21 to step S25, the calculated value of each step is as follows Figure 5 As shown in the figure, the addition and subtraction in the figure are binary domain modular operations. As can be seen from the figure, the final modular inverse result is 3. According to the solution of binary domain modular inverse, the modular inverse can be obtained by using the polynomial division method. 4 +z+1=(z 3 +z 2 +z)(z+1)+1, that is (z 3 +z 2 +z) -1 mod(z 4 +z+1)=z+1, which is represented by 11 in binary, equal to 3, and the calculation result is correct. It can be seen that the hardware implementation method provided by the present application can realize the modular inverse operation of the prime field and the binary field only through modular addition, modular subtraction and shift operations, which reduces the difficulty of operation, is easy to implement in hardware, and improves efficiency.
[0114] In summary, the method provided by the present application includes: constructing a state machine and an operation unit; according to the mode selection bit, selecting to jump to the prime domain state machine, or, jumping to the binary domain state machine; based on the current state machine, through the preset modular inverse strategy, calling the operation unit, performing modular inverse operation, and determining the target result; the preset modular inverse strategy includes: determining the initial values of the first parameter, the second parameter, the third parameter, and the fourth parameter; according to the parity of the second parameter and the fourth parameter, updating the first parameter, the second parameter, the third parameter, and the fourth parameter; according to the updated first parameter, the second parameter, the third parameter, and the fourth parameter, determining the target result. The embodiment of the present application constructs a state machine and an operation unit, wherein the state machine can be used in the prime domain or in the binary domain, and can implement the modular inverse operation of the prime domain and the binary domain in hardware; the embodiment of the present application implements the modular inverse operation by the preset modular inverse strategy, and performs shift, addition and subtraction operations according to the parity of the relevant parameters to determine the target result. The operation process of the embodiment of the present application is simple and easy to implement through hardware, which is conducive to improving the operation speed and reducing resource consumption.
[0115] On the other hand, an embodiment of the present application provides a public key encryption method, including:
[0116] Obtaining a fifth parameter and a sixth parameter, and determining the product of the fifth parameter and the sixth parameter as a first modulus;
[0117] Determine a seventh parameter according to the fifth parameter and the sixth parameter by using the Euler function; and select an eighth parameter according to the seventh parameter; wherein the seventh parameter and the eighth parameter are mutually prime;
[0118] Using the eighth parameter as the initial value of the second parameter and the seventh parameter as the initial value of the fourth parameter, and determining a ninth parameter for performing a modular inverse operation on the eighth parameter by the hardware implementation method of the dual-domain modular inversion as described above;
[0119] Encrypting the plaintext according to the eighth parameter and the first modulus to obtain a ciphertext;
[0120] The ciphertext is decrypted according to the ninth parameter and the first modulus to obtain plaintext.
[0121] It can be understood that the hardware implementation method provided in this application can be used to generate RSA public key passwords, can also be used to generate ECC passwords, and can also generate corresponding passwords according to actual needs, and this application does not make specific restrictions.
[0122] It can be seen that the contents of the above-mentioned hardware implementation method embodiment are all applicable to the present encryption method embodiment, the functions specifically implemented by the present encryption method embodiment are the same as those of the above-mentioned hardware implementation method embodiment, and the beneficial effects achieved are also the same as those achieved by the above-mentioned hardware implementation method embodiment.
[0123] On the other hand, refer to the attached Figure 6 A hardware implementation system for dual-domain modular inversion proposed according to an embodiment of the present invention is described, including:
[0124] The first module 610 is used to construct a state machine and a computing unit;
[0125] The second module 620 is used to select to jump to the prime domain state machine or to jump to the binary domain state machine according to the mode selection bit;
[0126] The third module 630 is used to call the operation unit based on the current state machine and perform modular inverse operation through a preset modular inverse strategy to determine the target result;
[0127] The preset modular inversion strategy includes: a fourth module, used to determine the initial values of the first parameter, the second parameter, the third parameter and the fourth parameter;
[0128] updating the first parameter, the second parameter, the third parameter and the fourth parameter according to the parity of the second parameter and the fourth parameter;
[0129] The target result is determined according to the updated first parameter, the second parameter, the third parameter and the fourth parameter.
[0130] It can be seen that the contents of the above method embodiments are all applicable to the present system embodiments, the functions specifically implemented by the present system embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0131] Reference Figure 7 The embodiment of the present invention provides a hardware implementation device of dual-domain modular inversion, including:
[0132] at least one processor 710;
[0133] At least one memory 720, used to store at least one program;
[0134] When the at least one program is executed by the at least one processor 710, the at least one processor 710 implements the hardware implementation method of the dual-domain modular inversion.
[0135] Similarly, the contents of the above method embodiments are all applicable to the present device embodiments. The functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0136] An embodiment of the present invention further provides a computer-readable storage medium, in which a program executable by a processor is stored. When the program executable by the processor is executed by the processor, it is used to execute the hardware implementation method of the above-mentioned dual-domain modular inversion.
[0137] Similarly, the contents of the above method embodiments are all applicable to the present storage medium embodiments. The functions specifically implemented by the present storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0138] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part for which is described as a larger operation is performed independently.
[0139] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise specified, one or more of the functions and / or features can be integrated into a single physical device and / or software module, or one or more functions and / or features can be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the present invention. More specifically, in view of the properties, functions and internal relationships of the various functional modules in the device disclosed herein, the actual implementation of the module will be understood within the conventional skills of the engineer. Therefore, those skilled in the art can implement the present invention set forth in the claims without excessive experimentation using ordinary techniques. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present invention, which is determined by the full scope of the appended claims and their equivalents.
[0140] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the 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 programs to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0141] The logic and / or steps represented in the flowchart or otherwise described herein, for example, may be considered as an ordered list of executable programs for implementing the logical functions, and may be embodied in any computer-readable medium for use by a program execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch and execute a program from a program execution system, device or apparatus), or in conjunction with such program execution systems, devices or apparatuses. For purposes of this specification, a "computer-readable medium" may be any device that can contain, store, communicate, propagate or transmit a program for use by a program execution system, device or apparatus, or in conjunction with such program execution systems, devices or apparatuses.
[0142] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.
[0143] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable program execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0144] In the above description of this specification, the description with reference to the terms "one embodiment / example", "another embodiment / example" or "certain embodiments / examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0145] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
[0146] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present invention.
Claims
1. A hardware implementation method for dual-domain modular inversion, characterized in that: The hardware implementation method comprises the following steps: Constructing a state machine and an operation unit; the operation unit includes a shift operation unit, a modular subtraction operation unit and a modular addition operation unit; According to the mode selection bit, choose to jump to the prime domain state machine, or jump to the binary domain state machine; Based on the current state machine, the operation unit is called through a preset modular inverse strategy to perform a modular inverse operation and determine a target result; The preset model inversion strategy determines the target result through the following steps: Determining initial values of the first parameter, the second parameter, the third parameter, and the fourth parameter; According to the parity of the second parameter and the fourth parameter, updating the first parameter, the second parameter, the third parameter and the fourth parameter through the operation unit; The target result is determined according to the updated first parameter, the second parameter, the third parameter and the fourth parameter.
2. The hardware implementation method of dual-domain modular inversion according to claim 1 is characterized in that: The determining of the initial values of the first parameter, the second parameter, the third parameter and the fourth parameter comprises: Determine that the initial value of the first parameter is 1, the initial value of the third parameter is 0, and the second parameter is a given positive integer; If the current state machine is the prime number domain state machine, the initial value of the fourth parameter is determined to be the modulus of the prime number domain; or, if the current state machine is the binary number domain state machine, the initial value of the fourth parameter is determined to be an irreducible polynomial of the binary number domain.
3. The hardware implementation method of dual-domain modular inversion according to claim 1 is characterized in that: Updating the first parameter, the second parameter, the third parameter, and the fourth parameter according to the parity of the second parameter and the fourth parameter, comprising: If the second parameter is an even number, update the first parameter and the second parameter; Alternatively, if the fourth parameter is an even number, updating the third parameter and the fourth parameter; Alternatively, if the second parameter is an odd number, the fourth parameter is an odd number, and both the second parameter and the fourth parameter are not 1, the first parameter, the second parameter, the third parameter and the fourth parameter are updated according to the sizes of the second parameter and the fourth parameter.
4. The hardware implementation method of dual-domain modular inversion according to claim 3 is characterized in that: If the second parameter is an even number, updating the first parameter and the second parameter comprises: If the second parameter is an even number, the parameter after the current second parameter is processed by the shift operation unit is used as a new second parameter; If the first parameter is an even number, the parameter after the current first parameter is processed by the shift operation unit is used as the new first parameter; or, if the first parameter is an odd number, the new first parameter is determined by the operation unit according to the current first parameter and the first initial value; the first initial value is the initial value of the fourth parameter.
5. The hardware implementation method of dual-domain modular inversion according to claim 3 is characterized in that: The updating of the first parameter, the second parameter, the third parameter and the fourth parameter according to the sizes of the second parameter and the fourth parameter comprises: If the second parameter is greater than the fourth parameter, the difference between the current second parameter and the current fourth parameter is determined as a new second parameter by the modular subtraction operation unit; and the difference between the current first parameter and the current third parameter is determined as a new first parameter by the modular subtraction operation unit; Alternatively, if the second parameter is less than or equal to the fourth parameter, the difference between the current fourth parameter and the current second parameter is determined as the new second parameter through the modular subtraction operation unit; and the difference between the current third parameter and the current first parameter is determined as the new first parameter through the modular subtraction operation unit.
6. The hardware implementation method of dual-domain modular inversion according to claim 1 is characterized in that: Determining the target result according to the updated first parameter, the second parameter, the third parameter, and the fourth parameter includes: If the updated second parameter and the updated fourth parameter are both odd numbers, and the updated second parameter is 1, determining that the updated first parameter is the target result; Alternatively, if the updated second parameter and the updated fourth parameter are both odd numbers, and the updated fourth parameter is 1, the updated third parameter is determined to be the target result; Alternatively, returning the parity of the second parameter and the fourth parameter, and updating the first parameter, the second parameter, the third parameter and the fourth parameter.
7. A public key encryption method, characterized in that: The encryption method comprises: Obtaining a fifth parameter and a sixth parameter, and determining the product of the fifth parameter and the sixth parameter as a first modulus; Determine a seventh parameter according to the fifth parameter and the sixth parameter by using the Euler function; and select an eighth parameter according to the seventh parameter; wherein the seventh parameter and the eighth parameter are mutually prime; Using the eighth parameter as the initial value of the second parameter and the seventh parameter as the initial value of the fourth parameter, and determining a ninth parameter for performing a modular inverse operation on the eighth parameter by the hardware implementation method for dual-domain modular inversion according to any one of claims 1 to 6; Encrypting the plaintext according to the eighth parameter and the first modulus to obtain a ciphertext; The ciphertext is decrypted according to the ninth parameter and the first modulus to obtain plaintext.
8. A hardware implementation system for dual-domain modular inversion, characterized in that: include: The first module is used to build a state machine and an operation unit; The second module is used to select to jump to the prime domain state machine or the binary domain state machine according to the mode selection bit; The third module is used to call the operation unit based on the current state machine and perform modular inverse operation through a preset modular inverse strategy to determine the target result; The preset modular inversion strategy includes: a fourth module, used to determine the initial values of the first parameter, the second parameter, the third parameter and the fourth parameter; updating the first parameter, the second parameter, the third parameter and the fourth parameter according to the parity of the second parameter and the fourth parameter; The target result is determined according to the updated first parameter, the second parameter, the third parameter and the fourth parameter.
9. A hardware implementation device for dual-domain modular inversion, characterized in that: include: at least one processor; at least one memory for storing at least one program; When the at least one program is executed by the at least one processor, the at least one processor implements the hardware implementation method of the dual-domain modular inversion according to any one of claims 1 to 6.
10. A computer-readable storage medium storing a program executable by a processor, characterized in that: The processor-executable program is used to implement the hardware implementation method of dual-domain modular inversion as claimed in any one of claims 1 to 6 when executed by the processor.
