HMAC-base key derivation function (IETF RFC 5869) implemented with Python
Project description
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
- Implements RFC 5869
- See also python-hkdf
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hkdfref-2024.2.tar.gz
.
File metadata
- Download URL: hkdfref-2024.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e1db8ee302a50632f97e70bba728f72650c8c3d6d711a56dc793e7986bd9107 |
|
MD5 | dc42cc815f3902d96ac215288e3b8e17 |
|
BLAKE2b-256 | 7338516301d68c8a98ae26230d5aed4487c084e37d734a0c373bbefc0a8fb63e |
File details
Details for the file hkdfref-2024.2-py3-none-any.whl
.
File metadata
- Download URL: hkdfref-2024.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1d4a53c7daeaae04164d0ab062465d21abfd42233ce308ae492c504e7cfe12b |
|
MD5 | 745792dcff6f4a2f177baa6f1f733aee |
|
BLAKE2b-256 | 35cee0cc065965c255cd1153c4e2260053469be95cd75f291f5cf8494ed924db |