ark-curves-cherry-picked/bls12_377/src/curves/tests/mod.rs
bls12_377/src/curves/tests/mod.rsRaw
1use crate::{Bls12_377, G1Projective, G2Projective};
2use ark_algebra_test_templates::*;
3
4test_group!(g1; G1Projective; sw);
5test_group!(g2; G2Projective; sw);
6test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bls12_377>; msm);
7test_pairing!(pairing; crate::Bls12_377);
8test_h2c!(g1_h2c; "./src/curves/tests"; "BLS12377G1"; crate::g1::Config; crate::Fq; crate::Fq; 1);
9test_h2c!(g2_hc2; "./src/curves/tests"; "BLS12377G2"; crate::g2::Config; crate::Fq2; crate::Fq; 2);
10
11#[cfg(test)]
12mod test {
13 use ark_ec::{
14 hashing::{
15 curve_maps::wb::{WBConfig, WBMap},
16 map_to_curve_hasher::MapToCurveBasedHasher,
17 HashToCurve,
18 },
19 short_weierstrass::Projective,
20 };
21 use ark_ff::field_hashers::DefaultFieldHasher;
22 use ark_std::Zero;
23
24 /// make a simple hash
25 fn wb_hash_arbitrary_string_to_curve<WBCurve: WBConfig>() {
26 use sha2::Sha256;
27 let test_wb_to_curve_hasher = MapToCurveBasedHasher::<
28 Projective<WBCurve>,
29 DefaultFieldHasher<Sha256, 128>,
30 WBMap<WBCurve>,
31 >::new(&[1])
32 .unwrap();
33
34 let hash_result = test_wb_to_curve_hasher.hash(b"if you stick a Babel fish in your ear you can instantly understand anything said to you in any form of language.").expect("fail to hash the string to curve");
35
36 assert!(
37 hash_result.x != WBCurve::BaseField::zero()
38 && hash_result.y != WBCurve::BaseField::zero(),
39 "we assume that not both a and b coefficienst are zero for the test curve"
40 );
41
42 assert!(
43 hash_result.is_on_curve(),
44 "hash results into a point off the curve"
45 );
46 }
47
48 #[test]
49 fn wb_hash_arbitrary_string_to_g1() {
50 wb_hash_arbitrary_string_to_curve::<crate::g1::Config>();
51 }
52
53 #[test]
54 fn wb_hash_arbitrary_string_to_g2() {
55 wb_hash_arbitrary_string_to_curve::<crate::g2::Config>();
56 }
57}