Crate hkd32

source · []
Expand description

HMAC-based Hierarchical Key Derivation: deterministically derive a hierarchy of symmetric keys from initial keying material through repeated applications of the Hash-based Message Authentication Code (HMAC) construction.

This library implements a fully symmetric construction inspired by BIP-0032: Hierarchical Deterministic Wallets.

Usage

To derive a key using HKD32, you’ll need the following:

Derivation paths can be raw bytestrings but also support a Unix path-like syntax which can be parsed using the String::parse method:

let path = "/foo/bar/baz".parse::<hkd32::PathBuf>().unwrap();

Example

use rand_core::OsRng;

// Parent key
let input_key_material = hkd32::KeyMaterial::random(&mut OsRng);

// Path to the child key
let derivation_path = "/foo/bar/baz".parse::<hkd32::PathBuf>().unwrap();

// Derive subkey from the parent key. Call `as_bytes()` on this to obtain
// a byte slice containing the derived key.
let output_key_material = input_key_material.derive_subkey(derivation_path);

Modules

Support for BIP39 mnemonic phrases.

Structs

Component of a derivation path

Iterator over the components of a path

Opaque error type

Cryptographic key material: 256-bit (32-byte) uniformly random bytestring generated either via a CSRNG or via hierarchical derivation.

Key derivation paths: location within a key hierarchy which names/identifies a specific key.

Key derivation paths: location within a key hierarchy which names/identifies a specific key.

Constants

Delimiter used for strings containing paths

Size of input key material and derived keys.

Maximum length of a derivation component