Skip to content

Commit

Permalink
elliptic-curve: bump crypto-bigint and format crates; MSRV 1.65
Browse files Browse the repository at this point in the history
Bumps the following dependencies:

- `crypto-bigint` v0.5
- `pem-rfc7468` v0.7
- `pkcs8` v0.10
- `sec1` v0.7
- `serdect` v0.2
  • Loading branch information
tarcieri committed Feb 28, 2023
1 parent 9da51ba commit 0082576
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/elliptic-curve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
rust:
- 1.61.0 # MSRV
- 1.65.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
strategy:
matrix:
rust:
- 1.61.0 # MSRV
- 1.65.0 # MSRV
- stable
- nightly
steps:
Expand Down
53 changes: 30 additions & 23 deletions elliptic-curve/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions elliptic-curve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "elliptic", "weierstrass"]
edition = "2021"
rust-version = "1.61"
rust-version = "1.65"

[dependencies]
base16ct = "0.1.1"
crypto-bigint = { version = "=0.5.0-pre.3", default-features = false, features = ["rand_core", "generic-array", "zeroize"] }
generic-array = { version = "0.14", default-features = false }
crypto-bigint = { version = "0.5", default-features = false, features = ["rand_core", "generic-array", "zeroize"] }
generic-array = { version = "0.14.6", default-features = false, features = ["zeroize"] }
rand_core = { version = "0.6.4", default-features = false }
subtle = { version = "2", default-features = false }
zeroize = { version = "1.5", default-features = false }
Expand All @@ -30,10 +30,10 @@ ff = { version = "0.13", optional = true, default-features = false }
group = { version = "0.13", optional = true, default-features = false }
hkdf = { version = "0.12", optional = true, default-features = false }
hex-literal = { version = "0.3", optional = true }
pem-rfc7468 = { version = "0.6", optional = true }
pkcs8 = { version = "0.9", optional = true, default-features = false }
sec1 = { version = "0.3", optional = true, features = ["subtle", "zeroize"] }
serdect = { version = "0.1", optional = true, default-features = false, features = ["alloc"] }
pem-rfc7468 = { version = "0.7", optional = true }
pkcs8 = { version = "0.10", optional = true, default-features = false }
sec1 = { version = "0.7.1", optional = true, features = ["subtle", "zeroize"] }
serdect = { version = "0.2", optional = true, default-features = false, features = ["alloc"] }
serde_json = { version = "1", optional = true, default-features = false, features = ["alloc"] }

[dev-dependencies]
Expand All @@ -59,7 +59,7 @@ std = [

arithmetic = ["group"]
bits = ["arithmetic", "ff/bits"]
dev = ["arithmetic", "hex-literal", "pem", "pkcs8"]
dev = ["arithmetic", "dep:hex-literal", "pem", "pkcs8"]
hash2curve = ["arithmetic", "digest"]
ecdh = ["arithmetic", "digest", "hkdf"]
group = ["dep:group", "ff"]
Expand Down
4 changes: 2 additions & 2 deletions elliptic-curve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and public/secret keys composed thereof.

## Minimum Supported Rust Version

Requires Rust **1.61** or higher.
Requires Rust **1.65** or higher.

Minimum supported Rust version can be changed in the future, but it will be
done with a minor version bump.
Expand Down Expand Up @@ -49,6 +49,6 @@ dual licensed as above, without any additional terms or conditions.
[build-image]: https://github.com/RustCrypto/traits/actions/workflows/elliptic-curve.yml/badge.svg
[build-link]: https://github.com/RustCrypto/traits/actions/workflows/elliptic-curve.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.61+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves
28 changes: 13 additions & 15 deletions elliptic-curve/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,30 +339,27 @@ where
}

#[cfg(all(feature = "pkcs8", feature = "sec1"))]
impl<C> TryFrom<pkcs8::SubjectPublicKeyInfo<'_>> for PublicKey<C>
impl<C> TryFrom<pkcs8::SubjectPublicKeyInfoRef<'_>> for PublicKey<C>
where
C: AssociatedOid + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldBytesSize<C>: ModulusSize,
{
type Error = pkcs8::spki::Error;

fn try_from(spki: pkcs8::SubjectPublicKeyInfo<'_>) -> pkcs8::spki::Result<Self> {
fn try_from(spki: pkcs8::SubjectPublicKeyInfoRef<'_>) -> pkcs8::spki::Result<Self> {
spki.algorithm.assert_oids(ALGORITHM_OID, C::OID)?;
Self::from_sec1_bytes(spki.subject_public_key)

let public_key_bytes = spki
.subject_public_key
.as_bytes()
.ok_or_else(|| der::Tag::BitString.value_error())?;

Self::from_sec1_bytes(public_key_bytes)
.map_err(|_| der::Tag::BitString.value_error().into())
}
}

#[cfg(all(feature = "pkcs8", feature = "sec1"))]
impl<C> DecodePublicKey for PublicKey<C>
where
C: AssociatedOid + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldBytesSize<C>: ModulusSize,
{
}

#[cfg(all(feature = "alloc", feature = "pkcs8"))]
impl<C> EncodePublicKey for PublicKey<C>
where
Expand All @@ -371,16 +368,17 @@ where
FieldBytesSize<C>: ModulusSize,
{
fn to_public_key_der(&self) -> pkcs8::spki::Result<der::Document> {
let algorithm = pkcs8::AlgorithmIdentifier {
let algorithm = pkcs8::AlgorithmIdentifierRef {
oid: ALGORITHM_OID,
parameters: Some((&C::OID).into()),
};

let public_key_bytes = self.to_encoded_point(false);
let subject_public_key = der::asn1::BitStringRef::new(0, public_key_bytes.as_bytes())?;

pkcs8::SubjectPublicKeyInfo {
pkcs8::SubjectPublicKeyInfoRef {
algorithm,
subject_public_key: public_key_bytes.as_ref(),
subject_public_key,
}
.try_into()
}
Expand Down
8 changes: 2 additions & 6 deletions elliptic-curve/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ where
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldBytesSize<C>: ModulusSize,
{
// TODO(tarcieri): wrap `secret_key_bytes` in `Zeroizing`
let mut private_key_bytes = self.to_bytes();
let private_key_bytes = Zeroizing::new(self.to_bytes());
let public_key_bytes = self.public_key().to_encoded_point(false);

let ec_private_key = Zeroizing::new(
Expand All @@ -200,12 +199,9 @@ where
parameters: None,
public_key: Some(public_key_bytes.as_bytes()),
}
.to_vec()?,
.to_der()?,
);

// TODO(tarcieri): wrap `private_key_bytes` in `Zeroizing`
private_key_bytes.zeroize();

Ok(ec_private_key)
}

Expand Down
9 changes: 1 addition & 8 deletions elliptic-curve/src/secret_key/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ where
}
}

impl<C> DecodePrivateKey for SecretKey<C>
where
C: Curve + AssociatedOid + ValidatePublicKey,
FieldBytesSize<C>: ModulusSize,
{
}

#[cfg(all(feature = "alloc", feature = "arithmetic"))]
impl<C> EncodePrivateKey for SecretKey<C>
where
Expand All @@ -57,7 +50,7 @@ where
FieldBytesSize<C>: ModulusSize,
{
fn to_pkcs8_der(&self) -> pkcs8::Result<der::SecretDocument> {
let algorithm_identifier = pkcs8::AlgorithmIdentifier {
let algorithm_identifier = pkcs8::AlgorithmIdentifierRef {
oid: ALGORITHM_OID,
parameters: Some((&C::OID).into()),
};
Expand Down
1 change: 1 addition & 0 deletions elliptic-curve/tests/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn example_private_key() -> der::SecretDocument {

#[test]
fn decode_pkcs8_private_key_from_der() {
dbg!(example_private_key().as_bytes());
let secret_key = SecretKey::from_pkcs8_der(example_private_key().as_bytes()).unwrap();
assert_eq!(secret_key.to_bytes().as_slice(), &EXAMPLE_SCALAR);
}
Expand Down

0 comments on commit 0082576

Please sign in to comment.