Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrapping Function Doubt #251

Open
divyesh98 opened this issue Jul 22, 2022 · 0 comments
Open

Bootstrapping Function Doubt #251

divyesh98 opened this issue Jul 22, 2022 · 0 comments

Comments

@divyesh98
Copy link

I tried using bootstrap function, but it seemed to give incorrect result. Can anyone explain this behavior?!

Attaching Code and result for reference.

// Includes
#include <stdio.h>
#include
#include
#include
#include
#include
#include
#include <sys/time.h>
#include
// Multi-processing
#include <sys/wait.h>
#include <unistd.h>
//#include <tbb/parallel_for.h>
// tfhe-lib
#include "tfhe.h"
#include "tfhe_garbage_collector.h"
#include "lwesamples.h"
#include "lwekey.h"
#include "lweparams.h"
#include "polynomials.h"
#include "tfhe_gate_bootstrapping_functions.h"

using namespace std;
using namespace std::chrono;

int32_t main(int32_t argc, char** argv){

//generate params
int32_t minimum_lambda = 80;
TFheGateBootstrappingParameterSet *params = new_default_gate_bootstrapping_parameters(minimum_lambda);

const LweParams *in_out_params = params -> in_out_params;
LweKey *lwe_key = new_LweKey(params -> in_out_params);

lweKeyGen(lwe_key);

TGswKey *tgsw_key = new_TGswKey(params->tgsw_params);
tGswKeyGen(tgsw_key);
LweBootstrappingKey *bootkey = new_LweBootstrappingKey(params->ks_t, params->ks_basebit, params->in_out_params,
                                                  params->tgsw_params);
tfhe_createLweBootstrappingKey(bootkey, lwe_key, tgsw_key);
TFheGateBootstrappingSecretKeySet *keyset = new_random_gate_bootstrapping_secret_keyset(params);
const LweBootstrappingKeyFFT *bs_key = keyset->cloud.bkFFT;
const TFheGateBootstrappingCloudKeySet * cloudkeyset = new TFheGateBootstrappingCloudKeySet(params, bootkey, bs_key);

//parameters generated

int slots = 700;
double alpha = pow(2, -30);
int x = 10;

Torus32 phase = modSwitchToTorus32(x, slots);

LweSample* cipher1 = new_LweSample_array(1, in_out_params);
LweSample* cipher2 = new_LweSample_array(1, in_out_params);

//encrypting with lwekey
lweSymEncrypt(cipher1 + 0, phase, alpha, lwe_key);

//noiseless encryption
lweNoiselessTrivial(cipher2 + 0, phase, in_out_params);

cout << "Original value of integer is " << x << endl;

//bootstrap operations for cipher1
tfhe_bootstrap(cipher2 + 0, keyset->cloud.bk, phase, cipher2 + 0);
Torus32 phase1 = lweSymDecrypt(cipher2 + 0, lwe_key, slots);	
cout << "Bootstrapped value of the Noiseless cipher = " << modSwitchFromTorus32(phase1, slots) << endl;; 

tfhe_bootstrap(cipher1 + 0, keyset->cloud.bk, phase, cipher1 + 0);
phase1 = lweSymDecrypt(cipher1 + 0, lwe_key, slots);	
cout << "Bootstrapped value of the Lwe Encrypted cipher = " << modSwitchFromTorus32(phase1, slots) << endl;; 
return 0;

ss11
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant