-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpaillier.h
77 lines (70 loc) · 2.11 KB
/
paillier.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <NTL/ZZ.h>
#include <NTL/ZZ_pXFactoring.h>
class Paillier {
public:
/* Completely generate everything, from scratch */
Paillier();
Paillier(const NTL::ZZ& modulus, const NTL::ZZ& lambda);
//Paillier(path to public key, path to private key).
/* Paillier encryption function. Takes in a message from the
* integers modulo n (Paillier.modulus) and returns a message in
* the integers modulo n**2.
*
* Parameters
* ==========
* NTL::ZZ message : The message to encrypt, as a number.
*
* Returns
* =======
* NTL:ZZ ciphertext : The encyrpted message.
*/
NTL::ZZ encrypt(const NTL::ZZ& message);
/* Paillier encryption function with provided randomness, if user
* wants to provide their own randomness.
*
* Random number should be coprime to modulus.
*
* Parameters
* ==========
* NTL::ZZ message : The message to encrypt, as a number.
* NTL::ZZ random : The random mask.
*
* Returns
* =======
* NTL:ZZ ciphertext : The encyrpted message.
*/
NTL::ZZ encrypt(const NTL::ZZ& message, const NTL::ZZ& random);
/* Paillier decryption function. Takes in a cipertext from Z mod
* n**2 and returns a message in the Z mod n.
*
* Parameters
* ==========
* NTL::ZZ cipertext : The encrypted message.
*
* Returns
* =======
* NTL::ZZ message : The original message.
*/
NTL::ZZ decrypt(const NTL::ZZ& ciphertext);
private:
/* modulus = pq, where p and q are primes */
NTL::ZZ modulus;
NTL::ZZ generator;
NTL::ZZ lambda;
NTL::ZZ lambdaInverse;
/* The L function in the paillier cryptosystem. See
* <https://en.wikipedia.org/wiki/Paillier_cryptosystem> for more
* details.
*
* Parameters
* ==========
* NTL::ZZ x : The argument to L.
* NTL::ZZ n : The paillier modulus.
*
* Returns
* =======
* NTL::ZZ result : (x - 1) / n
*/
NTL::ZZ L_function(const NTL::ZZ& n) { return (n - 1) / modulus; }
void GenPrimePair(NTL::ZZ& p, NTL::ZZ& q, long keyLength);
};