1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

add define for RFC6979

This commit is contained in:
Pavol Rusnak 2013-10-03 18:19:30 +02:00
parent 678e5b1af2
commit f87e706407
2 changed files with 14 additions and 8 deletions

16
ecdsa.c
View File

@ -144,10 +144,10 @@ int generate_k_random(bignum256 *k) {
} }
k->val[8] = random32() & 0xFFFF; k->val[8] = random32() & 0xFFFF;
// if k is too big or too small, we don't like it // 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 ( !bn_is_zero(k) && bn_is_less(k, &order256k1) ) {
if (k->val[5] == 0x0 && k->val[6] == 0x0 && k->val[7] == 0x0 && k->val[8] == 0x0) continue;
return 0; // good number - no error return 0; // good number - no error
} }
}
// we generated 10000 numbers, none of them is good -> fail // we generated 10000 numbers, none of them is good -> fail
return 1; 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); bn_read_be(hash, &z);
// generate random number k #if USE_RFC6979
//if (generate_k_random(&k) != 0) {
// return 1;
//}
// generate K deterministically // generate K deterministically
if (generate_k_rfc6979(&k, priv_key, hash) != 0) { if (generate_k_rfc6979(&k, priv_key, hash) != 0) {
return 1; return 1;
} }
#else
// generate random number k
if (generate_k_random(&k) != 0) {
return 1;
}
#endif
// compute k*G // compute k*G
scalar_multiply(&k, &R); scalar_multiply(&k, &R);

View File

@ -28,6 +28,10 @@
#include "secp256k1.h" #include "secp256k1.h"
#ifndef USE_RFC6979
#define USE_RFC6979 1
#endif
// all functions use secp256k1 curve // all functions use secp256k1 curve
int ecdsa_sign(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, uint8_t *sig); 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); void ecdsa_get_public_key33(const uint8_t *priv_key, uint8_t *pub_key);