From f2883028dc8bebdb4ef19448e12a0f75f4ab2b1e Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Tue, 1 Aug 2017 02:09:34 +0000 Subject: [PATCH] Use subtle version 0.2.0. * CLOSES PR#66 https://github.com/isislovecruft/curve25519-dalek/pull/66 --- Cargo.toml | 4 ++-- src/curve.rs | 25 +++++++++++++------------ src/decaf.rs | 9 +++++---- src/field.rs | 12 ++++++------ src/field_32bit.rs | 4 ++-- src/field_64bit.rs | 4 ++-- src/scalar.rs | 17 +++++++++-------- 7 files changed, 39 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dc614bf..321e8a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ version = "0.3" version = "0.6" [dependencies.subtle] -version = "^0.1" +version = "^0.2" default-features = false [dependencies.generic-array] @@ -47,7 +47,7 @@ version = "0.6" version = "0.6" [features] -nightly = ["radix_51"] +nightly = ["radix_51", "subtle/nightly"] default = ["std"] std = ["rand", "subtle/std"] alloc = [] diff --git a/src/curve.rs b/src/curve.rs index 08e80e5..95146e7 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -90,11 +90,12 @@ use core::ops::Index; use constants; use field::FieldElement; use scalar::Scalar; -use subtle::arrays_equal; + +use subtle::slices_equal; use subtle::bytes_equal; -use subtle::CTAssignable; -use subtle::CTEq; -use subtle::CTNegatable; +use subtle::ConditionallyAssignable; +use subtle::ConditionallyNegatable; +use subtle::Equal; // ------------------------------------------------------------------------ // Compressed points @@ -486,7 +487,7 @@ impl ValidityCheck for ExtendedPoint { // Constant-time assignment // ------------------------------------------------------------------------ -impl CTAssignable for ProjectiveNielsPoint { +impl ConditionallyAssignable for ProjectiveNielsPoint { fn conditional_assign(&mut self, other: &ProjectiveNielsPoint, choice: u8) { self.Y_plus_X.conditional_assign(&other.Y_plus_X, choice); self.Y_minus_X.conditional_assign(&other.Y_minus_X, choice); @@ -495,7 +496,7 @@ impl CTAssignable for ProjectiveNielsPoint { } } -impl CTAssignable for AffineNielsPoint { +impl ConditionallyAssignable for AffineNielsPoint { fn conditional_assign(&mut self, other: &AffineNielsPoint, choice: u8) { // PreComputedGroupElementCMove() self.y_plus_x.conditional_assign(&other.y_plus_x, choice); @@ -504,7 +505,7 @@ impl CTAssignable for AffineNielsPoint { } } -impl CTAssignable for ExtendedPoint { +impl ConditionallyAssignable for ExtendedPoint { fn conditional_assign(&mut self, other: &ExtendedPoint, choice: u8) { self.X.conditional_assign(&other.X, choice); self.Y.conditional_assign(&other.Y, choice); @@ -517,9 +518,9 @@ impl CTAssignable for ExtendedPoint { // Constant-time Equality // ------------------------------------------------------------------------ -impl CTEq for ExtendedPoint { +impl Equal for ExtendedPoint { fn ct_eq(&self, other: &ExtendedPoint) -> u8 { - arrays_equal(self.compress_edwards().as_bytes(), + slices_equal(self.compress_edwards().as_bytes(), other.compress_edwards().as_bytes()) } } @@ -533,7 +534,7 @@ pub trait IsIdentity { /// Implement generic identity equality testing for a point representations /// which have constant-time equality testing and a defined identity /// constructor. -impl IsIdentity for T where T: CTEq + Identity { +impl IsIdentity for T where T: Equal + Identity { fn is_identity(&self) -> bool { self.ct_eq(&T::identity()) == 1u8 } @@ -1156,7 +1157,7 @@ impl ExtendedPoint { /// x ≤ 8`, compute `x * B` in constant time, i.e., without branching /// on x or using it as an array index. fn select_precomputed_point(x: i8, points: &[T; 8]) -> T - where T: Identity + CTAssignable, for<'a> &'a T: Neg + where T: Identity + ConditionallyAssignable, for<'a> &'a T: Neg { debug_assert!(x >= -8); debug_assert!(x <= 8); @@ -1371,7 +1372,7 @@ mod test { use decaf::DecafPoint; use field::FieldElement; use scalar::Scalar; - use subtle::CTAssignable; + use subtle::ConditionallyAssignable; use constants; use super::*; diff --git a/src/decaf.rs b/src/decaf.rs index ff9c3b9..c2dad53 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -32,8 +32,6 @@ use generic_array::typenum::U32; use constants; use field::FieldElement; -use subtle::CTAssignable; -use subtle::CTNegatable; use core::ops::{Add, Sub, Neg}; use core::ops::{AddAssign, SubAssign}; @@ -46,6 +44,9 @@ use curve::EdwardsBasepointTable; use curve::Identity; use scalar::Scalar; +use subtle::ConditionallyAssignable; +use subtle::ConditionallyNegatable; + // ------------------------------------------------------------------------ // Compressed points // ------------------------------------------------------------------------ @@ -631,7 +632,7 @@ impl DecafBasepointTable { // Constant-time conditional assignment // ------------------------------------------------------------------------ -impl CTAssignable for DecafPoint { +impl ConditionallyAssignable for DecafPoint { /// Conditionally assign `other` to `self`, if `choice == 1u8`. /// /// # Example @@ -640,7 +641,7 @@ impl CTAssignable for DecafPoint { /// # extern crate subtle; /// # extern crate curve25519_dalek; /// # - /// # use subtle::CTAssignable; + /// # use subtle::ConditionallyAssignable; /// # /// # use curve25519_dalek::curve::Identity; /// # use curve25519_dalek::decaf::DecafPoint; diff --git a/src/field.rs b/src/field.rs index c29c6de..3fe0950 100644 --- a/src/field.rs +++ b/src/field.rs @@ -22,10 +22,10 @@ use core::cmp::{Eq, PartialEq}; -use subtle::arrays_equal; +use subtle::slices_equal; use subtle::byte_is_nonzero; -use subtle::CTAssignable; -use subtle::CTEq; +use subtle::ConditionallyAssignable; +use subtle::Equal; use constants; @@ -62,7 +62,7 @@ impl PartialEq for FieldElement { } } -impl CTEq for FieldElement { +impl Equal for FieldElement { /// Test equality between two `FieldElement`s. Since the /// internal representation is not canonical, the field elements /// are normalized to wire format before comparison. @@ -71,7 +71,7 @@ impl CTEq for FieldElement { /// /// `1u8` if the two `FieldElement`s are equal, and `0u8` otherwise. fn ct_eq(&self, other: &FieldElement) -> u8 { - arrays_equal(&self.to_bytes(), &other.to_bytes()) + slices_equal(&self.to_bytes(), &other.to_bytes()) } } @@ -323,7 +323,7 @@ impl FieldElement { #[cfg(test)] mod test { use field::*; - use subtle::CTNegatable; + use subtle::ConditionallyNegatable; /// Random element a of GF(2^255-19), from Sage /// a = 1070314506888354081329385823235218444233221\ diff --git a/src/field_32bit.rs b/src/field_32bit.rs index 2c1a2ba..0814b85 100644 --- a/src/field_32bit.rs +++ b/src/field_32bit.rs @@ -30,7 +30,7 @@ use core::ops::{Sub, SubAssign}; use core::ops::{Mul, MulAssign}; use core::ops::Neg; -use subtle::CTAssignable; +use subtle::ConditionallyAssignable; use utils::{load3, load4}; @@ -189,7 +189,7 @@ impl<'a> Neg for &'a FieldElement32 { } } -impl CTAssignable for FieldElement32 { +impl ConditionallyAssignable for FieldElement32 { fn conditional_assign(&mut self, f: &FieldElement32, choice: u8) { let mask = -(choice as i32); for i in 0..10 { diff --git a/src/field_64bit.rs b/src/field_64bit.rs index 4e10a62..46428fe 100644 --- a/src/field_64bit.rs +++ b/src/field_64bit.rs @@ -25,7 +25,7 @@ use core::ops::{Sub, SubAssign}; use core::ops::{Mul, MulAssign}; use core::ops::Neg; -use subtle::CTAssignable; +use subtle::ConditionallyAssignable; use utils::load8; @@ -166,7 +166,7 @@ impl<'a> Neg for &'a FieldElement64 { } } -impl CTAssignable for FieldElement64 { +impl ConditionallyAssignable for FieldElement64 { fn conditional_assign(&mut self, f: &FieldElement64, choice: u8) { let mask = (-(choice as i64)) as u64; for i in 0..5 { diff --git a/src/scalar.rs b/src/scalar.rs index e8beab7..be3cde2 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -45,9 +45,10 @@ use generic_array::typenum::U64; use constants; use utils::{load3, load4}; -use subtle::CTAssignable; -use subtle::CTEq; -use subtle::arrays_equal; + +use subtle::slices_equal; +use subtle::ConditionallyAssignable; +use subtle::Equal; /// The `Scalar` struct represents an element in ℤ/lℤ, where /// @@ -76,18 +77,18 @@ impl PartialEq for Scalar { /// /// True if they are equal, and false otherwise. fn eq(&self, other: &Self) -> bool { - arrays_equal(&self.0, &other.0) == 1u8 + slices_equal(&self.0, &other.0) == 1u8 } } -impl CTEq for Scalar { +impl Equal for Scalar { /// Test equality between two `Scalar`s in constant time. /// /// # Returns /// /// `1u8` if they are equal, and `0u8` otherwise. fn ct_eq(&self, other: &Self) -> u8 { - arrays_equal(&self.0, &other.0) + slices_equal(&self.0, &other.0) } } @@ -154,14 +155,14 @@ impl<'a> Neg for &'a Scalar { } } -impl CTAssignable for Scalar { +impl ConditionallyAssignable for Scalar { /// Conditionally assign another Scalar to this one. /// /// ``` /// # extern crate curve25519_dalek; /// # extern crate subtle; /// # use curve25519_dalek::scalar::Scalar; - /// # use subtle::CTAssignable; + /// # use subtle::ConditionallyAssignable; /// # fn main() { /// let a = Scalar([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);