From 5d769e5398f683fb7aebda820e4e7f87b17df4d6 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Tue, 4 Aug 2020 09:28:02 -0700 Subject: [PATCH] Use `const_oid` crate Uses types from the `const-oid` crate to define OIDs (optionally, gated on the `oid` cargo feature) --- Cargo.lock | 9 ++++++++- k256/Cargo.toml | 3 ++- k256/src/lib.rs | 10 +++++++--- p256/Cargo.toml | 1 + p256/src/lib.rs | 10 +++++++--- p384/Cargo.toml | 1 + p384/src/lib.rs | 6 +++++- 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd3676d9..99e90650 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,6 +97,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "const-oid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d9162b7289a46e86208d6af2c686ca5bfde445878c41a458a9fac706252d0b" + [[package]] name = "cpuid-bool" version = "0.1.2" @@ -236,8 +242,9 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" [[package]] name = "elliptic-curve" version = "0.5.0-pre" -source = "git+https://github.com/RustCrypto/traits#83c41ca3a5e19a5d8d776ac7f74123de8373e2e8" +source = "git+https://github.com/RustCrypto/traits#72f1909a39571b0fe57f2751c1393680f364ee32" dependencies = [ + "const-oid", "generic-array", "rand_core", "subtle", diff --git a/k256/Cargo.toml b/k256/Cargo.toml index 0fd3f252..03aae19c 100644 --- a/k256/Cargo.toml +++ b/k256/Cargo.toml @@ -27,13 +27,14 @@ num-traits = "0.2" criterion = "0.3" [features] -default = ["arithmetic", "std"] +default = ["arithmetic", "oid", "std"] arithmetic = [] digest = ["ecdsa-core/digest"] ecdsa = ["arithmetic", "ecdsa-core/signer", "ecdsa-core/verifier", "rand", "sha256", "zeroize"] endomorphism-mul = [] field-montgomery = [] force-32-bit = [] +oid = ["elliptic-curve/oid"] rand = ["elliptic-curve/rand_core"] sha256 = ["digest", "sha2"] test-vectors = [] diff --git a/k256/src/lib.rs b/k256/src/lib.rs index 30953f1f..70b90ded 100644 --- a/k256/src/lib.rs +++ b/k256/src/lib.rs @@ -35,7 +35,10 @@ pub use arithmetic::{ AffinePoint, ProjectivePoint, }; -use elliptic_curve::{consts::U32, ObjectIdentifier}; +use elliptic_curve::consts::U32; + +#[cfg(feature = "oid")] +use elliptic_curve::oid::ObjectIdentifier; /// K-256 (secp256k1) elliptic curve. /// @@ -56,12 +59,13 @@ impl elliptic_curve::Curve for Secp256k1 { type ElementSize = U32; } +impl elliptic_curve::weierstrass::Curve for Secp256k1 {} + +#[cfg(feature = "oid")] impl elliptic_curve::Identifier for Secp256k1 { const OID: ObjectIdentifier = ObjectIdentifier::new(&[1, 3, 132, 0, 10]); } -impl elliptic_curve::weierstrass::Curve for Secp256k1 {} - /// K-256 (secp256k1) Secret Key. pub type SecretKey = elliptic_curve::SecretKey; diff --git a/p256/Cargo.toml b/p256/Cargo.toml index e6500481..7cffb14c 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -26,6 +26,7 @@ proptest = "0.10" default = ["arithmetic", "std"] arithmetic = [] ecdsa = ["arithmetic", "ecdsa-core/signer", "ecdsa-core/verifier", "rand", "sha256", "zeroize"] +oid = ["elliptic-curve/oid"] rand = ["elliptic-curve/rand_core"] sha256 = ["ecdsa-core/digest", "ecdsa-core/hazmat", "sha2"] test-vectors = [] diff --git a/p256/src/lib.rs b/p256/src/lib.rs index d9970de8..88b68800 100644 --- a/p256/src/lib.rs +++ b/p256/src/lib.rs @@ -35,7 +35,10 @@ pub use arithmetic::{ #[cfg(all(feature = "arithmetic", feature = "rand"))] pub use arithmetic::scalar::blinding::BlindedScalar; -use elliptic_curve::{consts::U32, oid::ObjectIdentifier}; +use elliptic_curve::consts::U32; + +#[cfg(feature = "oid")] +use elliptic_curve::oid::ObjectIdentifier; /// NIST P-256 elliptic curve. /// @@ -64,12 +67,13 @@ impl elliptic_curve::Curve for NistP256 { type ElementSize = U32; } +impl elliptic_curve::weierstrass::Curve for NistP256 {} + +#[cfg(feature = "oid")] impl elliptic_curve::Identifier for NistP256 { const OID: ObjectIdentifier = ObjectIdentifier::new(&[1, 2, 840, 10045, 3, 1, 7]); } -impl elliptic_curve::weierstrass::Curve for NistP256 {} - /// NIST P-256 Secret Key pub type SecretKey = elliptic_curve::SecretKey; diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 9d5b7d1e..dbeb18fe 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -26,6 +26,7 @@ version = "0.9" optional = true [features] +oid = ["elliptic-curve/oid"] sha384 = ["ecdsa/digest", "ecdsa/hazmat", "sha2"] std = ["elliptic-curve/std"] diff --git a/p384/src/lib.rs b/p384/src/lib.rs index 2ddc77c2..6166e133 100644 --- a/p384/src/lib.rs +++ b/p384/src/lib.rs @@ -19,7 +19,10 @@ pub mod ecdsa; pub use elliptic_curve; -use elliptic_curve::{consts::U48, ObjectIdentifier}; +use elliptic_curve::consts::U48; + +#[cfg(feature = "oid")] +use elliptic_curve::oid::ObjectIdentifier; /// NIST P-384 elliptic curve. /// @@ -49,6 +52,7 @@ impl elliptic_curve::Curve for NistP384 { type ElementSize = U48; } +#[cfg(feature = "oid")] impl elliptic_curve::Identifier for NistP384 { const OID: ObjectIdentifier = ObjectIdentifier::new(&[1, 3, 132, 0, 34]); }