A fast modular multiplication chip implementation device and method based on SM2 specific domain
By designing a fast modular multiplication chip in the SM2 elliptic curve encryption algorithm, using a 256-bit multiplier and SM2 fast modular reducer, combined with a decomposition reassembler and a compression multiplier, the modular multiplication algorithm is optimized and solves the problem of the high cost and high cost of traditional chip design. To solve the problem of insufficient throughput rate, the SM2 elliptic curve modular multiplication algorithm with low power consumption, low latency and high throughput rate is implemented.
Patent Information
- Application Number
- CN202210616387.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-01
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-06-01
AI Technical Summary
It is difficult to implement the SM2 elliptic curve encryption modular multiplication algorithm with high efficiency, low power consumption, low latency and low area time product with existing technology, especially in scenarios where data encryption requirements are high in Internet of Things terminal equipment. Traditional chip design costs are high and Insufficient throughput.
A fast modular multiplication chip based on SM2 specific domain is designed, using a 256-bit fast multiplier and SM2 fast modular reducer, using a decomposition reassembler, a 90-bit specific long compression multiplier and a data post-processor to perform modular multiplication operations. And through the traveling wave carry adder and congruence properties, the modular reduction algorithm is optimized to maximize the use of FPGA resources, reduce lengthy addition and carry chains, and improve reusability.
It implements the SM2 elliptic curve modular multiplication algorithm with low power consumption, low latency, low area time product and high throughput rate. It is suitable for high-frequency circuit applications, improves the performance and efficiency of the chip, and meets the high throughput rate of IoT terminal equipment. need.
Smart Images

Figure CN115048076B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of encryption algorithms, and in particular to a device and method for realizing a fast modular multiplication chip based on an SM2 specific domain. Background Art
[0002] The security of 160-bit elliptic curve (ECC) encryption is equivalent to 1024-bit RSA encryption, and the security of 210-bit elliptic curve encryption is even equivalent to 2048-bit RSA encryption. Therefore, for the elliptic curve encryption system, from the perspective of computational complexity, processing speed, storage space, and communication bandwidth, the elliptic curve encryption system has great advantages. It is easy to implement on a computer using software or hardware, and the encryption and signing speeds are very high. Now the cryptography community generally believes that it will replace RSA as a universal public key cryptography algorithm. It has become a research hotspot and a very promising research direction.
[0003] As an elliptic curve cryptosystem, the mathematical basis of the SM2 algorithm is the discrete logarithm problem in the Abel addition group composed of points on the elliptic curve. Attacking the algorithm requires exponential time. Mathematical calculations can prove that the difficulty of the discrete logarithm problem of the elliptic curve on a finite field is higher than the difficulty of the discrete logarithm problem on a general multiplication group. It has strong security. There is currently no effective attack on the SM2 elliptic curve. Under the condition of the same key length, the security of the SM2 elliptic curve encryption algorithm is far stronger than the existing standard ciphers such as RSA and AES series, and the design is compact.
[0004] In addition to the above, the SM2 encryption algorithm also has the advantages of small computational volume and storage, small bandwidth, low overhead, and high encryption and signature speed. Therefore, SM2 is considered to be the most common public key cryptographic system of the next generation and has broad application prospects in the cryptographic field. The SM2 cryptographic algorithm is attracting the attention of the industry with its shorter key and theoretically higher strength, and its chip implementation will also be a focus in the public key cryptographic system.
[0005] Although the cryptographic algorithm implemented by software has low design cost and short development cycle, the encryption algorithm implemented by software is limited by the operating frequency of the processor and it is difficult to achieve high-speed encryption. In addition, since there are multiple solutions for the modular multiplication algorithm based on the finite field SM2, the algorithm needs to be continuously iterated, so the design of a dedicated chip requires reinvestment in R&D costs. Summary of the invention
[0006] In order to solve the above technical problems, the present invention provides a fast modular multiplication chip implementation device and method based on the SM2 specific domain, so as to achieve the characteristics of low power consumption, low latency, low area-time product, and high throughput, and can meet the data encryption requirements of Internet of Things terminal devices with high throughput requirements.
[0007] To achieve the above object, the technical solution of the present invention is as follows:
[0008] A fast modular multiplication chip implementation device based on an SM2 specific domain includes a 256-bit fast multiplier and an SM2 fast modular reducer, wherein the 256-bit fast multiplier is connected to the SM2 fast modular reducer to transmit a final 512-bit multiplication result to the SM2 fast modular reducer;
[0009] The 256-bit fast multiplier includes a decomposition and recombiner, a 90-bit fixed-length compression multiplier and a data post-processor which are connected in sequence. Two 256-bit unsigned integers are input from the outside and enter the decomposition and recombiner. The decomposition and recombiner sends the recombined result to the 90-bit fixed-length compression multiplier in cycles. The obtained result is then sent to the data post-processor for processing, and finally a 512-bit multiplication result is output;
[0010] The decomposition and recombining device comprises a delay unit and a 90-bit adder, which first decomposes the input 256-bit unsigned integer into three 90-bit unsigned integers, and then uses the 90-bit adder to recombine the corresponding 90-bit unsigned integers, which are output in sequence after passing through the delay unit and sent to the 90-bit fixed-length compression multiplier;
[0011] The 90-bit fixed-length compression multiplier comprises a 24×18-bit partial product multiplication grouper, a 3-2 compressor, a 4-2 compressor, a 5-2 compressor, and a 180-bit adder; after inputting two 90-bit unsigned integers to be operated after reorganization, firstly, a 24×18-bit multiplication operation is performed using DSP resources, and then the obtained partial products are grouped, and each group of data is processed using a 3-2 compressor, a 4-2 compressor, and a 5-2 compressor, respectively, to finally obtain a sum and a carry, both of which are 180 bits, and are input into a 180-bit adder, and the final 90-bit multiplication result is output; the 180-bit adder adopts a ripple carry adder to form a carry structure, and the 90-bit fixed-length compression multiplier is connected to a data post-processor, and the obtained result is sent to the data post-processor for subsequent processing;
[0012] The data post-processor includes a 90-bit adder-subtractor and a 180-bit adder-subtractor, takes the result of the 90-bit fixed-length compression multiplier as input, first processes the data using the 90-bit adder-subtractor and the 180-bit adder as required, then stores the result in different registers, and obtains the final result after splicing;
[0013] The SM2 fast modular reducer includes a 32-bit adder-subtractor, and adopts a ripple carry adder to form a carry structure. The input 512-bit multiplication result is split into 16 32-bit unsigned integers, and then the repeated parts and factors are calculated. Next, 32-bit high-radix addition is performed, and finally the carry of each 32-bit addition result is processed to obtain the final output modular multiplication result.
[0014] In the above scheme, the operation process of the decomposition and recombination device is as follows:
[0015] Assume that 256-bit unsigned integers A and B are input values. First, they enter the decomposition and recombiner, and A and B are divided into 90-bit A2, A1, A0, B2, B1, B0, that is, A = (A2, A1, A0) 90x3 , B=(B2,B1,B0) 90x3 , where A0 and B0 correspond to bits 1 to 90 of A and B, A1 and B1 correspond to bits 91 to 180 of A and B, and A2 and B2 correspond to bits 181 to 256 of A and B. If A2 and B2 are less than 90 bits, they are padded with zeros; a 90-bit adder is used to calculate to obtain A2+A1, A2+A0, A1+A0, B2+B1, B2+B0, and B1+B0; then a delay unit is used to delay the paired inputs ①A2, B2, ②A1, B1, ③(A2+A1), (B2+B1), ④A0, B0, ⑤(A0+A1), (B0+B1), ⑥(A2+A0), (B2+B0) by 0, 1, 2, 3, 4, and 5 clock cycles respectively and send them to a 90-bit fixed-length compression multiplier.
[0016] In the above scheme, the 90-bit fixed-length compression multiplier completes the multiplication operation of a 90-bit unsigned integer, and its output result is a 180-bit unsigned integer, wherein the operation process is as follows:
[0017] Assume that 90-bit unsigned integers a and b are input values. First, divide a into a3, a2, a1, a0 every 24 bits, and divide b into b4, b3, b2, b1, b0 every 18 bits, that is, a = (a3, a2, a1, a0) 24x4 , b=(b4,b3,b2,b1,b0) 18x5, using the DSP in 20 FPGAs for calculation. After the calculation is completed, 20 42-bit partial product results are obtained. These partial products are spliced together according to the weights. Each part of the spliced result is 21 bits of data. Therefore, the final multiplication result can be obtained by adding each column accordingly. After the 90-bit fixed-length compression multiplier generates an output for the first time, it outputs the operation results in each clock cycle and sends them to the data post-processor.
[0018] In the above scheme, the data post-processor uses six 180-bit registers P2, P1, P0, P 12 ,P 01 ,P 02 The output results of six different inputs are stored; for different numbers sent to the 90-bit fixed-length compression multiplier, the operation output requires different post-processing: when the input is ①A2, B2, ②A1, B1, ④A0, B0, the results are directly stored in registers P2, P1, P0 respectively; when the input is ③(A2+A1), (B2+B1), the result needs to be subtracted from P2 and P1 and then stored in P 12 When the input is ⑤(A0+A1) or (B0+B1), it is necessary to subtract P1 and P0 from the result, add the high 90 bits of P0 and store it in P 01 When the input is ⑥(A2+A0) and (B2+B0), P2 and P0 need to be subtracted from the result, and P1 and P0 need to be added. 01 The high 90 bits are then stored in P 02 ; The addition and subtraction involved in this process requires the use of a 180-bit adder and subtractor;
[0019] When the above operations are completed, the high 90 bits of P2 and the low 90 bits of P2 are added to P 12 The high 90 bits of the addition result, P 12 Low 90 bits and P 02 The high 90 bits of the addition result, P 02 Low 90 bits, P 01 The lower 90 bits, the lower 90 bits of the binary result of P0 are sequentially spliced and intercepted to the lower 512 bits, which is the output result of the 256-bit fast multiplier; the addition and subtraction involved in this process require the use of a 90-bit adder and subtractor;
[0020] In the above scheme, the SM2 fast modular reducer realizes the function of taking the remainder of the prime number p, wherein the operation process is as follows:
[0021] First, input a 512-bit integer c modulo a prime number p, where the range of c is 0≤c<p 2 ,p=2 256 -2 224 -2 96 +2 64-1, split the 512-bit integer c into 32-bit parts, that is, c = (c 15 ,c 14 ,c 13 ,c 12 ,c 11 ,c 10 ,c9,c8,c7,c6,c5,c4,c3,c2,c1,c0) 32x16 , where c i The result of splitting c into 32 bits each is obtained by using the congruence property to write c into the following c' form:
[0022] c'=3c 15 2 224 +c 15 2 192 +c 15 2 128 +c 15 2 96 +2c 15 2 32 +2c 15 +2c 14 2 224 +c 14 2 192 +c 14 2 160 +2c 14 2 128 +c 14 2 96 -c 14 2 64 +2c 14 2 32 +2c 14 +2c 13 2 224 +c 13 2 160 +c 13 2 128 +2c 13 2 96 -c 13 2 64 +c 13 2 32 +2c 13 +2c 12 2 224 +c 12 2 128 +2c 12 2 96 +c 12 2 32 +c 12 +2c 11 2 224 +c 11 2192 +c 11 2 96 +c 11 2 32 +c 11 +c 10 2 224 +c 10 2 160 +c 10 2 32 +c 10 +c92 224 +c92 128 -c92 64 +c92 32 +c9+c82 224 +c82 96 -c82 64 +c8+c72 224 +c62 192 +c52 160 +c42 128 +c32 96 +c22 64 +c12 32 +c0
[0023] Then, expand c' to 32 bits to c' = (r8, r7, r6, r5, r4, r3, r2, r1, r0) 32x9 , r i That is, c' is split into 32 bits, and then c" = (r7, r6, r5, r4, r3, r2, r1, r0) 32 -(r8,0,0,0,r8,-r8,0,r8) 32 , the range of c″ is (0,2p);
[0024] Finally, determine whether c″ is greater than the prime number p. If it is greater, subtract p to get the final result. If it is less, output the result directly.
[0025] A method for implementing a fast modular multiplication chip based on an SM2 specific domain, using the fast modular multiplication chip implementation device based on an SM2 specific domain as described above, includes the following process:
[0026] (1) After loading two 256-bit unsigned integers A and B, they are input into the decomposition and recombination device of the 256-bit fast multiplier, which internally decomposes the two 256-bit unsigned integers into six 90-bit integers, namely A2, A1, A0, B2, B1, B0, where A = (A2, A1, A0) 90x3 , B=(B2,B1,B0) 90x3, where A0 and B0 correspond to bits 1 to 90 of A and B, A1 and B1 correspond to bits 91 to 180 of A and B, and A2 and B2 correspond to bits 181 to 256 of A and B. If A2 and B2 are less than 90 bits, they are padded with zeros; the 90-bit integers are added to obtain six groups of 90-bit unsigned integers to be multiplied: ①A2 and B2, ②A1 and B1, ③(A2+A1), (B2+B1), ④A0 and B0, ⑤(A0+A1), (B0+B1), ⑥(A2+A0), (B2+B0), and these six groups of data are sent to the 90-bit fixed-length compression multiplier in different clock cycles;
[0027] (2) In the 90-bit fixed-length compression multiplier, two 90-bit unsigned integers are input, and there is a three-stage pipeline structure. The first stage of the pipeline splits one of the 90-bit unsigned integers into four 24-bit unsigned integers every 24 bits, and the other 90-bit unsigned integer is split into five 18-bit unsigned integers every 18 bits, and then performs a 24×18-bit partial product multiplication grouper, which is divided into 9 groups in total; the second stage of the pipeline performs four rounds of compression on the reorganized partial products of the 9 groups using a 3-2 compressor, a 4-2 compressor, and a 5-2 compressor, and the final compressed results are assembled into two 180-bit unsigned integers; the third stage of the pipeline completes the addition of the two 180-bit unsigned integers;
[0028] (3) When a 90-bit unsigned integer is input for the first time, it takes 3 clock cycles to output the first input, and then each clock cycle outputs the corresponding results of the sequential input. The results obtained from different inputs are sent to the data post-processor for corresponding addition and stored in different registers. Finally, a 512-bit multiplication result is obtained by splicing and input into the SM2 fast modular reducer.
[0029] (4) In the SM2 fast modular reducer, a 512-bit unsigned integer is input and split into 16 32-bit unsigned integers. The repeated parts and factors are then calculated. Next, 32-bit high-radix addition is performed. Finally, the carry of each 32-bit addition result is processed to obtain the final output modular multiplication result.
[0030] Through the above technical solution, the fast modular multiplication chip implementation device and method based on the SM2 specific domain provided by the present invention has the following beneficial effects:
[0031] 1. The present invention designs a 90-bit fixed-length compression multiplier structure, which has certain scalability, and has the advantages of low latency, low area, and high performance. It maximizes the use of digital signal processor (DSP) resources in FPGA, uses logical operations such as AND, XOR, and data selectors to replace the lengthy addition carry chain, and solves the high latency problem caused by the traditional multiplier relying on a large number of adders. Compared with the existing Wallace tree multiplier structure, the bit width of each compressor of the multiplier structure proposed by the present invention is the same, while the bit width of each layer of the compressor of the Wallace tree multiplier is different. The present invention has the ability to better reuse compressors, thereby optimizing area and performance to a greater extent.
[0032] 2. The 256-bit fast multiplier structure designed by the present invention has a pipeline structure. When there is continuous input data, each designed multiplier structure can be used to the maximum extent, so that after the first operation output is generated, each clock cycle can be output. Therefore, when there is continuous input, the average operation time of the 256-bit fast multiplier depends on the highest frequency of the circuit. The multiplier designed by the present invention has an operating frequency of more than 229MHz and is suitable for working in high-frequency circuits.
[0033] 3. The present invention designs an SM2 fast modular reducer. Since the algorithm needs to be operated on a finite field, all operation results need to be within the range of the finite field, otherwise a modulo operation needs to be performed. According to the specific prime number characteristics on SM2, combined with the existing fast modular reduction algorithm and using the congruence property, a fast modular reduction algorithm suitable for SM2 is obtained. The present invention uses addition and subtraction to replace the division operation involved in the traditional algorithm when taking the module, and reuses the results for the repeated intermediate terms in the fast modular reduction algorithm, thereby maximally reducing the area of the module. For the traditional fast modular reduction algorithm, at most 12 subtractions are required during post-processing to make the result within the range of the finite field, while the SM2 fast modular reduction algorithm designed by the present invention only needs to be judged once at most during the post-processing process, which greatly shortens the delay.
[0034] 4. The present invention proposes a chip implementation strategy for the modular multiplication algorithm on a specific domain of the SM2 elliptic curve. In scenarios where there is a large demand for high throughput, the present invention can achieve high-frequency execution of the modular multiplication algorithm, and from the perspective of area-time product, the present invention can better balance the relationship between resource consumption and delay, thereby minimizing the product of the two.
[0035] 5. The chip implementation device and method of the modular multiplication algorithm on the specific field of the SM2 elliptic curve proposed in the present invention have the characteristics of low power consumption, low latency, low area-time product, and high throughput, and can meet the data encryption requirements of IoT terminal devices with high throughput requirements.
[0036] 6. On Xilinx 7 series FPGA (Virtex-7), when using the area-time product optimization solution, the SM2 modular multiplication algorithm occupies 4.8k LUTs, the maximum operating frequency is 229.5MHz, the single operation time reaches 47.71ns, and the throughput can reach 5341Mbps. Ⅰ (The product of LUT area and delay (us)) is 0.229, AT Ⅱ (DSP area times delay (ms)) is 0.96, while achieving high throughput. Ⅰ and AT Ⅱ It also reached a relatively low value.
[0037] 7. On the Ultrascale series FPGA (zynq Ultrascale), when using the area-time product optimization solution, the SM2 modular multiplication algorithm occupies 4.8k LUTs, the maximum operating frequency is 464.0MHz, the single operation time reaches 26.46ns, and the throughput can reach 10799Mbps (10.799Gbps), AT Ⅰ is 0.127, AT Ⅱ is 0.53, while achieving high throughput, AT Ⅰ and AT Ⅱ It also reached a relatively low value. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0039] Figure 1 A schematic diagram of a fast modular multiplication chip implementation device based on an SM2 specific domain disclosed in an embodiment of the present invention;
[0040] Figure 2 It is the structure diagram of 256-bit fast multiplier;
[0041] Figure 3 The structure diagram of the 90-bit fixed-length compression multiplier is shown below;
[0042] Figure 4 This is the structure diagram of the 3-2 compressor;
[0043] Figure 5 This is the structure diagram of the 4-2 compressor;
[0044] Figure 6 This is the structural diagram of the 5-2 compressor device;
[0045] Figure 7 This is the structural diagram of the SM2 fast module reducer. DETAILED DESCRIPTION
[0046] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0047] The present invention provides a fast modular multiplication chip implementation device based on SM2 specific domain, such as Figure 1 As shown, it includes a 256-bit fast multiplier and an SM2 fast modular reducer. The system requires that the input integers A and B are integers with a bit width less than or equal to 256 bits. The 256-bit fast multiplier is connected to the SM2 fast modular reducer, and the final 512-bit multiplication result is transmitted to the SM2 fast modular reducer. The SM2 fast modular reducer outputs a 256-bit modular multiplication result, and the operation is completed after the output.
[0048] 1. 256-bit fast multiplier
[0049] The 256-bit fast multiplier includes a decomposition and recombiner, a 90-bit fixed-length compression multiplier and a data post-processor which are connected in sequence. Two 256-bit unsigned integers are input from the outside, and the data is sent to the decomposition and recombiner. The decomposition and recombiner sends the recombined result to the 90-bit fixed-length compression multiplier in cycles. The result is then sent to the data post-processor for processing, and finally a 512-bit multiplication result is output.
[0050] 1. Decomposition and Recombination
[0051] The decomposition and recombiner includes a delay unit and a 90-bit adder. The input 256-bit unsigned integer is first decomposed into three 90-bit unsigned integers, and then the corresponding 90-bit data is recombined using the 90-bit adder. After passing through the delay unit, the data is output in sequence and sent to the 90-bit fixed-length compression multiplier.
[0052] The specific operation process of the decomposition and reorganization device is as follows:
[0053] Assume that 256-bit unsigned integers A and B are input values. First, they enter the decomposition and recombiner, and A and B are divided into 90-bit A2, A1, A0, B2, B1, B0, that is, A = (A2, A1, A0) 90x3 , B=(B2,B1,B0) 90x3, where A0 and B0 correspond to bits 1 to 90 of A and B, A1 and B1 correspond to bits 91 to 180 of A and B, and A2 and B2 correspond to bits 181 to 256 of A and B. If A2 and B2 are less than 90 bits, they are padded with zeros; a 90-bit adder is used to calculate to obtain A2+A1, A2+A0, A1+A0, B2+B1, B2+B0, and B1+B0; then a delay unit is used to delay the paired inputs ①A2, B2, ②A1, B1, ③(A2+A1), (B2+B1), ④A0, B0, ⑤(A0+A1), (B0+B1), ⑥(A2+A0), (B2+B0) by 0, 1, 2, 3, 4, and 5 clock cycles respectively and send them to a 90-bit fixed-length compression multiplier.
[0054] 2. 90-bit fixed-length compression multiplier
[0055] like Figure 3 As shown, the 90-bit fixed-length compression multiplier includes a 24×18-bit partial product multiplication grouper, a 3-2 compressor, a 4-2 compressor, a 5-2 compressor, and a 180-bit adder; two 90-bit unsigned integers to be operated after reorganization are input, and first a 24×18-bit multiplication operation is performed using DSP resources, and then the obtained partial products are grouped, and each group of data is processed using a 3-2 compressor, a 4-2 compressor, and a 5-2 compressor, respectively, to finally obtain a sum (Sum) and a carry (Carry), both of which are 180 bits, which are input into a 180-bit adder, and the final 90-bit multiplication result is output; the 180-bit adder uses a ripple carry adder to form a carry structure, and the 90-bit fixed-length compression multiplier is connected to a data post-processor, and the obtained result is sent to the data post-processor for subsequent processing.
[0056] The 90-bit fixed-length compression multiplier performs the multiplication operation of 90-bit unsigned integers, and its output result is a 180-bit unsigned integer. The operation process is as follows:
[0057] like Figure 3 The structure of the 90-bit fixed-length compression multiplier shown in the figure has the input as the value in the 90-bit a and b registers. First, the a register is divided once every 24 bits to obtain 4 24-bit numbers. The result less than 24 bits is padded with 0, and the b register is divided once every 18 bits to obtain 5 18-bit numbers, which can be completely divided. That is, 90-bit unsigned integers a and b are used as input values. First, a is divided into a3, a2, a1, a0 every 24 bits, and b is divided into b4, b3, b2, b1, b0 every 18 bits, that is, a=(a3, a2, a1, a0) 24x4 , b=(b4,b3,b2,b1,b0) 18x5 .
[0058] Send the four 24-bit numbers and the five 18-bit numbers to the 24×18bits partial product multiplication grouper, which performs the multiplication of the four 24-bit numbers and the five 18-bit numbers in pairs. Each multiplication of the 24-bit and 18-bit numbers uses exactly one DSP resource of the 7 series FPGA, that is, the DSP in 20 FPGAs is used for calculation:
[0059] X0=(X 0H , X 0L )=a0·b0,X1=(X 1H , X 1M , X 1L )=a1·b0,
[0060] X2=(X 2H , X 2M , X 2L )=a2·b0,X3=(X 3H , X 3M , X 3L )=a3·b0,
[0061] Y0=(Y 0H , Y 0M , Y 0L )=a0·b1,Y1=(Y 1H , Y 1L )=a1·b1,
[0062] Y2=(Y 2H , Y 2M , Y 2L )=a2·b1,Y3=(Y 3H , Y 3M , Y 3L )=a3·b1,
[0063] Z0=(Z 0H , Z 0M , Z 0L )=a0·b2,Z1=(Z 1H , Z 1M , Z 1L )=a1·b2,
[0064] Z2=(Z 2H , Z 2L )=a2·b2,Z3=(Z 3H , Z 3M , Z 3L )=a3·b2,
[0065] A0=(A 0H , A 0M , A 0L)=a0·b3,A1=(A 1H , A 1M , A 1L )=a1·b3,
[0066] A2=(A 2H , A 2M , A 2L )=a2·b3,A3=(A 3H , A 3L )=a3·b3,
[0067] B0=(B 0H , B 0M , B 0L )=a0·b4,B1=(B 1H , B 1M , B 1L )=a1·b4,
[0068] B2=(B 2H , B 2M , B 2L )=a2·b4,B3=(B 3H , B 3M , B 3L )=a3·b4
[0069] Among them, X n , Y n , Z n , A n , B n (n=0, 1, 2, 3) represent b0, b1, b2, b3, b4 and a respectively. n The result of the multiplication is split, the subscript L represents the lower 21 bits of the data, the subscript M represents the middle 21 bits of the data, and the subscript H represents the upper 21 bits of the data.
[0070] After the calculation is completed, 20 42-bit partial product results are obtained. The 20 42-bit partial products are aligned and split and reorganized, and then split according to the minimum unit of 21 bits, which can be split into 9 columns from 0 to 8. The 0th column contains 2 elements, the 1st column contains 4 elements, the 2nd column contains 7 elements, the 3rd column contains 10 elements, the 4th column contains 11 elements, the 5th column contains 10 elements, the 6th column contains 7 elements, the 7th column contains 4 elements, and the 8th column contains 1 element. As shown in Table 1, each part of the splicing result is 21 bits of data, so the final multiplication result can be obtained by adding each column.
[0071] Table 1 Splicing results
[0072] 21 21 21 21 21 21 21 21 21 <![CDATA[B 3H ]]> <![CDATA[Z 3H ]]> <![CDATA[Y 3H ]]> <![CDATA[X 3H ]]> <![CDATA[X 2H ]]> <![CDATA[X 1H ]]> <![CDATA[X 1M ]]> <![CDATA[X 0H ]]> <![CDATA[X 0L ]]> <![CDATA[A 3H ]]> <![CDATA[Z 3M ]]> <![CDATA[Y 2H ]]> <![CDATA[X 3M ]]> <![CDATA[X 2M ]]> <![CDATA[X 2L ]]> <![CDATA[X 1L ]]> <![CDATA[Y 0L ]]> <![CDATA[B 2H ]]> <![CDATA[A 2H ]]> <![CDATA[Y 3M ]]> <![CDATA[Y 2M ]]> <![CDATA[X 3L ]]> <![CDATA[Y 0H ]]> <![CDATA[Y 0M ]]> <![CDATA[B 3M ]]> <![CDATA[A 3L ]]> <![CDATA[Z 2H ]]> <![CDATA[Y 3L ]]> <![CDATA[Y 1H ]]> <![CDATA[Y 1L ]]> <![CDATA[Z 0L ]]> <![CDATA[B 1H ]]> <![CDATA[Z 3L ]]> <![CDATA[Z 1H ]]> <![CDATA[Y 2L ]]> <![CDATA[Z 0M ]]> <![CDATA[B 2M ]]> <![CDATA[A 1H ]]> <![CDATA[Z 2L ]]> <![CDATA[Z 0H ]]> <![CDATA[Z 1L ]]> <![CDATA[B 3L ]]> <![CDATA[A 2M ]]> <![CDATA[A 0H ]]> <![CDATA[Z 1M ]]> <![CDATA[A 0L ]]> <![CDATA[B 0H ]]> <![CDATA[A 1M ]]> <![CDATA[A 0M ]]> <![CDATA[B 1M ]]> <![CDATA[A 2L ]]> <![CDATA[Z 1L ]]> <![CDATA[B 2L ]]> <![CDATA[B 0M ]]> <![CDATA[B 0L ]]> <![CDATA[B 1L ]]> 1 4 7 10 11 10 7 4 2
[0073] Next, the partial products of each column after splitting and reorganizing are compressed. The function of the compressor is to convert the original sum of multiple numbers into the equivalent sum of fewer numbers. After four rounds of compression, the results of each column are as follows Figure 3 Stored in 180-bit S and C, where Figure 3 From left to right in the figure, it is from high to low, and every 21 bits are divided and stored. Finally, S and C are added, and the lower 180 bits are intercepted as the output of the 90-bit fixed length compression multiplier. This part involves a 3-stage pipeline to increase the operating frequency of the circuit. The first stage is 20 42-bit partial products relying on DSP multiplication operations, the second stage is a four-layer pipeline compression structure, and the third stage is the addition of S and C.
[0074] like Figure 4 , describes in detail the internal structure and simple block diagram of the 3-2 compressor. The 3-2 compressor inputs three 21-bit binary numbers X1, X2, and X3. X1 and X2 are XORed to provide a multiplex (Mux) selection signal, and then a bit-by-bit selection is required. For example, if the 0th bit is 1 after X1 and X2 are XORed, the 0th bit of the Mux output is the 0th bit of X3. If the 2nd bit is 0 after X1 and X2 are XORed, the 2nd bit of the Mux output is the 2nd bit of X1. In this way, the Mux outputs a 21-bit number, the lower 20 bits are output to the O port, the highest bit, i.e. the 21st bit, is output to the C port, and X1, X2, and X3 are XORed to the S port, which is a 21-bit binary number.
[0075] like Figure 5 , describes in detail the internal structure and simple block diagram of the 4-2 compressor. It mainly adds two AND gates and an XOR gate on the basis of the 3-2 compressor. There are 5 output ports in total, C1 and O1 are the highest and lower 20 bits of the 21-bit output of the Mux, and C2 and O2 are the highest and lower 20 bits of the 21-bit output of the rightmost AND gate.
[0076] like Figure 6 , describes in detail the internal structure and simple block diagram of the 5-2 compressor. It is mainly the series connection of the 3-2 compressor and the 4-2 compressor. There are 5 output ports in total, which just correspond to the 5 output ports of the 4-2.
[0077] 3. Data post-processor
[0078] The data post-processor includes a 90-bit adder-subtractor and a 180-bit adder-subtractor. It takes the result of the 90-bit fixed-length compression multiplier as input, first processes the data using the 90-bit adder-subtractor and the 180-bit adder-subtractor as required, and then stores the results in different registers. The final result can be obtained after splicing.
[0079] The result of the 90-bit fixed-length compression multiplier is sent to the data postprocessor, using six 180-bit registers P2, P1, P0, P 12 ,P 01 ,P 02 The output results of six different inputs are stored; for different numbers sent to the 90-bit fixed-length compression multiplier, the operation output requires different post-processing: when the input is ①A2, B2, ②A1, B1, ④A0, B0, the results are directly stored in registers P2, P1, P0 respectively; when the input is ③(A2+A1), (B2+B1), the result needs to be subtracted from P2 and P1 and then stored in P 12 When the input is ⑤(A0+A1) or (B0+B1), it is necessary to subtract P1 and P0 from the result, add the high 90 bits of P0 and store it in P 01 When the input is ⑥(A2+A0) and (B2+B0), P2 and P0 need to be subtracted from the result, and P1 and P0 need to be added. 01 The high 90 bits are then stored in P 02 ; The addition and subtraction involved in this process requires the use of a 180-bit adder and subtractor;
[0080] When the above operations are completed, the high 90 bits of P2 and the low 90 bits of P2 are added to P 12 The high 90 bits of the addition result, P 12 Low 90 bits and P 02 The high 90 bits of the addition result, P 02 Low 90 bits, P 01 The lower 90 bits, the lower 90 bits of the binary result of P0 are sequentially spliced and intercepted to the lower 512 bits, which is the output result of the 256-bit fast multiplier; the addition and subtraction involved in this process require the use of a 90-bit adder and subtractor;
[0081] like Figure 2, describes in detail the internal structure of the 256-bit fast multiplier. The input 256-bit integers A and B are decomposed into three 90-bit integers A2, A1, A0, B2, B1, B0, where A2 and B2 are less than 90 bits and need to be padded with 0. a and b are 90-bit registers used to store the two multipliers sent to the 90-bit fixed-length compression multiplier. D in the figure represents a delay of one clock cycle, 2D represents a delay of two clock cycles, and so on. A2, A1, A2+A1, A0, A1+A0, A2+A0 are sent to register a for storage at the 0th, 1st, 2nd, 3rd, 4th, and 5th clock cycles respectively, and B2, B1, B2+B1, B0, B1+B0, B2+B0 are sent to register b for storage at the 0th, 1st, 2nd, 3rd, 4th, and 5th clock cycles respectively. In each clock cycle, the values stored in registers a and b are sent to the 90-bit fixed-length compression multiplier for operation, and the operation outputs a 180-bit multiplication result, which is stored in registers P2, P1, and P2 respectively. 12 ,P0,P 01 ,P 02 Among them, P 2H Represents the high 90 bits of P2, P 2L Represents the lower 90 bits of P2, and so on. 12 Before the multiplication, P2 and P1 need to be subtracted and stored in P 01 Before that, you need to subtract P1, P0 and add P 0H , deposit into P 02 Need to add P1,P 01H , minus P0 and P2. When P is stored 02 After completion, follow {P 2H ,P 2L +P 12H ,P 12L +P 02H ,P 02L ,P 01L ,P 0L} can be concatenated to obtain a 512-bit multiplication result.
[0082] 2. SM2 Fast Modulus Reducer
[0083] The SM2 fast modular reducer contains 32-bit adders and subtractors, and uses ripple carry adders to form a carry structure. Figure 7 , describes the structure of the SM2 fast modular reducer in detail, uses the prime characteristics of SM2 and the properties of mathematical congruence to simplify the modular operation, splits the input 512-bit integer X into 32 bits from high to low, and obtains 16 32-bit results. Addition and shift operations are used to replace the division involved in the original modular operation, and the reuse of repeated sums is considered. A tree-like addition structure is given as shown in the figure, and the final output 256-bit result is the final result of the modular multiplication.
[0084] The SM2 fast modular reducer realizes the function of taking the remainder of a prime number p. The operation process is as follows:
[0085] Let c be the output of a 256-bit fast multiplier, c is 512 bits, and 0≤c<p 2 , for the special form of prime number p on the national secret algorithm SM2, p=2 256 -2 224 -2 96 +2 64 -1, find cmodp can be efficient. Split c into 32 bits, where c i is the result of splitting c into 32 bits, that is, c = (c 15 ,c 14 ,c 13 ,c 12 ,c 11 ,c 10 ,c9,c8,c7,c6,c5,c4,c3,c2,c1,c0) 32x16 , we can use the following congruence to reduce the high-order power of 2 in the formula:
[0086] 2 256 =2 224 +2 96 -2 64 +1(modp)
[0087] 2 288 =2 224 +2 128 -2 64 +2 32 +1(modp)
[0088] 2 320 =2 224 +2 160 +2 32 +1(modp)
[0089] 2 352 =2 224 +2 192 +2 96 +2 32 +1(modp)
[0090] 2 384 =2·2 224 +2 128 +2 96 +2 32 +1(modp)
[0091] 2 416 =2·2 224+2 160 +2 128 +2 2 96 -2 64 +2 32 +2(modp)
[0092] 2 448 =2·2 224 +2 192 +2 160 +2 2 128 +2 96 -2 64 +2 2 32 +2(modp)
[0093] 2 480 =3·2 224 +2 192 +2 2 160 +2 128 +2 96 +2 2 32 +2(modp)
[0094] So c can be expressed as c' as follows:
[0095] c'=3c 15 2 224 +c 15 2 192 +c 15 2 128 +c 15 2 96 +2c 15 2 32 +2c 15 +2c 14 2 224 +c 14 2 192 +c 14 2 160 +2c 14 2 128 +c 14 2 96 -c 14 2 64 +2c 14 2 32 +2c 14 +2c 13 2 224 +c 13 2 160 +c 13 2 128 +2c 13 2 96 -c 13 2 64 +c13 2 32 +2c 13 +2c 12 2 224 +c 12 2 128 +2c 12 2 96 +c 12 2 32 +c 12 +2c 11 2 224 +c 11 2 192 +c 11 2 96 +c 11 2 32 +c 11 +c 10 2 224 +c 10 2 160 +c 10 2 32 +c 10 +c92 224 +c92 128 -c92 64 +c92 32 +c9+c82 224 +c82 96 -c82 64 +c8+c72 224 +c62 192 +c52 160 +c42 128 +c32 96 +c22 64 +c12 32 +c0(modp)
[0096] According to the representation of c', the intermediate process y can be derived i The expression is:
[0097] Assume that c=(c 15 ,c 14 ,…,c0) 32x16 , then for y i ∈[0,2 256 -1], there is:
[0098] y1=(c7,c6,c5,c4,c3,c2,c1,c0)
[0099] y2=(c 15 ,0,0,0,0,0,0,0)
[0100] y3=(c12 ,0,c 15 ,c 14 ,0,0,0,c 13 )
[0101] y4=(c 13 ,0,0,0,0,0,c 14 ,c 15 )
[0102] y5=(c 14 ,0,0,0,c 13 ,0,c 15 ,c 14 )
[0103] y6=(c8,c 11 ,c 13 ,c 15 ,c 14 ,0,c9,c 10 )
[0104] y7=(c9,c 14 ,c 10 ,c 13 ,c8,0,c 11 ,c 12 )
[0105] y8=(c 10 ,c 15 ,c 14 ,c 12 ,c 11 ,0,c 13 ,c8)
[0106] y9=(c 11 ,0,0,c9,c 12 ,0,c 10 ,c9)
[0107] y 10 =(0,0,0,0,c 15 ,0,c 12 ,c 11 )
[0108] y 11 =(0,0,0,0,0,c8,0,0)
[0109] y 12 =(0,0,0,0,0,c9,0,0)
[0110] y 13 =(0,0,0,0,0,c 13 ,0,0)
[0111] y14 =(0,0,0,0,0,c 14 ,0,0)
[0112] That is, c' can be further transformed into the following expression, where r i The result of splitting c' into 32 bits:
[0113] c'=(r8,r7,r6,r5,r4,r3,r2,r1,r0) 32x9 =y1+3y2+2y3+2y4+2y5+y6+y7+y8+y9+y 10 -y 11 -y 12 -y 13 -y 14
[0114] For the traditional fast modular reduction algorithm, after obtaining the above modular reduction equation, it is necessary to repeatedly subtract p until the result is less than p. It can be seen that in the worst case, the intermediate results need to be subtracted 14 times to get the final result. In order to avoid too many subtraction algorithms, we perform another modular reduction operation, and the modular reduction in the second stage is:
[0115] y 15 =(r7,r6,r5,r4,r3,r2,r1,r0)
[0116] y 16 =(r8,0,0,0,r8,0,0,r8)
[0117] y 17 =(0,0,0,0,0,r8,0,0)
[0118] c"=y 15 +y 16 -y 17
[0119] c" is the final result. According to the expression of c", after obtaining c", only one more subtraction is needed in the worst case, which saves a lot of iterative subtraction steps compared with the traditional algorithm. After one subtraction, the result of cmodp can be obtained.
[0120] A method for implementing a fast modular multiplication chip based on an SM2 specific domain, using the above-mentioned fast modular multiplication chip implementation device based on an SM2 specific domain, includes the following process:
[0121] (1) After loading two 256-bit unsigned integers A and B, they are input into a 256-bit fast multiplier, which internally splits the two 256-bit unsigned integers into six 90-bit integers, namely A2, A1, A0, B2, B1, B0, where A = (A2, A1, A0) 90x3 , B=(B2,B1,B0) 90x3 , where A0 and B0 correspond to bits 1 to 90 of A and B, A1 and B1 correspond to bits 91 to 180 of A and B, and A2 and B2 correspond to bits 181 to 256 of A and B. If A2 and B2 are less than 90 bits, they are padded with zeros. According to the internal logical structure of the 256-bit fast multiplier, the 90-bit integers need to be added by a decomposition and recombiner to obtain six groups of 90-bit unsigned integers to be multiplied: ①A2 and B2, ②A1 and B1, ③(A2+A1), (B2+B1), ④A0 and B0, ⑤(A0+A1), (B0+B1), ⑥(A2+A0), (B2+B0). These six groups of data are sent to the 90-bit fixed-length compression multiplier in different clock cycles.
[0122] (2) In the 90-bit fixed-length compression multiplier, two 90-bit unsigned integers are input, and there is a three-stage pipeline structure. The first stage of the pipeline splits one of the 90-bit unsigned integers into four 24-bit unsigned integers every 24 bits, and the other 90-bit unsigned integer is split into five 18-bit unsigned integers every 18 bits, and then performs a 24×18-bit partial product multiplication grouper, which is divided into 9 groups in total; the second stage of the pipeline performs four rounds of compression on the reorganized partial products of the 9 groups using a 3-2 compressor, a 4-2 compressor, and a 5-2 compressor, and the final compressed results are assembled into two 180-bit unsigned integers; the third stage of the pipeline completes the addition of the two 180-bit unsigned integers;
[0123] (3) When a 90-bit unsigned integer is input for the first time, it takes 3 clock cycles to output the first input, and then each clock cycle outputs the corresponding results of the sequential input. The results obtained from different inputs are sent to the data post-processor for corresponding addition and stored in different registers. Finally, a 512-bit multiplication result is obtained by splicing and input into the SM2 fast modular reducer.
[0124] (4) In the SM2 fast modular reducer, a 512-bit unsigned integer is input and split into 16 32-bit unsigned integers. Then, according to the designed algorithm flow, the repeated parts and factors are first calculated, and then 32-bit high-radix addition is performed. Finally, the carry of each 32-bit addition result is processed to obtain the final output modular multiplication result.
[0125] The implementation scheme of the present invention for the chip is as follows:
[0126] For the input of two 256-bit unsigned integers, use the register resources inside the FPGA and configure two 256-bit registers to store the external input. Split them into three 90-bit unsigned integers, namely A2, A1, A0, B2, B1, and B0, take six 90-bit registers, read the corresponding data into the 90-bit registers, and fill them from low to high. When the 90 bits are not fully filled, the high bits need to be filled with zeros to prevent the appearance of uncertain X states.
[0127] Get the 6 split 90-bit unsigned integers, use the carry chain (CARRY) resources inside the FPGA, in the 7 series FPGA, CARRY is a 4-bit CARRY4 structure, its function is to implement the carry-lookahead addition of 2 4-bit unsigned numbers, in the Zynq UltraScale, CARRY is an 8-bit CARRY8 structure, its function is to implement the carry-lookahead addition of 2 8-bit unsigned numbers. Since the data used in the algorithm will not exceed 90 bits, the 90-bit register can be used to store its calculation results.
[0128] Since CARRY4 / CARRY8 can only implement 4 / 8-bit carry-lookahead addition, carry-lookahead addition is the adder structure with the shortest delay and the fastest operation speed. However, if a 90-bit carry-lookahead adder is to be implemented, its resource consumption is too large and it is not easy to implement on a chip. Therefore, the CARRY4 / CARRY8 inside the FPGA is used to form a ripple carry adder. Taking CARRY4 as an example, the principle is as follows: Each CARRY4 completes a 4-bit carry-lookahead addition and outputs the carry result of the 4-bit addition. In order to form a 90-bit adder, about 23 CARRY4s are required. Each CARRY4 receives two 4-bit inputs and a 1-bit carry input, and outputs a 4-bit addition result and a 1-bit carry result. The 23 CARRY4s are connected, and the carry result of the low-bit CARRY4 is connected to the carry input of the next CARRY4, and the carry input of the lowest-bit CARRY4 is set to 0. Divide the two 90-bit numbers into 4-bit increments, and input them into 23 CARRY4s from low to high. Finally, concatenate the 4-bit outputs of the 23 CARRY4s to get the result of adding the two 90-bit numbers. If it is on Zynq UltraScale, 12 CARRY8 structures are used in series.
[0129] According to the algorithm design, these six 90-bit data are added to obtain six groups of unsigned integers to be multiplied: ①A2, B2, ②A1, B1, ③(A2+A1), (B2+B1), ④A0, B0, ⑤(A0+A1), (B0+B1), ⑥(A2+A0), (B2+B0), and are input into the 90-bit fixed-length compression multiplier at the rising edge of each clock cycle.
[0130] In the 90-bit fixed-length compression multiplier, for two input 90-bit unsigned integers, one is split every 24 bits, a total of 4, and the other is split every 18 bits, a total of 5. In the 7 series FPGA and UltraScale, a DSP unit can complete a maximum of 25×18-bit multiplication operations. Here, 4 24-bit numbers and 5 18-bit numbers are multiplied in pairs, and one DSP is used for each multiplication of two numbers, consuming a total of 20 DSPs. After all operations are completed, 20 partial products are obtained, and then the 20 partial products are split and reorganized to form 9 columns, each of which is a 21-bit unsigned integer, a total of 56 new 21-bit unsigned numbers, which are stored in 56 21-bit registers.
[0131] 56 21-bit unsigned numbers are compressed in columns using 3-2 compressors, 4-2 compressors, and 5-2 compressors. The purpose of the compressors is to convert more additions into fewer equivalent additions. Through the compression method of the present invention, the 56 21-bit unsigned numbers can be finally converted into 16 and 21-bit unsigned numbers and 2 1-bit unsigned numbers, and finally converted into 2 180-bit unsigned integers for addition.
[0132] Regarding the detailed internal structure of the compressor, the 3-2 compressor consists of only two XOR gates and one select gate. The 4-2 compressor adds two AND gates and one XOR gate on the basis of 3-2. The 5-2 compressor can be regarded as a series connection of the 3-2 compressor and the 4-2 compressor. In FPGA, its internal logic implementation uses LUT, that is, a lookup table. Its principle is to calculate all possible outputs according to different inputs and store them in the LUT. When it is needed, it can directly find the corresponding result according to the input. Each 3-2 compressor consumes 21 LUTs, and the 4-2 compressor and the 5-2 compressor consume 42 LUTs. For the 4-2 compressor and the 5-2 compressor, although the same number of LUTs are used, the 5-2 compressor has a stronger compression capability, but it also increases the length of the critical path. The so-called critical path mainly limits the maximum frequency of the circuit. The longer the critical path, the higher the delay. The higher the delay, the lower the maximum frequency of the circuit. The lower the circuit operating frequency, the slower the circuit operation speed. The compression structure selected reasonably in the present invention is optimal, so that the comprehensive performance of area and delay is optimal.
[0133] As mentioned above, from the first input to the 90-bit fixed-length compression multiplier, due to its 3-stage pipeline structure, the first output is generated three clock cycles after the first input, and after the first output, the output is generated in each subsequent cycle. For different outputs, different post-processing is performed on the output and stored in a 180-bit register, mainly involving adders and subtractors. The SM2 fast modular reducer mainly involves 32-bit adders and subtractors, which are similar to the design ideas in the previous article and will not be repeated.
[0134] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A fast modular multiplication chip implementation device based on SM2 specific domain, characterized in that: It includes a 256-bit fast multiplier and an SM2 fast modular reducer, wherein the 256-bit fast multiplier is connected to the SM2 fast modular reducer, and transmits the final 512-bit multiplication result to the SM2 fast modular reducer; The 256-bit fast multiplier includes a decomposition and recombiner, a 90-bit fixed-length compression multiplier and a data post-processor which are connected in sequence. Two 256-bit unsigned integers are input from the outside and enter the decomposition and recombiner. The decomposition and recombiner sends the recombined result to the 90-bit fixed-length compression multiplier in cycles. The obtained result is then sent to the data post-processor for processing, and finally a 512-bit multiplication result is output; The decomposition and recombining device comprises a delay unit and a 90-bit adder, which first decomposes the input 256-bit unsigned integer into three 90-bit unsigned integers, and then uses the 90-bit adder to recombine the corresponding 90-bit unsigned integers, which are output in sequence after passing through the delay unit and sent to the 90-bit fixed-length compression multiplier; The 90-bit fixed-length compression multiplier comprises a 24×18-bit partial product multiplication grouper, a 3-2 compressor, a 4-2 compressor, a 5-2 compressor, and a 180-bit adder; after inputting two 90-bit unsigned integers to be operated after reorganization, firstly, a 24×18-bit multiplication operation is performed using DSP resources, and then the obtained partial products are grouped, and each group of data is processed using a 3-2 compressor, a 4-2 compressor, and a 5-2 compressor, respectively, to finally obtain a sum and a carry, both of which are 180 bits, and are input into a 180-bit adder, and the final 90-bit multiplication result is output; the 180-bit adder adopts a ripple carry adder to form a carry structure, and the 90-bit fixed-length compression multiplier is connected to a data post-processor, and the obtained result is sent to the data post-processor for subsequent processing; The data post-processor includes a 90-bit adder-subtractor and a 180-bit adder-subtractor, takes the result of the 90-bit fixed-length compression multiplier as input, first uses the 90-bit adder-subtractor and the 180-bit adder-subtractor to process the data as required, and then stores the results in different registers, and the final result can be obtained after splicing; The SM2 fast modular reducer includes a 32-bit adder-subtractor, and adopts a ripple carry adder to form a carry structure. The input 512-bit multiplication result is split into 16 32-bit unsigned integers, and then the repeated parts and factors are calculated. Next, 32-bit high-radix addition is performed, and finally the carry of each 32-bit addition result is processed to obtain the final output modular multiplication result.
2. A fast modular multiplication chip implementation device based on SM2 specific domain according to claim 1, characterized in that: The operation process of the decomposition and recombination device is as follows: Assume that 256-bit unsigned integers A and B are input values. First, they enter the decomposition and recombiner, and A and B are divided into 90-bit A2, A1, A0, B2, B1, B0, that is, A = (A2, A1, A0) 90x3 , B=(B2,B1,B0) 90x3 , where A0 and B0 correspond to bits 1 to 90 of A and B, A1 and B1 correspond to bits 91 to 180 of A and B, and A2 and B2 correspond to bits 181 to 256 of A and B. If A2 and B2 are less than 90 bits, they are padded with zeros; a 90-bit adder is used to calculate to obtain A2+A1, A2+A0, A1+A0, B2+B1, B2+B0, and B1+B0; then a delay unit is used to delay the paired inputs ①A2, B2, ②A1, B1, ③(A2+A1), (B2+B1), ④A0, B0, ⑤(A0+A1), (B0+B1), ⑥(A2+A0), (B2+B0) by 0, 1, 2, 3, 4, and 5 clock cycles respectively and send them to a 90-bit fixed-length compression multiplier.
3. The fast modular multiplication chip implementation device based on SM2 specific domain according to claim 2 is characterized in that: The 90-bit fixed-length compression multiplier performs a 90-bit unsigned integer multiplication operation, and its output result is a 180-bit unsigned integer, wherein the operation process is as follows: Assume that 90-bit unsigned integers a and b are input values. First, divide a into a3, a2, a1, a0 every 24 bits, and divide b into b4, b3, b2, b1, b0 every 18 bits, that is, a = (a3, a2, a1, a0) 24x4 , b=(b4,b3,b2,b1,b0) 18x5 , using the DSP in 20 FPGAs to perform calculations, after the calculations are completed, 20 42-bit partial product results are obtained, and these partial products are spliced together according to the corresponding weights. Each part of the spliced result is 21 bits of data, so each column is added together to get the final multiplication result; After the 90-bit fixed-length compression multiplier generates an output for the first time, it outputs the operation result in turn in each clock cycle and sends it to the data post-processor.
4. The fast modular multiplication chip implementation device based on the SM2 specific domain according to claim 3 is characterized in that: The data post-processor uses six 180-bit registers P2, P1, P0, P 12 ,P 01 ,P 02 The output results of six different inputs are stored; for different numbers sent to the 90-bit fixed-length compression multiplier, the operation output requires different post-processing: when the input is ①A2, B2, ②A1, B1, ④A0, B0, the results are directly stored in registers P2, P1, P0 respectively; when the input is ③(A2+A1), (B2+B1), the result needs to be subtracted from P2 and P1 and then stored in P 12 When the input is ⑤(A0+A1) or (B0+B1), it is necessary to subtract P1 and P0 from the result, add the high 90 bits of P0 and store it in P 01 When the input is ⑥(A2+A0) and (B2+B0), P2 and P0 need to be subtracted from the result, and P1 and P0 need to be added. 01 The high 90 bits are then stored in P 02 ; The addition and subtraction involved in this process requires the use of a 180-bit adder and subtractor; When the above operations are completed, the high 90 bits of P2 and the low 90 bits of P2 are added to P 12 The high 90 bits of the addition result, P 12 Low 90 bits and P 02 The high 90 bits of the addition result, P 02 Low 90 bits, P 01 The lower 90 bits, the lower 90 bits of the binary result of P0 are sequentially concatenated to intercept the lower 512 bits, which is the output result of the 256-bit fast multiplier; the addition and subtraction involved in this process requires the use of a 90-bit adder and subtractor.
5. The fast modular multiplication chip implementation device based on SM2 specific domain according to claim 1 is characterized in that: The SM2 fast modular reducer realizes the function of taking the remainder of a prime number p, wherein the operation process is as follows: First, input a 512-bit integer c modulo a prime number p, where the range of c is 0≤c<p 2 ,p=2 256 -2 224 -2 96 +2 64 -1, split the 512-bit integer c into 32-bit parts, that is, c = (c 15 ,c 14 ,c 13 ,c 12 ,c 11 ,c 10 ,c9,c8,c7,c6,c5,c4,c3,c2,c1,c0) 32x16 , where c i The result of splitting c into 32 bits each is obtained by using the congruence property to write c into the following c' form: c'=3c 15 2 224 +c 15 2 192 +c 15 2 128 +c 15 2 96 +2c 15 2 32 +2c 15 +2c 14 2 224 +c 14 2 192 +c 14 2 160 +2c 14 2 128 +c 14 2 96 -c 14 2 64 +2c 14 2 32 +2c 14 +2c 13 2 224 +c 13 2 160 +c 13 2 128 +2c 13 2 96 -c 13 2 64 +c 13 2 32 +2c 13 +2c 12 2 224 +c 12 2 128 +2c 12 2 96 +c 12 2 32 +c 12 +2c 11 2 224 +c 11 2 192 +c 11 2 96 +c 11 2 32 +c 11 +c 10 2 224 +c 10 2 160 +c 10 2 32 +c 10 +c92 224 +c92 128 -c92 64 +c92 32 +c9+c82 224 +c82 96 -c82 64 +c8+c72 224 +c62 192 +c52 160 +c42 128 +c32 96 +c22 64 +c12 32 +c0 Then, expand c' to 32 bits to c' = (r8, r7, r6, r5, r4, r3, r2, r1, r0) 32x9 , r i That is, c' is split into 32 bits, and then c" = (r7, r6, r5, r4, r3, r2, r1, r0) 32 -(r8,0,0,0,r8,-r8,0,r8) 32 , the range of c″ is (0,2p); Finally, determine whether c″ is greater than the prime number p. If it is greater, subtract p to get the final result. If it is less, output the result directly.
6. A method for implementing a fast modular multiplication chip based on a SM2 specific domain, using a fast modular multiplication chip implementation device based on a SM2 specific domain as claimed in claim 1, characterized in that: The process includes the following: (1) After loading two 256-bit unsigned integers A and B, they are input into the decomposition and recombination device of the 256-bit fast multiplier, which internally decomposes the two 256-bit unsigned integers into six 90-bit integers, namely A2, A1, A0, B2, B1, B0, where A = (A2, A1, A0) 90x3 , B=(B2,B1,B0) 90x3 , where A0 and B0 correspond to bits 1 to 90 of A and B, A1 and B1 correspond to bits 91 to 180 of A and B, and A2 and B2 correspond to bits 181 to 256 of A and B. If A2 and B2 are less than 90 bits, they are padded with zeros; the 90-bit integers are added to obtain six groups of 90-bit unsigned integers to be multiplied: ①A2 and B2, ②A1 and B1, ③(A2+A1), (B2+B1), ④A0 and B0, ⑤(A0+A1), (B0+B1), ⑥(A2+A0), (B2+B0), and these six groups of data are sent to the 90-bit fixed-length compression multiplier in different clock cycles; (2) In the 90-bit fixed-length compression multiplier, two 90-bit unsigned integers are input, and a three-stage pipeline structure is formed. The first stage of the pipeline splits one of the 90-bit unsigned integers into four 24-bit unsigned integers every 24 bits, and the other 90-bit unsigned integer is split into five 18-bit unsigned integers every 18 bits, and then a 24×18-bit partial product multiplication grouper is performed, which is divided into nine groups in total; The second-stage pipeline performs four rounds of compression on the 9 groups of reorganized partial products using a 3-2 compressor, a 4-2 compressor, and a 5-2 compressor, and assembles the final compressed results into two 180-bit unsigned integers; the third-stage pipeline completes the addition of the two 180-bit unsigned integers; (3) When a 90-bit unsigned integer is input for the first time, it takes 3 clock cycles to output the first input, and then each clock cycle outputs the corresponding results of the sequential input. The results obtained from different inputs are sent to the data post-processor for corresponding addition and stored in different registers. Finally, a 512-bit multiplication result is obtained by splicing and input into the SM2 fast modular reducer. (4) In the SM2 fast modular reducer, a 512-bit unsigned integer is input and split into 16 32-bit unsigned integers. The repeated parts and factors are then calculated. Next, 32-bit high-radix addition is performed. Finally, the carry of each 32-bit addition result is processed to obtain the final output modular multiplication result.
