]> git.codecow.com Git - Monocypher.git/commitdiff
Make Elligator test vector gen deterministic
authorFabio Scotoni <34964387+fscoto@users.noreply.github.com>
Wed, 22 Apr 2020 14:33:03 +0000 (16:33 +0200)
committerFabio Scotoni <34964387+fscoto@users.noreply.github.com>
Wed, 22 Apr 2020 14:36:35 +0000 (16:36 +0200)
This paves the way for reproducible tarballs.
Since the test vectors must be generated for a complete tarball,
these must agree everywhere.

The lack of actual randomness is harmless because these are test
vectors, not actual usages of Elligator.

tests/gen/elligator-direct.py
tests/gen/elligator-inverse.py

index cee3e561ec77285dea440232a37313a5c2d7c526..8b9b253d8b8015ff9f233595c19c10cdd0a34819 100755 (executable)
@@ -12,6 +12,7 @@
 # ------------------------------------------------------------------------
 #
 # Copyright (c) 2020, Loup Vaillant
+# Copyright (c) 2020, Fabio Scotoni
 # All rights reserved.
 #
 #
@@ -41,7 +42,7 @@
 #
 # ------------------------------------------------------------------------
 #
-# Written in 2020 by Loup Vaillant
+# Written in 2020 by Loup Vaillant and Fabio Scotoni
 #
 # To the extent possible under law, the author(s) have dedicated all copyright
 # and related neighboring rights to this software to the public domain
@@ -58,6 +59,7 @@ from elligator import fast_hash_to_curve
 from elligator import p
 from elligator import print_raw
 from random    import randrange
+from random    import seed
 
 def direct(r1, padding):
     q1 = hash_to_curve(r1)
@@ -73,5 +75,10 @@ direct(fe(0), 0) # representative 0 maps to point (0, 0)
 direct(fe(0), 1) # representative 0 maps to point (0, 0)
 direct(fe(0), 2) # representative 0 maps to point (0, 0)
 direct(fe(0), 3) # representative 0 maps to point (0, 0)
+
+# Make test vector generation deterministic, the actual randomness does
+# not matter here since these are just tests.
+seed(12345)
+
 for i in range(50):
     direct(fe(randrange(0, (p-1)/2)), i % 4)
index 4a993df24df2f57cc9fc06a4229ca0c5cb92efd0..8a7245c516c7cb02858c82465004591785dc53a2 100755 (executable)
@@ -12,6 +12,7 @@
 # ------------------------------------------------------------------------
 #
 # Copyright (c) 2020, Loup Vaillant
+# Copyright (c) 2020, Fabio Scotoni
 # All rights reserved.
 #
 #
@@ -41,7 +42,7 @@
 #
 # ------------------------------------------------------------------------
 #
-# Written in 2020 by Loup Vaillant
+# Written in 2020 by Loup Vaillant and Fabio Scotoni
 #
 # To the extent possible under law, the author(s) have dedicated all copyright
 # and related neighboring rights to this software to the public domain
@@ -60,6 +61,7 @@ from elligator import print_raw
 from elligator_scalarmult import scalarmult
 
 from random import randrange
+from random import seed
 
 def private_to_curve_and_hash(scalar, tweak):
     cofactor      = scalar % 8
@@ -78,6 +80,10 @@ def private_to_curve_and_hash(scalar, tweak):
     if u2 != u: raise ValueError('Round trip failure')
     return (u, r1.val + msb)
 
+# Make test vector generation deterministic, the actual randomness does
+# not matter here since these are just tests.
+seed(12345)
+
 # All possible failures
 for cofactor in range(8):
     tweak = randrange(0, 256)