简体   繁体   English

SEAL:如何读取模系数 forms 中的 Relinkkeys 数据?

[英]SEAL: How to read Relinkeys data in forms of modulo coefficients?

When running examples in SEAL (v3.6), I can print out polynomial coefficients of secret_key , public_key data using support functions在 SEAL (v3.6) 中运行示例时,我可以使用支持函数打印出secret_keypublic_key数据的多项式系数

ofstream sk;
sk.open(filename, ios::binary);
for (uint64_t i = 0; i < poly_modulus_degree; i++)
{
    sk << secret_key.data()[i] << endl;
}
sk.close();

with the coefficient data layout follow moduli is same with Simple Encrypted Arithmetic Library (SEAL) and the seal::Ciphertext variable .系数数据布局跟随模数与简单加密算术库 (SEAL) 和 seal::Ciphertext 变量相同。

Output coefficients 60 bits as examples:以 Output 系数 60 位为例:

348362126124274227
287021082413421529
790977662641979136
532895062119300067
...

But I can not understand the forms of relin_keys and how to use its class's support methods to print relin_keys data in forms of polynomial coefficients?但是我无法理解relin_keys的relin_keys以及如何使用其类的支持方法打印多项式系数的forms中的relin_keys数据? Thank for your help.感谢您的帮助。

RelinKeys is derived from KSwitchKeys which contains a data member in the type of vector<vector<PublicKey>> . RelinKeys派生自KSwitchKeys ,其中包含vector<vector<PublicKey>>类型的数据成员。 Since PublicKey is basically the same with Ciphertext , RelinKeys is simply a 2-dimensional vector of Ciphertext .由于PublicKeyCiphertext基本相同, RelinKeys只是Ciphertext的二维向量。

The first dimension enumerates the relinearization key generated for a certain power of secret key.第一个维度枚举了为特定幂的密钥生成的重新线性化密钥。 For example, by default only a relinearization key for the 2nd power of secret key is generated, therefore the first dimension usually has size 1 .例如,默认情况下,仅生成密钥的 2 次方的重新线性化密钥,因此第一个维度的大小通常为1 This is accessible by relin_keys.key(2) described by this method , which returns vector<PublicKey> .这可以通过此方法描述的relin_keys.key(2)访问,该方法返回vector<PublicKey>

The second dimension corresponds to the decomposition method used to generated relinearization keys and to perform relinearization.第二个维度对应于用于生成重新线性化键和执行重新线性化的分解方法。 The size of the second dimension is usually equal to context.first_context_data()->parms().coeff_modulus().size() .第二维的大小通常等于context.first_context_data()->parms().coeff_modulus().size() After this point, you should know how to print out each Ciphertext object.在这点之后,你应该知道如何打印出每个Ciphertext object。

The following code should help:以下代码应该会有所帮助:

void print_ciphertext(const Ciphertext &ciphertext) {
    // code to print coefficients of a Ciphertext object
}

RelinKeys relin_keys;
// ... generate keys ...

for (std::size_t key_power = 2; relin_keys.has_key(key_power); key_power++) {
    for (auto &public_key: relin_keys.key(key_power)) {
        print_ciphertext(public_key.data());
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM