Multi-scalar multiplication implementation method and apparatus, terminal, and storage medium
By processing the coefficient matrix of the elliptic curve in columns and combining the NAF algorithm and encoder instructions, the problem of multi-scalar multiplication calculation time is solved, achieving more efficient calculation efficiency and reducing power consumption.
Patent Information
- Application Number
- PCT/CN2023/097565
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2024-12-05
AI Technical Summary
The multi-scalar multiplication calculation of elliptic curves takes a long time, resulting in problems such as many zero-knowledge proof computing resources, long operation time and high power consumption.
By obtaining the coefficient matrix and processing it in columns, it is divided into n/256 coefficient sequences, and using NAF algorithm and encoder instructions to perform addition processing to obtain multi-scalar multiplication results, avoiding the memory switching overhead caused by row processing. And reduces the calculation time.
The calculation time of multi-scalar multiplication is significantly reduced, the calculation efficiency is improved, the power consumption is reduced, and the multi-scalar multiplication calculation process of elliptic curves is optimized.
Smart Images

Figure CN2023097565_05122024_PF_FP_ABST
Abstract
Description
Multi-scalar multiplication implementation method, device, terminal and storage medium Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, terminal, and storage medium for implementing multi-scalar multiplication. Background Art
[0002] As a highly secure encryption technology, zero-knowledge proofs hold broad application prospects in the future of information transmission. Through zero-knowledge proofs, private transaction information can be verified even in encrypted form. Elliptic curve multiplication (MSM) is a core area of zero-knowledge proof computing. However, due to its high computational resources, long computation times, and high power consumption, it has been a key area of research and optimization, both in terms of complexity and difficulty.
[0003] Currently, the calculation of multi-scalar multiplication for elliptic curves mainly involves obtaining the base points and coefficients corresponding to the base points on the elliptic curve, and implementing it by performing point addition and multiplication on the base points and coefficients.
[0004] However, the above implementation method may take a long time. Technical issues
[0005] The main purpose of this application is to provide a multi-scalar multiplication implementation method, device, terminal and storage medium to solve the problem of long time consumption in related technologies. Technical Solutions
[0006] In a first aspect, the present application provides a multi-scalar multiplication implementation method, comprising:
[0007] Get the coefficient matrix, where the coefficient matrix corresponds to the basis point on the elliptic curve;
[0008] The coefficient matrix is processed column by column to obtain a coefficient sequence of n / 256 corresponding to each column coefficient, where n is an integer;
[0009] Based on the n / 256 coefficient sequences corresponding to each column of coefficients, a multi-scalar multiplication result is obtained.
[0010] In some implementations, the coefficient matrix is processed column by column to obtain a coefficient sequence of n / 256 corresponding to each column of coefficients, including:
[0011] Each column of coefficients in the coefficient matrix is divided to obtain n / 256 coefficient sequences corresponding to each column of coefficients.
[0012] In some implementations, the coefficient matrix is a matrix with n rows and m columns, where m is an integer;
[0013] Divide each column of coefficients in the coefficient matrix to obtain n / 256 coefficient sequences corresponding to each column of coefficients, including:
[0014] Divide the n coefficients in each of the m columns by bits to obtain n / 256 groups of coefficients;
[0015] Arrange each group of coefficients in n / 256 groups of coefficients to form a coefficient sequence, and obtain the coefficient sequence corresponding to each group of coefficients;
[0016] The coefficient sequences corresponding to each group of coefficients are summarized to obtain n / 256 coefficient sequences.
[0017] In some implementations, a multi-scalar multiplication result is obtained based on the n / 256 coefficient sequence corresponding to each column of coefficients, including:
[0018] Process each of the n / 256 coefficient sequences using the NAF algorithm in combination with encoder instructions, and output a first output result and a second output result corresponding to each coefficient sequence, wherein the first output result includes a value where each bit in each coefficient sequence is +1, and the second output result includes a value where each bit in each coefficient sequence is -1;
[0019] A multi-scalar multiplication result is obtained based on the first output result and the second output result corresponding to each coefficient sequence.
[0020] In some implementations, processing each of the n / 256 coefficient sequences using a NAF algorithm in combination with encoder instructions, and outputting a first output result and a second output result corresponding to each coefficient sequence, includes:
[0021] receiving each coefficient sequence of n / 256 coefficient sequences;
[0022] The NAF algorithm is called through the encoder instruction to perform addition processing on each coefficient sequence, and the first output result and the second output result corresponding to each coefficient sequence are output.
[0023] In some implementations, calling the NAF algorithm through an encoder instruction to perform addition processing on each coefficient sequence and outputting a first output result and a second output result corresponding to each coefficient sequence includes:
[0024] Perform binary conversion on the coefficients in each coefficient sequence, and perform a sum operation on the previous coefficient and the next coefficient in the converted coefficient sequence to obtain a sum operation value;
[0025] Perform an XOR operation on the sum operation value and the next coefficient to obtain an XOR operation value;
[0026] Perform an AND operation on the XOR operation value and the previous coefficient, and output the first output result;
[0027] Perform an AND operation on the XOR operation value and the next coefficient, and output a second output result.
[0028] In some implementations, obtaining a multi-scalar multiplication result based on the first output result and the second output result corresponding to each coefficient sequence includes:
[0029] Summarize the first output results and the second output results corresponding to each coefficient sequence to obtain all first output results and all second output results corresponding to the coefficient matrix;
[0030] Performing column-wise sum calculations on all first output results to obtain a first sum value corresponding to each column, and performing column-wise sum calculations on all second output results to obtain a second sum value corresponding to each column;
[0031] Calculate the sum of the second sum value corresponding to each column and the second sum value to obtain the total sum value corresponding to each column;
[0032] Get the scalar multiplication result based on the corresponding sum value of each column.
[0033] In some implementations, obtaining a scalar multiplication result based on the corresponding sum value of each column includes:
[0034] Summarize the sum values corresponding to each column to obtain m sum values corresponding to the coefficient matrix;
[0035] Input the m sum values into the preset function to obtain a scalar multiplication result.
[0036] In a second aspect, an embodiment of the present application provides a multi-scalar multiplication implementation device, including:
[0037] An acquisition module, configured to acquire a coefficient matrix, wherein the coefficient matrix corresponds to a base point on the elliptic curve;
[0038] A processing module is used to process the coefficient matrix column by column to obtain n / 256 coefficient sequences corresponding to each column coefficient;
[0039] The calculation module is used to obtain a multi-scalar multiplication result based on the n / 256 coefficient sequences corresponding to each column of coefficients.
[0040] In a third aspect, an embodiment of the present application provides a terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of any of the above multi-scalar multiplication implementation methods are implemented.
[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of any of the above multi-scalar multiplication implementation methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0043] FIG1 is a flowchart of a multi-scalar multiplication implementation method provided in an embodiment of the present application;
[0044] FIG2 is a schematic diagram of a coefficient matrix provided in an embodiment of the present application;
[0045] FIG3 is a schematic diagram of the vnaf256() instruction structure provided in an embodiment of the present application;
[0046] FIG4 is a schematic diagram of an output result after encoding provided by an embodiment of the present application;
[0047] FIG5 is a schematic structural diagram of a multi-scalar multiplication implementation device provided in an embodiment of the present application;
[0048] FIG6 is a schematic diagram of a terminal provided in an embodiment of the present application.
[0049] Implementation Methods of the Application
[0050] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0051] The terms "first," "second," "third," "fourth," and so on (if any) in the specification and claims of this application and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or sequential sequence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of the application described herein can be implemented in orders other than those illustrated or described herein.
[0052] It should be understood that in the various embodiments of the present application, the size of the serial number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0053] It should be understood that in this application, "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products or apparatuses.
[0054] It should be understood that in this application, "multiple" means two or more. "And / or" is merely a description of the association relationship of associated objects, indicating that three relationships can exist. For example, and / or B can represent three situations: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "Contains A, B and C", "Contains A, B, C" means that A, B, and C are all included, "Contains A, B or C" means that one of A, B, and C is included, and "Contains A, B and / or C" means that any one, any two, or any three of A, B, and C are included.
[0055] It should be understood that, in this application, "B corresponding to A," "B corresponding to A," "A corresponds to B," or "B corresponds to A" means that B is associated with A and B can be determined based on A. Determining B based on A does not mean determining B based solely on A; B can also be determined based on A and / or other information. A and B match when the similarity between A and B is greater than or equal to a preset threshold.
[0056] Depending on the context, "if" as used herein may be interpreted as "when" or "when" or "in response to determining" or "in response to detecting."
[0057] The following specific embodiments are used to describe the technical solution of the present application in detail. The following specific embodiments can be combined with each other, and the same or similar concepts or processes will not be described in detail in some embodiments.
[0058] In order to make the purpose, technical solutions and advantages of this application clearer, specific embodiments will be described below with reference to the accompanying drawings.
[0059] Zero-Knowledge Proofs (ZKP), as a highly secure encryption technology, have broad application prospects in the future of information transmission. Elliptic curve multiple scalar multiplication (MSM) is one of the core components of ZKP computing. However, due to the high computing resources involved, long computation time, and high power consumption, it has always been a focus and difficulty in research and optimization.
[0060] At present, the calculation of multi-scalar multiplication for elliptic curves mainly uses the following formula to directly calculate multi-scalar multiplication. Specifically,
[0061] In the ZKP algorithm, the ellipse calculation that needs to be solved by the multi-scalar multiplication MSM can be expressed by formula (1): S = KG (1)
[0062] Where S represents the sum of the MSM calculations, K represents a coefficient (scalar) with a width of M bits and a length of L, and G represents an ellipse base with a length of L.
[0063] The computational problem of elliptic curves is usually composed of point addition (ADD, hereinafter referred to as A) and number multiplication (Double, hereinafter referred to as D). The coefficient k is processed in a row-wise manner, so formula (1) is further expanded into the following formula (2):
[0064] Wherein, k is the same as K in formula (1), which is used to represent the coefficient; g is the same as G in formula (1), which is used to represent the ellipse base point; m is the number of columns of the coefficient matrix; and N is the number of rows of the coefficient matrix.
[0065] Therefore, for a scalar multiplication (SM) calculation, that is, when formula (2) does not have Σ, the time required can be expressed as:
[0066] Among them, A and D represent the time overhead of ADD and Double respectively.
[0067] Based on this, the time required for multi-scalar multiplication MSM can be expressed as:
[0068] That is,
[0069] Since N is much larger than m, the overhead of ADD in formula (5) is very large and the multi-scalar multiplication MSM calculation takes a long time.
[0070] Based on the above problems, this application proposes a multi-scalar multiplication implementation method.
[0071] In one embodiment, as shown in FIG1 , the present application provides a method for implementing multi-scalar multiplication, comprising the following steps:
[0072] Step S101: Obtain a coefficient matrix.
[0073] The coefficient matrix is a matrix composed of segmented coefficients corresponding to base points on the ellipse.
[0074] Combined with Figure 2, suppose there are n base points on the elliptic curve, namely G0, G1, ... G n-1 , where each base point corresponds to a coefficient. Let n base points correspond to n coefficients k0, k1, ...k n-1 That is to say, the base point G0 corresponds to the coefficient k0, the base point G1 corresponds to the coefficient k1, ..., the base point G n-1 Corresponding coefficient k n-1 .
[0075] Each coefficient is segmented according to the preset length to form m coefficients. If the coefficient k0 is divided into equal lengths, k 0,0 ,k 0,1 ,...k 0,m-1 , coefficients k1...k n-1 Also segmented in the above way, forming k 1,0 ,k 1,1 ,...k 1,m-1 ...k n-1,0 ,k n-1,1 ,...k n-1,m-1 , thus forming a coefficient matrix of n rows and m columns.
[0076] Step S102: Process the coefficient matrix column by column to obtain n / 256 coefficient sequences corresponding to each column of coefficients.
[0077] The coefficient matrix is processed column by column to obtain n / 256 coefficient sequences corresponding to the coefficients in each column, mainly by dividing the coefficients in each column of the coefficient matrix to obtain n / 256 coefficient sequences corresponding to the coefficients in each column. Specifically, the n coefficients in each column of the m columns are first divided according to bits to obtain n / 256 groups of coefficients, and then each group of coefficients in the n / 256 groups of coefficients is arranged to form a coefficient sequence to obtain a coefficient sequence corresponding to each group of coefficients, and then the coefficient sequences corresponding to each group of coefficients are aggregated to obtain n / 256 coefficient sequences.
[0078] First, obtain the number of columns m of the coefficient matrix, and then divide the m columns of coefficients into bits in sequence. Specifically, the first column k of the coefficient matrix 0,0 ,k 1,0 ,...k n-1,0For example, all coefficients k in the first column 0,0 ,k 1,0 ,...k n-1,0 If divided according to 256 bits, it can be divided into n / 256 groups of coefficients. If the other columns are divided in the same way, each column of the coefficient matrix can form n / 256 groups of coefficients.
[0079] Each set of coefficients can form a coefficient sequence X, which is expressed as follows: X=(k i,0+j*256 ,k i,1+j*256 ,…,ki,255+j*256)
[0080] Among them, i∈(0, m-1) represents a column in the coefficient matrix; j represents a 256-bit coefficient.
[0081] Step S103: Obtain a multi-scalar multiplication result based on the n / 256 coefficient sequences corresponding to each column of coefficients.
[0082] After obtaining the n / 256 groups of coefficients corresponding to each column of the coefficient matrix, it is necessary to process the n / 256 coefficient sequences corresponding to each column of coefficients to obtain the multi-scalar multiplication result.
[0083] This application mainly uses the NAF algorithm combined with encoder instructions to process each coefficient sequence in n / 256 coefficient sequences and output the first output result and the second output result corresponding to each coefficient sequence. Specifically, each coefficient sequence in n / 256 coefficient sequences is first received, and then the NAF algorithm is called through the encoder instruction to perform addition processing on each coefficient sequence, and the first output result and the second output result corresponding to each coefficient sequence are output. The first output result includes a value where each bit in each coefficient sequence is +1, and the second output result includes a value where each bit in each coefficient sequence is -1.
[0084] For example, each coefficient sequence X is input into the vnaf256() instruction structure shown in FIG3 , and then the encoder instruction is called, which is vnaf256(np, nm, src), where src is a 256-bit input register, and np and nm are 256-bit registers returned. The vnaf256() instruction structure includes a binary converter, an AND operator, an XOR operator, and two AND operators, including a first AND operator and a second AND operator.
[0085] Specifically, the NAF algorithm is called through the encoder instruction to perform addition processing on each coefficient sequence. It is necessary to first perform binary conversion on the coefficients in each coefficient sequence, and perform an AND operation on the previous coefficient and the next coefficient in the converted coefficient sequence to obtain a sum operation value, and then perform an XOR operation on the sum operation value and the next coefficient to obtain an XOR operation value, and then perform an AND operation on the XOR operation value and the previous coefficient respectively to output the first output result, and perform an AND operation on the XOR operation value and the next coefficient to output the second output result.
[0086] Among them, the encoder instruction calls the NAF algorithm to perform addition processing on each coefficient sequence and can be integrated into the processor. The operation flow of the processor executing the encoder instruction is explained in conjunction with the vnaf256() instruction structure shown in Figure 3, as follows:
[0087] The encoder instruction includes the first field, the second field, the third field, the fourth field and the fifth field. The functions of the above fields are:
[0088] The first field is used to specify that the binary converter performs binary conversion on the coefficients in each coefficient sequence; the second field is used to specify that the AND operator performs an AND operation on the previous coefficient and the next coefficient in the converted coefficient sequence to obtain a sum operation value; the third field is used to specify that the XOR operator performs an XOR operation on the sum operation value and the next coefficient to obtain an XOR operation value; the fourth field is used to specify that the first AND operator among the multiple AND operators performs an AND operation on the XOR operation value and the previous coefficient, and outputs a first output result; the fifth field is used to specify that the second AND operator among the multiple AND operators performs an AND operation on the XOR operation value and the next coefficient, and outputs a second output result.
[0089] The first output result and the second output result are the bitmaps of 1 and -1 as shown in FIG4 , wherein the first output result output by the output terminal np and the second output result output by the output terminal nm respectively indicate the +1 and -1 situations of each bit in the N-bit sequence.
[0090] In practice, both the first output result outputted by output terminal np and the second output result outputted by output terminal nm represent 0 and 1, except that for the second output result outputted by output terminal nm, 1 represents the bit being -1. Therefore, the first and second output results can be easily obtained by calling the instruction using a 256-bit coefficient sequence X as shown in Figure 3.
[0091] After obtaining the first output result and the second output result corresponding to each coefficient sequence X in the above manner, the first output result and the second output result corresponding to each coefficient sequence can be calculated to obtain the sum value of each column of the coefficient matrix. Specifically, it is necessary to first summarize the first output result and the second output result corresponding to each coefficient sequence to obtain all the first output results and all the second output results corresponding to the coefficient matrix. Then, all the first output results are summed by column to obtain the first sum value corresponding to each column, and all the second output results are summed by column to obtain the second sum value corresponding to each column. Finally, the first sum value corresponding to each column is summed with the second sum value to obtain the sum value corresponding to each column.
[0092] For example, since the first output result output by the output terminal np and the second output result output by the output terminal nm are both represented by 0 and 1, all 1s in the first output result corresponding to each coefficient sequence can be directly accumulated, and all -1s in the second output result can be accumulated to obtain the first sum value and the second sum value respectively, and then the first sum value and the second sum value are summed to obtain the sum value corresponding to each coefficient sequence, and then the sum values corresponding to all coefficient sequences in this column are summed to obtain the total value of this column.
[0093] After the sum value corresponding to each column is calculated, the sum value corresponding to each column can be summarized to obtain m sum values corresponding to the coefficient matrix, and then the m sum values are input into a preset function to obtain a scalar multiplication result.
[0094] Since the coefficient k is processed in a column manner, the expression of the above formula (2) can be expressed by formula (6), specifically: S = 2(…(2(2(2g′ m-1 +g′ m-2 )+g′ m-3 )+…+g′1)+g′0 (6)
[0095] Among them, g′ i It is expressed as the sum of the i-th column of the coefficient matrix, i∈[0,m-1].
[0096] Therefore, after calculating the sum of each column, the sum of all columns is substituted into formula (6) to obtain the scalar multiplication result S.
[0097] The time required to implement MSM calculation using formula (6) can be expressed as:
[0098] In the current ZKP algorithm, the number N is much larger than m. Therefore, by comparing formulas (5) and (7), it can be seen intuitively that the computational efficiency of formula (6) is much higher than that of formula (1), avoiding the memory exchange overhead caused by processing and storing k row by row.
[0099] Since N is much larger than m, the ADD overhead in formula (7) is still very large. The total time overhead is further reduced by the NAF algorithm introduced above and with the help of encoder instructions.
[0100] Because the number of non-zero values represented by the NAF (Non-Adjacent Form) algorithm is effectively reduced (from 1 / 2 to 1 / 3) compared to the number represented in binary form, the reduction in the number of non-zero values (the coefficients become sparse) will greatly reduce the number of ADDs, so formula (7) can be further expressed as:
[0101] Estimated calculation speed can be improved:
[0102] An embodiment of the present application provides a method for implementing multi-scalar multiplication, including: first obtaining a coefficient matrix, wherein the coefficient matrix corresponds to a base point on an elliptic curve, then processing the coefficient matrix by column to obtain a sequence of n / 256 coefficients corresponding to each column coefficient, and then obtaining a multi-scalar multiplication result based on the sequence of n / 256 coefficients corresponding to each column coefficient. The present application avoids the memory exchange overhead caused by processing and storing by row by processing the coefficients in the coefficient matrix by column. In addition, on this basis, the coefficient sequence is processed by combining the NAF algorithm with instructions, further reducing the time spent on multi-scalar multiplication and improving computational efficiency.
[0103] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0104] The following are device embodiments of the present application. For details not fully described therein, please refer to the corresponding method embodiments described above.
[0105] FIG5 shows a schematic diagram of the structure of a multi-scalar multiplication implementation device provided by an embodiment of the present application. For ease of explanation, only the parts related to the embodiment of the present application are shown. The multi-scalar multiplication implementation device includes an acquisition module 51, a processing module 52, and a calculation module 53. The details are as follows:
[0106] An acquisition module 51 is configured to acquire a coefficient matrix, wherein the coefficient matrix corresponds to a base point on the elliptic curve;
[0107] A processing module 52 is configured to process the coefficient matrix column by column to obtain a coefficient sequence of n / 256 corresponding to each column of coefficients, where n is an integer;
[0108] The calculation module 53 is configured to obtain a multi-scalar multiplication result based on the n / 256 coefficient sequences corresponding to each column of coefficients.
[0109] In some implementations, the processing module 52 is further configured to divide each column of coefficients in the coefficient matrix to obtain n / 256 coefficient sequences corresponding to each column of coefficients.
[0110] In some implementations, the coefficient matrix is a matrix with n rows and m columns, where m is an integer;
[0111] The processing module 52 is further configured to divide the n coefficients in each of the m columns according to bits to obtain n / 256 groups of coefficients;
[0112] Arrange each group of coefficients in n / 256 groups of coefficients to form a coefficient sequence, and obtain the coefficient sequence corresponding to each group of coefficients;
[0113] The coefficient sequences corresponding to each group of coefficients are summarized to obtain n / 256 coefficient sequences.
[0114] In some implementations, the calculation module 53 is further configured to receive each coefficient sequence of the n / 256 coefficient sequences;
[0115] The NAF algorithm is called through the encoder instruction to perform addition processing on each coefficient sequence, and the first output result and the second output result corresponding to each coefficient sequence are output.
[0116] In some implementations, the calculation module 53 is further configured to perform binary conversion on the coefficients in each coefficient sequence, and perform a sum operation on the first coefficient and the second coefficient in the converted coefficient sequence to obtain a sum value;
[0117] Perform an XOR operation on the sum operation value and the next coefficient to obtain an XOR operation value;
[0118] Perform an AND operation on the XOR operation value and the previous coefficient, and output the first output result;
[0119] Perform an AND operation on the XOR operation value and the next coefficient, and output a second output result.
[0120] In some implementations, the calculation module 53 is further configured to aggregate the first output results and the second output results corresponding to each coefficient sequence to obtain all first output results and all second output results corresponding to the coefficient matrix;
[0121] Performing column-wise sum calculations on all first output results to obtain a first sum value corresponding to each column, and performing column-wise sum calculations on all second output results to obtain a second sum value corresponding to each column;
[0122] Calculate the sum of the second sum value corresponding to each column and the second sum value to obtain the total sum value corresponding to each column;
[0123] Get the scalar multiplication result based on the corresponding sum value of each column.
[0124] In some implementations, the calculation module 53 is further configured to aggregate the sum values corresponding to each column to obtain m sum values corresponding to the coefficient matrix;
[0125] Input the m sum values into the preset function to obtain a scalar multiplication result.
[0126] An embodiment of the present application provides a multi-scalar multiplication implementation device, which can be used to: first obtain a coefficient matrix, where the coefficient matrix corresponds to a base point on an elliptic curve, then process the coefficient matrix by column to obtain a sequence of n / 256 coefficients corresponding to each column coefficient, and then obtain a multi-scalar multiplication result based on the sequence of n / 256 coefficients corresponding to each column coefficient. The present application avoids the memory exchange overhead caused by processing and storing by row by processing the coefficients in the coefficient matrix by column. In addition, on this basis, the coefficient sequence is processed by combining the NAF algorithm with instructions, which further reduces the time spent on multi-scalar multiplication and improves computational efficiency.
[0127] FIG6 is a schematic diagram of a terminal provided in an embodiment of the present application. As shown in FIG6 , the terminal 6 of this embodiment includes: a processor 601, a memory 602, and a computer program 603 stored in the memory 602 and executable on the processor 601. When the processor 601 executes the computer program 603, the steps in the aforementioned multi-scalar multiplication implementation method embodiments are implemented, such as steps 101 to 103 shown in FIG1 . Alternatively, when the processor 601 executes the computer program 603, the functions of the modules / units in the aforementioned multi-scalar multiplication implementation device embodiments are implemented, such as the functions of the modules / units 51 to 53 shown in FIG5 .
[0128] The present application further provides a readable storage medium, wherein the readable storage medium stores a computer program. When the computer program is executed by a processor, the computer program is used to implement the multi-scalar multiplication implementation methods provided in the various embodiments described above, including:
[0129] Get the coefficient matrix, where the coefficient matrix corresponds to the basis point on the elliptic curve;
[0130] The coefficient matrix is processed column by column to obtain a coefficient sequence of n / 256 corresponding to each column coefficient, where n is an integer;
[0131] Based on the n / 256 coefficient sequences corresponding to each column of coefficients, a multi-scalar multiplication result is obtained.
[0132] In some implementations, the coefficient matrix is processed column by column to obtain a coefficient sequence of n / 256 corresponding to each column of coefficients, including:
[0133] Each column of coefficients in the coefficient matrix is divided to obtain n / 256 coefficient sequences corresponding to each column of coefficients.
[0134] In some implementations, the coefficient matrix is a matrix with n rows and m columns, where m is an integer;
[0135] Divide each column of coefficients in the coefficient matrix to obtain n / 256 coefficient sequences corresponding to each column of coefficients, including:
[0136] Divide the n coefficients in each of the m columns by bits to obtain n / 256 groups of coefficients;
[0137] Arrange each group of coefficients in n / 256 groups of coefficients to form a coefficient sequence, and obtain the coefficient sequence corresponding to each group of coefficients;
[0138] The coefficient sequences corresponding to each group of coefficients are summarized to obtain n / 256 coefficient sequences.
[0139] In some implementations, a multi-scalar multiplication result is obtained based on the n / 256 coefficient sequence corresponding to each column of coefficients, including:
[0140] Process each of the n / 256 coefficient sequences using the NAF algorithm in combination with encoder instructions, and output a first output result and a second output result corresponding to each coefficient sequence, wherein the first output result includes a value where each bit in each coefficient sequence is +1, and the second output result includes a value where each bit in each coefficient sequence is -1;
[0141] A multi-scalar multiplication result is obtained based on the first output result and the second output result corresponding to each coefficient sequence.
[0142] In some implementations, processing each of the n / 256 coefficient sequences using a NAF algorithm in combination with encoder instructions, and outputting a first output result and a second output result corresponding to each coefficient sequence, includes:
[0143] receiving each coefficient sequence of n / 256 coefficient sequences;
[0144] The NAF algorithm is called through the encoder instruction to perform addition processing on each coefficient sequence, and the first output result and the second output result corresponding to each coefficient sequence are output.
[0145] In some implementations, calling the NAF algorithm through an encoder instruction to perform addition processing on each coefficient sequence and outputting a first output result and a second output result corresponding to each coefficient sequence includes:
[0146] Perform binary conversion on the coefficients in each coefficient sequence, and perform a sum operation on the previous coefficient and the next coefficient in the converted coefficient sequence to obtain a sum operation value;
[0147] Perform an XOR operation on the sum operation value and the next coefficient to obtain an XOR operation value;
[0148] Perform an AND operation on the XOR operation value and the previous coefficient, and output the first output result;
[0149] Perform an AND operation on the XOR operation value and the next coefficient, and output a second output result.
[0150] In some implementations, obtaining a multi-scalar multiplication result based on the first output result and the second output result corresponding to each coefficient sequence includes:
[0151] Summarize the first output results and the second output results corresponding to each coefficient sequence to obtain all first output results and all second output results corresponding to the coefficient matrix;
[0152] Performing column-wise sum calculations on all first output results to obtain a first sum value corresponding to each column, and performing column-wise sum calculations on all second output results to obtain a second sum value corresponding to each column;
[0153] Calculate the sum of the second sum value corresponding to each column and the second sum value to obtain the total sum value corresponding to each column;
[0154] Get the scalar multiplication result based on the corresponding sum value of each column.
[0155] In some implementations, obtaining a scalar multiplication result based on the corresponding sum value of each column includes:
[0156] Summarize the sum values corresponding to each column to obtain m sum values corresponding to the coefficient matrix;
[0157] Input the m sum values into the preset function to obtain a scalar multiplication result.
[0158] Among them, the readable storage medium can be a computer storage medium or a communication medium. Communication media include any medium that facilitates the transmission of computer programs from one place to another. Computer storage media can be any available medium that can be accessed by a general-purpose or special-purpose computer. For example, a readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be an integral part of the processor. The processor and the readable storage medium can be located in an application-specific integrated circuit (ASIC). In addition, the ASIC can be located in a user device. Of course, the processor and the readable storage medium can also exist in a communication device as discrete components. The readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0159] The present application also provides a program product, comprising execution instructions stored in a readable storage medium. At least one processor of a device can read the execution instructions from the readable storage medium, and at least one processor executes the execution instructions to cause the device to implement the multi-scalar multiplication implementation methods provided in the various embodiments described above, including:
[0160] Get the coefficient matrix, where the coefficient matrix corresponds to the basis point on the elliptic curve;
[0161] The coefficient matrix is processed column by column to obtain a coefficient sequence of n / 256 corresponding to each column coefficient, where n is an integer;
[0162] Based on the n / 256 coefficient sequences corresponding to each column of coefficients, a multi-scalar multiplication result is obtained.
[0163] In some implementations, the coefficient matrix is processed column by column to obtain a coefficient sequence of n / 256 corresponding to each column of coefficients, including:
[0164] Each column of coefficients in the coefficient matrix is divided to obtain n / 256 coefficient sequences corresponding to each column of coefficients.
[0165] In some implementations, the coefficient matrix is a matrix with n rows and m columns, where m is an integer;
[0166] Divide each column of coefficients in the coefficient matrix to obtain n / 256 coefficient sequences corresponding to each column of coefficients, including:
[0167] Divide the n coefficients in each of the m columns by bits to obtain n / 256 groups of coefficients;
[0168] Arrange each group of coefficients in n / 256 groups of coefficients to form a coefficient sequence, and obtain the coefficient sequence corresponding to each group of coefficients;
[0169] The coefficient sequences corresponding to each group of coefficients are summarized to obtain n / 256 coefficient sequences.
[0170] In some implementations, a multi-scalar multiplication result is obtained based on the n / 256 coefficient sequence corresponding to each column of coefficients, including:
[0171] Process each of the n / 256 coefficient sequences using the NAF algorithm in combination with encoder instructions, and output a first output result and a second output result corresponding to each coefficient sequence, wherein the first output result includes a value where each bit in each coefficient sequence is +1, and the second output result includes a value where each bit in each coefficient sequence is -1;
[0172] A multi-scalar multiplication result is obtained based on the first output result and the second output result corresponding to each coefficient sequence.
[0173] In some implementations, processing each of the n / 256 coefficient sequences using a NAF algorithm in combination with encoder instructions, and outputting a first output result and a second output result corresponding to each coefficient sequence, includes:
[0174] receiving each coefficient sequence of n / 256 coefficient sequences;
[0175] The NAF algorithm is called through the encoder instruction to perform addition processing on each coefficient sequence, and the first output result and the second output result corresponding to each coefficient sequence are output.
[0176] In some implementations, calling the NAF algorithm through an encoder instruction to perform addition processing on each coefficient sequence and outputting a first output result and a second output result corresponding to each coefficient sequence includes:
[0177] Perform binary conversion on the coefficients in each coefficient sequence, and perform a sum operation on the previous coefficient and the next coefficient in the converted coefficient sequence to obtain a sum operation value;
[0178] Perform an XOR operation on the sum operation value and the next coefficient to obtain an XOR operation value;
[0179] Perform an AND operation on the XOR operation value and the previous coefficient, and output the first output result;
[0180] Perform an AND operation on the XOR operation value and the next coefficient, and output a second output result.
[0181] In some implementations, obtaining a multi-scalar multiplication result based on the first output result and the second output result corresponding to each coefficient sequence includes:
[0182] Summarize the first output results and the second output results corresponding to each coefficient sequence to obtain all first output results and all second output results corresponding to the coefficient matrix;
[0183] Performing column-wise sum calculations on all first output results to obtain a first sum value corresponding to each column, and performing column-wise sum calculations on all second output results to obtain a second sum value corresponding to each column;
[0184] Calculate the sum of the second sum value corresponding to each column and the second sum value to obtain the total sum value corresponding to each column;
[0185] Get the scalar multiplication result based on the corresponding sum value of each column.
[0186] In some implementations, obtaining a scalar multiplication result based on the corresponding sum value of each column includes:
[0187] Summarize the sum values corresponding to each column to obtain m sum values corresponding to the coefficient matrix;
[0188] Input the m sum values into the preset function to obtain a scalar multiplication result.
[0189] In the embodiments of the above-mentioned devices, it should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in this application may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0190] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for implementing multi-scalar multiplication, wherein: include: Obtaining a coefficient matrix, wherein the coefficient matrix corresponds to a base point on an elliptic curve; Processing the coefficient matrix by columns to obtain n / 256 coefficient sequences corresponding to each column of coefficients, where n is an integer; Based on the n / 256 coefficient sequences corresponding to each column of coefficients, a multi-scalar multiplication result is obtained.
2. The method for implementing multi-scalar multiplication as claimed in claim 1, wherein: The coefficient matrix is processed column by column to obtain n / 256 coefficient sequences corresponding to each column coefficient, including: Each column of coefficients in the coefficient matrix is divided to obtain n / 256 coefficient sequences corresponding to each column of coefficients.
3. The method for implementing multi-scalar multiplication as claimed in claim 2, wherein: The coefficient matrix is a matrix with n rows and m columns, where m is an integer; The dividing of each column of coefficients in the coefficient matrix to obtain n / 256 coefficient sequences corresponding to each column of coefficients includes: Divide the n coefficients in each column of m columns by bits to obtain n / 256 groups of coefficients; Arrange each group of coefficients in the n / 256 groups of coefficients to form a coefficient sequence, and obtain a coefficient sequence corresponding to each group of coefficients; The coefficient sequences corresponding to each group of coefficients are aggregated to obtain n / 256 coefficient sequences.
4. The method for implementing multi-scalar multiplication as claimed in claim 1, wherein: The obtaining of a multi-scalar multiplication result based on the n / 256 coefficient sequences corresponding to each column of coefficients includes: Processing each coefficient sequence in the n / 256 coefficient sequences by combining the NAF algorithm with the encoder instruction, and outputting a first output result and a second output result corresponding to each coefficient sequence, wherein the first output result includes a value where each bit in each coefficient sequence is +1, and the second output result includes a value where each bit in each coefficient sequence is -1; A multi-scalar multiplication result is obtained based on the first output result and the second output result corresponding to each coefficient sequence.
5. The method for implementing multi-scalar multiplication as claimed in claim 4, wherein: The method of combining the NAF algorithm with the encoder instruction to process each coefficient sequence in the n / 256 coefficient sequences and outputting a first output result and a second output result corresponding to each coefficient sequence includes: Receiving each coefficient sequence of the n / 256 coefficient sequences; The NAF algorithm is called through the encoder instruction to perform addition processing on each coefficient sequence, and a first output result and a second output result corresponding to each coefficient sequence are output.
6. The method for implementing multi-scalar multiplication as claimed in claim 5, wherein: The calling of the NAF algorithm through the encoder instruction to perform addition processing on each coefficient sequence, and outputting a first output result and a second output result corresponding to each coefficient sequence, comprises: Performing binary conversion on the coefficients in each coefficient sequence, and performing a sum operation on a previous coefficient and a next coefficient in the converted coefficient sequence to obtain a sum operation value; Performing an XOR operation on the sum operation value and the next coefficient to obtain an XOR operation value; Perform an AND operation on the XOR operation value and the previous coefficient, and output a first output result; The XOR operation value is ANDed with the next coefficient to output a second output result.
7. The method for implementing multi-scalar multiplication as claimed in claim 4, wherein: The obtaining of a multi-scalar multiplication result based on the first output result and the second output result corresponding to each coefficient sequence includes: Summarizing the first output results and the second output results corresponding to each coefficient sequence to obtain all the first output results and all the second output results corresponding to the coefficient matrix; Performing a sum calculation on all the first output results by column to obtain a first sum value corresponding to each column, and performing a sum calculation on all the second output results by column to obtain a second sum value corresponding to each column; Calculate the sum of the first sum value and the second sum value corresponding to each column to obtain the total sum value corresponding to each column; The scalar multiplication result is obtained based on the corresponding sum value of each column.
8. The method for implementing multi-scalar multiplication as claimed in claim 7, wherein: The obtaining the scalar multiplication result based on the sum value corresponding to each column includes: Summarize the sum values corresponding to each column to obtain m sum values corresponding to the coefficient matrix; The m sum values are input into a preset function to obtain the scalar multiplication result.
9. A multi-scalar multiplication implementation device, comprising: An acquisition module, used to acquire a coefficient matrix, wherein the coefficient matrix corresponds to a base point on an elliptic curve; A processing module, used for processing the coefficient matrix by column to obtain n / 256 coefficient sequences corresponding to each column coefficient; The calculation module is used to obtain a multi-scalar multiplication result based on the n / 256 coefficient sequences corresponding to each column of coefficients.
10. A terminal, wherein: comprising a memory, and one or more processors communicatively connected to the memory; The memory stores instructions that can be executed by the one or more processors, and the instructions are executed by the one or more processors to enable the one or more processors to implement the multi-scalar multiplication implementation method according to any one of claims 1 to 8.
11. A computer-readable storage medium, wherein: The invention comprises a program or an instruction, and when the program or the instruction is executed on a computer, the method for realizing multi-scalar multiplication according to any one of claims 1 to 8 is realized.
12. A processor, wherein: including a plurality of 256-bit single instruction multiple data registers, a decoder for decoding encoder instructions, and a processing circuit for executing a NAF program based on the encoder instructions; The encoder instructions have: A first field is used to specify a first 256-bit single instruction multiple data register among the multiple 256-bit single instruction multiple data registers, where the first 256-bit single instruction multiple data register is used to store a first operand; A second field is used to specify a second 256-bit single instruction multiple data register among the multiple 256-bit single instruction multiple data registers, where the second 256-bit single instruction multiple data register is used to store a second operand; The third field is used to specify the third 256-bit SIMD register in the plurality of 256-bit SIMD registers. A single instruction multiple data register, wherein the third 256-bit single instruction multiple data register is used to store a third operand; The processing circuit is coupled to the decoder and to the plurality of 256-bit single instruction multiple data registers, the processing circuit is used to execute a NAF program called by the encoder instruction, the NAF program is used to perform the following operations: Perform binary conversion on the coefficients in each coefficient sequence, and perform a sum operation on the previous coefficient and the next coefficient in the converted coefficient sequence through a sum operator to obtain a sum operation value, wherein the next coefficient is obtained by shifting the previous coefficient through a shift register; The XOR operator performs an XOR operation on the sum value and the next coefficient to obtain the XOR value. Performing an AND operation on the XOR operation value and the previous coefficient through a first AND operator to output a first output result, and performing an AND operation on the XOR operation value and the next coefficient through a second AND calculator to output a second output result; The first operand includes at least a coefficient sequence, the second operand includes at least a first output result, and the third operand includes at least a second output result.
Citation Information
Patent Citations
Elliptic curve password quick implementation method and device thereof
CN106888088A
Parallel computing method for large-scale elliptic curve multi-scalar multiplication based on GPU acceleration
CN115481364A
Cited By
Multi-scalar multiplication calculation method and device, computer equipment and program product
CN120104317A
