-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces unkeyed hashing for blake2 as specified in [Section 2.5 of RFC 7693](https://www.rfc-editor.org/rfc/rfc7693.html#section-2.5) states the following: The second (little-endian) byte of the parameter block, "kk", specifies the key size in bytes. Set kk = 00 for unkeyed hashing. I propose to make the key an `Option<&[u8]>`: ```rust pub fn new_with_salt_and_personal( key: Option<&[u8]>, salt: &[u8], persona: &[u8], ) -> Result<Self, InvalidLength> ``` By making the key an `Option<&[u8]>` - rather than opting for the unkeyed usage in case of an empty `key` - we make the unkeyed usage explicit and avoid inadvertent usages. This closes #482. See also #509.
- Loading branch information
1 parent
2795b4f
commit 01e79f7
Showing
4 changed files
with
70 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use blake2::{digest::FixedOutput, Blake2bMac512, Blake2sMac256}; | ||
use hex_literal::hex; | ||
|
||
#[test] | ||
fn blake2s_unkeyed() { | ||
let ctx = Blake2sMac256::new_with_salt_and_personal(None, b"salt", b"persona").unwrap(); | ||
assert_eq!( | ||
ctx.finalize_fixed(), | ||
hex!( | ||
"d7de83e2b1fedd9755db747235b7ba4b" | ||
"f9773a16b91c6b241e4b1d926160d9eb" | ||
), | ||
); | ||
} | ||
|
||
#[test] | ||
fn blake2b_unkeyed() { | ||
let ctx = Blake2bMac512::new_with_salt_and_personal(None, b"salt", b"persona").unwrap(); | ||
assert_eq!( | ||
ctx.finalize_fixed(), | ||
hex!( | ||
"fa3cd38902ae0602d8f0066f18c579fa" | ||
"e8068074fbe91f9f5774f841f5ab51fe" | ||
"39140ad78d6576f8a0b9f8f4c2642211" | ||
"11c9911d8ba1dbefcd034acdbedb8cde" | ||
), | ||
); | ||
} |