我正在使用带有CKKS方案的SEAL库,并且正在对双精度值进行批处理编码和加密,因此我想对它们进行求和。目前,我有这样的事情:
#include <iostream>
#include <vector>
#include <sstream>
#include "seal/seal.h"
int main()
{
const vector<double> x_coordinates = { -3, -3, 3, 3 };
const vector<double> y_coordinates = { -1, 0.5, 0.7, 1.7 };
const vector<double> x_centers = { 0., 6 };
const vector<double> y_centers = { 0., 6 };
// Create encryption parameters
EncryptionParameters params(scheme_type::CKKS);
size_t poly_modulus_degree = 16384;
params.set_poly_modulus_degree(poly_modulus_degree);
params.set_coeff_modulus(CoeffModulus::Create(poly_modulus_degree, { 60, 40, 40, 60 }));
cout << "Generating keys... ";
auto context = SEALContext::Create(params);
KeyGenerator keygen(context);
auto public_key = keygen.public_key();
auto secret_key = keygen.secret_key();
auto relin_keys = keygen.relin_keys();
Encryptor encryptor(context, public_key);
Evaluator evaluator(context);
Decryptor decryptor(context, secret_key);
cout << "Done!" << endl;
CKKSEncoder encoder(context);
size_t slot_count = encoder.slot_count();
double scale = pow(2.0, 40);
cout << "\nSlots: " << slot_count << endl;
cout << "Scale: " << scale << endl;
double norm = 1. / x_coordinates.size();
cout << "\nEcrypting coordinates... ";
// Encode the input coordinates and centers.
Plaintext plain_x, plain_y;
Plaintext plain_x_center, plain_y_center;
encoder.encode(x_coordinates, scale, plain_x);
encoder.encode(y_coordinates, scale, plain_y);
encoder.encode(x_centers, scale, plain_x_center);
encoder.encode(y_centers, scale, plain_y_center);
// Encrypt the encoded input coordinates and centers.
Ciphertext encrypted_x, encrypted_y;
Ciphertext encrypted_x_center, encrypted_y_center;
encryptor.encrypt(plain_x, encrypted_x);
encryptor.encrypt(plain_y, encrypted_y);
encryptor.encrypt(plain_x_center, encrypted_x_center);
encryptor.encrypt(plain_y_center, encrypted_y_center);
// NOTE: Now I want to sum the values inside encrypted_x.
Ciphertext result;
evaluator.add_many(encrypted_x, result); // This won't work as we have single ciphertext.
return 0;
}
因此,有没有一种方法可以对批加密值进行求和,而不是手动创建一个vector<Ciphertext>
然后一个一个地加密每个输入值,最后像上面那样做add_many
? / p>