From 2610ab872a6a0b4174455b52de461655df59e5fe Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Mon, 13 Mar 2017 16:28:43 -0700 Subject: [PATCH] Feature-gate basepoint table creation on a `nightly` feature --- Cargo.toml | 3 +++ src/curve.rs | 8 +++++--- src/lib.rs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 691f464..f0189e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,9 +33,12 @@ version = "^0.6" version = "0.4" [features] +nightly = ["basepoint_table_creation"] default = ["std"] std = ["rand"] yolocrypto = [] +# Needs nightly for placement new +basepoint_table_creation = [] # The development profile, used for `cargo build`. [profile.dev] diff --git a/src/curve.rs b/src/curve.rs index f90e69b..054b164 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -81,9 +81,6 @@ use core::fmt::Debug; use core::iter::Iterator; use core::ops::{Add, Sub, Neg}; -#[cfg(feature = "std")] -use std::boxed::Box; - use constants; use field::FieldElement; use scalar::Scalar; @@ -95,6 +92,8 @@ use subtle::CTNegatable; #[cfg(not(feature = "std"))] use collections::boxed::Box; +#[cfg(feature = "std")] +use std::boxed::Box; // ------------------------------------------------------------------------ // Compressed points @@ -831,6 +830,7 @@ pub struct EdwardsBasepointTable(pub [[AffineNielsPoint; 8]; 32]); impl EdwardsBasepointTable { /// Create a table of precomputed multiples of `basepoint`. + #[cfg(feature="basepoint_table_creation")] pub fn create(basepoint: &ExtendedPoint) -> Box { // Create the table storage // XXX can we be assured that this is not allocated on the stack? @@ -1312,6 +1312,7 @@ mod test { /// Test precomputed basepoint mult #[test] + #[cfg(feature="basepoint_table_creation")] fn test_precomputed_basepoint_mult() { let table = EdwardsBasepointTable::create(&constants::ED25519_BASEPOINT); let aB_1 = ExtendedPoint::basepoint_mult(&A_SCALAR); @@ -1487,6 +1488,7 @@ mod bench { b.iter(|| p1.mult_by_cofactor() ); } + #[cfg(feature="basepoint_table_creation")] #[bench] fn create_basepoint_table(b: &mut Bencher) { let aB = ExtendedPoint::basepoint_mult(&A_SCALAR); diff --git a/src/lib.rs b/src/lib.rs index bcacba1..b268354 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,9 +11,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(collections))] +#![cfg_attr(feature = "nightly", feature(box_syntax))] #![allow(unused_features)] #![feature(test)] -#![feature(box_syntax)] #![deny(missing_docs)] // refuse to compile if documentation is missing //! # curve25519-dalek