From f32b565722f2c46d2487037c8e088380beec5830 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Tue, 21 May 2024 22:20:59 -0700 Subject: [PATCH 1/2] digest: expose `AssociatedAlgorithmIdentifier` through `CoreWrapper` --- Cargo.lock | 1 + digest/Cargo.toml | 2 ++ digest/src/core_api/ct_variable.rs | 15 +++++++++++++++ digest/src/core_api/wrapper.rs | 12 ++++++++++++ digest/src/lib.rs | 2 ++ 5 files changed, 32 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1cf9a41f..01e7546b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -451,6 +451,7 @@ dependencies = [ "block-buffer 0.11.0-pre.5", "const-oid 0.10.0-pre.2", "crypto-common 0.2.0-pre.5 (registry+https://github.com/rust-lang/crates.io-index)", + "spki 0.8.0-pre.0", "subtle", "zeroize", ] diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 84821647..138cdec0 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -20,6 +20,7 @@ block-buffer = { version = "=0.11.0-pre.5", optional = true } subtle = { version = "2.4", default-features = false, optional = true } blobby = { version = "0.3", optional = true } const-oid = { version = "=0.10.0-pre.2", optional = true } +spki = { version = "=0.8.0-pre.0", optional = true } zeroize = { version = "1.7", optional = true, default-features = false } [features] @@ -28,6 +29,7 @@ core-api = ["block-buffer"] # Enable Core API traits mac = ["subtle"] # Enable MAC traits rand_core = ["crypto-common/rand_core"] # Enable random key generation methods oid = ["const-oid"] +spki = ["oid", "dep:spki"] zeroize = ["dep:zeroize", "block-buffer?/zeroize"] alloc = [] std = ["alloc", "crypto-common/std"] diff --git a/digest/src/core_api/ct_variable.rs b/digest/src/core_api/ct_variable.rs index fe917bfd..1b6dbfbb 100644 --- a/digest/src/core_api/ct_variable.rs +++ b/digest/src/core_api/ct_variable.rs @@ -18,6 +18,8 @@ use crypto_common::{ typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, Sum, U1, U256}, Block, BlockSizeUser, OutputSizeUser, }; +#[cfg(feature = "spki")] +use spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier}; /// Dummy type used with [`CtVariableCoreWrapper`] in cases when /// resulting hash does not have a known OID. @@ -167,6 +169,19 @@ where const OID: ObjectIdentifier = O::OID; } +#[cfg(feature = "spki")] +impl AssociatedAlgorithmIdentifier for CtVariableCoreWrapper +where + T: VariableOutputCore, + O: AssociatedAlgorithmIdentifier, + OutSize: ArraySize + IsLessOrEqual, + LeEq: NonZero, +{ + type Params = O::Params; + + const ALGORITHM_IDENTIFIER: AlgorithmIdentifier = O::ALGORITHM_IDENTIFIER; +} + #[cfg(feature = "zeroize")] impl zeroize::ZeroizeOnDrop for CtVariableCoreWrapper where diff --git a/digest/src/core_api/wrapper.rs b/digest/src/core_api/wrapper.rs index d366249f..44ee3ea9 100644 --- a/digest/src/core_api/wrapper.rs +++ b/digest/src/core_api/wrapper.rs @@ -23,6 +23,8 @@ use crypto_common::{ use crate::MacMarker; #[cfg(feature = "oid")] use const_oid::{AssociatedOid, ObjectIdentifier}; +#[cfg(feature = "spki")] +use spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier}; /// Wrapper around [`BufferKindUser`]. /// @@ -179,6 +181,16 @@ where const OID: ObjectIdentifier = T::OID; } +#[cfg(feature = "spki")] +impl AssociatedAlgorithmIdentifier for CoreWrapper +where + T: BufferKindUser + AssociatedAlgorithmIdentifier, +{ + type Params = T::Params; + + const ALGORITHM_IDENTIFIER: AlgorithmIdentifier = T::ALGORITHM_IDENTIFIER; +} + type CoreWrapperSerializedStateSize = Sum::SerializedStateSize, U1>, ::BlockSize>; diff --git a/digest/src/lib.rs b/digest/src/lib.rs index b535bc8a..2d26d0d0 100644 --- a/digest/src/lib.rs +++ b/digest/src/lib.rs @@ -61,6 +61,8 @@ pub use block_buffer; #[cfg(feature = "oid")] pub use const_oid; pub use crypto_common; +#[cfg(feature = "spki")] +pub use spki; #[cfg(feature = "const-oid")] pub use crate::digest::DynDigestWithOid; From 6a10fad9ce6aee814b9ca3d51cca288c23a4a69d Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Wed, 22 May 2024 11:18:31 -0700 Subject: [PATCH 2/2] digest: `spki` doesn't require `oid` --- digest/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 138cdec0..50ceda96 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -29,7 +29,6 @@ core-api = ["block-buffer"] # Enable Core API traits mac = ["subtle"] # Enable MAC traits rand_core = ["crypto-common/rand_core"] # Enable random key generation methods oid = ["const-oid"] -spki = ["oid", "dep:spki"] zeroize = ["dep:zeroize", "block-buffer?/zeroize"] alloc = [] std = ["alloc", "crypto-common/std"]