Modular operation method and device, electronic equipment and circuit

By performing congruent replacement operations on the data to be computed, large integer division is avoided, and the problems of large-scale computing resource consumption and low performance are solved, and the efficiency and performance of modular computing are improved.

CN118963704APending Publication Date: 2024-11-15BEIJING T-HEAD INFORMATION TECHNOLOGY CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411046612.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

In the existing modular operation methods, large integer division resources consume large amounts and low performance, especially in elliptic curve cryptography, the modular multiplication operation takes a long time, which affects the algorithm performance.

Method used

By performing multiple congruent replacement operations on the data to be computed, the binary sequence of the first preset number of bits is replaced with a binary sequence of the congruent and has the second preset number of bits is avoided, and the modulo operation is realized.

Benefits of technology

It improves the efficiency of modular computing, reduces resource consumption, and reduces deployment difficulty. It is suitable for large integer analog computing scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure HDA0004974568270000011
    Figure HDA0004974568270000011
  • Figure HDA0004974568270000021
    Figure HDA0004974568270000021
  • Figure HDA0004974568270000031
    Figure HDA0004974568270000031
Patent Text Reader

Abstract

The embodiment of the invention discloses a modular operation method and device, electronic equipment and a circuit. According to the embodiment of the invention, after the to-be-operated data is obtained, the congruence replacement operation is repeatedly performed on the to-be-operated data until the operation result is obtained, and the operation result is output. Wherein the congruence replacement operation is used for replacing the binary sequence of the first preset digit of the to-be-operated data with a congruence binary sequence with a second preset digit, the second preset digit is smaller than the first preset digit, and the operation result is the to-be-operated data with the digit equal to the second preset digit. Therefore, the original large integer division method is replaced by performing congruence replacement on the to-be-operated data for multiple times, the modular operation can be realized, and in the process of realizing the modular operation, the large integer division method is avoided, so that the modular operation efficiency is improved, and the resource consumption is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more specifically, to a modular operation method, device, electronic equipment and circuit. Background Art

[0002] Modular operation, also known as remainder operation, is a mathematical operation that is widely used in many fields. For example, in the field of security algorithms, especially in public key cryptography, the efficiency of modular operation has a decisive influence on the overall performance of the algorithm. This is particularly evident in ECC (Elliptic Curve Cryptography), because ECC is a cryptographic algorithm defined on elliptic curves, and the main operations are scalar multiplication, point addition, and point doubling. The core of these operations is modular multiplication and modular addition, among which modular multiplication is more time-consuming and is the key to performance.

[0003] Modular multiplication includes two steps: multiplication and modulo. The original modulo operation method is to divide the modulus by the modulus, and then output the remainder as the operation result. Since the implementation of division involves large resource consumption and low performance, it is generally avoided to use division for modulo. Common modulo implementation methods include Montgomery modular reduction, barret modular reduction, and fast modular reduction. Their original design intention is to avoid the use of division. The first two can support general moduli, but the performance is low; the third is for special moduli, with higher performance, but because it is too targeted, different modulo reduction calculations will be completely different, so it is less universal. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a modular operation method, device, electronic device and circuit to implement modular operation, and avoid large integer division in the process of implementing modular operation, thereby improving modular operation efficiency and reducing resource consumption.

[0005] In a first aspect, an embodiment of the present invention provides a modular operation method, the method comprising:

[0006] Obtain data to be calculated;

[0007] Repeating the congruence replacement operation on the data to be operated until an operation result is obtained, wherein the congruence replacement operation is used to replace a binary sequence of a first preset number of bits of the data to be operated with a binary sequence of a congruence and a second preset number of bits, the second preset number of bits is smaller than the first preset number of bits, and the operation result is the data to be operated with a number of bits equal to the second preset number of bits;

[0008] The operation result is output.

[0009] In a second aspect, an embodiment of the present invention provides a modular operation device, the device comprising:

[0010] An acquisition unit, used for acquiring data to be calculated;

[0011] a congruence replacement unit, configured to repeatedly perform a congruence replacement operation on the data to be operated until an operation result is obtained, wherein the congruence replacement operation is used to replace a binary sequence of a first preset number of bits of the data to be operated with a binary sequence of a congruence and a second preset number of bits, the second preset number of bits being smaller than the first preset number of bits, and the operation result being the data to be operated with a number of bits equal to the second preset number of bits;

[0012] An output unit is used to output the operation result.

[0013] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium storing computer program instructions, wherein the computer program instructions implement the method described in the first aspect when executed by a processor.

[0014] In a fourth aspect, an embodiment of the present invention provides an electronic device, the device comprising:

[0015] a memory for storing one or more computer program instructions;

[0016] A processor, wherein the one or more computer program instructions are executed by the processor to implement the method as described in the first aspect.

[0017] In a fifth aspect, an embodiment of the present invention provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the method as described in the first aspect.

[0018] In a sixty-fifth aspect, an embodiment of the present invention provides a modular operation circuit, wherein the modular operation circuit includes:

[0019] A memory, used for storing data to be calculated;

[0020] a congruence replacement circuit, configured to convert a first binary sequence having a first preset number of bits into a second binary sequence having a congruence and a second preset number of bits, and replace the binary sequence of the first preset number of bits of the data to be operated with the second binary sequence, wherein the second preset number of bits is smaller than the first preset number of bits;

[0021] The bit judgment circuit is used to input the binary sequence of the first first preset number of bits of the data to be calculated as the first binary sequence into the congruence replacement circuit when it is detected that the number of bits of the data to be calculated stored in the memory is greater than or equal to the first preset number of bits, and output the data to be calculated as the calculation result when it is detected that the number of bits of the data to be calculated stored in the memory is equal to the second preset number of bits.

[0022] After obtaining the data to be operated, the embodiment of the present invention repeatedly performs a congruence replacement operation on the data to be operated until the operation result is obtained, and outputs the operation result. The congruence replacement operation is used to replace the binary sequence of the first preset number of bits of the data to be operated with a binary sequence of congruence and a second preset number of bits, the second preset number of bits is less than the first preset number of bits, and the operation result is the data to be operated with a number of bits equal to the second preset number of bits. Therefore, by performing multiple congruence replacements on the data to be operated to replace the original large integer division, the embodiment of the present invention can realize modular operation, and in the process of realizing modular operation, avoid large integer division, thereby improving the efficiency of modular operation and reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:

[0024] Figure 1 Flow chart of the modular operation method according to an embodiment of the present invention

[0025] Figure 2 A flowchart of a method for determining a calculation result according to an embodiment of the present invention;

[0026] Figure 3 is a flowchart of a second binary sequence determination method according to an embodiment of the present invention;

[0027] Figure 4 A schematic diagram of splitting a first binary sequence according to an embodiment of the invention;

[0028] Figure 5 Schematic diagram of the transformation of the first subsequence according to an embodiment of the present invention;

[0029] Figure 6 Schematic diagram of determining the fourth subsequence according to an embodiment of the present invention;

[0030] Figure 7 A schematic diagram of replacing a binary sequence according to an embodiment of the present invention

[0031] Figure 8 Schematic diagram of a modular operation process according to an embodiment of the present invention;

[0032] Fig. 9 is a schematic diagram of a modular operation device according to an embodiment of the present invention;

[0033] Fig.10 is a schematic diagram of an electronic device according to an embodiment of the present invention;

[0034] Fig.11 Schematic diagram of the structure of the modular operation circuit according to an embodiment of the present invention;

[0035] Fig.12 It is an application schematic diagram of a modular operation circuit according to an embodiment of the invention;

[0036] Fig.13 Schematic diagram of the structure of a modular reduction circuit according to an embodiment of the present invention. DETAILED DESCRIPTION

[0037] The present application is described below based on embodiments, but the present application is not limited to these embodiments. In the detailed description of the present application below, some specific details are described in detail. It is possible for those skilled in the art to fully understand the present application without the description of these details. In order to avoid confusing the essence of the present application, known methods, processes, flows, components and circuits are not described in detail.

[0038] In addition, persons of ordinary skill in the art will appreciate that the drawings provided herein are for illustration purposes and are not necessarily drawn to scale.

[0039] Unless the context clearly requires otherwise, the words "include", "comprising" and similar words throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, the meaning is "including but not limited to".

[0040] In the description of this application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of this application, unless otherwise specified, the meaning of "plurality" is two or more.

[0041] The solutions described in this specification and in the examples, if they involve the processing of personal information, will be processed on the premise of having a legal basis (such as obtaining the consent of the subject of personal information, or being necessary for the performance of a contract, etc.), and will only be processed within the scope of regulations or agreements. If a user refuses to process personal information other than the necessary information for basic functions, it will not affect the user's use of basic functions.

[0042] It should be understood that, compared with the normal modular operation method and the existing modular operation optimization method, the modular operation method in the embodiment of the present invention only needs to use simple multiple additions and subtractions to achieve the optimization of the modular operation, thereby reducing the deployment difficulty of the modular operation method and at the same time improving the modular operation efficiency.

[0043] I hope to explain that as long as the modulus meets the requirements (that is, the modulus is a polynomial and the terms of the polynomial can be written as 2 32*n In the form of, n is a non-negative integer. For example, the required modulus can be 2 256 -2 224 +2 192 +296 -1 or 2 256 -2 224 -2 96 +2 64 -1), the modular operation method in the embodiment of the present invention can be used to optimize any modular operation where the modulus is a large integer, so as to obtain the operation result without performing large integer division, thereby improving the efficiency of the modular operation.

[0044] Figure 1 FIG. 1 is a flow chart of a modular operation method according to an embodiment of the present invention. Figure 1 As shown, the modular operation method may specifically include the following steps:

[0045] It should be understood that the execution subject of the modular operation method in the embodiment of the present invention can be any related embedded system (such as a microcontroller) or related data processing device (such as a smart phone, tablet computer, smart wearable device, laptop computer or server, etc.) with simple mathematical operation capabilities (i.e., addition and subtraction capabilities). Furthermore, the related embedded system or related device can meet its own modular operation needs by executing the modular operation method, and can also provide modular operation services to the outside by executing the modular operation method. This application does not limit this. For the convenience of description, the following will mainly take the execution subject of the modular operation method as a data processing device as an example for explanation.

[0046] Step S100: Obtain data to be calculated.

[0047] Specifically, when there is a modular operation requirement or a request for obtaining an operation service is received from an external device, the device can obtain the data to be operated, wherein the data to be operated can refer to the modulus, which can specifically be a large integer.

[0048] Optionally, the operation service acquisition request may include a modular operation service acquisition request (i.e., a request to provide a modular operation service) and a modular-related operation service acquisition request (i.e., a request to provide a modular-related operation service, such as a modular multiplication operation service), and the present application does not impose any restrictions on this.

[0049] Among them, the modular operation service acquisition request can directly carry the data to be calculated, and the modular-related operation service acquisition request can carry the related data used to calculate the data to be calculated. In step S100, if a modular operation service acquisition request is received, the device can directly obtain the data to be calculated from the modular operation service acquisition request. If a modular-related operation service acquisition request is received, the device can calculate and obtain the data to be calculated based on the related data carried in the modular-related operation service acquisition request. Specifically, taking the reception of a modular multiplication operation service acquisition request as an example, if a modular multiplication operation service acquisition request is received, the device can obtain the first multiplier and the second multiplier carried in the modular multiplication operation service acquisition request, and calculate the product of the first multiplier and the second multiplier to obtain the data to be calculated.

[0050] Step S200: repeatedly perform congruence replacement operations on the data to be calculated until a calculation result is obtained.

[0051] Among them, the congruence replacement operation is used to replace the binary sequence of the first preset number of bits of the data to be calculated with a binary sequence that is congruent and has a second preset number of bits, the second preset number of bits is smaller than the first preset number of bits, and the operation result is the data to be calculated with a number of bits equal to the second preset number of bits.

[0052] Specifically, after obtaining the data to be operated, the device can repeatedly perform the congruence replacement operation on the data to be operated to replace the binary sequence of the first preset number of bits of the data to be operated with a binary sequence of the second preset number of bits that is congruent, until the number of bits of the data to be operated is less than the first preset number of bits. At this time, the device stops performing the congruence replacement operation on the data to be operated, and determines the current data to be operated as the operation result.

[0053] It is desired to explain that, when the modulus remains unchanged, a partial binary sequence of the modulus is replaced with a binary sequence that is congruent therewith, and the modulus before the binary sequence replacement is also congruent with the modulus after the binary sequence replacement. Therefore, the embodiment of the present invention can simplify the data to be operated by continuously performing congruence replacement operations on the data to be operated without changing the final output result.

[0054] Figure 2 FIG. 1 is a flow chart of a method for determining a calculation result according to an embodiment of the present invention. Figure 2 As shown, the calculation result determination method may specifically include the following steps:

[0055] It should be understood that by executing Figure 2 The method for determining the operation result shown in the figure can implement the above step S200.

[0056] Step S210: Determine a first binary sequence.

[0057] Specifically, the device can determine a first binary sequence. The first binary sequence is the same as the binary sequence of the first preset number of bits of the data to be operated. The first preset number of bits can be determined according to the current modulus, which can be specifically the sum of the exponent of the first term (i.e., the highest term) of the current modulus and the default number of bits. The default number of bits can be 32, 16, 8 or other related values, which is not limited in this application. For example, if the current modulus is 2 256 -2 224 +2 192 +2 96 -1, the default number of bits is 32, then the first preset number of bits can be 288.

[0058] Step S220: Determine a second binary sequence that is congruent to the first binary sequence and has the second preset bit number.

[0059] Specifically, after determining the first binary sequence, the device may determine a second binary sequence that is congruent with the first binary sequence and has a second preset number of bits. The second preset number of bits may also be determined based on the current modulus, which may specifically be the exponent of the first term (i.e., the highest term) of the current modulus. For example, if the current modulus is 2 256 -2 224 +2 192 +2 96 -1, the second preset bit number may be 256.

[0060] Figure 3 FIG. 4 is a flow chart of a second binary sequence determination method according to an embodiment of the present invention. Figure 3 As shown, the second binary sequence determination method may specifically include the following steps:

[0061] It should be understood that by executing Figure 3 According to the second binary sequence determination method shown, the device can implement the above step S220.

[0062] Step S221: split the first binary sequence into a first subsequence having the first preset number of bits and a second subsequence having the second preset number of bits.

[0063] Specifically, when determining the second binary sequence, the device may first split the first binary sequence into a first subsequence having a first preset number of bits and a second subsequence having a second preset number of bits. The first subsequence may be the high-order portion of the first binary sequence, which may specifically be a binary sequence in which the binary characters of the first default number of bits of the first binary sequence are selected and the remaining bits of the first binary sequence are replaced with "0". The second subsequence may be the low-order portion of the first binary sequence, which may specifically be a binary sequence composed of the remaining bits of the first binary sequence after removing the binary characters of the first default number of bits of the first binary sequence.

[0064] Figure 4 FIG. 1 is a schematic diagram of splitting the first binary sequence of an embodiment of the invention. It should be understood that Figure 4 The content shown is when the current modulus is 2 256 -2 224 +2 192 +2 96 -1, schematic diagram of splitting the first binary sequence when the default number of bits is 32. Figure 4 Each square in each binary sequence shown in can be used to represent a binary segment with a bit number of 32. Figure 4 As shown, the device can split the first binary sequence 41 with a number of 288 into a first subsequence 42 with a number of 288 and a second subsequence 43 with a number of 256. The first subsequence 42 is the first 32 binary characters (i.e., square a) of the first binary sequence 41. 15 The remaining 256 bits of the first binary sequence 41 (i.e., square a) are 14 -a7) is replaced by a binary sequence of "0" ( Figure 4 The squares marked with "0" can be used to represent a binary segment consisting of 32 bits of "0". The second subsequence 43 is obtained by removing the first 32 bits of binary characters (i.e., square a) of the first binary sequence 41. 15 After the binary segment represented by the first binary sequence 41, the remaining 256 bits (i.e., square a 14 -a7 represents a binary sequence composed of binary segments.

[0065] Step S222: convert the first subsequence into a third subsequence which is congruent and has a third preset number of bits.

[0066] Specifically, after splitting to obtain the first subsequence and the second subsequence, the device can convert the first subsequence into a third subsequence that is congruent and has a third preset number of digits. The third preset number of digits is less than or equal to the second preset number of digits. The specific value of the third preset number of digits depends on the current modulus, which can be the sum of the exponent of the secondary term (i.e., the second highest term) of the current modulus and the default number of digits. For example, if the current modulus is 2 256 -2 224 +2 192 +2 96 -1, the default number of bits is 32, and the third preset number of bits can be 256.

[0067] Optionally, in step S222, the device can convert the first subsequence into a third subsequence having a congruence and a third preset number of bits according to the current modulus. Specifically, by performing a series of transformations on the current modulus, the present embodiment can obtain a corresponding congruence equation. Among them, one side of the congruence equation can be a binary sequence having a first preset number of bits, a first default number of bits of R (R is a binary segment with a default number of bits), and the remaining bits are "0". The other side of the congruence equation can be a binary sequence having a third preset number of bits and can be represented by R. The congruence equation can be used to indicate the conversion of the first subsequence into a third subsequence having a congruence and a third preset number of bits.

[0068] For ease of understanding, the following will assume that the current modulus P is 2 256 -2 224 +2 192 +2 96 -1 is used as an example to explain in detail. 256 -2 224 +2 192 +2 96 -1, take both sides of the equation modulo P and multiply by R, and then transform to get the following congruence equation:

[0069] R*2 256 ≡R*2 224 -R*2 192 -R*2 96 +R(mod P). The left side of the equation is a binary sequence with the first preset number of digits, the first default number of digits being R, and the remaining digits being "0". The right side of the equation is a binary sequence with the third preset number of digits and which can be represented by R. In this embodiment, the first subsequence can be converted into a third subsequence with the third preset number of digits by using the above congruence equation.

[0070] Figure 5 is a schematic diagram of the transformation of the first subsequence of an embodiment of the present invention. It should be understood that Figure 5 The content shown is when the current modulus is 2256 -2 224 +2 192 +2 96 -1, the default number of bits is 32, and the conversion diagram of converting the first subsequence into the third subsequence. Figure 5 Each square in each binary sequence shown in can be used to represent a binary segment with a bit number of 32. Figure 5 As shown, after obtaining the first subsequence 51 with a number of 288, the device can convert the first subsequence 51 into a third subsequence 52 with a number of 256 and a congruence (during the conversion process, the binary characters of the first default number of bits in the first subsequence 51 (i.e., square a 15 The binary segment represented by the first subsequence 51 is taken as R, and the binary character of the first default bit in the first subsequence 51 (ie, square a) is obtained. 15 The third subsequence 52) represented by the binary segment represented by .

[0071] Optionally, Figure 5 The third subsequence shown is only for ease of understanding. In the implementation and application process, the binary segment in the binary sequence cannot be a negative number. Therefore, when the device converts the first subsequence into the third subsequence, it actually first generates a minuend part and a subtrahend part corresponding to the first subsequence according to the current modulus, and then determines the difference between the minuend part and the subtrahend part as the third subsequence.

[0072] Furthermore, in the process of implementing the application, when generating the minuend part and the subtrahend part corresponding to the first subsequence according to the current modulus, the device does not actually need to convert the current modulus into a congruence equation first, and then generate the minuend part and the subtrahend part according to the congruence equation, but can directly generate the minuend part and the subtrahend part corresponding to the first subsequence according to the current modulus. Specifically, the device can directly generate the minuend part corresponding to the first subsequence according to each negative term of the current modulus, and then generate the subtrahend part corresponding to the first subsequence according to each positive term of the current modulus.

[0073] It should be understood that the examples of congruence equations and conversion processes given above are for illustration only. In actual applications, for other moduli that meet the requirements, the device can also use them to convert the first subsequence into a third subsequence. Therefore, the calculation method in this embodiment can be applied to calculation scenarios of different moduli.

[0074] Step S223: Determine the sum of the second subsequence and the third subsequence as a fourth subsequence.

[0075] Specifically, after converting the first subsequence into the third subsequence, the device may determine the sum of the second subsequence and the third subsequence as the fourth subsequence.

[0076] Figure 6 FIG. 4 is a schematic diagram of determining the fourth subsequence in an embodiment of the present invention. Figure 6 As shown, the device may calculate the sum of the second subsequence 61 and the third subsequence 62 , and determine the sum of the second subsequence 61 and the third subsequence 62 as the fourth subsequence 63 .

[0077] Step S224: Determine the second binary sequence according to the fourth subsequence.

[0078] Specifically, after obtaining the fourth subsequence, the device may determine the second binary sequence according to the fourth subsequence.

[0079] Optionally, in order to ensure the operation efficiency, each time the device performs the congruence replacement operation on the operation data, it is necessary to ensure that the second binary sequence is the minimum congruence number of the first binary sequence (that is, to ensure that the second binary sequence is less than the current modulus), and in step S223, the device is likely to have a carry in the process of determining the fourth subsequence, and the fourth subsequence after the carry cannot meet the above conditions. In this regard, in step S224, the device can determine whether there is a carry in the calculation process of the fourth subsequence. If so, the device can calculate the difference between the fourth subsequence and the current modulus, and determine the difference between the fourth subsequence and the current modulus as the second binary sequence. If not, the device can directly determine the fourth subsequence as the second binary sequence.

[0080] Step S230: Replace the first binary sequence of the first preset number of bits of the data to be calculated with the second binary sequence.

[0081] Specifically, after obtaining the second binary sequence, the device may replace the binary sequence of the first preset number of bits of the data to be operated with the second binary sequence. Thus, this embodiment may complete a congruence replacement operation on the data to be operated.

[0082] Figure 7 FIG. 4 is a schematic diagram of replacing a binary sequence according to an embodiment of the present invention. Figure 7 As shown, after obtaining the second binary sequence 71, the device can convert the binary sequence of the first preset number of bits of the data to be operated 72 (that is, the square a 15 -a7) is replaced by the second binary sequence (that is, the binary segment represented by square b8-b1), thereby obtaining new data 73 to be calculated.

[0083] Step S240: determine whether the number of bits of the data to be calculated is less than a first preset number of bits.

[0084] Specifically, each time a congruence replacement operation on the data to be operated is completed, the device can determine whether the number of digits of the current data to be operated is less than the first preset number of digits. If so, the device can execute step S250 to determine the operation result. If not, the device can return to step S210 to perform the next congruence replacement operation. It should be understood that the current data to be operated will replace the original data to be operated to participate in the next congruence replacement operation.

[0085] Step S250: determining the data to be calculated as the calculation result.

[0086] Specifically, when it is determined that the number of digits of the current data to be calculated is less than the first preset number of digits, the device may determine the data to be calculated as the calculation result.

[0087] Step S300: output the operation result.

[0088] Specifically, after determining the operation result, the device can output the operation result. It should be understood that the output operation result can be fed back by the device to the external device that obtains the operation service (that is, the device that sends the operation service acquisition request), or the output operation result can also be used by the device to perform subsequent data processing operations.

[0089] Figure 8 FIG. 1 is a schematic diagram of a modular operation process according to an embodiment of the present invention. Figure 8 As shown, after obtaining the data to be operated 81, the device can start to perform a congruence replacement operation on the data to be operated. In each congruence replacement operation, the device converts the binary sequence of the first preset number of bits of the data to be operated into a binary sequence of congruence and second preset number of bits (for example, in the first congruence replacement operation, the device can convert the square a in the data to be operated 81 into a binary sequence of congruence and second preset number of bits). 15 -a 17 The binary segment represented by square b8-b1 is replaced with the binary segment represented by square b8-b1, thereby obtaining data 82 to be operated. In the second congruence replacement operation, the device can replace the binary segment represented by square b8-b1 and square a6 in the data 82 to be operated with the binary segment represented by square c8-c1, thereby obtaining data 83 to be operated. In the third congruence replacement operation, the device can replace the binary segment represented by square c8-c1 and square a5 in the data 83 to be operated with the binary segment represented by square d8-d1, thereby obtaining data 83 to be operated, which will not be repeated here). The congruence replacement operation will be repeated until the number of bits of the data to be operated is less than the first preset number of bits. At this time, the device will determine the data 84 to be operated whose number of bits is less than the first preset number of bits as the output result and output it.

[0090] After obtaining the data to be operated, the embodiment of the present invention repeatedly performs a congruence replacement operation on the data to be operated until the operation result is obtained, and outputs the operation result. The congruence replacement operation is used to replace the binary sequence of the first preset number of bits of the data to be operated with a binary sequence of congruence and a second preset number of bits, the second preset number of bits is less than the first preset number of bits, and the operation result is the data to be operated with a number of bits equal to the second preset number of bits. Therefore, by performing multiple congruence replacements on the data to be operated to replace the original large integer division, the embodiment of the present invention can realize modular operation, and in the process of realizing modular operation, avoid large integer division, thereby improving the efficiency of modular operation and reducing resource consumption.

[0091] Fig. 9 Schematic diagram of a modular operation device according to an embodiment of the present invention. Fig. 9 As shown, the modular operation device of the embodiment of the present invention includes an acquisition unit 91, a congruence replacement unit 92 and an output unit 93.

[0092] Specifically, the acquisition unit 91 is used to acquire data to be calculated;

[0093] The congruence replacement unit 92 is used to repeatedly perform a congruence replacement operation on the data to be operated until an operation result is obtained, wherein the congruence replacement operation is used to replace a binary sequence of a first preset number of bits of the data to be operated with a binary sequence of a congruence and a second preset number of bits, the second preset number of bits is less than the first preset number of bits, and the operation result is the data to be operated with a number of bits equal to the second preset number of bits;

[0094] The output unit 93 is used to output the operation result.

[0095] After obtaining the data to be operated, the embodiment of the present invention repeatedly performs a congruence replacement operation on the data to be operated until the operation result is obtained, and outputs the operation result. The congruence replacement operation is used to replace the binary sequence of the first preset number of bits of the data to be operated with a binary sequence of congruence and a second preset number of bits, the second preset number of bits is less than the first preset number of bits, and the operation result is the data to be operated with a number of bits equal to the second preset number of bits. Therefore, by performing multiple congruence replacements on the data to be operated to replace the original large integer division, the embodiment of the present invention can realize modular operation, and in the process of realizing modular operation, avoid large integer division, thereby improving the efficiency of modular operation and reducing resource consumption.

[0096] Fig.10 FIG. 1 is a schematic diagram of an electronic device according to an embodiment of the present invention. In this embodiment, the electronic device may specifically be a data processing device according to the above embodiment. Fig.10As shown, the electronic device: includes: at least one processor 101; and a memory 102 communicatively connected to at least one processor 101; and a communication component 103 communicatively connected to a scanning device, the communication component 103 receives and sends data under the control of the processor 101; wherein the memory 102 stores instructions executable by at least one processor 101, and the instructions are executed by at least one processor 101 to implement the above-mentioned modular operation method.

[0097] Specifically, the electronic device includes: one or more processors 101 and a memory 102, Fig.10 A processor 101 is taken as an example. The processor 101 and the memory 102 may be connected via a bus or other means. Fig.10 The bus connection is used as an example. The memory 102 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The processor 101 executes various functional applications and data processing of the device by running the non-volatile software programs, instructions and modules stored in the memory 102, that is, realizing the above-mentioned modular operation method.

[0098] The memory 102 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store a list of options, etc. In addition, the memory 102 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 102 may optionally include a memory remotely arranged relative to the processor 101, and these remote memories may be connected to an external device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0099] One or more modules are stored in the memory 102, and when executed by one or more processors 101, the modular operation method in any of the above method embodiments is performed.

[0100] The above-mentioned product can execute the method provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the method provided in the embodiment of the present application.

[0101] After obtaining the data to be operated, the embodiment of the present invention repeatedly performs a congruence replacement operation on the data to be operated until the operation result is obtained, and outputs the operation result. The congruence replacement operation is used to replace the binary sequence of the first preset number of bits of the data to be operated with a binary sequence of congruence and a second preset number of bits, the second preset number of bits is less than the first preset number of bits, and the operation result is the data to be operated with a number of bits equal to the second preset number of bits. Therefore, by performing multiple congruence replacements on the data to be operated to replace the original large integer division, the embodiment of the present invention can avoid performing large integer division when performing modular operations, thereby improving the efficiency of modular operations.

[0102] Another embodiment of the present invention relates to a non-volatile storage medium for storing a computer-readable program, wherein the computer-readable program is used for a computer to execute part or all of the above method embodiments.

[0103] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. 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 and other media that can store program codes.

[0104] In some embodiments, in addition to being implemented by an embedded system or a data processing device, the modular operation method in the embodiment of the present invention can also be implemented by a modular operation circuit. The modular operation circuit can be obtained by mapping the operation logic of the modular operation method in the embodiment of the present invention to an editable integrated circuit (such as a field programmable gate array (FPGA)) after the relevant personnel use a hardware description language (such as VHDL or Verilog) to describe the operation logic.

[0105] Fig.11 FIG. 1 is a schematic diagram of the structure of a modular operation circuit according to an embodiment of the present invention. Fig.11As shown, the modular operation circuit may include a memory 111, a digit determination circuit 112 and a congruence replacement circuit 113. The memory 111 is a storage medium for storing data to be operated, which may be a register, a random access memory, a storage circuit composed of logic elements or other devices with storage functions, and the present application does not limit this. The digit determination circuit 112 and the congruence replacement circuit 113 may be circuits obtained by mapping the operation logic corresponding to the modular operation method in the embodiment of the present invention to an editable integrated circuit. The digit determination circuit 112 and the congruence replacement circuit 113 are used to repeatedly perform congruence replacement operations on the data to be operated stored in the memory 111 by cooperating with each other, that is, continuously replacing the binary sequence of the first preset digits of the data to be operated stored in the memory 111 with a binary sequence of congruence and having a second preset digit.

[0106] Specifically, after the data to be operated is obtained, the data to be operated will be first stored in the memory 111. After detecting that the data to be operated is stored in the memory 111, the bit judgment circuit 112 will judge whether the number of bits of the data to be operated stored in the memory 111 is greater than or equal to the first preset number of bits. When it is detected that the number of bits of the data to be operated stored in the memory 111 is greater than or equal to the first preset number of bits, the bit judgment circuit 112 will read out the binary sequence of the first preset number of bits of the data to be operated from the memory 111 as the first binary sequence and input it into the congruence replacement circuit 113 (it should be understood that this reading operation will not change the data to be operated stored in the memory 111). After the first binary sequence is input into the congruence replacement circuit 113, the congruence replacement circuit 113 will convert the first binary sequence into a second binary sequence that is congruent and has a second preset number of bits, and replace the binary sequence of the first preset number of bits of the data to be operated stored in the memory 111 with the second binary sequence, thereby completing a congruence replacement operation on the data to be operated. Furthermore, each time after completing a congruence replacement operation on the data to be operated, the bit number determination circuit 112 will again determine whether the bit number of the data to be operated stored in the memory 111 is greater than or equal to the first preset bit number, and when detecting that the bit number of the data to be operated stored in the memory 111 is still greater than or equal to the first preset bit number, continue to read out the binary sequence of the first preset bit number before the data to be operated from the memory 111 as a new first binary sequence and input it into the congruence replacement circuit 113, so that the congruence replacement circuit 113 performs the next congruence replacement operation on the data to be operated stored in the memory 111. The congruence replacement operation will be repeated until the bit number of the data to be operated stored in the memory 111 is less than the first preset bit number. When detecting that the bit number of the data to be operated stored in the memory 111 is less than the first preset bit number, the bit number determination circuit 112 will output the data to be operated as the operation result.

[0107] Fig.12 FIG. 1 is an application diagram of a modular operation circuit according to an embodiment of the invention. It should be understood that Fig.12 The content shown is a schematic diagram of the modular operation circuit in the embodiment of the invention when it is applied to modular multiplication calculation. Fig.12 As shown, the modular operation circuit includes an input circuit 121, a multiplication circuit 122, a memory 123, a bit number judgment circuit 124 and a congruence replacement circuit 125.

[0108] Specifically, when performing modular multiplication calculation, the input circuit 121 first receives the input first multiplier and second multiplier, and inputs the first multiplier and second multiplier into the multiplication circuit 122. After receiving the input first multiplier and second multiplier, the multiplication circuit 122 calculates the product of the first multiplier and the second multiplier to obtain the data to be calculated, and stores the data to be calculated into the memory 123.

[0109] Further, the bit number determination circuit 124 includes a bit number detection circuit 1241, a read circuit 1242 and an output circuit 1243. After detecting that the data to be calculated is stored in the memory 123, the bit number detection circuit 1241 will detect the bit number of the data to be calculated stored in the memory 123, and output the detection result to the read circuit 1242. After receiving the input detection result, the read circuit 1242 will determine whether the bit number of the data to be calculated stored in the memory 123 is greater than or equal to the first preset bit number according to the detection result. If so, the read circuit 1242 will read the binary sequence of the first preset bit number of the data to be calculated stored in the memory 123, and output the binary sequence to the output circuit 1243, so that the output circuit 1243 further outputs the binary sequence as the first binary sequence to the congruence replacement circuit 125. If not, the read circuit 1242 will read the data to be calculated stored in the memory 123, and output the data to be calculated to the output circuit 1243, so that the output circuit 1243 outputs the data to be calculated as the calculation result.

[0110] Furthermore, the congruence replacement circuit 125 includes a modular reduction circuit 1251 and a writing circuit 1252. After receiving the input first binary sequence, the modular reduction circuit 1251 converts the first binary sequence into a second binary sequence that is congruent and has a second preset number of bits, and outputs the second binary sequence to the writing circuit 1252, so that the writing circuit 1252 replaces the binary sequence of the first preset number of bits of the data to be operated stored in the memory 123 with the second binary sequence, thereby completing a congruence replacement operation on the data to be operated.

[0111] It should be understood that whenever it is detected that the congruence replacement circuit 125 completes a congruence replacement operation (the detection of the congruence replacement operation can be achieved by detecting whether the number of bits of the data to be operated stored in the memory has changed), the number of bits detection circuit 1241 of the number of bits judgment circuit 124 will output the changed number of bits of the data to be operated as the detection result to the reading circuit 1242 again, so as to perform the next congruence replacement operation. Such congruence replacement operation will be repeated until the number of bits of the data to be operated stored in the memory 123 is less than the first preset number of bits, at which time, the data to be operated will be output as the operation result by the output circuit 1243 in the number of bits judgment circuit 124.

[0112] Fig.13 FIG. 1 is a schematic diagram of the structure of a modular reduction circuit according to an embodiment of the present invention. Fig.13 As shown, the modular reduction circuit 131 includes a multiplexing circuit 1311 , a congruential conversion circuit 1312 , an addition circuit 1313 and a carry adjustment circuit 1314 .

[0113] After receiving the input first binary sequence, the multiplexing circuit 1311 can split the first binary sequence into a first subsequence having a first preset number of bits and a second subsequence having a second preset number of bits (that is, performing the following steps: Figure 4 The first subsequence and the second subsequence are output to the congruential conversion circuit 1312 and the adding circuit 1313 respectively. After receiving the input first subsequence, the congruential conversion circuit 1312 can convert the first subsequence into a third subsequence that is congruential and has a third preset number of bits (i.e., performing the following steps): Figure 5 The process shown in FIG. 13 is shown in FIG. 13), and the third subsequence is output to the adding circuit 1313. After receiving the second subsequence and the third subsequence as input, the adding circuit 1313 can calculate the sum of the second subsequence and the third subsequence to obtain the fourth subsequence (i.e., perform the process shown in FIG. 13). Figure 6 , and outputs the fourth subsequence to the carry adjustment circuit 1314. After receiving the fourth subsequence, the carry adjustment circuit 1314 can detect whether there is a carry in the calculation process of the fourth subsequence. If so, the carry adjustment circuit 1314 will calculate the difference between the fourth subsequence and the current modulus to obtain the fifth subsequence, and output the fifth subsequence as the second binary sequence to the subsequent write circuit. If not, the carry adjustment circuit 1314 will directly output the fourth subsequence as the second binary sequence to the subsequent write circuit. After receiving the second binary sequence, the write circuit will replace the binary sequence of the first first preset number of bits of the data to be calculated stored in the memory with the second binary sequence (that is, execute as shown in the figure). Figure 7 process shown).

[0114] Optionally, since negative numbers cannot appear in binary segments in a binary sequence, the congruential conversion circuit may specifically include a generation circuit and a first subtraction circuit. The generation circuit may generate a minuend part and a subtrahend part corresponding to the first subsequence, and output the minuend part and the subtrahend part to the first subtraction circuit. After receiving the input minuend part and the subtrahend part, the first subtraction circuit may calculate the difference between the minuend part and the subtrahend part to obtain the third subsequence.

[0115] Optionally, the carry adjustment circuit may specifically include a carry detection circuit and a second subtraction circuit. The carry detection circuit may detect whether there is a carry in the calculation process of the fourth subsequence, and determine whether to directly output the fourth subsequence as the second binary sequence to the subsequent write circuit or output the fourth subsequence to the second subtraction circuit according to the detection result. The second subtraction circuit may calculate the difference between the fourth subsequence and the current modulus to obtain a fifth subsequence, and output the fifth subsequence as the second binary sequence to the subsequent write circuit.

[0116] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A modular operation method, characterized in that: The method comprises: Obtain data to be calculated; Repeating the congruence replacement operation on the data to be operated until an operation result is obtained, wherein the congruence replacement operation is used to replace a binary sequence of a first preset number of bits of the data to be operated with a binary sequence of a congruence and a second preset number of bits, the second preset number of bits is smaller than the first preset number of bits, and the operation result is the data to be operated with a number of bits equal to the second preset number of bits; The operation result is output.

2. The method according to claim 1, characterized in that The repeatedly performing the congruence replacement operation on the data to be operated until the operation result is obtained comprises: Iteratively perform the following steps until the calculation result is obtained: Determine a first binary sequence, where the first binary sequence is the same as a binary sequence of a first preset number of bits of the data to be operated; Determine a second binary sequence that is congruent to the first binary sequence and has the second preset number of bits; The first binary sequence of the first preset number of bits of the data to be operated is replaced by the second binary sequence.

3. The method according to claim 2, characterized in that The determining of a second binary sequence which is congruent with the first binary sequence and has the second preset number of bits comprises: Splitting the first binary sequence into a first subsequence having the first preset number of bits and a second subsequence having the second preset number of bits; Converting the first subsequence into a third subsequence that is congruent and has a third preset number of bits, where the third preset number of bits is less than or equal to the second preset number of bits; Determine a sum of the second subsequence and the third subsequence as a fourth subsequence; The second binary sequence is determined according to the fourth subsequence.

4. The method according to claim 3, characterized in that The converting the first subsequence into a third subsequence having a congruence and a third preset number of bits comprises: generating a minuend part and a subtrahend part corresponding to the first subsequence according to the current modulus; The difference between the minuend part and the subtrahend part is determined as the third subsequence.

5. The method according to claim 4, characterized in that Generating a subtrahend part and a minuend part corresponding to the first subsequence according to the current modulus comprises: generating a minuend part corresponding to the first subsequence according to each negative term of the current modulus; A subtrahend part corresponding to the first subsequence is generated according to each positive term of the current modulus.

6. The method according to claim 3, characterized in that The determining the second binary sequence according to the fourth subsequence comprises: In response to the absence of a carry in the calculation process of the fourth subsequence, determining the fourth subsequence as the second binary sequence; In response to a carry occurring during the calculation process of the fourth subsequence, a difference between the fourth subsequence and a current modulus is determined as the second binary sequence.

7. The method according to claim 1, characterized in that The obtaining of data to be calculated comprises: Receiving a modular multiplication operation service acquisition request, wherein the modular multiplication operation service acquisition request includes a first multiplier and a second multiplier; The product of the first multiplier and the second multiplier is calculated to obtain the data to be operated.

8. A modular operation device, characterized in that: The device comprises: An acquisition unit, used for acquiring data to be calculated; a congruence replacement unit, configured to repeatedly perform a congruence replacement operation on the data to be operated until an operation result is obtained, wherein the congruence replacement operation is used to replace a binary sequence of a first preset number of bits of the data to be operated with a binary sequence of a congruence and a second preset number of bits, the second preset number of bits being smaller than the first preset number of bits, and the operation result being the data to be operated with a number of bits equal to the second preset number of bits; An output unit is used to output the operation result.

9. A computer-readable storage medium storing computer program instructions, characterized in that: The computer program instructions implement the method according to any one of claims 1 to 7 when executed by a processor.

10. An electronic device, characterized in that: The device comprises: a memory for storing one or more computer program instructions; A processor, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 7.

11. A computer program product, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 7.

12. A modular arithmetic circuit, characterized in that: The modular operation circuit comprises: A memory, used for storing data to be calculated; a congruence replacement circuit, configured to convert a first binary sequence having a first preset number of bits into a second binary sequence having a congruence and a second preset number of bits, and replace the binary sequence of the first preset number of bits of the data to be operated with the second binary sequence, wherein the second preset number of bits is smaller than the first preset number of bits; The bit judgment circuit is used to input the binary sequence of the first first preset number of bits of the data to be calculated as the first binary sequence into the congruence replacement circuit when it is detected that the number of bits of the data to be calculated stored in the memory is greater than or equal to the first preset number of bits, and output the data to be calculated as the calculation result when it is detected that the number of bits of the data to be calculated stored in the memory is equal to the second preset number of bits.