1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

normalize y^2 in pubkey validation

fix last commit
This commit is contained in:
Pavol Rusnak 2014-07-07 21:11:25 +02:00
parent b9d5896174
commit 0fe1857513
2 changed files with 5 additions and 4 deletions

View File

@ -459,7 +459,7 @@ int ecdsa_read_pubkey(const uint8_t *pub_key, curve_point *pub)
if (pub_key[0] == 0x04) {
bn_read_be(pub_key + 1, &(pub->x));
bn_read_be(pub_key + 33, &(pub->y));
#ifdef USE_PUBKEY_VALIDATE
#if USE_PUBKEY_VALIDATE
return ecdsa_validate_pubkey(pub);
#else
return 1;
@ -468,7 +468,7 @@ int ecdsa_read_pubkey(const uint8_t *pub_key, curve_point *pub)
if (pub_key[0] == 0x02 || pub_key[0] == 0x03) { // compute missing y coords
bn_read_be(pub_key + 1, &(pub->x));
uncompress_coords(pub_key[0], &(pub->x), &(pub->y));
#ifdef USE_PUBKEY_VALIDATE
#if USE_PUBKEY_VALIDATE
return ecdsa_validate_pubkey(pub);
#else
return 1;
@ -502,6 +502,8 @@ int ecdsa_validate_pubkey(const curve_point *pub)
// y^2
bn_multiply(&(pub->y), &y_2, &prime256k1);
bn_mod(&y_2, &prime256k1);
// x^3 + b
bn_multiply(&(pub->x), &x_3_b, &prime256k1);
bn_multiply(&(pub->x), &x_3_b, &prime256k1);
@ -542,7 +544,6 @@ int ecdsa_verify_double(const uint8_t *pub_key, const uint8_t *sig, const uint8_
}
// returns 0 if verification succeeded
// it is assumed that public key is valid otherwise calling this does not make much sense
int ecdsa_verify_digest(const uint8_t *pub_key, const uint8_t *sig, const uint8_t *digest)
{
int i, j;

View File

@ -887,7 +887,7 @@ START_TEST(test_pubkey_validity)
res = ecdsa_read_pubkey(pub_key, &pub);
ck_assert_int_eq(res, 1);
#ifdef USE_PUBKEY_VALIDATE
#if USE_PUBKEY_VALIDATE
memcpy(pub_key, fromhex("04f80490839af36d13701ec3f9eebdac901b51c362119d74553a3c537faff31b17e2a59ebddbdac9e87b816307a7ed5b826b8f40b92719086238e1bebf00000000"), 65);
res = ecdsa_read_pubkey(pub_key, &pub);
ck_assert_int_eq(res, 0);