libhcs
pcs.h
Go to the documentation of this file.
1 
16 #ifndef HCS_PCS_H
17 #define HCS_PCS_H
18 
19 #include <gmp.h>
20 #include "hcs_random.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
29 typedef struct {
30  mpz_t n;
31  mpz_t g;
32  mpz_t n2;
34 
38 typedef struct {
39  mpz_t p;
40  mpz_t q;
41  mpz_t p2;
42  mpz_t q2;
43  mpz_t hp;
44  mpz_t hq;
45  mpz_t lambda;
46  mpz_t mu;
47  mpz_t n;
48  mpz_t n2;
50 
59 
68 
90  hcs_random *hr, const unsigned long bits);
91 
100 void pcs_encrypt(pcs_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t plain1);
101 
112 void pcs_encrypt_r(pcs_public_key *pk, mpz_t rop, mpz_t plain1, mpz_t r);
113 
123 void pcs_reencrypt(pcs_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t op);
124 
134 void pcs_ep_add(pcs_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t plain1);
135 
145 void pcs_ee_add(pcs_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t cipher2);
146 
157 void pcs_ep_mul(pcs_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t plain1);
158 
167 void pcs_decrypt(pcs_private_key *vk, mpz_t rop, mpz_t cipher1);
168 
184 
193 
202 
211 
224 
235 
245 
254 int pcs_import_public_key(pcs_public_key *pk, const char *json);
255 
264 int pcs_import_private_key(pcs_private_key *vk, const char *json);
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif
Provides secure random state for use in functions which require random values.
void pcs_encrypt_r(pcs_public_key *pk, mpz_t rop, mpz_t plain1, mpz_t r)
Encrypt a value plain1, and set rop to the encrypted result.
mpz_t q2
Precomputation: q^2.
Definition: pcs.h:42
void pcs_clear_public_key(pcs_public_key *pk)
This function zeros all data in pk.
mpz_t lambda
Precomputation: euler-phi(p, q)
Definition: pcs.h:45
mpz_t p2
Precomputation: p^2.
Definition: pcs.h:41
char * pcs_export_private_key(pcs_private_key *vk)
Export a private key as a string.
pcs_public_key * pcs_init_public_key(void)
Initialise a pcs_public_key and return a pointer to the newly created structure.
mpz_t hq
Precomputation: L_p(g^{q-1} mod q^2)^{-1} mod q.
Definition: pcs.h:44
void pcs_clear_private_key(pcs_private_key *vk)
This function zeros all data in pk.
void pcs_ep_mul(pcs_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t plain1)
Multiply a plaintext value plain1 with an encrypted value cipher1, storing the result in rop...
mpz_t mu
Precomputation: lambda^{-1} mod n.
Definition: pcs.h:46
void pcs_ee_add(pcs_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t cipher2)
Add an encrypted value cipher2 to an encrypted value cipher1, storing the result in rop...
void pcs_free_public_key(pcs_public_key *pk)
Frees a pcs_public_key and all associated memory.
int pcs_verify_key_pair(pcs_public_key *pk, pcs_private_key *vk)
Check certain values shared between public and private keys to ensure they indeed are pairs...
mpz_t hp
Precomputation: L_p(g^{p-1} mod p^2)^{-1} mod p.
Definition: pcs.h:43
mpz_t n
Modulus of the key: n = p * q.
Definition: pcs.h:30
void pcs_reencrypt(pcs_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t op)
Reencrypt an encrypted value op.
void pcs_generate_key_pair(pcs_public_key *pk, pcs_private_key *vk, hcs_random *hr, const unsigned long bits)
Initialise a key pair with modulus size bits.
int pcs_import_public_key(pcs_public_key *pk, const char *json)
Import a public key from a string.
int pcs_import_private_key(pcs_private_key *vk, const char *json)
Import a private key from a string.
mpz_t n2
Precomputation: n^2.
Definition: pcs.h:48
void pcs_ep_add(pcs_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t plain1)
Add a plaintext value plain1 to an encrypted value cipher1, storing the result in rop...
void pcs_encrypt(pcs_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t plain1)
Encrypt a value plain1, and set rop to the encrypted result.
Public key for use in the Paillier system.
Definition: pcs.h:29
char * pcs_export_public_key(pcs_public_key *pk)
Export a public key as a string.
void pcs_decrypt(pcs_private_key *vk, mpz_t rop, mpz_t cipher1)
Decrypt a value cipher1, and set rop to the decrypted result.
Private key for use in the Paillier system.
Definition: pcs.h:38
mpz_t q
A random prime determined during key generation.
Definition: pcs.h:40
mpz_t p
A random prime determined during key generation.
Definition: pcs.h:39
void pcs_free_private_key(pcs_private_key *vk)
Frees a pcs_private_key and all associated memory.
mpz_t n2
Precomputation: n^2.
Definition: pcs.h:32
mpz_t g
Precomputation: n + 1 usually, be 2.
Definition: pcs.h:31
mpz_t n
Precomputation: p * q.
Definition: pcs.h:47
pcs_private_key * pcs_init_private_key(void)
Initialise a pcs_private_key and return a pointer to the newly created structure. ...
Random state used by a number of cryptographic functions.
Definition: hcs_random.h:39