-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blake2 missing functionality while migrating from blake2-rfc
#360
Comments
Unfortunately, how BLAKE2 handles keys does not map well to the API exposed by I think the most practical solution right now will be to introduce |
Currently I'm able to reproduce the output of:
With:
|
@davxy solution works for me use blake2::{
digest::{typenum::U32, FixedOutput, Update},
Blake2bMac,
};
use blake2_rfc::blake2b::Blake2b;
fn main() {
let data = b"hello world";
let key = b"somekey";
let mut ctx = Blake2b::with_key(32, key);
ctx.update(data);
let hash = ctx.finalize();
// hash to string
let hash_str1 = hash
.as_bytes()
.iter()
.map(|b| format!("{:02x}", b))
.collect::<String>();
let mut ctx = Blake2bMac::<U32>::new_with_salt_and_personal(key, &[], &[]).unwrap();
ctx.update(data);
let hash = ctx.finalize_fixed();
// hash to string
let hash_str2 = hash
.iter()
.map(|b| format!("{:02x}", b))
.collect::<String>();
assert_eq!(hash_str1, hash_str2);
} |
Not sure if this is a feature request or a question...
I was previously using the
blake2-rfc
crate and now I want to migrate to theblake2
crate. However previously I was using theBlake2b::with_key
constructor (as per https://docs.rs/blake2-rfc/0.2.18/blake2_rfc/blake2b/struct.Blake2b.html#method.with_key) and I can't seem to find the proper equivalent in case of theblake2
crate.There seems to exist
Blake2bVarCore::new_with_params
(as per https://docs.rs/blake2/0.10.2/blake2/struct.Blake2bVarCore.html#method.new_with_params), however I can't seem to convert that into aBlake2bVar
(which I need to get variable hash output).Based on the current
blake2b
implementation, it seems I should be able to just replace thecore
member of theBlake2bVar
with theBlake2bVarCore
instance, which indeed works if I "hack my way" by using pointers. However there is no "official" (as per the public API) way of doing this.A simple
From
implementation, or even anunsafe
constructor that takes aBlake2bVarCore
and yields aBlake2bVar
would seem to suffice.The text was updated successfully, but these errors were encountered: