Skip to content

Commit

Permalink
Merge pull request AntonKueltz#72 from bbbrumley/bbb_large
Browse files Browse the repository at this point in the history
[fastecdsa/tests] regression test: multiplication by large scalars
  • Loading branch information
AntonKueltz authored Jul 14, 2021
2 parents 7fd4156 + ca2dacb commit 904d962
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions fastecdsa/tests/test_prime_field_curve_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,31 @@ def test_mul_by_negative(self):
self.assertEqual(P.x, Q.x)
self.assertEqual(P.y, Q.y)

def test_mul_by_large(self):
# W25519 test
# this is an order h * q point, where ord(G) = q and cofactor h satisfies card(E) = h * q
P_25519 = (35096664872667797862139202932949049580901987963171775123990915594423742128033,
22480573877477866270168076032006671893585325258603943218058327520008883368696)
# scalar larger than q but smaller than h * q
k_25519 = 29372000253601831461196252357151931556312986177449743872632027037220559545805
# KAT: Q = k * P
Q_25519 = (49706689516442043243945288648738077613576846608357551203998149787039218825283,
39031159953669648926560068238390400180132971507115734045330364888380270413913)
P_25519 = Point(P_25519[0], P_25519[1], curve=W25519)
R = k_25519 * P_25519
expected = Point(Q_25519[0], Q_25519[1], curve=W25519)
self.assertEqual(R, expected)

# W448 test
# this is an order h * q point, where ord(G) = q and cofactor h satisfies card(E) = h * q
P_448 = (231480979532797508943026590383724571663349496894338686929676625369384864922735088561874582237479033305968563866115522624182905190510908,
386642878578520576902801772187402730328995571185781418728101620741813344331894790606494081334128109534545128357659367878296954820089456)
# scalar larger than q but smaller than h * q
k_448 = 402277635739946816237642095194112559838556500677282525912537756673080201343619608058123416303707654128973619279630717054942423338738673
# KAT: Q = k * P
Q_448 = (594031426065062897452711501095164269186787326947787097339623446049485959406429079799671040253813345976305183137288555654745835823926292,
397805400082591898298129134663530334000872412871159149907636409950148029590985263340056678772524289857573459442468777694902850559368658)
P_448 = Point(P_448[0], P_448[1], curve=W448)
R = k_448 * P_448
expected = Point(Q_448[0], Q_448[1], curve=W448)
self.assertEqual(R, expected)

0 comments on commit 904d962

Please sign in to comment.