简单加密算法库 (SEAL) 和 seal::Ciphertext 变量

Simple Encrypted Arithmetic Library (SEAL) and the seal::Ciphertext variable

我正在使用 Microsoft 密码学研究组的 Simple Encrypted Arithmetic Library (SEAL) 库。有没有办法获取seal::Ciphertext variable的内容?我试图理解 ciphertext.h 和 ciphertext.cpp 并发现:

/**
Saves the ciphertext to an output stream. The output is in binary format and not 
human-readable. The output stream must have the "binary" flag set.

@param[in] stream The stream to save the ciphertext to
@see load() to load a saved ciphertext.
*/
void save(std::ostream &stream) const;

/**
Loads a ciphertext from an input stream overwriting the current ciphertext.

@param[in] stream The stream to load the ciphertext from
@see save() to save a ciphertext.
*/
void load(std::istream &stream);

但我找不到另一个选项来获取任何 seal::Ciphertext variable 的内容,它不是二进制流,也不是指向某个内存地址的指针,并将其保存为字符串。

如果你们中的任何人从上面的 link 下载了 SEAL 库并在不做任何更改的情况下将其解压缩。您可以在 SEAL_2.3.1\SEAL\seal\ciphertext.hSEAL_2 中找到对 seal::Ciphertext 所有允许的操作.3.1\SEAL\seal\ciphertext.cpp

简而言之,没有其他方法可以访问 SEAL 中的密文数据。 Ciphertext::data 返回的指针将使您可以直接访问密文数据,从这个意义上讲,您可以对其进行任何类型的计算,例如如果出于某种原因您想要转换为人类可读的字符串。

当然,要做到任何可理解的事情,您都需要知道密文的数据布局。在 BFV 方案中,密文由一对具有大(大小 coeff_modulus)系数的多项式(c0、c1)组成.由于对具有如此大系数的多项式进行运算很不方便,因此 SEAL 2.3.1 使用复合 coeff_modulus 并存储 c0 和 c1 modulo coeff_modulus 中指定的每个质因数(表示这些因数 q1,q2 ,...,qk)。每个 qi 适合一个 64 位字,因此所有这些 2k 多项式都有字大小系数。

密文系数数据布局如下(内存中连续):

[ c0 mod q1 ][ c0 modq2]...[c0modqk ][ c1 mod q1 ][ c1 mod q2]...[c1modqk]

其中每个 [ ci mod qj ] 看起来像

[ c0[0] mod qj ][ c1[0] mod qj ]...[ cn-1[0] mod q j]

这里我用ci[k]表示ci的k次系数。请注意,每个系数都存储在uint64_t中。

Ciphertext::data returns 指向 c0 多项式的常数系数的指针,相对于你的第一个 modulus coeff_modulus,即c0[0]modq1。除了此系数数据外,密文还包含一些其他字段,您可以使用成员函数读取这些字段。