From d0b8719701664a1140c74ad3cc319c1dc430dc76 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 26 Jan 2024 12:30:00 -0700 Subject: [PATCH] crypto-common: rename `serializable_state` module to `hazmat` Also removes the toplevel re-exports for the traits, forcing users to go through the now `pub hazmat` module. There's a lot of misuse potential with these traits, which are intended to make it possible to serialize/deserialize the internal state of hash functions. However previously they were presented side-by-side with other traits, which made that unclear. This commit deliberately doesn't make other changes to the file so git will preserve its history: diff --git a/crypto-common/src/serializable_state.rs b/crypto-common/src/hazmat.rs similarity index 100% rename from crypto-common/src/serializable_state.rs rename to crypto-common/src/hazmat.rs It would be very good for a followup commit to massively expand the documentation around both the module and the traits, especially to spell out the various ways they can be misused. --- Cargo.lock | 43 +++++-------------- Cargo.toml | 2 + .../src/{serializable_state.rs => hazmat.rs} | 0 crypto-common/src/lib.rs | 9 ++-- digest/src/core_api/ct_variable.rs | 4 +- digest/src/core_api/rt_variable.rs | 4 +- digest/src/core_api/wrapper.rs | 4 +- 7 files changed, 21 insertions(+), 45 deletions(-) rename crypto-common/src/{serializable_state.rs => hazmat.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 79faf45a..2ecedf26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ dependencies = [ "arrayvec", "blobby", "bytes", - "crypto-common 0.2.0-pre.4 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-common 0.2.0-pre.4", "heapless", ] @@ -136,7 +136,7 @@ version = "0.11.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0edadbde8e0243b49d434f9a23ec0590af201f400a34d7d51049284e4a77c568" dependencies = [ - "crypto-common 0.2.0-pre.4 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-common 0.2.0-pre.4", "zeroize", ] @@ -226,7 +226,7 @@ name = "cipher" version = "0.5.0-pre.2" dependencies = [ "blobby", - "crypto-common 0.2.0-pre.4 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-common 0.2.0-pre.4", "inout 0.2.0-pre.4", "zeroize", ] @@ -341,17 +341,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "crypto-common" -version = "0.2.0-pre.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806e4e3731d44f1340b069551225b44c2056c105cad9e67f0c46266db8a3a6b9" -dependencies = [ - "getrandom", - "hybrid-array", - "rand_core 0.6.4", -] - [[package]] name = "crypto-mac" version = "0.11.0" @@ -450,23 +439,11 @@ dependencies = [ "blobby", "block-buffer 0.11.0-pre.4", "const-oid 0.10.0-pre.2", - "crypto-common 0.2.0-pre.4 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-common 0.2.0-pre.4", "subtle", "zeroize", ] -[[package]] -name = "digest" -version = "0.11.0-pre.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957713a19ffdda287c63772e607f848512f67ba948f17d8e42cb8d50fd98a786" -dependencies = [ - "block-buffer 0.11.0-pre.4", - "const-oid 0.10.0-pre.2", - "crypto-common 0.2.0-pre.4 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle", -] - [[package]] name = "dunce" version = "1.0.4" @@ -546,7 +523,7 @@ dependencies = [ "base16ct 0.2.0", "base64ct", "crypto-bigint 0.6.0-pre.12", - "digest 0.11.0-pre.7 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.11.0-pre.7", "ff 0.13.0", "group 0.13.0", "hex-literal", @@ -751,7 +728,7 @@ version = "0.13.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fac01891f12d968a2737928c9af2532abdc750e56a890fdbcafdfff17017678" dependencies = [ - "digest 0.11.0-pre.7 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.11.0-pre.7", ] [[package]] @@ -1216,7 +1193,7 @@ checksum = "e18b939d4051b69874cbdb8f55de6a14ae44b357ccb94bdbd0a2122f8f875a46" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.11.0-pre.7 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.11.0-pre.7", ] [[package]] @@ -1225,7 +1202,7 @@ version = "0.11.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cecb44e361133b3304a1b3e325a1d8c999339fec8c19762b55e1509a17d6806" dependencies = [ - "digest 0.11.0-pre.7 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.11.0-pre.7", "keccak", ] @@ -1252,7 +1229,7 @@ dependencies = [ name = "signature" version = "2.3.0-pre.2" dependencies = [ - "digest 0.11.0-pre.7 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.11.0-pre.7", "hex-literal", "rand_core 0.6.4", "sha2 0.11.0-pre.2", @@ -1352,7 +1329,7 @@ dependencies = [ name = "universal-hash" version = "0.6.0-pre" dependencies = [ - "crypto-common 0.2.0-pre.4 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-common 0.2.0-pre.4", "subtle", ] diff --git a/Cargo.toml b/Cargo.toml index e1fa03b8..354080ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,6 @@ members = [ ] [patch.crates-io] +crypto-common = { path = "./crypto-common" } +digest = { path = "./digest" } signature = { path = "./signature" } diff --git a/crypto-common/src/serializable_state.rs b/crypto-common/src/hazmat.rs similarity index 100% rename from crypto-common/src/serializable_state.rs rename to crypto-common/src/hazmat.rs diff --git a/crypto-common/src/lib.rs b/crypto-common/src/lib.rs index bdaff2cd..45ee0553 100644 --- a/crypto-common/src/lib.rs +++ b/crypto-common/src/lib.rs @@ -12,6 +12,9 @@ #[cfg(feature = "std")] extern crate std; +/// Hazardous materials. +pub mod hazmat; + #[cfg(feature = "getrandom")] pub use getrandom; #[cfg(feature = "rand_core")] @@ -29,12 +32,6 @@ use hybrid_array::{ #[cfg(feature = "rand_core")] use rand_core::CryptoRngCore; -mod serializable_state; -pub use serializable_state::{ - AddSerializedStateSize, DeserializeStateError, SerializableState, SerializedState, - SubSerializedStateSize, -}; - /// Block on which [`BlockSizeUser`] implementors operate. pub type Block = Array::BlockSize>; diff --git a/digest/src/core_api/ct_variable.rs b/digest/src/core_api/ct_variable.rs index fe3aa86c..fe917bfd 100644 --- a/digest/src/core_api/ct_variable.rs +++ b/digest/src/core_api/ct_variable.rs @@ -14,9 +14,9 @@ use core::{ }; use crypto_common::{ array::{Array, ArraySize}, + hazmat::{DeserializeStateError, SerializableState, SerializedState, SubSerializedStateSize}, typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, Sum, U1, U256}, - Block, BlockSizeUser, DeserializeStateError, OutputSizeUser, SerializableState, - SerializedState, SubSerializedStateSize, + Block, BlockSizeUser, OutputSizeUser, }; /// Dummy type used with [`CtVariableCoreWrapper`] in cases when diff --git a/digest/src/core_api/rt_variable.rs b/digest/src/core_api/rt_variable.rs index c9631e92..ccbb563a 100644 --- a/digest/src/core_api/rt_variable.rs +++ b/digest/src/core_api/rt_variable.rs @@ -9,11 +9,11 @@ use core::{ fmt, ops::{Add, Sub}, }; -use crypto_common::SubSerializedStateSize; use crypto_common::{ array::{Array, ArraySize}, + hazmat::{DeserializeStateError, SerializableState, SerializedState, SubSerializedStateSize}, typenum::{Diff, IsLess, Le, NonZero, Sum, Unsigned, U1, U256}, - AddBlockSize, DeserializeStateError, SerializableState, SerializedState, SubBlockSize, + AddBlockSize, SubBlockSize, }; #[cfg(feature = "zeroize")] use zeroize::ZeroizeOnDrop; diff --git a/digest/src/core_api/wrapper.rs b/digest/src/core_api/wrapper.rs index fc3ca9d9..32b8a5a1 100644 --- a/digest/src/core_api/wrapper.rs +++ b/digest/src/core_api/wrapper.rs @@ -13,9 +13,9 @@ use core::{ }; use crypto_common::{ array::{Array, ArraySize}, + hazmat::{DeserializeStateError, SerializableState, SerializedState, SubSerializedStateSize}, typenum::{Diff, IsLess, Le, NonZero, Sum, U1, U256}, - BlockSizeUser, DeserializeStateError, InvalidLength, Key, KeyInit, KeySizeUser, Output, - SerializableState, SerializedState, SubSerializedStateSize, + BlockSizeUser, InvalidLength, Key, KeyInit, KeySizeUser, Output, }; #[cfg(feature = "mac")]