Remove std feature (#459)

All of the existing usages of `std` can be replaced with `alloc`.

They are legacy usages from before when liballoc was stabilized.
This commit is contained in:
Tony Arcieri 2022-12-08 13:05:59 -07:00 committed by GitHub
parent 6b56edf776
commit 1013560fe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 35 additions and 79 deletions

View file

@ -114,10 +114,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
# This filter selects no benchmarks, so we don't run any, only build them.
- name: Build u32 bench
run: env RUSTFLAGS="--cfg curve25519_dalek_bits=\"32\"" cargo bench "nonexistentbenchmark"
run: env RUSTFLAGS="--cfg curve25519_dalek_bits=\"32\"" cargo build --benches
- name: Build u64 bench
run: env RUSTFLAGS="--cfg curve25519_dalek_bits=\"64\"" cargo bench "nonexistentbenchmark"
run: env RUSTFLAGS="--cfg curve25519_dalek_bits=\"64\"" cargo build --benches
- name: Build default (host native) bench
run: cargo bench "nonexistentbenchmark"
run: cargo build --benches

View file

@ -36,11 +36,12 @@ bincode = "1"
criterion = { version = "0.4.0", features = ["html_reports"] }
hex = "0.4.2"
rand = "0.8"
rand_core = { version = "0.6", default-features = false }
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
[[bench]]
name = "dalek_benchmarks"
harness = false
required-features = ["rand_core"]
[dependencies]
cfg-if = "1"
@ -56,8 +57,7 @@ fiat-crypto = { version = "0.1.6", optional = true}
[features]
nightly = ["subtle/nightly"]
default = ["std"]
std = ["alloc", "subtle/std", "rand_core/std"]
default = ["alloc"]
alloc = ["zeroize/alloc"]
# fiat-crypto backend with formally-verified field arithmetic

View file

@ -11,6 +11,8 @@
#![allow(non_snake_case)]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::cmp::Ordering;
@ -18,9 +20,6 @@ use crate::edwards::EdwardsPoint;
use crate::scalar::Scalar;
use crate::traits::VartimeMultiscalarMul;
#[allow(unused_imports)]
use crate::prelude::*;
/// Implements a version of Pippenger's algorithm.
///
/// The algorithm works as follows:
@ -62,8 +61,6 @@ use crate::prelude::*;
/// This algorithm is adapted from section 4 of <https://eprint.iacr.org/2012/549.pdf>.
pub struct Pippenger;
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl VartimeMultiscalarMul for Pippenger {
type Point = EdwardsPoint;

View file

@ -11,6 +11,8 @@
#![allow(non_snake_case)]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::cmp::Ordering;
@ -23,9 +25,6 @@ use crate::traits::Identity;
use crate::traits::VartimePrecomputedMultiscalarMul;
use crate::window::{NafLookupTable5, NafLookupTable8};
#[allow(unused_imports)]
use crate::prelude::*;
#[allow(missing_docs)]
pub struct VartimePrecomputedStraus {
static_lookup_tables: Vec<NafLookupTable8<AffineNielsPoint>>,

View file

@ -13,6 +13,8 @@
#![allow(non_snake_case)]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::cmp::Ordering;
@ -21,9 +23,6 @@ use crate::scalar::Scalar;
use crate::traits::MultiscalarMul;
use crate::traits::VartimeMultiscalarMul;
#[allow(unused_imports)]
use crate::prelude::*;
/// Perform multiscalar multiplication by the interleaved window
/// method, also known as Straus' method (since it was apparently
/// [first published][solution] by Straus in 1964, as a solution to [a

View file

@ -11,7 +11,7 @@
use crate::traits::Identity;
use std::ops::{Add, Neg, Sub};
use core::ops::{Add, Neg, Sub};
use subtle::Choice;
use subtle::ConditionallySelectable;

View file

@ -14,13 +14,10 @@ pub mod variable_base;
pub mod vartime_double_base;
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub mod straus;
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub mod precomputed_straus;
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub mod pippenger;

View file

@ -9,6 +9,8 @@
#![allow(non_snake_case)]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::cmp::Ordering;
@ -17,16 +19,11 @@ use crate::edwards::EdwardsPoint;
use crate::scalar::Scalar;
use crate::traits::{Identity, VartimeMultiscalarMul};
#[allow(unused_imports)]
use crate::prelude::*;
/// Implements a version of Pippenger's algorithm.
///
/// See the documentation in the serial `scalar_mul::pippenger` module for details.
pub struct Pippenger;
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl VartimeMultiscalarMul for Pippenger {
type Point = EdwardsPoint;

View file

@ -11,6 +11,8 @@
#![allow(non_snake_case)]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::cmp::Ordering;
@ -21,9 +23,6 @@ use crate::traits::Identity;
use crate::traits::VartimePrecomputedMultiscalarMul;
use crate::window::{NafLookupTable5, NafLookupTable8};
#[allow(unused_imports)]
use crate::prelude::*;
pub struct VartimePrecomputedStraus {
static_lookup_tables: Vec<NafLookupTable8<CachedPoint>>,
}

View file

@ -11,6 +11,8 @@
#![allow(non_snake_case)]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::cmp::Ordering;
@ -22,9 +24,6 @@ use crate::scalar::Scalar;
use crate::traits::{Identity, MultiscalarMul, VartimeMultiscalarMul};
use crate::window::{LookupTable, NafLookupTable5};
#[allow(unused_imports)]
use crate::prelude::*;
/// Multiscalar multiplication using interleaved window / Straus'
/// method. See the `Straus` struct in the serial backend for more
/// details.

View file

@ -129,9 +129,6 @@ use crate::window::LookupTableRadix256;
use crate::window::LookupTableRadix32;
use crate::window::LookupTableRadix64;
#[allow(unused_imports)]
use crate::prelude::*;
use crate::traits::BasepointTable;
use crate::traits::ValidityCheck;
use crate::traits::{Identity, IsIdentity};
@ -710,7 +707,6 @@ impl<'a, 'b> Mul<&'b EdwardsPoint> for &'a Scalar {
// forward to a specific backend implementation.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl MultiscalarMul for EdwardsPoint {
type Point = EdwardsPoint;
@ -743,7 +739,6 @@ impl MultiscalarMul for EdwardsPoint {
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl VartimeMultiscalarMul for EdwardsPoint {
type Point = EdwardsPoint;
@ -783,11 +778,9 @@ impl VartimeMultiscalarMul for EdwardsPoint {
// decouple stability of the inner type from the stability of the
// outer type.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub struct VartimeEdwardsPrecomputation(scalar_mul::precomputed_straus::VartimePrecomputedStraus);
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl VartimePrecomputedMultiscalarMul for VartimeEdwardsPrecomputation {
type Point = EdwardsPoint;
@ -1126,6 +1119,9 @@ mod test {
use crate::scalar::Scalar;
use subtle::ConditionallySelectable;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
/// X coordinate of the basepoint.
/// = 15112221349535400772501151409588531511454012693041857206046113283949847762202
static BASE_X_COORD_BYTES: [u8; 32] = [

View file

@ -167,7 +167,6 @@ impl FieldElement {
///
/// When an input `FieldElement` is zero, its value is unchanged.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub fn batch_invert(inputs: &mut [FieldElement]) {
// Montgomerys Trick and Fast Implementation of Masked AES
// Genelle, Prouff and Quisquater

View file

@ -32,7 +32,8 @@
#[macro_use]
extern crate alloc;
#[cfg(feature = "std")]
// TODO: move std-dependent tests to `tests/`
#[cfg(test)]
#[macro_use]
extern crate std;
@ -78,10 +79,6 @@ pub mod backend;
#[cfg(not(docsrs))]
pub(crate) mod backend;
// Crate-local prelude (for alloc-dependent features like `Vec`)
pub(crate) mod prelude;
// Generic code for window lookups
pub(crate) mod window;

View file

@ -374,6 +374,9 @@ mod test {
use super::*;
use crate::constants;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
#[cfg(feature = "rand_core")]
use rand_core::OsRng;
@ -480,9 +483,9 @@ mod test {
];
#[test]
#[cfg(feature = "alloc")] // Vec
#[cfg(feature = "alloc")]
fn montgomery_elligator_correct() {
let bytes: alloc::vec::Vec<u8> = (0u8..32u8).collect();
let bytes: Vec<u8> = (0u8..32u8).collect();
let bits_in: [u8; 32] = (&bytes[..]).try_into().expect("Range invariant broken");
let fe = FieldElement::from_bytes(&bits_in);

View file

@ -1,19 +0,0 @@
// -*- mode: rust; -*-
//
// This file is part of curve25519-dalek.
// Copyright (c) 2016-2021 isis lovecruft
// Copyright (c) 2016-2019 Henry de Valence
// See LICENSE for licensing information.
//
// Authors:
// - isis agora lovecruft <isis@patternsinthevoid.net>
// - Henry de Valence <hdevalence@hdevalence.ca>
//! Crate-local prelude (for alloc-dependent features like `Vec`)
// TODO: switch to alloc::prelude
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::vec::Vec;
#[cfg(feature = "std")]
pub use std::vec::Vec;

View file

@ -158,6 +158,9 @@
//! [ristretto_main]:
//! https://ristretto.group/
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::fmt::Debug;
use core::iter::Sum;
@ -186,9 +189,6 @@ use zeroize::Zeroize;
use crate::edwards::EdwardsBasepointTable;
use crate::edwards::EdwardsPoint;
#[allow(unused_imports)]
use crate::prelude::*;
use crate::scalar::Scalar;
use crate::traits::BasepointTable;
@ -525,7 +525,6 @@ impl RistrettoPoint {
/// # }
/// ```
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub fn double_and_compress_batch<'a, I>(points: I) -> Vec<CompressedRistretto>
where
I: IntoIterator<Item = &'a RistrettoPoint>,
@ -932,7 +931,6 @@ define_mul_variants!(LHS = Scalar, RHS = RistrettoPoint, Output = RistrettoPoint
// forward to the EdwardsPoint implementations.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl MultiscalarMul for RistrettoPoint {
type Point = RistrettoPoint;
@ -949,7 +947,6 @@ impl MultiscalarMul for RistrettoPoint {
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl VartimeMultiscalarMul for RistrettoPoint {
type Point = RistrettoPoint;
@ -970,11 +967,9 @@ impl VartimeMultiscalarMul for RistrettoPoint {
// decouple stability of the inner type from the stability of the
// outer type.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub struct VartimeRistrettoPrecomputation(scalar_mul::precomputed_straus::VartimePrecomputedStraus);
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
impl VartimePrecomputedMultiscalarMul for VartimeRistrettoPrecomputation {
type Point = RistrettoPoint;

View file

@ -150,9 +150,6 @@ use core::ops::{Add, AddAssign};
use core::ops::{Mul, MulAssign};
use core::ops::{Sub, SubAssign};
#[allow(unused_imports)]
use crate::prelude::*;
use cfg_if::cfg_if;
#[cfg(feature = "rand_core")]
@ -797,7 +794,6 @@ impl Scalar {
/// # }
/// ```
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub fn batch_invert(inputs: &mut [Scalar]) -> Scalar {
// This code is essentially identical to the FieldElement
// implementation, and is documented there. Unfortunately,
@ -1257,6 +1253,9 @@ mod test {
use super::*;
use crate::constants;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
/// x = 2238329342913194256032495932344128051776374960164957527413114840482143558222
pub static X: Scalar = Scalar {
bytes: [