Skip to content
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

How to use BLAKE3 with HKDF? #223

Closed
jbis9051 opened this issue Jan 22, 2022 · 4 comments
Closed

How to use BLAKE3 with HKDF? #223

jbis9051 opened this issue Jan 22, 2022 · 4 comments

Comments

@jbis9051
Copy link
Contributor

I attempted to use the following from https://github.com/RustCrypto/KDFs/

Hkdf::<CoreWrapper<CtVariableCoreWrapper<blake3::Hasher, U32>>>

however I am getting

error[E0277]: the trait bound `blake3::Hasher: digest::core_api::VariableOutputCore` is not satisfied
  --> peer/src/services/wpskka_client_handler.rs:65:27
   |
65 |         /*             code          */
   |                           ^^^^ the trait `digest::core_api::VariableOutputCore` is not implemented for `blake3::Hasher`
   |
   = note: required because of the requirements on the impl of `crypto_common::BlockSizeUser` for `digest::core_api::ct_variable::CtVariableCoreWrapper<blake3::Hasher, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>>`
   = note: required because of the requirements on the impl of `digest::core_api::wrapper::CoreProxy` for `digest::core_api::wrapper::CoreWrapper<digest::core_api::ct_variable::CtVariableCoreWrapper<blake3::Hasher, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>>>`
@oconnor663
Copy link
Member

The hmac crate provides a SimpleHmac API for hashes that haven't integrated themselves with the new UpdateCore trait, but it looks like hkdf doesn't have something similar? I haven't put in the time yet to understand these new traits or how much work it would be to integrate this crate with them. See also #212 and RustCrypto/KDFs#54.

For what it's worth, BLAKE3 provides a derive_key, which supports many of the same use cases as HKDF. That could be an alternative.

@jbis9051
Copy link
Contributor Author

@oconnor663 Thanks for the suggestion, unfortunately the spec calls for HMAC so I can't use derive_key.


Possibly a different issue, but I'm having trouble using SimpleHmac as well

use hmac::{Mac, SimpleHmac};
use blake3::{Hasher};

fn main() {
   let mut x = SimpleHmac::<Hasher>::new_from_slice(b"test");
   x.update(b"test2");
   println!("{:?}", x.finalize().into_bytes());
}
error[E0599]: the function or associated item `new_from_slice` exists for struct `SimpleHmac<blake3::Hasher>`, but its trait bounds were not satisfied
  --> src/main.rs:5:38
   |
5  |    let mut x = SimpleHmac::<Hasher>::new_from_slice(b"test");
   |                                      ^^^^^^^^^^^^^^ function or associated item cannot be called on `SimpleHmac<blake3::Hasher>` due to unsatisfied trait bounds
   |
  ::: /Users/jbis/.cargo/registry/src/github.com-1ecc6299db9ec823/hmac-0.12.0/src/simple.rs:14:1
   |
14 | pub struct SimpleHmac<D: Digest + BlockSizeUser> {
   | ------------------------------------------------
   | |
   | doesn't satisfy `SimpleHmac<blake3::Hasher>: FixedOutput`
   | doesn't satisfy `SimpleHmac<blake3::Hasher>: KeyInit`
   | doesn't satisfy `SimpleHmac<blake3::Hasher>: MacMarker`
   | doesn't satisfy `SimpleHmac<blake3::Hasher>: Mac`
   | doesn't satisfy `SimpleHmac<blake3::Hasher>: Sized`
   | doesn't satisfy `SimpleHmac<blake3::Hasher>: Update`
   |
   = note: the following trait bounds were not satisfied:
           `SimpleHmac<blake3::Hasher>: Sized`
           which is required by `SimpleHmac<blake3::Hasher>: Mac`
           `SimpleHmac<blake3::Hasher>: KeyInit`
           which is required by `SimpleHmac<blake3::Hasher>: Mac`
           `SimpleHmac<blake3::Hasher>: Update`
           which is required by `SimpleHmac<blake3::Hasher>: Mac`
           `SimpleHmac<blake3::Hasher>: FixedOutput`
           which is required by `SimpleHmac<blake3::Hasher>: Mac`
           `SimpleHmac<blake3::Hasher>: MacMarker`
           which is required by `SimpleHmac<blake3::Hasher>: Mac`
           `&SimpleHmac<blake3::Hasher>: KeyInit`
           which is required by `&SimpleHmac<blake3::Hasher>: Mac`
           `&SimpleHmac<blake3::Hasher>: Update`
           which is required by `&SimpleHmac<blake3::Hasher>: Mac`
           `&SimpleHmac<blake3::Hasher>: FixedOutput`
           which is required by `&SimpleHmac<blake3::Hasher>: Mac`
           `&SimpleHmac<blake3::Hasher>: MacMarker`
           which is required by `&SimpleHmac<blake3::Hasher>: Mac`
           `&mut SimpleHmac<blake3::Hasher>: KeyInit`
           which is required by `&mut SimpleHmac<blake3::Hasher>: Mac`
           `&mut SimpleHmac<blake3::Hasher>: Update`
           which is required by `&mut SimpleHmac<blake3::Hasher>: Mac`
           `&mut SimpleHmac<blake3::Hasher>: FixedOutput`
           which is required by `&mut SimpleHmac<blake3::Hasher>: Mac`
           `&mut SimpleHmac<blake3::Hasher>: MacMarker`
           which is required by `&mut SimpleHmac<blake3::Hasher>: Mac`

This is with

[dependencies]
hmac = "0.12.0"
blake3 = { version = "1.3.0", features = ["traits-preview"] }

@tarcieri
Copy link

cc @newpavlov

@jbis9051
Copy link
Contributor Author

jbis9051 commented Jan 23, 2022

Closed in favor of #224. HKDF uses Hmac. BLAKE3 isn't compatible with Hmac. However, it should be compatible with SimpleHmac (see the other issue). Once it works for SimpleHmac and RustCrypto/KDFs#56 is merged, blake3 will work with HKDF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants