2021SC@SDUSC
2021-12-27
前言
本篇开始我将讨论SEAL中rotation.cpp的代码实现。
简介
BFV方案(使用BatchEncoder)和CKKS方案都支持对加密数字进行native计算。除了slot-wise计算外,还可以循环地旋转加密向量。
代码分析
void example_rotation_bfv()
先是和前文类似的设置一些参数。
print_example_banner("Example: Rotation / Rotation in BFV");
EncryptionParameters parms(scheme_type::bfv);
size_t poly_modulus_degree = 8192;
parms.set_poly_modulus_degree(poly_modulus_degree);
parms.set_coeff_modulus(CoeffModulus::BFVDefault(poly_modulus_degree));
parms.set_plain_modulus(PlainModulus::Batching(poly_modulus_degree, 20));
SEALContext context(parms);
print_parameters(context);
cout << endl;
KeyGenerator keygen(context);
SecretKey secret_key = keygen.secret_key();
PublicKey public_key;
keygen.create_public_key(public_key);
RelinKeys relin_keys;
keygen.create_relin_keys(relin_keys);
Encryptor encryptor(context, public_key);
Evaluator evaluator(context);
Decryptor decryptor(context, secret_key);
BatchEncoder batch_encoder(context);
size_t slot_count = batch_encoder.slot_count();
size_t row_size = slot_count / 2;
cout << "Plaintext matrix row size: " << row_size << endl;
vector<uint64_t> pod_matrix(slot_count, 0ULL);
pod_matrix[0] = 0ULL;
pod_matrix[1] = 1ULL;
pod_matrix[2] = 2ULL;
pod_matrix[3] = 3ULL;
pod_matrix[row_size] = 4ULL;
pod_matrix[row_size + 1] = 5ULL;
pod_matrix[row_size + 2] = 6ULL;
pod_matrix[row_size + 3] = 7ULL;
cout << "Input plaintext matrix:" << endl;
print_matrix(pod_matrix, row_size);
首先,我们使用BatchEncoder将矩阵编码成明文。我们像往常一样加密明文。

本文深入探讨了SEAL库中BFV和CKKS加密方案的旋转操作实现,包括行旋转和列旋转。通过示例代码详细解释了如何在加密数据上进行这些操作,并强调了旋转操作不消耗噪音预算的重要性。同时,介绍了CKKS方案中的复数向量旋转。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



