diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2017-04-02 17:47:51 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2017-04-02 17:48:58 +0200 |
| commit | d680f8d3848cbc3adf7d6b2c49e10abc4499cfca (patch) | |
| tree | f0ed54f1551bfa9639160354ee542c13bcc404bb | |
| parent | 44273a12096fe99a847c53480847f90f15622624 (diff) | |
| download | cmix-d680f8d3848cbc3adf7d6b2c49e10abc4499cfca.tar.gz cmix-d680f8d3848cbc3adf7d6b2c49e10abc4499cfca.tar.bz2 cmix-d680f8d3848cbc3adf7d6b2c49e10abc4499cfca.zip | |
Fixes a rare bug in the Elgamal implementation.
| -rw-r--r-- | libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c | 30 | ||||
| -rwxr-xr-x | run.sh | 6 |
2 files changed, 29 insertions, 7 deletions
diff --git a/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c b/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c index 4e6115c..8f8019a 100644 --- a/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c +++ b/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c @@ -5,6 +5,7 @@ #include <stddef.h> #include <stdbool.h> +#include <stdlib.h> #ifdef POINTER_TRACING #define TRACE(FILE, LINE, PTR) \ @@ -18,6 +19,7 @@ static gcry_mpi_t q; static gcry_mpi_t g; static const unsigned int nr_bytes = 256; static const unsigned int nr_bits = 256*8; +static const unsigned int message_size = nr_bytes-1; void check(gcry_error_t error) { if (error) { @@ -48,7 +50,7 @@ void gcrypt_elgamal_initialize(void) { } gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); - gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); + gcry_control (GCRYCTL_INIT_SECMEM, 1048576, 0); gcry_control (GCRYCTL_RESUME_SECMEM_WARN); gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); @@ -122,7 +124,16 @@ void gcrypt_elgamal_delete_keypair(struct KeyPair* pair) { void gcrypt_elgamal_element_to_array(unsigned char** buffer, size_t* len, void* key) { gcry_error_t error; - error = gcry_mpi_aprint(GCRYMPI_FMT_USG, buffer, len, (gcry_mpi_t) key); + + unsigned char* temp; + error = gcry_mpi_aprint(GCRYMPI_FMT_USG, &temp, len, (gcry_mpi_t) key); + + *buffer = (unsigned char*) calloc(nr_bytes, sizeof(unsigned char)); + + memcpy((*buffer) + (nr_bytes - *len), temp, *len); + *len = nr_bytes; + gcry_free(temp); + TRACE(__FILE__, __LINE__, *buffer); check(error); } @@ -150,8 +161,19 @@ GroupElement gcrypt_elgamal_message_to_element(char const* buffer, size_t len, b } void gcrypt_elgamal_element_to_message(unsigned char** buffer, GroupElement el) { + gcry_error_t error; + size_t len; - gcrypt_elgamal_element_to_array(buffer, &len, el); + unsigned char* temp; + error = gcry_mpi_aprint(GCRYMPI_FMT_USG, &temp, &len, (gcry_mpi_t) el); + + *buffer = (unsigned char*) calloc(message_size, sizeof(unsigned char)); + + memcpy((*buffer) + (message_size - len), temp, len); + gcry_free(temp); + + TRACE(__FILE__, __LINE__, *buffer); + check(error); } void gcrypt_elgamal_get_pub_key_hash(char** buffer, size_t* len, GroupElement const pub) { @@ -238,7 +260,7 @@ size_t gcrypt_elgamal_get_group_element_array_size() { } size_t gcrypt_elgamal_get_message_size() { - return nr_bytes - 1; + return message_size; } void gcrypt_elgamal_delete_group_element(void* el) { @@ -1,7 +1,7 @@ #!/bin/bash -#build_dir=/home/dennis/projects/cmix/build-cmix-Desktop-Debug -build_dir=/home/dbrentje/projects/cmix/build +build_dir=/home/dennis/projects/cmix/build-cmix-Desktop-Debug +#build_dir=/home/dbrentje/projects/cmix/build if [ $# == 0 ] ; then tool="" @@ -17,7 +17,7 @@ else tool="" fi -nr_clients=1 +nr_clients=500 tmux new-session -s cmix -d |
