From f734f35a2668fa9c715185dfd2e27451670f6d5a Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Mon, 29 Jan 2024 19:18:38 -0500 Subject: [PATCH] unify on_curve module --- src/lib.rs | 5 +++-- src/on_curve.rs | 27 ++++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 55d7d1c..70db8b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,9 @@ pub use fields::{fp::Fp, fq::Fq, fr::Fr}; mod sign; +mod on_curve; +use on_curve::OnCurve; + cfg_if! { if #[cfg(feature = "arkworks")] { pub mod bls12_377; @@ -20,7 +23,6 @@ cfg_if! { mod error; mod field_ext; mod invsqrt; - mod on_curve; mod ops; pub mod rand; pub mod serialize; @@ -37,7 +39,6 @@ cfg_if! { pub use bls12_377::Bls12_377; - use on_curve::OnCurve; /// Return the conventional generator for `decaf377`. pub fn basepoint() -> Element { diff --git a/src/on_curve.rs b/src/on_curve.rs index c37f76d..39313ed 100644 --- a/src/on_curve.rs +++ b/src/on_curve.rs @@ -1,16 +1,22 @@ -use ark_ec::{ - models::{twisted_edwards::Projective, twisted_edwards::TECurveConfig}, - Group, -}; -use ark_ff::{BigInteger, Field, PrimeField, Zero}; -use ark_serialize::CanonicalSerialize; +use cfg_if::cfg_if; -use crate::constants; +cfg_if! { + if #[cfg(feature = "arkworks")] { + use ark_ec::{ + models::{twisted_edwards::Projective, twisted_edwards::TECurveConfig}, + Group, + }; + use ark_ff::{BigInteger, Field, PrimeField, Zero}; + use ark_serialize::CanonicalSerialize; + use crate::constants; + } +} pub trait OnCurve { fn is_on_curve(&self) -> bool; } +#[cfg(feature = "arkworks")] impl OnCurve for Projective

{ #[allow(non_snake_case)] fn is_on_curve(&self) -> bool { @@ -36,3 +42,10 @@ impl OnCurve for Projective

{ on_curve && on_segre_embedding && z_non_zero && point_order_2r } } + +#[cfg(not(feature = "arkworks"))] +impl OnCurve for Element { + fn is_on_curve(&self) -> bool { + todo!() + } +}