Skip to main content

hkdfref - HMAC-based key derivation function

Key derivation functions (KDFs) take as input certain initial keying material and return certain cryptographically strong secret keys. Cryptographic systems require KDFs. This tool provides a reference implementation of the HMAC-based KDF described in RFC 5869 (HKDF).


Details

The HKDF is modular, consisting of

  • extract (the function hkdfref.extract)
  • and expand (the function hkdfref.expand) parts.

In the extract part, a fixed-length psuedorandom key is extracted from the initial keying material. The extract part aims to increase the informational uniformity of the inital keying material. Scenarios where this step is helpful in particular includes: when an attacker might have partial knowledge or control of these input materials. Scenarios where this step is less helpful includes: the initial keying material is of sufficiently high informational uniformity. The RFC describes the extract part as optional.

In the expand part, the fixed-length pseudorandom key is exapnded into several additional pseudorandom keys. These several additional pseudorandom keys are the output of HKDF. The aim of this part is to ensure the output keys are suitable for a specific cyrptographic algorithm.

The differentiation of extract and expand parts is viewed in this RFC as circumventing possible shortcomings in KDF design. Further, the RFC's stated goal is to "accomodate a whide range of KDF requirements while minimizing the assumptions about the underlying hash function". The two parts can be executed together as described, using hkdfref.hkdf.

Usage

A simple example:

from hkdfref import hkdf


# input keying material
ikm = b"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"

# some salt bytes to pass to extract
salt = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c"

# information padding bytes
info = b"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9"

# desired output key material length
l = 42


# a secure cryptographic key (uses sha512)
okm = hkdf(ikm, salt=salt, info=info, l=l)

Installation

Depends only on the standard library. Sources available on GitHub and PyPI. Use pip to install:

python3 -m pip install hkdfref

References

Release files for hkdfref 2024.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hkdfref 2024.2
File Size Uploaded
hkdfref-2024.2.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hkdfref 2024.2
File Interpreter ABI Platform
hkdfref-2024.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / hkdfref-2024.2.tar.gz

Download URL hkdfref-2024.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5e1db8ee302a50632f97e70bba728f72650c8c3d6d711a56dc793e7986bd9107
BLAKE2b-256 checksum
How to use checksums
7338516301d68c8a98ae26230d5aed4487c084e37d734a0c373bbefc0a8fb63e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / hkdfref-2024.2-py3-none-any.whl

Download URL hkdfref-2024.2-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1d4a53c7daeaae04164d0ab062465d21abfd42233ce308ae492c504e7cfe12b
BLAKE2b-256 checksum
How to use checksums
35cee0cc065965c255cd1153c4e2260053469be95cd75f291f5cf8494ed924db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

2024.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page