Skip to content

Commit

Permalink
Tentative fix to test-curves
Browse files Browse the repository at this point in the history
  • Loading branch information
¨Jeff committed Jun 11, 2023
1 parent 95cbf11 commit 3d32841
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions test-templates/src/h2c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ macro_rules! test_h2c {
extern crate std;
use ark_ec::{
hashing::{
wb::WBMap, map_to_curve_hasher::MapToCurveBasedHasher, HashToCurve,
wb::WBMap, HashToCurve,
},
short_weierstrass::{Affine, Projective},
CurveGroup,
};
use ark_ff::{
field_hashers::{DefaultFieldHasher, HashToField},
field_hashers::{xmd_hash_to_field}, // zpad_expander, expand_for_field
fields::Field,
One, UniformRand, Zero,
};
Expand All @@ -41,27 +42,20 @@ macro_rules! test_h2c {

assert_eq!(data.hash, "sha256");
let dst = data.dst.as_bytes();
let hasher;
let g1_mapper = MapToCurveBasedHasher::<
Projective<$group>,
DefaultFieldHasher<Sha256, 128>,
WBMap<$group>,
>::new(dst)
.unwrap();
hasher = <DefaultFieldHasher<Sha256, 128> as HashToField<$field>>::new(dst);

for v in data.vectors.iter() {

// first, hash-to-field tests
let got: [$base_prime_field; { 2* $m } ] =
hasher.hash_to_field(&v.msg.as_bytes());
xmd_hash_to_field::<Sha256,Projective<TestSWUMapToCurveConfig>,{ 2* $m }>(128,dst,&v.msg.as_bytes());
let want: Vec<$base_prime_field> =
v.u.iter().map(read_fq_vec).flatten().collect();
assert_eq!(got[..], *want);

// then, test curve points
let x = read_fq_vec(&v.p.x);
let y = read_fq_vec(&v.p.y);
let got = g1_mapper.hash(&v.msg.as_bytes()).unwrap();
let got = <Projective<$group> as HashToCurve>::hash_to_curve(dst,v.msg.as_bytes()).unwrap().into_affine();
let want = Affine::<$group>::new_unchecked(
<$field>::from_base_prime_field_elems(x).unwrap(),
<$field>::from_base_prime_field_elems(y).unwrap(),
Expand Down

0 comments on commit 3d32841

Please sign in to comment.