From e4d041836e2311f114806bff5a09ef12981b2d1d Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Tue, 21 Feb 2017 06:06:46 +0000 Subject: [PATCH] Move load3 and load4 to new utils module and remove #[allow(dead_code)]. --- src/field.rs | 21 ++------------------- src/lib.rs | 1 + src/scalar.rs | 3 +-- src/utils.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 src/utils.rs diff --git a/src/field.rs b/src/field.rs index 9ed0aea..7d5bc44 100644 --- a/src/field.rs +++ b/src/field.rs @@ -29,6 +29,8 @@ use subtle::byte_is_nonzero; use subtle::CTAssignable; use subtle::CTEq; +use utils::{load3, load4}; + /// FieldElements are represented as an array of ten "Limbs", which are radix /// 25.5, that is, each Limb of a FieldElement alternates between being /// represented as a factor of 2^25 or 2^26 more than the last corresponding @@ -193,25 +195,6 @@ impl CTAssignable for FieldElement { } } -/// Convert an array of (at least) three bytes into an i64. -#[inline] -#[allow(dead_code)] -pub fn load3(input: &[u8]) -> i64 { - (input[0] as i64) - | ((input[1] as i64) << 8) - | ((input[2] as i64) << 16) -} - -/// Convert an array of (at least) four bytes into an i64. -#[inline] -#[allow(dead_code)] -pub fn load4(input: &[u8]) -> i64 { - (input[0] as i64) - | ((input[1] as i64) << 8) - | ((input[2] as i64) << 16) - | ((input[3] as i64) << 24) -} - impl FieldElement { /// Invert the sign of this field element pub fn negate(&mut self) { diff --git a/src/lib.rs b/src/lib.rs index 2007ada..7855923 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,6 +50,7 @@ pub mod scalar; // Constant-time functions and other miscelaneous utilities. pub mod subtle; +pub mod utils; // Low-level curve and point constants, as well as pre-computed curve group elements. diff --git a/src/scalar.rs b/src/scalar.rs index a1ec8d0..85c77be 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -36,9 +36,8 @@ use core::ops::{Neg}; #[cfg(feature = "std")] use rand::Rng; -// XXX should these be in a utility module ? use constants; -use field::{load3, load4}; +use utils::{load3, load4}; use subtle::CTAssignable; use subtle::CTEq; use subtle::arrays_equal_ct; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..ad53166 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,31 @@ +// -*- mode: rust; -*- +// +// To the extent possible under law, the authors have waived all copyright and +// related or neighboring rights to curve25519-dalek, using the Creative +// Commons "CC0" public domain dedication. See +// for full details. +// +// Authors: +// - Isis Agora Lovecruft +// - Henry de Valence + +//! Miscellaneous common utility function. + +/// Convert an array of (at least) three bytes into an i64. +#[inline] +//#[allow(dead_code)] +pub fn load3(input: &[u8]) -> i64 { + (input[0] as i64) + | ((input[1] as i64) << 8) + | ((input[2] as i64) << 16) +} + +/// Convert an array of (at least) four bytes into an i64. +#[inline] +//#[allow(dead_code)] +pub fn load4(input: &[u8]) -> i64 { + (input[0] as i64) + | ((input[1] as i64) << 8) + | ((input[2] as i64) << 16) + | ((input[3] as i64) << 24) +}