Merge remote-tracking branch 'tarcieri/no-std' into develop

This commit is contained in:
Isis Lovecruft 2017-01-27 02:13:04 +00:00
commit d88b6c01c4
Failed to extract signature
5 changed files with 37 additions and 25 deletions

View file

@ -14,9 +14,16 @@ exclude = [
".gitignore" ".gitignore"
] ]
[dependencies] [dependencies.arrayref]
rand = "0.3" version = "0.3.3"
arrayref = "0.3.2"
[dependencies.rand]
optional = true
version = "0.3"
[features]
default = ["std"]
std = ["rand"]
# The development profile, used for `cargo build`. # The development profile, used for `cargo build`.
[profile.dev] [profile.dev]

View file

@ -77,10 +77,10 @@
// affine and projective cakes and eat both of them too. // affine and projective cakes and eat both of them too.
#![allow(non_snake_case)] #![allow(non_snake_case)]
use std::fmt::Debug; use core::fmt::Debug;
use std::iter::Iterator; use core::iter::Iterator;
use std::ops::{Add, Sub, Neg, Index}; use core::ops::{Add, Sub, Neg, Index};
use std::cmp::{PartialEq, Eq}; use core::cmp::{PartialEq, Eq};
use constants; use constants;
use field::FieldElement; use field::FieldElement;
@ -101,9 +101,9 @@ use util::CTAssignable;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct CompressedEdwardsY(pub [u8; 32]); pub struct CompressedEdwardsY(pub [u8; 32]);
impl Debug for CompressedEdwardsY { impl Debug for CompressedPoint {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "CompressedEdwardsY: {:?}", &self.0[..]) write!(f, "CompressedPoint: {:?}", &self.0[..])
} }
} }
@ -782,35 +782,35 @@ impl ExtendedPoint {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
impl Debug for ExtendedPoint { impl Debug for ExtendedPoint {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "ExtendedPoint(\n\tX: {:?},\n\tY: {:?},\n\tZ: {:?},\n\tT: {:?}\n)", write!(f, "ExtendedPoint(\n\tX: {:?},\n\tY: {:?},\n\tZ: {:?},\n\tT: {:?}\n)",
&self.X, &self.Y, &self.Z, &self.T) &self.X, &self.Y, &self.Z, &self.T)
} }
} }
impl Debug for ProjectivePoint { impl Debug for ProjectivePoint {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "ProjectivePoint(\n\tX: {:?},\n\tY: {:?},\n\tZ: {:?}\n)", write!(f, "ProjectivePoint(\n\tX: {:?},\n\tY: {:?},\n\tZ: {:?}\n)",
&self.X, &self.Y, &self.Z) &self.X, &self.Y, &self.Z)
} }
} }
impl Debug for CompletedPoint { impl Debug for CompletedPoint {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "CompletedPoint(\n\tX: {:?},\n\tY: {:?},\n\tZ: {:?},\n\tT: {:?}\n)", write!(f, "CompletedPoint(\n\tX: {:?},\n\tY: {:?},\n\tZ: {:?},\n\tT: {:?}\n)",
&self.X, &self.Y, &self.Z, &self.T) &self.X, &self.Y, &self.Z, &self.T)
} }
} }
impl Debug for PreComputedPoint { impl Debug for PreComputedPoint {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "PreComputedPoint(\n\ty_plus_x: {:?},\n\ty_minus_x: {:?},\n\txy2d: {:?}\n)", write!(f, "PreComputedPoint(\n\ty_plus_x: {:?},\n\ty_minus_x: {:?},\n\txy2d: {:?}\n)",
&self.y_plus_x, &self.y_minus_x, &self.xy2d) &self.y_plus_x, &self.y_minus_x, &self.xy2d)
} }
} }
impl Debug for CachedPoint { impl Debug for CachedPoint {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "CachedPoint(\n\tY_plus_X: {:?},\n\tY_minus_X: {:?},\n\tZ: {:?},\n\tT2d: {:?}\n)", write!(f, "CachedPoint(\n\tY_plus_X: {:?},\n\tY_minus_X: {:?},\n\tZ: {:?},\n\tT2d: {:?}\n)",
&self.Y_plus_X, &self.Y_minus_X, &self.Z, &self.T2d) &self.Y_plus_X, &self.Y_minus_X, &self.Z, &self.T2d)
} }

View file

@ -15,14 +15,14 @@
//! Based on Adam Langley's curve25519-donna and (Golang) ed25519 //! Based on Adam Langley's curve25519-donna and (Golang) ed25519
//! implementations. //! implementations.
use std::clone::Clone; use core::clone::Clone;
use std::fmt::Debug; use core::fmt::Debug;
use std::ops::{Add, AddAssign}; use core::ops::{Add, AddAssign};
use std::ops::{Sub, SubAssign}; use core::ops::{Sub, SubAssign};
use std::ops::{Mul, MulAssign}; use core::ops::{Mul, MulAssign};
use std::ops::{Index, IndexMut}; use core::ops::{Index, IndexMut};
use std::cmp::{Eq, PartialEq}; use core::cmp::{Eq, PartialEq};
use std::ops::Neg; use core::ops::Neg;
use util::byte_is_nonzero; use util::byte_is_nonzero;
use util::CTAssignable; use util::CTAssignable;
@ -66,7 +66,7 @@ impl PartialEq for FieldElement {
impl Eq for FieldElement {} impl Eq for FieldElement {}
impl Debug for FieldElement { impl Debug for FieldElement {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "FieldElement: {:?}", &self.0[..]) write!(f, "FieldElement: {:?}", &self.0[..])
} }
} }

View file

@ -9,6 +9,7 @@
// - Isis Agora Lovecruft <isis@patternsinthevoid.net> // - Isis Agora Lovecruft <isis@patternsinthevoid.net>
// - Henry de Valence <hdevalence@hdevalence.ca> // - Henry de Valence <hdevalence@hdevalence.ca>
#![no_std]
#![allow(unused_features)] #![allow(unused_features)]
#![feature(test)] #![feature(test)]
#![deny(missing_docs)] // refuse to compile if documentation is missing #![deny(missing_docs)] // refuse to compile if documentation is missing
@ -37,6 +38,7 @@ extern crate test;
#[macro_use] #[macro_use]
extern crate arrayref; extern crate arrayref;
#[cfg(feature = "std")]
extern crate rand; extern crate rand;
// Modules for low-level operations directly on field elements and curve points. // Modules for low-level operations directly on field elements and curve points.

View file

@ -29,8 +29,10 @@
//! between two scalars, the `UnpackedScalar` struct is stored as //! between two scalars, the `UnpackedScalar` struct is stored as
//! limbs. //! limbs.
use std::ops::{Index, IndexMut}; use core::clone::Clone;
use core::ops::{Index, IndexMut};
#[cfg(feature = "std")]
use rand::Rng; use rand::Rng;
// XXX should these be in a utility module ? // XXX should these be in a utility module ?
@ -104,6 +106,7 @@ impl Scalar {
/// # Returns /// # Returns
/// ///
/// A random scalar within /l. /// A random scalar within /l.
#[cfg(feature = "std")]
pub fn random<T: Rng>(csprng: &mut T) -> Self { pub fn random<T: Rng>(csprng: &mut T) -> Self {
let mut scalar_bytes = [0u8; 64]; let mut scalar_bytes = [0u8; 64];
csprng.fill_bytes(&mut scalar_bytes); csprng.fill_bytes(&mut scalar_bytes);