mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Move load3 and load4 to new utils module and remove #[allow(dead_code)].
This commit is contained in:
parent
4b738c7e19
commit
e4d041836e
4 changed files with 35 additions and 21 deletions
21
src/field.rs
21
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) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
31
src/utils.rs
Normal 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)
|
||||
}
|
||||
Loading…
Reference in a new issue