c++ - 简单加密算术库 (SEAL) 和 seal::Ciphertext 变量
问题描述
我正在使用 Microsoft Cryptography Research Group 的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
不是二进制流或只是指向某个内存地址的指针的内容并将其保存为字符串。
如果你们中的任何人从上面的链接中下载了 SEAL 库并在不更改任何内容的情况下提取了它。seal::Ciphertext
您可以在SEAL_2.3.1\SEAL\seal\ciphertext.h和SEAL_2.3.1\SEAL\seal\ciphertext.cpp中找到所有允许的操作
解决方案
简短的回答是没有其他方法可以访问 SEAL 中的密文数据。返回的指针Ciphertext::data
将使您可以直接访问密文数据,从这个意义上说,您可以对其进行任何类型的计算,例如,如果出于某种原因您想要这样做,则转换为人类可读的字符串。
当然,要做任何可以理解的事情,您都需要知道密文的数据布局。在 BFV 方案中,密文由一对具有大 (size ) 系数的多项式 (c 0 , c 1 ) 组成。coeff_modulus
由于对具有如此大系数的多项式进行操作很不方便,SEAL 2.3.1 改为使用复合coeff_modulus
并存储 c 0和 c 1模数中指定的每个素因数coeff_modulus
(表示这些因数 q 1 ,q 2 ,..., q k )。每个 q i都适合一个 64 位的字,因此所有这些 2k 多项式都有字长系数。
密文系数数据布局如下(在内存中连续):
[ c 0 mod q 1 ][ c 0 mod q 2 ]...[ c 0 mod q k ][ c 1 mod q 1 ][ c 1 mod q 2 ]...[ c 1 mod q k ]
每个 [ c i mod q j ] 看起来像
[ c 0 [0] mod q j ][ c 1 [0] mod q j ]...[ c n-1 [0] mod q j ]
这里我用 c i [k] 来表示 c i的 k 次系数。请注意,每个系数都存储在一个uint64_t
.
Ciphertext::data
返回指向 c 0多项式相对于您的第一个模数的常数系数的指针coeff_modulus
,即指向 c 0 [0] mod q 1的指针。除了这个系数数据之外,Ciphertext 还包含一些其他字段,您可以使用成员函数读取这些字段。
推荐阅读
- c++ - 如何在 Matlab 中保存多维矩阵的二进制并将其作为 C++ 结构加载?
- c# - 卡在异步等待线程中
- java - 如何生成 PDF 发票并将其附加到电子邮件?
- python - 如何将块的结果放入 csv 列
- flutter - Different between shared preference and using redux
- postgresql - 自动检测 PostgreSQL 的主/从代理
- nuget - Artifactory nuget push - 不存在的用户(API 密钥/访问令牌)
- rxjs - 茉莉花测试期间出现意外错误(可观察到)
- makefile - 覆盖包含(删除路径)
- swift - 快速刷新标签栏控制器以在标签栏项目上显示徽章