Skip to content

Commit ee835e3

Browse files
authored
Bump crypto-bigint to v0.7.0-pre.5 (#382)
...and all of the downstream dependencies needed to upgrade it: - `dsa` - `rsa` - `p256` - `p384` - `p521` This notably includes some changes to `dsa` and `rsa` which eliminate the use of `Odd` and `NonZero` input parameters, putting those checks in the constructor instead.
1 parent 44deecc commit ee835e3

10 files changed

Lines changed: 46 additions & 144 deletions

File tree

Cargo.lock

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

ssh-encoding/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rust-version = "1.85"
1717

1818
[dependencies]
1919
base64ct = { version = "1.7", optional = true }
20-
bigint = { package = "crypto-bigint", version = "=0.7.0-pre.4", optional = true, default-features = false, features = ["alloc"] }
20+
bigint = { package = "crypto-bigint", version = "=0.7.0-pre.5", optional = true, default-features = false, features = ["alloc"] }
2121
bytes = { version = "1", optional = true, default-features = false }
2222
digest = { version = "0.11.0-rc.0", optional = true, default-features = false }
2323
pem-rfc7468 = { version = "1.0.0-rc.3", optional = true }

ssh-encoding/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,3 @@ use alloc::vec::Vec;
264264

265265
#[cfg(feature = "bigint")]
266266
pub use bigint::BoxedUint as Uint;
267-
268-
/// Non-zero [`Uint`].
269-
#[cfg(feature = "bigint")]
270-
pub type NonZeroUint = bigint::NonZero<Uint>;
271-
272-
/// Odd [`Uint`].
273-
#[cfg(feature = "bigint")]
274-
pub type OddUint = bigint::Odd<Uint>;

ssh-encoding/src/mpint.rs

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use alloc::{boxed::Box, vec::Vec};
55
use core::fmt;
66

77
#[cfg(feature = "bigint")]
8-
use crate::{NonZeroUint, OddUint, Uint};
8+
use crate::Uint;
99

1010
#[cfg(feature = "subtle")]
1111
use subtle::{Choice, ConstantTimeEq};
@@ -207,42 +207,6 @@ impl fmt::UpperHex for Mpint {
207207
}
208208
}
209209

210-
#[cfg(feature = "bigint")]
211-
impl TryFrom<NonZeroUint> for Mpint {
212-
type Error = Error;
213-
214-
fn try_from(uint: NonZeroUint) -> Result<Mpint> {
215-
Mpint::try_from(&uint)
216-
}
217-
}
218-
219-
#[cfg(feature = "bigint")]
220-
impl TryFrom<&NonZeroUint> for Mpint {
221-
type Error = Error;
222-
223-
fn try_from(uint: &NonZeroUint) -> Result<Mpint> {
224-
Self::try_from(uint.as_ref())
225-
}
226-
}
227-
228-
#[cfg(feature = "bigint")]
229-
impl TryFrom<OddUint> for Mpint {
230-
type Error = Error;
231-
232-
fn try_from(uint: OddUint) -> Result<Mpint> {
233-
Mpint::try_from(&uint)
234-
}
235-
}
236-
237-
#[cfg(feature = "bigint")]
238-
impl TryFrom<&OddUint> for Mpint {
239-
type Error = Error;
240-
241-
fn try_from(uint: &OddUint) -> Result<Mpint> {
242-
Self::try_from(uint.as_ref())
243-
}
244-
}
245-
246210
#[cfg(feature = "bigint")]
247211
impl TryFrom<Uint> for Mpint {
248212
type Error = Error;
@@ -262,46 +226,6 @@ impl TryFrom<&Uint> for Mpint {
262226
}
263227
}
264228

265-
#[cfg(feature = "bigint")]
266-
impl TryFrom<Mpint> for NonZeroUint {
267-
type Error = Error;
268-
269-
fn try_from(mpint: Mpint) -> Result<NonZeroUint> {
270-
NonZeroUint::try_from(&mpint)
271-
}
272-
}
273-
274-
#[cfg(feature = "bigint")]
275-
impl TryFrom<&Mpint> for NonZeroUint {
276-
type Error = Error;
277-
278-
fn try_from(mpint: &Mpint) -> Result<NonZeroUint> {
279-
let uint = Uint::try_from(mpint)?;
280-
NonZeroUint::new(uint)
281-
.into_option()
282-
.ok_or(Error::MpintEncoding)
283-
}
284-
}
285-
286-
#[cfg(feature = "bigint")]
287-
impl TryFrom<Mpint> for OddUint {
288-
type Error = Error;
289-
290-
fn try_from(mpint: Mpint) -> Result<OddUint> {
291-
OddUint::try_from(&mpint)
292-
}
293-
}
294-
295-
#[cfg(feature = "bigint")]
296-
impl TryFrom<&Mpint> for OddUint {
297-
type Error = Error;
298-
299-
fn try_from(mpint: &Mpint) -> Result<OddUint> {
300-
let uint = Uint::try_from(mpint)?;
301-
OddUint::new(uint).into_option().ok_or(Error::MpintEncoding)
302-
}
303-
}
304-
305229
#[cfg(feature = "bigint")]
306230
impl TryFrom<Mpint> for Uint {
307231
type Error = Error;
@@ -316,14 +240,9 @@ impl TryFrom<&Mpint> for Uint {
316240
type Error = Error;
317241

318242
fn try_from(mpint: &Mpint) -> Result<Uint> {
243+
// TODO(tarcieri): enforce a maximum size?
319244
let bytes = mpint.as_positive_bytes().ok_or(Error::MpintEncoding)?;
320-
let bits_precision = bytes
321-
.len()
322-
.checked_mul(8)
323-
.and_then(|n| u32::try_from(n).ok())
324-
.ok_or(Error::MpintEncoding)?;
325-
326-
Ok(Uint::from_be_slice(bytes, bits_precision)?)
245+
Ok(Uint::from_be_slice_vartime(bytes))
327246
}
328247
}
329248

ssh-key/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ zeroize = { version = "1", default-features = false }
2828
# optional dependencies
2929
argon2 = { version = "0.6.0-rc.0", optional = true, default-features = false, features = ["alloc"] }
3030
bcrypt-pbkdf = { version = "0.11.0-rc.0", optional = true, default-features = false, features = ["alloc"] }
31-
dsa = { version = "0.7.0-rc.0", optional = true, default-features = false, features = ["hazmat"] }
31+
dsa = { version = "0.7.0-rc.1", optional = true, default-features = false, features = ["hazmat"] }
3232
ed25519-dalek = { version = "=2.2.0-pre", optional = true, default-features = false }
3333
hex = { version = "0.4", optional = true, default-features = false, features = ["alloc"] }
3434
hmac = { version = "0.13.0-rc.0", optional = true }
3535
home = { version = "0.5", optional = true }
36-
p256 = { version = "0.14.0-pre.5", optional = true, default-features = false, features = ["ecdsa"] }
37-
p384 = { version = "0.14.0-pre.5", optional = true, default-features = false, features = ["ecdsa"] }
38-
p521 = { version = "0.14.0-pre.5", optional = true, default-features = false, features = ["ecdsa"] }
36+
p256 = { version = "0.14.0-pre.7", optional = true, default-features = false, features = ["ecdsa"] }
37+
p384 = { version = "0.14.0-pre.7", optional = true, default-features = false, features = ["ecdsa"] }
38+
p521 = { version = "0.14.0-pre.7", optional = true, default-features = false, features = ["ecdsa"] }
3939
rand_core = { version = "0.9", optional = true, default-features = false }
40-
rsa = { version = "0.10.0-rc.0", optional = true, default-features = false, features = ["sha2"] }
40+
rsa = { version = "0.10.0-rc.1", optional = true, default-features = false, features = ["sha2"] }
4141
sec1 = { version = "0.8.0-rc.5", optional = true, default-features = false, features = ["point"] }
4242
serde = { version = "1.0.16", optional = true }
4343
sha1 = { version = "0.11.0-rc.0", optional = true, default-features = false, features = ["oid"] }

ssh-key/src/private/dsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl TryFrom<&dsa::SigningKey> for DsaPrivateKey {
136136

137137
fn try_from(key: &dsa::SigningKey) -> Result<DsaPrivateKey> {
138138
Ok(DsaPrivateKey {
139-
inner: key.x().try_into()?,
139+
inner: key.x().as_ref().try_into()?,
140140
})
141141
}
142142
}

ssh-key/src/private/rsa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use zeroize::Zeroize;
88

99
#[cfg(feature = "rsa")]
1010
use {
11-
encoding::{OddUint, Uint},
11+
encoding::Uint,
1212
rand_core::CryptoRng,
1313
rsa::{
1414
pkcs1v15,
@@ -252,7 +252,7 @@ impl TryFrom<&RsaKeypair> for rsa::RsaPrivateKey {
252252

253253
fn try_from(key: &RsaKeypair) -> Result<rsa::RsaPrivateKey> {
254254
let ret = rsa::RsaPrivateKey::from_components(
255-
OddUint::try_from(key.public.n())?,
255+
Uint::try_from(key.public.n())?,
256256
Uint::try_from(key.public.e())?,
257257
Uint::try_from(&key.private.d)?,
258258
vec![

ssh-key/src/public/dsa.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::hash::{Hash, Hasher};
55
use encoding::{CheckedSum, Decode, Encode, Reader, Writer};
66

77
#[cfg(feature = "dsa")]
8-
use encoding::{NonZeroUint, OddUint};
8+
use encoding::Uint;
99

1010
/// Digital Signature Algorithm (DSA) public key.
1111
///
@@ -119,10 +119,10 @@ impl TryFrom<&DsaPublicKey> for dsa::VerifyingKey {
119119
type Error = Error;
120120

121121
fn try_from(key: &DsaPublicKey) -> Result<dsa::VerifyingKey> {
122-
let p = OddUint::try_from(&key.p)?;
123-
let q = NonZeroUint::try_from(&key.q)?;
124-
let g = NonZeroUint::try_from(&key.g)?;
125-
let y = NonZeroUint::try_from(&key.y)?;
122+
let p = Uint::try_from(&key.p)?;
123+
let q = Uint::try_from(&key.q)?;
124+
let g = Uint::try_from(&key.g)?;
125+
let y = Uint::try_from(&key.y)?;
126126

127127
let components = dsa::Components::from_components(p, q, g)?;
128128
dsa::VerifyingKey::from_components(components, y).map_err(|_| Error::Crypto)
@@ -144,10 +144,10 @@ impl TryFrom<&dsa::VerifyingKey> for DsaPublicKey {
144144

145145
fn try_from(key: &dsa::VerifyingKey) -> Result<DsaPublicKey> {
146146
Ok(DsaPublicKey {
147-
p: key.components().p().try_into()?,
148-
q: key.components().q().try_into()?,
149-
g: key.components().g().try_into()?,
150-
y: key.y().try_into()?,
147+
p: key.components().p().as_ref().try_into()?,
148+
q: key.components().q().as_ref().try_into()?,
149+
g: key.components().g().as_ref().try_into()?,
150+
y: key.y().as_ref().try_into()?,
151151
})
152152
}
153153
}

ssh-key/src/public/rsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl TryFrom<&rsa::RsaPublicKey> for RsaPublicKey {
139139

140140
fn try_from(key: &rsa::RsaPublicKey) -> Result<RsaPublicKey> {
141141
let e = Mpint::try_from(key.e())?;
142-
let n = Mpint::try_from(key.n())?;
142+
let n = Mpint::try_from(key.n().as_ref())?;
143143
RsaPublicKey::new(e, n)
144144
}
145145
}

ssh-key/src/signature.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{private::Ed25519Keypair, public::Ed25519PublicKey};
1212
#[cfg(feature = "dsa")]
1313
use {
1414
crate::{private::DsaKeypair, public::DsaPublicKey},
15-
encoding::{NonZeroUint, Uint},
15+
encoding::Uint,
1616
signature::{DigestSigner, DigestVerifier},
1717
};
1818

@@ -389,16 +389,7 @@ impl TryFrom<&Signature> for dsa::Signature {
389389

390390
let r = Uint::from_be_slice(components.0, component_bits)?;
391391
let s = Uint::from_be_slice(components.1, component_bits)?;
392-
let signature = Self::from_components(
393-
NonZeroUint::new(r)
394-
.into_option()
395-
.ok_or(encoding::Error::MpintEncoding)?,
396-
NonZeroUint::new(s)
397-
.into_option()
398-
.ok_or(encoding::Error::MpintEncoding)?,
399-
);
400-
401-
Ok(signature)
392+
Ok(Self::from_components(r, s).ok_or(encoding::Error::MpintEncoding)?)
402393
}
403394
}
404395

0 commit comments

Comments
 (0)