44 lines
1.1 KiB
Python
Executable File
44 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import sys; assert sys.version_info[0] >= 3, "Python 3 required."
|
|
|
|
from zcash_test_vectors.orchard.pallas import Fp
|
|
from zcash_test_vectors.orchard import poseidon
|
|
from zcash_test_vectors.utils import leos2ip
|
|
from zcash_test_vectors.output import render_args, render_tv
|
|
from zcash_test_vectors.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()
|