libhcs
|
The Damgard-Jurik scheme is a scheme which provides homomorphic addition, and limited multiplication on encrypted data. More...
Go to the source code of this file.
Data Structures | |
struct | djcs_public_key |
Public key for use in the Paillier system. More... | |
struct | djcs_private_key |
Private key for use in the Paillier system. More... | |
Functions | |
djcs_public_key * | djcs_init_public_key (void) |
Initialise a djcs_public_key and return a pointer to the newly created structure. More... | |
djcs_private_key * | djcs_init_private_key (void) |
Initialise a djcs_private_key and return a pointer to the newly created structure. More... | |
int | djcs_generate_key_pair (djcs_public_key *pk, djcs_private_key *vk, hcs_random *hr, unsigned long s, unsigned long bits) |
Initialise a key pair with modulus size bits . More... | |
void | djcs_encrypt (djcs_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t plain1) |
Encrypt a value plain1 , and set rop to the encrypted result. More... | |
void | djcs_reencrypt (djcs_public_key *pk, hcs_random *hr, mpz_t rop, mpz_t op) |
Reencrypt an encrypted value op . More... | |
void | djcs_ep_add (djcs_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 . More... | |
void | djcs_ee_add (djcs_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 . More... | |
void | djcs_ep_mul (djcs_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 . More... | |
void | djcs_decrypt (djcs_private_key *vk, mpz_t rop, mpz_t cipher1) |
Decrypt a value cipher1 , and set rop to the decrypted result. More... | |
void | djcs_clear_public_key (djcs_public_key *pk) |
Clears all data in a djcs_public_key. More... | |
void | djcs_clear_private_key (djcs_private_key *vk) |
Clears all data in a djcs_private_key. More... | |
void | djcs_free_public_key (djcs_public_key *pk) |
Frees a djcs_public_key and all associated memory. More... | |
void | djcs_free_private_key (djcs_private_key *vk) |
Frees a djcs_private_key and all associated memory. More... | |
int | djcs_verify_key_pair (djcs_public_key *pk, djcs_private_key *vk) |
Check certain values shared between public and private keys to ensure they indeed are pairs. More... | |
char * | djcs_export_public_key (djcs_public_key *pk) |
Export a public key as a string. More... | |
char * | djcs_export_private_key (djcs_private_key *vk) |
Export a private key as a string. More... | |
int | djcs_import_public_key (djcs_public_key *pk, const char *json) |
Import a public key from a string. More... | |
int | djcs_import_private_key (djcs_private_key *vk, const char *json) |
Import a private key from a string. More... | |
The Damgard-Jurik scheme is a scheme which provides homomorphic addition, and limited multiplication on encrypted data.
It is a generalisation of the Paillier cryptoscheme, where the modulus n^2 is extended to n^(s+1) for s > 0.
djcs_public_key* djcs_init_public_key | ( | void | ) |
Initialise a djcs_public_key and return a pointer to the newly created structure.
djcs_private_key* djcs_init_private_key | ( | void | ) |
Initialise a djcs_private_key and return a pointer to the newly created structure.
int djcs_generate_key_pair | ( | djcs_public_key * | pk, |
djcs_private_key * | vk, | ||
hcs_random * | hr, | ||
unsigned long | s, | ||
unsigned long | bits | ||
) |
Initialise a key pair with modulus size bits
.
It is required that pk
and vk
are initialised before calling this function. pk
and vk
are expected to not be NULL.
In practice the bits
value should usually be greater than 2048 to ensure sufficient security.
Whilst s
is variable and and can be any value upto a minimum of 32 bits, beware when calling the function with large values. The modulus grows exponentially given s
, so even small values greater than 7 will incur massive performance penalties, and increase the risk of overflow (~40 million digits for the modulus for this to occur).
pk | A pointer to an initialised djcs_public_key |
vk | A pointer to an initialised djcs_private_key |
hr | A pointer to an initialised hcs_random type |
s | The size exponent for the ciphertext space we wish to work in |
bits | The number of bits for the modulus of the key |
void djcs_encrypt | ( | djcs_public_key * | pk, |
hcs_random * | hr, | ||
mpz_t | rop, | ||
mpz_t | plain1 | ||
) |
Encrypt a value plain1
, and set rop
to the encrypted result.
pk | A pointer to an initialised djcs_public_key |
hr | A pointer to an initialised hcs_random type |
rop | mpz_t where the encrypted result is stored |
plain1 | mpz_t to be encrypted |
void djcs_reencrypt | ( | djcs_public_key * | pk, |
hcs_random * | hr, | ||
mpz_t | rop, | ||
mpz_t | op | ||
) |
Reencrypt an encrypted value op
.
Upon decryption, this newly encrypted value, rop
, will retain the same value as op
.
pk | A pointer to an initialised djcs_public_key |
hr | A pointer to an initialised hcs_random type |
rop | mpz_t where the newly encrypted value is stored |
op | mpz_t to be reencrypted |
void djcs_ep_add | ( | djcs_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
.
pk | A pointer to an initialised djcs_public_key |
rop | mpz_t where the newly encrypted value is stored |
cipher1 | mpz_t to be added together |
plain1 | mpz_t to be added together |
void djcs_ee_add | ( | djcs_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
.
pk | A pointer to an initialised djcs_public_key. |
rop | mpz_t where the newly encrypted value is stored |
cipher1 | mpz_t to be added together |
cipher2 | mpz_t to be added together |
void djcs_ep_mul | ( | djcs_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
.
pk | A pointer to an initialised djcs_public_key |
rop | Where the new encrypted result is stored |
cipher1 | The encrypted value which is to be multipled to |
plain1 | The plaintext value which is to be multipled |
void djcs_decrypt | ( | djcs_private_key * | vk, |
mpz_t | rop, | ||
mpz_t | cipher1 | ||
) |
Decrypt a value cipher1
, and set rop
to the decrypted result.
rop
and cipher1
can aliases for the same mpz_t.
vk | A pointer to an initialised djcs_private_key |
rop | mpz_t where the decrypted result is stored |
cipher1 | mpz_t to be decrypted |
void djcs_clear_public_key | ( | djcs_public_key * | pk | ) |
Clears all data in a djcs_public_key.
This does not free memory in the keys, only putting it into a state whereby they can be safely used to generate new key values.
pk | A pointer to an initialised djcs_public_key |
void djcs_clear_private_key | ( | djcs_private_key * | vk | ) |
Clears all data in a djcs_private_key.
This does not free memory in the keys, only putting it into a state whereby they can be safely used to generate new key values.
vk | A pointer to an initialised djcs_private_key |
void djcs_free_public_key | ( | djcs_public_key * | pk | ) |
Frees a djcs_public_key and all associated memory.
The key memory is not zeroed, so one must call djcs_clear_public_key if it is required. one does not need to call djcs_clear_public_key before using this function.
pk | A pointer to an initialised djcs_public_key |
void djcs_free_private_key | ( | djcs_private_key * | vk | ) |
Frees a djcs_private_key and all associated memory.
The key memory is not zeroed, so one must call djcs_clear_private_key if it is required. one does not need to call djcs_clear_private_key before using this function.
vk | v pointer to an initialised djcs_private_key |
int djcs_verify_key_pair | ( | djcs_public_key * | pk, |
djcs_private_key * | vk | ||
) |
Check certain values shared between public and private keys to ensure they indeed are pairs.
This checks only the n and s values, and assumes that the caller has not altered other internal values. If the caller has only interacted with the keys through the usual functions, then this should guarantee the keys are pairs.
pk | A pointer to an initialised djcs_public_key |
vk | A pointer to an initialised djcs_private_key |
char* djcs_export_public_key | ( | djcs_public_key * | pk | ) |
Export a public key as a string.
We only store the minimum required values to restore the key. In this case, these are the s and n values.
The format these strings export as is as a JSON object.
pk | A pointer to an initialised djcs_public_key |
char* djcs_export_private_key | ( | djcs_private_key * | vk | ) |
Export a private key as a string.
We only store the minimum required values to restore the key. In this case, these are the s, n and d values. The remaining values are then computed from these on import.
vk | A pointer to an initialised djcs_private_key |
int djcs_import_public_key | ( | djcs_public_key * | pk, |
const char * | json | ||
) |
Import a public key from a string.
The input string is expected to match the format given by the export functions.
pk | A pointer to an initialised djcs_public_key |
json | A string storing the contents of a public key |
int djcs_import_private_key | ( | djcs_private_key * | vk, |
const char * | json | ||
) |
Import a private key from a string.
The input string is expected to match the format given by the export functions.
vk | A pointer to an initialised djcs_private_key |
json | A string storing the contents of a private key |