Skip to content
22 changes: 11 additions & 11 deletions ec/src/hashing/curve_maps/swu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
/// y^2 = x^3 + a*x + b where ab != 0. From [\[WB2019\]]
///
/// - [\[WB2019\]] <https://eprint.iacr.org/2019/403>
pub trait SWUParams: SWCurveConfig {
pub trait SWUConfig: SWCurveConfig {
/// An element of the base field that is not a square root see \[WB2019, Section 4\].
/// It is also convenient to have $g(b/ZETA * a)$ to be square. In general
/// we use a `ZETA` with low absolute value coefficients when they are
Expand All @@ -22,7 +22,7 @@ pub trait SWUParams: SWCurveConfig {
}

/// Represents the SWU hash-to-curve map defined by `P`.
pub struct SWUMap<P: SWUParams>(PhantomData<fn() -> P>);
pub struct SWUMap<P: SWUConfig>(PhantomData<fn() -> P>);

/// Trait defining a parity method on the Field elements based on [\[1\]] Section 4.1
///
Expand All @@ -34,7 +34,7 @@ pub fn parity<F: Field>(element: &F) -> bool {
.map_or(false, |x| x.into_bigint().is_odd())
}

impl<P: SWUParams> MapToCurve<Projective<P>> for SWUMap<P> {
impl<P: SWUConfig> MapToCurve<Projective<P>> for SWUMap<P> {
/// Constructs a new map if `P` represents a valid map.
fn new() -> Result<Self, HashToCurveError> {
// Verifying that ZETA is a non-square
Expand Down Expand Up @@ -171,9 +171,9 @@ mod test {

const F127_ONE: F127 = MontFp!("1");

struct TestSWUMapToCurveParams;
struct TestSWUMapToCurveConfig;

impl CurveConfig for TestSWUMapToCurveParams {
impl CurveConfig for TestSWUMapToCurveConfig {
const COFACTOR: &'static [u64] = &[1];

#[rustfmt::skip]
Expand All @@ -197,7 +197,7 @@ mod test {
/// pass
///
/// y^2 = x^3 + x + 63
impl SWCurveConfig for TestSWUMapToCurveParams {
impl SWCurveConfig for TestSWUMapToCurveConfig {
/// COEFF_A = 1
const COEFF_A: F127 = F127_ONE;

Expand All @@ -208,7 +208,7 @@ mod test {
const GENERATOR: Affine<Self> = Affine::new_unchecked(MontFp!("62"), MontFp!("70"));
}

impl SWUParams for TestSWUMapToCurveParams {
impl SWUConfig for TestSWUMapToCurveConfig {
const ZETA: F127 = MontFp!("-1");
}

Expand Down Expand Up @@ -237,9 +237,9 @@ mod test {
#[test]
fn hash_arbitary_string_to_curve_swu() {
let test_swu_to_curve_hasher = MapToCurveBasedHasher::<
Projective<TestSWUMapToCurveParams>,
Projective<TestSWUMapToCurveConfig>,
DefaultFieldHasher<Sha256, 128>,
SWUMap<TestSWUMapToCurveParams>,
SWUMap<TestSWUMapToCurveConfig>,
>::new(&[1])
.unwrap();

Expand All @@ -256,9 +256,9 @@ mod test {
/// elements should be mapped to curve successfully. everything can be mapped
#[test]
fn map_field_to_curve_swu() {
let test_map_to_curve = SWUMap::<TestSWUMapToCurveParams>::new().unwrap();
let test_map_to_curve = SWUMap::<TestSWUMapToCurveConfig>::new().unwrap();

let mut map_range: Vec<Affine<TestSWUMapToCurveParams>> = vec![];
let mut map_range: Vec<Affine<TestSWUMapToCurveConfig>> = vec![];
for current_field_element in 0..127 {
map_range.push(
test_map_to_curve
Expand Down
40 changes: 20 additions & 20 deletions ec/src/hashing/curve_maps/wb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
AffineRepr,
};

use super::swu::{SWUMap, SWUParams};
use super::swu::{SWUConfig, SWUMap};
type BaseField<MP> = <MP as CurveConfig>::BaseField;

/// [`IsogenyMap`] defines an isogeny between curves of
Expand Down Expand Up @@ -70,20 +70,20 @@ where
/// From [\[WB2019\]]
///
/// - [\[WB2019\]] <http://dx.doi.org/10.46586/tches.v2019.i4.154-179>
pub trait WBParams: SWCurveConfig + Sized {
pub trait WBConfig: SWCurveConfig + Sized {
// The isogenous curve should be defined over the same base field but it can have
// different scalar field type IsogenousCurveScalarField :
type IsogenousCurve: SWUParams<BaseField = BaseField<Self>>;
type IsogenousCurve: SWUConfig<BaseField = BaseField<Self>>;

const ISOGENY_MAP: IsogenyMap<'static, Self::IsogenousCurve, Self>;
}

pub struct WBMap<P: WBParams> {
pub struct WBMap<P: WBConfig> {
swu_field_curve_hasher: SWUMap<P::IsogenousCurve>,
curve_params: PhantomData<fn() -> P>,
}

impl<P: WBParams> MapToCurve<Projective<P>> for WBMap<P> {
impl<P: WBConfig> MapToCurve<Projective<P>> for WBMap<P> {
/// Constructs a new map if `P` represents a valid map.
fn new() -> Result<Self, HashToCurveError> {
match P::ISOGENY_MAP.apply(P::IsogenousCurve::GENERATOR) {
Expand Down Expand Up @@ -119,8 +119,8 @@ mod test {
use crate::{
hashing::{
curve_maps::{
swu::SWUParams,
wb::{IsogenyMap, WBMap, WBParams},
swu::SWUConfig,
wb::{IsogenyMap, WBConfig, WBMap},
},
map_to_curve_hasher::MapToCurveBasedHasher,
HashToCurve,
Expand All @@ -141,9 +141,9 @@ mod test {
const F127_ONE: F127 = MontFp!("1");

/// The struct defining our parameters for the target curve of hashing
struct TestWBF127MapToCurveParams;
struct TestWBF127MapToCurveConfig;

impl CurveConfig for TestWBF127MapToCurveParams {
impl CurveConfig for TestWBF127MapToCurveConfig {
const COFACTOR: &'static [u64] = &[1];

#[rustfmt::skip]
Expand All @@ -155,7 +155,7 @@ mod test {

/// E: Elliptic Curve defined by y^2 = x^3 + 3 over Finite
/// Field of size 127
impl SWCurveConfig for TestWBF127MapToCurveParams {
impl SWCurveConfig for TestWBF127MapToCurveConfig {
/// COEFF_A = 0
const COEFF_A: F127 = F127_ZERO;

Expand All @@ -171,12 +171,12 @@ mod test {
/// E_isogenous : Elliptic Curve defined by y^2 = x^3 + 109*x + 124 over Finite
/// Field of size 127
/// Isogenous to E : y^2 = x^3 + 3
struct TestSWU127MapToIsogenousCurveParams;
struct TestSWU127MapToIsogenousCurveConfig;

/// First we define the isogenous curve
/// sage: E_isogenous.order()
/// 127
impl CurveConfig for TestSWU127MapToIsogenousCurveParams {
impl CurveConfig for TestSWU127MapToIsogenousCurveConfig {
const COFACTOR: &'static [u64] = &[1];

#[rustfmt::skip]
Expand All @@ -188,7 +188,7 @@ mod test {

/// E_isogenous : Elliptic Curve defined by y^2 = x^3 + 109*x + 124 over Finite
/// Field of size 127
impl SWCurveConfig for TestSWU127MapToIsogenousCurveParams {
impl SWCurveConfig for TestSWU127MapToIsogenousCurveConfig {
/// COEFF_A = 109
const COEFF_A: F127 = MontFp!("109");

Expand All @@ -201,7 +201,7 @@ mod test {
}

/// SWU parameters for E_isogenous
impl SWUParams for TestSWU127MapToIsogenousCurveParams {
impl SWUConfig for TestSWU127MapToIsogenousCurveConfig {
/// NON-SQUARE = - 1
const ZETA: F127 = MontFp!("-1");
}
Expand All @@ -223,8 +223,8 @@ mod test {
/// - 46*x^8 - 61*x^7 - 16*x^6 - 55*x^5 + 18*x^4 + 23*x^3 - 24*x^2 - 18*x + 32)
const ISOGENY_MAP_TESTWBF127: IsogenyMap<
'_,
TestSWU127MapToIsogenousCurveParams,
TestWBF127MapToCurveParams,
TestSWU127MapToIsogenousCurveConfig,
TestWBF127MapToCurveConfig,
> = IsogenyMap {
x_map_numerator: &[
MontFp!("4"),
Expand Down Expand Up @@ -303,8 +303,8 @@ mod test {
MontFp!("1"),
],
};
impl WBParams for TestWBF127MapToCurveParams {
type IsogenousCurve = TestSWU127MapToIsogenousCurveParams;
impl WBConfig for TestWBF127MapToCurveConfig {
type IsogenousCurve = TestSWU127MapToIsogenousCurveConfig;

const ISOGENY_MAP: super::IsogenyMap<'static, Self::IsogenousCurve, Self> =
ISOGENY_MAP_TESTWBF127;
Expand All @@ -316,9 +316,9 @@ mod test {
fn hash_arbitrary_string_to_curve_wb() {
use sha2::Sha256;
let test_wb_to_curve_hasher = MapToCurveBasedHasher::<
Projective<TestWBF127MapToCurveParams>,
Projective<TestWBF127MapToCurveConfig>,
DefaultFieldHasher<Sha256, 128>,
WBMap<TestWBF127MapToCurveParams>,
WBMap<TestWBF127MapToCurveConfig>,
>::new(&[1])
.unwrap();

Expand Down
16 changes: 7 additions & 9 deletions ec/src/hashing/tests/suites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use ark_test_curves::{
};

use ark_ff::{Field, PrimeField};
use ark_test_curves::bls12_381::{
g1::Parameters as G1Parameters, g2::Parameters as G2Parameters, Fq, Fq2,
};
use ark_test_curves::bls12_381::{g1::Config as G1Config, g2::Config as G2Config, Fq, Fq2};
use sha2::Sha256;

#[test]
Expand All @@ -38,15 +36,15 @@ fn run_test_w(data: &SuiteVector) -> Result<(), Failed> {
let hasher;
let m;
let g1_mapper = MapToCurveBasedHasher::<
Projective<G1Parameters>,
Projective<G1Config>,
DefaultFieldHasher<Sha256, 128>,
WBMap<G1Parameters>,
WBMap<G1Config>,
>::new(dst)
.unwrap();
let g2_mapper = MapToCurveBasedHasher::<
Projective<G2Parameters>,
Projective<G2Config>,
DefaultFieldHasher<Sha256, 128>,
WBMap<G2Parameters>,
WBMap<G2Config>,
>::new(dst)
.unwrap();
match data.curve.as_str() {
Expand Down Expand Up @@ -79,7 +77,7 @@ fn run_test_w(data: &SuiteVector) -> Result<(), Failed> {
match data.curve.as_str() {
"BLS12-381 G1" => {
let got = g1_mapper.hash(&v.msg.as_bytes()).unwrap();
let want = Affine::<G1Parameters>::new_unchecked(
let want = Affine::<G1Config>::new_unchecked(
Fq::from_base_prime_field_elems(&x[..]).unwrap(),
Fq::from_base_prime_field_elems(&y[..]).unwrap(),
);
Expand All @@ -95,7 +93,7 @@ fn run_test_w(data: &SuiteVector) -> Result<(), Failed> {
},
"BLS12-381 G2" => {
let got = g2_mapper.hash(&v.msg.as_bytes()).unwrap();
let want = Affine::<G2Parameters>::new_unchecked(
let want = Affine::<G2Config>::new_unchecked(
Fq2::from_base_prime_field_elems(&x[..]).unwrap(),
Fq2::from_base_prime_field_elems(&y[..]).unwrap(),
);
Expand Down
28 changes: 14 additions & 14 deletions ec/src/models/bls12/g1.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
use crate::{
bls12::Bls12Parameters,
bls12::Bls12Config,
short_weierstrass::{Affine, Projective},
AffineRepr, CurveGroup,
};
use ark_serialize::*;
use ark_std::vec::Vec;

pub type G1Affine<P> = Affine<<P as Bls12Parameters>::G1Parameters>;
pub type G1Projective<P> = Projective<<P as Bls12Parameters>::G1Parameters>;
pub type G1Affine<P> = Affine<<P as Bls12Config>::G1Config>;
pub type G1Projective<P> = Projective<<P as Bls12Config>::G1Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: Bls12Parameters"),
Debug(bound = "P: Bls12Parameters"),
PartialEq(bound = "P: Bls12Parameters"),
Eq(bound = "P: Bls12Parameters")
Clone(bound = "P: Bls12Config"),
Debug(bound = "P: Bls12Config"),
PartialEq(bound = "P: Bls12Config"),
Eq(bound = "P: Bls12Config")
)]
pub struct G1Prepared<P: Bls12Parameters>(pub G1Affine<P>);
pub struct G1Prepared<P: Bls12Config>(pub G1Affine<P>);

impl<P: Bls12Parameters> From<G1Affine<P>> for G1Prepared<P> {
impl<P: Bls12Config> From<G1Affine<P>> for G1Prepared<P> {
fn from(other: G1Affine<P>) -> Self {
G1Prepared(other)
}
}

impl<P: Bls12Parameters> From<G1Projective<P>> for G1Prepared<P> {
impl<P: Bls12Config> From<G1Projective<P>> for G1Prepared<P> {
fn from(q: G1Projective<P>) -> Self {
q.into_affine().into()
}
}

impl<'a, P: Bls12Parameters> From<&'a G1Affine<P>> for G1Prepared<P> {
impl<'a, P: Bls12Config> From<&'a G1Affine<P>> for G1Prepared<P> {
fn from(other: &'a G1Affine<P>) -> Self {
G1Prepared(*other)
}
}

impl<'a, P: Bls12Parameters> From<&'a G1Projective<P>> for G1Prepared<P> {
impl<'a, P: Bls12Config> From<&'a G1Projective<P>> for G1Prepared<P> {
fn from(q: &'a G1Projective<P>) -> Self {
q.into_affine().into()
}
}

impl<P: Bls12Parameters> G1Prepared<P> {
impl<P: Bls12Config> G1Prepared<P> {
pub fn is_zero(&self) -> bool {
self.0.is_zero()
}
}

impl<P: Bls12Parameters> Default for G1Prepared<P> {
impl<P: Bls12Config> Default for G1Prepared<P> {
fn default() -> Self {
G1Prepared(G1Affine::<P>::generator())
}
Expand Down
Loading