PET-bootcamp-lecture 05 - FHE
PET-bootcamp-lecture 05 - FHE
LECTURE 5:
(DISTRIBUTED) HOMOMORPHIC ENCRYPTION
PET BOOTCAMP – COURSE TIMELINE
We are here
Lectures Holiday!
1 2 3 4 5 6 7 8 9 10
Assignments
CTF
Exam
PET BOOTCAMP – LECTURE OVERVIEW
Intro & overview,
Anonymization & Secure multi-party Secure multi-party
PET applications, and
pseudomization tech computation (SMPC) computation (SMPC)
privacy-enhanced
Differential privacy [session 1] [session 2]
communication
Dr. Maarten Everts Dr. Jasper Goseling Prof.dr.ir. Thijs Veugen Prof.dr.ir. Thijs Veugen
Dr. Florian Hahn Dr. Florian Hahn Dr. Maarten Everts Dr. Maarten Everts Prof.dr.ir. Thijs Veugen
QUESTIONS ABOUT
THE PREVIOUS
LECTURE?
ANY FEEDBACK
ALREADY ABOUT THE
COURSE?
PARTIALLY & FULLY
HOMOMORPHIC ENCRYPTION
IN THE MULTIPARTY SETTING
CONTENTS
• 𝐺𝑒𝑛 1𝜆 : Generate and output public key 𝑝𝑘 and secret key 𝑠𝑘.
• 𝐸𝑛𝑐(𝑝𝑘, 𝑚): Encrypt message 𝑚 using public key 𝑝𝑘 and output ciphertext 𝑐 = [𝑚]
• 𝐷𝑒𝑐(𝑠𝑘, 𝑐): Decrypt ciphertext 𝑐 = 𝑚 using secret key 𝑠𝑘 and output plaintext 𝑚
52 + 46 + 31 = [129]
Alice
52 46
[52] [46] Bob
[31]
Carol
31
PALLIER CRYPTOSYSTEM
𝐺𝑒𝑛 1𝜅 Carmichael Theorem:
• Like for RSA, pick two 𝜅-bit primes 𝑝, 𝑞 and let n = 𝑝 ⋅ 𝑞
For any element w ∈ ℤ∗𝑛2 it holds that
• Set 𝜆 = 𝑙𝑐𝑚 𝑝 − 1, 𝑞 − 1 𝑤 𝜆 ≡ 1 𝑚𝑜𝑑 𝑛
𝑤 𝑛 𝜆 ≡ 1 𝑚𝑜𝑑 𝑛2
• Set 𝑔 = 1 + 𝑛
• Output 𝑝𝑘 = 𝑛, 𝑔 and 𝑠𝑘 = 𝜆
PALLIER CRYPTOSYSTEM
𝐺𝑒𝑛 1𝜅 𝑔 has order 𝑛 mod 𝑛2 ; it generates a subgroup of order 𝑛 in ℤ∗𝑛2
• Like for RSA, pick two 𝜅-bit primes 𝑝, 𝑞 and let n = 𝑝 ⋅ 𝑞
• 1 + 𝑛 = 1 + 𝑛 𝑚𝑜𝑑 𝑛2
• Set 𝜆 = 𝑙𝑐𝑚 𝑝 − 1, 𝑞 − 1 • 1 + 𝑛 2 = 1 + 2n + n2 ≡ 1 + 2𝑛 𝑚𝑜𝑑 𝑛2
• 1 + 𝑛 3 = 1 + 3𝑛 + 3𝑛2 + 𝑛3 ≡ 1 + 3𝑛 𝑚𝑜𝑑 𝑛2
• Set 𝑔 = 1 + 𝑛 • …
• 1 + 𝑛 𝑖 ≡ 1 + 𝑖𝑛 𝑚𝑜𝑑 𝑛2
• Output 𝑝𝑘 = 𝑛, 𝑔 and 𝑠𝑘 = 𝜆 • …
• Finally, 1 + 𝑛 𝑛 ≡ 1 + 𝑛 𝑛 𝑚𝑜𝑑 𝑛2 ≡ 1 𝑚𝑜𝑑 𝑛2
PALLIER CRYPTOSYSTEM
𝐺𝑒𝑛 1𝜅 The random sampled 𝑟 makes the scheme probabilistic
• Like for RSA, pick two 𝜅-bit primes 𝑝, 𝑞 and let n = 𝑝 ⋅ 𝑞 • IND-CPA secure
• Set 𝜆 = 𝑙𝑐𝑚 𝑝 − 1, 𝑞 − 1
• Set 𝑔 = 1 + 𝑛
• Output 𝑝𝑘 = (𝑛, 𝑔) and 𝑠𝑘 = 𝜆 What about IND-CCA security?
𝐸𝑛𝑐 𝑝𝑘, 𝑚
• On input of message 𝑚 ∈ ℤ𝑛
• Select random 𝑟 ∈ ℤ𝑛
• Output 𝑚 = 𝑐 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝑚𝑜𝑑 𝑛2
PALLIER CRYPTOSYSTEM
𝐺𝑒𝑛 1𝜅 𝑐 𝜆 𝑚𝑜𝑑 𝑛2 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝜆 = 𝑔𝑚𝜆 𝑟 𝑛𝜆 𝑚𝑜𝑑 𝑛2
• Like for RSA, pick two 𝜅-bit primes 𝑝, 𝑞 and let n = 𝑝 ⋅ 𝑞 • 𝑟 𝑛𝜆 𝑚𝑜𝑑 𝑛2 ≡ 1 𝑚𝑜𝑑 𝑛2
• Set 𝜆 = 𝑙𝑐𝑚 𝑝 − 1, 𝑞 − 1 • 1 + 𝑛 𝑚𝜆 ≡ 1 + 𝑛𝑚𝜆 𝑚𝑜𝑑 𝑛2
• Set 𝑔 = 1 + 𝑛
• Output 𝑝𝑘 = (𝑛, 𝑔) and 𝑠𝑘 = 𝜆
𝑔𝜆 = 1 + 𝑛 𝜆 ≡ 1 + 𝑛𝜆 𝑚𝑜𝑑 𝑛2
𝐸𝑛𝑐 𝑝𝑘, 𝑚
• On input of message 𝑚 ∈ ℤ𝑛
• Select random 𝑟 ∈ ℤ𝑛
• Output 𝑚 = 𝑐 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝑚𝑜𝑑 𝑛2 𝐿 𝑐 𝜆 𝑚𝑜𝑑 𝑛2 𝑛𝑚𝜆
𝜆 2
= =𝑚
𝐿(𝑔 𝑚𝑜𝑑 𝑛 ) 𝑛𝜆
𝐷𝑒𝑐 𝑠𝑘, 𝑐
• On input of ciphertext 𝑐 = 𝑚 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝑚𝑜𝑑 𝑛2 ∈ ℤ𝑛2
𝐿 𝑐 𝜆 𝑚𝑜𝑑 𝑛2 𝑥−1
• Decrypt as 𝑚 = 𝑚𝑜𝑑 𝑛 where 𝐿 𝑥 =
𝐿(𝑔𝜆 𝑚𝑜𝑑 𝑛2 ) 𝑛
PALLIER CRYPTOSYSTEM
Addition of two ciphertexts
𝐺𝑒𝑛 1𝜅 • 𝑐1 = 𝑔𝑚1 ⋅ 𝑟1𝑛
• Like for RSA, pick two 𝜅-bit primes 𝑝, 𝑞 and let n = 𝑝 ⋅ 𝑞
• Set 𝜆 = 𝑙𝑐𝑚 𝑝 − 1, 𝑞 − 1 • 𝑐2 = 𝑔𝑚2 ⋅ 𝑟2𝑛
• Set 𝑔 = 1 + 𝑛
• Output 𝑝𝑘 = (𝑛, 𝑔) and 𝑠𝑘 = 𝜆
• 𝑐1 ⋅ 𝑐2 = 𝑔𝑚1 +𝑚2 ⋅ 𝑟1 ⋅ 𝑟2 𝑛
𝐸𝑛𝑐 𝑝𝑘, 𝑚
• On input of message 𝑚 ∈ ℤ𝑛
• Select random 𝑟 ∈ ℤ𝑛
• Output 𝑚 = 𝑐 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝑚𝑜𝑑 𝑛2 We can always re-randomize by “adding zero”:
• 𝑐 ′ = 𝑐 + 0 = 𝑔𝑚 ⋅ 𝑟1𝑛 ⋅ 𝑟2𝑛 = 𝑔𝑚 ⋅ 𝑟1 ⋅ 𝑟2 𝑛
𝐷𝑒𝑐 𝑠𝑘, 𝑐
• On input of ciphertext 𝑐 = 𝑚 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝑚𝑜𝑑 𝑛2 ∈ ℤ𝑛2
𝐿 𝑐 𝜆 𝑚𝑜𝑑 𝑛2 𝑥−1
• Decrypt as 𝑚 = 𝑚𝑜𝑑 𝑛 where 𝐿 𝑥 =
𝐿(𝑔𝜆 𝑚𝑜𝑑 𝑛2 ) 𝑛
𝐸𝑛𝑐 𝑝𝑘, 𝑚
• On input of message 𝑚 ∈ ℤ𝑛
• Select random 𝑟 ∈ ℤ𝑛
• Output 𝑚 = 𝑐 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝑚𝑜𝑑 𝑛2
𝐷𝑒𝑐 𝑠𝑘, 𝑐
• On input of ciphertext 𝑐 = 𝑚 = 𝑔𝑚 ⋅ 𝑟 𝑛 𝑚𝑜𝑑 𝑛2 ∈ ℤ𝑛2
𝐿 𝑐 𝜆 𝑚𝑜𝑑 𝑛2 𝑥−1
• Decrypt as 𝑚 = 𝑚𝑜𝑑 𝑛 where 𝐿 𝑥 =
𝐿(𝑔𝜆 𝑚𝑜𝑑 𝑛2 ) 𝑛
• Assume shares:
• 𝑥1 + 𝑥2 = 𝑥
• 𝑦1 + 𝑦2 = 𝑦
Alice Bob
• 𝑥 ∗ 𝑦 = 𝑥1 𝑦1 + 𝑥1𝑦2 + 𝑥2 𝑦1 + 𝑥2𝑦2 =
𝑥1 , 𝑦1 𝑥1 𝑦2 𝑦1 𝑥2 [−𝑟]
= 𝑧1 + 𝑧2 = 𝑧
for random 𝑥1, 𝑦1 for random 𝑟, x2 , y2
𝐷𝑒𝑐( 𝑥1 𝑦2 𝑦1 𝑥2 [−𝑟])
= 𝑥1 𝑦2 + 𝑦1 𝑥2 − 𝑟
𝑧1 = 𝑥1 𝑦1 + 𝑥1𝑦2 + 𝑥2 𝑦1 − 𝑟 𝑧2 = 𝑥2𝑦2 + 𝑟
COMPUTING THE AVERAGE AGE – WITHOUT CENTRAL PARTY
[52]
Issues with this construction?
52 46
Alice Bob
[129] 52 ⊕ 46 =
52 + 46 = [98]
Carol
31
98 ⊕ 31
= [129]
COMPUTING THE AVERAGE AGE – WITHOUT CENTRAL PARTY
[52]
98 ⊕ 31
129 129 129
= [129]
Carol
OUTLOOK: FULLY HOMOMORPHIC ENCRYPTION
• 𝐺𝑒𝑛 1𝜆 : Generate and output public key 𝑝𝑘 and secret key 𝑠𝑘.
• 𝐸𝑛𝑐(𝑝𝑘, 𝑚): Encrypt message 𝑚 using public key 𝑝𝑘 and output ciphertext 𝑐 = [𝑚]
• 𝐷𝑒𝑐(𝑠𝑘, 𝑐): Decrypt ciphertext 𝑐 = [𝑚] using secret key 𝑠𝑘 and output plaintext 𝑚
We will use quotient ring 𝑅𝑞 = ℤ𝑞 𝑋 /(𝑋 𝑛 + 1) We can think about ℤ𝑞 in different ways:
• Polynomials with degree 𝑛 − 1 0, 1, … , 𝑞 − 2, 𝑞 − 1
• Each coefficient modulo 𝑞
but also
𝑞−1 𝑞−1
− , … , −1, 0, 1, … ,
2 2
Similarly, we use quotient ring 𝑅3 = ℤ3 𝑋 /(𝑋 𝑛 + 1)
• Polynomials with degree 𝑛 − 1
• Each coefficient value from {−1, 0, 1}
PRELIMINARIES FOR FULLY HOMOMORPHIC ENCRYPTION
We draw from an error distribution 𝜒, such that polynomial Gauss parameters mean and standard deviation depend on crypto
𝑒 ← 𝜒 has coefficients drawn from a discrete Gaussian instantiations.
distribution
DECISIONAL RING LEARNING WITH ERRORS (INFORMAL)
We will use quotient ring 𝑅𝑞 = ℤ𝑞 𝑋 /(𝑋 𝑛 + 1)
Given a uniformly random 𝑎 ← 𝑅𝑞 , a secret • Polynomials with degree 𝑛 − 1
• Each coefficient modulo 𝑞
𝑠 ← 𝑅3 and an error term 𝑒 ← 𝜒, it is
computationally hard for an adversary who does
not know 𝑠 and 𝑒 to distinguish between: Similarly, we use quotient ring 𝑅3 = ℤ3 𝑋 /(𝑋 𝑛 + 1)
• Polynomials with degree 𝑛 − 1
(𝑎𝑠 + 𝑒, 𝑎) • Each coefficient value from {−1, 0, 1}
and
(𝑏, 𝑎) We can draw from an error distribution 𝜒, such that polynomial
for another uniformly random 𝑏 ← 𝑅𝑞 . 𝑒 ← 𝜒 has coefficients drawn from a discrete Gaussian
distribution
BFV: HOMOMORPHIC ENCRYPTION
We will use quotient ring 𝑅𝑞 = ℤ𝑞 𝑋 /(𝑋 𝑛 + 1)
KeyGen: • Polynomials with degree 𝑛 − 1
• Each coefficient modulo 𝑞
• Sample 𝑠 ← 𝑅3
• Sample 𝑎 ← 𝑅𝑞
Similarly, we use quotient ring 𝑅3 = ℤ3 𝑋 /(𝑋 𝑛 + 1)
• Polynomials with degree 𝑛 − 1
• Sample 𝑒 ← 𝜒
• Each coefficient value from {−1, 0, 1}
• Output 𝑠𝑘 = 𝑠
We can draw from an error distribution 𝜒, such that polynomial
• Output 𝑝𝑘 = 𝑝𝑘0 , 𝑝𝑘1 = − 𝑎𝑠 + 𝑒 , 𝑎 𝑒 ← 𝜒 has coefficients drawn from a discrete Gaussian
distribution
BFV: HOMOMORPHIC ENCRYPTION
𝑞
Scaling factor W =
𝑝
• Transform 𝑀 from 𝑅𝑝 into 𝑅𝑞 (coefficients from ℤ𝑝 to ℤ𝑞 )
KeyGen:
• Sample 𝑠 ← 𝑅3 Similar to ElGamal, 𝑢 is a unique random mask to make encryption
• Sample 𝑎 ← 𝑅𝑞 probabilistic
• Sample 𝑒 ← 𝜒
• Output 𝑠𝑘 = 𝑠 Error terms 𝑒1 , 𝑒2 hide the information (as in the RLWE
• Output 𝑝𝑘 = 𝑝𝑘0 , 𝑝𝑘1 = − 𝑎𝑠 + 𝑒 , 𝑎
assumption)
Encrypt(pk, M):
• Message 𝑀 is element in 𝑅𝑝 with p < 𝑞
• Sample two error polynomials 𝑒1 , 𝑒2 ← χ
• Sample small polynomial 𝑢 ← 𝑅3
𝑞
• Set W = 𝑝
• Calculate c0 = 𝑊𝑀 + 𝑝𝑘0 𝑢 + 𝑒1
• Calculate c1 = 𝑝𝑘1 𝑢 + 𝑒2
• Output 𝑐 = 𝑐0 , 𝑐1
BFV: HOMOMORPHIC ENCRYPTION
Decryption from inner to outer steps:
Dec(sk, c): p
Remove noise by rounding to next integer ⋅
• Compute q
𝑐0 + 𝑐1 𝑠 𝑚𝑜𝑑 𝑞 mod p
Polynomial-ception!
𝑝 𝑞 𝑝
• 𝑞 𝑝
𝑀 + 𝑞 𝜀Ƹ
Polynomial-ception!
Polynomial-ception!
BFV-Enc
[𝑎]
Alice [𝑦] Alice
𝑦 = [𝑓(𝑎, 𝑏, 𝑐)]
MPC [𝑏] MPC
BFV-KeyGen BFV-Enc BFV-Eval
[𝑦] BFV-Decrypt
Bob Bob
[𝑐]
[𝑦]
BFV-Enc
𝑦
Carol Carol
MHE – KEY SWITCHING
Carol
[𝑦]
KeySwitch PubKeySwitch
Bob Bob
𝑦 𝐴𝑙𝑖𝑐𝑒,𝐶𝑎𝑟𝑜𝑙
𝑦 𝐶𝑎𝑟𝑜𝑙
Carol Carol
Carol
MHE – BRIDGING TO MPC
𝑦 𝐴
𝑦 𝐴
[𝑦] Alice
Alice Alice
𝑦 𝐵 𝑦 𝐵
[𝑦]
Enc2Share Share2Enc
[𝑦]
𝑦 Collective Bootstrapping
𝐴
𝑦 𝐴
Alice
𝑦 𝑦 𝐵
[𝑦]
𝐵
Enc2Share Share2Enc
Bob
𝑦 𝐶 𝑦 𝐶
Carol
MHE – COLLECTIVE BOOTSTRAPPING
[𝑦]
𝑦 Collective Bootstrapping
𝐴
𝑦 𝐴
Alice
𝑦 𝑦 𝐵
[𝑦]
𝐵
Enc2Share Share2Enc
Bob
𝑦 𝐶 𝑦 𝐶
Carol
MULTIPARTY HE – INPUT SELECTION EXAMPLE
MB
sec
#Parties #Parties
CONCLUSION
QUESTIONS?