Update to subtle 2.0

This commit is contained in:
Sean Bowe 2019-01-06 22:47:02 -07:00
parent a50b09caaa
commit e3f219ae84
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
3 changed files with 24 additions and 4 deletions

View File

@ -14,9 +14,8 @@ version = "1"
default-features = false
[dependencies.subtle]
version = "0.7"
version = "2"
default-features = false
features = ["generic-impls"]
[features]
default = ["std"]

View File

@ -2,7 +2,7 @@ use core::fmt;
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use byteorder::{ByteOrder, LittleEndian};
use subtle::{Choice, ConditionallyAssignable, ConditionallySelectable, ConstantTimeEq};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
/// Represents an element of `GF(q)`.
// The internal representation of this type is four 64-bit unsigned

View File

@ -6,7 +6,7 @@ extern crate std;
use core::ops::{Add, AddAssign, Neg, Sub, SubAssign};
use subtle::{Choice, ConditionallyAssignable, ConditionallySelectable, ConstantTimeEq};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
#[macro_use]
mod util;
@ -47,6 +47,15 @@ impl PartialEq for AffinePoint {
}
}
impl ConditionallySelectable for AffinePoint {
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
AffinePoint {
u: Fq::conditional_select(&a.u, &b.u, choice),
v: Fq::conditional_select(&a.v, &b.v, choice),
}
}
}
/// Represents the affine point `(u/z, v/z)` with
/// `z` nonzero and `t1 * t2 = uv/z`.
#[derive(Clone, Copy)]
@ -69,6 +78,18 @@ impl ConstantTimeEq for ExtendedPoint {
}
}
impl ConditionallySelectable for ExtendedPoint {
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
ExtendedPoint {
u: Fq::conditional_select(&a.u, &b.u, choice),
v: Fq::conditional_select(&a.v, &b.v, choice),
z: Fq::conditional_select(&a.z, &b.z, choice),
t1: Fq::conditional_select(&a.t1, &b.t1, choice),
t2: Fq::conditional_select(&a.t2, &b.t2, choice),
}
}
}
impl PartialEq for ExtendedPoint {
fn eq(&self, other: &Self) -> bool {
self.ct_eq(other).unwrap_u8() == 1