Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions ec/src/hashing/tests/mod.rs → ec/src/hashing/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use crate::hashing::curve_maps::swu::parity;
use ark_test_curves::bls12_381::{Fq, Fq2, Fq6};

#[cfg(all(test, feature = "std"))]
mod json;
#[cfg(all(test, feature = "std"))]
mod suites;

#[test]
fn test_parity_of_prime_field_elements() {
let a1 = Fq::from(0);
Expand Down
121 changes: 0 additions & 121 deletions ec/src/hashing/tests/suites.rs

This file was deleted.

4 changes: 4 additions & 0 deletions test-curves/src/bls12_381/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ test_group!(g2; G2Projective; sw);
test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bls12_381>; msm);
#[cfg(feature = "bls12_381_curve")]
test_pairing!(pairing; crate::bls12_381::Bls12_381);
#[cfg(feature = "bls12_381_curve")]
test_h2c!(g1_h2c; "./src/testdata"; "BLS12381G1"; crate::bls12_381::g1::Config; crate::bls12_381::Fq; crate::bls12_381::Fq; 1);
#[cfg(feature = "bls12_381_curve")]
test_h2c!(g2_hc2; "./src/testdata"; "BLS12381G2"; crate::bls12_381::g2::Config; crate::bls12_381::Fq2; crate::bls12_381::Fq; 2);
5 changes: 5 additions & 0 deletions test-templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ ark-ec = { version = "^0.3.0", path = "../ec", default-features = false }
num-bigint = { version = "0.4", default-features = false }
num-integer = { version = "0.1", default-features = false }
num-traits = { version = "0.2", default-features = false }
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
hex = "0.4"
sha2 = { version = "0.10", default-features = false }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion test-templates/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ macro_rules! __test_field {

assert_eq!(r, <$field>::R.into());
assert_eq!(r2, <$field>::R2.into());
assert_eq!(inv, <$field>::INV.into());
assert_eq!(inv, u64::from(<$field>::INV));
assert_eq!(inv2, <$field>::INV);
}
}
Expand Down
File renamed without changes.
87 changes: 87 additions & 0 deletions test-templates/src/h2c/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
pub mod json;
extern crate hex;
extern crate serde_json;
extern crate sha2;
pub use hex::decode;
pub use serde_json::from_reader;
pub use sha2::Sha256;

#[macro_export]
macro_rules! test_h2c {
($mod_name: ident; $test_path: literal; $test_name: literal; $group: ty; $field: ty; $base_prime_field: ty; $m: literal) => {
mod $mod_name {
use ark_ff::PrimeField;

extern crate std;
use ark_ec::{
hashing::{
curve_maps::wb::WBMap, map_to_curve_hasher::MapToCurveBasedHasher, HashToCurve,
},
short_weierstrass::{Affine, Projective},
};
use ark_ff::{
field_hashers::{DefaultFieldHasher, HashToField},
fields::Field,
One, UniformRand, Zero,
};
use ark_std::{format, string::String, vec::Vec};
use std::{
fs::{read_dir, File},
io::BufReader,
};
use $crate::decode;
use $crate::Sha256;

use $crate::json::SuiteVector;
#[test]
fn test_h2c() {
let filename = format!("{}/{}_XMD-SHA-256_SSWU_RO_.json", $test_path, $test_name);

let file = File::open(filename).unwrap();
let data: SuiteVector = $crate::from_reader(BufReader::new(file)).unwrap();

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: Vec<$base_prime_field> =
hasher.hash_to_field(&v.msg.as_bytes(), 2 * $m);
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 want = Affine::<$group>::new_unchecked(
<$field>::from_base_prime_field_elems(&x[..]).unwrap(),
<$field>::from_base_prime_field_elems(&y[..]).unwrap(),
);
assert!(got.is_on_curve());
assert!(want.is_on_curve());
assert_eq!(got, want);
}
}
pub fn read_fq_vec(input: &String) -> Vec<$base_prime_field> {
input
.split(",")
.map(|f| {
<$base_prime_field>::from_be_bytes_mod_order(
&decode(f.trim_start_matches("0x")).unwrap(),
)
})
.collect()
}
}
};
}
3 changes: 3 additions & 0 deletions test-templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pub mod fields;
pub mod msm;
#[macro_use]
pub mod pairing;
#[macro_use]
pub mod h2c;
pub use h2c::*;

pub use num_bigint;
pub use num_integer;
Expand Down