New query function ecc_montgomery_is_identity.

To begin with, this allows me to add a regression test for the change
in the previous commit.
This commit is contained in:
Simon Tatham 2020-02-28 19:32:35 +00:00
Родитель 141b75a71a
Коммит c9a8fa639e
4 изменённых файлов: 17 добавлений и 0 удалений

5
ecc.c
Просмотреть файл

@ -833,6 +833,11 @@ void ecc_montgomery_get_affine(MontgomeryPoint *mp, mp_int **x)
*x = monty_export(mc->mc, mp->X);
}
unsigned ecc_montgomery_is_identity(MontgomeryPoint *mp)
{
return mp_eq_integer(mp->Z, 0);
}
/* ----------------------------------------------------------------------
* Twisted Edwards curves.
*/

5
ecc.h
Просмотреть файл

@ -170,6 +170,11 @@ MontgomeryPoint *ecc_montgomery_multiply(MontgomeryPoint *, mp_int *);
*/
void ecc_montgomery_get_affine(MontgomeryPoint *mp, mp_int **x);
/*
* Test whether a point is the curve identity.
*/
unsigned ecc_montgomery_is_identity(MontgomeryPoint *mp);
/* ----------------------------------------------------------------------
* Twisted Edwards curves.
*

Просмотреть файл

@ -769,6 +769,12 @@ class ecc(MyTestBase):
check_point(ecc_montgomery_double(mP), rP + rP)
check_point(ecc_montgomery_double(mQ), rQ + rQ)
zero = ecc_montgomery_point_new(mc, 0)
self.assertEqual(ecc_montgomery_is_identity(zero), False)
identity = ecc_montgomery_double(zero)
ecc_montgomery_get_affine(identity)
self.assertEqual(ecc_montgomery_is_identity(identity), True)
def testEdwardsSimple(self):
p, d, a = 3141592661, 2688750488, 367934288

Просмотреть файл

@ -110,6 +110,7 @@ FUNC3(val_mpoint, ecc_montgomery_diff_add, val_mpoint, val_mpoint, val_mpoint)
FUNC1(val_mpoint, ecc_montgomery_double, val_mpoint)
FUNC2(val_mpoint, ecc_montgomery_multiply, val_mpoint, val_mpint)
FUNC2(void, ecc_montgomery_get_affine, val_mpoint, out_val_mpint)
FUNC1(boolean, ecc_montgomery_is_identity, val_mpoint)
FUNC4(val_ecurve, ecc_edwards_curve, val_mpint, val_mpint, val_mpint, opt_val_mpint)
FUNC3(val_epoint, ecc_edwards_point_new, val_ecurve, val_mpint, val_mpint)
FUNC3(val_epoint, ecc_edwards_point_new_from_y, val_ecurve, val_mpint, uint)