arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
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_group!(g1_glv; G1Projective; glv);
 9test_group!(g2_glv; G2Projective; glv);
10test_h2c!(g1_h2c; "./src/curves/tests"; "BLS12377G1"; crate::g1::Config; crate::Fq; crate::Fq; 1);
11test_h2c!(g2_hc2; "./src/curves/tests"; "BLS12377G2"; crate::g2::Config; crate::Fq2; crate::Fq; 2);
12
13#[cfg(test)]
14mod test {
15    use ark_ec::{
16        hashing::{
17            curve_maps::wb::{WBConfig, WBMap},
18            map_to_curve_hasher::MapToCurveBasedHasher,
19            HashToCurve,
20        },
21        short_weierstrass::Projective,
22    };
23    use ark_ff::field_hashers::DefaultFieldHasher;
24    use ark_std::Zero;
25
26    /// make a simple hash
27    fn wb_hash_arbitrary_string_to_curve<WBCurve: WBConfig>() {
28        use sha2::Sha256;
29        let test_wb_to_curve_hasher = MapToCurveBasedHasher::<
30            Projective<WBCurve>,
31            DefaultFieldHasher<Sha256, 128>,
32            WBMap<WBCurve>,
33        >::new(&[1])
34        .unwrap();
35
36        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");
37
38        assert!(
39            hash_result.x != WBCurve::BaseField::zero()
40                && hash_result.y != WBCurve::BaseField::zero(),
41            "we assume that not both a and b coefficienst are zero for the test curve"
42        );
43
44        assert!(
45            hash_result.is_on_curve(),
46            "hash results into a point off the curve"
47        );
48    }
49
50    #[test]
51    fn wb_hash_arbitrary_string_to_g1() {
52        wb_hash_arbitrary_string_to_curve::<crate::g1::Config>();
53    }
54
55    #[test]
56    fn wb_hash_arbitrary_string_to_g2() {
57        wb_hash_arbitrary_string_to_curve::<crate::g2::Config>();
58    }
59}