本文介绍了简单加密算术库(SEAL)和seal :: Ciphertext变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用库。有没有办法获取 seal :: Ciphertext变量的内容?我试图了解ciphertext.h和ciphertext.cpp并找到了:

I'm using the Simple Encrypted Arithmetic Library (SEAL) library from Microsoft Cryptography Research Group. Is there a way to get the content of seal::Ciphertext variable? I've tried to understand the ciphertext.h and ciphertext.cpp and found the:

/**
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);

但我找不到其他方法来获取任何密封件的内容:: Ciphertext变量不是二进制流,也不是指向某个内存地址的指针,而是将其保存为字符串。

But I coudn't find another option to get the content of anyseal::Ciphertext variable that is not a binary stream or just a pointer to some memory address and save it a string.

如果有人从上面的链接下载了SEAL库并提取了它,而没有进行任何更改。您可以在 SEAL_2.3.1\SEAL\seal\ciphertext.h 中的 seal :: Ciphertext 上找到所有允许的操作> SEAL_2.3.1\SEAL\seal\ciphertext.cpp

If any of you have download the SEAL library from the link above and extracted it without changing anything. You can find all the allowed operations on seal::Ciphertext in SEAL_2.3.1\SEAL\seal\ciphertext.h and SEAL_2.3.1\SEAL\seal\ciphertext.cpp

推荐答案

简短的答案是:没有其他方法可以在SEAL中访问密文数据。 Ciphertext :: data 返回的指针将使您可以直接访问密文数据,从这种意义上讲,您可以对其进行任何类型的计算,例如

Short answer is that there are no other ways of accessing the ciphertext data in SEAL. The pointer returned by Ciphertext::data will give you direct access to the ciphertext data and in that sense allows you to do any kind of computation on it, e.g. converting to a human-readable string if for some reason you would want to do that.

当然,要执行任何可理解的操作,您需要了解密文的数据布局。在BFV方案中,密文由一对多项式(c ,c )组成,其大小较大( coeff_modulus )系数。由于对具有如此大系数的多项式进行运算很不方便,因此SEAL 2.3.1改为使用复合 coeff_modulus 并存储c 和c 对 coeff_modulus 中指定的每个主要因子取模(表示这些因子q ,q )。每个q 都适合一个64位单词,因此所有这2k多项式都具有单词大小系数。

Of course to do anything intelligible you need to know the data layout of the ciphertext. In the BFV scheme a ciphertext consists of a pair of polynomials (c, c) with large (size coeff_modulus) coefficients. Since operating on polynomials with such large coefficients is inconvenient, SEAL 2.3.1 instead uses a composite coeff_modulus and stores both c and c modulo each of the prime factors specified in the coeff_modulus (denote these factors q,q,...,q). Each q fits into a 64-bit word, so all of these 2k polynomials have word-size coefficients.

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

The ciphertext coefficient data layout is as follows (contiguous in memory):

[c mod q ] [c mod q ] ... [c mod q ] [c mod q ] [c mod q ] ... [c mod q ]

[ c mod q ][ c mod q ]...[ c mod q ][ c mod q ][ c mod q ]...[ c mod q ]

其中每个[c mod q ]看起来像

where each [ c mod q ] looks like

[c [0] mod q ] [c [0] mod q ] ... [c [0] mod q ]

[ c[0] mod q ][ c[0] mod q ]...[ c[0] mod q ]

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

Here I used c[k] to denote the degree k coefficient of c. Note that each coefficient is stored in a uint64_t.

Ciphertext :: data 返回指向c 的常数系数的指针关于 coeff_modulus 中的第一个模的多项式,即c [0] mod q 。除此系数数据外,密文还包含其他一些可以使用成员函数读取的字段。

Ciphertext::data returns a pointer to the constant coefficient of the c polynomial with respect to the first modulus in your coeff_modulus, i.e. to c[0] mod q. In addition to this coefficient data, a Ciphertext contains a few other fields that you can read using the member functions.

这篇关于简单加密算术库(SEAL)和seal :: Ciphertext变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 14:07