Generate random test vectors for MapToCurve, GroupHash, Sinsemilla
This commit is contained in:
parent
c6cd47a5dd
commit
9cb9e0f9bc
|
@ -10,6 +10,7 @@ from orchard_pallas import Fp, p, q, PALLAS_B, Point
|
|||
from orchard_iso_pallas import PALLAS_ISO_B, PALLAS_ISO_A
|
||||
from sapling_utils import i2beosp, cldiv, beos2ip, i2leosp, lebs2ip
|
||||
from tv_output import render_args, render_tv
|
||||
from tv_rand import Rand
|
||||
|
||||
# https://stackoverflow.com/questions/2612720/how-to-do-bitwise-exclusive-or-of-two-strings-in-python
|
||||
def sxor(s1,s2):
|
||||
|
@ -148,6 +149,25 @@ def main():
|
|||
|
||||
test_vectors = [(domain, msg) for (domain, msg, _) in fixed_test_vectors]
|
||||
|
||||
from random import Random
|
||||
rng = Random(0xabad533d)
|
||||
def randbytes(l):
|
||||
ret = []
|
||||
while len(ret) < l:
|
||||
ret.append(rng.randrange(0, 256))
|
||||
return bytes(ret)
|
||||
rand = Rand(randbytes)
|
||||
|
||||
# Generate test vectors with the following properties:
|
||||
# - One of two domains.
|
||||
# - Random message lengths between 0 and 255 bytes.
|
||||
# - Random message contents.
|
||||
for _ in range(10):
|
||||
domain = b"z.cash:test-longer" if rand.bool() else b"z.cash:test"
|
||||
msg_len = rand.u8()
|
||||
msg = bytes([rand.u8() for _ in range(msg_len)])
|
||||
test_vectors.append((domain, msg))
|
||||
|
||||
render_tv(
|
||||
render_args(),
|
||||
'orchard_group_hash',
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
from orchard_group_hash import map_to_curve_simple_swu
|
||||
from orchard_iso_pallas import Point as IsoPoint
|
||||
from orchard_pallas import Fp
|
||||
from sapling_utils import leos2ip
|
||||
from tv_output import render_args, render_tv
|
||||
from tv_rand import Rand
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -23,6 +25,19 @@ def main():
|
|||
|
||||
test_vectors = [u for (u, _) in fixed_test_vectors]
|
||||
|
||||
from random import Random
|
||||
rng = Random(0xabad533d)
|
||||
def randbytes(l):
|
||||
ret = []
|
||||
while len(ret) < l:
|
||||
ret.append(rng.randrange(0, 256))
|
||||
return bytes(ret)
|
||||
rand = Rand(randbytes)
|
||||
|
||||
# Generate random test vectors
|
||||
for _ in range(10):
|
||||
test_vectors.append(Fp(leos2ip(rand.b(32))))
|
||||
|
||||
render_tv(
|
||||
render_args(),
|
||||
'orchard_map_to_curve',
|
||||
|
|
|
@ -9,6 +9,7 @@ from orchard_pallas import Fp, Point
|
|||
from sapling_utils import cldiv, lebs2ip, i2leosp
|
||||
from orchard_group_hash import group_hash
|
||||
from tv_output import render_args, render_tv
|
||||
from tv_rand import Rand
|
||||
|
||||
SINSEMILLA_K = 10
|
||||
|
||||
|
@ -52,6 +53,25 @@ def main():
|
|||
assert sh == Point(Fp(19681977528872088480295086998934490146368213853811658798708435106473481753752),
|
||||
Fp(14670850419772526047574141291705097968771694788047376346841674072293161339903))
|
||||
|
||||
from random import Random
|
||||
rng = Random(0xabad533d)
|
||||
def randbytes(l):
|
||||
ret = []
|
||||
while len(ret) < l:
|
||||
ret.append(rng.randrange(0, 256))
|
||||
return bytes(ret)
|
||||
rand = Rand(randbytes)
|
||||
|
||||
# Generate test vectors with the following properties:
|
||||
# - One of two domains.
|
||||
# - Random message lengths between 0 and 255 bytes.
|
||||
# - Random message bits.
|
||||
for _ in range(10):
|
||||
domain = b"z.cash:test-Sinsemilla-longer" if rand.bool() else b"z.cash:test-Sinsemilla"
|
||||
msg_len = rand.u8()
|
||||
msg = bytes([rand.bool() for _ in range(msg_len)])
|
||||
test_vectors.append((domain, msg))
|
||||
|
||||
test_vectors = [{
|
||||
'domain': domain,
|
||||
'msg': msg,
|
||||
|
|
Loading…
Reference in New Issue