libhcs
|
The ElGamal scheme is a scheme which provides homormophic multiplication. More...
Go to the source code of this file.
Data Structures | |
struct | egcs_cipher |
Ciphertext type for use in the ElGamal scheme. More... | |
struct | egcs_public_key |
Public key for use in the ElGamal scheme. More... | |
struct | egcs_private_key |
Private key for use in the ElGamal scheme. More... | |
Functions | |
egcs_public_key * | egcs_init_public_key (void) |
Initialise a egcs_public_key and return a pointer to the newly created structure. More... | |
egcs_private_key * | egcs_init_private_key (void) |
Initialise a egcs_private_key and return a pointer to the newly created structure. More... | |
void | egcs_generate_key_pair (egcs_public_key *pk, egcs_private_key *vk, hcs_random *hr, const unsigned long bits) |
Initialise a key pair with modulus size bits . More... | |
egcs_cipher * | egcs_init_cipher (void) |
Initialise a egcs_cipher and return a pointer to the newly created structure. More... | |
void | egcs_set (egcs_cipher *rop, egcs_cipher *op) |
Copy value of op to rop. More... | |
void | egcs_encrypt (egcs_public_key *pk, hcs_random *hr, egcs_cipher *rop, mpz_t plain1) |
Encrypt a value plain1 , and set rop to the encrypted result. More... | |
void | egcs_ee_mul (egcs_public_key *pk, egcs_cipher *rop, egcs_cipher *ct1, egcs_cipher *ct2) |
Multiply an encrypted value ct1 with an encrypted value ct2 , storing the result in rop . More... | |
void | egcs_decrypt (egcs_private_key *vk, mpz_t rop, egcs_cipher *cipher1) |
Decrypt a value cipher1 , and set rop to the decrypted result. More... | |
void | egcs_clear_cipher (egcs_cipher *ct) |
Zero all data related to the given egcs_cipher. More... | |
void | egcs_free_cipher (egcs_cipher *ct) |
Free all associated memory with a given egcs_cipher. More... | |
void | egcs_clear_public_key (egcs_public_key *pk) |
Zero all memory associated with a egcs_public_key. More... | |
void | egcs_clear_private_key (egcs_private_key *vk) |
Zero all memory associated with a egcs_private_key. More... | |
void | egcs_free_public_key (egcs_public_key *pk) |
Frees a egcs_public_key and all associated memory. More... | |
void | egcs_free_private_key (egcs_private_key *vk) |
Frees a egcs_private_key and all associated memory. More... | |
The ElGamal scheme is a scheme which provides homormophic multiplication.
It is usually used with some padding scheme similar to RSA. This implementation only provides unpadded values to exploit this property.
Due to the nature of the ciphertext, this implementation provides a unique type for the ciphertext, rather than just using gmp mpz_t types. These can be used with the provided initialisation functions, and should be freed on program termination.
All mpz_t values can be alises unless otherwise stated.
egcs_public_key* egcs_init_public_key | ( | void | ) |
Initialise a egcs_public_key and return a pointer to the newly created structure.
egcs_private_key* egcs_init_private_key | ( | void | ) |
Initialise a egcs_private_key and return a pointer to the newly created structure.
void egcs_generate_key_pair | ( | egcs_public_key * | pk, |
egcs_private_key * | vk, | ||
hcs_random * | hr, | ||
const 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.
pk | A pointer to an initialised egcs_public_key |
vk | A pointer to an initialised egcs_private_key |
hr | A pointer to an initialised hcs_random type |
bits | The number of bits for the modulus of the key |
egcs_cipher* egcs_init_cipher | ( | void | ) |
Initialise a egcs_cipher and return a pointer to the newly created structure.
void egcs_set | ( | egcs_cipher * | rop, |
egcs_cipher * | op | ||
) |
Copy value of op to rop.
rop | A pointer to an initialised egcs_cipher |
op | A pointer to an initialised egcs_cipher |
void egcs_encrypt | ( | egcs_public_key * | pk, |
hcs_random * | hr, | ||
egcs_cipher * | rop, | ||
mpz_t | plain1 | ||
) |
Encrypt a value plain1
, and set rop
to the encrypted result.
pk | A pointer to an initialised egcs_public_key |
hr | A pointer to an initialised hcs_random type |
rop | egcs_cipher where the result is to be stored |
plain1 | mpz_t to be encrypted |
void egcs_ee_mul | ( | egcs_public_key * | pk, |
egcs_cipher * | rop, | ||
egcs_cipher * | ct1, | ||
egcs_cipher * | ct2 | ||
) |
Multiply an encrypted value ct1
with an encrypted value ct2
, storing the result in rop
.
pk | A pointer to an initialised egcs_public_key |
rop | egcs_cipher where the result is to be stored |
ct1 | egcs_cipher to be multiplied together |
ct2 | egcs_cipher to be multiplied together |
void egcs_decrypt | ( | egcs_private_key * | vk, |
mpz_t | rop, | ||
egcs_cipher * | cipher1 | ||
) |
Decrypt a value cipher1
, and set rop
to the decrypted result.
vk | A pointer to an initialised egcs_private_key |
rop | mpz_t where the decrypted result is stored |
cipher1 | egcs_cipher to be decrypted |
void egcs_clear_cipher | ( | egcs_cipher * | ct | ) |
Zero all data related to the given egcs_cipher.
ct | A pointer to an initialised egcs_cipher |
void egcs_free_cipher | ( | egcs_cipher * | ct | ) |
Free all associated memory with a given egcs_cipher.
ct | A pointer to an initialised egcs_cipher |
void egcs_clear_public_key | ( | egcs_public_key * | pk | ) |
Zero all memory associated with a egcs_public_key.
This does not free the memory, so the key is safe to use immediately after calling this.
pk | A pointer to an initialised egcs_public_key |
void egcs_clear_private_key | ( | egcs_private_key * | vk | ) |
Zero all memory associated with a egcs_private_key.
This does not free the memory, so the key is safe to use immediately after calling this.
vk | A pointer to an initialised egcs_private_key |
void egcs_free_public_key | ( | egcs_public_key * | pk | ) |
Frees a egcs_public_key and all associated memory.
pk | A pointer to an initialised egcs_public_key |
void egcs_free_private_key | ( | egcs_private_key * | vk | ) |
Frees a egcs_private_key and all associated memory.
vk | A pointer to an initialised egcs_private_key |