Move load3 and load4 to new utils module and remove #[allow(dead_code)].

This commit is contained in:
Isis Lovecruft 2017-02-21 06:06:46 +00:00
parent 4b738c7e19
commit e4d041836e
Failed to extract signature
4 changed files with 35 additions and 21 deletions

View file

@ -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) {

View file

@ -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.

View file

@ -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;

31
src/utils.rs Normal file
View file

@ -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
// <http://creativecommons.org/publicdomain/zero/.0/> for full details.
//
// Authors:
// - Isis Agora Lovecruft <isis@patternsinthevoid.net>
// - Henry de Valence <hdevalence@hdevalence.ca>
//! 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)
}