Uh oh!
There was an error while loading. Please reload this page.
Add hash customization traits - #1334
Conversation
14159d0 to
a9a41e3Comparenit: BLAKE2 calls this a "personalization string" which I think might be a bit more clear vs "custom" |
sylvainpelissier
commented
Jul 17, 2023
Should I change the function and/or parameter names ? |
tarcieri
commented
Jul 17, 2023
IMO it'd be clearer, but I'm curious what @newpavlov thinks |
newpavlov
commented
Jul 17, 2023
I don't have a particular preference, so I am fine with both options. I wonder if we should use an associated type, instead of simple byte slice. For example, cSHAKE also takes the "function-name" argument, which also can be viewed as a customization parameter. IIRC BLAKE2 in addition to the personalization string also can take salt and perform even finer-grained personalization. |
sylvainpelissier
commented
Jul 17, 2023
For SHA3, the "function-name" argument is more an internal parameter used for example by TupleHash to instantiate CSHAKE. It may not be accessible from outside. For Blake2 I'm not aware of the salt usage. |
a9a41e3 to
e1c7888Comparesylvainpelissier
commented
Jul 17, 2023
I made the changes. |
e1c7888 to
ffab790Comparetarcieri
commented
Jul 17, 2023
I guess BLAKE3 calls it a "context string", and also has some additional stipulations about how it be used (i.e. hardcoded at compile time) |
Uh oh!
There was an error while loading. Please reload this page.
ffab790 to
0e16ed1Comparesylvainpelissier
commented
Jul 24, 2023
Is there anything I need to add to this PR ? |
Uh oh!
There was an error while loading. Please reload this page.
tarcieri
commented
Mar 12, 2024
@sylvainpelissier sorry for the belated reply! I think it'd be good if you could also open a PR to https://github.com/RustCrypto/hashes which impls these traits, so we can see if e.g. the potential name conflict I was asking about would occur in practice. Looks like this also needs a rebase. |
Uh oh!
There was an error while loading. Please reload this page.
tarcieri
commented
Mar 13, 2024
I've changed my mind on the name "personalization", especially since it's used by BLAKE2 but not BLAKE3. I know I didn't like "custom" before, but "customization" seems ok? It also goes well with e.g. cSHAKE. |
7793e0e to
3704a14Comparesylvainpelissier
commented
Mar 15, 2024
I'm not able to make a PR in hashes. There is an existing error when compiling hashes with the latest commit of trait (6c5f56e) without my modifications: $ cargo build
Compiling digest v0.11.0-pre.8 (https://github.com/RustCrypto/traits?rev=6c5f56e206ff0bbf6ac8b51a6cf4730d278d7c8b#6c5f56e2)
Compiling sha3 v0.11.0-pre.3 (/home/sylvain/software/hashes/sha3)
Compiling k12 v0.4.0-pre (/home/sylvain/software/hashes/k12)
error[E0277]: the trait bound `TurboShake128ReaderCore: digest::core_api::XofReaderCore` is not satisfied
--> k12/src/lib.rs:207:11
|
207 | tshk: XofReaderCoreWrapper<TurboShake128ReaderCore>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `digest::core_api::XofReaderCore` is not implemented for`TurboShake128ReaderCore`|
= help: the trait `digest::core_api::XofReaderCore` is implemented for`KangarooTwelveReaderCore`
note: required by a bound in`digest::core_api::XofReaderCoreWrapper`
--> /home/sylvain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/digest-0.11.0-pre.8/src/core_api/xof_reader.rs:12:8
|
10 | pub struct XofReaderCoreWrapper<T>| -------------------- required by a bound in this struct
11 | where
12 | T: XofReaderCore,
| ^^^^^^^^^^^^^ required by this bound in`XofReaderCoreWrapper`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `k12` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...Would you prefer I rebase my modification at digest-v0.11.0-pre.8 |
tarcieri
commented
Mar 15, 2024
Can you still open a PR so we can see the error in context? It's hard to tell what's wrong without code. |
sylvainpelissier
commented
Apr 11, 2024
It seems there is no naming conflict in hashes. Is there still something missing ? |
tarcieri
commented
Apr 11, 2024
I would still suggest changing the name to |
3704a14 to
ca4e628Comparesylvainpelissier
commented
Apr 12, 2024
Ah yes, I made the change to |
tarcieri
commented
Apr 12, 2024
@sylvainpelissier can you also change the trait name from |
ca4e628 to
665aee9Comparesylvainpelissier
commented
Apr 12, 2024
Yes right. It should be good now. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tarcieri
commented
Apr 12, 2024
Needs rustfmt |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
23e0117 to
415c2ceCompare415c2ce to
ec3e8ffComparenewpavlov
commented
Apr 12, 2024
Thank you! |
Use the new function `new_customized` from RustCrypto/traits#1334 in CSHAKE tests
## Added - `CustomizedInit` trait (#1334) - `SerializableState` support (#1369) - `DynDigestWithOid` wrapper trait (#1390) - `VariableOutputCoreCustomized` trait (#1787, #2043) - `buffer_fixed`, `buffer_ct_variable`, `buffer_rt_variable`, and `buffer_xof` macros (#1799) - `XofFixedWrapper` (#1815) - `CollisionResistance` trait (#1820) - `CoreProxy::compose/decompose` methods (#1898) - `EagerHash` trait (#2014) ## Changed - Replaced `generic-array` with `hybrid-array` (#1358) - `crypto-common` dependency bumped to v0.2 (#1173) - Edition changed to 2024 and MSRV bumped to 1.85 (#1759) - Bump `const-oid` dependency to v0.10 (#1772) - `digest::core_api` renamed to `digest::block_api` (#1799) - `CtVariableCoreWrapper` renamed to `CtOutWrapper` (#1799) - Removed the OID type parameter from `CtOutWrapper` (#1799) - Implementations of the `SerializableState` trait (#1953) - `new_test!` and `new_mac_test!` macros (#1958) - Bump `block-buffer` to v0.11 (#2082) - Re-export of `crypto-common` moved to `digest::common` (#2237) - Bump `crypto-common` to v0.2 (#2276) - Replace `subtle` with `ctutils` (#2301) ## Removed - `Mac::{new, new_from_slice, generate_key}` methods (#1173) - `CoreWrapper`, `RtVariableCoreWrapper`, and `XofReaderCoreWrapper` types (#1799) - `io::Write/Read` implementations in favor of the `digest_io::IoWrapper` type (#1809) - `VariableOutput` trait (#2043) - Implementation of `subtle::ConstantTimeEq` for `CtOutput`. Note that implementation of `PartialEq`/`Eq` trait is still const time. (#2292)
Some hash function constructions allow to have a customization string to have domain separation in hash functions. This is the case for CSHAKE and Blake2:
With these new traits, the construction of hash functions with customization strings would be simpler. From currently for CSHAKE:
To: