Merge files that were only separate in order to provide multiple entry points.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2022-02-08 14:56:48 +00:00
parent f07451a025
commit d6d69f8388
7 changed files with 117 additions and 150 deletions

View File

@ -31,7 +31,7 @@ secp256k1 = "0.14.0"
[tool.poetry.scripts] [tool.poetry.scripts]
# General test vectors # General test vectors
f4jumble = "zcash_test_vectors.f4jumble:main" f4jumble = "zcash_test_vectors.f4jumble:main"
f4jumble_long = "zcash_test_vectors.f4jumble_long:main" f4jumble_long = "zcash_test_vectors.f4jumble:long_test_vectors"
unified_address = "zcash_test_vectors.unified_address:main" unified_address = "zcash_test_vectors.unified_address:main"
unified_full_viewing_keys = "zcash_test_vectors.unified_full_viewing_keys:main" unified_full_viewing_keys = "zcash_test_vectors.unified_full_viewing_keys:main"
unified_incoming_viewing_keys = "zcash_test_vectors.unified_incoming_viewing_keys:main" unified_incoming_viewing_keys = "zcash_test_vectors.unified_incoming_viewing_keys:main"
@ -51,10 +51,10 @@ sapling_zip32 = "zcash_test_vectors.sapling.zip32:main"
orchard_empty_roots = "zcash_test_vectors.orchard.empty_roots:main" orchard_empty_roots = "zcash_test_vectors.orchard.empty_roots:main"
orchard_generators = "zcash_test_vectors.orchard.generators:main" orchard_generators = "zcash_test_vectors.orchard.generators:main"
orchard_group_hash = "zcash_test_vectors.orchard.group_hash:main" orchard_group_hash = "zcash_test_vectors.orchard.group_hash:main"
orchard_map_to_curve = "zcash_test_vectors.orchard.group_hash:map_to_curve_test_vectors"
orchard_key_components = "zcash_test_vectors.orchard.key_components:main" orchard_key_components = "zcash_test_vectors.orchard.key_components:main"
orchard_map_to_curve = "zcash_test_vectors.orchard.map_to_curve:main"
orchard_merkle_tree = "zcash_test_vectors.orchard.merkle_tree:main" orchard_merkle_tree = "zcash_test_vectors.orchard.merkle_tree:main"
orchard_note_encryption = "zcash_test_vectors.orchard.note_encryption:main" orchard_note_encryption = "zcash_test_vectors.orchard.note_encryption:main"
orchard_poseidon = "zcash_test_vectors.orchard.poseidon:main" orchard_poseidon = "zcash_test_vectors.orchard.poseidon:main"
orchard_poseidon_hash = "zcash_test_vectors.orchard.poseidon_hash:main" orchard_poseidon_hash = "zcash_test_vectors.orchard.poseidon:hash_test_vectors"
orchard_sinsemilla = "zcash_test_vectors.orchard.sinsemilla:main" orchard_sinsemilla = "zcash_test_vectors.orchard.sinsemilla:main"

View File

@ -123,6 +123,35 @@ def main():
plain_test_vectors, plain_test_vectors,
) )
def long_test_vectors():
args = render_args()
hashed_test_vectors = []
for l_M in [
3246395,
MAX_l_M,
]:
M = bytes([i & 0xFF for i in range(l_M)])
jumbled = f4jumble(M)
assert len(jumbled) == len(M)
assert f4jumble_inv(jumbled) == M
hashed_test_vectors.append({
'length': l_M,
'jumbled_hash': blake2b(jumbled).digest()
})
render_tv(
args,
'f4jumble_long',
(
('length', 'usize'),
('jumbled_hash', '[u8; 64]'),
),
hashed_test_vectors,
)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,41 +0,0 @@
#!/usr/bin/env python3
import sys; assert sys.version_info[0] >= 3, "Python 3 required."
from hashlib import blake2b
from .output import render_args, render_tv
from .f4jumble import f4jumble, f4jumble_inv, MAX_l_M
def main():
args = render_args()
hashed_test_vectors = []
for l_M in [
3246395,
MAX_l_M,
]:
M = bytes([i & 0xFF for i in range(l_M)])
jumbled = f4jumble(M)
assert len(jumbled) == len(M)
assert f4jumble_inv(jumbled) == M
hashed_test_vectors.append({
'length': l_M,
'jumbled_hash': blake2b(jumbled).digest()
})
render_tv(
args,
'f4jumble_long',
(
('length', 'usize'),
('jumbled_hash', '[u8; 64]'),
),
hashed_test_vectors,
)
if __name__ == "__main__":
main()

View File

@ -7,11 +7,13 @@ import math
from . import iso_pallas from . import iso_pallas
from .pallas import Fp, p, q, PALLAS_B, Point from .pallas import Fp, p, q, PALLAS_B, Point
from .iso_pallas import PALLAS_ISO_B, PALLAS_ISO_A from .iso_pallas import PALLAS_ISO_B, PALLAS_ISO_A, Point as IsoPoint
from ..utils import i2beosp, cldiv, beos2ip, i2leosp, lebs2ip
from ..utils import i2beosp, cldiv, beos2ip, i2leosp, lebs2ip, leos2ip
from ..output import render_args, render_tv from ..output import render_args, render_tv
from ..rand import Rand from ..rand import Rand
# https://stackoverflow.com/questions/2612720/how-to-do-bitwise-exclusive-or-of-two-strings-in-python # https://stackoverflow.com/questions/2612720/how-to-do-bitwise-exclusive-or-of-two-strings-in-python
def sxor(s1,s2): def sxor(s1,s2):
return bytes([a ^ b for a,b in zip(s1,s2)]) return bytes([a ^ b for a,b in zip(s1,s2)])
@ -182,6 +184,49 @@ def main():
} for (domain, msg) in test_vectors], } for (domain, msg) in test_vectors],
) )
def map_to_curve_test_vectors():
fixed_test_vectors = [
(Fp(0), IsoPoint(Fp(19938918781445865934736160264407396416050199005817793816893455093350997047296),
Fp(1448774895934493446148762800986014913165975534940595774801697325542407056356))),
(Fp(1), IsoPoint(Fp(5290181550357368025040301950220623271393946308300025648720253222947454165280),
Fp(24520995241805476578231005891941079870703368870355132644748659103632565232759))),
(Fp(0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef0123),
IsoPoint(Fp(16711718778908753690082328243251803703269853000652055785581237369882690082595),
Fp(1764705856161931038824461929646873031992914829456409784642560948827969833589))),
]
for (u, point) in fixed_test_vectors:
P = map_to_curve_simple_swu(u)
assert P == point
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',
(
('u', '[u8; 32]'),
('point', '[u8; 32]'),
),
[{
'u': bytes(u),
'point': bytes(map_to_curve_simple_swu(u)),
} for u in test_vectors],
)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,58 +0,0 @@
#!/usr/bin/env python3
import sys; assert sys.version_info[0] >= 3, "Python 3 required."
from .group_hash import map_to_curve_simple_swu
from .iso_pallas import Point as IsoPoint
from .pallas import Fp
from ..utils import leos2ip
from ..output import render_args, render_tv
from ..rand import Rand
def main():
fixed_test_vectors = [
(Fp(0), IsoPoint(Fp(19938918781445865934736160264407396416050199005817793816893455093350997047296),
Fp(1448774895934493446148762800986014913165975534940595774801697325542407056356))),
(Fp(1), IsoPoint(Fp(5290181550357368025040301950220623271393946308300025648720253222947454165280),
Fp(24520995241805476578231005891941079870703368870355132644748659103632565232759))),
(Fp(0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef0123),
IsoPoint(Fp(16711718778908753690082328243251803703269853000652055785581237369882690082595),
Fp(1764705856161931038824461929646873031992914829456409784642560948827969833589))),
]
for (u, point) in fixed_test_vectors:
P = map_to_curve_simple_swu(u)
assert P == point
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',
(
('u', '[u8; 32]'),
('point', '[u8; 32]'),
),
[{
'u': bytes(u),
'point': bytes(map_to_curve_simple_swu(u)),
} for u in test_vectors],
)
if __name__ == "__main__":
main()

View File

@ -1,13 +1,16 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys; assert sys.version_info[0] >= 3, "Python 3 required." import sys; assert sys.version_info[0] >= 3, "Python 3 required."
from ..orchard.pallas import Fp
import numpy as np import numpy as np
from itertools import chain from itertools import chain
from .pallas import Fp
from ..utils import leos2ip from ..utils import leos2ip
from ..output import render_args, render_tv from ..output import render_args, render_tv
from ..rand import Rand from ..rand import Rand
# Number of full rounds # Number of full rounds
R_F = 8 R_F = 8
# Number of partial rounds # Number of partial rounds
@ -156,8 +159,8 @@ def hash(x, y):
assert isinstance(y, Fp) assert isinstance(y, Fp)
return perm([x, y, CAPACITY_ELEMENT])[0] return perm([x, y, CAPACITY_ELEMENT])[0]
def main():
def main():
# These are test vectors from https://github.com/daira/pasta-hadeshash/commit/f7ca15dcf8568f1a4b2c4b7188815e80e9ab8975. # These are test vectors from https://github.com/daira/pasta-hadeshash/commit/f7ca15dcf8568f1a4b2c4b7188815e80e9ab8975.
fixed_test_input = [ fixed_test_input = [
Fp(0x0000000000000000000000000000000000000000000000000000000000000000), Fp(0x0000000000000000000000000000000000000000000000000000000000000000),
@ -204,5 +207,38 @@ def main():
} for input in test_vectors], } for input in test_vectors],
) )
def hash_test_vectors():
test_vectors = [[Fp.ZERO, Fp(1)]]
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))),
Fp(leos2ip(rand.b(32))),
])
render_tv(
render_args(),
'orchard_poseidon_hash',
(
('input', '[[u8; 32]; 2]'),
('output', '[u8; 32]'),
),
[{
'input': list(map(bytes, input)),
'output': bytes(hash(input[0], input[1])),
} for input in test_vectors],
)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,44 +0,0 @@
#!/usr/bin/env python3
import sys; assert sys.version_info[0] >= 3, "Python 3 required."
from .pallas import Fp
from . import poseidon
from ..utils import leos2ip
from ..output import render_args, render_tv
from ..rand import Rand
def main():
test_vectors = [[Fp.ZERO, Fp(1)]]
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))),
Fp(leos2ip(rand.b(32))),
])
render_tv(
render_args(),
'orchard_poseidon_hash',
(
('input', '[[u8; 32]; 2]'),
('output', '[u8; 32]'),
),
[{
'input': list(map(bytes, input)),
'output': bytes(poseidon.hash(input[0], input[1])),
} for input in test_vectors],
)
if __name__ == "__main__":
main()