Skip to content

Commit

Permalink
treewide: use cose_crypt_get_random
Browse files Browse the repository at this point in the history
  • Loading branch information
fjmolinas committed Apr 25, 2022
1 parent 702a4a0 commit 29100ac
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"files.associations": {
"*Makefile.*": "makefile",
"*.mk.*": "makefile",
"*makefile*": "makefile",
"*.sls": "yaml",
"selectors.h": "c"
}
}
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

0 comments on commit 29100ac

Please sign in to comment.