|
1 | | -use ark_ec::{AffineRepr, CurveGroup, Group, ScalarMul, VariableBaseMSM}; |
2 | | -use ark_ed_on_bls12_377::{EdwardsAffine, EdwardsConfig, EdwardsProjective}; |
| 1 | +use ark_ec::{ |
| 2 | + twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig}, |
| 3 | + AffineRepr, CurveConfig, CurveGroup, Group, ScalarMul, VariableBaseMSM, |
| 4 | +}; |
| 5 | +use ark_ed_on_bls12_377::EdwardsConfig; |
| 6 | +use ark_ff::MontFp; |
3 | 7 | use ark_serialize::Valid; |
4 | 8 |
|
5 | | -use crate::{Fq, Fr}; |
| 9 | +use crate::{ |
| 10 | + constants::{GENERATOR_X, GENERATOR_Y}, |
| 11 | + Fq, Fr, |
| 12 | +}; |
6 | 13 |
|
7 | 14 | pub mod affine; |
8 | 15 | pub mod projective; |
9 | 16 |
|
10 | 17 | pub use affine::AffineElement; |
11 | 18 | pub use projective::Element; |
12 | 19 |
|
| 20 | +#[derive(Clone, Default, PartialEq, Eq)] |
| 21 | +pub struct Decaf377EdwardsConfig; |
| 22 | + |
| 23 | +// These types should not be exported. They are similar to `EdwardsAffine` and |
| 24 | +// `EdwardsProjective` from the `ark_ed_on_bls12_377` crate, except using our own |
| 25 | +// `Decaf377Config` that has the cofactor set to 1. Consumers of this |
| 26 | +// library should use the `AffineElement` and `Element` (projective) |
| 27 | +// types. |
| 28 | +pub(crate) type EdwardsAffine = Affine<Decaf377EdwardsConfig>; |
| 29 | +pub(crate) type EdwardsProjective = Projective<Decaf377EdwardsConfig>; |
| 30 | + |
| 31 | +impl CurveConfig for Decaf377EdwardsConfig { |
| 32 | + type BaseField = Fq; |
| 33 | + type ScalarField = Fr; |
| 34 | + |
| 35 | + const COFACTOR: &'static [u64] = &[1]; |
| 36 | + |
| 37 | + const COFACTOR_INV: Fr = MontFp!("1"); |
| 38 | +} |
| 39 | + |
| 40 | +impl TECurveConfig for Decaf377EdwardsConfig { |
| 41 | + /// COEFF_A = -1 |
| 42 | + const COEFF_A: Fq = <EdwardsConfig as ark_ec::twisted_edwards::TECurveConfig>::COEFF_A; |
| 43 | + |
| 44 | + /// COEFF_D = 3021 |
| 45 | + const COEFF_D: Fq = <EdwardsConfig as ark_ec::twisted_edwards::TECurveConfig>::COEFF_D; |
| 46 | + |
| 47 | + const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y); |
| 48 | + |
| 49 | + type MontCurveConfig = EdwardsConfig; |
| 50 | + |
| 51 | + /// Multiplication by `a` is just negation. |
| 52 | + #[inline(always)] |
| 53 | + fn mul_by_a(elem: Self::BaseField) -> Self::BaseField { |
| 54 | + -elem |
| 55 | + } |
| 56 | + |
| 57 | + fn is_in_correct_subgroup_assuming_on_curve(_: &Affine<Self>) -> bool { |
| 58 | + true |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +impl MontCurveConfig for Decaf377EdwardsConfig { |
| 63 | + const COEFF_A: Fq = <EdwardsConfig as ark_ec::twisted_edwards::MontCurveConfig>::COEFF_A; |
| 64 | + |
| 65 | + const COEFF_B: Fq = <EdwardsConfig as ark_ec::twisted_edwards::MontCurveConfig>::COEFF_B; |
| 66 | + |
| 67 | + type TECurveConfig = Decaf377EdwardsConfig; |
| 68 | +} |
| 69 | + |
13 | 70 | impl Valid for Element { |
14 | 71 | fn check(&self) -> Result<(), ark_serialize::SerializationError> { |
15 | | - todo!() |
| 72 | + Ok(()) |
16 | 73 | } |
17 | 74 | } |
18 | 75 |
|
@@ -84,7 +141,7 @@ impl CurveGroup for Element { |
84 | 141 |
|
85 | 142 | impl Valid for AffineElement { |
86 | 143 | fn check(&self) -> Result<(), ark_serialize::SerializationError> { |
87 | | - todo!() |
| 144 | + Ok(()) |
88 | 145 | } |
89 | 146 | } |
90 | 147 |
|
|
0 commit comments