Skip to main content

hash_derive_key_context

Function hash_derive_key_context 

Source
pub fn hash_derive_key_context(context: &str) -> ContextKey
Expand description

Hash a key-derivation context string and return a ContextKey.

This has the same security requirement as key derivation. The context string should be hardcoded, globally unique, and application-specific.

Its one use is Mode::DeriveKeyMaterial: a program that derives many keys from one context hashes the context once.

ยงExample

use blake3_servil::Mode;

let context_key = blake3_servil::hash_derive_key_context("foo");
let derived = blake3_servil::hash_with(Mode::DeriveKeyMaterial(&context_key), b"bar");
assert_eq!(derived, blake3_servil::hash_with(Mode::DeriveKey("foo"), b"bar"));