Skip to content

Commit 39eebb4

Browse files
authored
Bump (transitive) pkcs8 dependency to v0.11 (#1749)
Updates the `elliptic-curve` dependency to v0.14.0-rc.32 which transitively pulls in `pkcs8` v0.11, and also updates some specific requirements for other crates like `pkcs8` itself and `ed448`. This also migrates `ed448-goldilocks` to using `ed448::pkcs8::KeypairBytes` rather than specifying its own similar-shaped structure, so we don't have to duplicate the `pkcs8` API changes and can instead handle them in one place.
1 parent e3a3918 commit 39eebb4

17 files changed

Lines changed: 36 additions & 100 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ ed448-goldilocks = { path = "ed448-goldilocks" }
2626
hash2curve = { path = "hash2curve" }
2727
primefield = { path = "primefield" }
2828
primeorder = { path = "primeorder" }
29-
30-
elliptic-curve = { git = "https://github.com/RustCrypto/traits" }

bignp256/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ edition = "2024"
1818
rust-version = "1.85"
1919

2020
[dependencies]
21-
elliptic-curve = { version = "0.14.0-rc.31", features = ["sec1"] }
21+
elliptic-curve = { version = "0.14.0-rc.32", features = ["sec1"] }
2222

2323
# optional dependencies
2424
belt-block = { version = "0.2", optional = true }
@@ -30,15 +30,15 @@ hex-literal = { version = "1", optional = true }
3030
hkdf = { version = "0.13", optional = true }
3131
hmac = { version = "0.13", optional = true }
3232
rand_core = "0.10"
33-
pkcs8 = { version = "0.11.0-rc.11", optional = true }
33+
pkcs8 = { version = "0.11", optional = true }
3434
primefield = { version = "0.14.0-rc.9", optional = true }
3535
primeorder = { version = "0.14.0-rc.9", optional = true }
3636
sec1 = { version = "0.8.1", optional = true }
3737
signature = { version = "3.0.0-rc.10", optional = true }
3838

3939
[dev-dependencies]
4040
criterion = "0.7"
41-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["dev"] }
41+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["dev"] }
4242
hex-literal = "1"
4343
primeorder = { version = "0.14.0-rc.9", features = ["dev"] }
4444
proptest = "1"

bignp256/src/secret_key.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ impl TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for SecretKey {
142142
private_key_info
143143
.algorithm
144144
.assert_oids(ALGORITHM_OID, BignP256::OID)?;
145+
145146
Self::from_slice(private_key_info.private_key.as_bytes())
146-
.map_err(|_| pkcs8::Error::KeyMalformed)
147+
.map_err(|_| pkcs8::KeyError::Invalid.into())
147148
}
148149
}
149150

bp256/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2024"
1414
rust-version = "1.85"
1515

1616
[dependencies]
17-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["sec1"] }
17+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["sec1"] }
1818

1919
# optional dependencies
2020
ecdsa = { version = "0.17.0-rc.17", optional = true, default-features = false, features = ["der"] }
@@ -24,7 +24,7 @@ sha2 = { version = "0.11", optional = true, default-features = false }
2424

2525
[dev-dependencies]
2626
criterion = "0.7"
27-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["dev"] }
27+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["dev"] }
2828

2929
[features]
3030
default = ["pkcs8", "std"]

bp384/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2024"
1414
rust-version = "1.85"
1515

1616
[dependencies]
17-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["sec1"] }
17+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["sec1"] }
1818

1919
# optional dependencies
2020
ecdsa = { version = "0.17.0-rc.17", optional = true, default-features = false, features = ["der"] }
@@ -24,7 +24,7 @@ sha2 = { version = "0.11", optional = true, default-features = false }
2424

2525
[dev-dependencies]
2626
criterion = "0.7"
27-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["dev"] }
27+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["dev"] }
2828

2929
[features]
3030
default = ["pkcs8", "std"]

ed448-goldilocks/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ This crate also includes signing and verifying of Ed448 signatures.
1616
"""
1717

1818
[dependencies]
19-
elliptic-curve = { version = "0.14.0-rc.31", features = ["arithmetic", "pkcs8"] }
19+
elliptic-curve = { version = "0.14.0-rc.32", features = ["arithmetic", "pkcs8"] }
2020
hash2curve = "0.14.0-rc.12"
2121
rand_core = { version = "0.10", default-features = false }
2222
sha3 = { version = "0.11", default-features = false }
2323
subtle = { version = "2.6", default-features = false }
2424

2525
# optional dependencies
26-
ed448 = { version = "0.5.0-rc.3", optional = true, default-features = false }
26+
ed448 = { version = "0.5.0-rc.6", optional = true, default-features = false }
2727
serdect = { version = "0.4", optional = true }
2828
signature = { version = "3.0.0-rc.10", optional = true, default-features = false, features = ["digest", "rand_core"] }
2929

@@ -44,7 +44,7 @@ std = ["alloc", "getrandom"]
4444

4545
bits = ["elliptic-curve/bits"]
4646
getrandom = ["elliptic-curve/getrandom"]
47-
pkcs8 = ["ed448?/pkcs8", "elliptic-curve/pkcs8"]
47+
pkcs8 = ["ed448/pkcs8", "elliptic-curve/pkcs8"]
4848
signing = ["dep:ed448", "dep:signature"]
4949
serde = ["dep:serdect", "ed448?/serde_bytes"]
5050

ed448-goldilocks/src/sign/signing_key.rs

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use signature::Error;
1616
use subtle::{Choice, ConstantTimeEq};
1717

1818
#[cfg(feature = "pkcs8")]
19-
use crate::{PUBLIC_KEY_LENGTH, edwards::affine::PointBytes};
19+
use ::ed448::pkcs8::{KeypairBytes, PublicKeyBytes};
2020

2121
/// Ed448 secret key as defined in [RFC8032 § 5.2.5]
2222
///
@@ -329,70 +329,6 @@ impl pkcs8::spki::DynSignatureAlgorithmIdentifier for SigningKey {
329329
}
330330
}
331331

332-
#[cfg(feature = "pkcs8")]
333-
/// Keypair bytes for Ed448
334-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
335-
pub struct KeypairBytes {
336-
/// The secret key bytes
337-
pub secret_key: PointBytes,
338-
/// The public key bytes if included
339-
pub verifying_key: Option<PointBytes>,
340-
}
341-
342-
#[cfg(all(feature = "alloc", feature = "pkcs8"))]
343-
impl pkcs8::EncodePrivateKey for KeypairBytes {
344-
fn to_pkcs8_der(&self) -> pkcs8::Result<pkcs8::SecretDocument> {
345-
let verifying_key = self.verifying_key.as_ref();
346-
let public_key = verifying_key
347-
.map(|k| pkcs8::der::asn1::BitStringRef::from_bytes(k))
348-
.transpose()?;
349-
let private_key = pkcs8::der::asn1::OctetStringRef::new(self.secret_key.as_ref())?;
350-
351-
let private_key_info = pkcs8::PrivateKeyInfoRef {
352-
algorithm: super::ALGORITHM_ID,
353-
private_key,
354-
public_key,
355-
};
356-
let result = pkcs8::SecretDocument::encode_msg(&private_key_info)?;
357-
358-
Ok(result)
359-
}
360-
}
361-
362-
#[cfg(feature = "pkcs8")]
363-
impl TryFrom<pkcs8::PrivateKeyInfoRef<'_>> for KeypairBytes {
364-
type Error = pkcs8::Error;
365-
366-
fn try_from(value: pkcs8::PrivateKeyInfoRef<'_>) -> Result<Self, Self::Error> {
367-
if value.algorithm.oid != super::ALGORITHM_OID {
368-
return Err(pkcs8::Error::KeyMalformed);
369-
}
370-
if value.private_key.as_bytes().len() != SECRET_KEY_LENGTH {
371-
return Err(pkcs8::Error::KeyMalformed);
372-
}
373-
let mut secret_key = [0u8; SECRET_KEY_LENGTH];
374-
secret_key.copy_from_slice(value.private_key.as_bytes());
375-
let verifying_key = if let Some(public_key) = value.public_key {
376-
if public_key.has_unused_bits() {
377-
return Err(pkcs8::Error::KeyMalformed);
378-
}
379-
let public_key = public_key.raw_bytes();
380-
if public_key.len() != PUBLIC_KEY_LENGTH {
381-
return Err(pkcs8::Error::KeyMalformed);
382-
}
383-
let mut bytes = [0u8; PUBLIC_KEY_LENGTH];
384-
bytes.copy_from_slice(public_key);
385-
Some(bytes)
386-
} else {
387-
None
388-
};
389-
Ok(KeypairBytes {
390-
secret_key,
391-
verifying_key,
392-
})
393-
}
394-
}
395-
396332
#[cfg(feature = "pkcs8")]
397333
impl TryFrom<KeypairBytes> for SigningKey {
398334
type Error = pkcs8::Error;
@@ -410,11 +346,11 @@ impl TryFrom<&KeypairBytes> for SigningKey {
410346
let signing_key =
411347
SigningKey::from(SecretKey::try_from(&value.secret_key[..]).expect("invalid length"));
412348

413-
if let Some(public_bytes) = value.verifying_key {
414-
let verifying_key =
415-
VerifyingKey::from_bytes(&public_bytes).map_err(|_| pkcs8::Error::KeyMalformed)?;
349+
if let Some(public_bytes) = &value.public_key {
350+
let verifying_key = VerifyingKey::from_bytes(public_bytes.as_ref())
351+
.map_err(|_| pkcs8::KeyError::Invalid)?;
416352
if signing_key.verifying_key() != verifying_key {
417-
return Err(pkcs8::Error::KeyMalformed);
353+
return Err(pkcs8::KeyError::Invalid.into());
418354
}
419355
}
420356
Ok(signing_key)
@@ -425,8 +361,8 @@ impl TryFrom<&KeypairBytes> for SigningKey {
425361
impl From<&SigningKey> for KeypairBytes {
426362
fn from(signing_key: &SigningKey) -> Self {
427363
KeypairBytes {
428-
secret_key: PointBytes::from(signing_key.to_bytes()),
429-
verifying_key: Some(PointBytes::from(signing_key.verifying_key().to_bytes())),
364+
secret_key: signing_key.to_bytes().into(),
365+
public_key: Some(PublicKeyBytes(signing_key.verifying_key().to_bytes())),
430366
}
431367
}
432368
}

hash2curve/Cargo.toml

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

1616
[dependencies]
1717
digest = { version = "0.11" }
18-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["arithmetic"] }
18+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["arithmetic"] }
1919

2020
[dev-dependencies]
2121
hex-literal = "1"

k256/Cargo.toml

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

2121
[dependencies]
2222
cpubits = "0.1"
23-
elliptic-curve = { version = "0.14.0-rc.31", default-features = false, features = ["sec1"] }
23+
elliptic-curve = { version = "0.14.0-rc.32", default-features = false, features = ["sec1"] }
2424
hash2curve = { version = "0.14.0-rc.12", optional = true }
2525

2626
# optional dependencies

0 commit comments

Comments
 (0)