From 758dcd4aebf18d01b9ae74ae96492daa737e9bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 17:47:38 +0300 Subject: [PATCH 01/10] digest v0.11 --- .github/workflows/digest.yml | 27 +------------ digest/CHANGELOG.md | 5 +++ digest/Cargo.toml | 11 ++--- digest/src/core_api.rs | 23 ++--------- digest/src/core_api/ct_variable.rs | 26 +----------- digest/src/core_api/rt_variable.rs | 36 ++--------------- digest/src/core_api/wrapper.rs | 65 ++---------------------------- digest/src/core_api/xof_reader.rs | 19 ++------- 8 files changed, 29 insertions(+), 183 deletions(-) diff --git a/.github/workflows/digest.yml b/.github/workflows/digest.yml index ee77a7116..625127772 100644 --- a/.github/workflows/digest.yml +++ b/.github/workflows/digest.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.57.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -50,7 +50,7 @@ jobs: strategy: matrix: rust: - # - 1.41.0 # MSRV + - 1.57.0 # MSRV - stable steps: - uses: actions/checkout@v3 @@ -67,26 +67,3 @@ 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@v3 - - 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/digest/CHANGELOG.md b/digest/CHANGELOG.md index e03398bfc..d912c991f 100644 --- a/digest/CHANGELOG.md +++ b/digest/CHANGELOG.md @@ -5,6 +5,11 @@ 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). +## UNRELEASED +### Changed +- `crypto-common` dependency bumped to v0.2 +- Edition changed to 2021 and MSRV bumped to 1.57 + ## 0.10.6 (2022-11-17) ### Added - `Mac::verify_reset` and `Mac::verify_slice_reset` methods ([#1154]) diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 943378c13..5e93ec786 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -1,21 +1,22 @@ [package] name = "digest" description = "Traits for cryptographic hash functions and message authentication codes" -version = "0.10.6" +version = "0.11.0" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" -edition = "2018" +edition = "2021" +rust-version = "1.57" documentation = "https://docs.rs/digest" repository = "https://github.com/RustCrypto/traits" keywords = ["digest", "crypto", "hash"] categories = ["cryptography", "no-std"] [dependencies] -crypto-common = { version = "0.1.3", path = "../crypto-common" } +crypto-common = { git = "https://github.com/RustCrypto/traits", branch = "crypto_common_v0.2" } # optional dependencies -block-buffer = { version = "0.10", optional = true } +block-buffer = { git = "https://github.com/RustCrypto/utils", branch = "hex_literal_0.11", optional = true } subtle = { version = "=2.4", default-features = false, optional = true } blobby = { version = "0.3", optional = true } const-oid = { version = "0.9", optional = true } @@ -25,7 +26,7 @@ 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 +oid = ["const-oid"] alloc = [] std = ["alloc", "crypto-common/std"] dev = ["blobby"] diff --git a/digest/src/core_api.rs b/digest/src/core_api.rs index 2cf384efe..6e8b8def7 100644 --- a/digest/src/core_api.rs +++ b/digest/src/core_api.rs @@ -8,10 +8,7 @@ use crate::InvalidOutputSize; pub use crypto_common::{AlgorithmName, Block, BlockSizeUser, OutputSizeUser, Reset}; use block_buffer::{BlockBuffer, BufferKind}; -use crypto_common::{ - typenum::{IsLess, Le, NonZero, U256}, - Output, -}; +use crypto_common::Output; mod ct_variable; mod rt_variable; @@ -40,22 +37,14 @@ pub trait BufferKindUser: BlockSizeUser { } /// Core trait for hash functions with fixed output size. -pub trait FixedOutputCore: UpdateCore + BufferKindUser + OutputSizeUser -where - Self::BlockSize: IsLess, - Le: NonZero, -{ +pub trait FixedOutputCore: UpdateCore + BufferKindUser + OutputSizeUser { /// Finalize state using remaining data stored in the provided block buffer, /// write result into provided array and leave `self` in a dirty state. fn finalize_fixed_core(&mut self, buffer: &mut Buffer, out: &mut Output); } /// Core trait for hash functions with extendable (XOF) output size. -pub trait ExtendableOutputCore: UpdateCore + BufferKindUser -where - Self::BlockSize: IsLess, - Le: NonZero, -{ +pub trait ExtendableOutputCore: UpdateCore + BufferKindUser { /// XOF reader core state. type ReaderCore: XofReaderCore; @@ -81,11 +70,7 @@ pub trait XofReaderCore: BlockSizeUser { /// [`finalize_variable_core`]: VariableOutputCore::finalize_variable_core /// [`new`]: VariableOutputCore::new /// [`TRUNC_SIDE`]: VariableOutputCore::TRUNC_SIDE -pub trait VariableOutputCore: UpdateCore + OutputSizeUser + BufferKindUser + Sized -where - Self::BlockSize: IsLess, - Le: NonZero, -{ +pub trait VariableOutputCore: UpdateCore + OutputSizeUser + BufferKindUser + Sized { /// Side which should be used in a truncated result. const TRUNC_SIDE: TruncSide; diff --git a/digest/src/core_api/ct_variable.rs b/digest/src/core_api/ct_variable.rs index 7ee1bed0a..0011a9262 100644 --- a/digest/src/core_api/ct_variable.rs +++ b/digest/src/core_api/ct_variable.rs @@ -10,7 +10,7 @@ use const_oid::{AssociatedOid, ObjectIdentifier}; use core::{fmt, marker::PhantomData}; use crypto_common::{ generic_array::{ArrayLength, GenericArray}, - typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, U256}, + typenum::{IsLessOrEqual, LeEq, NonZero}, Block, BlockSizeUser, OutputSizeUser, }; @@ -27,8 +27,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { inner: T, _out: PhantomData<(OutSize, O)>, @@ -39,8 +37,6 @@ where T: VariableOutputCore + HashMarker, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { } @@ -50,8 +46,6 @@ where T: VariableOutputCore + MacMarker, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { } @@ -60,8 +54,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { type BlockSize = T::BlockSize; } @@ -71,8 +63,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn update_blocks(&mut self, blocks: &[Block]) { @@ -85,8 +75,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual + 'static, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { type OutputSize = OutSize; } @@ -96,8 +84,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { type BufferKind = T::BufferKind; } @@ -107,8 +93,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual + 'static, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn finalize_fixed_core( @@ -132,8 +116,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn default() -> Self { @@ -149,8 +131,6 @@ where T: VariableOutputCore, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn reset(&mut self) { @@ -163,8 +143,6 @@ where T: VariableOutputCore + AlgorithmName, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { T::write_alg_name(f)?; @@ -181,8 +159,6 @@ where O: AssociatedOid, OutSize: ArrayLength + IsLessOrEqual, LeEq: NonZero, - T::BlockSize: IsLess, - Le: NonZero, { const OID: ObjectIdentifier = O::OID; } diff --git a/digest/src/core_api/rt_variable.rs b/digest/src/core_api/rt_variable.rs index 3dae748f5..94708ee77 100644 --- a/digest/src/core_api/rt_variable.rs +++ b/digest/src/core_api/rt_variable.rs @@ -5,16 +5,14 @@ use crate::{HashMarker, InvalidBufferSize}; use crate::{InvalidOutputSize, Reset, Update, VariableOutput, VariableOutputReset}; use block_buffer::BlockBuffer; use core::fmt; -use crypto_common::typenum::{IsLess, Le, NonZero, Unsigned, U256}; +use crypto_common::typenum::Unsigned; /// Wrapper around [`VariableOutputCore`] which selects output size /// at run time. #[derive(Clone)] pub struct RtVariableCoreWrapper where - T: VariableOutputCore + UpdateCore, - T::BlockSize: IsLess, - Le: NonZero, + T: VariableOutputCore, { core: T, buffer: BlockBuffer, @@ -24,8 +22,6 @@ where impl RtVariableCoreWrapper where T: VariableOutputCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn finalize_dirty(&mut self, out: &mut [u8]) -> Result<(), InvalidBufferSize> { @@ -49,29 +45,15 @@ where } } -impl HashMarker for RtVariableCoreWrapper -where - T: VariableOutputCore + HashMarker, - T::BlockSize: IsLess, - Le: NonZero, -{ -} +impl HashMarker for RtVariableCoreWrapper where T: VariableOutputCore + HashMarker {} #[cfg(feature = "mac")] #[cfg_attr(docsrs, doc(cfg(feature = "mac")))] -impl MacMarker for RtVariableCoreWrapper -where - T: VariableOutputCore + MacMarker, - T::BlockSize: IsLess, - Le: NonZero, -{ -} +impl MacMarker for RtVariableCoreWrapper where T: VariableOutputCore + MacMarker {} impl Reset for RtVariableCoreWrapper where T: VariableOutputCore + UpdateCore + Reset, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn reset(&mut self) { @@ -83,8 +65,6 @@ where impl Update for RtVariableCoreWrapper where T: VariableOutputCore + UpdateCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn update(&mut self, input: &[u8]) { @@ -96,8 +76,6 @@ where impl VariableOutput for RtVariableCoreWrapper where T: VariableOutputCore + UpdateCore, - T::BlockSize: IsLess, - Le: NonZero, { const MAX_OUTPUT_SIZE: usize = T::OutputSize::USIZE; @@ -122,8 +100,6 @@ where impl VariableOutputReset for RtVariableCoreWrapper where T: VariableOutputCore + UpdateCore + Reset, - T::BlockSize: IsLess, - Le: NonZero, { fn finalize_variable_reset(&mut self, out: &mut [u8]) -> Result<(), InvalidBufferSize> { self.finalize_dirty(out)?; @@ -136,8 +112,6 @@ where impl fmt::Debug for RtVariableCoreWrapper where T: VariableOutputCore + UpdateCore + AlgorithmName, - T::BlockSize: IsLess, - Le: NonZero, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { T::write_alg_name(f)?; @@ -150,8 +124,6 @@ where impl std::io::Write for RtVariableCoreWrapper where T: VariableOutputCore + UpdateCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn write(&mut self, buf: &[u8]) -> std::io::Result { diff --git a/digest/src/core_api/wrapper.rs b/digest/src/core_api/wrapper.rs index ca977381e..af77b11c8 100644 --- a/digest/src/core_api/wrapper.rs +++ b/digest/src/core_api/wrapper.rs @@ -7,10 +7,7 @@ use crate::{ }; use block_buffer::BlockBuffer; use core::fmt; -use crypto_common::{ - typenum::{IsLess, Le, NonZero, U256}, - BlockSizeUser, InvalidLength, Key, KeyInit, KeySizeUser, Output, -}; +use crypto_common::{BlockSizeUser, InvalidLength, Key, KeyInit, KeySizeUser, Output}; #[cfg(feature = "mac")] use crate::MacMarker; @@ -24,37 +21,21 @@ use const_oid::{AssociatedOid, ObjectIdentifier}; pub struct CoreWrapper where T: BufferKindUser, - T::BlockSize: IsLess, - Le: NonZero, { core: T, buffer: BlockBuffer, } -impl HashMarker for CoreWrapper -where - T: BufferKindUser + HashMarker, - T::BlockSize: IsLess, - Le: NonZero, -{ -} +impl HashMarker for CoreWrapper where T: BufferKindUser + HashMarker {} #[cfg(feature = "mac")] #[cfg_attr(docsrs, doc(cfg(feature = "mac")))] -impl MacMarker for CoreWrapper -where - T: BufferKindUser + MacMarker, - T::BlockSize: IsLess, - Le: NonZero, -{ -} +impl MacMarker for CoreWrapper where T: BufferKindUser + MacMarker {} // this blanket impl is needed for HMAC impl BlockSizeUser for CoreWrapper where T: BufferKindUser + HashMarker, - T::BlockSize: IsLess, - Le: NonZero, { type BlockSize = T::BlockSize; } @@ -62,8 +43,6 @@ where impl CoreWrapper where T: BufferKindUser, - T::BlockSize: IsLess, - Le: NonZero, { /// Create new wrapper from `core`. #[inline] @@ -83,8 +62,6 @@ where impl KeySizeUser for CoreWrapper where T: BufferKindUser + KeySizeUser, - T::BlockSize: IsLess, - Le: NonZero, { type KeySize = T::KeySize; } @@ -92,8 +69,6 @@ where impl KeyInit for CoreWrapper where T: BufferKindUser + KeyInit, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn new(key: &Key) -> Self { @@ -115,8 +90,6 @@ where impl fmt::Debug for CoreWrapper where T: BufferKindUser + AlgorithmName, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { @@ -128,8 +101,6 @@ where impl Reset for CoreWrapper where T: BufferKindUser + Reset, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn reset(&mut self) { @@ -141,8 +112,6 @@ where impl Update for CoreWrapper where T: BufferKindUser + UpdateCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn update(&mut self, input: &[u8]) { @@ -154,8 +123,6 @@ where impl OutputSizeUser for CoreWrapper where T: BufferKindUser + OutputSizeUser, - T::BlockSize: IsLess, - Le: NonZero, { type OutputSize = T::OutputSize; } @@ -163,8 +130,6 @@ where impl FixedOutput for CoreWrapper where T: FixedOutputCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn finalize_into(mut self, out: &mut Output) { @@ -176,8 +141,6 @@ where impl FixedOutputReset for CoreWrapper where T: FixedOutputCore + Reset, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn finalize_into_reset(&mut self, out: &mut Output) { @@ -191,10 +154,6 @@ where impl ExtendableOutput for CoreWrapper where T: ExtendableOutputCore, - T::BlockSize: IsLess, - Le: NonZero, - ::BlockSize: IsLess, - Le<::BlockSize, U256>: NonZero, { type Reader = XofReaderCoreWrapper; @@ -210,10 +169,6 @@ where impl ExtendableOutputReset for CoreWrapper where T: ExtendableOutputCore + Reset, - T::BlockSize: IsLess, - Le: NonZero, - ::BlockSize: IsLess, - Le<::BlockSize, U256>: NonZero, { #[inline] fn finalize_xof_reset(&mut self) -> Self::Reader { @@ -234,8 +189,6 @@ where impl AssociatedOid for CoreWrapper where T: BufferKindUser + AssociatedOid, - T::BlockSize: IsLess, - Le: NonZero, { const OID: ObjectIdentifier = T::OID; } @@ -245,8 +198,6 @@ where impl std::io::Write for CoreWrapper where T: BufferKindUser + UpdateCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn write(&mut self, buf: &[u8]) -> std::io::Result { @@ -272,19 +223,11 @@ mod sealed { pub trait Sealed {} } -impl sealed::Sealed for CoreWrapper -where - T: BufferKindUser, - T::BlockSize: IsLess, - Le: NonZero, -{ -} +impl sealed::Sealed for CoreWrapper where T: BufferKindUser {} impl CoreProxy for CoreWrapper where T: BufferKindUser, - T::BlockSize: IsLess, - Le: NonZero, { type Core = T; } diff --git a/digest/src/core_api/xof_reader.rs b/digest/src/core_api/xof_reader.rs index e18ac133a..665e2a76d 100644 --- a/digest/src/core_api/xof_reader.rs +++ b/digest/src/core_api/xof_reader.rs @@ -1,8 +1,7 @@ use super::{AlgorithmName, XofReaderCore}; use crate::XofReader; -use block_buffer::EagerBuffer; +use block_buffer::ReadBuffer; use core::fmt; -use crypto_common::typenum::{IsLess, Le, NonZero, U256}; /// Wrapper around [`XofReaderCore`] implementations. /// @@ -11,18 +10,14 @@ use crypto_common::typenum::{IsLess, Le, NonZero, U256}; pub struct XofReaderCoreWrapper where T: XofReaderCore, - T::BlockSize: IsLess, - Le: NonZero, { pub(super) core: T, - pub(super) buffer: EagerBuffer, + pub(super) buffer: ReadBuffer, } impl fmt::Debug for XofReaderCoreWrapper where T: XofReaderCore + AlgorithmName, - T::BlockSize: IsLess, - Le: NonZero, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { T::write_alg_name(f)?; @@ -33,17 +28,11 @@ where impl XofReader for XofReaderCoreWrapper where T: XofReaderCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn read(&mut self, buffer: &mut [u8]) { let Self { core, buffer: buf } = self; - buf.set_data(buffer, |blocks| { - for block in blocks { - *block = core.read_block(); - } - }); + buf.read(buffer, |block| *block = core.read_block()); } } @@ -52,8 +41,6 @@ where impl std::io::Read for XofReaderCoreWrapper where T: XofReaderCore, - T::BlockSize: IsLess, - Le: NonZero, { #[inline] fn read(&mut self, buf: &mut [u8]) -> std::io::Result { From 1aff15edaf0bc94625339e7d3fa117fb74c754eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 17:50:09 +0300 Subject: [PATCH 02/10] Change version to v0.11.0-pre --- digest/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 5e93ec786..445dbb6eb 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "digest" description = "Traits for cryptographic hash functions and message authentication codes" -version = "0.11.0" +version = "0.11.0-pre" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" From a64e98a7267f9f7a810c3bb53262150578bc8c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 18:14:46 +0300 Subject: [PATCH 03/10] Remove -pre --- digest/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 445dbb6eb..5e93ec786 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "digest" description = "Traits for cryptographic hash functions and message authentication codes" -version = "0.11.0-pre" +version = "0.11.0" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" From c4e2e77a21300c3f46ddaf5cb6739b09b865dd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 18:53:27 +0300 Subject: [PATCH 04/10] Remove Mac::new method --- digest/CHANGELOG.md | 9 +++++++-- digest/src/mac.rs | 13 ------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/digest/CHANGELOG.md b/digest/CHANGELOG.md index d912c991f..a6ead2b2c 100644 --- a/digest/CHANGELOG.md +++ b/digest/CHANGELOG.md @@ -7,8 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## UNRELEASED ### Changed -- `crypto-common` dependency bumped to v0.2 -- Edition changed to 2021 and MSRV bumped to 1.57 +- `crypto-common` dependency bumped to v0.2 ([#1173]) +- Edition changed to 2021 and MSRV bumped to 1.57 ([#1173]) + +### Removed +- `Mac::new` method ([#1173]) + +[#1173]: https://github.com/RustCrypto/traits/pull/1173 ## 0.10.6 (2022-11-17) ### Added diff --git a/digest/src/mac.rs b/digest/src/mac.rs index 1c31359ea..6d704a453 100644 --- a/digest/src/mac.rs +++ b/digest/src/mac.rs @@ -17,11 +17,6 @@ pub trait MacMarker {} /// traits and provides additional convenience methods. #[cfg_attr(docsrs, doc(cfg(feature = "mac")))] pub trait Mac: OutputSizeUser + Sized { - /// Create new value from fixed size key. - fn new(key: &Key) -> Self - where - Self: KeyInit; - /// Generate random key using the provided [`CryptoRng`]. #[cfg(feature = "rand_core")] #[cfg_attr(docsrs, doc(cfg(feature = "rand_core")))] @@ -95,14 +90,6 @@ pub trait Mac: OutputSizeUser + Sized { } impl Mac for T { - #[inline(always)] - fn new(key: &Key) -> Self - where - Self: KeyInit, - { - KeyInit::new(key) - } - #[inline(always)] fn new_from_slice(key: &[u8]) -> Result where From 44fca3b121a8ff07388bf24949cd0d246073d9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 20:25:22 +0300 Subject: [PATCH 05/10] Set version to 0.11.0-pre --- Cargo.lock | 32 ++++++++++++++++++++++++++++++++ Cargo.toml | 4 +--- digest/Cargo.toml | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b022e230b..3a3838ce0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,6 +139,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.11.0-pre" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b6a33d658e9ef24ba0c4566d3d023d7978ca2ea3efb65e4eacd4586695892b" +dependencies = [ + "crypto-common 0.2.0-pre (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array", +] + [[package]] name = "block-padding" version = "0.3.2" @@ -305,6 +315,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.0-pre" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6faaa83e7700e0832cbbf84854d4c356270526907d9b14fab927fc7a9b5befb8" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "typenum", +] + [[package]] name = "crypto-mac" version = "0.11.1" @@ -377,6 +398,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "digest" +version = "0.11.0-pre" +dependencies = [ + "blobby", + "block-buffer 0.11.0-pre", + "const-oid 0.9.1", + "crypto-common 0.2.0-pre (registry+https://github.com/rust-lang/crates.io-index)", + "subtle", +] + [[package]] name = "dunce" version = "1.0.3" diff --git a/Cargo.toml b/Cargo.toml index 38e3e4117..dc7d95785 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,12 +5,10 @@ members = [ "cipher", "crypto", "crypto-common", + "digest", "elliptic-curve", "kem", "signature", "signature/async", "universal-hash", ] -exclude = [ - "digest", -] diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 11cb21481..61f468357 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "digest" description = "Traits for cryptographic hash functions and message authentication codes" -version = "0.11.0" +version = "0.11.0-pre" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" From 5ca99745f22e45707a0a5b51850d7699f4cfa2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 20:29:04 +0300 Subject: [PATCH 06/10] Remove remaining KeyInit methods from the Mac trait --- digest/CHANGELOG.md | 2 +- digest/src/mac.rs | 38 +++----------------------------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/digest/CHANGELOG.md b/digest/CHANGELOG.md index a6ead2b2c..6713389fd 100644 --- a/digest/CHANGELOG.md +++ b/digest/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Edition changed to 2021 and MSRV bumped to 1.57 ([#1173]) ### Removed -- `Mac::new` method ([#1173]) +- `Mac::new`, `Mac::new_from_slice`, and `Mac::generate_key` methods ([#1173]) [#1173]: https://github.com/RustCrypto/traits/pull/1173 diff --git a/digest/src/mac.rs b/digest/src/mac.rs index 6d704a453..9e91b8ef7 100644 --- a/digest/src/mac.rs +++ b/digest/src/mac.rs @@ -1,8 +1,6 @@ use crate::{FixedOutput, FixedOutputReset, Update}; -use crypto_common::{InvalidLength, Key, KeyInit, Output, OutputSizeUser, Reset}; +use crypto_common::{Output, OutputSizeUser, Reset}; -#[cfg(feature = "rand_core")] -use crate::rand_core::{CryptoRng, RngCore}; use core::fmt; use crypto_common::typenum::Unsigned; use subtle::{Choice, ConstantTimeEq}; @@ -13,22 +11,10 @@ pub trait MacMarker {} /// Convenience wrapper trait covering functionality of Message Authentication algorithms. /// -/// This trait wraps [`KeyInit`], [`Update`], [`FixedOutput`], and [`MacMarker`] -/// traits and provides additional convenience methods. +/// This trait wraps [`Update`], [`FixedOutput`], and [`MacMarker`] traits +/// and provides additional convenience methods. #[cfg_attr(docsrs, doc(cfg(feature = "mac")))] pub trait Mac: OutputSizeUser + Sized { - /// Generate random key using the provided [`CryptoRng`]. - #[cfg(feature = "rand_core")] - #[cfg_attr(docsrs, doc(cfg(feature = "rand_core")))] - fn generate_key(rng: impl CryptoRng + RngCore) -> Key - where - Self: KeyInit; - - /// Create new value from variable size key. - fn new_from_slice(key: &[u8]) -> Result - where - Self: KeyInit; - /// Update state using the provided data. fn update(&mut self, data: &[u8]); @@ -90,14 +76,6 @@ pub trait Mac: OutputSizeUser + Sized { } impl Mac for T { - #[inline(always)] - fn new_from_slice(key: &[u8]) -> Result - where - Self: KeyInit, - { - KeyInit::new_from_slice(key) - } - #[inline] fn update(&mut self, data: &[u8]) { Update::update(self, data); @@ -210,16 +188,6 @@ impl Mac for T { Err(MacError) } } - - #[cfg(feature = "rand_core")] - #[cfg_attr(docsrs, doc(cfg(feature = "rand_core")))] - #[inline] - fn generate_key(rng: impl CryptoRng + RngCore) -> Key - where - Self: KeyInit, - { - ::generate_key(rng) - } } /// Fixed size output value which provides a safe [`Eq`] implementation that From 0e8d3db1ffa033181ee08cdf306f1e722b409de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 20:36:46 +0300 Subject: [PATCH 07/10] Update readmes --- README.md | 3 +-- digest/README.md | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8d1821067..d907874ad 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Collection of traits which describe functionality of cryptographic primitives. | [`async‑signature`] | [Digital signature] | [![crates.io](https://img.shields.io/crates/v/async-signature.svg)](https://crates.io/crates/async-signature) | [![Documentation](https://docs.rs/async-signature/badge.svg)](https://docs.rs/async-signature) | ![MSRV 1.56][msrv-1.56] | | [`cipher`] | [Block] and [stream cipher] | [![crates.io](https://img.shields.io/crates/v/cipher.svg)](https://crates.io/crates/cipher) | [![Documentation](https://docs.rs/cipher/badge.svg)](https://docs.rs/cipher) | ![MSRV 1.56][msrv-1.56] | | [`crypto‑common`] | Common cryptographic traits | [![crates.io](https://img.shields.io/crates/v/crypto-common.svg)](https://crates.io/crates/crypto-common) | [![Documentation](https://docs.rs/crypto-common/badge.svg)](https://docs.rs/crypto-common) | ![MSRV 1.56][msrv-1.56] | -| [`digest`] | [Cryptographic hash function] | [![crates.io](https://img.shields.io/crates/v/digest.svg)](https://crates.io/crates/digest) | [![Documentation](https://docs.rs/digest/badge.svg)](https://docs.rs/digest) | ![MSRV 1.41][msrv-1.41] | +| [`digest`] | [Cryptographic hash function] | [![crates.io](https://img.shields.io/crates/v/digest.svg)](https://crates.io/crates/digest) | [![Documentation](https://docs.rs/digest/badge.svg)](https://docs.rs/digest) | ![MSRV 1.57][msrv-1.57] | | [`elliptic‑curve`] | [Elliptic curve cryptography] | [![crates.io](https://img.shields.io/crates/v/elliptic-curve.svg)](https://crates.io/crates/elliptic-curve) | [![Documentation](https://docs.rs/elliptic-curve/badge.svg)](https://docs.rs/elliptic-curve) | ![MSRV 1.57][msrv-1.57] | | [`kem`] | [Key encapsulation mechanism] | [![crates.io](https://img.shields.io/crates/v/kem.svg)](https://crates.io/crates/kem) | [![Documentation](https://docs.rs/kem/badge.svg)](https://docs.rs/kem) | ![MSRV 1.56][msrv-1.56] | | [`password-hash`] | [Password hashing] | [![crates.io](https://img.shields.io/crates/v/password-hash.svg)](https://crates.io/crates/password-hash) | [![Documentation](https://docs.rs/password-hash/badge.svg)](https://docs.rs/password-hash) | ![MSRV 1.57][msrv-1.57] | @@ -49,7 +49,6 @@ Unless you explicitly state otherwise, any contribution intentionally submitted [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg [deps-image]: https://deps.rs/repo/github/RustCrypto/traits/status.svg [deps-link]: https://deps.rs/repo/github/RustCrypto/traits -[msrv-1.41]: https://img.shields.io/badge/rustc-1.41.0+-blue.svg [msrv-1.56]: https://img.shields.io/badge/rustc-1.56.0+-blue.svg [msrv-1.57]: https://img.shields.io/badge/rustc-1.57.0+-blue.svg diff --git a/digest/README.md b/digest/README.md index 9f68559cd..1d5f1f8fb 100644 --- a/digest/README.md +++ b/digest/README.md @@ -16,7 +16,7 @@ See [RustCrypto/hashes][1] for implementations which use this trait. ## Minimum Supported Rust Version -Rust **1.41** or higher. +Rust **1.57** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -35,7 +35,7 @@ First add the `sha2` crate to your `Cargo.toml`: ```toml [dependencies] -sha2 = "0.10" +sha2 = "0.11" ``` `sha2` and other crates re-export `digest` crate and `Digest` trait for @@ -147,7 +147,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/digest/badge.svg [docs-link]: https://docs.rs/digest/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260041-hashes [build-image]: https://github.com/RustCrypto/traits/workflows/digest/badge.svg?branch=master&event=push From 6eb80461d52610b3bf045fc8f070292708bd81a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 20:43:15 +0300 Subject: [PATCH 08/10] Fix mac tests --- digest/src/dev/mac.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/digest/src/dev/mac.rs b/digest/src/dev/mac.rs index 0d4a37dfc..b7c5260d7 100644 --- a/digest/src/dev/mac.rs +++ b/digest/src/dev/mac.rs @@ -17,10 +17,10 @@ macro_rules! new_mac_test { fn $name() { use core::cmp::min; use digest::dev::blobby::Blob3Iterator; - use digest::Mac; + use digest::{Mac, KeyInit}; fn run_test(key: &[u8], input: &[u8], tag: &[u8]) -> Option<&'static str> { - let mac0 = <$mac as Mac>::new_from_slice(key).unwrap(); + let mac0 = <$mac as KeyInit>::new_from_slice(key).unwrap(); let mut mac = mac0.clone(); mac.update(input); @@ -92,10 +92,10 @@ macro_rules! new_resettable_mac_test { fn $name() { use core::cmp::min; use digest::dev::blobby::Blob3Iterator; - use digest::Mac; + use digest::{Mac, KeyInit}; fn run_test(key: &[u8], input: &[u8], tag: &[u8]) -> Option<&'static str> { - let mac0 = <$mac as Mac>::new_from_slice(key).unwrap(); + let mac0 = <$mac as KeyInit>::new_from_slice(key).unwrap(); let mut mac = mac0.clone(); mac.update(input); From 9ec4d99b615ff1e69350e5261db8322a7a03e70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 20:44:53 +0300 Subject: [PATCH 09/10] fmt --- digest/src/dev/mac.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digest/src/dev/mac.rs b/digest/src/dev/mac.rs index b7c5260d7..18f985471 100644 --- a/digest/src/dev/mac.rs +++ b/digest/src/dev/mac.rs @@ -17,7 +17,7 @@ macro_rules! new_mac_test { fn $name() { use core::cmp::min; use digest::dev::blobby::Blob3Iterator; - use digest::{Mac, KeyInit}; + use digest::{KeyInit, Mac}; fn run_test(key: &[u8], input: &[u8], tag: &[u8]) -> Option<&'static str> { let mac0 = <$mac as KeyInit>::new_from_slice(key).unwrap(); @@ -92,7 +92,7 @@ macro_rules! new_resettable_mac_test { fn $name() { use core::cmp::min; use digest::dev::blobby::Blob3Iterator; - use digest::{Mac, KeyInit}; + use digest::{KeyInit, Mac}; fn run_test(key: &[u8], input: &[u8], tag: &[u8]) -> Option<&'static str> { let mac0 = <$mac as KeyInit>::new_from_slice(key).unwrap(); From 7000ab3b693a551efb4037b1167b342ccd8dea78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 19 Dec 2022 20:57:45 +0300 Subject: [PATCH 10/10] Update crypto workflow --- .github/workflows/crypto.yml | 48 ++++++++++-------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/.github/workflows/crypto.yml b/.github/workflows/crypto.yml index 8687448cc..276594d36 100644 --- a/.github/workflows/crypto.yml +++ b/.github/workflows/crypto.yml @@ -40,21 +40,19 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} --features aead,cipher,digest,elliptic-curve,signature,universal-hash - # TODO: use the reusable workflow after this crate will be part of the - # toot workspace - # minimal-versions: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - uses: RustCrypto/actions/cargo-cache@master - # - uses: actions-rs/toolchain@v1 - # with: - # toolchain: nightly - # override: true - # profile: minimal - # - uses: RustCrypto/actions/cargo-hack-install@master - # - run: cargo update -Z minimal-versions - # - run: cargo hack test --release --feature-powerset + minimal-versions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: RustCrypto/actions/cargo-cache@master + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + profile: minimal + - uses: RustCrypto/actions/cargo-hack-install@master + - run: cargo update -Z minimal-versions + - run: cargo hack test --release --feature-powerset test: runs-on: ubuntu-latest @@ -88,23 +86,3 @@ jobs: override: true profile: minimal - run: cargo clippy --all --all-features -- -D warnings - - rustfmt: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v3 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - components: rustfmt - override: true - profile: minimal - - - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check