diff --git a/Cargo.toml b/Cargo.toml index 508038f..e1be11b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/fq.rs b/src/fq.rs index c2ed2f6..2a8db52 100644 --- a/src/fq.rs +++ b/src/fq.rs @@ -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 diff --git a/src/lib.rs b/src/lib.rs index bdaced0..f3fd2a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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