Skip to content

Commit 0284c59

Browse files
authored
Migrate from subtle to ctutils (#507)
See RustCrypto/meta#29
1 parent 51bd0aa commit 0284c59

14 files changed

Lines changed: 37 additions & 37 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh-cipher/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ aes = { version = "0.9.0-rc.4", optional = true, default-features = false }
2828
aes-gcm = { version = "0.11.0-rc.3", optional = true, default-features = false, features = ["aes"] }
2929
cbc = { version = "0.2", optional = true }
3030
ctr = { version = "0.10.0-rc.4", optional = true, default-features = false }
31+
ctutils = { version = "0.4", optional = true, default-features = false }
3132
chacha20 = { version = "0.10.0-rc.10", optional = true, default-features = false, features = ["cipher", "legacy"] }
3233
des = { version = "0.9.0-rc.3", optional = true, default-features = false }
3334
poly1305 = { version = "0.9.0-rc.6", optional = true, default-features = false }
34-
subtle = { version = "2", optional = true, default-features = false }
3535
zeroize = { version = "1", optional = true, default-features = false }
3636

3737
[dev-dependencies]
@@ -41,7 +41,7 @@ hex-literal = "1"
4141
aes-cbc = ["dep:aes", "dep:cbc"]
4242
aes-ctr = ["dep:aes", "dep:ctr"]
4343
aes-gcm = ["dep:aead", "dep:aes", "dep:aes-gcm"]
44-
chacha20poly1305 = ["dep:aead", "dep:chacha20", "dep:poly1305", "dep:subtle"]
44+
chacha20poly1305 = ["dep:aead", "dep:chacha20", "dep:poly1305", "dep:ctutils"]
4545
tdes = ["dep:des", "dep:cbc"]
4646
zeroize = [
4747
"dep:zeroize",

ssh-cipher/src/chacha20poly1305.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use aead::{
99
inout::InOutBuf,
1010
};
1111
use cipher::{KeyIvInit, StreamCipher, StreamCipherSeek};
12+
use ctutils::CtEq;
1213
use poly1305::{Poly1305, universal_hash::UniversalHash};
13-
use subtle::ConstantTimeEq;
1414

1515
#[cfg(feature = "zeroize")]
1616
use zeroize::{Zeroize, ZeroizeOnDrop};

ssh-encoding/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ rust-version = "1.85"
1919
base64ct = { version = "1.8", optional = true }
2020
bigint = { package = "crypto-bigint", version = "0.7", optional = true, default-features = false, features = ["alloc"] }
2121
bytes = { version = "1", optional = true, default-features = false }
22+
ctutils = { version = "0.4", optional = true, default-features = false }
2223
digest = { version = "0.11", optional = true, default-features = false }
2324
pem-rfc7468 = { version = "1", optional = true }
2425
ssh-derive = { version = "0.3.0-rc.0", optional = true }
25-
subtle = { version = "2", optional = true, default-features = false }
2626
zeroize = { version = "1", optional = true, default-features = false }
2727

2828
[dev-dependencies]

ssh-encoding/src/mpint.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use core::fmt;
77
#[cfg(feature = "bigint")]
88
use crate::Uint;
99

10-
#[cfg(feature = "subtle")]
11-
use subtle::{Choice, ConstantTimeEq};
10+
#[cfg(feature = "ctutils")]
11+
use ctutils::{Choice, CtEq};
1212

1313
#[cfg(any(feature = "bigint", feature = "zeroize"))]
1414
use zeroize::Zeroize;
@@ -40,8 +40,8 @@ use zeroize::Zeroizing;
4040
/// | 80 | `00 00 00 02 00 80`
4141
/// |-1234 | `00 00 00 02 ed cc`
4242
/// | -deadbeef | `00 00 00 05 ff 21 52 41 11`
43-
#[cfg_attr(not(feature = "subtle"), derive(Clone))]
44-
#[cfg_attr(feature = "subtle", derive(Clone, Ord, PartialOrd))] // TODO: constant time (Partial)`Ord`?
43+
#[cfg_attr(not(feature = "ctutils"), derive(Clone))]
44+
#[cfg_attr(feature = "ctutils", derive(Clone, Ord, PartialOrd))] // TODO: constant time (Partial)`Ord`?
4545
pub struct Mpint {
4646
/// Inner big endian-serialized integer value
4747
inner: Box<[u8]>,
@@ -112,17 +112,17 @@ impl AsRef<[u8]> for Mpint {
112112
}
113113
}
114114

115-
#[cfg(feature = "subtle")]
116-
impl ConstantTimeEq for Mpint {
115+
#[cfg(feature = "ctutils")]
116+
impl CtEq for Mpint {
117117
fn ct_eq(&self, other: &Self) -> Choice {
118118
self.as_ref().ct_eq(other.as_ref())
119119
}
120120
}
121121

122-
#[cfg(feature = "subtle")]
122+
#[cfg(feature = "ctutils")]
123123
impl Eq for Mpint {}
124124

125-
#[cfg(feature = "subtle")]
125+
#[cfg(feature = "ctutils")]
126126
impl PartialEq for Mpint {
127127
fn eq(&self, other: &Self) -> bool {
128128
self.ct_eq(other).into()

ssh-key/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ features = ["zeroize"]
2727
[dependencies.encoding]
2828
version = "0.3.0-rc.8"
2929
package = "ssh-encoding"
30-
features = ["base64", "digest", "pem", "subtle", "zeroize"]
30+
features = ["base64", "digest", "pem", "ctutils", "zeroize"]
3131

3232
[dependencies]
33+
ctutils = { version = "0.4", default-features = false }
3334
sha2 = { version = "0.11", default-features = false }
3435
signature = { version = "3", default-features = false }
35-
subtle = { version = "2", default-features = false }
3636
zeroize = { version = "1", default-features = false }
3737

3838
# optional dependencies

ssh-key/src/ppk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use sha2::Sha256;
1717
use crate::private::KeypairData;
1818
use crate::public::KeyData;
1919
use crate::{Algorithm, Error, PublicKey};
20+
use ctutils::CtEq;
2021
use encoding::base64::{self, Base64, Encoding};
2122
use encoding::{Decode, Encode, LabelError, Reader};
22-
use subtle::ConstantTimeEq;
2323

2424
#[derive(Debug)]
2525
pub enum Kdf {

ssh-key/src/private.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ pub use self::sk::SkEcdsaSha2NistP256;
143143
use crate::{Algorithm, Cipher, Error, Fingerprint, HashAlg, Kdf, PublicKey, Result, public};
144144
use cipher::Tag;
145145
use core::str;
146+
use ctutils::{Choice, CtEq};
146147
use encoding::{
147148
CheckedSum, Decode, DecodePem, Encode, EncodePem, Reader, Writer,
148149
pem::{LineEnding, PemLabel},
149150
};
150-
use subtle::{Choice, ConstantTimeEq};
151151

152152
#[cfg(feature = "alloc")]
153153
use {
@@ -737,7 +737,7 @@ impl PrivateKey {
737737
}
738738
}
739739

740-
impl ConstantTimeEq for PrivateKey {
740+
impl CtEq for PrivateKey {
741741
fn ct_eq(&self, other: &Self) -> Choice {
742742
// Constant-time with respect to private key data
743743
self.key_data.ct_eq(&other.key_data)

ssh-key/src/private/dsa.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::{Error, Mpint, Result, public::DsaPublicKey};
44
use core::fmt;
5+
use ctutils::{Choice, CtEq};
56
use encoding::{CheckedSum, Decode, Encode, Reader, Writer};
6-
use subtle::{Choice, ConstantTimeEq};
77
use zeroize::Zeroize;
88

99
#[cfg(feature = "dsa")]
@@ -51,7 +51,7 @@ impl AsRef<[u8]> for DsaPrivateKey {
5151
}
5252
}
5353

54-
impl ConstantTimeEq for DsaPrivateKey {
54+
impl CtEq for DsaPrivateKey {
5555
fn ct_eq(&self, other: &Self) -> Choice {
5656
self.inner.ct_eq(&other.inner)
5757
}
@@ -181,7 +181,7 @@ impl DsaKeypair {
181181
}
182182
}
183183

184-
impl ConstantTimeEq for DsaKeypair {
184+
impl CtEq for DsaKeypair {
185185
fn ct_eq(&self, other: &Self) -> Choice {
186186
Choice::from((self.public == other.public) as u8) & self.private.ct_eq(&other.private)
187187
}

ssh-key/src/private/ecdsa.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
use crate::{Algorithm, EcdsaCurve, Error, Result, public::EcdsaPublicKey};
44
use core::fmt;
5+
use ctutils::{Choice, CtEq};
56
use encoding::{CheckedSum, Decode, Encode, Reader, Writer};
67
use sec1::consts::{U32, U48, U66};
7-
use subtle::{Choice, ConstantTimeEq};
88
use zeroize::Zeroize;
99

1010
#[cfg(feature = "rand_core")]
@@ -106,7 +106,7 @@ impl<const SIZE: usize> AsRef<[u8; SIZE]> for EcdsaPrivateKey<SIZE> {
106106
}
107107
}
108108

109-
impl<const SIZE: usize> ConstantTimeEq for EcdsaPrivateKey<SIZE> {
109+
impl<const SIZE: usize> CtEq for EcdsaPrivateKey<SIZE> {
110110
fn ct_eq(&self, other: &Self) -> Choice {
111111
self.as_ref().ct_eq(other.as_ref())
112112
}
@@ -282,7 +282,7 @@ impl EcdsaKeypair {
282282
}
283283
}
284284

285-
impl ConstantTimeEq for EcdsaKeypair {
285+
impl CtEq for EcdsaKeypair {
286286
fn ct_eq(&self, other: &Self) -> Choice {
287287
let public_eq =
288288
Choice::from((EcdsaPublicKey::from(self) == EcdsaPublicKey::from(other)) as u8);

0 commit comments

Comments
 (0)