Merge pull request #28 from zcash/27-remove-std-feature-flag

Remove `std` feature flag
This commit is contained in:
str4d 2021-12-25 12:36:29 +00:00 committed by GitHub
commit 738fb60796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 59 deletions

View file

@ -22,6 +22,8 @@ and this project adheres to Rust's notion of
- `FieldExt::{from_bytes, read, to_bytes, write}`
(use `ff::PrimeField::{from_repr, to_repr}` instead).
- `FieldExt::rand` (use `ff::Field::random` instead).
- `CurveAffine::{read, write}`
(use `group::GroupEncoding::{from_bytes, to_bytes}` instead).
## [0.2.1] - 2021-09-17
### Changed

View file

@ -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"]

View file

@ -7,8 +7,6 @@
mod curves;
mod fields;
pub(crate) use fields::*;
pub use curves::*;
pub use fields::*;

View file

@ -1,29 +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,
io::{self, Read, Write},
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>
@ -90,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,
@ -123,21 +122,6 @@ pub trait CurveAffine:
/// always be true unless an "unchecked" API was used.
fn is_on_curve(&self) -> Choice;
/// Reads a compressed element from the buffer and attempts to parse it
/// using `from_bytes`.
fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
let mut compressed = Self::Repr::default();
reader.read_exact(compressed.as_mut())?;
Option::from(Self::from_bytes(&compressed))
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point encoding in proof"))
}
/// Writes an element in compressed form to the buffer.
fn write<W: Write>(&self, writer: &mut W) -> io::Result<()> {
let compressed = self.to_bytes();
writer.write_all(compressed.as_ref())
}
/// Returns the curve constant $a$.
fn a() -> Self::Base;
@ -146,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.
///
@ -185,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 {

View file

@ -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> {

View file

@ -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};

View file

@ -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;

View file

@ -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;