Technology Sharing

[Cryptology Basics] Fully Homomorphic Encryption Scheme Based on LWE (Learning with Errors)

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Learning Resources:
Fully Homomorphic Encryption I: Theory and Foundations (Professor Yu Yu from Shanghai Jiao Tong University)
Fully Homomorphic Encryption II: Theory and Construction of Fully Homomorphic Encryption (Teacher Xiang Xie)


Now the second-generation (such as BGV and BFV) and third-generation fully homomorphic encryption schemes are all based on LWE. Now advanced fully homomorphic schemes are also based on LWE, so this article summarizes the basic knowledge of LWE.
First, we want to encrypt a number. s s s, now with a series of a i a_i airight s s sEncrypt and get a i s a_is aisIn fact, by solving the greatest common divisor GCD, we can find s s sHowever, if we add a random noise e i e_i ei,get a i s + e i a_is+e_i ais+ei, then it will be difficult to solve s s sThis process is my simple understanding of LWE. The so-called error is a noise.

insert image description here

The calculation process of fully homomorphic encryption is divided into three steps: key generation KeyGen, encryption Enc, homomorphic calculation Eval, and decryption Dec.

KeyGen:

insert image description here
First, construct the above equation, s ⋅ A + e = s A + e scdot A + e = sA+e sA+e=sA+e, and then get the public key pk ( − A -A Aand s A + e sA+e sA+esplicing), and the private key sk ( s s sand 1). So the result of multiplying pk and sk is random noise e (close to 0).

Enc:

The public key pk used for encryption, r is a random vector containing only 0 or 1, and m is the information to be encrypted (placed in the lowest bit of the vector).
insert image description here
insert image description here

Dec:

The private key sk used for decryption is used to calculate the inner product with ct and then mod 2 to get the decrypted result.

insert image description here
Proof of correctness:
insert image description here
Multiplying sk and pk gives 2e (the condition satisfied in KeyGen), and then doing the inner product with r gives a very small even noise. The final result is m + very small even noise, so the noise can be eliminated by mod 2 to get the decrypted result m. ​​This is why the constructed noise is 2e, not e. My understanding is that by constructing even random noise, it is convenient to eliminate the noise by mod 2 during decryption.

Safety Proof:

insert image description here
When pk is pseudo-random and r has high enough entropy (i.e. very random?), pk and pk multiplied by r are both pseudo-random. After adding the vector with m, the encrypted result is also pseudo-random.

insert image description here

The following is a formulaic description by Xiang Xie:
Encryption formula: ciphertext c = public key pk ✖️ random r + plaintext m
Decryption formula: Plaintext m = <ciphertext sk, private key sk> mod q mod 2

insert image description here
On this basis, the value of plaintext m can be decrypted by modulo 2. As long as the noise is small enough, the correctness can be guaranteed.
There is one thing that needs to be distinguished here: P K = ( A , b = A s ′ + 2 e ) PK=(A, b=As'+2e) PK=(A,b=As+2e)is the BGV scheme, while BFV is P K = ( A , b = A s ′ + e ) PK=(A, b=As'+e) PK=(A,b=As+e)The difference is that BGV encodes information in the low bits, while BFV encodes messages in the high bits (this will be explained when learning BFV).

Eval (additive homomorphism and multiplicative homomorphism):

insert image description here
Note that homomorphic addition or multiplication will lead to significant noise accumulation, and multiplication grows quadratically.
Next, let's talk about how to decrypt the result of homomorphic multiplication. From the following formula, we can see that multiplying two ciphertexts is equivalent to first taking the tensor product of the ciphertext and the private key, and then taking the inner product. Therefore, it is obvious that the size of the ciphertext and the private key has doubled. Example is a proof of equivalence.

insert image description here

So the question is, how to restore the size of the ciphertext and the size of the private key after homomorphic multiplication? This is the problem that Key Switching solves.

Here is a description from teacher Xiang Xie:

insert image description here

Key Switching

The goal is to restore the size of the ciphertext and private key to linear size.
insert image description here
Now find the multiplication of ciphertext c1 and c2:

insert image description here
insert image description here

The above process is based on the concept of bit decomposition:

insert image description here

Here is a description from teacher Xiang Xie:

The goal of Key Switching is to transfer the private key s ~ tilde s s~Next c ~ tilde c c~ Convert to private key s s sNext c c c,and c ~ tilde c c~and c c cThey are all the same plaintext encrypted.
A core concept here is Key Switching Key (KSK), which is to use private key s s sTo encrypt s ~ tilde s s~

insert image description here
Through the Key Switching process, the private key can be derived from s ⊗ s sotimes s ssBecomes linear s s s, while the ciphertext from c ~ tilde c c~Becomes linear c c cAnd from the last line of the formula, we can see that after Key Switching ⟨ c , s ⟩ langle c, srangle c,sand the original ⟨ c ~ , s ⊗ s ⟩ langle tilde c, sotimes srangle c~,ssThere is a noise difference between 2 c ~ T e ~ 2tilde c^Ttilde e 2c~Te~, this part can be very large! So here we still can't implement Key Switching.

A Gadget matrix G is introduced here:
insert image description here
Therefore, the Key Switching process becomes as follows:

insert image description here
At this point, the added error is very small.
To sum up, through Key Switching, the original private key s ~ = s ⊗ s tilde s=s otimes s s~=ssNext c ~ = c ⊗ c tilde c=cotimes c c~=cc, converted into a private key s s sNext c c c, note that after Key Switching s , c s, c s,cThey are no longer the original values ​​(double check).

insert image description here
For BGV, the noise of addition increases linearly, and the noise of multiplication increases quadratically. Although Key Switching can support multiplication (limiting sk to become very large), the noise is actually a small noise added to the original multiplication noise, and the overall noise is also very large. Therefore, it is necessary to further reduce this noise.

Modulus Reduction

insert image description here
So far, LWE has been used to implement homomorphic multiplication and addition calculations of very small depth, and key switching uses new keys for each layer. However, as the calculation depth increases, the expansion of noise is explosive, so it is not yet a levelled FHE (FHE that can calculate a specified depth).
Now we hope to implement an FHE that can calculate a certain depth without the help of bootstrapping, which requires the use of modular transformation.
insert image description here

insert image description here

insert image description here

I don't quite understand the process in the middle, but in short, it transforms the ciphertext c from the domain of modulo q to the domain of modulo p (p<
Here is a concrete example:
If Modulus Reduction is not performed, the noise will increase in a double exponential trend as the depth increases, and decryption errors will occur after level >= 3.
insert image description here
If Modulus Reduction is performed on each level, the noise will be maintained within an absolute value range, but the cost is that the modulus will continue to decrease.

insert image description here

So to achieve a levelled FHE, you can set a modulus B d B^d Bd, then we can calculate a depth of d d dThe circuit (where B B Bis the noise upper bound of the refreshed ciphertext). d d dAfter the depth, the modulus should be reduced to B B B, to ensure that decryption does not go wrong at this time. BGV is a levelled FHE.

insert image description here