mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-12 18:49:07 +00:00
add define for RFC6979
This commit is contained in:
parent
678e5b1af2
commit
f87e706407
18
ecdsa.c
18
ecdsa.c
@ -144,9 +144,9 @@ int generate_k_random(bignum256 *k) {
|
||||
}
|
||||
k->val[8] = random32() & 0xFFFF;
|
||||
// if k is too big or too small, we don't like it
|
||||
if (k->val[5] == 0x3FFFFFFF && k->val[6] == 0x3FFFFFFF && k->val[7] == 0x3FFFFFFF && k->val[8] == 0xFFFF) continue;
|
||||
if (k->val[5] == 0x0 && k->val[6] == 0x0 && k->val[7] == 0x0 && k->val[8] == 0x0) continue;
|
||||
return 0; // good number - no error
|
||||
if ( !bn_is_zero(k) && bn_is_less(k, &order256k1) ) {
|
||||
return 0; // good number - no error
|
||||
}
|
||||
}
|
||||
// we generated 10000 numbers, none of them is good -> fail
|
||||
return 1;
|
||||
@ -214,15 +214,17 @@ int ecdsa_sign(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, ui
|
||||
|
||||
bn_read_be(hash, &z);
|
||||
|
||||
// generate random number k
|
||||
//if (generate_k_random(&k) != 0) {
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
#if USE_RFC6979
|
||||
// generate K deterministically
|
||||
if (generate_k_rfc6979(&k, priv_key, hash) != 0) {
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
// generate random number k
|
||||
if (generate_k_random(&k) != 0) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute k*G
|
||||
scalar_multiply(&k, &R);
|
||||
|
4
ecdsa.h
4
ecdsa.h
@ -28,6 +28,10 @@
|
||||
|
||||
#include "secp256k1.h"
|
||||
|
||||
#ifndef USE_RFC6979
|
||||
#define USE_RFC6979 1
|
||||
#endif
|
||||
|
||||
// all functions use secp256k1 curve
|
||||
int ecdsa_sign(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, uint8_t *sig);
|
||||
void ecdsa_get_public_key33(const uint8_t *priv_key, uint8_t *pub_key);
|
||||
|
Loading…
Reference in New Issue
Block a user