From ea5886026fac93f2a7544f425fa0480d6e896220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Wed, 26 Jan 2022 18:49:24 +0100 Subject: [PATCH] refactor(crypto,legacy): extend parameters of init_rfc6979 by curve --- crypto/ecdsa.c | 2 +- crypto/rfc6979.c | 2 +- crypto/rfc6979.h | 2 +- crypto/tests/test_check.c | 4 ++-- legacy/firmware/fsm_msg_crypto.h | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c index 1f6f378ee..f9ff33faf 100644 --- a/crypto/ecdsa.c +++ b/crypto/ecdsa.c @@ -687,7 +687,7 @@ int ecdsa_sign_digest(const ecdsa_curve *curve, const uint8_t *priv_key, #if USE_RFC6979 rfc6979_state rng = {0}; - init_rfc6979(priv_key, digest, &rng); + init_rfc6979(priv_key, digest, curve, &rng); #endif bn_read_be(digest, &z); diff --git a/crypto/rfc6979.c b/crypto/rfc6979.c index bb4051264..634da0569 100644 --- a/crypto/rfc6979.c +++ b/crypto/rfc6979.c @@ -27,7 +27,7 @@ #include "memzero.h" void init_rfc6979(const uint8_t *priv_key, const uint8_t *hash, - rfc6979_state *state) { + const ecdsa_curve *curve, rfc6979_state *state) { hmac_drbg_init(state, priv_key, 32, hash, 32); } diff --git a/crypto/rfc6979.h b/crypto/rfc6979.h index 3e4095350..de253f453 100644 --- a/crypto/rfc6979.h +++ b/crypto/rfc6979.h @@ -33,7 +33,7 @@ typedef HMAC_DRBG_CTX rfc6979_state; void init_rfc6979(const uint8_t *priv_key, const uint8_t *hash, - rfc6979_state *rng); + const ecdsa_curve *curve, rfc6979_state *rng); void generate_rfc6979(uint8_t rnd[32], rfc6979_state *rng); void generate_k_rfc6979(bignum256 *k, rfc6979_state *rng); diff --git a/crypto/tests/test_check.c b/crypto/tests/test_check.c index 79ceca2bc..b75dbb679 100644 --- a/crypto/tests/test_check.c +++ b/crypto/tests/test_check.c @@ -3757,7 +3757,7 @@ END_TEST #define test_deterministic(KEY, MSG, K) \ do { \ sha256_Raw((uint8_t *)MSG, strlen(MSG), buf); \ - init_rfc6979(fromhex(KEY), buf, &rng); \ + init_rfc6979(fromhex(KEY), buf, NULL, &rng); \ generate_k_rfc6979(&k, &rng); \ bn_write_be(&k, buf); \ ck_assert_mem_eq(buf, fromhex(K), 32); \ @@ -6790,7 +6790,7 @@ START_TEST(test_ed25519_cosi) { "26c76712d89d906e6672dafa614c42e5cb1caac8c6568e4d2493087db51f0d36"), fromhex( "26659c1cf7321c178c07437150639ff0c5b7679c7ea195253ed9abda2e081a37"), - &rng); + NULL, &rng); for (int N = 1; N < 11; N++) { ed25519_public_key pk; diff --git a/legacy/firmware/fsm_msg_crypto.h b/legacy/firmware/fsm_msg_crypto.h index da9e76cd4..5e2b8df9e 100644 --- a/legacy/firmware/fsm_msg_crypto.h +++ b/legacy/firmware/fsm_msg_crypto.h @@ -259,7 +259,7 @@ void fsm_msgCosiCommit(const CosiCommit *msg) { uint8_t nonce[32]; sha256_Raw(msg->data.bytes, msg->data.size, nonce); rfc6979_state rng; - init_rfc6979(node->private_key, nonce, &rng); + init_rfc6979(node->private_key, nonce, NULL, &rng); generate_rfc6979(nonce, &rng); resp->has_commitment = true; @@ -302,7 +302,7 @@ void fsm_msgCosiSign(const CosiSign *msg) { uint8_t nonce[32]; sha256_Raw(msg->data.bytes, msg->data.size, nonce); rfc6979_state rng; - init_rfc6979(node->private_key, nonce, &rng); + init_rfc6979(node->private_key, nonce, NULL, &rng); generate_rfc6979(nonce, &rng); resp->signature.size = 32;