Hardware acceleration implementation method and device for number-theory transformation and security chip
Through the splitting and shift calculation of polynomial data of the logarithmic transformation module, the problem that the hardware-based number theory transformation module cannot support large number of terms and large bit width is solved, and infinite expansion and efficient calculation of hardware computing capabilities are achieved.
Patent Information
- Application Number
- CN202411444251.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2024-11-29
AI Technical Summary
The existing hardware-based number theory transformation module cannot flexibly expand the number of terms and bit width, resulting in insufficient computing power, and increasing hardware overhead to support large terms and bit width will lead to an increase in chip area.
By splitting the polynomial data to be calculated into polynomial data with the number of small terms and the width of small bits according to the preset polynomial splitting method, and using the number theory transform hardware calculation unit for calculation processing, and using the split algorithm hardware module for shift calculation, finally, The calculation result of splicing into the number of large terms and large bit width.
Without increasing hardware overhead, the calculation ability of hardware-based number theory transforms large terms and large bit width is realized, breaking through the hardware limitation, so that the number of terms and bit width supported by the number theory transform hardware calculation unit can be infinitely expanded to achieve a greater degree of Small hardware resources achieve the purpose of large-scale computing.
Smart Images

Figure CN119046594A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of hardware accelerators, and in particular to a hardware acceleration implementation method for number theoretic transformation, a hardware acceleration implementation device for number theoretic transformation, and a security chip. Background Art
[0002] The application field of the fast number theoretic transform (NTT) algorithm is extremely wide, and it is the underlying core operator of many computing algorithms. However, the transformation process for large numbers of terms and large bit widths consumes a lot of computer computing power. Therefore, the hardware design of NTT to achieve acceleration is more common in fields such as dedicated chips or FPGAs.
[0003] At present, the number of items and bit width of the NTT module designed by hardware are basically fixed. This is because they are affected by the logical judgment in the hardware and the number of items and bit width are fixed registers, which cannot be flexibly expanded. At the same time, the space of BRAM (Block RAM) used for data buffering in NTT is limited. These factors lead to the number of items and bit width supported by the transformation process of the hardware module NTT being backward compatible but not upward compatible, so the flexibility is poor. However, if the NTT hardware module supporting a larger number of items and bit width is directly designed, it will bring a lot of hardware overhead and increase the chip area.
[0004] Therefore, how to improve the computing power of hardware-based number theory transformations with large terms and large bit widths without increasing hardware overhead has become a technical problem that needs to be urgently solved by technical personnel in this field. Summary of the invention
[0005] The present invention provides a hardware acceleration implementation method for number theoretic transformation, a hardware acceleration implementation device for number theoretic transformation and a security chip, which solve the problem existing in the related art that the computing power of hardware number theoretic transformation with large number of terms and large bit width cannot be improved without increasing the cost.
[0006] As a first aspect of the present invention, a method for hardware acceleration of number theory transformation is provided, which comprises:
[0007] Obtaining polynomial data to be calculated, where the number of terms of the polynomial data to be calculated is p, the bit width of the polynomial data to be calculated is q, and both p and q are natural numbers greater than 1;
[0008] Splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain polynomial split data to be calculated, wherein the preset polynomial splitting method includes term number splitting or bit width splitting, the number of terms of the polynomial split data to be calculated is less than or equal to p / 2, and the bit width of the polynomial split data to be calculated is less than or equal to q / 2;
[0009] Calling a number theory transformation hardware calculation unit, and inputting the polynomial split data to be calculated into the number theory transformation hardware calculation unit, the number theory transformation hardware calculation unit can perform calculation processing on the polynomial split data to be calculated to obtain multiple forward transformation calculation sequences or multiple inverse transformation calculation sequences, wherein the number of polynomial terms supported by the number theory transformation hardware calculation unit is less than p, and the polynomial bit width supported by the number theory transformation hardware calculation unit is less than q;
[0010] Multiple forward transform calculation sequences are input into the split algorithm hardware module for shift calculation to obtain polynomial forward transform calculation results, or multiple inverse transform calculation sequences are input into the split algorithm hardware module for shift calculation to obtain polynomial inverse transform calculation results, the number of terms of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is p, and the bit width of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is q.
[0011] Further, a plurality of forward transform calculation sequences are input into the split algorithm hardware module for shift calculation to obtain a polynomial forward transform calculation result, or a plurality of inverse transform calculation sequences are input into the split algorithm hardware module for shift calculation to obtain a polynomial inverse transform calculation result, including:
[0012] Determine the number of forward transformation calculation sequences, or determine the number of inverse transformation calculation sequences;
[0013] Shift calculations are performed on multiple forward transform calculation sequences in sequence according to the splitting order, and the results of the shift calculations of each forward transform calculation sequence are added to obtain a polynomial forward transform calculation result; or, shift calculations are performed on multiple inverse transform calculation sequences in sequence according to the splitting order, and the results of the shift calculations of each inverse transform calculation sequence are added to obtain a polynomial inverse transform calculation result.
[0014] Further, the splitting algorithm hardware module includes: a counter and a calculation unit, wherein the calculation unit is connected to the counter;
[0015] The counter is used to determine the number of forward transformation calculation sequences or the number of inverse transformation calculation sequences obtained after the polynomial data to be calculated is split;
[0016] The calculation unit is used to perform shift calculation and addition calculation on multiple forward transformation calculation sequences to obtain polynomial forward transformation calculation results, or to perform shift calculation and addition calculation on multiple inverse transformation calculation sequences to obtain polynomial inverse transformation calculation results.
[0017] Furthermore, the splitting algorithm hardware module also includes a combinational logic unit, which is connected to the computing unit, and is used to logically control the computing process of the computing unit according to a judgment signal generated during the computing process of the computing unit.
[0018] Further, the polynomial data to be calculated is split according to a preset polynomial splitting method to obtain the polynomial split data to be calculated, including:
[0019] The polynomial data to be calculated is evenly split according to the term number splitting method to obtain at least two polynomial split data to be calculated.
[0020] Further, the polynomial data to be calculated is split according to a preset polynomial splitting method to obtain the polynomial split data to be calculated, including:
[0021] According to the bit width splitting method, the polynomial data to be calculated is evenly split in the order of bit width from high to low to obtain at least two polynomial split data to be calculated.
[0022] Furthermore, the hardware acceleration implementation method for number theory transformation also includes the following steps before inputting the polynomial splitting data to be calculated into the number theory transformation hardware calculation unit:
[0023] Determine whether the number of polynomial terms supported by the currently called number theory transformation hardware computing unit is greater than or equal to the number of terms of the current polynomial split data to be calculated, or determine whether the polynomial bit width supported by the currently called number theory transformation hardware computing unit is greater than or equal to the bit width of the current polynomial split data to be calculated;
[0024] If the number of polynomial terms supported by the currently called number theory transformation hardware computing unit is greater than or equal to the number of terms of the current polynomial split data to be calculated, or if the polynomial bit width supported by the currently called number theory transformation hardware computing unit is greater than or equal to the bit width of the current polynomial split data to be calculated, then it is determined that the currently called number theory transformation hardware computing unit is capable of performing calculation processing on the polynomial split data to be calculated;
[0025] If the number of polynomial terms supported by the currently called number theoretic transformation hardware computing unit is less than the number of terms of the current polynomial split data to be calculated, or if the polynomial bit width supported by the currently called number theoretic transformation hardware computing unit is less than the bit width of the current polynomial split data to be calculated, then the action of splitting the current polynomial split data to be calculated according to the preset polynomial splitting method is repeated until the number of terms of the polynomial split data to be calculated after the split is less than or equal to the number of polynomial terms supported by the currently called number theoretic transformation hardware computing unit, or until the bit width of the polynomial split data to be calculated after the split is less than or equal to the polynomial bit width supported by the currently called number theoretic transformation hardware computing unit.
[0026] Further, the number theory transformation hardware computing unit includes at least one NTT hardware computing module or at least one INTT hardware computing module, the number of polynomial terms supported by each NTT hardware computing module and each INTT hardware computing module is less than p, and the bit width of the polynomial supported by each NTT hardware computing module and each INTT hardware computing module is less than q;
[0027] When the number theory transformation hardware calculation unit includes an NTT hardware calculation module or an INTT hardware calculation module, the multiple polynomial split data to be calculated are calculated in sequence by the NTT hardware calculation module or the INTT hardware calculation module;
[0028] When the number theory transformation hardware computing unit includes multiple NTT hardware computing modules or multiple INTT hardware computing modules, multiple polynomial split data to be calculated can be calculated in parallel by multiple NTT hardware computing modules or multiple INTT hardware computing modules.
[0029] As another aspect of the present invention, a hardware acceleration implementation device for number theory transformation is provided, which is used to implement the hardware acceleration implementation method for number theory transformation described above, and includes:
[0030] An acquisition module, used for acquiring polynomial data to be calculated, wherein the number of terms of the polynomial data to be calculated is p, the bit width of the polynomial data to be calculated is q, and both p and q are natural numbers greater than 1;
[0031] A splitting module, used for splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain polynomial split data to be calculated, wherein the preset polynomial splitting method includes term number splitting or bit width splitting, the number of terms of the polynomial split data to be calculated is less than or equal to p / 2, and the bit width of the polynomial split data to be calculated is less than or equal to q / 2;
[0032] A calling and calculating module, used for calling a number theory transformation hardware calculating unit, and inputting the polynomial split data to be calculated into the number theory transformation hardware calculating unit, wherein the number theory transformation hardware calculating unit can calculate and process the polynomial split data to be calculated to obtain multiple forward transformation calculation sequences or multiple inverse transformation calculation sequences, wherein the number of polynomial terms supported by the number theory transformation hardware calculating unit is less than p, and the polynomial bit width supported by the number theory transformation hardware calculating unit is less than q;
[0033] A shift calculation module is used to input multiple forward transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial forward transform calculation results, or to input multiple inverse transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial inverse transform calculation results, wherein the number of terms of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is p, and the bit width of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is q.
[0034] As another aspect of the present invention, a security chip is provided, which includes a chip carrier and the hardware acceleration implementation device for number theory transformation described above, which is arranged on the chip carrier.
[0035] The hardware acceleration implementation method for number theoretic transformation provided by the present invention is to split the polynomial data to be calculated according to the preset polynomial splitting method to obtain the polynomial split data to be calculated, and call the number theoretic transformation hardware calculation unit to calculate the polynomial split data to obtain multiple positive transformation calculation sequences or multiple inverse transformation calculation sequences, and finally input the multiple positive transformation calculation sequences or multiple inverse transformation calculation sequences into the splitting algorithm hardware module for shift calculation to obtain the final calculation result. This hardware acceleration implementation method for number theoretic transformation can realize polynomial calculations with large terms or large bit widths without changing the existing number theoretic transformation hardware calculation unit, so that the number of terms and bit widths supported by the number theoretic transformation hardware calculation unit can be infinitely expanded, so as to achieve the purpose of realizing large-scale number theoretic transformation calculations with smaller hardware resources. Therefore, this hardware acceleration implementation method for number theoretic transformation of the present invention can break through the hardware limitations and improve the computing power of hardware number theoretic transformation with large terms and large bit widths without increasing the hardware overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present invention, but do not constitute a limitation of the present invention.
[0037] Figure 1 A flowchart of the hardware acceleration implementation method for number theory transformation provided by the present invention.
[0038] Figure 2 A flow chart of a method for performing shift calculations in the splitting algorithm hardware module provided by the present invention.
[0039] Figure 3 A structural diagram of an embodiment of the splitting algorithm hardware module provided by the present invention.
[0040] Figure 4 This is a specific structural block diagram of the computing unit provided by the present invention.
[0041] Figure 5 This is a structural diagram of another embodiment of the splitting algorithm hardware module provided by the present invention.
[0042] Figure 6 This is a structural diagram of another embodiment of the splitting algorithm hardware module provided by the present invention.
[0043] Figure 7 This is a schematic diagram of implementing the item number splitting method provided by the present invention.
[0044] Figure 8 This is a schematic diagram of implementing the bit width splitting method provided by the present invention.
[0045] Fig. 9 A schematic diagram of the overall process of the hardware acceleration implementation method for number theory transformation provided by the present invention.
[0046] Fig.10 A schematic diagram of the results of running the large-term polynomial multiplication as a whole and splitting through Python code provided by the present invention.
[0047] Fig.11a A schematic diagram of the running results of the large-bit-width NTT transform splitting python code provided by the present invention.
[0048] Fig.11b A schematic diagram of the running result of the unsplit Python code of the large-bit-width NTT transformation provided by the present invention.
[0049] Fig.12 A structural block diagram of a hardware acceleration implementation device for number theory transformation provided by the present invention.
[0050] Fig.13 This is a structural block diagram of the security chip provided by the present invention. DETAILED DESCRIPTION
[0051] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0052] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiment of the present invention. Obviously, the described embodiment is only a part of the embodiment of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of the present invention.
[0053] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so as to describe the embodiments of the present invention described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0054] During the process of optimizing the design of the NTT module, it was found that considering that the NTT module itself is a very mature algorithm, it is very difficult to directly modify its internal structure. Instead, NTT is treated as a whole that can be scheduled at any time for operation, and the NTT transformation itself facilitates the multiplication of polynomials. Therefore, from the algorithmic point of view, the multiplication of polynomials with large terms and large bit widths is split into multiple multiplications of polynomials with small terms and small bit widths. Through multiple reuse of NTT modules and shift-addition operations, the results of small polynomial multiplications are spliced into large polynomial multiplication results. In this way, the operation of large polynomial multiplication is realized by using small NTT modules from the algorithmic point of view. In order to further achieve a higher acceleration ratio, this software splitting and scheduling NTT solution is also implemented in hardware. This combination of software and hardware can maximize the performance of hardware acceleration.
[0055] Based on this, a hardware acceleration implementation method for number theory transformation is provided in this embodiment. Figure 1 is a flowchart of a method for hardware acceleration implementation of number theory transformation according to an embodiment of the present invention, such as Figure 1 As shown, including:
[0056] S100, obtaining polynomial data to be calculated, where the number of terms of the polynomial data to be calculated is p, the bit width of the polynomial data to be calculated is q, and both p and q are natural numbers greater than 1;
[0057] In an embodiment of the present invention, the specific number of terms of the polynomial data to be calculated is p, and the bit width is q. The number of terms of the polynomial data to be calculated exceeds the number of polynomial terms supported by the existing number theory transformation hardware calculation unit, and the bit width of the polynomial data to be calculated exceeds the bit width supported by the existing number theory transformation hardware calculation unit.
[0058] S200, splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain polynomial split data to be calculated, wherein the preset polynomial splitting method includes term number splitting or bit width splitting, the number of terms of the polynomial split data to be calculated is less than or equal to p / 2, and the bit width of the polynomial split data to be calculated is less than or equal to q / 2;
[0059] It should be understood that the polynomial data to be calculated is split using a preset polynomial splitting method. Specifically, it can be split according to the number of terms or according to the bit width. The specific preset polynomial splitting method is selected according to needs and is not limited here.
[0060] It should be noted that the maximum number of terms of the polynomial split data to be calculated obtained after splitting by the term number splitting method does not exceed p / 2, and the maximum bit width of the polynomial split data to be calculated obtained after splitting by the bit width splitting method does not exceed q / 2.
[0061] It should be understood that when splitting by the number of terms, it can be specifically split into two, that is, splitting the p term into two p / 2s, and if the p / 2 after the split still cannot be used for direct calculation, then each p / 2 can be split into two until the number of terms after the split meets the computing power of the number theory transformation hardware computing unit. Similarly, when splitting by the bit width splitting method, it can be specifically split into two, that is, splitting the bit width q into two q / 2s, and if the q / 2 after the split still cannot be used for direct calculation, then each q / 2 can be split into two until the bit width after the split meets the computing power of the number theory transformation hardware computing unit.
[0062] S300, calling a number theory transformation hardware calculation unit, and inputting the polynomial split data to be calculated into the number theory transformation hardware calculation unit, wherein the number theory transformation hardware calculation unit can perform calculation processing on the polynomial split data to be calculated to obtain multiple forward transformation calculation sequences or multiple inverse transformation calculation sequences, wherein the number of polynomial terms supported by the number theory transformation hardware calculation unit is less than p, and the polynomial bit width supported by the number theory transformation hardware calculation unit is less than q;
[0063] In an embodiment of the present invention, the above-mentioned polynomial split data to be calculated is input into the number theory transformation hardware calculation unit for calculation processing. It should be understood that since the number of polynomial terms supported by the number theory transformation hardware calculation unit is less than p, and the supported polynomial bit width is less than q, the number of terms and / or bit width of the called number theory transformation hardware calculation unit meets the calculation requirements of the number of terms or bit width of the polynomial split data to be calculated, so the polynomial split data to be calculated is processed by forward transformation calculation or inverse transformation calculation based on the called number theory transformation hardware calculation unit.
[0064] S400. Input multiple forward transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial forward transform calculation results, or input multiple inverse transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial inverse transform calculation results, wherein the number of terms of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is p, and the bit width of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is q.
[0065] Since the polynomial data to be calculated is previously processed by forward transformation or inverse transformation after splitting, it is necessary to shift the above multiple forward transformation calculation sequences through the splitting algorithm hardware module to obtain the polynomial forward transformation calculation results, or shift the multiple inverse transformation calculation sequences through the splitting algorithm hardware module to obtain the polynomial inverse transformation calculation results. That is, the number of terms of the final polynomial forward transformation calculation results and the polynomial inverse transformation calculation results is p, and the bit width of the polynomial forward transformation calculation results and the polynomial inverse transformation calculation results is q.
[0066] Therefore, the hardware acceleration implementation method for number theoretic transformation provided by the embodiment of the present invention is to split the polynomial data to be calculated according to the preset polynomial splitting method to obtain the polynomial split data to be calculated, and call the number theoretic transformation hardware calculation unit to calculate the polynomial split data to obtain multiple positive transformation calculation sequences or multiple inverse transformation calculation sequences, and finally input the multiple positive transformation calculation sequences or multiple inverse transformation calculation sequences into the splitting algorithm hardware module for shift calculation to obtain the final calculation result. This hardware acceleration implementation method for number theoretic transformation can realize polynomial calculations with large terms or large bit widths without changing the existing number theoretic transformation hardware calculation unit, so that the number of terms and bit widths supported by the number theoretic transformation hardware calculation unit can be infinitely expanded, so as to achieve the purpose of realizing large-scale number theoretic transformation calculations with smaller hardware resources. Therefore, this hardware acceleration implementation method for number theoretic transformation of the present invention can break through the hardware limitations and improve the computing power of hardware number theoretic transformation with large terms and large bit widths without increasing the hardware overhead.
[0067] In an embodiment of the present invention, multiple forward transform calculation sequences are input into a split algorithm hardware module for shift calculation to obtain a polynomial forward transform calculation result, or multiple inverse transform calculation sequences are input into a split algorithm hardware module for shift calculation to obtain a polynomial inverse transform calculation result, such as Figure 2 As shown, including:
[0068] S410, determining the number of forward transformation calculation sequences, or determining the number of inverse transformation calculation sequences;
[0069] Specifically, the splitting algorithm hardware module first counts the number of forward transform calculation sequences or the number of inverse transform calculation sequences to be shifted, and obtains the number of forward transform calculation sequences or the number of inverse transform calculation sequences.
[0070] S420. Shift calculations are performed on multiple forward transform calculation sequences in sequence according to the splitting order, and the results of the shift calculations of each forward transform calculation sequence are added to obtain a polynomial forward transform calculation result; or, shift calculations are performed on multiple inverse transform calculation sequences in sequence according to the splitting order, and the results of the shift calculations of each inverse transform calculation sequence are added to obtain a polynomial inverse transform calculation result.
[0071] In an embodiment of the present invention, after determining the number of forward transform calculation sequences or inverse transform calculation sequences, multiple forward transform calculation sequences are shifted in sequence according to the splitting order, and then the results of the shift calculations are added to obtain the polynomial forward transform calculation result; or, multiple inverse transform calculation sequences are shifted in sequence according to the splitting order, and then the results of the shift calculations are added to obtain the polynomial inverse transform calculation result.
[0072] It should be understood that by performing shift calculations on multiple forward transform calculation sequences or multiple inverse transform calculation sequences in the split order, the accuracy of the shift calculation results can be guaranteed, and thus the accuracy of the results after the addition calculation can be guaranteed.
[0073] In the embodiment of the present invention, Figure 3 As shown, the splitting algorithm hardware module 100 includes: a counter 110 and a calculation unit 120, and the calculation unit 120 is connected to the counter 110;
[0074] The counter 110 is used to determine the number of forward transformation calculation sequences or the number of inverse transformation calculation sequences obtained after the polynomial data to be calculated is split;
[0075] The calculation unit 120 is used to perform shift calculation and addition calculation on multiple forward transformation calculation sequences to obtain polynomial forward transformation calculation results, or to perform shift calculation and addition calculation on multiple inverse transformation calculation sequences to obtain polynomial inverse transformation calculation results.
[0076] Specifically, the counter 110 can count the number of forward transformation calculation sequences or the number of inverse transformation calculation sequences after the polynomial data to be calculated is split; Figure 4 As shown, the calculation unit 120 may specifically include a shift register 121 and an adder 122 connected to the shift register, wherein the shift register is used to perform a shift operation on a forward transformation calculation sequence or an inverse transformation calculation sequence, and the adder is used to perform an addition operation on the result after the shift operation of the forward transformation calculation sequence, or to perform an addition operation on the result after the inverse transformation shift sequence operation. It should be noted that the specific circuit structure of the shift register and the adder in the embodiment of the present invention can be combined according to the functional requirements of the shift operation, which is not limited here.
[0077] In the embodiment of the present invention, Figure 5 As shown, the splitting algorithm hardware module also includes a combinational logic unit 130, which is connected to the calculation unit 120. The combinational logic unit 130 is used to logically control the calculation process of the calculation unit according to the judgment signal generated during the calculation process of the calculation unit 120.
[0078] It should be understood that the combinational logic unit 130 can be used to implement logical control such as judgment of data in the calculation process of the calculation unit and prevention of data congestion.
[0079] Specifically, the combinational logic unit 130 may include an interrupt logic judgment module, a start / end logic judgment module and a mode switching judgment module, wherein the interrupt logic judgment module can generate an interrupt signal when the calculation data of the calculation unit accumulates to a certain level to prevent data congestion; the start / end logic judgment module can judge the start and end of the calculation process of the calculation unit to facilitate the continuous jumping of the entire calculation process; the mode switching judgment module can determine whether the current operation is the number of terms splitting mode or the bit width splitting mode, so as to facilitate different shift calculation operations.
[0080] It should be noted that the interrupt logic judgment module can be specifically implemented by a trigger, and the specific implementation logic can be combined as needed, which is not limited here; the start / end logic judgment module and the mode switching judgment module can be implemented by a combination of some logic gates, which is not limited here.
[0081] like Figure 6As shown in FIG. 1 , it is a structural diagram of the splitting algorithm hardware module. The splitting algorithm hardware module can be used in conjunction with the number theory transformation hardware calculation unit. The specific operation mode is: first, the mode selection signal is specifically divided into 0 and 1. 0 represents the splitting of the polynomial multiplication with a large number of terms, and 1 represents the splitting of the number theory transformation with a large bit width. The data_in signal represents the point value of the polynomial calculated by the NTT or INTT module to be injected, and the corresponding item_num represents the number of terms of the small polynomial after the splitting. Part_num represents the splitting into several parts. Other conventional signals, including clock signals and reset signals, are injected into the splitting algorithm hardware module. After all signals are injected into the module, the number of split data is first determined by the counter. The split data enters the calculation part for calculation, including operations such as shifting and addition, and finally the calculation result is obtained. Some judgment signals will be generated during the calculation process, which can be specifically controlled by the combinational logic unit, for example, by generating an interrupt signal to prevent excessive data.
[0082] In an embodiment of the present invention, splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain the polynomial split data to be calculated includes:
[0083] The polynomial data to be calculated is evenly split according to the term number splitting method to obtain at least two polynomial split data to be calculated.
[0084] It should be understood that the term splitting method is specifically to perform an average splitting on the polynomial data to be calculated to obtain the polynomial split data to be calculated.
[0085] For example, Figure 7 As shown in the figure, the multiplication of two large polynomials m and n can be split into four groups of small polynomials, m1*n1, m1*n2, m2*n1 and m2*n2. Finally, the results of these four groups are shifted and added to get the final result. The multiplication of the four groups of small polynomials can be implemented by NTT and INTT transformation processes.
[0086] To be more specific, the multiplication of two 4096-term polynomials is the multiplication of polynomial m and polynomial n. The first 2048 terms and the last 2048 terms of polynomial m are split into polynomials m1 and m2 respectively, and the corresponding polynomial n is split into n1 and n2. Then (m1+m2)*(n1+n2)=m1n1+m2n1+m1n2+m2n2. These four sets of polynomial multiplications are quickly multiplied using NTT or INTT that supports a maximum of 2048 terms, and finally a shift and add operation is performed to obtain the product of the 4096-term polynomials m and n.
[0087] In an embodiment of the present invention, splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain the polynomial split data to be calculated includes:
[0088] According to the bit width splitting method, the polynomial data to be calculated is evenly split in the order of bit width from high to low to obtain at least two polynomial split data to be calculated.
[0089] It should be understood that the bit width splitting method is specifically to sort the polynomial data to be calculated in order of bit width from high to low and then perform average splitting to obtain the polynomial split data to be calculated.
[0090] For example, Figure 8 As shown in the figure, the large bit width polynomial multiplication is split into small bit width polynomial multiplication, mainly splitting the large bit width polynomial into two parts, high bit and low bit. Therefore, it is necessary to sort the polynomial data to be calculated from high to low according to the bit width, and then perform number theory transformation respectively, and then perform shift and addition operations on the two groups, and finally obtain the large bit width number theory transformation process.
[0091] For the large bit width number theory transformation process, specifically, if the result of a polynomial is F(x)=A0B0+A1B1x+A2B2x 2 +A3B3x 3 +……A 4095 B 4095 x 4095 , here in A n B n It is 64 bits spliced together. To do NTT transformation, just put x=w0,w1,w2...w 4095 Substituting into the equation, we can obtain F(w0), F(w1), ..., F(w 4095 )These 4096 values.
[0092] F(x)=(A0*2 32 +B0)+(A1*2 32 +B1)x+(A2*2 32 +B2)x 2 +……+(A 4095 *2 32 +B 4095 )
[0093] x 4095 ;
[0094] g(x)=A0+A1x+A2x 2 +A3x 3 +A4x 4 +……A 4095 x 4095 ;
[0095] k(x)=B0+B1x+B2x 2 +B3x 3 +B4x 4 +…B 4095 x 4095 ;
[0096] F(x)=g(x)*2 32 +k(x);
[0097] F(w)=g(w)*2 32 +k(w);
[0098] Therefore, F(w0), F(w1), ..., F(w 4095 ) are transformed into g(w0)*2 32 +k(w0),g(w1)*2 32 +k(w1), ..., g(w 4095 )*2 32 +k(w 4095 ).
[0099] Therefore, a NTT transformation is performed on g(x) to obtain a series of numbers: g0, g1, ..., g 4095 , do an NTT transformation on k(x) to get a string of numbers k0, k1, ..., k 4095 .
[0100] The string of numbers obtained by NTT transformation of F(x) is:
[0101] g0<<32+K0, g1<<32+K1,……,g 4095 <<32+K 4095 .
[0102] For the calculation process of finding INTT, you can replace the substituted value with the multiplicative inverse element of W and multiply it by 1 / n.
[0103] In an embodiment of the present invention, the hardware acceleration implementation method for number theory transformation further includes the following steps before inputting the polynomial splitting data to be calculated into the number theory transformation hardware calculation unit:
[0104] 1) Determine whether the number of polynomial terms supported by the currently called number theory transformation hardware computing unit is greater than or equal to the number of terms of the current polynomial split data to be calculated, or determine whether the polynomial bit width supported by the currently called number theory transformation hardware computing unit is greater than or equal to the bit width of the current polynomial split data to be calculated;
[0105] 2) If the number of polynomial terms supported by the currently called number theory transformation hardware computing unit is greater than or equal to the number of terms of the current polynomial split data to be calculated, or if the polynomial bit width supported by the currently called number theory transformation hardware computing unit is greater than or equal to the bit width of the current polynomial split data to be calculated, it is determined that the currently called number theory transformation hardware computing unit is capable of performing calculation processing on the polynomial split data to be calculated;
[0106] 3) If the number of polynomial terms supported by the currently called number theoretic transformation hardware computing unit is smaller than the number of terms of the current polynomial split data to be calculated, or if the polynomial bit width supported by the currently called number theoretic transformation hardware computing unit is smaller than the bit width of the current polynomial split data to be calculated, then the action of splitting the current polynomial split data to be calculated according to the preset polynomial splitting method is repeated until the number of terms of the polynomial split data to be calculated after the splitting is smaller than or equal to the number of polynomial terms supported by the currently called number theoretic transformation hardware computing unit, or until the bit width of the polynomial split data to be calculated after the splitting is smaller than or equal to the bit width of the polynomial supported by the currently called number theoretic transformation hardware computing unit.
[0107] Specifically, before inputting the polynomial split data to be calculated into the number theory transformation hardware calculation unit, it is necessary to first determine whether the number of polynomial terms supported by the currently called number theory transformation hardware calculation unit can meet the current calculation requirements, or determine whether the polynomial bit width supported by the currently called number theory transformation hardware calculation unit can meet the current calculation requirements. For example, if the number of terms of the current polynomial split data to be calculated is 2048, and the number of polynomial terms supported by the currently called number theory transformation hardware calculation unit is 1024, it is necessary to continue to split the current polynomial split data to be calculated; and if the number of polynomial terms supported by the currently called number theory transformation hardware calculation unit is 2048, the calculation can be performed directly through the number theory transformation hardware calculation unit.
[0108] In an embodiment of the present invention, the number theory transformation hardware computing unit includes at least one NTT hardware computing module or includes at least one INTT hardware computing module, and the number of polynomial terms supported by each NTT hardware computing module and each INTT hardware computing module is less than p, and the bit width of the polynomial supported by each NTT hardware computing module and each INTT hardware computing module is less than q;
[0109] When the number theory transformation hardware calculation unit includes an NTT hardware calculation module or an INTT hardware calculation module, the multiple polynomial split data to be calculated are calculated in sequence by the NTT hardware calculation module or the INTT hardware calculation module;
[0110] When the number theory transformation hardware computing unit includes multiple NTT hardware computing modules or multiple INTT hardware computing modules, multiple polynomial split data to be calculated can be calculated in parallel by multiple NTT hardware computing modules or multiple INTT hardware computing modules.
[0111] It should be understood that the number theory transformation hardware computing unit may include one NTT hardware computing module or one INTT hardware computing module, or may include multiple NTT hardware computing modules or multiple INTT hardware computing modules.
[0112] When one NTT hardware computing module or one INTT hardware computing module is included, multiple polynomial split data to be calculated can be sequentially subjected to forward transformation calculations through the NTT hardware computing module, or subjected to inverse transformation calculations through the INTT hardware computing module.
[0113] When multiple NTT hardware computing modules or multiple INTT hardware computing modules are included, multiple polynomial split data to be calculated can be subjected to forward transformation calculation or inverse transformation calculation in parallel, thereby improving computing efficiency.
[0114] Combine the following Fig. 9 The overall process of the hardware acceleration implementation method for number theory transformation provided by the present invention is described.
[0115] First, a large polynomial data to be calculated is split into multiple polynomial split data to be calculated by selecting the method of splitting by number of terms or splitting by bit width.
[0116] Secondly, the split data of the multiple polynomials to be calculated are all input into a number theory transformation hardware calculation unit, and the number theory transformation hardware calculation unit may include one NTT or INTT, and may also include multiple NTTs or INTTs.
[0117] Finally, the output results of the number theory transformation hardware calculation unit are input into the splitting algorithm hardware module. After being grouped by the counter, they enter the calculation unit for shift and addition operations. This calculation process will be controlled by the combinational logic to send out interrupt, reset, start and other signals, and finally the results of the shift calculation will be obtained.
[0118] It should be understood that the processes of NTT calculation and INTT calculation are the same, the main difference is the calculated rotation factors, where the rotation factor of INTT is the rotation factor of NTT replaced by the multiplicative inverse element of the rotation factor and then divided by 1 / n, and the final output number is the output result of INTT.
[0119] For the hardware acceleration implementation method for number theory transformation of the present invention, the effect of term number splitting and bit width splitting was verified through Python code.
[0120] like Fig.10 As shown, it is a schematic diagram of the results of running the large-term polynomial multiplication as a whole and split through Python code. Fig.10 The third column of data below is the calculation result of the number theory transformation realized by the term splitting method, and the fourth column is the result of the overall operation without splitting. It can be seen that the calculation results of the split calculation and the unsplit calculation are the same, which means that the hardware acceleration implementation method for number theory transformation provided by the present invention can not only realize the polynomial multiplication calculation of large terms by term splitting, but also can realize larger-scale NTT transformation or INTT transformation calculation with smaller hardware resources without being limited by the current number theory transformation hardware.
[0121] like Fig.11a and Fig.11b As shown in the figure, there are schematic diagrams of the running results of the python code split by the large bit width NTT transformation and the running results of the python code without splitting the large bit width NTT transformation. Fig.11a and Fig.11b It can be seen that the running results of the split python code for the large bit-width NTT transform are the same as the running results of the unsplit python code for the large bit-width NTT transform. Therefore, it can be explained that the hardware acceleration implementation method for number theory transform provided by the present invention can not only realize the large bit-width NTT transform by bit-width splitting, but also can realize larger-scale NTT transform or INTT transform calculation with smaller hardware resources without being limited by the current number theory transform hardware.
[0122] In summary, the hardware acceleration implementation method for number theoretic transformation provided by the present invention splits the multiplication of polynomials with large terms and large bit width into multiple multiplications of polynomials with small terms and small bit width, and splices the results of multiplication of small polynomials into large multiplication results of polynomials through multiple reuse and shift-addition operations of NTT modules or INTT modules, thereby solving the defect that conventional hardware-based NTT modules or INTT modules cannot support NTT transformations with larger bit widths and multiplication of polynomials with larger terms. Therefore, the hardware acceleration implementation method for number theoretic transformation provided by the present invention can make the number of terms and bit widths that can be supported by the hardware of the NTT module or INTT module infinitely expand, and use smaller hardware resources to realize larger-scale NTT transformation or INTT transformation calculations, breaking through its own hardware limitations.
[0123] As another embodiment of the present invention, a hardware acceleration implementation device 10 for number theory transformation is provided, which is used to implement the hardware acceleration implementation method for number theory transformation described above, wherein: Fig.12 As shown, including:
[0124] An acquisition module 11 is used to acquire polynomial data to be calculated, where the number of terms of the polynomial data to be calculated is p, the bit width of the polynomial data to be calculated is q, and both p and q are natural numbers greater than 1;
[0125] A splitting module 12 is used to split the polynomial data to be calculated according to a preset polynomial splitting method to obtain polynomial split data to be calculated, wherein the preset polynomial splitting method includes term number splitting or bit width splitting, the number of terms of the polynomial split data to be calculated is less than or equal to p / 2, and the bit width of the polynomial split data to be calculated is less than or equal to q / 2;
[0126] The calling and calculating module 13 is used to call the number theory transformation hardware calculation unit, and input the polynomial split data to be calculated into the number theory transformation hardware calculation unit, the number theory transformation hardware calculation unit can calculate and process the polynomial split data to be calculated to obtain multiple forward transformation calculation sequences or multiple inverse transformation calculation sequences, wherein the number of polynomial terms supported by the number theory transformation hardware calculation unit is less than p, and the polynomial bit width supported by the number theory transformation hardware calculation unit is less than q;
[0127] The shift calculation module 14 is used to input multiple forward transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial forward transform calculation results, or to input multiple inverse transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial inverse transform calculation results, wherein the number of terms of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is p, and the bit width of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is q.
[0128] The hardware acceleration implementation device for number theoretic transformation provided by the present invention obtains the polynomial split data to be calculated by splitting the polynomial data to be calculated according to the preset polynomial splitting method, and calls the number theoretic transformation hardware calculation unit to calculate the polynomial split data to obtain multiple positive transformation calculation sequences or multiple inverse transformation calculation sequences, and finally inputs the multiple positive transformation calculation sequences or multiple inverse transformation calculation sequences into the splitting algorithm hardware module for shift calculation to obtain the final calculation result. This hardware acceleration implementation device for number theoretic transformation can realize polynomial calculation with large number of terms or large bit width without changing the existing number theoretic transformation hardware calculation unit, so that the number of terms and bit width supported by the number theoretic transformation hardware calculation unit can be infinitely expanded, so as to achieve the purpose of realizing large-scale number theoretic transformation calculation with smaller hardware resources. Therefore, this hardware acceleration implementation device for number theoretic transformation of the present invention can break through the hardware limitation and improve the computing power of hardware number theoretic transformation with large number of terms and large bit width without increasing the hardware overhead.
[0129] The specific working principle and process of the hardware acceleration implementation device for number theoretic transformation of the present invention can be referred to the description of the hardware acceleration implementation method for number theoretic transformation in the previous text, which will not be repeated here.
[0130] As another embodiment of the present invention, a security chip 20 is provided, wherein: Fig.13 As shown, it includes a chip carrier 21 and the hardware acceleration implementation device 10 for number theory transformation described above, which is arranged on the chip carrier 21.
[0131] In the embodiment of the present invention, the chip carrier 21 may specifically include FPGA or ASIC.
[0132] The security chip provided by the present invention, due to the use of the hardware acceleration implementation device for number theoretic transformation mentioned above, can improve the computing power of hardware number theoretic transformation with large number of terms and large bit width without increasing hardware overhead, break through the current hardware limitations, and achieve the purpose of realizing larger-scale number theoretic transformation calculations with smaller hardware resources, thereby having a market competitive advantage.
[0133] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present invention, but the present invention is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. A method for hardware acceleration of number theory transformation, characterized in that: include: Obtaining polynomial data to be calculated, where the number of terms of the polynomial data to be calculated is p, the bit width of the polynomial data to be calculated is q, and both p and q are natural numbers greater than 1; Splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain polynomial split data to be calculated, wherein the preset polynomial splitting method includes term number splitting or bit width splitting, the number of terms of the polynomial split data to be calculated is less than or equal to p / 2, and the bit width of the polynomial split data to be calculated is less than or equal to q / 2; Calling a number theory transformation hardware calculation unit, and inputting the polynomial split data to be calculated into the number theory transformation hardware calculation unit, the number theory transformation hardware calculation unit can perform calculation processing on the polynomial split data to be calculated to obtain multiple forward transformation calculation sequences or multiple inverse transformation calculation sequences, wherein the number of polynomial terms supported by the number theory transformation hardware calculation unit is less than p, and the polynomial bit width supported by the number theory transformation hardware calculation unit is less than q; Multiple forward transform calculation sequences are input into the split algorithm hardware module for shift calculation to obtain polynomial forward transform calculation results, or multiple inverse transform calculation sequences are input into the split algorithm hardware module for shift calculation to obtain polynomial inverse transform calculation results, the number of terms of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is p, and the bit width of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is q.
2. The method for hardware acceleration of number theory transformation according to claim 1, characterized in that: Inputting multiple forward transformation calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial forward transformation calculation results, or inputting multiple inverse transformation calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial inverse transformation calculation results, including: Determine the number of forward transformation calculation sequences, or determine the number of inverse transformation calculation sequences; Shift calculations are performed on multiple forward transform calculation sequences in sequence according to the splitting order, and the results of the shift calculations of each forward transform calculation sequence are added to obtain a polynomial forward transform calculation result; or, shift calculations are performed on multiple inverse transform calculation sequences in sequence according to the splitting order, and the results of the shift calculations of each inverse transform calculation sequence are added to obtain a polynomial inverse transform calculation result.
3. The method for hardware acceleration of number theory transformation according to claim 1 or 2, characterized in that: The splitting algorithm hardware module includes: a counter and a calculation unit, wherein the calculation unit is connected to the counter; The counter is used to determine the number of forward transformation calculation sequences or the number of inverse transformation calculation sequences obtained after the polynomial data to be calculated is split; The calculation unit is used to perform shift calculation and addition calculation on multiple forward transformation calculation sequences to obtain polynomial forward transformation calculation results, or to perform shift calculation and addition calculation on multiple inverse transformation calculation sequences to obtain polynomial inverse transformation calculation results.
4. The method for hardware acceleration of number theory transformation according to claim 3, characterized in that: The splitting algorithm hardware module also includes a combinational logic unit, which is connected to the calculation unit and is used to logically control the calculation process of the calculation unit according to a judgment signal generated during the calculation process of the calculation unit.
5. The method for hardware acceleration of number theory transformation according to claim 1, characterized in that: Splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain the polynomial split data to be calculated, including: The polynomial data to be calculated is evenly split according to the term number splitting method to obtain at least two polynomial split data to be calculated.
6. The method for hardware acceleration of number theory transformation according to claim 1, characterized in that: Splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain the polynomial split data to be calculated, including: According to the bit width splitting method, the polynomial data to be calculated is evenly split in the order of bit width from high to low to obtain at least two polynomial split data to be calculated.
7. The method for hardware acceleration of number theory transformation according to claim 1, characterized in that: The hardware acceleration implementation method for number theory transformation also includes the following steps before inputting the polynomial splitting data to be calculated into the number theory transformation hardware calculation unit: Determine whether the number of polynomial terms supported by the currently called number theory transformation hardware computing unit is greater than or equal to the number of terms of the current polynomial split data to be calculated, or determine whether the polynomial bit width supported by the currently called number theory transformation hardware computing unit is greater than or equal to the bit width of the current polynomial split data to be calculated; If the number of polynomial terms supported by the currently called number theory transformation hardware computing unit is greater than or equal to the number of terms of the current polynomial split data to be calculated, or if the polynomial bit width supported by the currently called number theory transformation hardware computing unit is greater than or equal to the bit width of the current polynomial split data to be calculated, then it is determined that the currently called number theory transformation hardware computing unit is capable of performing calculation processing on the polynomial split data to be calculated; If the number of polynomial terms supported by the currently called number theoretic transformation hardware computing unit is less than the number of terms of the current polynomial split data to be calculated, or if the polynomial bit width supported by the currently called number theoretic transformation hardware computing unit is less than the bit width of the current polynomial split data to be calculated, then the action of splitting the current polynomial split data to be calculated according to the preset polynomial splitting method is repeated until the number of terms of the polynomial split data to be calculated after the split is less than or equal to the number of polynomial terms supported by the currently called number theoretic transformation hardware computing unit, or until the bit width of the polynomial split data to be calculated after the split is less than or equal to the polynomial bit width supported by the currently called number theoretic transformation hardware computing unit.
8. The method for hardware acceleration of number theory transformation according to claim 1, characterized in that: The number theory transformation hardware computing unit includes at least one NTT hardware computing module or at least one INTT hardware computing module, the number of polynomial terms supported by each NTT hardware computing module and each INTT hardware computing module is less than p, and the bit width of the polynomial supported by each NTT hardware computing module and each INTT hardware computing module is less than q; When the number theory transformation hardware calculation unit includes an NTT hardware calculation module or an INTT hardware calculation module, the multiple polynomial split data to be calculated are calculated in sequence by the NTT hardware calculation module or the INTT hardware calculation module; When the number theory transformation hardware computing unit includes multiple NTT hardware computing modules or multiple INTT hardware computing modules, multiple polynomial split data to be calculated can be calculated in parallel by multiple NTT hardware computing modules or multiple INTT hardware computing modules.
9. A hardware acceleration implementation device for number theory transformation, used to implement the hardware acceleration implementation method for number theory transformation according to any one of claims 1 to 8, characterized in that: include: An acquisition module, used for acquiring polynomial data to be calculated, wherein the number of terms of the polynomial data to be calculated is p, the bit width of the polynomial data to be calculated is q, and both p and q are natural numbers greater than 1; A splitting module, used for splitting the polynomial data to be calculated according to a preset polynomial splitting method to obtain polynomial split data to be calculated, wherein the preset polynomial splitting method includes term number splitting or bit width splitting, the number of terms of the polynomial split data to be calculated is less than or equal to p / 2, and the bit width of the polynomial split data to be calculated is less than or equal to q / 2; A calling and calculating module, used for calling a number theory transformation hardware calculating unit, and inputting the polynomial split data to be calculated into the number theory transformation hardware calculating unit, wherein the number theory transformation hardware calculating unit can calculate and process the polynomial split data to be calculated to obtain multiple forward transformation calculation sequences or multiple inverse transformation calculation sequences, wherein the number of polynomial terms supported by the number theory transformation hardware calculating unit is less than p, and the polynomial bit width supported by the number theory transformation hardware calculating unit is less than q; A shift calculation module is used to input multiple forward transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial forward transform calculation results, or to input multiple inverse transform calculation sequences into the split algorithm hardware module for shift calculation to obtain polynomial inverse transform calculation results, wherein the number of terms of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is p, and the bit width of the polynomial forward transform calculation results and the polynomial inverse transform calculation results is q.
10. A security chip, characterized in that: The invention comprises a chip carrier and a hardware acceleration implementation device for number theory transformation as claimed in claim 9 arranged on the chip carrier.
Citation Information
Cited By
Method and device for decomposing data according to bit width
CN119814268A
