Skip to content

Commit

Permalink
unify on_curve module
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Jan 30, 2024
1 parent 1dd9977 commit f734f35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub use fields::{fp::Fp, fq::Fq, fr::Fr};

mod sign;

mod on_curve;
use on_curve::OnCurve;

Check warning on line 14 in src/lib.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

unused import: `on_curve::OnCurve`

Check warning on line 14 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build without alloc

unused import: `on_curve::OnCurve`

cfg_if! {
if #[cfg(feature = "arkworks")] {
pub mod bls12_377;
Expand All @@ -20,7 +23,6 @@ cfg_if! {
mod error;
mod field_ext;
mod invsqrt;
mod on_curve;
mod ops;
pub mod rand;
pub mod serialize;
Expand All @@ -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 {
Expand Down
27 changes: 20 additions & 7 deletions src/on_curve.rs
Original file line number Diff line number Diff line change
@@ -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<P: TECurveConfig> OnCurve for Projective<P> {
#[allow(non_snake_case)]
fn is_on_curve(&self) -> bool {
Expand All @@ -36,3 +42,10 @@ impl<P: TECurveConfig> OnCurve for Projective<P> {
on_curve && on_segre_embedding && z_non_zero && point_order_2r
}
}

#[cfg(not(feature = "arkworks"))]
impl OnCurve for Element {

Check failure on line 47 in src/on_curve.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find type `Element` in this scope

Check failure on line 47 in src/on_curve.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find type `Element` in this scope
fn is_on_curve(&self) -> bool {
todo!()
}
}

0 comments on commit f734f35

Please sign in to comment.