[0031] Example 1:
[0032] refer to figure 1 As shown, the present invention discloses a method of calculating a cipher core-based covariance matrix method based on row.
[0033] Set data matrix x∈R n×d , Contain N samples, each sample has D-Dimensional features, X i,j Represents the JR feature in the i-th sample.
[0034] in,
[0035] The covariance is generally used to draw the similarities between two random variables. The covariance matrix is calculated, and it is a similar relationship between each column of the data matrix X as a variable, the covariance matrix is used to portray the similar relationship between the variables of each column and other variables. Also, (σ X ) ij (Σ) x ) ji The meaning of expression is the same, and the value is also equal.
[0036] That is, the covariance matrix σ X It is a symmetrical matrix, its calculation process is as follows:
[0037] Where, μ represents the mean vector of the data matrix X, order μ = [μ 0 μ 1 , ..., μ d-1 ], X = [x 0 , X 1 , ..., x d ], Where X i Represents column vector of data matrix, μ i Data vector x i Corresponding mean,
[0038] Stateless encryption is a cryptographic primitive that supports an arithmetic operation of encrypted data, allowing the completion of the same-state addition and the same multiplication operation in the absence of data, and is considered to prevent A potential solution for privacy leaks.
[0039] Preferably, the ciphertext covariance matrix calculation method is encrypted, decrypted and analogy based on the CKKS pending algorithm based on the CKKS formation.
[0040] Among them, the CKKS peak encryption algorithm mainly includes the following algorithms:
[0041] (1) HE.Keygen (params): Key generation algorithm, where params are determined by security parameters λ and hierarchical parameter L. Output public key PK, private key SK, calculate the key EVK.
[0042] (2) HE.enc pk (m): Encryption algorithm, encrypt the plaintext M using the public key to output ciphertext C.
[0043] (3) HE.DEC sk (c): Decryptive algorithm, encrypt the ciphertext C using the public key to output a plaintext m.
[0044] (4) HE.ADD evk (c 1 , C 2 : State addition operation, C 1 And C 2 Is M 1 And M 2 Correspondence, output C add Is M 1 + M 2 The corresponding ciphertext.
[0045] (5) He.mul evk (c 1 , C 2 : Normal multiplication operation, C 1 And C 2 Is M 1 And M 2 Correspondence, output C mul Is M 1 × M 2 The corresponding ciphertext.
[0046] (6) HE.ROTATE_VECTOR (C, i), moving I bits in the ciphertext C., when I ≥ 0 means moving to the left, when i <0 is moved to the right.
[0047] In addition, the CKKS scheme supports the layout polynomial P that packages a numerical vector V encoding a ring, which is called encoding, that is, P = Encode (V), the inverse transformation process is the decoding process, that is, V = decode (P) .
[0048] Specifically, the ciphertext covariance matrix calculation method of the present invention includes the steps:
[0049] Step S1: Line package encoding step, package the data matrix X to encode into a clear text vector PTXT, PTXT [i] = Encode (x i ), Where X i A line vector representing the row in the matrix X.
[0050] specifically, - Package code - →
[0051] In the general data collection, the number of data samples is generally smaller than the number of nslots of the expressions. Therefore, all features of each sample data can be packaged into a plaintext of all features (ie, each row data) of each sample data can be encoded in accordance with the original data line. Each eigenval value corresponds to a plaintest slot in a clear text.
[0052] Step S2: Ming Text Normal Encryption Steps, for each of the plain text PTXT in the clear text vector i Encryption, get ciphertext vector CTXT, CTXT i = HE.enc pk (PTXT i ).
[0053] specifically, - Encryption - →
[0054] Step S3: Calculate the tabular mean step in the denoministic field. Calculate the tidist mean of ciphertext data in one-time batch C mean The specific steps are as follows: 1. Directly coding using the CKKS formation encryption program Encoded into clear text N plain ,Right now 2. Pipe the ciphertext in each of the ciphertext vector CTXT to obtain ciphertext and C sum; 3. Calculate the tester C mean = HE.mul (c sum N plain ).
[0055] Step S4: Using the tabular mean C mean Calculate the ciphertext covariance matrix vector C calculated in the denominations covar.
[0056] Preferably, the step S4 includes: X T X calculation, obtain a ciphertext vector C 1 , Then carry out Calculate, C 1 Each element is multiplied in n plain ,Right now At the same time, complete the ciphertext field calculation μ T μ, get the ciphertext vector C 2.
[0057] And, calculated in the denominations Get ciphertext covariance matrix vector C covar Let He.mul (C 1 [i], n plain ) = C 1 [i], get C covar [i] = HE.SUB (c 1 [i], c 2 [i]).
[0058] Ciphethological domain calculates a covariance matrix, and finally gets a D-Dimetic Ciphethical Negative Paraction Vector, and the i-th covarian difference Channel C. covar [i] The corresponding ciphertext is the element on the first diagonal line of the plain text, distributed in cizewent C covar [I] The front D-I of the previous D-I.
[0059] Preferably, the ciphertext field is calculated to obtain a ciphertext covariance matrix vector C covar The specific algorithm can be as follows 1 below.
[0060] Table 1 Ciphertext Code Base Method Based on Row Coding
[0061]
[0062]
[0063] Since the data is encoded in accordance with the line, the covariance is used as a characteristic variable, and when calculating the covariance matrix in the ciphertext, the data ciphertice needs to be changed accordingly, and the co-calculation covariance is calculated.
[0064] So, under the plain text, X T The calculation process of x is as follows:
[0065]
[0066] In the ciphertext domain, the ciphertext is packaged encoded according to the line of data matrix, so the multiple ciphertext calculations X T The result of x corresponds to the plain text X T X diagonal elements, by performing the secrets, you can sequentially get X T The value of all the elements of the X matrix, corresponds to figure 2 As shown, the specific calculation step is:
[0067] (1) Ciphethological domain calculates X T X master diagonal elements, namely:
[0068] CTXT 0 · CTX 0 + CTXT 1 · CTXT 1 + ... + CTXT n-1 · CTXT n-1 ,
[0069] The ciphertext obtained by this step contains all the elements on the primary diagonal, distributed on the corresponding plaintext before D effective plain text slots;
[0070] (2) Cipher domain calculation x T X The upper right second diagonal element, namely:
[0071] CTXT 0 · (CTXT 0 Left shift 1 slot) + CTXT 1 · (CTXT 1 Left shift 1 slot) + ... + CTXT n-1 · (CTXT n-1 Left shift 1 slot), the ciphertext obtained by this step contains all the elements on the second diagonal, distributed in the corresponding express text D-1 effective plaintext slot;
[0072] (3) Calculate other diagonal elements in turn;
[0073] (4) Cipher domain calculate X T X upper right corner elements, namely: CTXT 0 · (CTXT 0 Left shift D-1 slot) + CTXT 1 · (CTXT 1 Left shift D-1 slot) + ... + CTXT n-1 · (CTXT n-1 Left shift D-1 slot)
[0074] The ciphertext obtained in this step contains the upper right corner element, distributed on the first bright tank of the corresponding plaintext.
[0075] Under the plain text, μ T The calculation process of μ is as follows:
[0076]
[0077] Similarly, in the ciphertext domain, a plurality of ciphertext calculations T The result of μ corresponds to the plain text μ T The diagonal element of μ, can be obtained in turn T The value of all the elements of the μ matrix, corresponds to image 3 Indicated.
[0078] Specific calculation steps:
[0079] (1) Ciphest domain calculate μ T μ main diagonal elements, namely: c mean · C mean. The ciphertext obtained by this step contains all the elements on the primary diagonal, distributed on the corresponding plaintext before D effective plain text slots;
[0080] (2) Calvisor calculation μ T μ on the upper right second diagonal element, namely: c mean · (C mean Left shift 1 slot), the ciphertext obtained by this step contains all the elements on the second diagonal, distributed in the corresponding express text D-1 effective plaintext slot;
[0081] (3) Calculate other diagonal elements in turn;
[0082] (4) Ciphest domain calculate μ T μ above the upper right corner element, namely: c mean · (Cmean Left shift D-1 slot). The ciphertext obtained in this step contains the upper right corner element, distributed on the first bright tank of the corresponding plaintext.
[0083] Step S5: Ciphethological covariance matrix vector decryption step.
[0084] Preferably, in step S5: ciphertext covarian matrix vector decryption step specifically includes: decrypting the obtained covarian matrix vector of the plain text vector P covar Where P covar [i] = HE.DEC sk (c covar [i]).
[0085] S6: Ming Text Vector Decoding Steps and gives a plain text covariance matrix. That is, it is a calculation result of the covariance matrix.
[0086] Preferably, the step S6 specifically includes: a plain text covariance matrix vector P covar Decoding gets a covariance to the corner vector Covar [i], where Covar [i] = decode (P covar [i]); At the same time, the covariance difference value corresponding to the corner line vector Covar [I] is arranged in accordance with the corresponding position, and finally obtains a plain text covariance matrix.
[0087] Specifically, the elements on the first diagonal of the other diagonal difference matrices are distributed in the clear text vector of the covarian matrix. covar Ionic P covar [I] The front D-I of the previous D-I. Therefore, there is a need for each plaintext polynomial element P covar [i] decoding, obtain the value of the covarian matrix, ie Covar [I] = decode (P covar [i]). COVAR [i] represents a covariance matrix II diagonal vector, contains D-I effective values.
[0088] Finally, the positional arrangement of the covariance difference value corresponding to the corner difference to the angle vector Covar [I] is finally obtained by the platen a clearly text covariance matrix.
[0089] Advantages of a cipher text-based covariance matrix calculation method based on row-coded coding include:
[0090] (1) Support for the ciphertext correction matrix calculation of high latitude data, and calculating the time floating, no significant increase as the dimension increases;
[0091] (2) Use efficient packing bank encoding for data to batch calculations on the coordination difference between the data different dimensions in the ciphertext field, and finally constitute a ciphertext covariance matrix;
[0092] (3) The complexity of the denoministic domain calculation is higher. The multiplication depth of the process of the present invention is only 1, and the secret text is shifted, the ciphertext product, the cipher texture, and the data dimension are only linear.
[0093] The present invention proposed a row-based coded ciphertext covariance matrix calculation method that guarantees privacy security of raw data during the entire calculation process, and maliodol cannot easily obtain malicious operations. The calculation method of the present invention can be applied to a statistical and machine learning model that requires a covariance matrix calculation, providing safety protection during operation.