libhcs
Data Structures | Functions
egcs.h File Reference

The ElGamal scheme is a scheme which provides homormophic multiplication. More...

#include <gmp.h>
#include "hcs_random.h"
Include dependency graph for egcs.h:

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_keyegcs_init_public_key (void)
 Initialise a egcs_public_key and return a pointer to the newly created structure. More...
 
egcs_private_keyegcs_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_cipheregcs_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...
 

Detailed Description

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.

Function Documentation

egcs_public_key* egcs_init_public_key ( void  )

Initialise a egcs_public_key and return a pointer to the newly created structure.

Returns
A pointer to an initialised egcs_public_key, NULL on allocation failure
egcs_private_key* egcs_init_private_key ( void  )

Initialise a egcs_private_key and return a pointer to the newly created structure.

Returns
A pointer to an initialised egcs_private_key, NULL on allocation failure
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.

Parameters
pkA pointer to an initialised egcs_public_key
vkA pointer to an initialised egcs_private_key
hrA pointer to an initialised hcs_random type
bitsThe 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.

Returns
A pointer to an initialised egcs_cipher, NULL on allocation failure
void egcs_set ( egcs_cipher rop,
egcs_cipher op 
)

Copy value of op to rop.

Parameters
ropA pointer to an initialised egcs_cipher
opA 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.

Parameters
pkA pointer to an initialised egcs_public_key
hrA pointer to an initialised hcs_random type
ropegcs_cipher where the result is to be stored
plain1mpz_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.

Parameters
pkA pointer to an initialised egcs_public_key
ropegcs_cipher where the result is to be stored
ct1egcs_cipher to be multiplied together
ct2egcs_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.

Parameters
vkA pointer to an initialised egcs_private_key
ropmpz_t where the decrypted result is stored
cipher1egcs_cipher to be decrypted
void egcs_clear_cipher ( egcs_cipher ct)

Zero all data related to the given egcs_cipher.

Parameters
ctA pointer to an initialised egcs_cipher
void egcs_free_cipher ( egcs_cipher ct)

Free all associated memory with a given egcs_cipher.

Parameters
ctA 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.

Parameters
pkA 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.

Parameters
vkA 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.

Parameters
pkA 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.

Parameters
vkA pointer to an initialised egcs_private_key