mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-12 18:49:07 +00:00
Account for case when point.y == 0 when doubling.
This commit is contained in:
parent
6d61cefdb3
commit
d827b2c862
21
ecdsa.c
21
ecdsa.c
@ -54,14 +54,12 @@ void point_add(const curve_point *cp1, curve_point *cp2)
|
||||
point_copy(cp1, cp2);
|
||||
return;
|
||||
}
|
||||
if (point_is_equal(cp1, cp2)) {
|
||||
point_double(cp2);
|
||||
if (point_is_negative_of(cp1, cp2)) {
|
||||
point_set_infinity(cp2);
|
||||
return;
|
||||
}
|
||||
if (point_is_negative_of(cp1, cp2)) {
|
||||
// set to point at infinity
|
||||
bn_zero(&(cp2->x));
|
||||
bn_zero(&(cp2->y));
|
||||
if (point_is_equal(cp1, cp2)) {
|
||||
point_double(cp2);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -98,6 +96,10 @@ void point_double(curve_point *cp)
|
||||
if (point_is_infinity(cp)) {
|
||||
return;
|
||||
}
|
||||
if (bn_is_zero(&(cp->y))) {
|
||||
point_set_infinity(cp);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&inverse_y, &(cp->y), sizeof(bignum256));
|
||||
bn_inverse(&inverse_y, &prime256k1);
|
||||
@ -151,6 +153,13 @@ void point_multiply(const bignum256 *k, const curve_point *p, curve_point *res)
|
||||
bn_mod(&(res->y), &prime256k1);
|
||||
}
|
||||
|
||||
// set point to internal representation of point at infinity
|
||||
void point_set_infinity(curve_point *p)
|
||||
{
|
||||
bn_zero(&(p->x));
|
||||
bn_zero(&(p->y));
|
||||
}
|
||||
|
||||
// return true iff p represent point at infinity
|
||||
// both coords are zero in internal representation
|
||||
int point_is_infinity(const curve_point *p)
|
||||
|
1
ecdsa.h
1
ecdsa.h
@ -36,6 +36,7 @@ void point_copy(const curve_point *cp1, curve_point *cp2);
|
||||
void point_add(const curve_point *cp1, curve_point *cp2);
|
||||
void point_double(curve_point *cp);
|
||||
void point_multiply(const bignum256 *k, const curve_point *p, curve_point *res);
|
||||
void point_set_infinity(curve_point *p);
|
||||
int point_is_infinity(const curve_point *p);
|
||||
int point_is_equal(const curve_point *p, const curve_point *q);
|
||||
int point_is_negative_of(const curve_point *p, const curve_point *q);
|
||||
|
Loading…
Reference in New Issue
Block a user