diff --git a/ecc.c b/ecc.c index 857fc024c4d502ffaa19fe8330f7afc2e07400ca..72f9bfe5830386927414aa787a19fe0f249159b7 100644 --- a/ecc.c +++ b/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. */ diff --git a/ecc.h b/ecc.h index 13118b2952198a8ef7743d978c3b24bde465ddb1..96eebdf0613c5e5bf9f6b1f20b9ddccf1a0b61ef 100644 --- a/ecc.h +++ b/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. * diff --git a/test/cryptsuite.py b/test/cryptsuite.py index 1df54117f5ee6a235c35c5daebeb573c9d684a8f..18a2a3300e0d2fefa8736e91f5899948d2848952 100755 --- a/test/cryptsuite.py +++ b/test/cryptsuite.py @@ -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 diff --git a/testcrypt.h b/testcrypt.h index 9efbb87d981ff758dde09bf7caebda115a135520..bc9dcea9a5d3bc15354ca55b21e7bdf3b950bf02 100644 --- a/testcrypt.h +++ b/testcrypt.h @@ -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)