SEAL全同态加密开源库(五)
一.解密Decrypt
首先是构造函数,解密的一种形式代表
public Decryptor(SEALContext context, SecretKey secretKey)
{
if (null == context)
throw new ArgumentNullException(nameof(context));
if (null == secretKey)
throw new ArgumentNullException(nameof(secretKey));
if (!context.ParametersSet)
throw new ArgumentException("Encryption parameters are not set correctly");
if (!ValCheck.IsValidFor(secretKey, context))
throw new ArgumentException("Secret key is not valid for encryption parameters");
NativeMethods.Decryptor_Create(context.NativePtr, secretKey.NativePtr, out IntPtr ptr);
NativePtr = ptr;
}
下面是解密的主要方法和过程
public void Decrypt(Ciphertext encrypted, Plaintext destination)
{
if (null == encrypted)
throw new ArgumentNullException(nameof(encrypted));
if (null == destination)
throw new ArgumentNullException(nameof(destination));
NativeMethods.Decryptor_Decrypt(NativePtr, encrypted.NativePtr, destination.NativePtr);
}
public int InvariantNoiseBudget(Ciphertext encrypted)
{
if (null == encrypted)
throw new ArgumentNullException(nameof(encrypted));
NativeMethods.Decryptor_InvariantNoiseBudget(NativePtr, encrypted.NativePtr, out int result);
return result;
}
二.解密的具体过程
如上所述,解密相对简单。首先,我们计算[ct0 + ct1s]q,它将从消息中完全移除掩码。这给我们一个多项式,它可以展开为[qm / t + e1 + eu + e2s]q -也就是说,缩放后的信息加上一些噪声。因此,只要噪声不太大,我们就可以恢复消息。
明确地,
在这里您可以看到,除了明文的两个非零系数(x8和x0)之外,所有的系数都小于q/t = 128。如果我们把这个多项式缩放回mod t范围内的值,那么我们就得到
四舍五入这些系数可以恢复我们的消息m = 3 − 3x8。
我们通过将系数四舍五入,来舍入到最接近的整数后得到我们的信息:
把它们放在一起,我们通过如下计算来解密密文
⌊⌉表示舍入到最接近的整数(四舍五入)。
如果系数中噪音太大,那么它们最终会更接近一个与正确整数不同的整数,然后解密会(悄无声息地)失败并产生错误的结果。在上面的示例中,最大的噪音为13 / 128,所以仍然有一些空间允许产生更多的噪音,并且能够正确解密。噪音的含量可以通过将q / t的比值变大或变小来调节。