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"
]
[dependencies]
rand = "0.3"
arrayref = "0.3.2"
[dependencies.arrayref]
version = "0.3.3"
[dependencies.rand]
optional = true
version = "0.3"
[features]
default = ["std"]
std = ["rand"]
# The development profile, used for `cargo build`.
[profile.dev]

View file

@ -77,10 +77,10 @@
// affine and projective cakes and eat both of them too.
#![allow(non_snake_case)]
use std::fmt::Debug;
use std::iter::Iterator;
use std::ops::{Add, Sub, Neg, Index};
use std::cmp::{PartialEq, Eq};
use core::fmt::Debug;
use core::iter::Iterator;
use core::ops::{Add, Sub, Neg, Index};
use core::cmp::{PartialEq, Eq};
use constants;
use field::FieldElement;
@ -101,9 +101,9 @@ use util::CTAssignable;
#[derive(Copy, Clone)]
pub struct CompressedEdwardsY(pub [u8; 32]);
impl Debug for CompressedEdwardsY {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "CompressedEdwardsY: {:?}", &self.0[..])
impl Debug for CompressedPoint {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "CompressedPoint: {:?}", &self.0[..])
}
}
@ -782,35 +782,35 @@ impl 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)",
&self.X, &self.Y, &self.Z, &self.T)
}
}
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)",
&self.X, &self.Y, &self.Z)
}
}
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)",
&self.X, &self.Y, &self.Z, &self.T)
}
}
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)",
&self.y_plus_x, &self.y_minus_x, &self.xy2d)
}
}
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)",
&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
//! implementations.
use std::clone::Clone;
use std::fmt::Debug;
use std::ops::{Add, AddAssign};
use std::ops::{Sub, SubAssign};
use std::ops::{Mul, MulAssign};
use std::ops::{Index, IndexMut};
use std::cmp::{Eq, PartialEq};
use std::ops::Neg;
use core::clone::Clone;
use core::fmt::Debug;
use core::ops::{Add, AddAssign};
use core::ops::{Sub, SubAssign};
use core::ops::{Mul, MulAssign};
use core::ops::{Index, IndexMut};
use core::cmp::{Eq, PartialEq};
use core::ops::Neg;
use util::byte_is_nonzero;
use util::CTAssignable;
@ -66,7 +66,7 @@ impl PartialEq for FieldElement {
impl Eq 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[..])
}
}

View file

@ -9,6 +9,7 @@
// - Isis Agora Lovecruft <isis@patternsinthevoid.net>
// - Henry de Valence <hdevalence@hdevalence.ca>
#![no_std]
#![allow(unused_features)]
#![feature(test)]
#![deny(missing_docs)] // refuse to compile if documentation is missing
@ -37,6 +38,7 @@ extern crate test;
#[macro_use]
extern crate arrayref;
#[cfg(feature = "std")]
extern crate rand;
// 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
//! limbs.
use std::ops::{Index, IndexMut};
use core::clone::Clone;
use core::ops::{Index, IndexMut};
#[cfg(feature = "std")]
use rand::Rng;
// XXX should these be in a utility module ?
@ -104,6 +106,7 @@ impl Scalar {
/// # Returns
///
/// A random scalar within /l.
#[cfg(feature = "std")]
pub fn random<T: Rng>(csprng: &mut T) -> Self {
let mut scalar_bytes = [0u8; 64];
csprng.fill_bytes(&mut scalar_bytes);