mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Move CTAssignable trait to util.rs from curve.rs
This commit is contained in:
parent
42c2578f4c
commit
098ff2ffca
2 changed files with 10 additions and 9 deletions
11
src/curve.rs
11
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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue