From 72d1b70a91bf04fb08c3189767f833a0e7553e16 Mon Sep 17 00:00:00 2001 From: Fabio Scotoni <34964387+fscoto@users.noreply.github.com> Date: Wed, 22 Apr 2020 16:33:03 +0200 Subject: [PATCH] Make Elligator test vector gen deterministic 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 | 9 ++++++++- tests/gen/elligator-inverse.py | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/gen/elligator-direct.py b/tests/gen/elligator-direct.py index cee3e56..8b9b253 100755 --- a/tests/gen/elligator-direct.py +++ b/tests/gen/elligator-direct.py @@ -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) diff --git a/tests/gen/elligator-inverse.py b/tests/gen/elligator-inverse.py index 4a993df..8a7245c 100755 --- a/tests/gen/elligator-inverse.py +++ b/tests/gen/elligator-inverse.py @@ -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) -- 2.47.3