A fast matrix multiplication method in Paillier ciphertext space
By performing low-precision encoding of plaintext matrix in Paillier ciphertext space and ciphertext matrix modulo inverse value cache, and using a parallel computing framework for matrix multiplication, the problem of large overhead of matrix multiplication in ciphertext space is solved, and computing efficiency and security are improved.
Patent Information
- Application Number
- CN202311346034.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-18
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2043-10-18
AI Technical Summary
In the Paillier ciphertext space, the computational overhead of matrix multiplication operation is relatively large, especially when the number of elements of ciphertext matrix and plaintext matrix is large, it becomes a computing efficiency bottleneck of the privacy protection protocol.
By encoding the plaintext matrix with preset accuracy, the calculation amount is reduced, and the modulus inverse value of the ciphertext element in the ciphertext matrix is cached to avoid repeated calculations. The parallel computing framework is used to perform matrix vector multiplication and element-by-element multiplication, and the results are summarized using the quick summation method in Paillier's ciphertext space.
It effectively reduces the time overhead of matrix multiplication operations in Paillier's ciphertext space, improves calculation performance and efficiency, and ensures the accuracy and security of calculation results.
Smart Images

Figure CN117312743B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of data security and cryptography, and in particular to a fast matrix multiplication method in a Paillier ciphertext space, an electronic device and a storage medium. Background Art
[0002] In the field of privacy computing, the Paillier homomorphic encryption algorithm is a widely used cryptographic method with strict security proofs. The algorithm is used in many privacy-preserving machine learning algorithms and protocols, such as federated learning, privacy set intersection, and anonymous query.
[0003] In algorithms and protocols designed based on Paillier homomorphic encryption, matrix multiplication in ciphertext space is a basic cryptographic operator, which is widely used in algorithm protocols such as vertical linear regression, vertical logistic regression, and vertical neural network. For example, in the vertical logistic regression algorithm, when calculating the gradient in the ciphertext space, it is necessary to perform matrix multiplication using local plaintext training data and the received ciphertext residual vector.
[0004] However, due to the high computational overhead of addition and multiplication operations in the Paillier ciphertext space, when the number of elements in the ciphertext matrix and the plaintext matrix is large, the computational overhead of the matrix multiplication operation in the ciphertext space will become very large, becoming the computational efficiency bottleneck of the entire protocol, thereby affecting the effective implementation and widespread application of the privacy protection protocol. Summary of the invention
[0005] In view of the above problems, the present invention provides a fast matrix multiplication method in a Paillier ciphertext space, an electronic device and a storage medium, in order to solve at least one of the above problems.
[0006] According to a first aspect of the present invention, a fast matrix multiplication method in a Paillier ciphertext space is provided, which is applied to the fields of financial big data, medical big data, cloud computing and federated learning, including:
[0007] Encode the plaintext elements in the plaintext matrix with a preset precision to obtain a preprocessed plaintext matrix, calculate the modular inverse values of the ciphertext elements in the ciphertext matrix, and cache the modular inverse values of the ciphertext elements in a storage device;
[0008] Using the modular inverse value of the ciphertext elements cached in the storage device, the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained A set of column vectors, where is a positive integer greater than or equal to 1, and each column vector set includes multiple column vectors;
[0009] Using the fast summation method in Paillier ciphertext space Each column vector set in the column vector set is summed along the vertical axis, and we get row vectors, and The row vectors are concatenated along the vertical axis to obtain the matrix multiplication result.
[0010] According to an embodiment of the present invention, the encoding of the plaintext elements in the plaintext matrix with a preset precision includes encoding the plaintext elements into a data form with a user-specified precision according to a floating-point number encoding standard specified by a user;
[0011] The data format with user-specified precision is as shown in formula (1):
[0012] (1),
[0013] in, Indicates the plaintext matrix Line The plain text elements of the column, Representation and The corresponding mantissa part, is the base, The index part.
[0014] According to an embodiment of the present invention, the above-mentioned calculating the modular inverse value of the ciphertext element in the ciphertext matrix and caching the modular inverse value of the ciphertext element in the storage device includes:
[0015] Calculate the modular inverse value of the ciphertext element according to a preset modular inverse value calculation formula and a preset Paillier public key, and avoid repeated calculation of the modular inverse value in the Paillier ciphertext space by pre-caching the modular inverse value of the ciphertext element in the storage device;
[0016] The preset modular inverse value calculation formula is shown in formula (2):
[0017] (2),
[0018] in, Represents the first Line The ciphertext elements of the column, Representation and The corresponding modular inverse value is, Represents the preset Paillier public key.
[0019] According to an embodiment of the present invention, the modular inverse value of the ciphertext element cached in the storage device is used to convert the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained The set of column vectors includes:
[0020] In the memory device, construct a matrix with the same dimensions as the plaintext matrix A cache matrix;
[0021] Using the modular inverse value of the ciphertext element cached in the storage device, a row vector in the ciphertext matrix is subjected to matrix-vector multiplication with the preprocessed plaintext matrix to obtain a column vector set;
[0022] Parallelize and repeat the matrix-vector multiplication on all row vectors in the ciphertext matrix to obtain A set of column vectors;
[0023] Will The collection of column vectors is stored in cache matrices, each of which stores a set of column vectors.
[0024] According to an embodiment of the present invention, the modular inverse value of the ciphertext element cached in the storage device is used to perform matrix-vector multiplication on a row vector in the ciphertext matrix and the preprocessed plaintext matrix to obtain a column vector set including:
[0025] Integrate the positive numbers in the plaintext row vectors involved in the calculation into a positive vector, and integrate the negative numbers in the plaintext row vectors involved in the calculation into a negative vector;
[0026] Performing an element-by-element calculation operation on the ciphertext element and the positive vector to obtain a forward calculation result, and performing an element-by-element calculation operation on the negative vector using the modular inverse value of the ciphertext element to obtain a negative calculation result;
[0027] According to the subscript information of the ciphertext element and the subscript information of the plaintext row vector, the forward calculation result and the negative calculation result are assigned to the cache matrix respectively.
[0028] According to a second aspect of the present invention, a fast matrix multiplication system in a Paillier ciphertext space is provided, which is applied to the fields of financial big data, medical big data, cloud computing and federated learning, and includes:
[0029] A preprocessing module is used to encode the plaintext elements in the plaintext matrix with a preset precision to obtain a preprocessed plaintext matrix, calculate the modular inverse values of the ciphertext elements in the ciphertext matrix, and cache the modular inverse values of the ciphertext elements in a storage device;
[0030] The matrix-vector multiplication module is used to use the modular inverse value of the ciphertext elements cached in the storage device to multiply the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained A set of column vectors, where is a positive integer greater than or equal to 1, and each column vector set includes multiple column vectors;
[0031] Vector summarization module, used to use the fast summation method in Paillier ciphertext space to Each column vector set in the column vector set is summed along the vertical axis, and we get row vectors, and The row vectors are concatenated along the vertical axis to obtain the matrix multiplication result.
[0032] According to a third aspect of the present invention, there is provided an electronic device, comprising:
[0033] one or more processors;
[0034] a storage device for storing one or more programs,
[0035] When one or more programs are executed by one or more processors, the one or more processors execute a fast matrix multiplication method in a Paillier ciphertext space.
[0036] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute a fast matrix multiplication method in a Paillier ciphertext space.
[0037] The fast matrix multiplication method in the Paillier ciphertext space provided by the present invention is intended to reduce the time overhead of matrix multiplication operations in the ciphertext space. Unlike the traditional matrix multiplication based on the Paillier homomorphic encryption algorithm, the present invention first pre-processes the data, encodes the plaintext matrix with low precision to reduce the amount of calculation, and caches the modular inverse value of the ciphertext in the ciphertext matrix to avoid repeated calculations; a parallelized computing framework is used to simultaneously calculate the matrix-vector multiplication between multiple groups of ciphertext vectors and plaintext matrices. In each group of matrix-vector multiplication, a parallelized framework is also used to simultaneously calculate the element-by-element multiplication between the ciphertext and the plaintext vector; all results are summarized to obtain the result of the matrix multiplication operation in the entire ciphertext space. The above method provided by the present invention can minimize repeated modular inverse operations and make full use of the CPU multi-core computing power, thereby improving the performance and efficiency of matrix multiplication operations in the Paillier ciphertext space. At the same time, since the method is based on the Paillier homomorphic encryption algorithm, the accuracy and security of the calculation results can be guaranteed. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1is a flow chart of a fast matrix multiplication method in a Paillier ciphertext space according to an embodiment of the present invention;
[0039] Figure 2 is a schematic diagram comparing computer time overheads of different fast matrix multiplications based on Paillier ciphertext space according to an embodiment of the present invention;
[0040] Figure 3 is a schematic diagram of the structure of a fast matrix multiplication system in a Paillier ciphertext space according to an embodiment of the present invention;
[0041] Figure 4 A block diagram of an electronic device suitable for implementing a fast matrix multiplication method in a Paillier ciphertext space according to an embodiment of the present invention is schematically shown. DETAILED DESCRIPTION
[0042] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings.
[0043] It should be particularly pointed out that in the technical solution disclosed in the present invention, the acquisition of the plaintext data and ciphertext data involved has been authorized by the relevant parties, and the above data is processed, applied and stored with the permission of the relevant parties. The relevant process complies with the provisions of laws and regulations, and necessary and reliable confidentiality measures are taken to meet the requirements of public order and good morals.
[0044] The above method provided by the present invention can be applied to many fields such as finance, government affairs, and medical care. For example, in the financial loan assessment scenario, banks or financial institutions have depositors' personal deposits, loan history, consumption records and other data. In order to improve the lending accuracy of loan business, they often encrypt their private data through the Paillier homomorphic algorithm first, and then jointly calculate the matrix multiplication operation in the ciphertext space with other Internet companies to obtain the lending risk probability of each depositor. In addition, in the medical cancer diagnosis scenario, public tertiary hospitals and private medical institutions have a certain amount of customer privacy data, such as medical history, genetic history, medical insurance amount, etc., but the data cannot be shared with each other, so private medical institutions will use the Paillier homomorphic algorithm to encrypt the private data held by the institution, and then perform matrix multiplication operations on the ciphertext space with the data of public tertiary hospitals to obtain the probability of each customer suffering from cancer.
[0045] In order to solve various technical problems in the prior art, the present invention provides a fast matrix multiplication method in Paillier ciphertext space to accelerate the fast ciphertext space matrix multiplication operation based on the Paillier homomorphic encryption algorithm.
[0046] In order to improve the computational efficiency of matrix multiplication operations in the Paillier ciphertext space while ensuring a certain accuracy of floating-point calculation results, the following optimization strategy is adopted.
[0047] First, the data is preprocessed and each element in the plaintext matrix is encoded with low precision to reduce the amount of calculation. Secondly, the modular inverse value of each ciphertext in the ciphertext matrix is calculated and cached to avoid repeated calculations. Then, the idea of parallel computing is adopted to perform matrix-vector multiplication on each row vector in the ciphertext matrix and the plaintext matrix at the same time. In the calculation of matrix-vector multiplication, the parallelization idea is also adopted to calculate the element-by-element multiplication of each ciphertext in the ciphertext row vector with the plaintext vector. Finally, the fast summation method on the Paillier ciphertext set is used to sum the column vectors to obtain the results of each group of matrix-vector multiplication, and these results are spliced together to obtain the final calculation result. These optimization strategies are used to reduce the computational overhead of matrix multiplication operations in the Paillier ciphertext space, thereby improving the performance of the privacy computing system.
[0048] Figure 1 4 is a flowchart of a fast matrix multiplication method in a Paillier ciphertext space according to an embodiment of the present invention.
[0049] like Figure 1 As shown, the above-mentioned fast matrix multiplication method in the Paillier ciphertext space is applied to the fields of financial big data, medical big data, cloud computing and federated learning, including operations S110 to S130.
[0050] In operation S110, plaintext elements in the plaintext matrix are encoded with a preset precision to obtain a preprocessed plaintext matrix, and modular inverse values of ciphertext elements in the ciphertext matrix are calculated, and the modular inverse values of the ciphertext elements are cached in a storage device.
[0051] The encoding with preset precision may adopt, for example, the IEEE754 floating point encoding standard.
[0052] According to an embodiment of the present invention, the encoding of the plaintext elements in the plaintext matrix with a preset precision includes encoding the plaintext elements into a data form with a user-specified precision according to a floating-point number encoding standard specified by a user;
[0053] The data format with user-specified precision is as shown in formula (1):
[0054] (1),
[0055] in, Indicates the plaintext matrix Line The plain text elements of the column, Representation and The corresponding mantissa part, is the base, The index part.
[0056] According to an embodiment of the present invention, the above-mentioned calculating the modular inverse value of the ciphertext element in the ciphertext matrix and caching the modular inverse value of the ciphertext element in the storage device includes:
[0057] Calculate the modular inverse value of the ciphertext element according to a preset modular inverse value calculation formula and a preset Paillier public key, and avoid repeated calculation of the modular inverse value in the Paillier ciphertext space by pre-caching the modular inverse value of the ciphertext element in the storage device;
[0058] The preset modular inverse value calculation formula is shown in formula (2):
[0059] (2),
[0060] in, Represents the first Line The ciphertext elements of the column, Representation and The corresponding modular inverse value is, Represents the preset Paillier public key.
[0061] The data preprocessing stage of the above method of the present invention is to respectively perform low-precision encoding on the plaintext matrix and the ciphertext matrix and calculate the modular inverse value, that is, before performing the matrix multiplication operation in the ciphertext space, the ciphertext matrix and the plaintext matrix need to be preprocessed.
[0062] In the plaintext matrix low-precision encoding sub-stage, each element in the plaintext matrix , according to the IEEE 754 floating point encoding standard, it is encoded as form, in which is the mantissa of the floating point number. is the base, The exponent term. After low-precision encoding of floating-point numbers, the mantissa is smaller. According to the multiplication property of Paillier ciphertext, the mantissa will be used as the exponent term of modular exponentiation in subsequent multiplication operations with ciphertext. Therefore, a smaller mantissa can effectively reduce the computational overhead of ciphertext multiplication operations.
[0063] In the sub-phase of calculating the modular inverse of the ciphertext matrix and caching the calculation results, for each element in the ciphertext matrix , calculate its modular inverse and cache to satisfy ,in is the Paillier public key. In this way, for each ciphertext, when performing ciphertext space multiplication operations with multiple different negative plaintexts, it can effectively avoid repeated calculations of the modular inverse value, thereby improving the calculation efficiency.
[0064] In operation S120, the modular inverse value of the ciphertext element cached in the storage device is used to convert the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained A set of column vectors, where is a positive integer greater than or equal to 1, and each column vector set includes multiple column vectors.
[0065] According to an embodiment of the present invention, the modular inverse value of the ciphertext element cached in the storage device is used to convert the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained The set of column vectors includes: in the memory device, construct a matrix with the same dimensions as the plaintext matrix cache matrix; using the modular inverse value of the ciphertext element cached in the storage device, perform matrix-vector multiplication on a row vector in the ciphertext matrix and the preprocessed plaintext matrix to obtain a column vector set; parallelize and repeat the matrix-vector multiplication on all row vectors in the ciphertext matrix to obtain A set of column vectors; The collection of column vectors is stored in cache matrices, each of which stores a set of column vectors.
[0066] According to an embodiment of the present invention, the above-mentioned use of the modular inverse value of the ciphertext element cached in the storage device to perform matrix-vector multiplication on a row vector in the ciphertext matrix and the preprocessed plaintext matrix to obtain a column vector set includes: integrating the positive numbers in the plaintext row vectors participating in the calculation into a positive vector, and integrating the negative numbers in the plaintext row vectors participating in the calculation into a negative vector; using the ciphertext element and the positive vector to perform an element-by-element calculation operation to obtain a forward calculation result, and using the modular inverse value of the ciphertext element and the negative vector to perform an element-by-element calculation operation to obtain a negative calculation result; according to the subscript information of the ciphertext element and the subscript information of the plaintext row vector, the forward calculation result and the negative calculation result are respectively assigned to the cache matrix.
[0067] In operation S130, a fast summation method in the Paillier ciphertext space is used to Each column vector set in the column vector set is summed along the vertical axis, and we get row vectors, and The row vectors are concatenated along the vertical axis to obtain the matrix multiplication result.
[0068] The above operations S120 to S130 belong to the parallel matrix multiplication stage of the above method of the present invention. After completing the data preprocessing of the plaintext matrix and the ciphertext matrix involved in operation S110, a parallel computing framework is used to complete the multiplication operation of the processed ciphertext matrix.
[0069] The parallelized matrix multiplication stage includes two sub-stages, namely, the parallelized calculation of ciphertext vector and plaintext matrix multiplication sub-stage and the aggregation of intermediate results to generate the final output sub-stage.
[0070] Parallelize the calculation of the ciphertext vector and plaintext matrix multiplication sub-stage, for each row vector of the ciphertext matrix , parallelize the calculation of the ciphertext vector and the plaintext matrix Multiplication First create a cache matrix of the same size as the plaintext matrix , whose dimensions are also , then decompose the ciphertext vector and plaintext matrix multiplication process into the following two sub-processes:
[0071] (1) Parallelize the element-by-element multiplication between a single ciphertext and a plaintext row vector: Each ciphertext , parallelize the calculation of the corresponding plaintext row vector The element-by-element multiplication between the two is performed, and the calculated ciphertext row vector is stored in the cache matrix OK, that is In the calculation When further disassembling and grouping, Integrate the positive numbers in into the vector In Integrate the negative numbers in the vector Then, we simultaneously calculate and Element-wise multiplication of two groups, where When you need to use , which is used to speed up the calculation process. Finally, the calculation results on the two groups are assigned back according to the corresponding relationship between the element subscripts. middle.
[0072] (2) Sum each column vector of the cache matrix: After parallelizing the element-by-element multiplication between each ciphertext and plaintext row vector, we get The ciphertext matrix Then, along the vertical axis, we use the fast summation method on the Paillier ciphertext set to sum each column vector, and finally get the dimension The result vector .
[0073] Aggregate the intermediate results to generate the final output sub-stage. In the above parallelized calculation of the ciphertext vector and plaintext matrix multiplication sub-stage, each ciphertext row vector is multiplied with the plaintext matrix to obtain a dimension of The ciphertext row vector ,Will The row vectors are spliced along the vertical axis to get the final result matrix , the calculation process is completed.
[0074] The fast matrix multiplication method in the Paillier ciphertext space provided by the present invention is intended to reduce the time overhead of matrix multiplication operations in the ciphertext space. Unlike the traditional matrix multiplication based on the Paillier homomorphic encryption algorithm, the present invention first pre-processes the data, encodes the plaintext matrix with low precision to reduce the amount of calculation, and caches the modular inverse value of the ciphertext in the ciphertext matrix to avoid repeated calculations; a parallelized computing framework is used to simultaneously calculate the matrix-vector multiplication between multiple groups of ciphertext vectors and plaintext matrices. In each group of matrix-vector multiplication, a parallelized framework is also used to simultaneously calculate the element-by-element multiplication between the ciphertext and the plaintext vector; all results are summarized to obtain the result of the matrix multiplication operation in the entire ciphertext space. The above method provided by the present invention can minimize repeated modular inverse operations and make full use of the CPU multi-core computing power, thereby improving the performance and efficiency of matrix multiplication operations in the Paillier ciphertext space. At the same time, since the method is based on the Paillier homomorphic encryption algorithm, the accuracy and security of the calculation results can be guaranteed.
[0075] In summary, the fast matrix multiplication method in the ciphertext space proposed by the present invention is optimized in data preprocessing and parallel computing, effectively reducing the computational overhead and improving the efficiency and performance of the algorithm protocol. The method is applicable to a variety of privacy protection fields, such as federated learning, privacy set intersection and anonymous query. The above method provided by the present invention is simple to implement, easy to deploy, and can protect data privacy and security, and has broad application prospects.
[0076] In order to further illustrate the effectiveness and advantages of the above method provided by the present invention, the above method provided by the present invention is verified by an experiment below.
[0077] Figure 2 It is a schematic diagram comparing computer time overheads of different fast matrix multiplications based on Paillier ciphertext space according to an embodiment of the present invention.
[0078] The test environment of the present invention is MacOS Ventura 13.3.1 operating system, 1.4GHz quad-core Intel Core i5 CPU, and 8G memory. Figure 2The computational time overhead of the two methods is compared under four different matrix sizes, namely 32x32, 64x64, 128x128, and 256x256, with the plaintext matrix and the ciphertext matrix of the same size. In each case, the random seed is first fixed to 0, and the plaintext matrix is randomly generated using the Numpy package. Then, the open source python-paillier homomorphic encryption library is used to encrypt the plaintext matrix to obtain a ciphertext matrix of the same size. The floating point encoding precision is fixed to 0.001.
[0079] Figure 2 The horizontal axis represents the running time of the multiplication of the ciphertext matrix and the plaintext matrix, which is the average of three running times in seconds; in the vertical axis, "cipher_matmul" represents the traditional ciphertext matrix multiplication, which is calculated by calling the matmul() function of the Numpy package, and "fast_cipher_matmul" represents the fast matrix multiplication method in the Paillier ciphertext space proposed in the present invention.
[0080] Table 1 Comparison of running time of cipher_matmul and fast_cipher_matmul
[0081]
[0082] The experimental results show that the operation time of the fast matrix multiplication method in Paillier cipher space on matrices of four different sizes is significantly faster than that of the traditional cipher matrix multiplication method, as shown in Table 1. Specifically, from the speed-up ratio in Table 1 (i.e., cipher_matmul / fast_cipher_matmul), the running time is increased by 10.1 times, 11.3 times, 11.6 times, and 11.0 times, respectively, which fully verifies the effectiveness of this method.
[0083] Figure 3 4 is a schematic diagram of the structure of a fast matrix multiplication system in a Paillier ciphertext space according to an embodiment of the present invention.
[0084] like Figure 3 As shown, the fast matrix multiplication system 300 in the Paillier ciphertext space is applied to the fields of financial big data, medical big data, cloud computing and federated learning, and includes a preprocessing module 310, a matrix-vector multiplication module 320 and a vector aggregation module 330.
[0085] A preprocessing module 310 is used to encode the plaintext elements in the plaintext matrix with a preset precision to obtain a preprocessed plaintext matrix, calculate the modular inverse values of the ciphertext elements in the ciphertext matrix, and cache the modular inverse values of the ciphertext elements in a storage device;
[0086] The matrix-vector multiplication module 320 is used to use the modular inverse value of the ciphertext element cached in the storage device to multiply the ciphertext matrix by Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained A set of column vectors, where is a positive integer greater than or equal to 1, and each column vector set includes multiple column vectors;
[0087] Vector summarization module 330, used to use the fast summation method in Paillier ciphertext space to Each column vector set in the column vector set is summed along the vertical axis, and we get row vectors, and The row vectors are concatenated along the vertical axis to obtain the matrix multiplication result.
[0088] The fast matrix multiplication method in the Paillier ciphertext space provided by the present invention is further described in detail below in conjunction with specific embodiments.
[0089] In a specific embodiment of the present invention, the random seed of the Numpy package is fixed to 0, and the random module thereof is used to randomly generate a scale of The plaintext matrix , then use the python-paillier open source library to create a 1024-bit key pair, where the public key is , the private key is . Using the public key Pair Matrix Encrypt each element in to get the ciphertext matrix Then calculate according to the following process .
[0090] The fast matrix multiplication method in the Paillier ciphertext space provided by the present invention includes two stages, namely a data preprocessing stage and a parallelized matrix multiplication stage.
[0091] In the data preprocessing stage, first, the plaintext matrix is encoded with low precision: the floating point encoding precision is fixed to 0.001, and the plaintext matrix is encoded with the help of the encode() function in the python-paillier package. Encode each element in the low-precision format and assign the encoded result back to middle.
[0092] Secondly, calculate the modular inverse of the ciphertext matrix and cache the calculation results: With the help of the invert() function in the gmpy2 open source library, calculate the ciphertext matrix The modular inverse value of each element in is ,in Public key The final modular inverse matrix is , and cache the calculation results.
[0093] In the parallel matrix multiplication phase, first, parallelize the calculation of the ciphertext vector and the plaintext matrix multiplication: for each row vector of the ciphertext matrix , parallelize the calculation of the ciphertext vector Same plaintext matrix Multiplication First, create a cache matrix of the same size as the plaintext matrix , whose dimensions are also , and then calculate the following two sub-processes: (1) Parallelize the element-by-element multiplication between a single ciphertext and a plaintext row vector: Each ciphertext , parallelize the calculation of the corresponding plaintext row vector Element-wise multiplication between , and let In the calculation When, yes Further disassembly and grouping will Integrate positive numbers into vectors In Integrate the negative numbers in the vector In the meantime, calculate and Element-wise multiplication of two groups. When you need to use , which is used to speed up the calculation process. Finally, the calculation results on the two groups are assigned back according to the corresponding relationship between the element subscripts. (2) Sum each column vector of the cache matrix: After parallelizing the element-by-element multiplication between each ciphertext and plaintext row vector, we get The ciphertext matrix Then, along the vertical axis, we use the fast summation method on the Paillier ciphertext set to sum each column vector, and finally get the dimension The result vector .
[0094] Secondly, the intermediate results are aggregated to produce the final output: each ciphertext row vector in the above steps Same plaintext matrix After calculating the multiplication, the dimensions are The ciphertext row vector , then concatenate the 16 row vectors along the vertical axis to get the final result matrix , the calculation is completed.
[0095] Figure 4A block diagram of an electronic device suitable for implementing a fast matrix multiplication method in a Paillier ciphertext space according to an embodiment of the present invention is schematically shown.
[0096] like Figure 4 As shown, the electronic device 400 according to an embodiment of the present invention includes a processor 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 408 to a random access memory (RAM) 403. The processor 401 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 401 may also include an onboard memory for caching purposes. The processor 401 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.
[0097] In RAM 403, various programs and data required for the operation of electronic device 400 are stored. Processor 401, ROM 402 and RAM 403 are connected to each other via bus 404. Processor 401 performs various operations of the method flow according to the embodiment of the present invention by executing the programs in ROM 402 and / or RAM 403. It should be noted that the program can also be stored in one or more memories other than ROM 402 and RAM 903. Processor 401 can also perform various operations of the method flow according to the embodiment of the present invention by executing the programs stored in one or more memories.
[0098] According to an embodiment of the present invention, the electronic device 400 may further include an input / output (I / O) interface 405, which is also connected to the bus 404. The electronic device 400 may further include one or more of the following components connected to the I / O interface 405: an input portion 406 including a keyboard, a mouse, etc.; an output portion 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 408 including a hard disk, etc.; and a communication portion 409 including a network interface card such as a LAN card, a modem, etc. The communication portion 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage portion 408 as needed.
[0099] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiment; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present invention is implemented.
[0100] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, it may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 402 and / or RAM 403 described above and / or one or more memories other than ROM 402 and RAM 403.
[0101] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0102] The above specific embodiments further illustrate the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A fast matrix multiplication method in Paillier ciphertext space, applied to the fields of financial big data, medical big data, cloud computing and federated learning, characterized in that: include: Encoding the plaintext elements in the plaintext matrix with a preset precision to obtain a preprocessed plaintext matrix, and calculating the modular inverse values of the ciphertext elements in the ciphertext matrix, and caching the modular inverse values of the ciphertext elements in a storage device; Using the modular inverse value of the ciphertext element cached in the storage device, Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained A set of column vectors, where is a positive integer greater than or equal to 1, and each of the column vector sets includes a plurality of column vectors; The fast summation method in the Paillier ciphertext space is used to Each column vector set in the column vector set is summed along the vertical axis, and we get row vectors, and for the The row vectors are spliced along the vertical axis to obtain the matrix multiplication result; Wherein, the modular inverse value of the ciphertext element cached in the storage device is used to convert the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained The set of column vectors includes: In the memory device, construct a matrix with the same dimensions as the plaintext matrix A cache matrix; Using the modular inverse value of the ciphertext element cached in the storage device, perform matrix-vector multiplication on a row vector in the ciphertext matrix and the preprocessed plaintext matrix to obtain a column vector set; Parallelize and repeat the matrix-vector multiplication on all row vectors in the ciphertext matrix to obtain A set of column vectors; Will The collection of column vectors is stored in cache matrices, wherein each of the cache matrices stores a set of column vectors; Among them, using the modular inverse value of the ciphertext element cached in the storage device, a row vector in the ciphertext matrix is subjected to matrix-vector multiplication with the preprocessed plaintext matrix to obtain a column vector set including: Integrate the positive numbers in the plaintext row vectors involved in the calculation into a positive vector, and integrate the negative numbers in the plaintext row vectors involved in the calculation into a negative vector; Performing an element-by-element calculation operation on the ciphertext element and the positive vector to obtain a forward calculation result, and performing an element-by-element calculation operation on the modulo inverse value of the ciphertext element and the negative vector to obtain a negative calculation result; According to the subscript information of the ciphertext element and the subscript information of the plaintext row vector, the forward calculation result and the negative calculation result are respectively assigned to the cache matrix.
2. The method according to claim 1, characterized in that Encoding the plaintext elements in the plaintext matrix with a preset precision includes encoding the plaintext elements into a data form with a user-specified precision according to a floating-point number encoding standard specified by a user; The data format with user-specified precision is as shown in formula (1): (1), in, Indicates the plaintext matrix Line The plain text elements of the column, Representation and The corresponding mantissa part, Base, The index part.
3. The method according to claim 1, characterized in that Calculating the modular inverse value of the ciphertext element in the ciphertext matrix and caching the modular inverse value of the ciphertext element in the storage device includes: Calculating the modular inverse value of the ciphertext element according to a preset modular inverse value calculation formula and a preset Paillier public key, and avoiding repeated calculation of the modular inverse value in the Paillier ciphertext space by pre-caching the modular inverse value of the ciphertext element in the storage device; The preset modular inverse value calculation formula is shown in formula (2): (2), in, Represents the first Line The ciphertext elements of the column, Representation and The corresponding modular inverse value is, Represents the preset Paillier public key.
4. A fast matrix multiplication system in Paillier ciphertext space, applied in the fields of financial big data, medical big data, cloud computing and federated learning, characterized in that: include: A preprocessing module, used to encode the plaintext elements in the plaintext matrix with a preset precision to obtain a preprocessed plaintext matrix, and calculate the modular inverse values of the ciphertext elements in the ciphertext matrix, and cache the modular inverse values of the ciphertext elements in a storage device; The matrix-vector multiplication module is used to use the modular inverse value of the ciphertext element cached in the storage device to multiply the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained A set of column vectors, where is a positive integer greater than or equal to 1, and each of the column vector sets includes a plurality of column vectors; A vector summarization module is used to use the fast summation method in the Paillier ciphertext space to Each column vector set in the column vector set is summed along the vertical axis, and we get row vectors, and The row vectors are spliced along the vertical axis to obtain the matrix multiplication result; Wherein, the modular inverse value of the ciphertext element cached in the storage device is used to convert the ciphertext matrix Parallel matrix-vector multiplication of row vectors with the preprocessed plaintext matrix is obtained The set of column vectors includes: In the memory device, construct a matrix with the same dimensions as the plaintext matrix A cache matrix; Using the modular inverse value of the ciphertext element cached in the storage device, perform matrix-vector multiplication on a row vector in the ciphertext matrix and the preprocessed plaintext matrix to obtain a column vector set; Parallelize and repeat the matrix-vector multiplication on all row vectors in the ciphertext matrix to obtain A set of column vectors; Will The collection of column vectors is stored in cache matrices, wherein each of the cache matrices stores a set of column vectors; Among them, using the modular inverse value of the ciphertext element cached in the storage device, a row vector in the ciphertext matrix is subjected to matrix-vector multiplication with the preprocessed plaintext matrix to obtain a column vector set including: Integrate the positive numbers in the plaintext row vectors involved in the calculation into a positive vector, and integrate the negative numbers in the plaintext row vectors involved in the calculation into a negative vector; Performing an element-by-element calculation operation on the ciphertext element and the positive vector to obtain a forward calculation result, and performing an element-by-element calculation operation on the modulo inverse value of the ciphertext element and the negative vector to obtain a negative calculation result; According to the subscript information of the ciphertext element and the subscript information of the plaintext row vector, the forward calculation result and the negative calculation result are respectively assigned to the cache matrix.
5. An electronic device comprising: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors execute the method according to any one of claims 1 to 3.
6. A computer-readable storage medium having executable instructions stored thereon, wherein when the instructions are executed by a processor, the processor executes the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Paillier decryption system, chip and method
CN112988237A
Paillier homomorphic encryption processor and processing method thereof
CN116049907A