From 098ff2ffca98774a0c963f52a9afb62c7d49d64f Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 6 Jan 2017 12:26:43 -0500 Subject: [PATCH] Move CTAssignable trait to util.rs from curve.rs --- src/curve.rs | 11 ++--------- src/util.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/curve.rs b/src/curve.rs index 971cdb5..079907c 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -86,6 +86,7 @@ use constants; use field::FieldElement; use scalar::Scalar; use util::bytes_equal_ct; +use util::CTAssignable; // ------------------------------------------------------------------------ // Compressed points @@ -282,15 +283,6 @@ impl Identity for PreComputedPoint { // Constant-time assignment // ------------------------------------------------------------------------ -/// Trait for items which can be conditionally assigned in constant time. -pub trait CTAssignable { - /// If `choice == 1u8`, assign `other` to `self`. - /// Otherwise, leave `self` unchanged. - /// Executes in constant time. - // XXX this trait should be extracted? - fn conditional_assign(&mut self, other: &Self, choice: u8); -} - impl CTAssignable for CachedPoint { fn conditional_assign(&mut self, other: &CachedPoint, choice: u8) { self.Y_plus_X.conditional_assign(&other.Y_plus_X, choice); @@ -806,6 +798,7 @@ mod test { use test::Bencher; use field::FieldElement; use scalar::Scalar; + use util::CTAssignable; use constants; use super::*; use super::select_precomputed_point; diff --git a/src/util.rs b/src/util.rs index d94a853..1391ef8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -11,6 +11,14 @@ //! Utility functions and tools for constant-time comparisons. +/// Trait for items which can be conditionally assigned in constant time. +pub trait CTAssignable { + /// If `choice == 1u8`, assign `other` to `self`. + /// Otherwise, leave `self` unchanged. + /// Executes in constant time. + fn conditional_assign(&mut self, other: &Self, choice: u8); +} + /// Check equality of two bytes in constant time. /// /// # Return