Rename subtle::arrays_equal_ct() to subtle::arrays_equal().

It's already obvious that it's constant-time because it's in the subtle
module.
This commit is contained in:
Isis Lovecruft 2017-05-26 21:25:31 +00:00
parent e74be0024d
commit 0c38718346
Failed to extract signature
4 changed files with 13 additions and 13 deletions

View file

@ -90,7 +90,7 @@ use core::ops::Index;
use constants; use constants;
use field::FieldElement; use field::FieldElement;
use scalar::Scalar; use scalar::Scalar;
use subtle::arrays_equal_ct; use subtle::arrays_equal;
use subtle::bytes_equal_ct; use subtle::bytes_equal_ct;
use subtle::CTAssignable; use subtle::CTAssignable;
use subtle::CTEq; use subtle::CTEq;
@ -518,8 +518,8 @@ impl CTAssignable for ExtendedPoint {
impl CTEq for ExtendedPoint { impl CTEq for ExtendedPoint {
fn ct_eq(&self, other: &ExtendedPoint) -> u8 { fn ct_eq(&self, other: &ExtendedPoint) -> u8 {
arrays_equal_ct( self.compress_edwards().as_bytes(), arrays_equal( self.compress_edwards().as_bytes(),
other.compress_edwards().as_bytes()) other.compress_edwards().as_bytes())
} }
} }

View file

@ -23,7 +23,7 @@ use core::ops::{Index, IndexMut};
use core::cmp::{Eq, PartialEq}; use core::cmp::{Eq, PartialEq};
use core::ops::Neg; use core::ops::Neg;
use subtle::arrays_equal_ct; use subtle::arrays_equal;
use subtle::byte_is_nonzero; use subtle::byte_is_nonzero;
use subtle::CTAssignable; use subtle::CTAssignable;
use subtle::CTEq; use subtle::CTEq;
@ -96,7 +96,7 @@ impl CTEq for FieldElement {
/// ///
/// `1u8` if the two `FieldElement`s are equal, and `0u8` otherwise. /// `1u8` if the two `FieldElement`s are equal, and `0u8` otherwise.
fn ct_eq(&self, other: &FieldElement) -> u8 { fn ct_eq(&self, other: &FieldElement) -> u8 {
arrays_equal_ct(&self.to_bytes(), &other.to_bytes()) arrays_equal(&self.to_bytes(), &other.to_bytes())
} }
} }

View file

@ -47,7 +47,7 @@ use constants;
use utils::{load3, load4}; use utils::{load3, load4};
use subtle::CTAssignable; use subtle::CTAssignable;
use subtle::CTEq; use subtle::CTEq;
use subtle::arrays_equal_ct; use subtle::arrays_equal;
/// The `Scalar` struct represents an element in /l, where /// The `Scalar` struct represents an element in /l, where
/// ///
@ -76,7 +76,7 @@ impl PartialEq for Scalar {
/// ///
/// True if they are equal, and false otherwise. /// True if they are equal, and false otherwise.
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
arrays_equal_ct(&self.0, &other.0) == 1u8 arrays_equal(&self.0, &other.0) == 1u8
} }
} }
@ -87,7 +87,7 @@ impl CTEq for Scalar {
/// ///
/// `1u8` if they are equal, and `0u8` otherwise. /// `1u8` if they are equal, and `0u8` otherwise.
fn ct_eq(&self, other: &Self) -> u8 { fn ct_eq(&self, other: &Self) -> u8 {
arrays_equal_ct(&self.0, &other.0) arrays_equal(&self.0, &other.0)
} }
} }

View file

@ -101,12 +101,12 @@ pub fn byte_is_nonzero(b: u8) -> u8 {
/// ///
/// ``` /// ```
/// # extern crate curve25519_dalek; /// # extern crate curve25519_dalek;
/// # use curve25519_dalek::subtle::arrays_equal_ct; /// # use curve25519_dalek::subtle::arrays_equal;
/// # fn main() { /// # fn main() {
/// let a: [u8; 3] = [0, 1, 2]; /// let a: [u8; 3] = [0, 1, 2];
/// let b: [u8; 3] = [1, 2, 3]; /// let b: [u8; 3] = [1, 2, 3];
/// ///
/// assert!(arrays_equal_ct(&a, &b) == 0); /// assert!(arrays_equal(&a, &b) == 0);
/// # } /// # }
/// ``` /// ```
/// ///
@ -114,12 +114,12 @@ pub fn byte_is_nonzero(b: u8) -> u8 {
/// ///
/// ``` /// ```
/// # extern crate curve25519_dalek; /// # extern crate curve25519_dalek;
/// # use curve25519_dalek::subtle::arrays_equal_ct; /// # use curve25519_dalek::subtle::arrays_equal;
/// # fn main() { /// # fn main() {
/// let a: [u8; 3] = [0, 1, 2]; /// let a: [u8; 3] = [0, 1, 2];
/// let b: [u8; 3] = [0, 1, 2]; /// let b: [u8; 3] = [0, 1, 2];
/// ///
/// assert!(arrays_equal_ct(&a, &b) == 1); /// assert!(arrays_equal(&a, &b) == 1);
/// # } /// # }
/// ``` /// ```
/// ///
@ -131,7 +131,7 @@ pub fn byte_is_nonzero(b: u8) -> u8 {
/// ///
/// Returns `1u8` if `a == b` and `0u8` otherwise. /// Returns `1u8` if `a == b` and `0u8` otherwise.
#[inline(always)] #[inline(always)]
pub fn arrays_equal_ct(a: &[u8; 32], b: &[u8; 32]) -> u8 { pub fn arrays_equal(a: &[u8; 32], b: &[u8; 32]) -> u8 {
let mut x: u8 = 0; let mut x: u8 = 0;
for i in 0..32 { for i in 0..32 {