Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digest: expose AssociatedAlgorithmIdentifier through CoreWrapper #1575

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions digest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, this has a circular dependency: spki has an optional dependency on sha2 for computing SPKI fingerprints.

Copy link
Member Author

@baloo baloo May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I missed this one.

Newtype then ? :D
And we get the AssociatedOid and AssociatedAlgorithmIdentifier attached to those ? :D
(I agree with the usability comment you made over #1069)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we had newtypes, it would at least get rid of any coupling between spki and digest, though the problem would remain for sha2.

We could potentially split off an e.g. spki-fingerprint crate so spki doesn't depend on sha2. It is something of a niche feature.

zeroize = { version = "1.7", optional = true, default-features = false }

[features]
Expand Down
15 changes: 15 additions & 0 deletions digest/src/core_api/ct_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -167,6 +169,19 @@ where
const OID: ObjectIdentifier = O::OID;
}

#[cfg(feature = "spki")]
impl<T, OutSize, O> AssociatedAlgorithmIdentifier for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
O: AssociatedAlgorithmIdentifier,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
{
type Params = O::Params;

const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> = O::ALGORITHM_IDENTIFIER;
}

#[cfg(feature = "zeroize")]
impl<T, OutSize, O> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize, O>
where
Expand Down
12 changes: 12 additions & 0 deletions digest/src/core_api/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand Down Expand Up @@ -179,6 +181,16 @@ where
const OID: ObjectIdentifier = T::OID;
}

#[cfg(feature = "spki")]
impl<T> AssociatedAlgorithmIdentifier for CoreWrapper<T>
where
T: BufferKindUser + AssociatedAlgorithmIdentifier,
{
type Params = T::Params;

const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> = T::ALGORITHM_IDENTIFIER;
}

type CoreWrapperSerializedStateSize<T> =
Sum<Sum<<T as SerializableState>::SerializedStateSize, U1>, <T as BlockSizeUser>::BlockSize>;

Expand Down
2 changes: 2 additions & 0 deletions digest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading