-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfully_homomorphic.h
57 lines (49 loc) · 2.14 KB
/
fully_homomorphic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef FULLY_HOMOMORPHIC_H
#define FULLY_HOMOMORPHIC_H
#include "type_defs.h"
#include <cstdio>
#include <cmath>
#include <gmp.h>
#include "utilities.h"
#include "circuit.h"
#include "security_settings.h"
#include <cryptopp/osrng.h>
#include <vector>
#include <stack>
class FullyHomomorphic
{
private:
static unsigned int MAX_SOMEWHAT_PUBLIC_KEY_TRIES;
SecuritySettings *sec;
gmp_randstate_t rand_state;
CryptoPP::RandomPool rng;
void create_somewhat_private_key(SomewhatPrivateKey private_key);
void create_somewhat_public_key(SomewhatPublicKey result, SomewhatPrivateKey sk);
void create_additional_somewhat_public_key(SomewhatPublicKey result, SomewhatPrivateKey sk);
void choose_random_d(mpz_t result, SomewhatPrivateKey p);
unsigned int* create_S_vector();
void create_u_vector(mpz_t_arr result, mpz_t x_p, unsigned int* S);
void store_cipher_bit(FILE* stream, CipherBit &c);
public:
FullyHomomorphic(SecuritySettings *security_settings);
void key_gen(PrivateKey &sk, PublicKey &pk);
void print_key(const PrivateKey &sk, const PublicKey &pk);
void print_cipher_bit(const CipherBit &c);
void encrypt_bit(CipherBit &result, const PublicKey &pk, const bool m);
bool decrypt_bit(const CipherBit &c, const PrivateKey &sk);
void clear_cipher_bit(CipherBit &c);
CipherBit** encrypt_bit_vector(const PublicKey &pk, const bool* m_vector, const unsigned long int m_vector_length);
bool* decrypt_bit_vector(const PrivateKey &sk, CipherBit** c_vector, const unsigned long int c_vector_length);
//std::vector<CipherBit> evaluate(CircuitNode *circuit, std::vector<CipherBit> inputs);
CipherBit** evaluate(std::vector<Gate*> output_gates, CipherBit** inputs, const PublicKey &pk);
std::vector<Gate*> create_decryption_cicuit();
Gate*** create_3_for_2_circuit(Gate** a, Gate** b, Gate** c, unsigned int n);
void test_decryption_circuit(const PublicKey &pk, const PrivateKey &sk);
bool is_allowed_circuit(std::vector<Gate*> output_gates);
/* static CipherBit TRUE; */
/* static CipherBit FALSE; */
// For debugging
mpz_t ssk;
void old_encrypt_bit(mpz_t result, const PublicKey &pk, const bool m);
};
#endif //FULLY_HOMOMORPHIC_H