Skip to content

Commit c9a8fa6

Browse files
committed
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.
1 parent 141b75a commit c9a8fa6

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

ecc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ void ecc_montgomery_get_affine(MontgomeryPoint *mp, mp_int **x)
833833
*x = monty_export(mc->mc, mp->X);
834834
}
835835

836+
unsigned ecc_montgomery_is_identity(MontgomeryPoint *mp)
837+
{
838+
return mp_eq_integer(mp->Z, 0);
839+
}
840+
836841
/* ----------------------------------------------------------------------
837842
* Twisted Edwards curves.
838843
*/

ecc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ MontgomeryPoint *ecc_montgomery_multiply(MontgomeryPoint *, mp_int *);
170170
*/
171171
void ecc_montgomery_get_affine(MontgomeryPoint *mp, mp_int **x);
172172

173+
/*
174+
* Test whether a point is the curve identity.
175+
*/
176+
unsigned ecc_montgomery_is_identity(MontgomeryPoint *mp);
177+
173178
/* ----------------------------------------------------------------------
174179
* Twisted Edwards curves.
175180
*

test/cryptsuite.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,12 @@ def check_point(mp, rp):
769769
check_point(ecc_montgomery_double(mP), rP + rP)
770770
check_point(ecc_montgomery_double(mQ), rQ + rQ)
771771

772+
zero = ecc_montgomery_point_new(mc, 0)
773+
self.assertEqual(ecc_montgomery_is_identity(zero), False)
774+
identity = ecc_montgomery_double(zero)
775+
ecc_montgomery_get_affine(identity)
776+
self.assertEqual(ecc_montgomery_is_identity(identity), True)
777+
772778
def testEdwardsSimple(self):
773779
p, d, a = 3141592661, 2688750488, 367934288
774780

testcrypt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ FUNC3(val_mpoint, ecc_montgomery_diff_add, val_mpoint, val_mpoint, val_mpoint)
110110
FUNC1(val_mpoint, ecc_montgomery_double, val_mpoint)
111111
FUNC2(val_mpoint, ecc_montgomery_multiply, val_mpoint, val_mpint)
112112
FUNC2(void, ecc_montgomery_get_affine, val_mpoint, out_val_mpint)
113+
FUNC1(boolean, ecc_montgomery_is_identity, val_mpoint)
113114
FUNC4(val_ecurve, ecc_edwards_curve, val_mpint, val_mpint, val_mpint, opt_val_mpint)
114115
FUNC3(val_epoint, ecc_edwards_point_new, val_ecurve, val_mpint, val_mpint)
115116
FUNC3(val_epoint, ecc_edwards_point_new_from_y, val_ecurve, val_mpint, uint)

0 commit comments

Comments
 (0)