diff options
Diffstat (limited to 'libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c')
| -rw-r--r-- | libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c b/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c index 4839ce5..8807282 100644 --- a/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c +++ b/libcmix-crypto/ed25519/gcrypt/gcrypt_ed25519.c @@ -154,7 +154,7 @@ GroupElement DEF(message_to_element)(char const* buffer, size_t len, bool secure (void) secure; gcry_error_t error; - //assert(len == 31); + assert(len == 31); gcry_mpi_t mpi; gcry_mpi_scan(&mpi, GCRYMPI_FMT_USG, buffer, len, NULL); @@ -167,11 +167,16 @@ GroupElement DEF(message_to_element)(char const* buffer, size_t len, bool secure unsigned int count = 0; do { encoded_point[0] = 0x40; - - unsigned int byte_size = (unsigned) ceil(gcry_mpi_get_nbits(mpi) / 8.0); - //gcry_mpi_print(GCRYMPI_FMT_USG, (unsigned char*) encoded_point + 1 + (32 - byte_size), byte_size, NULL, mpi); - gcry_mpi_print(GCRYMPI_FMT_USG, (unsigned char*) encoded_point + 1, 32, NULL, mpi); + memset(encoded_point + 1, '\0', 32); + unsigned char* gcry_buffer; + size_t nr_written; + + gcry_mpi_aprint(GCRYMPI_FMT_USG, &gcry_buffer, &nr_written, mpi); + + memcpy(encoded_point + 1 + (nr_bytes - nr_written), gcry_buffer, nr_written); + gcry_free(gcry_buffer); + for(int i = 0; i < 16; i++) { char temp = encoded_point[i+1]; encoded_point[i+1] = encoded_point[32-i]; @@ -222,7 +227,7 @@ void DEF(element_to_message)(unsigned char** buffer, const GroupElement el) { size_t nr_written; gcry_mpi_aprint(GCRYMPI_FMT_USG, &buffer2, &nr_written, y); - memcpy(*buffer, buffer2, mes_len); + memcpy(*buffer + (mes_len - nr_written), buffer2, nr_written); gcry_free(buffer2); gcry_mpi_release(y); |
