|
@ -559,37 +559,14 @@ where |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
|
|
mod fp {
|
|
|
|
|
|
use ff::PrimeField;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(PrimeField)]
|
|
|
|
|
|
#[PrimeFieldModulus = "28948022309329048855892746252171976963363056481941560715954676764349967630337"]
|
|
|
|
|
|
#[PrimeFieldGenerator = "5"]
|
|
|
|
|
|
#[PrimeFieldReprEndianness = "little"]
|
|
|
|
|
|
pub struct Fp([u64; 4]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
|
|
mod fq {
|
|
|
|
|
|
use ff::PrimeField;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(PrimeField)]
|
|
|
|
|
|
#[PrimeFieldModulus = "28948022309329048855892746252171976963363056481941647379679742748393362948097"]
|
|
|
|
|
|
#[PrimeFieldGenerator = "5"]
|
|
|
|
|
|
#[PrimeFieldReprEndianness = "little"]
|
|
|
|
|
|
pub struct Fq([u64; 4]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
mod tests {
|
|
|
use super::*;
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
#[test]
|
|
|
fn test_ecc_ops() {
|
|
|
fn test_ecc_ops() {
|
|
|
use super::{fp::Fp, fq::Fq};
|
|
|
|
|
|
|
|
|
type Fp = pasta_curves::pallas::Base;
|
|
|
|
|
|
type Fq = pasta_curves::pallas::Scalar;
|
|
|
|
|
|
|
|
|
// perform some curve arithmetic
|
|
|
// perform some curve arithmetic
|
|
|
let a = Point::<Fp, Fq>::random_vartime();
|
|
|
let a = Point::<Fp, Fq>::random_vartime();
|
|
@ -601,35 +578,35 @@ mod tests { |
|
|
|
|
|
|
|
|
// perform the same computation by translating to pasta_curve types
|
|
|
// perform the same computation by translating to pasta_curve types
|
|
|
let a_pasta = EpAffine::from_xy(
|
|
|
let a_pasta = EpAffine::from_xy(
|
|
|
pasta_curves::Fp::from_repr(a.x.to_repr().0).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(a.y.to_repr().0).unwrap(),
|
|
|
|
|
|
|
|
|
pasta_curves::Fp::from_repr(a.x.to_repr()).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(a.y.to_repr()).unwrap(),
|
|
|
)
|
|
|
)
|
|
|
.unwrap();
|
|
|
.unwrap();
|
|
|
let b_pasta = EpAffine::from_xy(
|
|
|
let b_pasta = EpAffine::from_xy(
|
|
|
pasta_curves::Fp::from_repr(b.x.to_repr().0).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(b.y.to_repr().0).unwrap(),
|
|
|
|
|
|
|
|
|
pasta_curves::Fp::from_repr(b.x.to_repr()).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(b.y.to_repr()).unwrap(),
|
|
|
)
|
|
|
)
|
|
|
.unwrap();
|
|
|
.unwrap();
|
|
|
let c_pasta = (a_pasta + b_pasta).to_affine();
|
|
|
let c_pasta = (a_pasta + b_pasta).to_affine();
|
|
|
let d_pasta = (a_pasta + a_pasta).to_affine();
|
|
|
let d_pasta = (a_pasta + a_pasta).to_affine();
|
|
|
let e_pasta = a_pasta
|
|
|
let e_pasta = a_pasta
|
|
|
.mul(pasta_curves::Fq::from_repr(s.to_repr().0).unwrap())
|
|
|
|
|
|
|
|
|
.mul(pasta_curves::Fq::from_repr(s.to_repr()).unwrap())
|
|
|
.to_affine();
|
|
|
.to_affine();
|
|
|
|
|
|
|
|
|
// transform c, d, and e into pasta_curve types
|
|
|
// transform c, d, and e into pasta_curve types
|
|
|
let c_pasta_2 = EpAffine::from_xy(
|
|
|
let c_pasta_2 = EpAffine::from_xy(
|
|
|
pasta_curves::Fp::from_repr(c.x.to_repr().0).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(c.y.to_repr().0).unwrap(),
|
|
|
|
|
|
|
|
|
pasta_curves::Fp::from_repr(c.x.to_repr()).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(c.y.to_repr()).unwrap(),
|
|
|
)
|
|
|
)
|
|
|
.unwrap();
|
|
|
.unwrap();
|
|
|
let d_pasta_2 = EpAffine::from_xy(
|
|
|
let d_pasta_2 = EpAffine::from_xy(
|
|
|
pasta_curves::Fp::from_repr(d.x.to_repr().0).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(d.y.to_repr().0).unwrap(),
|
|
|
|
|
|
|
|
|
pasta_curves::Fp::from_repr(d.x.to_repr()).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(d.y.to_repr()).unwrap(),
|
|
|
)
|
|
|
)
|
|
|
.unwrap();
|
|
|
.unwrap();
|
|
|
let e_pasta_2 = EpAffine::from_xy(
|
|
|
let e_pasta_2 = EpAffine::from_xy(
|
|
|
pasta_curves::Fp::from_repr(e.x.to_repr().0).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(e.y.to_repr().0).unwrap(),
|
|
|
|
|
|
|
|
|
pasta_curves::Fp::from_repr(e.x.to_repr()).unwrap(),
|
|
|
|
|
|
pasta_curves::Fp::from_repr(e.y.to_repr()).unwrap(),
|
|
|
)
|
|
|
)
|
|
|
.unwrap();
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|