Remove boxes

This commit is contained in:
Henry de Valence 2017-04-25 21:55:19 -07:00 committed by Henry & Isis
parent 0678e619cc
commit 127169c151
4 changed files with 10 additions and 25 deletions

View file

@ -36,12 +36,10 @@ version = "^0.6"
version = "0.4" version = "0.4"
[features] [features]
nightly = ["basepoint_table_creation", "radix_51"] nightly = ["radix_51"]
default = ["std"] default = ["std"]
std = ["rand"] std = ["rand"]
yolocrypto = [] yolocrypto = []
# Needs nightly for placement new
basepoint_table_creation = []
bench = [] bench = []
# Radix-51 arithmetic using u128 # Radix-51 arithmetic using u128
radix_51 = [] radix_51 = []

View file

@ -92,11 +92,6 @@ use subtle::CTAssignable;
use subtle::CTEq; use subtle::CTEq;
use subtle::CTNegatable; use subtle::CTNegatable;
#[cfg(all(not(feature = "std"), feature = "basepoint_table_creation"))]
use collections::boxed::Box;
#[cfg(all(feature = "std", feature = "basepoint_table_creation"))]
use std::boxed::Box;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Compressed points // Compressed points
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -877,12 +872,11 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a EdwardsBasepointTable {
impl EdwardsBasepointTable { impl EdwardsBasepointTable {
/// Create a table of precomputed multiples of `basepoint`. /// Create a table of precomputed multiples of `basepoint`.
#[cfg(feature="basepoint_table_creation")] pub fn create(basepoint: &ExtendedPoint) -> EdwardsBasepointTable {
pub fn create(basepoint: &ExtendedPoint) -> Box<EdwardsBasepointTable> {
// Create the table storage // Create the table storage
// XXX can we be assured that this is not allocated on the stack?
// XXX can we skip the initialization without too much unsafety? // XXX can we skip the initialization without too much unsafety?
let mut table = box EdwardsBasepointTable([[AffineNielsPoint::identity(); 8]; 32]); // stick 30K on the stack and call it a day.
let mut table = EdwardsBasepointTable([[AffineNielsPoint::identity(); 8]; 32]);
let mut P = basepoint.clone(); let mut P = basepoint.clone();
for i in 0..32 { for i in 0..32 {
// P = (16^2)^i * B // P = (16^2)^i * B
@ -894,7 +888,7 @@ impl EdwardsBasepointTable {
} }
P = P.mult_by_pow_2(8); P = P.mult_by_pow_2(8);
} }
return table table
} }
} }
@ -1352,7 +1346,7 @@ mod test {
fn test_precomputed_basepoint_mult() { fn test_precomputed_basepoint_mult() {
let table = EdwardsBasepointTable::create(&constants::ED25519_BASEPOINT); let table = EdwardsBasepointTable::create(&constants::ED25519_BASEPOINT);
let aB_1 = &constants::ED25519_BASEPOINT_TABLE * &A_SCALAR; let aB_1 = &constants::ED25519_BASEPOINT_TABLE * &A_SCALAR;
let aB_2 = &(*table) * &A_SCALAR; let aB_2 = &table * &A_SCALAR;
assert_eq!(aB_1.compress_edwards(), aB_2.compress_edwards()); assert_eq!(aB_1.compress_edwards(), aB_2.compress_edwards());
} }

View file

@ -32,11 +32,6 @@ use subtle::CTNegatable;
use core::ops::{Add, Sub, Neg}; use core::ops::{Add, Sub, Neg};
use core::ops::{Mul, MulAssign}; use core::ops::{Mul, MulAssign};
#[cfg(all(not(feature = "std"), feature = "basepoint_table_creation"))]
use collections::boxed::Box;
#[cfg(all(feature = "std", feature = "basepoint_table_creation"))]
use std::boxed::Box;
use curve; use curve;
use curve::ExtendedPoint; use curve::ExtendedPoint;
use curve::EdwardsBasepointTable; use curve::EdwardsBasepointTable;
@ -278,10 +273,8 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a DecafBasepointTable {
impl DecafBasepointTable { impl DecafBasepointTable {
/// Create a precomputed table of multiples of the given `basepoint`. /// Create a precomputed table of multiples of the given `basepoint`.
#[cfg(feature = "basepoint_table_creation")] pub fn create(basepoint: &DecafPoint) -> DecafBasepointTable {
pub fn create(basepoint: &DecafPoint) -> Box<DecafBasepointTable> { DecafBasepointTable(EdwardsBasepointTable::create(&basepoint.0))
let edwards_table = EdwardsBasepointTable::create(&basepoint.0);
box DecafBasepointTable(*edwards_table)
} }
} }

View file

@ -11,10 +11,10 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(collections))] #![cfg_attr(not(feature = "std"), feature(collections))]
#![cfg_attr(feature = "nightly", feature(box_syntax))]
#![cfg_attr(feature = "nightly", feature(i128_type))] #![cfg_attr(feature = "nightly", feature(i128_type))]
#![allow(unused_features)]
#![cfg_attr(feature = "bench", feature(test))] #![cfg_attr(feature = "bench", feature(test))]
#![allow(unused_features)]
#![deny(missing_docs)] // refuse to compile if documentation is missing #![deny(missing_docs)] // refuse to compile if documentation is missing
//! # curve25519-dalek //! # curve25519-dalek