parent
69cf8f5f77
commit
21fd9e2c1b
|
@ -25,7 +25,7 @@ rand_xorshift = "0.3"
|
|||
[[bench]]
|
||||
name = "hashtocurve"
|
||||
harness = false
|
||||
required-features = ["std"]
|
||||
required-features = ["alloc"]
|
||||
|
||||
[[bench]]
|
||||
name = "fp"
|
||||
|
@ -38,7 +38,7 @@ harness = false
|
|||
[[bench]]
|
||||
name = "point"
|
||||
harness = false
|
||||
required-features = ["std"]
|
||||
required-features = ["alloc"]
|
||||
|
||||
[dependencies]
|
||||
blake2b_simd = { version = "0.5", default-features = false }
|
||||
|
@ -52,8 +52,7 @@ subtle = { version = "2.3", default-features = false }
|
|||
lazy_static = { version = "1.4.0", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["bits", "sqrt-table", "std"]
|
||||
default = ["bits", "sqrt-table"]
|
||||
alloc = ["group/alloc"]
|
||||
bits = ["ff/bits"]
|
||||
sqrt-table = ["alloc", "lazy_static"]
|
||||
std = ["alloc"]
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
mod curves;
|
||||
mod fields;
|
||||
|
||||
pub(crate) use fields::*;
|
||||
|
||||
pub use curves::*;
|
||||
pub use fields::*;
|
||||
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
//! This module contains the `Curve`/`CurveAffine` abstractions that allow us to
|
||||
//! write code that generalizes over a pair of groups.
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
use group::prime::{PrimeCurve, PrimeCurveAffine};
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
use super::{FieldExt, Group};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::{
|
||||
boxed::Box,
|
||||
ops::{Add, Mul, Sub},
|
||||
};
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::boxed::Box;
|
||||
#[cfg(feature = "alloc")]
|
||||
use core::ops::{Add, Mul, Sub};
|
||||
|
||||
/// This trait is a common interface for dealing with elements of an elliptic
|
||||
/// curve group in a "projective" form, where that arithmetic is usually more
|
||||
/// efficient.
|
||||
///
|
||||
/// Currently requires the `std` feature flag because of `hash_to_curve`, and
|
||||
/// `CurveAffine::{read, write}`.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
/// Requires the `alloc` feature flag because of `hash_to_curve`.
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
|
||||
pub trait CurveExt:
|
||||
PrimeCurve<Affine = <Self as CurveExt>::AffineExt>
|
||||
+ group::Group<Scalar = <Self as CurveExt>::ScalarExt>
|
||||
|
@ -89,8 +87,10 @@ pub trait CurveExt:
|
|||
|
||||
/// This trait is the affine counterpart to `Curve` and is used for
|
||||
/// serialization, storage in memory, and inspection of $x$ and $y$ coordinates.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
///
|
||||
/// Requires the `alloc` feature flag because of `hash_to_curve` on [`CurveExt`].
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
|
||||
pub trait CurveAffine:
|
||||
PrimeCurveAffine<
|
||||
Scalar = <Self as CurveAffine>::ScalarExt,
|
||||
|
@ -130,15 +130,15 @@ pub trait CurveAffine:
|
|||
}
|
||||
|
||||
/// The affine coordinates of a point on an elliptic curve.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Coordinates<C: CurveAffine> {
|
||||
pub(crate) x: C::Base,
|
||||
pub(crate) y: C::Base,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<C: CurveAffine> Coordinates<C> {
|
||||
/// Returns the x-coordinate.
|
||||
///
|
||||
|
@ -169,7 +169,7 @@ impl<C: CurveAffine> Coordinates<C> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<C: CurveAffine> ConditionallySelectable for Coordinates<C> {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
Coordinates {
|
||||
|
|
|
@ -6,8 +6,8 @@ use core::fmt;
|
|||
use core::iter::Sum;
|
||||
use core::ops::{Add, Mul, Neg, Sub};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::boxed::Box;
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::boxed::Box;
|
||||
|
||||
use ff::{Field, PrimeField};
|
||||
use group::{
|
||||
|
@ -19,9 +19,10 @@ use rand::RngCore;
|
|||
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
|
||||
use super::{Fp, Fq};
|
||||
use crate::arithmetic::Group;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use crate::arithmetic::{Coordinates, CurveAffine, CurveExt, FieldExt, Group};
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::arithmetic::{Coordinates, CurveAffine, CurveExt, FieldExt};
|
||||
|
||||
macro_rules! new_curve_impl {
|
||||
(($($privacy:tt)*), $name:ident, $name_affine:ident, $iso:ident, $base:ident, $scalar:ident,
|
||||
|
@ -102,8 +103,8 @@ macro_rules! new_curve_impl {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
|
||||
impl group::WnafGroup for $name {
|
||||
fn recommended_wnaf_for_num_scalars(num_scalars: usize) -> usize {
|
||||
// Copied from bls12_381::g1, should be updated.
|
||||
|
@ -123,7 +124,8 @@ macro_rules! new_curve_impl {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
|
||||
impl CurveExt for $name {
|
||||
type ScalarExt = $scalar;
|
||||
type Base = $base;
|
||||
|
@ -695,7 +697,8 @@ macro_rules! new_curve_impl {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
|
||||
impl CurveAffine for $name_affine {
|
||||
type ScalarExt = $scalar;
|
||||
type Base = $base;
|
||||
|
@ -779,7 +782,6 @@ macro_rules! new_curve_impl {
|
|||
impl_binops_multiplicative!($name, $scalar);
|
||||
impl_binops_multiplicative_mixed!($name_affine, $scalar, $name);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Group for $name {
|
||||
type Scalar = $scalar;
|
||||
|
||||
|
@ -880,7 +882,7 @@ macro_rules! impl_projective_curve_specific {
|
|||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
macro_rules! impl_projective_curve_ext {
|
||||
($name:ident, $iso:ident, $base:ident, special_a0_b5) => {
|
||||
fn hash_to_curve<'a>(domain_prefix: &'a str) -> Box<dyn Fn(&[u8]) -> Self + 'a> {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
|
@ -25,7 +25,7 @@ pub mod arithmetic;
|
|||
pub mod pallas;
|
||||
pub mod vesta;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
mod hashtocurve;
|
||||
|
||||
pub use curves::*;
|
||||
|
@ -33,7 +33,7 @@ pub use fields::*;
|
|||
|
||||
pub extern crate group;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[test]
|
||||
fn test_endo_consistency() {
|
||||
use crate::arithmetic::{CurveExt, FieldExt};
|
||||
|
|
|
@ -14,7 +14,7 @@ pub type Point = Ep;
|
|||
/// A Pallas point in the affine coordinate space (or the point at infinity).
|
||||
pub type Affine = EpAffine;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[test]
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
fn test_iso_map() {
|
||||
|
@ -65,7 +65,7 @@ fn test_iso_map() {
|
|||
assert!(p2 == p.double());
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[test]
|
||||
fn test_iso_map_identity() {
|
||||
use crate::arithmetic::CurveExt;
|
||||
|
@ -100,7 +100,7 @@ fn test_iso_map_identity() {
|
|||
assert!(bool::from(p.is_identity()));
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[test]
|
||||
fn test_map_to_curve_simple_swu() {
|
||||
use crate::arithmetic::CurveExt;
|
||||
|
@ -135,7 +135,7 @@ fn test_map_to_curve_simple_swu() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[test]
|
||||
fn test_hash_to_curve() {
|
||||
use crate::arithmetic::CurveExt;
|
||||
|
|
|
@ -14,7 +14,7 @@ pub type Point = Eq;
|
|||
/// A Vesta point in the affine coordinate space (or the point at infinity).
|
||||
pub type Affine = EqAffine;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[test]
|
||||
fn test_map_to_curve_simple_swu() {
|
||||
use crate::arithmetic::CurveExt;
|
||||
|
@ -49,7 +49,7 @@ fn test_map_to_curve_simple_swu() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(feature = "alloc")]
|
||||
#[test]
|
||||
fn test_hash_to_curve() {
|
||||
use crate::arithmetic::CurveExt;
|
||||
|
|
Loading…
Reference in New Issue