Untitled
unknown
c_cpp
3 years ago
2.3 kB
55
No Index
#include <iostream>
#include "openfhe.h"
using namespace lbcrypto;
using namespace std;
int main() {
cout << "CryptoContext and Keys generation started..." << endl;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetSecretKeyDist(UNIFORM_TERNARY);
parameters.SetSecurityLevel(lbcrypto::HEStd_128_classic);
parameters.SetRingDim(1 << 16);
ScalingTechnique rescaleTech = FLEXIBLEAUTO;
usint dcrtBits = 59;
usint firstMod = 60;
parameters.SetScalingModSize(dcrtBits);
parameters.SetScalingTechnique(rescaleTech);
parameters.SetFirstModSize(firstMod);
std::vector<uint32_t> levelBudget = {4, 4};
uint32_t approxBootstrapDepth = 8;
uint32_t levelsUsedBeforeBootstrap = 8;
usint depth =
levelsUsedBeforeBootstrap + FHECKKSRNS::GetBootstrapDepth(approxBootstrapDepth, levelBudget, UNIFORM_TERNARY);
parameters.SetMultiplicativeDepth(depth);
cout << "Generating crypto context..." << endl;
CryptoContext<DCRTPoly> crypto_context = GenCryptoContext(parameters);
crypto_context->Enable(PKE);
crypto_context->Enable(KEYSWITCH);
crypto_context->Enable(LEVELEDSHE);
crypto_context->Enable(ADVANCEDSHE);
crypto_context->Enable(FHE);
KeyPair<DCRTPoly> key_pair = crypto_context->KeyGen();
cout << "Evaluating MultKeyGen..." << endl;
crypto_context->EvalRotateKeyGen(key_pair.secretKey, {1, 128, 128*2, 128*2*2, 128*4,128*8,128*16,128*128});
vector<double> v = {1, 2, 3, 4};
cout << "Encoding and encrypting a vector..." << endl;
Plaintext p = crypto_context->MakeCKKSPackedPlaintext(v, 1, 0,nullptr,v.size());
Ciphertext<DCRTPoly> c = crypto_context->Encrypt(key_pair.publicKey, p);
auto digits2 = crypto_context->EvalFastRotationPrecompute(c);
for (int i = 0; i < 7; i++) {
cout << "Iteration " << i << ": " << endl;
c = crypto_context->EvalAdd(c,
crypto_context->EvalFastRotation(c, 128 * pow(2, i), crypto_context->GetCyclotomicOrder(), digits2));
Plaintext ress;
crypto_context->Decrypt(key_pair.secretKey, c, &ress);
cout << "Decryptable" << endl;
}
return 0;
}
Editor is loading...