diff --git a/Cargo.toml b/Cargo.toml
index 3ca54f9..4d195cb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -32,14 +32,13 @@ version = "0.3"
[dependencies.digest]
version = "0.4"
+[dependencies.subtle]
+version = "^0.1"
+
[dependencies.generic-array]
# same version that digest depends on
version = "^0.6"
-[dependencies.num-traits]
-optional = true
-version = "^0.1"
-
[dev-dependencies.sha2]
version = "0.4"
@@ -49,7 +48,7 @@ version = "0.6"
[features]
nightly = ["radix_51"]
default = ["std"]
-std = ["rand", "num-traits"]
+std = ["rand"]
yolocrypto = []
bench = []
# Radix-51 arithmetic using u128
diff --git a/src/decaf.rs b/src/decaf.rs
index 08abe89..2b489b0 100644
--- a/src/decaf.rs
+++ b/src/decaf.rs
@@ -620,10 +620,15 @@ impl CTAssignable for DecafPoint {
/// # Example
///
/// ```
+ /// # extern crate subtle;
+ /// # extern crate curve25519_dalek;
+ /// #
+ /// # use subtle::CTAssignable;
+ /// #
/// # use curve25519_dalek::curve::Identity;
/// # use curve25519_dalek::decaf::DecafPoint;
- /// # use curve25519_dalek::subtle::CTAssignable;
/// # use curve25519_dalek::constants;
+ /// # fn main() {
/// let A = DecafPoint::identity();
/// let B = constants::DECAF_ED25519_BASEPOINT;
///
@@ -633,6 +638,7 @@ impl CTAssignable for DecafPoint {
/// assert!(P == A);
/// P.conditional_assign(&B, 1u8);
/// assert!(P == B);
+ /// # }
/// ```
fn conditional_assign(&mut self, other: &DecafPoint, choice: u8) {
self.0.X.conditional_assign(&other.0.X, choice);
diff --git a/src/field.rs b/src/field.rs
index e1dda92..bcf8d17 100644
--- a/src/field.rs
+++ b/src/field.rs
@@ -340,25 +340,33 @@ impl CTAssignable for FieldElement {
/// If `choice == 0`, replace `self` with `self`:
///
/// ```
+ /// # extern crate subtle;
+ /// # extern crate curve25519_dalek;
/// # use curve25519_dalek::field::FieldElement;
- /// # use curve25519_dalek::subtle::CTAssignable;
+ /// # use subtle::CTAssignable;
+ /// # fn main() {
/// let f = FieldElement([1,1,1,1,1,1,1,1,1,1]);
/// let g = FieldElement([2,2,2,2,2,2,2,2,2,2]);
/// let mut h = FieldElement([1,1,1,1,1,1,1,1,1,1]);
/// h.conditional_assign(&g, 0);
/// assert!(h == f);
+ /// # }
/// ```
///
/// If `choice == 1`, replace `self` with `f`:
///
/// ```
+ /// # extern crate subtle;
+ /// # extern crate curve25519_dalek;
/// # use curve25519_dalek::field::FieldElement;
- /// # use curve25519_dalek::subtle::CTAssignable;
+ /// # use subtle::CTAssignable;
+ /// # fn main() {
/// # let f = FieldElement([1,1,1,1,1,1,1,1,1,1]);
/// # let g = FieldElement([2,2,2,2,2,2,2,2,2,2]);
/// # let mut h = FieldElement([1,1,1,1,1,1,1,1,1,1]);
/// h.conditional_assign(&g, 1);
/// assert!(h == g);
+ /// # }
/// ```
///
/// # Preconditions
diff --git a/src/lib.rs b/src/lib.rs
index ac8522e..2a15780 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -47,6 +47,7 @@ extern crate arrayref;
extern crate generic_array;
extern crate digest;
+extern crate subtle;
#[cfg(feature = "serde")]
extern crate serde;
@@ -59,9 +60,6 @@ extern crate core;
#[cfg(feature = "std")]
extern crate rand;
-#[cfg(feature = "std")]
-extern crate num_traits;
-
#[cfg(not(feature = "std"))]
extern crate collections;
@@ -75,9 +73,8 @@ pub mod curve;
#[cfg(feature = "yolocrypto")]
pub mod decaf;
-// Constant-time functions and other miscelaneous utilities.
+// Other miscelaneous utilities.
-pub mod subtle;
pub mod utils;
// Low-level curve and point constants, as well as pre-computed curve group elements.
diff --git a/src/scalar.rs b/src/scalar.rs
index ed38c0d..e8beab7 100644
--- a/src/scalar.rs
+++ b/src/scalar.rs
@@ -158,8 +158,11 @@ impl CTAssignable for Scalar {
/// Conditionally assign another Scalar to this one.
///
/// ```
+ /// # extern crate curve25519_dalek;
+ /// # extern crate subtle;
/// # use curve25519_dalek::scalar::Scalar;
- /// # use curve25519_dalek::subtle::CTAssignable;
+ /// # use subtle::CTAssignable;
+ /// # fn main() {
/// let a = Scalar([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
/// let b = Scalar([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
@@ -169,6 +172,7 @@ impl CTAssignable for Scalar {
/// assert!(t[0] == a[0]);
/// t.conditional_assign(&b, 1u8);
/// assert!(t[0] == b[0]);
+ /// # }
/// ```
///
/// # Preconditions
diff --git a/src/subtle.rs b/src/subtle.rs
deleted file mode 100644
index b29b635..0000000
--- a/src/subtle.rs
+++ /dev/null
@@ -1,274 +0,0 @@
-// -*- mode: rust; -*-
-//
-// To the extent possible under law, the authors have waived all copyright and
-// related or neighboring rights to curve25519-dalek, using the Creative
-// Commons "CC0" public domain dedication. See
-// for full details.
-//
-// Authors:
-// - Isis Agora Lovecruft
-// - Henry de Valence
-
-//! Constant-time traits and utility functions.
-
-#[cfg(feature = "std")]
-use core::ops::BitAnd;
-#[cfg(feature = "std")]
-use core::ops::BitOr;
-#[cfg(feature = "std")]
-use core::ops::Not;
-#[cfg(feature = "std")]
-use core::ops::Sub;
-
-use core::ops::Neg;
-
-#[cfg(feature = "std")]
-use num_traits::One;
-#[cfg(feature = "std")]
-use num_traits::Signed;
-
-
-/// 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);
-}
-
-/// Trait for items whose equality to another item may be tested in constant time.
-pub trait CTEq {
- /// Determine if two items are equal in constant time.
- ///
- /// # Returns
- ///
- /// `1u8` if the two items are equal, and `0u8` otherwise.
- fn ct_eq(&self, other: &Self) -> u8;
-}
-
-/// Trait for items which can be conditionally negated in constant time.
-///
-/// Note: it is not necessary to implement this trait, as a generic
-/// implementation is provided.
-pub trait CTNegatable {
- /// Conditionally negate an element if `choice == 1u8`.
- fn conditional_negate(&mut self, choice: u8);
-}
-
-impl CTNegatable for T
- where T: CTAssignable, for<'a> &'a T: Neg