Increase the number of pedersen hash generators, exercise all test vectors.

This commit is contained in:
Taylor Hornby 2019-08-29 15:57:02 -06:00 committed by Jack Grigg
parent 4dff8055bf
commit 3701c2b442
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
2 changed files with 17 additions and 11 deletions

View File

@ -220,7 +220,7 @@ impl JubjubBls12 {
{
let mut pedersen_hash_generators = vec![];
for m in 0..5 {
for m in 0..6 {
use byteorder::{LittleEndian, WriteBytesExt};
let mut segment_number = [0u8; 4];

View File

@ -124,19 +124,25 @@ pub mod test {
fn test_pedersen_hash_points() {
let test_vectors = pedersen_hash_vectors::get_vectors();
let params = &JubjubBls12::new();
assert!(test_vectors.len() > 0);
let v = &test_vectors[0];
let input_bools: Vec<bool> = v.input_bits.iter().map(|&i| i == 1).collect();
for v in test_vectors.iter() {
let params = &JubjubBls12::new();
// The 6 bits prefix is handled separately
assert_eq!(v.personalization.get_bits(), &input_bools[..6]);
let input_bools: Vec<bool> = v.input_bits.iter().map(|&i| i == 1).collect();
let (x, y) =
pedersen_hash::<Bls12, _>(v.personalization, input_bools.into_iter().skip(6), params)
.to_xy();
// The 6 bits prefix is handled separately
assert_eq!(v.personalization.get_bits(), &input_bools[..6]);
assert_eq!(x.to_string(), v.hash_x);
assert_eq!(y.to_string(), v.hash_y);
let (x, y) = pedersen_hash::<Bls12, _>(
v.personalization,
input_bools.into_iter().skip(6),
params,
)
.to_xy();
assert_eq!(x.to_string(), v.hash_x);
assert_eq!(y.to_string(), v.hash_y);
}
}
}