TFHE Deep Dive 系列的博客出自Ilaria Chillotti (即 TFHE 方案的第一作者)在 zara
上发布的一系列的技术博客, 并进行了报告,感兴趣的读者可以自行探索。 该篇博客是笔者学习 TFHE 算法总结性的 notes。
本文的 Markmap,以及该博客的 pdf 版本:
References : by the 1st author of TFHE , , TFHE Deep Dive Series posted in 2022:
- TFHE Deep Dive - Part I - Ciphertext types
- TFHE Deep Dive - Part II - Encodings and linear leveled operations
- TFHE Deep Dive - Part III - Key switching and leveled multiplications
- TFHE Deep Dive - Part IV - Programmable Bootstrapping
Notions Before TFHE
Remarks:
- the ring of integer polynomials modulo the cyclotomic polynomial , with power of 2 . (定义在整数环上的多项式商环:模多项式为 )
- , i.e., the same ring of integers as above, but this time the coefficients are modulo $q$. Observe that we often note $\mathbb{Z} / q \mathbb{Z}$ as $\mathbb{Z}_q$. (定义在整数商环 $\mathbb{Z} / q \mathbb{Z}$ 上的多项式商环:模多项式为 )
- Balanced Mod : 整数商环 上的剩余系代表我们选取 :
- 数字均用小写字母表示 , 多项式均用大写字母表示 .
- 整数区间: 到 记为 .
- MSB for Most Significant Bit and LSB for Least Significant Bit respectively.
- 取整:
PlainText And CipherText Space
- 明文模数 : ;明文空间
- 密文模数 : ;密文空间
- Scaling Factor :
Ciphertext Types
GLWE
密钥 : ;明文 :
记 : 为 GLWE 类型密文的一般表示 。
GLev
密钥 : ;明文 :
不同 scaling factor 下相同明文的 GLWE 密文向量:
记 : 为 GLev 类型密文的一般表示 。
GGSW
密钥 : ;明文 :
密钥每一维的 neg-polynomial(额外包含 1)与明文乘积的 GLev 密文
记 : 为 GGSW 类型密文的一般表示 。
Torus Visualization
Where is our message in TFHE ? Encoded in MSB !
What if real numbers in a fixed interval ? Encoded in MSB but mixed with errors !
环形结构 Torus, a mathematical structure that looks like a donut. Why this way ?
Building Blocks
Building Blocks Fast Programmable Bootstrapping.
Message encrypted by the same key
Homomorphic ADD :
密钥 : ;明文 : ; 密文 :
Little By Little , from constant-ciphertext multiplication to ciphertext-ciphertext multiplication !
- Homomorphic Mul by a small constant polynomial. Mul :
Homomorphic Mul by a large constant.
If we directly times them :
We need :
We need ciphertext :
Mul :
Homomorphic Mul by a large constant polynomial.
Almost the same with the constant one. Decompose the polynomial this time:
where , with , such that:
PS : 实际上是一个升维过程, 是降维过程。
Homomorphic Mul by a ciphertext ? Before this , we come into a similar process called .
更换加密密钥 :
原始密钥 : ;明文 : ; 原始密文 :
Key Switching Key
思路:用 加密后的 去执行解密的第一步,就得到了 加密后的密文。实际上完整的 是一个 GGSW 密文。 与密文的同态乘法是很类似的。
Switching :
Finally : between two ciphertexts called in TFHE.
Setting : GLWE 密文 与 GGSW 密文
- a GLWE ciphertext encrypting a message under the secret key :where the elements for are sampled uniformly random from , and , and has coefficients sampled from a Gaussian distribution , as we have already seen before.
- a GGSW ciphertext encrypting a message under the same secret key :where for and
Process of !
同时 和
- GLWE 密钥不变,为
- GGSW 的密文使用一个不同的密钥
得到 :
In TFHE :
Setting :
- a GGSW ciphertext encrypting a message under the same secret key :where, for :with for and with for
- a GGSW ciphertext encrypting a message under the same secret key :where for and
Process between GGSW and GGSW!
The result is :
The CMux operation is the homomorphic version of a Mux gate, also known as multiplexer gate.
简单来说一次乘法、两次加法即可实现:
密文空间变换 :
Let and be two positive integers (powers of 2 for simplicity), such that and let . Let’s recall that an LWE ciphertext encrypting a message under the secret key is a tuple:
The from to is easy :
A sample extraction is an operation that takes as input a GLWE ciphertext, encrypting a polynomial message, and extracts the encryption of one of the coefficients of the message as a LWE ciphertext.
即 提取 GLWE 加密的多项式其中的一个系数加密后的结果(LWE 密文)。
Let’s take a GLWE ciphertext encrypting a message under secret key:
The ciphertext :
从上述密文中提取 加密多项式 的第 h 个系数:
加密密钥 :
其中 的 LWE 密文
The core of the fast bootstrapping!
How to rotate :
Rotate the coefficients of a polynomial ?
Shift the coefficients towards the left (or the right) :
How ?
We multiply it times
Rotate the coefficients of an encrypted polynomial ?
Rotating :
Blind Rotation ? We wanna hide the shift !
Binary decomposition :
Then :
Compute
The full process of Blind Rotation
We need ciphertexts as follows :
- a GGSW encryption of ;
- a GLWE encryption of as the “0” option ;
- a GLWE encryption of (rotation of a clear number of positions) as the “1” option.
One :
The whole blind rotation :
What is Bootstrapping ? Evaluate the decryption function homomorphically
在 类问题中,解密算法可以分为下面两步:
STEP-1 : The computation of the linear combination :
STEP-2 : The rescale and rounding :
其中 STEP-1 是简单的,用同态加/乘法足以解决,而真正做到减低噪声是第二步,这一步非常关键,也往往是 Bootstrapping 里面最耗费时间的操作。在 TFHE 中,最大的突破在于实现了 Fast Bootstrapping。
STEP-1 是简单的,因此这里首先讨论在 TFHE 中如如何进行 STEP-2 :将第一步得到的结果 作为 的指数,即 去 Blind Rotate 一个 Look-Up Table (LUT:evaluates the second step of the decryption (rescale and rounding).)
Step 2 Blind Rotation in Bootstrapping
Associate the value with the plaintext , the message distribution in :
We call the blocks containing multiple repetitions of the same value mega-cases.
The way we evaluate such LUT is by performing a polynomial rotation: the idea is to put all the elements of the redundant LUT into a polynomial and rotate the polynomial by multiplying . The rotation has the effect to bring one of the elements contained in the mega-case corresponding to in the constant position of the polynomial.
将 LUT 表存入一个多项式,用 Blind Rotation 操作去 rotate ( 乘 ),常数项上的系数就对应解密的 , 即 reading position。
How to store such LUT in detail ?
- TFHE 里我们操作的多项式均模 , 即 最多 N 个系数 (通常 : )。我们肯定需要进行数据压缩 modulus switching。
- 考虑 单项式 在多项式商环上的阶,为 : 。也就是说,利用 rotation,我们最多得到 个结果 ()。于是我们要把 上的 对应信息 转换到 上的元素内。(if negacyclic property exists, N is OK without padding bit)
Finally, the modulus switching is going to be done from to !
Step 1 + 2
Need :
Compute polynomial
Bootstrapping key : GGSW encryptions of under a new GLWE secret key :
Process
Modulus switching :
Step 2 需要的 exponential information 是限定在 2N 范围内的,于是 :
Blind rotation
Initialize the blind rotation by multiplying the trivial GLWE encryption (rotation)
Pass the trivial encryption of as input to a first :
- Selector : the GGSW encryption of the bit
- Options : and
- Output : a GLWE encryption of
Pass the GLWE encryption of to the second :
- Selector : the GGSW encryption of the bit
- Options : and
- Output : a GLWE encryption of
Until N done.
Final Output :
Figure : Blind Rotation Sample Extraction : extract the constant sample, that is .
(Key switching : )
Why programmable ?
The polynomial is actually a table. Do operations f on V and we obtain a new table encode .
Non-arithmetic Operation
An example of bootstrapping: the Gate Bootstrapping ! Non-arithmetic Operation can be implemented by the programmable LUT.
所有的比特门运算 (AND, NAND, OR, XOR, etc.) ,都可以通过 programmable bootstrapping 实现。这里以 ADD 门为例,构造 ADD Gate Bootstrapping 。
ADD Gate Bootstrapping Construction
Input : two LWE ciphertexts encrypting two bits under the same secret key.
- Ciphertext 1
- Ciphertext 2
Encoding info :
Process :
- 线性运算,取决于需要计算的函数。AND Gate 使用:
基于 LUT 进行Bootstrapping,LUT 对应多项式为
V is rescaled sign function : 对所有正数输入得到 q/8 , 对所有负数输入得到 - q/8
由于 TFHE 很好地支持了非算术运算,因此 TFHE 中 Gate Bootstrapping 中可以用于神经网络的非线性激活函数构造。