aboutsummaryrefslogtreecommitdiff
path: root/libcmix-crypto/elgamal/gcrypt
diff options
context:
space:
mode:
Diffstat (limited to 'libcmix-crypto/elgamal/gcrypt')
-rw-r--r--libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c30
1 files changed, 26 insertions, 4 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) {