Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: use cose_crypt_get_random #128

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion makefiles/c25519.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion makefiles/hacl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion makefiles/monocypher.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/crypt/c25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 */
3 changes: 2 additions & 1 deletion src/crypt/hacl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 0 additions & 18 deletions src/crypt/helpers.c

This file was deleted.

6 changes: 4 additions & 2 deletions src/crypt/monocypher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down