libhcs
pcs_t.h
Go to the documentation of this file.
1 
18 #ifndef HCS_PCS_T_H
19 #define HCS_PCS_T_H
20 
21 #include <gmp.h>
22 #include "hcs_random.h"
23 #include "hcs_shares.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
34 typedef struct {
35  mpz_t e[2];
36  mpz_t u[2];
37  mpz_t a[2];
38  mpz_t z[2];
39  unsigned long m1;
40  unsigned long m2;
41  mpz_t generator;
42 } pcs_t_proof;
43 
47 typedef struct {
48  unsigned long n;
49  mpz_t *coeff;
51 
55 typedef struct {
56  unsigned long i;
57  mpz_t si;
59 
65 typedef struct {
66  unsigned long w;
67  unsigned long l;
68  mpz_t n;
69  mpz_t g;
70  mpz_t n2;
71  mpz_t delta;
73 
81 typedef struct {
82  unsigned long w;
83  unsigned long l;
84  mpz_t *vi;
85  mpz_t v;
86  mpz_t d;
87  mpz_t n;
88  mpz_t n2;
89  mpz_t nm;
91 
100 
109 
144  hcs_random *hr, const unsigned long bits, const unsigned long l,
145  const unsigned long w);
146 
159 void pcs_t_encrypt_r(pcs_t_public_key *pk, mpz_t rop, mpz_t r, mpz_t plain1);
160 
173  mpz_t r, mpz_t rop, mpz_t plain1);
174 
183 void pcs_t_encrypt(pcs_t_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t plain1);
184 
194 void pcs_t_reencrypt(pcs_t_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t op);
195 
205 void pcs_t_ep_add(pcs_t_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t plain1);
206 
216 void pcs_t_ee_add(pcs_t_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t cipher2);
217 
227 void pcs_t_ep_mul(pcs_t_public_key *pk, mpz_t rop, mpz_t cipher1, mpz_t plain1);
228 
236 
245 void pcs_t_set_proof(pcs_t_proof *pf, mpz_t generator, unsigned long m1,
246  unsigned long m2);
247 
266  pcs_t_proof *pf, mpz_t cipher_m, mpz_t cipher_r, unsigned long nth_power,
267  unsigned long id);
268 
278  unsigned long id);
279 
289  mpz_t cipher, unsigned long id);
290 
296 void pcs_t_free_proof(pcs_t_proof *pf);
297 
319 
331  mpz_t rop, const unsigned long x);
332 
341 
350 
361 void pcs_t_set_auth_server(pcs_t_auth_server *au, mpz_t si, unsigned long i);
362 
375  mpz_t rop, mpz_t cipher1);
376 
395 int pcs_t_share_combine(pcs_t_public_key *vk, mpz_t rop, hcs_shares *hs);
396 
403 
412 
421 
430 
439 
449 
459 int pcs_t_import_public_key(pcs_t_public_key *pk, const char *json);
460 
469 
478 
487 int pcs_t_import_auth_server(pcs_t_auth_server *au, const char *json);
488 
504 
517 int pcs_t_import_verify_values(pcs_t_private_key *vk, const char *json);
518 
519 #ifdef __cplusplus
520 }
521 #endif
522 
523 #endif
mpz_t d
d = 0 mod m and d = 1 mod n^2
Definition: pcs_t.h:86
void pcs_t_free_proof(pcs_t_proof *pf)
Frees a pcs_t proof object and all values associated with it.
unsigned long w
The number of servers req to successfully decrypt.
Definition: pcs_t.h:66
Provides secure random state for use in functions which require random values.
void pcs_t_free_auth_server(pcs_t_auth_server *au)
Frees a pcs_t_auth_server and all associated memory.
This is a structure which is designed to hold a number of shares.
void pcs_t_set_proof(pcs_t_proof *pf, mpz_t generator, unsigned long m1, unsigned long m2)
Set a proof object's value to check for.
mpz_t generator
Value of generator (base) in 1of2 protocol.
Definition: pcs_t.h:41
void pcs_t_compute_1of2_ns_protocol(pcs_t_public_key *pk, hcs_random *hr, pcs_t_proof *pf, mpz_t cipher_m, mpz_t cipher_r, unsigned long nth_power, unsigned long id)
Compute a proof for a particular value ciper_m, and an id.
pcs_t_auth_server * pcs_t_init_auth_server(void)
Initialise a pcs_t_auth_server and return a pointer to the newly created structure.
unsigned long i
The server index in the particular instance.
Definition: pcs_t.h:56
void pcs_t_set_auth_server(pcs_t_auth_server *au, mpz_t si, unsigned long i)
Set the internal values for the server au.
unsigned long m2
Value of second power for 1of2 protocol.
Definition: pcs_t.h:40
void pcs_t_encrypt_r(pcs_t_public_key *pk, mpz_t rop, mpz_t r, mpz_t plain1)
Encrypt a value plain1, and set rop to the encryted result.
void pcs_t_clear_private_key(pcs_t_private_key *vk)
Clears all data in a pcs_t_private_key.
Private key for use in the Threshold Paillier system.
Definition: pcs_t.h:81
Stores a number of shares, with flags indicating if they are currently to be counted.
Definition: hcs_shares.h:26
unsigned long l
The number of decryption servers.
Definition: pcs_t.h:67
void pcs_t_compute_polynomial(pcs_t_private_key *vk, pcs_t_polynomial *px, mpz_t rop, const unsigned long x)
Compute a polynomial P(x) for a given x value in the required finite field.
void pcs_t_ep_add(pcs_t_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...
unsigned long n
The number of terms in the polynomial.
Definition: pcs_t.h:48
pcs_t_proof * pcs_t_init_proof(void)
Allocate and initialise the values in a pcs_t_proof object.
void pcs_t_encrypt(pcs_t_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t plain1)
Encrypt a value plain1, and set rop to the encrypted result.
pcs_t_private_key * pcs_t_init_private_key(void)
Initialise a pcs_t_private_key and return a pointer to the newly created structure.
mpz_t n
Modulus of the key: p * q.
Definition: pcs_t.h:87
int pcs_t_import_auth_server(pcs_t_auth_server *au, const char *json)
Import an auth server from a json string.
mpz_t nm
Precomputation: n * m.
Definition: pcs_t.h:89
void pcs_t_ep_mul(pcs_t_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 si
The polynomial evaluation at i.
Definition: pcs_t.h:57
mpz_t v
Cyclic generator of squares in Z*n^2.
Definition: pcs_t.h:85
void pcs_t_ee_add(pcs_t_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...
mpz_t n2
Precomputation: n^2.
Definition: pcs_t.h:88
int pcs_t_import_public_key(pcs_t_public_key *pk, const char *json)
Import a public key from a json string.
int pcs_t_verify_ns_protocol(pcs_t_public_key *pk, pcs_t_proof *pf, unsigned long id)
Verify a proof and return whether it is an n'th power.
mpz_t n
Modulus of the key.
Definition: pcs_t.h:68
void pcs_t_reencrypt(pcs_t_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t op)
Reencrypt an encrypted value cipher1.
char * pcs_t_export_public_key(pcs_t_public_key *pk)
Export a public key from as a json string.
mpz_t g
Precomputation: n + 1.
Definition: pcs_t.h:69
mpz_t delta
Precomputation: l!
Definition: pcs_t.h:71
void pcs_t_r_encrypt(pcs_t_public_key *pk, hcs_random *hr, mpz_t r, mpz_t rop, mpz_t plain1)
Encrypt a value plain1, and set rop to the encrypted result.
int pcs_t_verify_1of2_ns_protocol(pcs_t_public_key *pk, pcs_t_proof *pf, mpz_t cipher, unsigned long id)
Compute the value for an n^s protocol, limited to 1 of 2 values.
unsigned long l
The number of decryption servers in total.
Definition: pcs_t.h:83
char * pcs_t_export_auth_server(pcs_t_auth_server *au)
Export an auth server as a json string.
void pcs_t_free_private_key(pcs_t_private_key *vk)
Frees a pcs_t_private_key and all associated memory.
int pcs_t_generate_key_pair(pcs_t_public_key *pk, pcs_t_private_key *vk, hcs_random *hr, const unsigned long bits, const unsigned long l, const unsigned long w)
Initialise a key pair with modulus size bits.
mpz_t n2
Precomputation: n^2.
Definition: pcs_t.h:70
int pcs_t_import_verify_values(pcs_t_private_key *vk, const char *json)
Import an array of verification values stored in a json string.
int pcs_t_verify_key_pair(pcs_t_public_key *pk, pcs_t_private_key *vk)
Sanity check to quickly determine if pk and vk refer to the same values and are compatible.
pcs_t_polynomial * pcs_t_init_polynomial(pcs_t_private_key *vk, hcs_random *hr)
Allocate and initialise the values in a random polynomial.
char * pcs_t_export_verify_values(pcs_t_private_key *vk)
Export an array of verification values corresponding to each server as a json array.
Stores data pertaining to the usage of proof computation and verification.
Definition: pcs_t.h:34
Details of the polynomial used to compute values for decryption servers.
Definition: pcs_t.h:47
int pcs_t_share_combine(pcs_t_public_key *vk, mpz_t rop, hcs_shares *hs)
Combine an array of shares c, storing the result in rop.
unsigned long w
The number of servers req to decrypt.
Definition: pcs_t.h:82
void pcs_t_share_decrypt(pcs_t_public_key *vk, pcs_t_auth_server *au, mpz_t rop, mpz_t cipher1)
For a given ciphertext cipher1, compute the server au's share and store the result in the variable ro...
unsigned long m1
Value of first power for 1of2 protocol.
Definition: pcs_t.h:39
void pcs_t_free_public_key(pcs_t_public_key *pk)
Frees a pcs_t_public_key and all associated memory.
void pcs_t_free_polynomial(pcs_t_polynomial *px)
Frees a given polynomial (array of mpz_t values) and all associated data.
void pcs_t_clear_public_key(pcs_t_public_key *pk)
Clears all data in a pcs_t_public_key.
Public key for use in the Threshold Paillier system.
Definition: pcs_t.h:65
mpz_t * vi
Verification values for the decryption servers.
Definition: pcs_t.h:84
Details that a decryption server is required to keep track of.
Definition: pcs_t.h:55
pcs_t_public_key * pcs_t_init_public_key(void)
Initialise a pcs_t_public_key and return a pointer to the newly created structure.
Random state used by a number of cryptographic functions.
Definition: hcs_random.h:39
mpz_t * coeff
Coefficients of the polynomial.
Definition: pcs_t.h:49