Move CTAssignable trait to util.rs from curve.rs

This commit is contained in:
Henry de Valence 2017-01-06 12:26:43 -05:00
parent 42c2578f4c
commit 098ff2ffca
2 changed files with 10 additions and 9 deletions

View file

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

View file

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