diff --git a/makefiles/c25519.mk b/makefiles/c25519.mk index ae3c7ec..57bcd05 100644 --- a/makefiles/c25519.mk +++ b/makefiles/c25519.mk @@ -1,7 +1,6 @@ C25519_DIR ?= ../c25519 CFLAGS+=-DCRYPTO_C25519 -I../c25519/src CRYPTOSRC=$(SRC_DIR)/crypt/c25519.c -CRYPTOSRC+=$(SRC_DIR)/crypt/helpers.c CFLAGS_CRYPTO += -I$(C25519_DIR)/src CRYPTOOBJS+=$(C25519_DIR)/src/edsign.o CRYPTOOBJS+=$(C25519_DIR)/src/ed25519.o diff --git a/makefiles/hacl.mk b/makefiles/hacl.mk index b4e01e8..10ca9f1 100644 --- a/makefiles/hacl.mk +++ b/makefiles/hacl.mk @@ -2,6 +2,5 @@ HACL_DIR ?= ../hacl-c CFLAGS+=-DCRYPTO_HACL HACLLIB=hacl CRYPTOSRC += $(SRC_DIR)/crypt/hacl.c -CRYPTOSRC += $(SRC_DIR)/crypt/helpers.c CFLAGS_CRYPTO += -I$(HACL_DIR) LDFLAGS_CRYPTO += -Wl,$(HACL_DIR)/libhacl.so diff --git a/makefiles/monocypher.mk b/makefiles/monocypher.mk index 135f48a..f9ea19a 100644 --- a/makefiles/monocypher.mk +++ b/makefiles/monocypher.mk @@ -1,7 +1,6 @@ MONOCYPHERLIB=monocypher CFLAGS +=-DCRYPTO_MONOCYPHER -DED25519_SHA512 -CRYPTOSRC +=$(SRC_DIR)/crypt/helpers.c CRYPTOSRC +=$(SRC_DIR)/crypt/monocypher.c MONOCYPHER_DIR ?= $(PWD)/../Monocypher diff --git a/src/crypt/c25519.c b/src/crypt/c25519.c index a6293a7..8dc9a90 100644 --- a/src/crypt/c25519.c +++ b/src/crypt/c25519.c @@ -18,7 +18,9 @@ #include "cose/crypto/c25519.h" #include "cose/crypto/selectors.h" -extern void randombytes(uint8_t *target, uint64_t n); + +extern cose_crypt_rng cose_crypt_get_random; +extern void *cose_crypt_rng_arg; #ifdef CRYPTO_C25519_INCLUDE_ED25519 int cose_crypto_sign_ed25519(const cose_key_t *key, uint8_t *sign, size_t *signlen, uint8_t *msg, unsigned long long int msglen) @@ -38,7 +40,7 @@ int cose_crypto_verify_ed25519(const cose_key_t *key, const uint8_t *sign, size_ void cose_crypto_keypair_ed25519(cose_key_t *key) { - randombytes(key->d, EDSIGN_SECRET_KEY_SIZE); + cose_crypt_get_random(cose_crypt_rng_arg, key->d, EDSIGN_SECRET_KEY_SIZE); edsign_sec_to_pub(key->x, key->d); } #endif /* CRYPTO_C25519_INCLUDE_ED25519 */ diff --git a/src/crypt/hacl.c b/src/crypt/hacl.c index 0d320cf..7908d54 100644 --- a/src/crypt/hacl.c +++ b/src/crypt/hacl.c @@ -22,7 +22,8 @@ extern void Hacl_Ed25519_sign(uint8_t *signature, uint8_t *secret, uint8_t *msg, uint32_t len1); extern bool Hacl_Ed25519_verify(uint8_t *public, uint8_t *msg, uint32_t len1, uint8_t *signature); -extern void randombytes(uint8_t *target, uint64_t n); +extern cose_crypt_rng cose_crypt_get_random; +extern void *cose_crypt_rng_arg; #ifdef CRYPTO_HACL_INCLUDE_CHACHAPOLY int cose_crypto_aead_encrypt_chachapoly(uint8_t *c, diff --git a/src/crypt/helpers.c b/src/crypt/helpers.c deleted file mode 100644 index b79c764..0000000 --- a/src/crypt/helpers.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2018 Freie Universitat Berlin - * Copyright (C) 2018 Inria - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -#include -#include - -void randombytes(uint8_t *target, uint64_t n) -{ - for(uint64_t i = 0; i < n; i++) { - target[i] = rand() % 256; - } -} diff --git a/src/crypt/monocypher.c b/src/crypt/monocypher.c index 57cd5ed..154c97e 100644 --- a/src/crypt/monocypher.c +++ b/src/crypt/monocypher.c @@ -19,7 +19,9 @@ #include "cose/crypto.h" #include "cose/crypto/selectors.h" -extern void randombytes(uint8_t *target, uint64_t n); + +extern cose_crypt_rng cose_crypt_get_random; +extern void *cose_crypt_rng_arg; static const uint8_t zero[32] = { 0 }; #ifdef CRYPTO_MONOCYPHER_INCLUDE_CHACHAPOLY @@ -128,7 +130,7 @@ static void _ed25519_clamp(uint8_t *key) void cose_crypto_keypair_ed25519(cose_key_t *key) { - randombytes(key->d, COSE_CRYPTO_SIGN_ED25519_SECRETKEYBYTES); + cose_crypt_get_random(cose_crypt_rng_arg, key->d, COSE_CRYPTO_SIGN_ED25519_SECRETKEYBYTES); _ed25519_clamp(key->d); crypto_ed25519_public_key(key->x, key->d); }