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