diff --git a/.github/workflows/digest.yml b/.github/workflows/digest.yml index 585de6cb7..51ee473b8 100644 --- a/.github/workflows/digest.yml +++ b/.github/workflows/digest.yml @@ -50,7 +50,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + # - 1.41.0 # MSRV - stable steps: - uses: actions/checkout@v2 @@ -60,8 +60,6 @@ jobs: toolchain: ${{ matrix.rust }} override: true profile: minimal - # Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates - - run: rm ../Cargo.toml - run: cargo check --all-features - run: cargo test --no-default-features - run: cargo test @@ -69,3 +67,26 @@ jobs: - run: cargo test --features alloc - run: cargo test --features std - run: cargo test --all-features + + # The `oid` feature bumps MSRV to 1.57, so we temporarily split this job. + test-msrv: + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - 1.41.0 # MSRV + steps: + - uses: actions/checkout@v2 + - uses: RustCrypto/actions/cargo-cache@master + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + profile: minimal + # Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates + - run: rm ../Cargo.toml + - run: cargo test --no-default-features + - run: cargo test + - run: cargo test --features dev + - run: cargo test --features alloc + - run: cargo test --features std diff --git a/Cargo.lock b/Cargo.lock index 77f459530..c3c02c529 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,9 +50,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -168,9 +168,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -282,9 +282,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc948ebb96241bb40ab73effeb80d9f93afaad49359d159a5e61be51619fe813" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] @@ -308,7 +308,7 @@ dependencies = [ "aead 0.5.1", "cipher 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "crypto-common 0.1.6", - "digest 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.10.3", "elliptic-curve 0.12.3", "password-hash", "signature 1.6.0", @@ -423,21 +423,22 @@ dependencies = [ [[package]] name = "digest" version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "blobby", - "block-buffer 0.10.2", - "crypto-common 0.1.6", + "block-buffer 0.10.3", + "crypto-common 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "subtle", ] [[package]] name = "digest" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +version = "0.10.4" dependencies = [ - "block-buffer 0.10.2", - "crypto-common 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "blobby", + "block-buffer 0.10.3", + "const-oid 0.9.0", + "crypto-common 0.1.6", "subtle", ] @@ -483,7 +484,7 @@ dependencies = [ "base64ct", "crypto-bigint 0.4.8", "der 0.6.0", - "digest 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.10.3", "ff 0.12.0", "generic-array", "group 0.12.0", @@ -660,7 +661,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.10.3", ] [[package]] @@ -672,7 +673,7 @@ dependencies = [ "aes-gcm", "byteorder", "chacha20poly1305", - "digest 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.10.3", "generic-array", "hkdf 0.12.3", "hmac 0.12.1", @@ -1143,7 +1144,7 @@ checksum = "cf9db03534dff993187064c4e0c05a5708d2a9728ace9a8959b77bedf415dac5" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.10.3", ] [[package]] @@ -1152,7 +1153,7 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaedf34ed289ea47c2b741bb72e5357a209512d67bcd4bda44359e5bf0470f56" dependencies = [ - "digest 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.10.3", "keccak", ] @@ -1170,7 +1171,7 @@ dependencies = [ name = "signature" version = "1.6.0" dependencies = [ - "digest 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.10.3", "hex-literal", "rand_core 0.6.3", "sha2 0.10.5", diff --git a/digest/CHANGELOG.md b/digest/CHANGELOG.md index c9f52c64e..2553f5e74 100644 --- a/digest/CHANGELOG.md +++ b/digest/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.10.4 (2022-09-16) +### Added +- Feature-gated implementation of the `const_oid::AssociatedOid` trait +for the core wrappers. ([#1098]) + +[#1098]: https://github.com/RustCrypto/traits/pull/1098 + ## 0.10.3 (2022-02-16) ### Fixed - Minimal versions build ([#940]) diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 94ff540e3..253da27ba 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "digest" description = "Traits for cryptographic hash functions" -version = "0.10.3" # Also update html_root_url in lib.rs when bumping this +version = "0.10.4" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -18,12 +18,14 @@ crypto-common = { version = "0.1.3", path = "../crypto-common" } block-buffer = { version = "0.10", optional = true } subtle = { version = "=2.4", default-features = false, optional = true } blobby = { version = "0.3", optional = true } +const-oid = { version = "0.9", optional = true } [features] default = ["core-api"] 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"] # OID support. WARNING: Bumps MSRV to 1.57 alloc = [] std = ["alloc", "crypto-common/std"] dev = ["blobby"] diff --git a/digest/src/core_api/ct_variable.rs b/digest/src/core_api/ct_variable.rs index 40efff65c..7ee1bed0a 100644 --- a/digest/src/core_api/ct_variable.rs +++ b/digest/src/core_api/ct_variable.rs @@ -5,6 +5,8 @@ use super::{ use crate::HashMarker; #[cfg(feature = "mac")] use crate::MacMarker; +#[cfg(feature = "oid")] +use const_oid::{AssociatedOid, ObjectIdentifier}; use core::{fmt, marker::PhantomData}; use crypto_common::{ generic_array::{ArrayLength, GenericArray}, @@ -12,10 +14,15 @@ use crypto_common::{ Block, BlockSizeUser, OutputSizeUser, }; +/// Dummy type used with [`CtVariableCoreWrapper`] in cases when +/// resulting hash does not have a known OID. +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] +pub struct NoOid; + /// Wrapper around [`VariableOutputCore`] which selects output size /// at compile time. #[derive(Clone)] -pub struct CtVariableCoreWrapper +pub struct CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, @@ -24,10 +31,10 @@ where Le: NonZero, { inner: T, - _out: PhantomData, + _out: PhantomData<(OutSize, O)>, } -impl HashMarker for CtVariableCoreWrapper +impl HashMarker for CtVariableCoreWrapper where T: VariableOutputCore + HashMarker, OutSize: ArrayLength + IsLessOrEqual, @@ -38,7 +45,7 @@ where } #[cfg(feature = "mac")] -impl MacMarker for CtVariableCoreWrapper +impl MacMarker for CtVariableCoreWrapper where T: VariableOutputCore + MacMarker, OutSize: ArrayLength + IsLessOrEqual, @@ -48,7 +55,7 @@ where { } -impl BlockSizeUser for CtVariableCoreWrapper +impl BlockSizeUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, @@ -59,7 +66,7 @@ where type BlockSize = T::BlockSize; } -impl UpdateCore for CtVariableCoreWrapper +impl UpdateCore for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, @@ -73,7 +80,7 @@ where } } -impl OutputSizeUser for CtVariableCoreWrapper +impl OutputSizeUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual + 'static, @@ -84,7 +91,7 @@ where type OutputSize = OutSize; } -impl BufferKindUser for CtVariableCoreWrapper +impl BufferKindUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, @@ -95,7 +102,7 @@ where type BufferKind = T::BufferKind; } -impl FixedOutputCore for CtVariableCoreWrapper +impl FixedOutputCore for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual + 'static, @@ -120,7 +127,7 @@ where } } -impl Default for CtVariableCoreWrapper +impl Default for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, @@ -137,7 +144,7 @@ where } } -impl Reset for CtVariableCoreWrapper +impl Reset for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, @@ -151,7 +158,7 @@ where } } -impl AlgorithmName for CtVariableCoreWrapper +impl AlgorithmName for CtVariableCoreWrapper where T: VariableOutputCore + AlgorithmName, OutSize: ArrayLength + IsLessOrEqual, @@ -165,3 +172,33 @@ where write!(f, "{}", OutSize::USIZE) } } + +#[cfg(feature = "oid")] +#[cfg_attr(docsrs, doc(cfg(feature = "oid")))] +impl AssociatedOid for CtVariableCoreWrapper +where + T: VariableOutputCore, + O: AssociatedOid, + OutSize: ArrayLength + IsLessOrEqual, + LeEq: NonZero, + T::BlockSize: IsLess, + Le: NonZero, +{ + const OID: ObjectIdentifier = O::OID; +} + +/// Implement dummy type with hidden docs which is used to "carry" hasher +/// OID for [`CtVariableCoreWrapper`]. +#[macro_export] +macro_rules! impl_oid_carrier { + ($name:ident, $oid:literal) => { + #[doc(hidden)] + #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] + pub struct $name; + + #[cfg(feature = "oid")] + impl AssociatedOid for $name { + const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid); + } + }; +} diff --git a/digest/src/core_api/wrapper.rs b/digest/src/core_api/wrapper.rs index 4ad0f7eea..ca977381e 100644 --- a/digest/src/core_api/wrapper.rs +++ b/digest/src/core_api/wrapper.rs @@ -14,6 +14,8 @@ use crypto_common::{ #[cfg(feature = "mac")] use crate::MacMarker; +#[cfg(feature = "oid")] +use const_oid::{AssociatedOid, ObjectIdentifier}; /// Wrapper around [`BufferKindUser`]. /// @@ -227,6 +229,17 @@ where } } +#[cfg(feature = "oid")] +#[cfg_attr(docsrs, doc(cfg(feature = "oid")))] +impl AssociatedOid for CoreWrapper +where + T: BufferKindUser + AssociatedOid, + T::BlockSize: IsLess, + Le: NonZero, +{ + const OID: ObjectIdentifier = T::OID; +} + #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::io::Write for CoreWrapper diff --git a/digest/src/lib.rs b/digest/src/lib.rs index c2edb40ee..fc82e2e3a 100644 --- a/digest/src/lib.rs +++ b/digest/src/lib.rs @@ -27,8 +27,7 @@ #![forbid(unsafe_code)] #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", - html_root_url = "https://docs.rs/digest/0.10.3" + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" )] #![warn(missing_docs, rust_2018_idioms)] @@ -60,6 +59,9 @@ mod mac; #[cfg(feature = "core-api")] #[cfg_attr(docsrs, doc(cfg(feature = "core-api")))] pub use block_buffer; +#[cfg(feature = "oid")] +#[cfg_attr(docsrs, doc(cfg(feature = "oid")))] +pub use const_oid; pub use crypto_common; pub use crate::digest::{Digest, DynDigest, HashMarker};