mirror of https://github.com/zcash/orchard.git
Add hash() and permute() test vectors for Poseidon over Fq.
This commit is contained in:
parent
f5775b6c6d
commit
2c97e56da7
|
@ -833,7 +833,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn hash_test_vectors() {
|
||||
for tv in crate::primitives::poseidon::test_vectors::hash() {
|
||||
for tv in crate::primitives::poseidon::test_vectors::fp::hash() {
|
||||
let message = [
|
||||
pallas::Base::from_repr(tv.input[0]).unwrap(),
|
||||
pallas::Base::from_repr(tv.input[1]).unwrap(),
|
||||
|
|
|
@ -264,9 +264,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn permute_test_vectors() {
|
||||
{
|
||||
let (round_constants, mds, _) = super::P128Pow5T3.constants();
|
||||
|
||||
for tv in crate::primitives::poseidon::test_vectors::permute() {
|
||||
for tv in crate::primitives::poseidon::test_vectors::fp::permute() {
|
||||
let mut state = [
|
||||
Fp::from_repr(tv.initial_state[0]).unwrap(),
|
||||
Fp::from_repr(tv.initial_state[1]).unwrap(),
|
||||
|
@ -281,9 +282,28 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
let (round_constants, mds, _) = super::P128Pow5T3.constants();
|
||||
|
||||
for tv in crate::primitives::poseidon::test_vectors::fq::permute() {
|
||||
let mut state = [
|
||||
Fq::from_repr(tv.initial_state[0]).unwrap(),
|
||||
Fq::from_repr(tv.initial_state[1]).unwrap(),
|
||||
Fq::from_repr(tv.initial_state[2]).unwrap(),
|
||||
];
|
||||
|
||||
permute::<Fq, super::P128Pow5T3, 3, 2>(&mut state, &mds, &round_constants);
|
||||
|
||||
for (expected, actual) in tv.final_state.iter().zip(state.iter()) {
|
||||
assert_eq!(&actual.to_repr(), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_test_vectors() {
|
||||
for tv in crate::primitives::poseidon::test_vectors::hash() {
|
||||
for tv in crate::primitives::poseidon::test_vectors::fp::hash() {
|
||||
let message = [
|
||||
Fp::from_repr(tv.input[0]).unwrap(),
|
||||
Fp::from_repr(tv.input[1]).unwrap(),
|
||||
|
@ -293,5 +313,16 @@ mod tests {
|
|||
|
||||
assert_eq!(result.to_repr(), tv.output);
|
||||
}
|
||||
|
||||
for tv in crate::primitives::poseidon::test_vectors::fq::hash() {
|
||||
let message = [
|
||||
Fq::from_repr(tv.input[0]).unwrap(),
|
||||
Fq::from_repr(tv.input[1]).unwrap(),
|
||||
];
|
||||
|
||||
let result = Hash::init(super::P128Pow5T3, ConstantLength).hash(message);
|
||||
|
||||
assert_eq!(result.to_repr(), tv.output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue