Preview of main at f2aeee3, 2026-12-05

hash is one entry point for hashing and key derivation in a C++20 program, on every target webcpp has, one of the libraries of webcpp. The algorithms are Boost.Hash2’s and those of C libraries, each a backend that the program names in its own Jamfile.

This page is written for two readers at once: a developer who knows little cryptography and wants the right function for an application, and a language model that reads it to choose a function for someone. Both can start at Choose by use case, which goes from a need to a function, a backend and a program that shows it. The chapters after it teach one family of functions each, opening with two tables that compare everything in the family, what each function is and how to choose it; each section says what a function is for, shows a program of example/ that the build compiles and runs on every target with the output it prints, and lists the mistakes that cost security. Three chapters then follow an application from end to end: a peer-to-peer network, a cryptocurrency wallet, and the privacy of a login and a password manager. The reference that closes the page lists every name the headers declare, and llms.txt, beside this page, is the same guide as an index for language models (An index for language models).

Why hash

webcpp::hash is one entry point for hashing and key derivation in a C++ program, on every target webcpp has: native (Linux x86-64 and arm64, macOS arm64, Windows with MSVC), wasip2, wasip3 and Emscripten. It is a wrapper: webcpp’s interface over code other projects wrote.

A hash function turns any amount of data into a short, fixed-size value, its digest, such that the same input always gives the same digest and different inputs, in practice, never do. A cryptographic hash adds that nobody can find two inputs with the same digest, or an input for a given digest, without an amount of work no computer will ever do. Everything else on this page is built from that property: a message authentication code is a hash that only the holder of a key can compute; a key derivation function turns one secret into several keys, or a password into a key; a password hash makes every guess of a stolen password database slow and costly. Each of them protects something an ordinary application holds: the integrity of a downloaded file, the authenticity of a request, the keys of an encrypted chat, the passwords of a login.

What Where it comes from

MD5, SHA-1, SHA-2, SHA-3, SHAKE, RIPEMD, BLAKE2b/s, the non-cryptographic hashes, HMAC

Boost.Hash2, re-exported by alias, and backends::hash2 for the families

The families: digest_of and hasher over a tag of digests, mac over a tag of macs, argon2 over a tag of kdfs

the tag’s default backend, or the backend the call names (One call, or pieces with one result: digest_of and hasher, A MAC in one call: mac, Every parameter of Argon2: argon2)

Keccak-256 with the original padding (Ethereum’s)

XKCP’s Keccak-p[1600] permutation, in Hash2’s HashAlgorithm form

Keccak-224 to Keccak-512, SHA-3 and SHAKE; SP 800-185’s cSHAKE, KMAC, TupleHash and ParallelHash; RFC 9861’s KangarooTwelve and TurboSHAKE

XKCP’s own code, backends::xkcp, through digest_of, hasher and mac

BLAKE3, keyed BLAKE3, BLAKE3’s key derivation and its extendable output

the official BLAKE3 C implementation, in Hash2’s HashAlgorithm form

HKDF (RFC 5869: extract, expand, extract-and-expand)

a backend: backends::hash2, backends::sodium, backends::bearssl, backends::openssl, backends::botan

PBKDF2 (RFC 8018)

a backend: backends::hash2, backends::openssl, backends::botan

Argon2id (RFC 9106, parallelism 1)

libsodium’s crypto_pwhash_argon2id

Argon2i and Argon2id with the parameters of RFC 9106 (argon2)

libsodium’s crypto_pwhash_argon2i and crypto_pwhash_argon2id, one lane

scrypt (RFC 7914)

libsodium’s crypto_pwhash_scryptsalsa208sha256_ll

BLAKE2b subkeys (libsodium’s crypto_kdf)

libsodium’s crypto_kdf_blake2b_derive_from_key

TurboSHAKE128 and TurboSHAKE256 (RFC 9861)

libsodium’s crypto_xof_turboshake128 and crypto_xof_turboshake256

BLAKE2b with key, salt, personalisation and length; SHA-256/512, SHA3-256/512, SHAKE; HMAC-SHA-256/512; keyed BLAKE2b, SipHash-2-4 and SipHash-2-4x as MACs

libsodium, backends::sodium

MD5, SHA-1, SHA-2, MD5-SHA1 and SHAKE as digests; HMAC and HKDF over MD5, SHA-1 and SHA-2

BearSSL, backends::bearssl named in the call

MD5, SHA-1, SHA-2, SHA-3, SHAKE, Keccak, BLAKE2, RIPEMD-160, MD5-SHA1 and SM3 as digests; HMAC, KMAC, SipHash and keyed BLAKE2 as MACs; HKDF, PBKDF2, Argon2 and scrypt

OpenSSL 3.5’s EVP_MD, EVP_MAC and EVP_KDF, backends::openssl named in the call

KBKDF (NIST SP 800-108), the one-step KDF (NIST SP 800-56C), the X9.63 KDF (ANSI X9.63)

OpenSSL’s EVP_KDF implementations or Botan’s KDF, on backends::openssl or backends::botan named in the call

MD5, SHA-1, SHA-2, SHA-3, SHAKE, Keccak, BLAKE2, RIPEMD-160, SM3, Streebog, Whirlpool and Skein-512 as digests; HMAC over them, KMAC, SipHash and keyed BLAKE2b as MACs; HKDF, PBKDF2, Argon2, scrypt and the key derivations of standards; bcrypt and bcrypt_pbkdf (bcrypt.hpp)

Botan 3.14.1, backends::botan named in the call, natively and on Emscripten, in a program built with exceptions; Streebog, Whirlpool, Skein-512, their HMACs, bcrypt and bcrypt_pbkdf are Botan’s alone

Asynchronous forms: async_digest, async_hmac, async_hkdf, async_pbkdf2, async_argon2id, async_argon2, async_scrypt, async_bcrypt, async_bcrypt_pbkdf, async_bcrypt_verify

<webcpp/hash/async.hpp> over webcpp::asio, on the synchronous default backend, or on backends::webcrypto, the browser’s WebCrypto, named in the type on Emscripten (Asynchronous calls)

Every synchronous function reports failure as a value (boost::system::result), takes its data as std::span, and allocates nothing in webcpp’s own code (What each backend does with secrets and memory names what the C libraries allocate). <webcpp/hash/async.hpp> gives the slow ones and the ones WebCrypto has an asynchronous form, which completes through an event loop with a boost::system::error_code (Asynchronous calls). No exception leaves hash: backends::botan, whose library throws, needs a build with exceptions, and hash catches Botan’s at each call’s boundary (Exceptions).

The shape of a hash

A hash comes in two shapes. The types of algorithms.hpp, hmac.hpp, keccak.hpp and blake3.hpp have Boost.Hash2’s shape, the HashAlgorithm: construct it (with a key or a seed where it takes one), update it with bytes as often as the data arrives, and call result for the digest, a digest<N> of N bytes, or an integer for the non-cryptographic hashes and SipHash; the type is Hash2’s own, so every part of Hash2, hash_append and get_integral_result among them, takes it unchanged, and result can be called again. The families take a tag and a backend instead: digest_of hashes a message in one call, hasher takes it in pieces and gives exactly one result (a second finish is error::invalid_state), mac computes a tag in one call, and argon2 derives a key (One call, or pieces with one result: digest_of and hasher, A MAC in one call: mac). digest_of, mac, argon2 and every key derivation are functions that fill a caller’s std::span and return boost::system::result<void>; hasher is a type whose finish does the same.

The examples share one small header, example/hex.hpp, which writes bytes in hexadecimal and reads text and hexadecimal as bytes:

#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <vector>

namespace example {

/** The bytes of `data`, two lowercase hexadecimal digits each. */
inline std::string hex(std::span<std::uint8_t const> data) {
    constexpr std::string_view digits = "0123456789abcdef";
    std::string out;
    out.reserve(2 * data.size());
    for (std::uint8_t const byte : data) {
        out += digits[byte >> 4U];
        out += digits[byte & 0x0fU];
    }
    return out;
}

/** The bytes of `text`, as they are: a password, a label, a message. */
inline std::span<std::uint8_t const> bytes(std::string_view text) {
    // A char and a std::uint8_t share their object representation.
    return {reinterpret_cast<std::uint8_t const*>(text.data()), text.size()};
}

/** The bytes `text` writes in hexadecimal, two digits each. */
inline std::vector<std::uint8_t> from_hex(std::string_view text) {
    auto const digit = [](char c) {
        auto const u = static_cast<unsigned char>(c);
        return u <= '9' ? u - unsigned{'0'} : (u | 0x20U) - unsigned{'a'} + 10U;
    };
    std::vector<std::uint8_t> out(text.size() / 2);
    for (std::size_t i = 0; i < out.size(); ++i) {
        out[i] = static_cast<std::uint8_t>((digit(text[2 * i]) << 4U) | digit(text[(2 * i) + 1]));
    }
    return out;
}

}  // namespace example

What hash is not

hash is not a new implementation of a primitive: every permutation, compression function and hash is Boost.Hash2’s or a C library’s, and the two constructions webcpp writes over them are listed in The code webcpp writes, and what the C libraries do. It is not webcpp::crypto either: encryption, signatures and randomness stay there. Constant-time comparison is webcpp::secure’s, which hash depends on: webcpp::secure::constant_time_equal is what compares a MAC. It holds primitives only: what a protocol defines on top of them (Bitcoin’s BIP39 seeds and hash160, Ethereum’s EIP-55 addresses, Nostr’s event ids and NIP-44’s keys) belongs to domain libraries, webcpp::bitcoin, webcpp::ethereum and webcpp::nostr, which build them from these functions. The chapters by use case show those steps as examples, each marked as what such a library builds, never as hash’s API.

Choose by use case

Find the need in the first column; the row names the function and its parameters, the backends that implement it with the line the program’s Jamfile adds, what to do about the backend, and the program of example/ that shows it. The section the function’s name links teaches it and its mistakes. The backend column is the capability table’s, doc/capabilities.json, and the table is generated from it and from doc/guide.json.

I need to …​ Use Its backends: the Jamfile names Backend Example

check that a file or message was not changed by accident or on the way

sha2_256 (or blake3 for large data)

hash2: /webcpp/hash//hash

none: one backend

example/sha256.cpp

name content by what it holds (a file-sharing app, a cache, a store of blobs)

blake3

blake3: /third_party//blake3

link /third_party//blake3

example/content_address.cpp

prove a message comes from someone who holds a shared secret key (an API request, a cookie, a webhook)

hmac_sha2_256, checked with webcpp::secure::constant_time_equal

hash2: /webcpp/hash//hash

none: one backend

example/hmac_sha256.cpp

store users’ passwords for a login

argon2id with argon2id_interactive or stronger, a random 16-byte salt per user

sodium: /third_party//sodium, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan

link /third_party//sodium

example/password_storage.cpp

turn a password into an encryption key (a password manager, an encrypted backup)

argon2id with argon2id_moderate or argon2id_sensitive, then hkdf for each purpose

sodium: /third_party//sodium, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan

link /third_party//sodium

example/argon2id.cpp

check or make the bcrypt strings a system already stores, or read and write OpenSSH’s encrypted private keys

bcrypt and bcrypt_verify at a cost of 10 or more (bcrypt_pbkdf for OpenSSH’s keys); argon2id for a new design

botan (with exceptions only): /third_party//botan

name backends::botan and link /third_party//botan, with exceptions

example/bcrypt.cpp

turn a shared secret (an ECDH result) into keys

hkdf over hmac_sha2_256, one application info label per key

hash2: /webcpp/hash//hash, sodium: /third_party//sodium, bearssl: /third_party//bearssl, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan, webcrypto (asynchronous family only): /webcpp/asio//asio

the default; name a backend only to match another program’s

example/hkdf.cpp

derive the key JOSE’s ECDH-ES (a JWE) or another NIST SP 800-56C protocol derives from a shared secret

sskdf over digests::sha2_256, the fixed info as the protocol writes it

openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan

name backends::openssl (or backends::botan) and link its library, /webcpp/hash//openssl (or /third_party//botan)

example/sskdf.cpp

derive the keys of ECIES or of a smart card’s key agreement (ANSI X9.63)

x963kdf over digests::sha2_256, the shared info as the scheme writes it

openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan

name backends::openssl (or backends::botan) and link its library, /webcpp/hash//openssl (or /third_party//botan)

example/x963kdf.cpp

derive keys from a key as NIST SP 800-108 or Kerberos does (a label and a context)

kbkdf over hmac_sha2_256 with the label and the context

openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan

name backends::openssl (or backends::botan) and link its library, /webcpp/hash//openssl (or /third_party//botan)

example/kbkdf.cpp

derive many keys from one master key, one per purpose

hkdf_expand (or hkdf) with distinct application info labels, blake2b_subkey (libsodium’s crypto_kdf) by id, or blake3::derive_key with a context string

hash2: /webcpp/hash//hash, sodium: /third_party//sodium, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan, webcrypto (asynchronous family only): /webcpp/asio//asio

the default

example/subkeys.cpp

build a hash table, set or Bloom filter whose keys come from the network

siphash_64 keyed with 16 random bytes per process

hash2: /webcpp/hash//hash

none: one backend

example/siphash.cpp

build a hash table of my own trusted keys, or a fast checksum

xxh3_128 or fnv1a_64

hash2: /webcpp/hash//hash

none: one backend

example/checksums.cpp

compute a Bitcoin wallet’s BIP39 seed from its words

pbkdf2 over hmac_sha2_512, 2,048 iterations (a domain library’s step)

hash2: /webcpp/hash//hash, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan, webcrypto (asynchronous family only): /webcpp/asio//asio

the default

example/bip39_seed.cpp

compute a Bitcoin address’s hash160

ripemd_160 over sha2_256 (a domain library’s step)

hash2: /webcpp/hash//hash

none: one backend

example/bitcoin_hash160.cpp

compute an Ethereum address or a Solidity selector

keccak_256 (never sha3_256)

xkcp: /third_party//xkcp

link /third_party//xkcp

example/ethereum_address.cpp

compute a Nostr event id

sha2_256 over NIP-01’s serialization (a domain library’s step)

hash2: /webcpp/hash//hash

none: one backend

example/nostr_event_id.cpp

derive NIP-44’s conversation key

hkdf_extract over hmac_sha2_256 with the salt nip44-v2 (a domain library’s step)

hash2: /webcpp/hash//hash, sodium: /third_party//sodium, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan, webcrypto (asynchronous family only): /webcpp/asio//asio

the default

example/nip44_conversation_key.cpp

draw a long stream of pseudorandom bytes from a seed

shake_128 or shake_256, or blake3’s squeeze

hash2: /webcpp/hash//hash

none: one backend

example/sha3_shake.cpp

build the smallest WebAssembly program

the default backend, backends::hash2, header-only, and link only the libraries the program uses

hash2: /webcpp/hash//hash, sodium: /third_party//sodium, bearssl: /third_party//bearssl, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan, webcrypto (asynchronous family only): /webcpp/asio//asio

the default

example/hkdf_backends.cpp

run the same code, with the same results, on every target

the default backend, backends::hash2, the same code on every target

hash2: /webcpp/hash//hash, sodium: /third_party//sodium, bearssl: /third_party//bearssl, openssl: /webcpp/hash//openssl, botan (with exceptions only): /third_party//botan, webcrypto (asynchronous family only): /webcpp/asio//asio

the default

example/hkdf_backends.cpp

Three rules decide most cases that the table does not list.

  1. A password is never a key. Anything a person types and remembers is guessable: it goes through Argon2id (Argon2id) before it becomes a key, never through a digest, an HMAC or HKDF alone.

  2. A secret that is already random needs no slow function. A Diffie-Hellman result, a master key or 32 bytes from webcpp::crypto::random_device go through HKDF (HKDF), which is fast and separates each purpose by its info label.

  3. A standard names its function. Ethereum names Keccak-256, BIP39 names PBKDF2-HMAC-SHA-512, Nostr names SHA-256: use exactly what the format names, even where a newer function would be chosen for a new design.

Using webcpp::hash in your Jamfile

hash is header-only. A program names /webcpp/hash//hash, which adds hash’s include directory, Boost’s headers and webcpp’s configuration, and the C library of each part it uses; webcpp builds each C library from its pinned sources, for the program’s target:

The program uses Its Jamfile adds Targets

Boost.Hash2’s digests, HMAC and SipHash; HKDF and PBKDF2 on backends::hash2

nothing more

every target

keccak_256, or a tag on backends::xkcp (Keccak, SHA-3, SHAKE, SP 800-185, KMAC, KangarooTwelve, TurboSHAKE)

/third_party//xkcp

every target

blake3

/third_party//blake3

every target

argon2id, scrypt, blake2b_subkey, or HKDF, BLAKE2b, SipHash, SHA-2, SHA-3, SHAKE, TurboSHAKE, HMAC and argon2 on backends::sodium

/third_party//sodium

every target

HKDF, a digest or HMAC on backends::bearssl

/third_party//bearssl

every target

HKDF, PBKDF2, scrypt, Argon2, KBKDF, the one-step KDF, the X9.63 KDF, a digest or a MAC on backends::openssl

/webcpp/hash//openssl

native, wasip2, wasip3

bcrypt, bcrypt_verify, bcrypt_pbkdf, or HKDF, PBKDF2, scrypt, Argon2, KBKDF, the one-step KDF, the X9.63 KDF, a digest (Streebog, Whirlpool and Skein-512 among them) or a MAC on backends::botan

/third_party//botan, in a program built with exceptions

native, emscripten

hash::formats::base58_with_checksum (Base58Check), which includes webcpp::codecs

/webcpp/hash//base58_with_checksum in place of /webcpp/hash//hash

every target

A program that hashes passwords with Argon2id and derives keys with HKDF on the default backend, backends::hash2, names, for example:

exe app : app.cpp /webcpp/hash//hash /third_party//sodium ;

Each library’s target defines the macro WEBCPP_HASH_HAS_<NAME> that hash’s headers read, so linking a library is what makes its backend available; a program built without b2 defines the macro itself. libsodium and BearSSL are the same copies webcpp::crypto links, so a program of both libraries links each once. On Emscripten /third_party//sodium also links the program with -sALLOW_MEMORY_GROWTH=1, since Argon2id and scrypt allocate more than Emscripten’s fixed 16 MiB.

Botan is the one library that needs exceptions: it reports its failures by throwing, so /third_party//botan stops the build of a program with exception-handling=off, and <webcpp/hash/backends/botan.hpp> declares nothing under WEBCPP_HASH_NO_EXCEPTIONS. It is built natively and for Emscripten, and stops the build on wasip2 and wasip3, which webcpp::crypto’s Botan increment decides. webcpp builds it from its pinned sources, configured for each target by Botan’s own configure.py with the modules tools/botan/modules.txt lists, hash’s and webcpp::crypto’s, one copy per program however many libraries use it; on Emscripten it links with -sALLOW_MEMORY_GROWTH=1 too. A program that hashes with Botan’s Streebog, for example, names:

exe app : app.cpp /webcpp/hash//hash /third_party//botan : <exception-handling>on ;

The library’s own target, as build.jam declares it:

alias hash : : : : <include>include <library>/boost//headers <library>/webcpp/config//config
    <library>/webcpp/secure//secure ;

and the one of Base58Check, which brings codecs with it:

# Base58Check, hash::formats::base58_with_checksum: hash, and codecs, whose
# header it includes.
alias base58_with_checksum : : : : <library>hash <library>/webcpp/codecs//codecs ;

When the build stops

A call that needs a library the program does not link, a backend that lacks the function, or two settings that contradict each other stops the build with a message that starts webcpp::hash: and says what to change. The messages, by what causes them:

Cause What to change

keccak_256, blake3, argon2id, scrypt, a backend, or a tag whose default is a backend, used without its library

The message is "…​ needs XKCP" (or BLAKE3’s C implementation, libsodium, BearSSL, OpenSSL) and gives the whole Jamfile line, as exe app : app.cpp /webcpp/hash//hash /third_party//xkcp ;: add that library.

/webcpp/hash//openssl on Emscripten

OpenSSL is not built for Emscripten: remove it; HKDF and PBKDF2 then run on backends::hash2.

backends::botan named in a program that does not link Botan

The message is "webcpp::hash: backends::botan needs Botan. Add /third_party//botan to the program’s Jamfile (native and Emscripten, with exceptions): exe app : app.cpp /webcpp/hash//hash /third_party//botan ;": add that library.

backends::botan named in a program without exceptions

The message is "webcpp::hash: backends::botan needs exceptions: Botan reports its errors by throwing, and its header declares nothing without them. Build with exception-handling=on, or name another backend.": build with exceptions, or name another backend.

/third_party//botan with exception-handling=off, or on wasip2 or wasip3

b2 stops before building: Botan needs exceptions, and is built natively and for Emscripten alone. Build the program with exception-handling=on, or remove the library.

pbkdf2 on backends::sodium or backends::bearssl

Neither library has PBKDF2: name backends::hash2 (every hmac), backends::openssl (every hmac but hmac_ripemd_128) or backends::botan (every hmac but hmac_ripemd_128 and hmac_sha2_512_224).

HKDF, PBKDF2 or kbkdf over hmac_ripemd_128 or hmac_sha2_512_224 on backends::botan, or sskdf over SHA-512/224 there

Botan 3.14.1 has neither RIPEMD-128 nor SHA-512/224: the message names the backends that have the hmac or the digest.

hkdf_extract or hkdf_expand on backends::bearssl

BearSSL’s HKDF does both steps together: call hkdf, or name another backend.

HKDF over an hmac that backends::sodium or backends::bearssl does not have

The message lists the hmacs the backend has and the backends that have the one asked for.

hmac_ripemd_128 on backends::openssl

OpenSSL 3.5 has no RIPEMD-128: name backends::hash2.

kbkdf over an hmac backends::openssl does not have

No backend has it: use an hmac of hmac.hpp but hmac_ripemd_128.

sskdf or x963kdf over a digest its standard does not take

The message lists the digests the standard takes (SP 800-56C: SHA-1, SHA-2, SHA-3; ANSI X9.63: SHA-1, SHA-224 to SHA-512): name one.

argon2id or scrypt on another backend than backends::sodium, backends::openssl or backends::botan

Name one of them and add /third_party//sodium, /webcpp/hash//openssl or /third_party//botan.

bcrypt, bcrypt_verify or bcrypt_pbkdf without a backend, or on another backend than backends::botan

The message is "…​ has no default backend. Name one of: backends::botan." (or "…​ is not in this backend."): name backends::botan and add /third_party//botan.

async_bcrypt, async_bcrypt_pbkdf or async_bcrypt_verify in a build without threads

As the other heavy functions: natively remove WEBCPP_HASH_NO_THREADS; on Emscripten link with -pthread; Botan is not built for WASI.

blake2b_subkey on another backend than backends::sodium

Name backends::sodium and add /third_party//sodium.

A key derivation over a type that is not a Boost.Hash2 hmac of a digest

Pass an hmac, as hmac_sha2_256.

digest_of, hasher, mac or argon2 over a tag a backend does not have

The message names the backends that have it, as "digests::blake3 is not in this backend. Name one of: backends::blake3.": name one of them.

A tag with no default backend, called without a backend

The message is "…​ has no default backend. Name one of: …​": name one of the backends it lists as the second template argument.

digest_of, hasher, mac or argon2 over a type that is not a tag

Pass a tag of digests, macs, or kdfs::argon2id (argon2i, argon2d).

backends::webcrypto named in a synchronous function (hkdf, pbkdf2, digest_of, mac, …​)

WebCrypto is asynchronous: call async_hkdf (or async_pbkdf2, async_digest, async_hmac) with a completion token, or name a synchronous backend (Asynchronous calls).

backends::webcrypto named in an asynchronous function off Emscripten

It exists only on Emscripten: name a synchronous backend, or leave the default.

async_argon2id, async_argon2, async_scrypt or async_pbkdf2 (on a synchronous backend) in a build without threads

They run on another thread: natively remove WEBCPP_HASH_NO_THREADS; on Emscripten link with -pthread (b2’s threading=multi); on WASI call the synchronous function the message names.

async_digest, async_hmac or async_hkdf over an algorithm WebCrypto lacks

They take SHA-1, SHA-256, SHA-384 and SHA-512 (and HMAC and HKDF over them): call the synchronous function the message names.

backends::webcrypto given the executor of a thread_pool (or of another context than an io_context)

WebCrypto’s promise settles in the JavaScript event loop, to which only the run of an io_context returns: pass the executor of the io_context run on the calling thread (WebCrypto in the browser). Behind any_io_executor the same mistake completes with invalid_parameters.

async_pbkdf2 on backends::webcrypto over an hmac WebCrypto lacks

WebCrypto’s PBKDF2 is over SHA-1 and SHA-2 alone: name a synchronous backend for the others.

Every message is tested: each is a test of test/messages/, which compiles a program that makes the mistake and checks the compiler prints the whole text, on every target where the mistake is possible; on Emscripten, where the messages of backends::webcrypto alone arise, the same program is a case of the superproject’s tools/test/hash_jamfiles_test.py.

Exceptions

hash raises no exception of its own: every operation that can fail reports it as a value, a boost::system::result, whether or not the program has exceptions. <webcpp/hash/config.hpp>, which every header of hash includes first, defines WEBCPP_HASH_NO_EXCEPTIONS when webcpp has none (the compiler has none, or the program defined WEBCPP_NO_EXCEPTIONS for every webcpp library), and a program may define it for hash alone. Boost.Hash2’s types, on which every digest is built, do not throw either. One backend needs exceptions: backends::botan, since Botan reports its failures by throwing; hash catches every exception Botan throws at the boundary of the call and returns it as a value, so that none leaves hash, and a program without exceptions has no backends::botan (When the build stops). Every test of hash runs twice, with exceptions and without, but Botan’s, which run with them alone.

Errors

Every operation of hash that can fail reports it with an error of the category webcpp.hash, as a boost::system::error_code. The values are fixed and never reused, so a program may store them. A guard runs before any work: a call it refuses leaves its output untouched; a backend that fails after it started zeroes the output, so that half a key is never used.

Value Name Raised when

1

invalid_output_size

The output is not of a size the function produces: empty, not a fixed-size digest’s size, or past the function’s limits (HKDF: past 255 times the digest; Argon2id: under 16 bytes; HMAC: under 10 bytes).

2

invalid_key_size

A key is not of a size the function takes: the pseudorandom key given to hkdf_expand is not of the hmac’s digest size; a MAC’s key is outside the MAC’s sizes (SipHash: 16 bytes; keyed BLAKE2b: 1 to 64 bytes; keyed BLAKE2s: 1 to 32 bytes; KMAC: at most SIZE_MAX / 8 bytes); the key option of the BLAKE2b digest is longer than 64 bytes; the master key of blake2b_subkey is not of 32 bytes; the secret or key of kbkdf, sskdf or x963kdf is empty.

3

invalid_salt_size

The salt is not of a size the function accepts (Argon2id: 16 bytes).

4

invalid_iterations

PBKDF2’s iteration count is zero, or more than the backend takes (backend_limits<Backend>::pbkdf2_iterations: 2^32 - 1 on backends::webcrypto).

5

invalid_parameters

A parameter is outside the function’s limits: a cost (Argon2id’s passes or memory, Argon2’s passes, lanes or memory, scrypt’s cost, block_size and parallelism); an option (BLAKE2b’s personalisation not of 16 bytes, TurboSHAKE’s domain byte outside 0x01 to 0x7F, ParallelHash’s block size of zero, the counter width of kbkdf other than 8, 16, 24 or 32 bits); the context of blake2b_subkey not of 8 bytes; an executor that backends::webcrypto cannot complete on.

6

input_too_long

An input is longer than the function or the backend accepts (HKDF: a single buffer’s application info past 32,768 bytes, where the forms over pieces have no cap; OpenSSL’s int lengths).

7

backend_failure

A backend failed where its contract says it does not.

8

unsupported_by_backend

A parameter the chosen backend does not take.

9

invalid_state

A hasher is used after its finish, once moved from, or after a backend failure spent it.

argon2id, argon2 and scrypt on every backend, kbkdf, sskdf and x963kdf, and every call on backends::openssl or backends::botan (a digest, a hasher, a MAC, a key derivation, bcrypt) also return errc::not_enough_memory of the generic category when the memory they need cannot be allocated: a program that handles the errors of hash checks that value too. A value that error does not define has the message "unknown webcpp.hash error".

Digests

A cryptographic digest is a fingerprint of data: a few dozen bytes that stand for a file, a message or a block of a chain, such that changing any bit of the data changes the fingerprint beyond recognition. It is what lets a file-sharing app check that the file it received is the one it asked for, a backup tool skip what it already stored, a wallet name a transaction, and a signature sign a short value instead of a whole document. A digest has no key: anybody can compute it, so it protects against accidents and against changes made where the attacker cannot also replace the digest. Where the attacker can, the answer is a MAC (Message authentication) or a signature.

Three properties make a hash cryptographic, each with its strength in bits: collision resistance (nobody finds two inputs with the same digest; at best half the digest’s bits, by the birthday bound), preimage resistance (nobody finds an input for a given digest) and second-preimage resistance (nobody finds another input with the digest of a given one). A digest of 256 bits gives 128-bit collision resistance, which no computer will reach; the "Security" column below gives each function’s.

A digest sets no DIT. hash sets 64-bit ARM’s DIT (data-independent timing) around every call that computes on a key, a password or a key derivation’s secret input (Data-independent timing (DIT)), and a digest’s input is not a secret by its contract: a program that must keep a value secret and derive from it uses a MAC or a key derivation. A digest is also the streaming case, called once per chunk, often per network read, where a guard per call would cost every checksum a real part of a short chunk’s time for no secret (The timing guard’s cost); and the same algorithm is also Boost.Hash2’s own type by alias, which hash cannot guard, so that a guard on one spelling would make the protection depend on the spelling. The keyed modes are MACs and set DIT: digest_of and hasher of digests::blake2b when the options carry a key (BLAKE2b with a key, a salt, a personalisation and a length), and blake3 in its keyed, key-derivation and seeded keyed modes (BLAKE3). Boost.Hash2’s blake2b_512 and blake2s_256 constructed with a key are its own types by alias and set none: for a keyed BLAKE2 with DIT, use mac<macs::blake2b_mac> or digests::blake2b with a key.

Table 1. What each of "Digests" is
Name Output Security Standard Status In the browser (WebCrypto)

md5_128

128 bits

broken: collisions are found in seconds

RFC 1321

broken

no

sha1_160

160 bits

broken: chosen-prefix collisions are practical

RFC 3174, FIPS 180-4

broken

SHA-1

sha2_224

224 bits

112-bit collision resistance

FIPS 180-4

recommended

no

sha2_256

256 bits

128-bit collision resistance

FIPS 180-4

recommended

SHA-256

sha2_384

384 bits

192-bit collision resistance

FIPS 180-4

recommended

SHA-384

sha2_512

512 bits

256-bit collision resistance

FIPS 180-4

recommended

SHA-512

sha2_512_224

224 bits

112-bit collision resistance

FIPS 180-4

recommended

no

sha2_512_256

256 bits

128-bit collision resistance

FIPS 180-4

recommended

no

digests::md5

128 bits

broken: collisions are found in seconds

RFC 1321

broken

no

digests::sha1

160 bits

broken: chosen-prefix collisions are practical

RFC 3174, FIPS 180-4

broken

SHA-1

digests::sha2_224

224 bits

112-bit collision resistance

FIPS 180-4

recommended

no

digests::sha2_256

256 bits

128-bit collision resistance

FIPS 180-4

recommended

SHA-256

digests::sha2_384

384 bits

192-bit collision resistance

FIPS 180-4

recommended

SHA-384

digests::sha2_512

512 bits

256-bit collision resistance

FIPS 180-4

recommended

SHA-512

digests::sha2_512_224

224 bits

112-bit collision resistance

FIPS 180-4

recommended

no

digests::sha2_512_256

256 bits

128-bit collision resistance

FIPS 180-4

recommended

no

digests::md5_sha1

288 bits

legacy: a collision of the pair costs little more than one of SHA-1 (Joux’s multicollisions), far below its 288 bits; SLOTH (2016) turned it into attacks on TLS

RFC 2246

legacy

no

sha3_224

224 bits

112-bit collision resistance

FIPS 202

recommended

no

sha3_256

256 bits

128-bit collision resistance

FIPS 202

recommended

no

sha3_384

384 bits

192-bit collision resistance

FIPS 202

recommended

no

sha3_512

512 bits

256-bit collision resistance

FIPS 202

recommended

no

shake_128

any length

up to 128 bits, and half the output length for collisions

FIPS 202

recommended

no

shake_256

any length

up to 256 bits, and half the output length for collisions

FIPS 202

recommended

no

digests::sha3_224

224 bits

112-bit collision resistance

FIPS 202

recommended

no

digests::sha3_256

256 bits

128-bit collision resistance

FIPS 202

recommended

no

digests::sha3_384

384 bits

192-bit collision resistance

FIPS 202

recommended

no

digests::sha3_512

512 bits

256-bit collision resistance

FIPS 202

recommended

no

digests::shake_128

any length

up to 128 bits, and half the output length for collisions

FIPS 202

recommended

no

digests::shake_256

any length

up to 256 bits, and half the output length for collisions

FIPS 202

recommended

no

digests::turboshake_128

any length

up to 128 bits, and half the output length for collisions

RFC 9861

recommended

no

digests::turboshake_256

any length

up to 256 bits, and half the output length for collisions

RFC 9861

recommended

no

keccak_256

256 bits

128-bit collision resistance

Keccak (the SHA-3 submission’s padding), as Ethereum uses it

recommended

no

digests::keccak_224

224 bits

112-bit collision resistance

Keccak (the SHA-3 submission’s padding)

legacy

no

digests::keccak_256

256 bits

128-bit collision resistance

Keccak (the SHA-3 submission’s padding), as Ethereum uses it

recommended

no

digests::keccak_384

384 bits

192-bit collision resistance

Keccak (the SHA-3 submission’s padding)

legacy

no

digests::keccak_512

512 bits

256-bit collision resistance

Keccak (the SHA-3 submission’s padding)

legacy

no

digests::cshake_128

any length from 1 byte

128-bit security (SP 800-185, section 8.1)

NIST SP 800-185, section 3

recommended

no

digests::cshake_256

any length from 1 byte

256-bit security (SP 800-185, section 8.1)

NIST SP 800-185, section 3

recommended

no

digests::tuplehash_128

any length from 1 byte; fixed-length or XOF form

128-bit security (SP 800-185, section 8.1)

NIST SP 800-185, section 5

recommended

no

digests::tuplehash_256

any length from 1 byte; fixed-length or XOF form

256-bit security (SP 800-185, section 8.1)

NIST SP 800-185, section 5

recommended

no

digests::parallelhash_128

any length from 1 byte; fixed-length or XOF form

128-bit security (SP 800-185, section 8.1)

NIST SP 800-185, section 6

recommended

no

digests::parallelhash_256

any length from 1 byte; fixed-length or XOF form

256-bit security (SP 800-185, section 8.1)

NIST SP 800-185, section 6

recommended

no

digests::kt128

any length

up to 128 bits, as SHAKE128, and half the output length for collisions (RFC 9861, section 7)

RFC 9861

recommended

no

digests::kt256

any length

up to 256 bits, as SHAKE256, and half the output length for collisions (RFC 9861, section 7)

RFC 9861

recommended

no

blake2b_512

512 bits

256-bit collision resistance

RFC 7693

recommended

no

blake2s_256

256 bits

128-bit collision resistance

RFC 7693

recommended

no

digests::blake2b

1 to 64 bytes, chosen before hashing

256-bit collision resistance at 64 bytes, half the output length in general; with a secret key of 16 bytes or more, a MAC

RFC 7693

recommended

no

digests::blake2s_256

256 bits

128-bit collision resistance

RFC 7693

recommended

no

blake3

256 bits, or any length

128-bit security in every mode

the BLAKE3 specification (hash, keyed hash, derive_key, extendable output)

recommended

no

digests::blake3

256 bits, or any length

128-bit security in every mode

the BLAKE3 specification (hash, keyed hash, derive_key, extendable output)

recommended

no

ripemd_128

128 bits

64-bit collision resistance: too short today

RIPEMD-128 (Dobbertin, Bosselaers, Preneel)

legacy

no

ripemd_160

160 bits

80-bit collision resistance

RIPEMD-160 (Dobbertin, Bosselaers, Preneel)

legacy

no

digests::ripemd_160

160 bits

80-bit collision resistance

RIPEMD-160 (Dobbertin, Bosselaers, Preneel)

legacy

no

digests::sm3

256 bits

128-bit collision resistance

GB/T 32905-2016 (ISO/IEC 10118-3:2018)

recommended

no

digests::streebog_256

256 bits

128-bit collision resistance; Botan warns that its S-box has a hidden structure

GOST R 34.11-2012 (RFC 6986)

legacy

no

digests::streebog_512

512 bits

256-bit collision resistance; Botan warns that its S-box has a hidden structure

GOST R 34.11-2012 (RFC 6986)

legacy

no

digests::whirlpool

512 bits

256-bit collision resistance

ISO/IEC 10118-3 (Whirlpool, Barreto and Rijmen)

legacy

no

digests::skein_512

512 bits

256-bit collision resistance

The Skein Hash Function Family, version 1.3

legacy

no

Table 2. How to choose among "Digests"
Name Fastest natively Smallest on Emscripten Where it is used Choose it when

md5_128

933 MiB/s (hash2)

8,039 bytes (hash2)

legacy checksums and old protocols; RFC 6151 retires it for signatures

Only to read or check data that already uses it.

sha1_160

1,190 MiB/s (hash2)

10,285 bytes (hash2)

Git’s original object ids, with collision detection; the first public collision, SHAttered (2017); the first public chosen-prefix collision, SHA-1 is a Shambles (2020)

Only to read or check data that already uses it.

sha2_224

606 MiB/s (hash2)

14,116 bytes (hash2)

FIPS 180-4’s shorter SHA-2

When a standard asks for it; otherwise SHA-256.

sha2_256

593 MiB/s (hash2)

14,108 bytes (hash2)

Bitcoin’s block and transaction ids (twice); Nostr’s event ids (NIP-01); Git’s SHA-256 object format; TLS 1.3’s cipher suites

The default digest: interoperable everywhere, in every browser, fast with hardware support.

sha2_384

913 MiB/s (hash2)

17,579 bytes (hash2)

TLS 1.3’s AES-256 cipher suite

When a standard asks for 192-bit strength, or a digest that resists length extension within SHA-2.

sha2_512

940 MiB/s (hash2)

17,582 bytes (hash2)

Ed25519’s signatures; BIP39’s seeds, through PBKDF2-HMAC-SHA-512

When a standard asks for it, or for a 512-bit digest.

sha2_512_224

941 MiB/s (hash2)

17,645 bytes (hash2)

FIPS 180-4’s truncated SHA-512

When a standard asks for it.

sha2_512_256

911 MiB/s (hash2)

17,597 bytes (hash2)

FIPS 180-4’s truncated SHA-512

A 256-bit SHA-2 digest that resists length extension, fast on 64-bit machines.

digests::md5

-

-

legacy checksums and old protocols; RFC 6151 retires it for signatures

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; md5_128 itself for hash_append and Boost.Hash2’s other functions.

digests::sha1

-

-

Git’s original object ids, with collision detection; the first public collision, SHAttered (2017); the first public chosen-prefix collision, SHA-1 is a Shambles (2020)

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha1_160 itself for hash_append and Boost.Hash2’s other functions.

digests::sha2_224

-

-

FIPS 180-4’s shorter SHA-2

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha2_224 itself for hash_append and Boost.Hash2’s other functions.

digests::sha2_256

-

-

Bitcoin’s block and transaction ids (twice); Nostr’s event ids (NIP-01); Git’s SHA-256 object format; TLS 1.3’s cipher suites

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha2_256 itself for hash_append and Boost.Hash2’s other functions.

digests::sha2_384

-

-

TLS 1.3’s AES-256 cipher suite

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha2_384 itself for hash_append and Boost.Hash2’s other functions.

digests::sha2_512

-

-

Ed25519’s signatures; BIP39’s seeds, through PBKDF2-HMAC-SHA-512

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha2_512 itself for hash_append and Boost.Hash2’s other functions.

digests::sha2_512_224

-

-

FIPS 180-4’s truncated SHA-512

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha2_512_224 itself for hash_append and Boost.Hash2’s other functions.

digests::sha2_512_256

-

-

FIPS 180-4’s truncated SHA-512

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha2_512_256 itself for hash_append and Boost.Hash2’s other functions.

digests::md5_sha1

-

-

TLS 1.0 and 1.1’s RSA signatures and Finished messages; SLOTH’s collision attacks on it (2016); TLS 1.0 and 1.1 deprecated by RFC 8996 (2021)

Only to read or check TLS 1.0 and 1.1 data, naming backends::bearssl or backends::openssl; never for anything new: SHA-256 instead.

sha3_224

733 MiB/s (hash2)

7,175 bytes (hash2)

FIPS 202

When a standard asks for it.

sha3_256

692 MiB/s (hash2)

7,172 bytes (hash2)

ML-KEM, NIST’s post-quantum key encapsulation

A standard 256-bit digest that is not SHA-2, immune to length extension.

sha3_384

529 MiB/s (hash2)

7,140 bytes (hash2)

FIPS 202

When a standard asks for it.

sha3_512

369 MiB/s (hash2)

7,142 bytes (hash2)

ML-KEM, NIST’s post-quantum key encapsulation

When a standard asks for it.

shake_128

848 MiB/s (hash2)

7,151 bytes (hash2)

ML-KEM’s and ML-DSA’s matrix expansion

To draw a long stream of bytes from one input, at 128-bit security.

shake_256

688 MiB/s (hash2)

7,151 bytes (hash2)

Ed448’s signatures

To draw a long stream of bytes from one input, at 256-bit security.

digests::sha3_224

-

-

FIPS 202

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha3_224 itself for hash_append and Boost.Hash2’s other functions.

digests::sha3_256

-

-

ML-KEM, NIST’s post-quantum key encapsulation

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha3_256 itself for hash_append and Boost.Hash2’s other functions.

digests::sha3_384

-

-

FIPS 202

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha3_384 itself for hash_append and Boost.Hash2’s other functions.

digests::sha3_512

-

-

ML-KEM, NIST’s post-quantum key encapsulation

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; sha3_512 itself for hash_append and Boost.Hash2’s other functions.

digests::shake_128

-

-

ML-KEM’s and ML-DSA’s matrix expansion

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; shake_128 itself for hash_append and Boost.Hash2’s other functions.

digests::shake_256

-

-

Ed448’s signatures

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; shake_256 itself for hash_append and Boost.Hash2’s other functions.

digests::turboshake_128

-

-

KT128’s inner function (KangarooTwelve); libsodium’s extendable-output functions, crypto_xof_turboshake128

For an extendable output faster than SHAKE128 with the same security claim, or for several functions from one primitive told apart by the domain byte; shake_128 where a standard names SHAKE.

digests::turboshake_256

-

-

KT256’s inner function (KangarooTwelve); libsodium’s extendable-output functions, crypto_xof_turboshake256

For an extendable output faster than SHAKE256 with the same security claim, or for several functions from one primitive told apart by the domain byte; shake_256 where a standard names SHAKE.

keccak_256

998 MiB/s (xkcp)

24,057 bytes (xkcp)

Ethereum’s addresses, transaction ids and state; EIP-55’s checksummed addresses

For Ethereum and every format that names Keccak-256; never in place of SHA3-256.

digests::keccak_224

-

-

The Keccak team’s final SHA-3 submission, before FIPS 202 changed the padding

Only where a format names Keccak-224, the padding before FIPS 202; SHA3-224 for anything new.

digests::keccak_256

-

-

Ethereum’s addresses, transaction ids and state; EIP-55’s checksummed addresses

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; keccak_256 itself for hash_append and Boost.Hash2’s other functions.

digests::keccak_384

-

-

The Keccak team’s final SHA-3 submission, before FIPS 202 changed the padding

Only where a format names Keccak-384, the padding before FIPS 202; SHA3-384 for anything new.

digests::keccak_512

-

-

The Keccak team’s final SHA-3 submission, before FIPS 202 changed the padding

Only where a format names Keccak-512, the padding before FIPS 202; SHA3-512 for anything new.

digests::cshake_128

-

-

The building block of KMAC, TupleHash and ParallelHash in NIST SP 800-185

When two uses of one hash must never give the same output for the same input: each takes its own customisation string.

digests::cshake_256

-

-

The building block of KMAC, TupleHash and ParallelHash in NIST SP 800-185

As cSHAKE128, where a format asks for 256-bit security.

digests::tuplehash_128

-

-

NIST SP 800-185, the SHA-3 derived functions

To hash several fields together without an encoding of your own: ("ab", "c") and ("a", "bc") never collide, as a plain concatenation does.

digests::tuplehash_256

-

-

NIST SP 800-185, the SHA-3 derived functions

As TupleHash128, where a format asks for 256-bit security.

digests::parallelhash_128

-

-

NIST SP 800-185, the SHA-3 derived functions

Where a format names ParallelHash and its block size; for a fast hash of large files without such a format, BLAKE3 or KT128.

digests::parallelhash_256

-

-

NIST SP 800-185, the SHA-3 derived functions

As ParallelHash128, where a format asks for 256-bit security.

digests::kt128

-

-

IANA’s COSE algorithms (KT128, -263) and named information hashes (k12-256)

For a fast hash of large files or a hash with an application’s customisation string, where no format names SHA-2 or SHA-3; BLAKE3 is the other fast choice.

digests::kt256

-

-

IANA’s COSE algorithms (KT256, -264) and named information hashes (k12-512)

As KT128, where a format asks for 256-bit security.

blake2b_512

1,617 MiB/s (hash2)

11,982 bytes (hash2)

Argon2’s internal hash; libsodium’s generic hash

A fast software digest or keyed hash where SHA-2 has no hardware support.

blake2s_256

921 MiB/s (hash2)

10,974 bytes (hash2)

WireGuard’s hash, MAC and HKDF

For WireGuard-style protocols and 32-bit targets.

digests::blake2b

-

-

Argon2’s internal hash; libsodium’s generic hash, crypto_generichash; Zcash’s transaction hashes, each personalised

For BLAKE2b of a length other than 64 bytes, keyed, salted or personalised (a format that names BLAKE2b-256 or a personalisation string), or to hash in pieces with one result; blake2b_512 itself for hash_append.

digests::blake2s_256

-

-

WireGuard’s hash, MAC and HKDF

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; blake2s_256 itself for hash_append and Boost.Hash2’s other functions.

blake3

2,414 MiB/s (blake3)

21,252 bytes (blake3)

the BLAKE3 specification: a Merkle tree, for verified streaming and content addressing

Large data verified in parts, content addressing, and key derivation from a context string.

digests::blake3

-

-

the BLAKE3 specification: a Merkle tree, for verified streaming and content addressing

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; blake3 itself for hash_append and Boost.Hash2’s other functions.

ripemd_128

989 MiB/s (hash2)

9,421 bytes (hash2)

the RIPEMD family’s page

Only to read existing data.

ripemd_160

610 MiB/s (hash2)

11,607 bytes (hash2)

Bitcoin’s hash160 (P2PKH, P2WPKH)

For Bitcoin’s hash160; never in a new design.

digests::ripemd_160

-

-

Bitcoin’s hash160 (P2PKH, P2WPKH)

To name the backend in the call, or to hash in pieces with a result that cannot be taken twice; ripemd_160 itself for hash_append and Boost.Hash2’s other functions.

digests::sm3

-

-

RFC 8998, ShangMi cipher suites for TLS 1.3; ISO/IEC 10118-3:2018, dedicated hash functions

Where a Chinese standard or a regulator requires it (SM2 signatures, the ShangMi suites of TLS 1.3), naming backends::openssl or backends::botan; SHA-256 everywhere else.

digests::streebog_256

-

-

RFC 6986, GOST R 34.11-2012: Hash Function; RFC 7836, the guidelines of the GOST algorithms, which build HMAC and KDFs over it

Only where a Russian standard requires GOST R 34.11-2012, naming backends::botan; SHA-256 everywhere else.

digests::streebog_512

-

-

RFC 6986, GOST R 34.11-2012: Hash Function; RFC 7836, the guidelines of the GOST algorithms

Only where a Russian standard requires GOST R 34.11-2012, naming backends::botan; SHA-512 everywhere else.

digests::whirlpool

-

-

ISO/IEC 10118-3:2018, dedicated hash functions; VeraCrypt’s header key derivation, PBKDF2 over HMAC-Whirlpool

Only to read what a format hashed with it, naming backends::botan; SHA-512 or SHA3-512 everywhere else.

digests::skein_512

-

-

The Skein Hash Function Family, version 1.3

Only to read what a format hashed with it, naming backends::botan; SHA3-512 or BLAKE2b everywhere else.

The measured columns are doc/measurements.json’s, a reference measured on 2026-11-16 on Apple M5 Max that decides nothing: the native throughput over 1 MiB, or the time of one derivation over hmac_sha2_256, of the fastest backend, and the smallest Emscripten program that calls the function; Measured size and throughput has every backend on every target.

SHA-2

SHA-2 is the family of digests NIST published in 2001 (FIPS 180-4 is its current text): SHA-224 and SHA-256 over 32-bit words, SHA-384, SHA-512, SHA-512/224 and SHA-512/256 over 64-bit words. SHA-256 is the most widely deployed digest: TLS, Bitcoin, Git’s new object format, Nostr and every browser’s WebCrypto have it, and recent x86 and Arm processors compute it in hardware. Each is a Merkle-DamgÃ¥rd construction: the message, padded with its length, is cut into blocks, and a compression function folds each block into a state whose last value is the digest.

#include "hex.hpp"

#include <webcpp/hash/algorithms.hpp>

#include <iostream>
#include <string_view>

int main() {
    std::string_view const message = "abc";

    webcpp::hash::sha2_256 whole;
    whole.update(message.data(), message.size());
    auto const digest = whole.result();
    std::cout << "sha2_256(abc) " << example::hex(digest) << '\n';

    // The standard's own value: a program that prints something else has a bug, not a new hash.
    if (example::hex(digest) !=
        "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") {
        return 1;
    }

    // Data that arrives in chunks (a socket, a file read in blocks) is hashed as it comes, without
    // collecting it first.
    webcpp::hash::sha2_256 pieces;
    pieces.update("a", 1);
    pieces.update("bc", 2);
    std::cout << "in two pieces " << (pieces.result() == digest ? "same" : "different") << '\n';
}
sha2_256(abc) ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
in two pieces same

Pitfalls.

  • Length extension. Whoever knows SHA-256(m) and the length of m can compute SHA-256(m || padding || x) for any x without knowing m. So the digest of a key followed by a message is not a MAC: an attacker appends to a signed request and computes its valid "tag". Use HMAC (HMAC), or a digest that resists it: SHA-384, SHA-512/256, SHA-3, BLAKE2 and BLAKE3.

  • A digest is not a password hash. SHA-256 runs at hundreds of megabytes per second; a stolen table of SHA-256 password digests is tested at billions of guesses per second on a graphics card. Passwords go through Argon2id (Argon2id).

  • A digest is compared as a public value. Comparing two digests with == is fine when both are public, a file’s expected digest for example; a tag that depends on a secret is compared with webcpp::secure::constant_time_equal (HMAC).

  • Other backends, by name. backends::bearssl, backends::openssl and backends::botan compute SHA-2 too, never as a default: a call names one (One call, or pieces with one result: digest_of and hasher). Botan has SHA-224, SHA-256, SHA-384, SHA-512 and SHA-512/256, not SHA-512/224, natively and on Emscripten, with exceptions; the bytes are the same on every backend.

Table 3. Who implements md5_128 to digests::md5_sha1, 17 names (RFC 1321, RFC 3174, FIPS 180-4)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

md5_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha1_160

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha2_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha2_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha2_384

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha2_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha2_512_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha2_512_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::md5

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::md5

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::md5

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::md5

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha1

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha1

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::sha1

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha1

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha1

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

digests::sha2_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_224

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_224

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha2_224

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha2_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_256

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_256

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_256

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha2_256

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha2_256

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

digests::sha2_384

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_384

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_384

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha2_384

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha2_384

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

digests::sha2_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_512

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_512

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_512

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha2_512

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha2_512

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

digests::sha2_512_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_512_224

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha2_512_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha2_512_256

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha2_512_256

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::md5_sha1

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::md5_sha1

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

What each backend states on constant time, as the capability table read it:

  • bearssl: BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_hash.h states constant time for its GHASH implementations alone, not for br_md5_*, br_sha1_*, br_sha224_* to br_sha512_* or br_md5sha1_*.

  • botan: Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_MD-*.pod, doc/man3/EVP_DigestInit.pod and providers/implementations/digests/ state no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

  • webcrypto: The Web Cryptography API (W3C Recommendation, 2017) states no constant-time property of digest, sign or deriveBits; each JavaScript runtime’s implementation decides, and webcpp reads none.

digests::md5_sha1 has no default backend: the call names one of its backends, as its second template argument (The default backend).

The default of digests::md5, digests::sha1, digests::sha2_224 and digests::sha2_384: hash2 on every target, whatever the program links; bearssl, botan, openssl only where the call names it, as its second template argument (The default backend).

The default of digests::sha2_256 and digests::sha2_512: hash2 on every target, whatever the program links; bearssl, botan, openssl, sodium only where the call names it, as its second template argument (The default backend).

The default of digests::sha2_512_224: hash2 on every target, whatever the program links; openssl only where the call names it, as its second template argument (The default backend).

The default of digests::sha2_512_256: hash2 on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

webcrypto serves the asynchronous family alone, on Emscripten, where the type of its asynchronous call names it (WebCrypto in the browser).

SHA-256 twice, as Bitcoin’s checksum. Bitcoin writes addresses and keys in Base58Check: the payload followed by the first 4 bytes of SHA-256 of the SHA-256 of the payload. webcpp::hash::checksums::double_sha256 (<webcpp/hash/checksums.hpp>, which <webcpp/hash.hpp> includes) is that checksum in the shape of webcpp::codecs’ formats::base58_checksum, and hash::formats::base58_with_checksum is the format built on it (An address and a key as text: Base58Check). It runs on a WIF key’s bytes, so it holds secure::timing_guard and wipes both digests and both hashers’ states.

SHA-3 and SHAKE

SHA-3 is the standard NIST chose by an open competition and published in 2015 as FIPS 202: the Keccak team’s sponge. A sponge absorbs the message into a large state of 1,600 bits, a block at a time, mixing it with the Keccak-p permutation, then squeezes output from it. Its design shares nothing with SHA-2, which is why it exists: if a weakness were found in SHA-2, SHA-3 would not share it. It resists length extension by construction. SHA3-224 to SHA3-512 have fixed digest sizes; SHAKE128 and SHAKE256 are extendable-output functions (XOFs), which give as many bytes as the caller takes, and are what NIST’s post-quantum standards (ML-KEM, ML-DSA) use to expand seeds into matrices.

#include "hex.hpp"

#include <webcpp/hash/algorithms.hpp>

#include <cstddef>
#include <iostream>
#include <string_view>

int main() {
    std::string_view const message = "abc";

    webcpp::hash::sha3_256 fixed;
    fixed.update(message.data(), message.size());
    std::cout << "sha3_256 " << example::hex(fixed.result()) << '\n';

    // SHAKE128 has no digest size: its output goes on as long as the caller asks. Hash2's
    // result() returns one whole block of 168 bytes, and each further call continues the stream.
    webcpp::hash::shake_128 xof;
    xof.update(message.data(), message.size());
    auto const first = xof.result();
    auto const second = xof.result();

    // The length is the caller's security choice. SHAKE128 has a 128-bit security strength, so
    // 32 bytes are as strong as it gets; keeping 16 bytes would give only 64 bits against
    // collisions. Take what the protocol needs and no less.
    constexpr std::size_t taken = 32;
    std::cout << "shake_128 first block " << example::hex({first.data(), taken}) << '\n';
    std::cout << "shake_128 second block " << example::hex({second.data(), taken}) << '\n';
}
sha3_256 3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532
shake_128 first block 5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8
shake_128 second block 6aa01b3f5af057805f973ff8ecb8b226ac32ada6f01c1fcd4818cb006aa5b4cd

Pitfalls.

  • An XOF’s output length is the caller’s security choice. SHAKE128 gives at most 128-bit security however much is taken, and a short output gives less: 16 bytes give only 64-bit collision resistance. Take what the protocol names.

  • Hash2’s result() returns a whole block. Each call of result() on shake_128 returns the next 168 bytes of the stream (136 for shake_256), as Boost.Hash2 defines it; a program that wants bytes 32 to 63 takes them from the first block, not from a second call.

  • SHA3-256 is not Keccak-256. The padding differs (Keccak).

  • libsodium has SHA3-256, SHA3-512 and both SHAKEs too. digest_of and hasher reach them with backends::sodium named in the call (libsodium’s crypto_hash_sha3256, crypto_hash_sha3512 and crypto_xof_shake*, every output size), as they reach its SHA-256 and SHA-512 (One call, or pieces with one result: digest_of and hasher); the bytes are the same on every backend. backends::openssl and backends::botan have SHA3-224 to SHA3-512 and both SHAKEs, at every output size, named in the call likewise.

Table 4. Who implements sha3_224 to digests::shake_256, 12 names (FIPS 202)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

sha3_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha3_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha3_384

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

sha3_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

shake_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

shake_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_224

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_224

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha3_224

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha3_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_256

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_256

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha3_256

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha3_384

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_384

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_384

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha3_384

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::sha3_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_512

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_512

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::sha3_512

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sha3_512

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::shake_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_128

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_128

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_128

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_128

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::shake_128

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::shake_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_256

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_256

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

digests::shake_256

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::shake_256

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • bearssl: BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_kdf.h states no constant-time property for br_shake_*.

  • botan:

    • Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of SHAKE or of its XOF interface, and its source (src/lib/xof/shake_xof/) none.

    • Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_MD-*.pod, doc/man3/EVP_DigestInit.pod and providers/implementations/digests/ state no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

  • xkcp: XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high/Keccak (KeccakSponge, FIPS202/KeccakHash) state no constant-time property.

The default of digests::sha3_224 and digests::sha3_384: hash2 on every target, whatever the program links; botan, openssl, xkcp only where the call names it, as its second template argument (The default backend).

The default of digests::sha3_256 and digests::sha3_512: hash2 on every target, whatever the program links; botan, openssl, sodium, xkcp only where the call names it, as its second template argument (The default backend).

The default of digests::shake_128 and digests::shake_256: hash2 on every target, whatever the program links; bearssl, botan, openssl, sodium, xkcp only where the call names it, as its second template argument (The default backend).

TurboSHAKE

TurboSHAKE128 and TurboSHAKE256 (RFC 9861, 2025, from the Keccak team) are SHAKE128 and SHAKE256 with half the rounds: the same sponge over the same 1,600-bit state, its permutation run 12 rounds instead of 24, which makes them roughly twice as fast with the same claimed security (128 and 256 bits; RFC 9861, sections 1 and 7). They are extendable-output functions, as SHAKE is, and take one parameter more: a domain separation byte D, from 0x01 to 0x7F (0x1F by default), absorbed after the message, so that each value is another function. A program that hashes several kinds of things gives each kind its own byte, and a value of one kind never stands for a value of another. TurboSHAKE is also the inner function of KangarooTwelve (KangarooTwelve (KT128 and KT256)). digest_of and hasher take the byte in digest_options<digests::turboshake_128> (or _256), on backends::xkcp, their default, XKCP’s own TurboSHAKE code, for which a program links /third_party//xkcp; or on backends::sodium, libsodium’s crypto_xof_turboshake128 and crypto_xof_turboshake256, named in the call. Both give the same bytes.

// TurboSHAKE128 of FF FF FF under two domain bytes: two unrelated functions.
auto const message = example::from_hex("ffffff");
std::array<std::uint8_t, 32> first{};
std::array<std::uint8_t, 32> second{};
if (!hash::digest_of<hash::digests::turboshake_128>(first, message, {.domain = 0x01}) ||
    !hash::digest_of<hash::digests::turboshake_128>(second, message, {.domain = 0x07})) {
    return 1;
}
std::cout << "turboshake_128 D=01 " << example::hex(first) << '\n';
std::cout << "turboshake_128 D=07 " << example::hex(second) << '\n';
turboshake_128 D=01 bf323f940494e88ee1c540fe660be8a0c93f43d15ec006998462fa994eed5dab
turboshake_128 D=07 b658576001cad9b1e5f399a9f77723bba05458042d68206f7252682dba3663ed

The same function on libsodium, named in the call:

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <span>

int main() {
    namespace hash = webcpp::hash;
    using webcpp::hash::backends::sodium;
    using webcpp::hash::digests::turboshake_128;

    // RFC 9861, section 5: TurboSHAKE128 of the empty message, D = 0x1F, 32 bytes.
    std::array<std::uint8_t, 32> empty{};
    if (!hash::digest_of<turboshake_128, sodium>(empty, {})) {
        return 1;
    }
    std::cout << "RFC 9861 " << example::hex(empty) << '\n';
    if (example::hex(empty) != "1e415f1c5983aff2169217277d17bb538cd945a397ddec541f1ce41af2c1b74c") {
        return 1;
    }

    // An extendable output: as many bytes as the caller takes, the shorter a prefix of the longer.
    auto const message = example::bytes("hello, world");
    std::array<std::uint8_t, 32> id{};
    std::array<std::uint8_t, 64> longer{};
    if (!hash::digest_of<turboshake_128, sodium>(id, message) ||
        !hash::digest_of<turboshake_128, sodium>(longer, message)) {
        return 1;
    }
    std::cout << "32 bytes " << example::hex(id) << '\n';
    std::cout << "64 bytes start alike: "
              << (std::ranges::equal(std::span(longer).first(32), id) ? "yes" : "no") << '\n';

    // The domain byte (0x01 to 0x7F; 0x1F by default) makes another function from the same
    // permutation: an application gives each of its uses its own byte.
    std::array<std::uint8_t, 32> other{};
    if (!hash::digest_of<turboshake_128, sodium>(other, message, {.domain = 0x0B})) {
        return 1;
    }
    std::cout << "domain 0x0B " << example::hex(other) << '\n';

    // A hasher takes the domain byte when it starts.
    auto hashing = hash::hasher<turboshake_128, sodium>::make({.domain = 0x1F});
    if (!hashing || !hashing->update(example::bytes("hello, ")) ||
        !hashing->update(example::bytes("world"))) {
        return 1;
    }
    std::array<std::uint8_t, 32> pieces{};
    if (!hashing->finish(pieces)) {
        return 1;
    }
    std::cout << "hasher " << (pieces == id ? "same" : "different") << '\n';

    // A domain byte outside RFC 9861's range is refused before any work.
    auto const refused = hash::digest_of<turboshake_128, sodium>(id, message, {.domain = 0x80});
    std::cout << "domain 0x80: " << refused.error().message() << '\n';
}
RFC 9861 1e415f1c5983aff2169217277d17bb538cd945a397ddec541f1ce41af2c1b74c
32 bytes 48bc83c7a80f5affa18f526c1e41b31bb83480b1c25f277cba6ce7b3f5f6fc34
64 bytes start alike: yes
domain 0x0B d9b578bfc741eca1dfee35ded1e8fa1af2c0aed72340083235e39bc5e288322c
hasher same
domain 0x80: a parameter is outside the function's limits

Pitfalls.

  • TurboSHAKE is not SHAKE. With 12 rounds instead of 24 it gives other bytes for the same message: a format that names SHAKE128 needs SHAKE128 (SHA-3 and SHAKE).

  • The domain byte is part of the function. Both sides of a protocol use the same byte for the same purpose; a byte outside 0x01 to 0x7F is refused (invalid_parameters) before any backend sees it, on every backend, although libsodium would accept it and XKCP would take any byte but 0, since RFC 9861 allows that range alone.

  • The output’s length is the caller’s security choice, as for SHAKE: 32 bytes of TurboSHAKE128 give 128-bit security, 16 bytes give only 64-bit collision resistance.

Table 5. Who implements digests::turboshake_128, digests::turboshake_256 (RFC 9861)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

digests::turboshake_128

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::turboshake_128

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::turboshake_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::turboshake_256

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

  • xkcp: XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high (KangarooTwelve, TurboSHAKE, Keccak/KeccakSponge) state no constant-time property.

The default of digests::turboshake_128 and digests::turboshake_256: xkcp on every target, whatever the program links; sodium only where the call names it, as its second template argument (The default backend).

KangarooTwelve (KT128 and KT256)

KT128 and KT256 (RFC 9861) are KangarooTwelve, the Keccak team’s fast hash of large inputs: a tree over TurboSHAKE (TurboSHAKE) that cuts its input in chunks of 8,192 bytes, hashes each chunk on its own and hashes the results, so that an implementation can hash a large file on several cores or vector units, as ParallelHash does (cSHAKE, TupleHash and ParallelHash (SP 800-185)), but faster and with no block size to choose (RFC 9861, section 1). An input of up to 8,192 bytes is one TurboSHAKE call, so a short message costs little more. Both are extendable-output functions with the security of SHAKE128 and SHAKE256 (RFC 9861, section 7), and take a customisation string C, as cSHAKE does: an application gives each of its uses its own string, and the outputs are unrelated. They are tags of digest_of and hasher (One call, or pieces with one result: digest_of and hasher), on backends::xkcp, their default: XKCP’s own KangarooTwelve code, which computes the chunks one after another. A program links /third_party//xkcp.

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>
#include <vector>

namespace hash = webcpp::hash;

int main() {
    // KT128 of RFC 9861's ptn(17), the bytes 00 to 10, with no customisation.
    std::vector<std::uint8_t> pattern(20000);
    for (std::size_t i = 0; i != pattern.size(); ++i) {
        pattern[i] = static_cast<std::uint8_t>(i % 251);
    }
    std::span<std::uint8_t const> const file(pattern);
    std::array<std::uint8_t, 32> digest{};
    if (!hash::digest_of<hash::digests::kt128>(digest, file.first(17))) {
        return 1;
    }
    std::cout << "kt128 " << example::hex(digest) << '\n';
    if (example::hex(digest) !=
        "6bf75fa2239198db4772e36478f8e19b0f371205f6a9a93a273f51df37122888") {
        return 1;
    }

    // A file read in pieces, with the application's customisation string, which the hasher
    // reads at finish: `label` lives until then.
    auto const label = example::bytes("webcpp example");
    auto hashing = hash::hasher<hash::digests::kt128>::make({.customisation = label});
    if (!hashing) {
        return 1;
    }
    for (std::size_t at = 0; at < file.size(); at += 4096) {
        if (!hashing->update(file.subspan(at, std::min<std::size_t>(4096, file.size() - at)))) {
            return 1;
        }
    }
    std::array<std::uint8_t, 32> pieces{};
    std::array<std::uint8_t, 32> once{};
    if (!hashing->finish(pieces) ||
        !hash::digest_of<hash::digests::kt128>(once, file, {.customisation = label})) {
        return 1;
    }
    std::cout << "kt128 of the file " << example::hex(pieces) << '\n';
    std::cout << "pieces and one call agree: " << (pieces == once ? "yes" : "no") << '\n';
    if (example::hex(pieces) !=
            "485b2905b93dacfa84cc6b94bef012cfd8aa9232aab119a0afae1073bd82c224" ||
        pieces != once) {
        return 1;
    }

    // TurboSHAKE128 of FF FF FF under two domain bytes: two unrelated functions.
    auto const message = example::from_hex("ffffff");
    std::array<std::uint8_t, 32> first{};
    std::array<std::uint8_t, 32> second{};
    if (!hash::digest_of<hash::digests::turboshake_128>(first, message, {.domain = 0x01}) ||
        !hash::digest_of<hash::digests::turboshake_128>(second, message, {.domain = 0x07})) {
        return 1;
    }
    std::cout << "turboshake_128 D=01 " << example::hex(first) << '\n';
    std::cout << "turboshake_128 D=07 " << example::hex(second) << '\n';
    return example::hex(first) ==
                       "bf323f940494e88ee1c540fe660be8a0c93f43d15ec006998462fa994eed5dab" &&
                   example::hex(second) ==
                       "b658576001cad9b1e5f399a9f77723bba05458042d68206f7252682dba3663ed"
               ? 0
               : 1;
}
kt128 6bf75fa2239198db4772e36478f8e19b0f371205f6a9a93a273f51df37122888
kt128 of the file 485b2905b93dacfa84cc6b94bef012cfd8aa9232aab119a0afae1073bd82c224
pieces and one call agree: yes
turboshake_128 D=01 bf323f940494e88ee1c540fe660be8a0c93f43d15ec006998462fa994eed5dab
turboshake_128 D=07 b658576001cad9b1e5f399a9f77723bba05458042d68206f7252682dba3663ed

Pitfalls.

  • A hasher reads C at finish. KangarooTwelve absorbs the customisation string after the message, and hasher keeps the span make took instead of copying it (no allocation): the bytes stay alive and unchanged until finish, or the digest is another one or the read is a dangling one. digest_of reads C during the call.

  • C is part of the function. KT128 with "app/v1" and KT128 with "app/v2" are unrelated; an empty C is the RFC’s default, and the 32-byte KT128 of a message with no C is what IANA’s "k12-256" names.

  • KT128 is not ParallelHash or BLAKE3. Each tree hash gives its own bytes: a format names one, and a file’s KT128 never matches another’s ParallelHash128.

  • The output’s length is the caller’s security choice, as for SHAKE: 32 bytes of KT128 give 128-bit security, 64 bytes of KT256 256-bit.

  • 32-bit XKCP counts chunks in a size_t. On wasm32 a message and C past a little under 32 TiB together would wrap XKCP’s count into a wrong digest; they are refused (input_too_long) before XKCP sees them.

Table 6. Who implements digests::kt128, digests::kt256 (RFC 9861)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

digests::kt128

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::kt256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • xkcp: XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high (KangarooTwelve, TurboSHAKE, Keccak/KeccakSponge) state no constant-time property.

The default of digests::kt128 and digests::kt256: xkcp on every target, whatever the program links (The default backend).

Keccak

Keccak-256 is Keccak as its authors submitted it to the SHA-3 competition, before NIST changed the padding for FIPS 202. Ethereum adopted it before the standard was final and kept it: an Ethereum address, a transaction id, a Solidity function selector and the state trie are all Keccak-256. hash’s keccak_256 runs XKCP’s Keccak-p[1600] permutation (the Keccak team’s own code) under a sponge written line for line as Boost.Hash2’s, so that it gives Hash2’s results for every sequence of calls (The code webcpp writes, and what the C libraries do, Upstream: Keccak in Boost.Hash2). A program links /third_party//xkcp.

#include "hex.hpp"

#include <webcpp/hash/algorithms.hpp>
#include <webcpp/hash/keccak.hpp>

#include <iostream>
#include <string_view>

int main() {
    std::string_view const empty;
    std::string_view const abc = "abc";

    webcpp::hash::keccak_256 keccak_of_empty;
    keccak_of_empty.update(empty.data(), empty.size());
    auto const empty_digest = example::hex(keccak_of_empty.result());
    std::cout << "keccak_256() " << empty_digest << '\n';

    webcpp::hash::keccak_256 keccak_of_abc;
    keccak_of_abc.update(abc.data(), abc.size());
    auto const abc_digest = example::hex(keccak_of_abc.result());
    std::cout << "keccak_256(abc) " << abc_digest << '\n';

    if (empty_digest != "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" ||
        abc_digest != "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45") {
        return 1;
    }

    // Not the same function. Keccak-256 pads with the byte 0x01, SHA3-256 with 0x06, so a
    // program that calls one where a protocol names the other computes a digest nobody else
    // computes, and the error shows only as a signature or an address that does not match.
    webcpp::hash::sha3_256 sha3_of_empty;
    sha3_of_empty.update(empty.data(), empty.size());
    std::cout << "sha3_256() " << example::hex(sha3_of_empty.result()) << '\n';
}
keccak_256() c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
keccak_256(abc) 4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45
sha3_256() a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a

Pitfalls.

  • Keccak-256 is not SHA3-256. The two differ in one padding byte, 0x01 against 0x06, and give unrelated digests. A library that offers "SHA3" for Ethereum, or "Keccak" for a FIPS 202 format, computes a value nobody else computes, and the mistake shows only as an address or a signature that does not match. Use keccak_256 exactly where a format says Keccak-256.

Keccak-224, Keccak-384 and Keccak-512, the submission’s other sizes, are tags of digest_of and hasher (One call, or pieces with one result: digest_of and hasher): digests::keccak_224, digests::keccak_384 and digests::keccak_512, on backends::xkcp, which runs XKCP’s FIPS 202 code (Keccak_Hash) with Keccak’s padding, and on backends::openssl when the call names it. The same XKCP backend, named in the call, computes SHA3-224 to SHA3-512 and SHAKE128 and SHAKE256, any number of bytes of SHAKE’s stream; XKCP’s own test vectors (the ShortMsgKAT files), Boost.Hash2 and OpenSSL give the same values. backends::botan has Keccak-224 to Keccak-512 too, named in the call (Botan’s Keccak-1600, whose module Botan 3.14.1 deprecates and still builds).

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <span>

int main() {
    namespace hash = webcpp::hash;
    auto const message = example::bytes("abc");

    // Keccak-512, the SHA-3 submission's padding: its default backend is XKCP.
    std::array<std::uint8_t, 64> keccak{};
    if (!hash::digest_of<hash::digests::keccak_512>(keccak, message)) {
        return 1;
    }
    std::cout << "keccak_512(abc) " << example::hex(keccak) << '\n';
    if (example::hex(keccak) !=
        "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5"
        "d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96") {
        return 1;
    }

    // SHA3-256 on XKCP, named in the call: the same digest as on backends::hash2.
    std::array<std::uint8_t, 32> sha3{};
    if (!hash::digest_of<hash::digests::sha3_256, hash::backends::xkcp>(sha3, message)) {
        return 1;
    }
    std::cout << "sha3_256(abc) " << example::hex(sha3) << '\n';
    if (example::hex(sha3) != "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532") {
        return 1;
    }

    // SHAKE128 on XKCP: any length, here 200 bytes, past the first block of 168.
    std::array<std::uint8_t, 200> shake{};
    if (!hash::digest_of<hash::digests::shake_128, hash::backends::xkcp>(shake, message)) {
        return 1;
    }
    std::cout << "shake_128(abc), bytes 168 to 199: " << example::hex(std::span(shake).subspan(168))
              << '\n';
}
keccak_512(abc) 18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96
sha3_256(abc) 3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532
shake_128(abc), bytes 168 to 199: 6aa01b3f5af057805f973ff8ecb8b226ac32ada6f01c1fcd4818cb006aa5b4cd

Pitfalls.

  • The tag names the padding. digests::keccak_512 and digests::sha3_512 differ as keccak_256 and sha3_256 do: one byte of padding, unrelated digests. Keccak-224 to Keccak-512 are found in formats written before FIPS 202, rarely since; a new format takes SHA-3.

  • Keccak-224, Keccak-384 and Keccak-512 have no Hash2-form type here: their proposal to Boost.Hash2 is in Upstream: Keccak in Boost.Hash2, and until it lands they are reached through their tags alone.

Table 7. Who implements keccak_256 to digests::keccak_512, 5 names (Keccak (the SHA-3 submission’s padding), as Ethereum uses it)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

keccak_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::keccak_224

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::keccak_224

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::keccak_224

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::keccak_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::keccak_256

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::keccak_256

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::keccak_384

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::keccak_384

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::keccak_384

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

digests::keccak_512

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::keccak_512

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::keccak_512

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_MD-*.pod, doc/man3/EVP_DigestInit.pod and providers/implementations/digests/ state no constant-time property.

  • xkcp: XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high/Keccak (KeccakSponge, FIPS202/KeccakHash) state no constant-time property.

The default of digests::keccak_224, digests::keccak_256, digests::keccak_384 and digests::keccak_512: xkcp on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

cSHAKE, TupleHash and ParallelHash (SP 800-185)

NIST SP 800-185 builds three hashes on SHAKE, each for a job a plain digest does badly. cSHAKE is SHAKE with a customisation string: an application that hashes the same data for two purposes, an identifier and a checksum, gives each purpose its own string, and the two outputs are unrelated, so that a value computed for one can never be passed off as the other. TupleHash hashes a list of byte strings, a record’s fields, so that the bounds between them count: a signing app that hashes name then amount by plain concatenation gives ("ab", "c") and ("a", "bc") the same digest, and an attacker who controls one field can move bytes across the bound; TupleHash encodes each field’s length and cannot be fooled that way. ParallelHash cuts a long input in blocks of B bytes, hashes each block on its own and hashes the results, so that a large file can be hashed on several cores (backends::xkcp computes the blocks one after another); the block size is part of the function. All three come in a 128-bit and a 256-bit strength (SP 800-185, section 8.1) and give any number of bytes; TupleHash and ParallelHash have a fixed-length form, which encodes the output’s length so that their 32-byte and 64-byte digests are unrelated, and an XOF form, which does not. They are tags of digest_of and hasher (One call, or pieces with one result: digest_of and hasher), on backends::xkcp, their default: XKCP’s own SP 800-185 code. A program links /third_party//xkcp.

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <initializer_list>
#include <iostream>
#include <span>

namespace {

namespace hash = webcpp::hash;

// TupleHash128 of a tuple, one hasher update per element, into digest.
bool tuple_hash(std::initializer_list<std::span<std::uint8_t const>> elements,
                std::span<std::uint8_t> digest) {
    auto hashing = hash::hasher<hash::digests::tuplehash_128>::make();
    if (!hashing) {
        return false;
    }
    for (auto const element : elements) {
        if (!hashing->update(element)) {
            return false;
        }
    }
    return hashing->finish(digest).has_value();
}

}  // namespace

int main() {
    // cSHAKE128: SHAKE128 separated from every other use by the customisation string S.
    std::array<std::uint8_t, 32> cshake{};
    if (!hash::digest_of<hash::digests::cshake_128>(
            cshake, example::from_hex("00010203"),
            {.customisation = example::bytes("Email Signature")})) {
        return 1;
    }
    std::cout << "cshake_128 " << example::hex(cshake) << '\n';
    if (example::hex(cshake) !=
        "c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5") {
        return 1;
    }

    // TupleHash128 of (00 01 02, 10 11 12 13 14 15): each update is one element.
    auto const first = example::from_hex("000102");
    auto const second = example::from_hex("101112131415");
    std::array<std::uint8_t, 32> tuple{};
    if (!tuple_hash({first, second}, tuple)) {
        return 1;
    }
    std::cout << "tuplehash_128 " << example::hex(tuple) << '\n';
    if (example::hex(tuple) != "c5d8786c1afb9b82111ab34b65b2c0048fa64e6d48e263264ce1707d3ffc8ed1") {
        return 1;
    }

    // ParallelHash128 in blocks of 8 bytes, a block size the call states.
    std::array<std::uint8_t, 32> parallel{};
    if (!hash::digest_of<hash::digests::parallelhash_128>(
            parallel, example::from_hex("000102030405060710111213141516172021222324252627"),
            {.block_size = 8})) {
        return 1;
    }
    std::cout << "parallelhash_128 " << example::hex(parallel) << '\n';
    if (example::hex(parallel) !=
        "ba8dc1d1d979331d3f813603c67f72609ab5e44b94a0b8f9af46514454a2b4f5") {
        return 1;
    }

    // ("ab", "c") and ("a", "bc") concatenate to the same bytes and hash apart.
    std::array<std::uint8_t, 32> ab_c{};
    std::array<std::uint8_t, 32> a_bc{};
    if (!tuple_hash({example::bytes("ab"), example::bytes("c")}, ab_c) ||
        !tuple_hash({example::bytes("a"), example::bytes("bc")}, a_bc)) {
        return 1;
    }
    std::cout << "(ab, c) and (a, bc) differ: " << (ab_c != a_bc ? "yes" : "no") << '\n';
    return ab_c != a_bc ? 0 : 1;
}
cshake_128 c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5
tuplehash_128 c5d8786c1afb9b82111ab34b65b2c0048fa64e6d48e263264ce1707d3ffc8ed1
parallelhash_128 ba8dc1d1d979331d3f813603c67f72609ab5e44b94a0b8f9af46514454a2b4f5
(ab, c) and (a, bc) differ: yes

Pitfalls.

  • A TupleHash hasher takes one element per update. Feeding a field in two pieces makes two elements and another digest; digest_of hashes the tuple of one element, its input. The empty tuple (no update) and the tuple of one empty element differ.

  • The form is part of the digest. TupleHash128 and TupleHashXOF128 of the same input differ at every length, and so do the two forms of ParallelHash; the fixed-length form’s 32-byte digest is not the start of its 64-byte one. Choose the form the format names, with .xof.

  • ParallelHash’s block size has no default. SP 800-185 leaves B to the application, and a digest under another B is another digest: the call states it (.block_size; 0 is invalid_parameters). XKCP takes a power of two of at least 8 bytes and answers any other with unsupported_by_backend, NIST’s samples with B = 12 included; 8192 is common for large files.

  • The function name is NIST’s. cSHAKE’s function_name is reserved for functions NIST defines on it; an application separates its uses with customisation. With both empty, cSHAKE is SHAKE.

  • Lengths in bits. SP 800-185 counts every string in bits, which XKCP holds in a size_t: on wasm32 a customisation, a TupleHash element, a ParallelHash input (all its pieces together) or a fixed-length output past 512 MiB is refused (input_too_long, invalid_output_size) before XKCP sees it, rather than hashed into a wrong digest.

Table 8. Who implements digests::cshake_128 to digests::parallelhash_256, 6 names (NIST SP 800-185 (cSHAKE, TupleHash, ParallelHash))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

digests::cshake_128

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::cshake_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::tuplehash_128

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::tuplehash_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::parallelhash_128

xkcp (partial: a block size that is not a power of two of at least 8 bytes; SP 800-185 takes any from 1)

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

digests::parallelhash_256

xkcp (partial: a block size that is not a power of two of at least 8 bytes; SP 800-185 takes any from 1)

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • xkcp: XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high/Keccak (KeccakSponge, FIPS202/KeccakHash, SP800-185) state no constant-time property.

The default of digests::cshake_128, digests::cshake_256, digests::tuplehash_128, digests::tuplehash_256, digests::parallelhash_128 and digests::parallelhash_256: xkcp on every target, whatever the program links (The default backend).

BLAKE2

BLAKE2 (RFC 7693) is a digest faster than MD5 in software and as strong as SHA-3, designed from BLAKE, a SHA-3 finalist. BLAKE2b works on 64-bit words and gives up to 64 bytes; BLAKE2s works on 32-bit words, for small machines, and gives up to 32 bytes. Both take a key, so a keyed BLAKE2 is a MAC without HMAC’s double pass (macs::blake2b_mac and macs::blake2s_mac, Keyed BLAKE2b on libsodium: macs::blake2b_mac). Argon2 is built on BLAKE2b, libsodium’s generic hash is BLAKE2b, and WireGuard uses BLAKE2s for its hash, its MAC and its HKDF.

#include "hex.hpp"

#include <webcpp/hash/algorithms.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <string_view>

int main() {
    std::string_view const message = "abc";

    webcpp::hash::blake2b_512 plain;
    plain.update(message.data(), message.size());
    auto const digest = example::hex(plain.result());
    std::cout << "blake2b_512(abc) " << digest << '\n';

    if (digest !=
        "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"
        "7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923") {
        return 1;
    }

    // The key goes to the constructor, which is the RFC's key parameter: BLAKE2b mixes it in as
    // a first block of its own. Never prepend the key to the message yourself; that is a
    // different function, whose output matches no other implementation's keyed BLAKE2b.
    // Hash2's BLAKE2b has no salt or personalisation parameter: libsodium's crypto_generichash
    // has them, and a later increment of webcpp::hash.
    std::array<std::uint8_t, 32> key{};
    for (std::size_t i = 0; i < key.size(); ++i) {
        key[i] = static_cast<std::uint8_t>(i);
    }
    webcpp::hash::blake2b_512 keyed(key.data(), key.size());
    keyed.update(message.data(), message.size());
    std::cout << "keyed " << example::hex(keyed.result()) << '\n';
}
blake2b_512(abc) ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923
keyed 9af0244b7da7fe29d90a89727e06a0c93977ce1ad7edcb76ac0b24142194ea00c77be4a1d3fededd31d5a593625a508e742fc90d708f8b48a5c246e4e8e42d94

Pitfalls.

  • The key goes to the constructor. blake2b_512(key, size) is RFC 7693’s key, up to 64 bytes (32 for BLAKE2s), mixed in as a block of its own; a key written into the message instead gives a different function, and a longer key gives a function no other BLAKE2 implementation computes, so keep keys at most 64 bytes (32 for BLAKE2s).

  • No salt, no personalisation, no variable length here. RFC 7693’s parameter block also carries a salt, a personalisation string (16 bytes for BLAKE2b, 8 for BLAKE2s) and the digest’s length; Boost.Hash2’s types fix them, so a digest cut to 32 bytes is not BLAKE2b-256, which encodes its length in its parameters. For BLAKE2b-256, or a salt or a personalisation, use digests::blake2b (BLAKE2b with a key, a salt, a personalisation and a length).

  • Other backends, by name. digests::blake2s_256 is on backends::hash2, its default, and on backends::openssl and backends::botan, named in the call, the same bytes.

Table 9. Who implements blake2b_512 to digests::blake2s_256, 4 names (RFC 7693)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

blake2b_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

blake2s_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::blake2b

hash2 (partial: an output under 64 bytes, a key, a salt or a personalisation: BLAKE2b’s output size is a parameter of the hash, and Boost.Hash2’s blake2b_512 has 64 bytes and no option alone)

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::blake2b

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

digests::blake2b

openssl (partial: a key, a salt or a personalisation: OpenSSL’s BLAKE2B-512 digest is unkeyed BLAKE2b of 1 to 64 bytes (its parameter size), and its keyed BLAKE2b is the MAC BLAKE2BMAC)

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::blake2b

botan (with exceptions only) (partial: a salt or a personalisation: Botan’s BLAKE2b takes neither (blake2b.h))

/third_party//botan

native, emscripten

-

not stated

digests::blake2s_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::blake2s_256

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::blake2s_256

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_MD-*.pod, doc/man3/EVP_DigestInit.pod and providers/implementations/digests/ state no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

The default of digests::blake2b: sodium on every target, whatever the program links; botan, hash2, openssl only where the call names it, as its second template argument (The default backend).

The default of digests::blake2s_256: hash2 on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

BLAKE2b with a key, a salt, a personalisation and a length

RFC 7693 defines BLAKE2b with four parameters besides the message, each written into the block that starts the hash, so that each choice is a different function: the output’s length (1 to 64 bytes), a key (up to 64 bytes, which makes it a MAC), a salt and a personalisation (16 bytes each). digest_of and hasher over the tag digests::blake2b take all four in digest_options<digests::blake2b>; the default backend, backends::sodium, is libsodium’s generic hash, crypto_generichash. A chat app that hashes message ids, attachment ids and contact keys personalises each kind, so that a value of one kind never stands for a value of another; a format such as Zcash’s transaction ids (ZIP 244) names BLAKE2b-256 with a personalisation of its own.

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using webcpp::hash::digests::blake2b;
    auto const message = example::bytes("hello, world");

    // The personalisation is 16 bytes, one per kind of hash an application makes; the output's
    // size is an option, since BLAKE2b-256 is not BLAKE2b-512 cut short.
    auto const message_ids = example::bytes("chatapp.msg.v001");
    hash::digest_options<blake2b> const id_options{
        .personalisation = message_ids,
        .output_size = 32,
    };
    std::array<std::uint8_t, 32> id{};
    if (!hash::digest_of<blake2b>(id, message, id_options)) {
        return 1;
    }
    std::cout << "message id " << example::hex(id) << '\n';
    if (example::hex(id) != "fa88bb46494debf0d96d9e2d15fb6ecc42d9ab6a1502e5900249db8274767960") {
        return 1;
    }

    // A hasher takes its options, the output's size among them, when it starts.
    auto hashing = hash::hasher<blake2b>::make(id_options);
    if (!hashing || !hashing->update(example::bytes("hello, ")) ||
        !hashing->update(example::bytes("world"))) {
        return 1;
    }
    std::array<std::uint8_t, 32> pieces{};
    if (!hashing->finish(pieces)) {
        return 1;
    }
    std::cout << "hasher " << (pieces == id ? "same" : "different") << '\n';

    // Without the personalisation: another function, another value.
    std::array<std::uint8_t, 32> plain{};
    if (!hash::digest_of<blake2b>(plain, message, {.output_size = 32})) {
        return 1;
    }
    std::cout << "unpersonalised " << example::hex(plain) << '\n';

    // A key makes BLAKE2b a MAC: here a 16-byte tag under a 32-byte key.
    std::array<std::uint8_t, 32> key{};
    for (std::size_t i = 0; i < key.size(); ++i) {
        key[i] = static_cast<std::uint8_t>(i);
    }
    std::array<std::uint8_t, 16> tag{};
    if (!hash::digest_of<blake2b>(tag, message, {.key = key, .output_size = 16})) {
        return 1;
    }
    std::cout << "tag " << example::hex(tag) << '\n';

    // A personalisation is 16 bytes or none: a shorter one is refused before any work.
    auto const refused = hash::digest_of<blake2b>(
        id, message, {.personalisation = example::bytes("chatapp"), .output_size = 32});
    std::cout << "7-byte personalisation: " << refused.error().message() << '\n';
}
message id fa88bb46494debf0d96d9e2d15fb6ecc42d9ab6a1502e5900249db8274767960
hasher same
unpersonalised 62fbf5098db33f5ee72f85b23b3751d39a2d8d8363f1c734bbb04e05ad2b3b58
tag d78577a3107d705547d17551fa69e742
7-byte personalisation: a parameter is outside the function's limits

Pitfalls.

  • The length is a parameter, not a cut. BLAKE2b-256 is not the first 32 bytes of BLAKE2b-512: the length goes in output_size, 64 by default, and the output given to digest_of or finish has exactly that size (invalid_output_size otherwise). A hasher takes it when it starts.

  • 16 bytes or nothing. A salt or a personalisation is 16 bytes or empty (invalid_salt_size, invalid_parameters); pad a shorter name yourself, the same way on every side, since the library does not guess a padding.

  • A key is a secret, the salt and personalisation are not. For a MAC, use a random key of 16 to 64 bytes from webcpp::crypto::random_device, compare tags with webcpp::secure::constant_time_equal, and prefer mac<macs::blake2b_mac> (Keyed BLAKE2b on libsodium: macs::blake2b_mac); a key of 0 bytes is the unkeyed hash. With a key, digest_of and each of make, update and finish of a hasher set DIT around the call (Data-independent timing (DIT)); without one, none does.

  • backends::hash2 has BLAKE2b-512 alone. Named in the call, it answers unsupported_by_backend to a shorter output, a key, a salt or a personalisation, rather than ignore one.

  • backends::botan has no salt or personalisation. Named in the call, it computes BLAKE2b at every length from 1 to 64 bytes, with a key or without (Botan’s BLAKE2b(<bits>)), and answers unsupported_by_backend to a salt or a personalisation, which Botan’s BLAKE2b does not take.

BLAKE3

BLAKE3 (2020) is one function with four uses: a digest, a keyed hash (a MAC), a key derivation from a context string, and an extendable output. It splits the input into chunks of 1 KiB, hashes them independently and joins them in a binary tree, so it uses every SIMD lane of a processor and verifies a large file in parts; its rounds are fewer than BLAKE2’s. hash runs the official C implementation, with its SIMD code natively and the portable code on WebAssembly; a program links /third_party//blake3. In the measured data (Measured size and throughput), BLAKE3 is the fastest cryptographic digest natively on 1 MiB, and BLAKE2b is faster than BLAKE3 on wasip2, wasip3 and Emscripten.

#include "hex.hpp"

#include <webcpp/hash/blake3.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <string_view>

int main() {
    // The test vectors' input: bytes 0, 1, 2 ... 250, 0, 1 ... For one byte, a single zero.
    std::array<std::uint8_t, 1> const input{0};

    // BLAKE3's plain hash. result() gives its 32 bytes.
    webcpp::hash::blake3 plain;
    plain.update(input.data(), input.size());
    auto const digest = example::hex(plain.result());
    std::cout << "hash " << digest << '\n';

    // The keyed hash is a MAC: the key is exactly 32 bytes, and the type says so.
    auto const key = example::bytes("whats the Elvish word for friend").first<32>();
    auto keyed = webcpp::hash::blake3::keyed(key);
    keyed.update(input.data(), input.size());
    auto const tag = example::hex(keyed.result());
    std::cout << "keyed_hash " << tag << '\n';

    // The key derivation takes a context, a string that names the purpose of the derived key:
    // the same secret under two contexts gives two unrelated keys, which is the point.
    auto derive =
        webcpp::hash::blake3::derive_key("BLAKE3 2019-12-27 16:29:52 test vectors context");
    derive.update(input.data(), input.size());
    auto const derived = example::hex(derive.result());
    std::cout << "derive_key " << derived << '\n';

    // Extendable output: any number of bytes from any position, without changing the hash. The
    // first 32 are the digest above.
    std::array<std::uint8_t, 64> extended{};
    plain.squeeze(extended);
    auto const stream = example::hex(extended);
    std::cout << "extended " << stream << '\n';

    if (digest != "2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213" ||
        tag != "6d7878dfff2f485635d39013278ae14f1454b8c0a3a2d34bc1ab38228a80c95b" ||
        derived != "b3e2e340a117a499c6cf2398a19ee0d29cca2bb7404c73063382693bf66cb06c" ||
        stream !=
            "2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213"
            "c3a6cb8bf623e20cdb535f8d1a5ffb86342d9c0b64aca3bce1d31f60adfa137b") {
        return 1;
    }
}
hash 2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213
keyed_hash 6d7878dfff2f485635d39013278ae14f1454b8c0a3a2d34bc1ab38228a80c95b
derive_key b3e2e340a117a499c6cf2398a19ee0d29cca2bb7404c73063382693bf66cb06c
extended 2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213c3a6cb8bf623e20cdb535f8d1a5ffb86342d9c0b64aca3bce1d31f60adfa137b

The example’s inputs are those of BLAKE3’s official test vectors (test_vectors.json of its repository), and its outputs are theirs.

Pitfalls.

  • Three modes, three results. The plain hash, keyed(key_bytes) and derive_key(context_string) of the same input are unrelated; a verifier must use the mode the producer used.

  • A context names one purpose, forever. BLAKE3’s authors ask that a context string be hardcoded, globally unique and specific to one use, such as "example.com 2026-11-15 chat message keys": never a variable, never a secret. The key material goes through update.

  • The seeded constructor is a keyed hash. blake3(seed_value) and blake3(input_data, input_size) exist for Boost.Hash2’s HashAlgorithm form and key the hash with the seed; for a MAC, call keyed with a 32-byte key.

  • A keyed object sets DIT around each call; a plain one does not. keyed, derive_key and the seeded constructors with a seed that keys the hash (a non-empty byte seed, a non-zero integer seed) set DIT (Data-independent timing (DIT)), and so do update, result, squeeze and reset of the object they make; the plain hash sets none. The flag that says which is part of the object: 1,928 bytes on 64-bit targets, BLAKE3’s state of 1,912 bytes, the count of bytes result() returned and the flag.

  • blake3 does not wipe itself. Like Hash2’s types, it holds the key in its state until it is destroyed; a program that needs the key gone writes over the object.

Table 10. Who implements blake3, digests::blake3 (the BLAKE3 specification (hash, keyed hash, derive_key, extendable output))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

blake3

blake3

/third_party//blake3

native, wasip2, wasip3, emscripten

-

not stated

digests::blake3

blake3

/third_party//blake3

native, wasip2, wasip3, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • blake3: BLAKE3 1.8.7: README.md and c/README.md state no constant-time property.

The default of digests::blake3: blake3 on every target, whatever the program links (The default backend).

MD5, SHA-1 and RIPEMD: legacy

MD5 (1992) and SHA-1 (1995) are broken: collisions of MD5 are found in seconds; the first public collision of SHA-1, an identical-prefix one, SHAttered, came in 2017, and the first public chosen-prefix collision, two documents of the attacker’s choosing with one digest, SHA-1 is a Shambles, in 2019 (published 2020). RIPEMD-160 (1996) is not broken, but its 160 bits give 80-bit collision resistance, below what new designs accept, and RIPEMD-128 gives 64. hash keeps them because data and protocols use them: Git’s original object ids, old checksums, and Bitcoin’s hash160, RIPEMD-160 over SHA-256, in every legacy and SegWit v0 address (A Bitcoin address: hash160).

#include "hex.hpp"

#include <webcpp/hash/algorithms.hpp>

#include <iostream>
#include <string_view>

int main() {
    std::string_view const abc = "abc";

    webcpp::hash::ripemd_160 of_abc;
    of_abc.update(abc.data(), abc.size());
    auto const abc_digest = example::hex(of_abc.result());
    std::cout << "ripemd_160(abc) " << abc_digest << '\n';

    // Nothing to update: the digest of the empty message.
    webcpp::hash::ripemd_160 of_nothing;
    auto const empty_digest = example::hex(of_nothing.result());
    std::cout << "ripemd_160() " << empty_digest << '\n';

    if (abc_digest != "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc" ||
        empty_digest != "9c1185a5c5e9fc54612808977ee8f548b2258d31") {
        return 1;
    }
}
ripemd_160(abc) 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
ripemd_160() 9c1185a5c5e9fc54612808977ee8f548b2258d31

Pitfalls. Never choose one of them for a new design: a signature over an MD5 or SHA-1 digest can be moved to a forged document. Read and check what already exists; write SHA-256, SHA-3 or BLAKE3. HMAC over MD5 or SHA-1 is not broken as a MAC, but it carries a broken name into audits; prefer hmac_sha2_256. MD5-SHA1, the 36 bytes TLS 1.0 and 1.1 sign (MD5 of the data, then SHA-1 of it; RFC 2246, section 4.7), is no stronger than SHA-1: digests::md5_sha1 has no default backend, and a program that must read old TLS data names backends::bearssl or backends::openssl (MD5-SHA1: TLS 1.0’s digest, on BearSSL or OpenSSL by name). MD5, SHA-1 and RIPEMD-160 are on backends::openssl and backends::botan too, named in the call (Botan 3.14.1 deprecates its MD5 module and still builds it).

Table 11. Who implements ripemd_128, ripemd_160, digests::ripemd_160 (RIPEMD-128 and RIPEMD-160 (Dobbertin, Bosselaers, Preneel))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

ripemd_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

ripemd_160

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::ripemd_160

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

digests::ripemd_160

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::ripemd_160

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_MD-*.pod, doc/man3/EVP_DigestInit.pod and providers/implementations/digests/ state no constant-time property.

The default of digests::ripemd_160: hash2 on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

MD5-SHA1: TLS 1.0’s digest, on BearSSL or OpenSSL by name

MD5-SHA1 is the 36-byte digest that TLS 1.0 and 1.1 sign and check: the MD5 of the data followed by the SHA-1 of the same data (RFC 2246, section 4.7). Its designers paired the two so that a break of one would not break the pair; Joux showed in 2004 that a collision of such a pair costs little more than a collision of its stronger half, and SLOTH (2016) turned the weakness into attacks on TLS. RFC 8996 deprecated TLS 1.0 and 1.1 in 2021. hash has it because a program that reads, replays or tests old TLS data needs the exact bytes: digests::md5_sha1 is in BearSSL (br_md5sha1_*) and OpenSSL (its "MD5-SHA1" digest) alone, so the call names backends::bearssl and the program links /third_party//bearssl, or names backends::openssl and links /webcpp/hash//openssl. No backend has an HMAC over it: no standard defines one. The same naming reaches BearSSL’s and OpenSSL’s other digests and MACs, which are never a default either.

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::bearssl;
    auto const message = example::bytes("abc");

    // MD5-SHA1 has no default backend: the call names BearSSL.
    std::array<std::uint8_t, 36> joined{};
    if (!hash::digest_of<hash::digests::md5_sha1, bearssl>(joined, message)) {
        return 1;
    }
    std::cout << "md5_sha1 " << example::hex(joined) << '\n';

    // It is the two digests side by side, which the default backend computes one by one.
    std::array<std::uint8_t, 16> md5{};
    std::array<std::uint8_t, 20> sha1{};
    if (!hash::digest_of<hash::digests::md5>(md5, message) ||
        !hash::digest_of<hash::digests::sha1>(sha1, message)) {
        return 1;
    }
    std::cout << "md5 then sha1 " << example::hex(md5) << example::hex(sha1) << '\n';
    if (example::hex(joined) !=
        "900150983cd24fb0d6963f7d28e17f72a9993e364706816aba3e25717850c26c9cd0d89d") {
        return 1;
    }

    // A handshake's messages arrive one by one: a hasher on BearSSL takes them in pieces.
    auto hashing = hash::hasher<hash::digests::md5_sha1, bearssl>::make();
    std::array<std::uint8_t, 36> pieces{};
    if (!hashing || !hashing->update(example::bytes("ab")) ||
        !hashing->update(example::bytes("c")) || !hashing->finish(pieces)) {
        return 1;
    }
    std::cout << "hasher " << (pieces == joined ? "same" : "different") << '\n';

    // Any digest BearSSL has is reached the same way, and gives the default backend's bytes.
    std::array<std::uint8_t, 32> by_name{};
    std::array<std::uint8_t, 32> by_default{};
    if (!hash::digest_of<hash::digests::sha2_256, bearssl>(by_name, message) ||
        !hash::digest_of<hash::digests::sha2_256>(by_default, message)) {
        return 1;
    }
    std::cout << "sha2_256 on bearssl " << (by_name == by_default ? "same" : "different") << '\n';
}
md5_sha1 900150983cd24fb0d6963f7d28e17f72a9993e364706816aba3e25717850c26c9cd0d89d
md5 then sha1 900150983cd24fb0d6963f7d28e17f72a9993e364706816aba3e25717850c26c9cd0d89d
hasher same
sha2_256 on bearssl same

Pitfalls.

  • Never for anything new. Its 288 bits suggest a strength it does not have: the pair is about as collision resistant as SHA-1, which is broken (MD5, SHA-1 and RIPEMD: legacy). Write SHA-256.

  • No default. digest_of<digests::md5_sha1> without a backend stops the build with a message that names backends::bearssl and backends::openssl; a program that names one without linking its library stops with a message that names the line to add.

  • The order is fixed. MD5’s 16 bytes come first, then SHA-1’s 20: SHA-1 followed by MD5 is another value, which a TLS 1.0 peer rejects.

SM3: China’s national digest

SM3 is the 256-bit digest of China’s commercial cryptography standards, published as GM/T 0004-2012 and as the national standard GB/T 32905-2016, and in ISO/IEC 10118-3 since 2018. Its design follows SHA-256’s (a Merkle-Damgard chain over 512-bit blocks), with its own message expansion and compression. A program needs it where a Chinese standard or regulator requires it: SM2 signatures hash with it, and RFC 8998 gives TLS 1.3 its ShangMi cipher suites. Elsewhere SHA-256 is the interoperable choice. hash has it on backends::openssl, OpenSSL 3.5.9’s default provider, and on backends::botan, Botan 3.14.1’s SM3; it has no default backend, so the call names one and the program links its library: /webcpp/hash//openssl (native, wasip2 and wasip3; OpenSSL is not built for Emscripten) or /third_party//botan (native and Emscripten, with exceptions).

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::openssl;
    auto const message = example::bytes("abc");

    // SM3 has no default backend: the call names OpenSSL, which the Jamfile links.
    std::array<std::uint8_t, 32> once{};
    if (!hash::digest_of<hash::digests::sm3, openssl>(once, message)) {
        return 1;
    }
    std::cout << "sm3 " << example::hex(once) << '\n';
    if (example::hex(once) != "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0") {
        return 1;
    }

    // The same digest in pieces: the hasher owns OpenSSL's context until it finishes.
    auto hashing = hash::hasher<hash::digests::sm3, openssl>::make();
    std::array<std::uint8_t, 32> pieces{};
    if (!hashing || !hashing->update(example::bytes("a")) ||
        !hashing->update(example::bytes("bc")) || !hashing->finish(pieces)) {
        return 1;
    }
    std::cout << "hasher " << (pieces == once ? "same" : "different") << '\n';

    // Other digests of OpenSSL, each named: Keccak-256 (Ethereum's) and TLS 1.0's MD5-SHA1.
    std::array<std::uint8_t, 32> keccak{};
    std::array<std::uint8_t, 36> md5_sha1{};
    if (!hash::digest_of<hash::digests::keccak_256, openssl>(keccak, message) ||
        !hash::digest_of<hash::digests::md5_sha1, openssl>(md5_sha1, message)) {
        return 1;
    }
    std::cout << "keccak_256 " << example::hex(keccak) << '\n';
    std::cout << "md5_sha1 " << example::hex(md5_sha1) << '\n';
}
sm3 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0
hasher same
keccak_256 4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45
md5_sha1 900150983cd24fb0d6963f7d28e17f72a9993e364706816aba3e25717850c26c9cd0d89d

Pitfalls.

  • No default. digest_of<digests::sm3> without a backend stops the build with a message that names backends::openssl and backends::botan; naming one without linking its library stops with a message that names the line to add.

  • OpenSSL allocates. A hasher on backends::openssl owns an EVP_MD_CTX that OpenSSL allocates with its own allocator when the hasher is made and frees when it finishes or is destroyed; digest_of allocates and frees one in each call (The code webcpp writes, and what the C libraries do).

Table 12. Who implements digests::sm3 (GB/T 32905-2016 (ISO/IEC 10118-3:2018))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

digests::sm3

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

digests::sm3

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_MD-*.pod, doc/man3/EVP_DigestInit.pod and providers/implementations/digests/ state no constant-time property.

digests::sm3 has no default backend: the call names one of its backends, as its second template argument (The default backend).

Streebog

Streebog (GOST R 34.11-2012, RFC 6986) is Russia’s national digest, which replaced GOST R 34.11-94 in 2013: Streebog-256 and Streebog-512, a 512-bit state compressed block by block with its own substitution, permutation and linear layers, and a checksum of the message folded in at the end. Russian standards build on it: HMAC over it and the key derivations of RFC 7836, the GOST signatures and the GOST cipher suites of TLS. Elsewhere SHA-256 and SHA-512 are the interoperable choice. hash has it on backends::botan alone, Botan 3.14.1’s Streebog-256 and Streebog-512: digests::streebog_256 and digests::streebog_512 have no default backend, so the call names backends::botan, and the program links /third_party//botan, natively or on Emscripten, with exceptions (Using webcpp::hash in your Jamfile).

This section adapts the warnings of Botan’s documentation on Streebog (doc/api_ref/hash.rst and doc/deprecated.rst of Botan 3.14.1, BSD-2-Clause licence, kept in NOTICE.md), in hash’s own terms.

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::botan;
    // M1 of RFC 6986, section 10.1: 63 digits.
    auto const message =
        example::bytes("012345678901234567890123456789012345678901234567890123456789012");

    // Streebog has no default backend: the call names Botan, which the Jamfile links.
    std::array<std::uint8_t, 32> short_digest{};
    std::array<std::uint8_t, 64> long_digest{};
    if (!hash::digest_of<hash::digests::streebog_256, botan>(short_digest, message) ||
        !hash::digest_of<hash::digests::streebog_512, botan>(long_digest, message)) {
        return 1;
    }
    std::cout << "streebog_256 " << example::hex(short_digest) << '\n';
    std::cout << "streebog_512 " << example::hex(long_digest) << '\n';
    if (example::hex(short_digest) !=
        "9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500") {
        return 1;
    }

    // Two functions: each size has its own initial value, so neither digest starts the other.
    bool const starts = std::equal(short_digest.begin(), short_digest.end(), long_digest.begin());
    std::cout << "streebog_256 starts streebog_512: " << (starts ? "yes" : "no") << '\n';
}
streebog_256 9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500
streebog_512 1b54d01a4af5b9d5cc3d86d68d285462b19abc2475222f35c085122be4ba1ffa00ad30f8767b3a82384c6574f024c311e2a481332b08ef7f41797891c1646f48
streebog_256 starts streebog_512: no

Pitfalls.

  • Its S-box has a hidden structure. Botan’s documentation warns that Streebog’s S-box was shown to have a structure that interacts with its linear layer in a way that may give a backdoor in some uses, and asks that Streebog be avoided wherever possible; Botan 3.14.1 deprecates its module, which it still builds. Use it only where a Russian standard requires it.

  • Table lookups indexed by the data. Botan’s Streebog uses tables indexed by the bytes it hashes, likely open to cache timing attacks on secret data; its constant-time code needs AVX-512 and GFNI, which webcpp’s build of Botan does not load. Hash public data with it, never a key.

  • The RFC writes its examples backwards. RFC 6986 prints each message and digest as a number, most significant byte first: the bytes an implementation hashes and writes are those bytes reversed, as the example’s are.

  • Two functions, not one cut. Streebog-256 starts from another initial value than Streebog-512: its digest is not the first half of the longer one.

Table 13. Who implements digests::streebog_256, digests::streebog_512 (GOST R 34.11-2012 (RFC 6986))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

digests::streebog_256

botan (with exceptions only)

/third_party//botan

native, emscripten

-

no

digests::streebog_512

botan (with exceptions only)

/third_party//botan

native, emscripten

-

no

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/hash.rst warns that Streebog’s baseline implementation uses table lookups indexed by the data and is likely vulnerable to cache-based side channels; its constant-time code needs AVX-512 and GFNI, an instruction-set module that /third_party//botan’s minimized build does not load.

digests::streebog_256 has no default backend: the call names one of its backends, as its second template argument (The default backend).

digests::streebog_512 has no default backend: the call names one of its backends, as its second template argument (The default backend).

Whirlpool

Whirlpool (Barreto and Rijmen, 2000) is a 512-bit digest built on a block cipher close to AES, chosen by the NESSIE project in 2003 and standardised in ISO/IEC 10118-3. Its use today is reading what was hashed with it: VeraCrypt and TrueCrypt volumes derive their header keys with PBKDF2 over HMAC-Whirlpool when the volume was made so, and some archives and file lists carry Whirlpool checksums. hash has it on backends::botan alone (OpenSSL keeps it in its legacy provider, which webcpp does not load): digests::whirlpool has no default backend, so the call names backends::botan and the program links /third_party//botan, natively or on Emscripten, with exceptions. Its pitfalls adapt the warning of Botan’s documentation on Whirlpool (doc/api_ref/hash.rst of Botan 3.14.1, BSD-2-Clause licence, kept in NOTICE.md).

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::botan;

    std::array<std::uint8_t, 64> once{};
    if (!hash::digest_of<hash::digests::whirlpool, botan>(once, example::bytes("abc"))) {
        return 1;
    }
    std::cout << "whirlpool " << example::hex(once) << '\n';
    if (example::hex(once) !=
        "4e2448a4c6f486bb16b6562c73b4020bf3043e3a731bce721ae1b303d97e6d4c"
        "7181eebdb6c57e277d0e34957114cbd6c797fc9d95d8b582d225292076d4eef5") {
        return 1;
    }

    // The same digest in pieces: the hasher owns Botan's object until it finishes.
    auto hashing = hash::hasher<hash::digests::whirlpool, botan>::make();
    std::array<std::uint8_t, 64> pieces{};
    if (!hashing || !hashing->update(example::bytes("a")) ||
        !hashing->update(example::bytes("bc")) || !hashing->finish(pieces)) {
        return 1;
    }
    std::cout << "hasher " << (pieces == once ? "same" : "different") << '\n';
}
whirlpool 4e2448a4c6f486bb16b6562c73b4020bf3043e3a731bce721ae1b303d97e6d4c7181eebdb6c57e277d0e34957114cbd6c797fc9d95d8b582d225292076d4eef5
hasher same

Pitfalls.

  • Three versions, one name. The digest of the first submission (Whirlpool-0) and of its 2001 revision (Whirlpool-T) differ from the final Whirlpool’s, which ISO standardised and Botan computes: a checksum made by an old tool may be one of the others.

  • Table lookups indexed by the data. Botan’s documentation warns that its baseline Whirlpool indexes tables by the data, likely open to cache timing attacks on secret data; its constant-time code needs AVX2 or AVX-512, which webcpp’s build of Botan does not load. HMAC-Whirlpool over a key, as VeraCrypt’s, runs that code too.

  • Slow and of another age. Whirlpool is slower than SHA-512 and has no hardware support; a new design takes SHA-512 or SHA3-512.

Table 14. Who implements digests::whirlpool (ISO/IEC 10118-3 (Whirlpool, Barreto and Rijmen))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

digests::whirlpool

botan (with exceptions only)

/third_party//botan

native, emscripten

-

no

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/hash.rst warns that Whirlpool’s baseline implementation uses table lookups indexed by the data and is likely vulnerable to cache-based side channels; its constant-time code needs AVX2 or AVX-512, instruction-set modules that /third_party//botan’s minimized build does not load.

digests::whirlpool has no default backend: the call names one of its backends, as its second template argument (The default backend).

Skein-512

Skein (Ferguson, Lucks, Schneier and others, 2008) is a finalist of the SHA-3 competition, built on Threefish, a tweakable block cipher of additions, rotations and XORs that is fast on 64-bit processors. Skein-512 has a 512-bit state and gives any length of output; digests::skein_512 is Skein-512 with its 64-byte digest, Skein 1.3, the version of the competition’s last round. Keccak won, and Skein remains where a format chose it before. hash has it on backends::botan alone, Botan’s Skein-512(512), with no default: the call names backends::botan and the program links /third_party//botan, natively or on Emscripten, with exceptions.

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::botan;

    std::array<std::uint8_t, 64> digest{};
    if (!hash::digest_of<hash::digests::skein_512, botan>(digest, {})) {
        return 1;
    }
    std::cout << "skein_512 " << example::hex(digest) << '\n';
    if (example::hex(digest) !=
        "bc5b4c50925519c290cc634277ae3d6257212395cba733bbad37a4af0fa06af4"
        "1fca7903d06564fea7a2d3730dbdb80c1f85562dfcc070334ea4d1d9e72cba7a") {
        return 1;
    }

    // The tag is Skein-512 with its 512-bit output: 32 bytes would be another function's digest,
    // Skein-512-256, which encodes its size in its configuration, not the first half of this one.
    std::array<std::uint8_t, 32> half{};
    std::cout << "32 bytes: "
              << hash::digest_of<hash::digests::skein_512, botan>(half, {}).error().message()
              << '\n';
}
skein_512 bc5b4c50925519c290cc634277ae3d6257212395cba733bbad37a4af0fa06af41fca7903d06564fea7a2d3730dbdb80c1f85562dfcc070334ea4d1d9e72cba7a
32 bytes: the output is not of a size the function produces

Pitfalls.

  • Skein 1.3 is not Skein 1.1. The rotation constants changed between the first versions and 1.3 (1.2 changed them, 1.3 changed the key schedule’s constant): a digest computed before 2010 may be another version’s.

  • The output’s size is in the hash. Skein-512-256 writes its 256 bits into its configuration block, so it is not the start of Skein-512-512; hash has the 512-bit digest alone, and refuses another size with invalid_output_size.

  • No personalisation, no key here. Skein’s other parameters (a personalisation string, Skein-MAC’s key, the tree mode) have no tag; Botan’s personalisation is not reached.

Table 15. Who implements digests::skein_512 (The Skein Hash Function Family, version 1.3)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

digests::skein_512

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

digests::skein_512 has no default backend: the call names one of its backends, as its second template argument (The default backend).

One call, or pieces with one result: digest_of and hasher

The types above are Boost.Hash2’s form: an object fed with update whose result() can be called again, and which hash_append and the rest of Boost.Hash2 take. Two functions reach the same algorithms through a tag of webcpp::hash::digests, as digests::sha2_256, and a backend: digest_of hashes a message in one call, and hasher takes it in pieces, as a file read in blocks or a stream arrives, and gives exactly one result. The backend is the tag’s default, the first of backends::hash2, backends::xkcp, backends::blake3 and backends::sodium that has it, or the one the call names as its second template argument; the tables of each algorithm list them.

#include "hex.hpp"

#include <webcpp/hash/digest.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    auto const message = example::bytes("abc");

    // One call: the tag names the algorithm, the default backend runs it (backends::hash2 here).
    std::array<std::uint8_t, 32> once{};
    if (!hash::digest_of<hash::digests::sha2_256>(once, message)) {
        return 1;
    }
    std::cout << "digest_of " << example::hex(once) << '\n';
    if (example::hex(once) != "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") {
        return 1;
    }

    // Data that arrives in pieces (a file read in blocks, a stream) goes through a hasher.
    auto hashing = hash::hasher<hash::digests::sha2_256>::make();
    if (!hashing || !hashing->update(example::bytes("a")) ||
        !hashing->update(example::bytes("bc"))) {
        return 1;
    }
    std::array<std::uint8_t, 32> pieces{};
    if (!hashing->finish(pieces)) {
        return 1;
    }
    std::cout << "hasher " << (pieces == once ? "same" : "different") << '\n';

    // The result is final: a second finish is an error, not the hash of nothing more.
    auto const again = hashing->finish(pieces);
    std::cout << "second finish: " << again.error().message() << '\n';

    // A fixed-size digest takes its size alone: the output is refused before any work.
    std::array<std::uint8_t, 20> too_short{};
    auto const refused = hash::digest_of<hash::digests::sha2_256>(too_short, message);
    std::cout << "20-byte output: " << refused.error().message() << '\n';

    // A backend named in the call: Boost.Hash2's SHAKE128, any size, the stream's first bytes.
    std::array<std::uint8_t, 16> shake{};
    if (!hash::digest_of<hash::digests::shake_128, hash::backends::hash2>(shake, message)) {
        return 1;
    }
    std::cout << "shake_128 " << example::hex(shake) << '\n';
}
digest_of ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
hasher same
second finish: the hasher was finished or moved from
20-byte output: the output is not of a size the function produces
shake_128 5881092dd818bf5cf8a3ddb793fbcba7

Pitfalls.

  • One result. A hasher gives its result once: a second finish, or an update after it, is error::invalid_state, not the hash of what came before; start another hasher for another message. A hasher is move-only, and wipes its state when it finishes, when it is destroyed and when it is moved from.

  • The output’s size is the digest’s. A fixed-size digest takes an output of exactly its size (invalid_output_size otherwise, the output untouched); an extendable-output function, SHAKE or BLAKE3, takes any size from 1 byte; BLAKE2b takes the size its options name (BLAKE2b with a key, a salt, a personalisation and a length).

  • A backend may have a tag in part. backends::hash2 has BLAKE2b with its 64-byte output and no option alone, and answers unsupported_by_backend to a shorter output or to an option; backends::openssl has BLAKE2b unkeyed, at every output size, with no key, salt or personalisation. A call that names a backend gets what that backend has, which its row of the tables says.

  • Some backends are reached only by name. backends::bearssl and backends::openssl are never a default. BearSSL’s MD5, SHA-1, SHA-2 and SHAKE (any output size) run only when the call names it, as digest_of<digests::sha2_256, backends::bearssl>, and the program links /third_party//bearssl; OpenSSL’s MD5, SHA-1, SHA-2, SHA-3, SHAKE (any output size), Keccak, BLAKE2, RIPEMD-160, MD5-SHA1 and SM3 likewise, with /webcpp/hash//openssl. backends::botan is reached by name too, in a program built with exceptions that links /third_party//botan: its MD5, SHA-1, SHA-2, SHA-3, SHAKE, Keccak, BLAKE2, RIPEMD-160 and SM3, and Streebog, Whirlpool and Skein-512, which no other backend has (Streebog, Whirlpool, Skein-512). digests::md5_sha1 is in BearSSL and OpenSSL alone and has no default (MD5-SHA1: TLS 1.0’s digest, on BearSSL or OpenSSL by name). OpenSSL’s SHA-256/192 (SHA-256’s first 24 bytes) and its KMAC hash have no tag, and Whirlpool is in OpenSSL’s legacy provider, which webcpp does not load: the capability table says why.

  • A tag without its backend stops the build. A tag whose backend the program does not link stops with a message that names the line to add; a tag that the backend does not have stops with a message that names the backends that have it, or says that none has it (When the build stops).

Message authentication

A message authentication code (MAC) is a digest that only the holders of a secret key can compute. A server that signs its session cookies, an API that checks a request came from a client holding its key, a webhook receiver that checks the sender, and a chat protocol that rejects altered messages all do the same thing: the sender computes a tag from the key and the message, the receiver computes it again and accepts the message only if the two tags are equal. Without the key an attacker can neither forge a tag for a new message nor change a message and keep its tag. A MAC does not hide the message, and it does not prove to a third party who wrote it (both sides hold the key); that is a signature’s job, webcpp::crypto’s.

mac sets DIT (data-independent timing) around each call, on every synchronous backend, on 64-bit ARM under macOS, iOS, Linux, Android and Windows where the CPU has FEAT_DIT, and leaves the thread’s DIT as it found it: a program does nothing (Data-independent timing (DIT)). Boost.Hash2’s types that hash names by alias, hmac<H> and its hmac_* aliases, siphash_32 and siphash_64, set none (HMAC): for HMAC with DIT, call mac<macs::hmac<D>>, and for SipHash with DIT, mac<macs::siphash_2_4>.

Table 16. What each of "Message authentication" is
Name Output Security Standard Status In the browser (WebCrypto)

siphash_32

32 bits

a 64-bit key; for hash tables only, not a MAC

HalfSipHash-2-4 (Aumasson)

recommended

no

siphash_64

64 bits

a 128-bit key; for hash tables only, not a MAC

SipHash-2-4 (Aumasson, Bernstein)

recommended

no

macs::siphash_2_4

64 bits

a 128-bit key; for hash tables only, not a MAC

SipHash-2-4 (Aumasson, Bernstein)

recommended

no

macs::siphash_2_4x

128 bits

a 128-bit key; fewer collisions than SipHash-2-4’s 64 bits, still not a MAC for messages

SipHash-2-4 with a 128-bit output (Aumasson, Bernstein; libsodium’s siphashx24)

recommended

no

macs::kmac_128

any length from 4 bytes (32 bits, SP 800-185 section 8.4.2)

128-bit security with a key of at least 16 bytes (SP 800-185, section 8.4)

NIST SP 800-185, section 4

recommended

no

macs::kmac_256

any length from 4 bytes (32 bits, SP 800-185 section 8.4.2)

256-bit security with a key of at least 32 bytes (SP 800-185, section 8.4)

NIST SP 800-185, section 4

recommended

no

macs::blake2b_mac

1 to 64 bytes

up to 256 bits, bounded by the key’s and the tag’s sizes

RFC 7693, keyed (section 2.5)

recommended

no

macs::blake2s_mac

1 to 32 bytes

128 bits and more, up to the tag’s size

RFC 7693, keyed (section 2.5)

recommended

no

hmac

the digest of H

that of H’s digest, with a key as long as it

RFC 2104

recommended

HMAC

hmac_md5_128

128 bits

still unforgeable as HMAC, but on a broken hash: legacy

RFC 2104

legacy

no

hmac_sha1_160

160 bits

still unforgeable as HMAC, but on a broken hash: legacy

RFC 2104

legacy

HMAC with SHA-1

hmac_sha2_224

224 bits

112 bits and more

RFC 2104

recommended

no

hmac_sha2_256

256 bits

128 bits and more

RFC 2104

recommended

HMAC with SHA-256

hmac_sha2_384

384 bits

192 bits and more

RFC 2104

recommended

HMAC with SHA-384

hmac_sha2_512

512 bits

256 bits

RFC 2104

recommended

HMAC with SHA-512

hmac_sha2_512_224

224 bits

112 bits and more

RFC 2104

recommended

no

hmac_sha2_512_256

256 bits

128 bits and more

RFC 2104

recommended

no

hmac_sha3_224

224 bits

112 bits and more

RFC 2104

recommended

no

hmac_sha3_256

256 bits

128 bits and more

RFC 2104

recommended

no

hmac_sha3_384

384 bits

192 bits and more

RFC 2104

recommended

no

hmac_sha3_512

512 bits

256 bits

RFC 2104

recommended

no

hmac_ripemd_128

128 bits

legacy

RFC 2104

legacy

no

hmac_ripemd_160

160 bits

legacy

RFC 2104

legacy

no

hmac_blake2b_512

512 bits

256 bits

RFC 2104

recommended

no

hmac_blake2s_256

256 bits

128 bits and more

RFC 2104

recommended

no

macs::hmac<digests::md5>

128 bits

still unforgeable as HMAC, but on a broken hash: legacy

RFC 2104

legacy

no

macs::hmac<digests::sha1>

160 bits

still unforgeable as HMAC, but on a broken hash: legacy

RFC 2104

legacy

HMAC with SHA-1

macs::hmac<digests::sha2_224>

224 bits

112 bits and more

RFC 2104

recommended

no

macs::hmac<digests::sha2_256>

256 bits

128 bits and more

RFC 2104

recommended

HMAC with SHA-256

macs::hmac<digests::sha2_384>

384 bits

192 bits and more

RFC 2104

recommended

HMAC with SHA-384

macs::hmac<digests::sha2_512>

512 bits

256 bits

RFC 2104

recommended

HMAC with SHA-512

macs::hmac<digests::sha2_512_224>

224 bits

112 bits and more

RFC 2104

recommended

no

macs::hmac<digests::sha2_512_256>

256 bits

128 bits and more

RFC 2104

recommended

no

macs::hmac<digests::sha3_224>

224 bits

112 bits and more

RFC 2104

recommended

no

macs::hmac<digests::sha3_256>

256 bits

128 bits and more

RFC 2104

recommended

no

macs::hmac<digests::sha3_384>

384 bits

192 bits and more

RFC 2104

recommended

no

macs::hmac<digests::sha3_512>

512 bits

256 bits

RFC 2104

recommended

no

macs::hmac<digests::ripemd_160>

160 bits

legacy

RFC 2104

legacy

no

macs::hmac<digests::blake2b>

512 bits

256 bits

RFC 2104

recommended

no

macs::hmac<digests::blake2s_256>

256 bits

128 bits and more

RFC 2104

recommended

no

macs::hmac<digests::keccak_224>

224 bits

112 bits and more

RFC 2104

legacy

no

macs::hmac<digests::keccak_256>

256 bits

128 bits and more

RFC 2104

legacy

no

macs::hmac<digests::keccak_384>

384 bits

192 bits and more

RFC 2104

legacy

no

macs::hmac<digests::keccak_512>

512 bits

256 bits and more

RFC 2104

legacy

no

macs::hmac<digests::sm3>

256 bits

128 bits and more

RFC 2104

recommended

no

macs::hmac<digests::streebog_256>

256 bits

128 bits and more

RFC 2104

legacy

no

macs::hmac<digests::streebog_512>

512 bits

256 bits and more

RFC 2104

legacy

no

macs::hmac<digests::whirlpool>

512 bits

256 bits and more

RFC 2104

legacy

no

macs::hmac<digests::skein_512>

512 bits

256 bits and more

RFC 2104

legacy

no

Table 17. How to choose among "Message authentication"
Name Fastest natively Smallest on Emscripten Where it is used Choose it when

siphash_32

1,624 MiB/s (hash2)

6,206 bytes (hash2)

the Linux kernel’s hsiphash

Hash tables on 32-bit targets whose keys an adversary chooses.

siphash_64

3,274 MiB/s (hash2)

6,294 bytes (hash2)

Python’s string hashing (PEP 456); Rust’s default HashMap hasher

Every hash table, set or Bloom filter whose keys come from the network or another user.

macs::siphash_2_4

-

-

Python’s string hashing (PEP 456)

To compute it in one call, on a backend named in the call; siphash_64 itself for hash_append and a hash table’s hasher.

macs::siphash_2_4x

-

-

libsodium’s short-input hashing; the SipHash reference implementation’s 128-bit output

For a 128-bit SipHash, as a libsodium program computes it: a large table, a filter or an identifier keyed against flooding; siphash_2_4 for 64 bits.

macs::kmac_128

-

-

A MAC and a KDF of NIST SP 800-56C (KMAC-based key derivation)

Where a standard or a format names KMAC; HMAC-SHA-256 elsewhere, which every platform has.

macs::kmac_256

-

-

A MAC and a KDF of NIST SP 800-56C (KMAC-based key derivation)

As KMAC128, where a format asks for 256-bit security.

macs::blake2b_mac

-

-

RFC 7693’s keyed BLAKE2b, a MAC without HMAC’s two passes; libsodium’s keyed generic hash, crypto_generichash with a key

A fast keyed tag on 64-bit machines, of any size from 1 to 64 bytes; HMAC-SHA-256 where a format or WebCrypto must agree.

macs::blake2s_mac

-

-

WireGuard’s MAC

A fast keyed tag on 32-bit and small machines, without HMAC’s two passes.

hmac

599 MiB/s (hash2)

14,437 bytes (hash2)

RFC 2104

HMAC over a hash that has no alias of its own.

hmac_md5_128

932 MiB/s (hash2)

8,330 bytes (hash2)

RFC 6151 on HMAC-MD5

Only for an existing protocol.

hmac_sha1_160

1,185 MiB/s (hash2)

10,569 bytes (hash2)

TOTP and HOTP codes (RFC 6238, RFC 4226)

Only for an existing protocol, such as authenticator-app codes.

hmac_sha2_224

582 MiB/s (hash2)

14,444 bytes (hash2)

RFC 4231’s test cases

When a standard asks for it.

hmac_sha2_256

582 MiB/s (hash2)

14,437 bytes (hash2)

JSON Web Tokens signed HS256; TLS 1.3’s HKDF

The default MAC: interoperable, in every browser.

hmac_sha2_384

911 MiB/s (hash2)

17,975 bytes (hash2)

JSON Web Tokens signed HS384

When a standard asks for it.

hmac_sha2_512

930 MiB/s (hash2)

17,980 bytes (hash2)

BIP32’s key derivation; JSON Web Tokens signed HS512

When a standard asks for it, or for a 512-bit tag.

hmac_sha2_512_224

939 MiB/s (hash2)

18,041 bytes (hash2)

FIPS 180-4’s truncated SHA-512

When a standard asks for it.

hmac_sha2_512_256

904 MiB/s (hash2)

17,992 bytes (hash2)

FIPS 180-4’s truncated SHA-512; not libsodium’s crypto_auth, which truncates HMAC-SHA-512’s tag

When a standard asks for it.

hmac_sha3_224

733 MiB/s (hash2)

7,427 bytes (hash2)

FIPS 202

When a standard asks for it.

hmac_sha3_256

686 MiB/s (hash2)

7,416 bytes (hash2)

FIPS 202

When a standard asks for it.

hmac_sha3_384

526 MiB/s (hash2)

7,383 bytes (hash2)

FIPS 202

When a standard asks for it.

hmac_sha3_512

366 MiB/s (hash2)

7,386 bytes (hash2)

FIPS 202

When a standard asks for it.

hmac_ripemd_128

959 MiB/s (hash2)

9,712 bytes (hash2)

RFC 2286’s test cases

Only for an existing protocol.

hmac_ripemd_160

607 MiB/s (hash2)

11,897 bytes (hash2)

RFC 2286’s test cases

Only for an existing protocol.

hmac_blake2b_512

1,548 MiB/s (hash2)

12,262 bytes (hash2)

RFC 7693, whose keyed mode makes HMAC unnecessary

When a protocol names HMAC-BLAKE2b; otherwise a keyed blake2b_512.

hmac_blake2s_256

922 MiB/s (hash2)

11,284 bytes (hash2)

WireGuard’s HKDF

For WireGuard-style protocols.

macs::hmac<digests::md5>

-

-

RFC 6151 on HMAC-MD5

To compute a tag in one call, on a backend named in the call; hmac_md5_128 itself to feed the message in pieces.

macs::hmac<digests::sha1>

-

-

TOTP and HOTP codes (RFC 6238, RFC 4226)

To compute a tag in one call, on a backend named in the call; hmac_sha1_160 itself to feed the message in pieces.

macs::hmac<digests::sha2_224>

-

-

RFC 4231’s test cases

To compute a tag in one call, on a backend named in the call; hmac_sha2_224 itself to feed the message in pieces.

macs::hmac<digests::sha2_256>

-

-

JSON Web Tokens signed HS256; TLS 1.3’s HKDF

To compute a tag in one call, on a backend named in the call; hmac_sha2_256 itself to feed the message in pieces.

macs::hmac<digests::sha2_384>

-

-

JSON Web Tokens signed HS384

To compute a tag in one call, on a backend named in the call; hmac_sha2_384 itself to feed the message in pieces.

macs::hmac<digests::sha2_512>

-

-

BIP32’s key derivation; JSON Web Tokens signed HS512

To compute a tag in one call, on a backend named in the call; hmac_sha2_512 itself to feed the message in pieces.

macs::hmac<digests::sha2_512_224>

-

-

FIPS 180-4’s truncated SHA-512

To compute a tag in one call, on a backend named in the call; hmac_sha2_512_224 itself to feed the message in pieces.

macs::hmac<digests::sha2_512_256>

-

-

FIPS 180-4’s truncated SHA-512; not libsodium’s crypto_auth, which truncates HMAC-SHA-512’s tag

To compute a tag in one call, on a backend named in the call; hmac_sha2_512_256 itself to feed the message in pieces.

macs::hmac<digests::sha3_224>

-

-

FIPS 202

To compute a tag in one call, on a backend named in the call; hmac_sha3_224 itself to feed the message in pieces.

macs::hmac<digests::sha3_256>

-

-

FIPS 202

To compute a tag in one call, on a backend named in the call; hmac_sha3_256 itself to feed the message in pieces.

macs::hmac<digests::sha3_384>

-

-

FIPS 202

To compute a tag in one call, on a backend named in the call; hmac_sha3_384 itself to feed the message in pieces.

macs::hmac<digests::sha3_512>

-

-

FIPS 202

To compute a tag in one call, on a backend named in the call; hmac_sha3_512 itself to feed the message in pieces.

macs::hmac<digests::ripemd_160>

-

-

RFC 2286’s test cases

To compute a tag in one call, on a backend named in the call; hmac_ripemd_160 itself to feed the message in pieces.

macs::hmac<digests::blake2b>

-

-

RFC 7693, whose keyed mode makes HMAC unnecessary

To compute a tag in one call, on a backend named in the call; hmac_blake2b_512 itself to feed the message in pieces.

macs::hmac<digests::blake2s_256>

-

-

WireGuard’s HKDF

To compute a tag in one call, on a backend named in the call; hmac_blake2s_256 itself to feed the message in pieces.

macs::hmac<digests::keccak_224>

-

-

The Keccak team’s final SHA-3 submission, before FIPS 202 changed the padding

Only where a format names HMAC over Keccak-224; HMAC over SHA3-224 for anything new.

macs::hmac<digests::keccak_256>

-

-

The Keccak team’s final SHA-3 submission, before FIPS 202 changed the padding

Only where a format names HMAC over Keccak-256; HMAC over SHA3-256 for anything new.

macs::hmac<digests::keccak_384>

-

-

The Keccak team’s final SHA-3 submission, before FIPS 202 changed the padding

Only where a format names HMAC over Keccak-384; HMAC over SHA3-384 for anything new.

macs::hmac<digests::keccak_512>

-

-

The Keccak team’s final SHA-3 submission, before FIPS 202 changed the padding

Only where a format names HMAC over Keccak-512; HMAC over SHA3-512 for anything new.

macs::hmac<digests::sm3>

-

-

RFC 8998, ShangMi cipher suites for TLS 1.3, whose HKDF runs HMAC-SM3; GM/T 0042-2015’s HMAC-SM3 test cases, in OpenSSL’s evpmac_sm3.txt

Where a Chinese standard or a regulator requires SM3, naming backends::openssl or backends::botan; HMAC-SHA-256 everywhere else.

macs::hmac<digests::streebog_256>

-

-

RFC 7836 section 4.1.1, HMAC_GOSTR3411_2012_256

Only where a Russian standard requires it, naming backends::botan; HMAC-SHA-256 everywhere else.

macs::hmac<digests::streebog_512>

-

-

RFC 7836 section 4.1.2, HMAC_GOSTR3411_2012_512

Only where a Russian standard requires it, naming backends::botan; HMAC-SHA-512 everywhere else.

macs::hmac<digests::whirlpool>

-

-

VeraCrypt’s header key derivation, PBKDF2 over HMAC-Whirlpool

Only where a format names HMAC over Whirlpool, naming backends::botan; HMAC-SHA-512 everywhere else.

macs::hmac<digests::skein_512>

-

-

The Skein Hash Function Family, version 1.3, whose hash HMAC’s generic construction takes

Only where a format names HMAC over Skein-512, naming backends::botan; HMAC-SHA-512 everywhere else.

The measured columns are doc/measurements.json’s, a reference measured on 2026-11-16 on Apple M5 Max that decides nothing: the native throughput over 1 MiB, or the time of one derivation over hmac_sha2_256, of the fastest backend, and the smallest Emscripten program that calls the function; Measured size and throughput has every backend on every target.

HMAC

HMAC (RFC 2104, 1997) turns any digest into a MAC: it hashes the key, padded to a block, with the message, then hashes that result again under the key padded another way. The double pass is what makes it safe over SHA-2 despite length extension, and HMAC remains secure even over hashes whose collision resistance is broken. HMAC-SHA-256 signs JSON Web Tokens (HS256), drives TLS 1.3’s key schedule through HKDF, and is in every browser’s WebCrypto. hash re-exports Boost.Hash2’s hmac<H> and one alias per Hash2 digest; mac computes HMAC over a tag of digests on any backend that has the digest (A MAC in one call: mac), HMAC over Streebog, Whirlpool and Skein-512 on backends::botan alone (The MACs of Botan: HMAC over its digests, KMAC, SipHash and keyed BLAKE2b).

#include "hex.hpp"

#include <webcpp/hash/hmac.hpp>
#include <webcpp/secure/constant_time_equal.hpp>

#include <iostream>
#include <span>
#include <string_view>

namespace {

webcpp::hash::hmac_sha2_256::result_type tag_of(std::span<std::uint8_t const> key,
                                                std::string_view message) {
    webcpp::hash::hmac_sha2_256 mac(key.data(), key.size());
    mac.update(message.data(), message.size());
    return mac.result();
}

}  // namespace

int main() {
    auto const key = example::bytes("Jefe");
    std::string_view const message = "what do ya want for nothing?";

    // The sender computes the tag and sends it along with the message.
    auto const tag = tag_of(key, message);
    std::cout << "hmac_sha2_256 " << example::hex(tag) << '\n';
    if (example::hex(tag) != "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843") {
        return 1;
    }

    // The receiver computes the tag again from the message it got, and compares it with the one
    // it got. Never with ==: memcmp stops at the first different byte, so an attacker who
    // measures how long the answer takes learns how many leading bytes of a guess are right,
    // and guesses a valid tag one byte at a time. secure::constant_time_equal reads every byte.
    bool const genuine = webcpp::secure::constant_time_equal(tag_of(key, message), tag);
    std::cout << "genuine: " << (genuine ? "yes" : "no") << '\n';

    // One byte of the message changed in transit: the tags differ.
    bool const forged =
        webcpp::secure::constant_time_equal(tag_of(key, "what do ya want for nothing!"), tag);
    std::cout << "tampered: " << (forged ? "accepted" : "refused") << '\n';
    if (!genuine || forged) {
        return 1;
    }
}
hmac_sha2_256 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
genuine: yes
tampered: refused

Pitfalls.

  • Compare tags with webcpp::secure::constant_time_equal, never with ==. The digest’s operator== is memcmp, which returns at the first byte that differs; an attacker who sends guesses and times the answers learns how many leading bytes are right and builds a valid tag one byte at a time, in a few thousand tries per byte instead of 2256 in all. constant_time_equal reads every byte whatever the data.

  • A key is random and as long as the digest. A 32-byte key from webcpp::crypto::random_device for HMAC-SHA-256; a password is not a key (Password hashing). A key longer than the hash’s block is hashed first, which gives it no more strength.

  • Authenticate everything the receiver acts on. A tag over the body alone lets an attacker change the headers, the recipient or the order of messages; put a version, the context and a counter or timestamp inside the authenticated bytes, with an unambiguous encoding (lengths, not separators).

  • hmac<H> and its aliases set no DIT; mac does. They are Boost.Hash2’s own classes, which hash names by alias, and a guard inside them would need a type of hash’s in place of the one a program shares with Boost.Hash2’s code. For an HMAC with DIT on 64-bit ARM, call mac<macs::hmac<D>>, which runs the same Boost.Hash2 code on backends::hash2 inside its guard, or set DIT around the computation yourself (Apple’s timingsafe_enable_if_supported).

  • Truncate only on purpose. A tag cut to 16 bytes still gives 128 bits against forgery; one cut to 4 bytes gives an attacker a one-in-four-billion chance per try, which a busy server can reach.

Table 18. Who implements hmac to macs::hmac<digests::skein_512>, 41 names (RFC 2104)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

hmac

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_md5_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha1_160

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha2_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha2_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha2_384

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha2_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha2_512_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha2_512_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha3_224

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha3_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha3_384

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_sha3_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_ripemd_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_ripemd_160

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_blake2b_512

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

hmac_blake2s_256

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::md5>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::md5>

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::md5>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::md5>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha1>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha1>

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha1>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha1>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha1>

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

macs::hmac<digests::sha2_224>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_224>

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha2_224>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha2_256>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_256>

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_256>

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha2_256>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha2_256>

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

macs::hmac<digests::sha2_384>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_384>

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_384>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha2_384>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha2_384>

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

macs::hmac<digests::sha2_512>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_512>

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_512>

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_512>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha2_512>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha2_512>

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

-

not stated

macs::hmac<digests::sha2_512_224>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_512_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha2_512_256>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha2_512_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha2_512_256>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha3_224>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha3_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha3_224>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha3_256>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha3_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha3_256>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha3_384>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha3_384>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha3_384>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sha3_512>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::sha3_512>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sha3_512>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::ripemd_160>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::ripemd_160>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::ripemd_160>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::blake2b>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::blake2b>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::blake2b>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::blake2s_256>

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::hmac<digests::blake2s_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::blake2s_256>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::keccak_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::keccak_224>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::keccak_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::keccak_256>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::keccak_384>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::keccak_384>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::keccak_512>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::keccak_512>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::sm3>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::hmac<digests::sm3>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::hmac<digests::streebog_256>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

no

macs::hmac<digests::streebog_512>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

no

macs::hmac<digests::whirlpool>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

no

macs::hmac<digests::skein_512>

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • bearssl: BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_hmac.h states constant time for br_hmac_outCT alone; mac calls br_hmac_out.

  • botan:

    • Botan 3.14.1: doc/api_ref/hash.rst warns that Streebog’s baseline implementation uses table lookups indexed by the data and is likely vulnerable to cache-based side channels; its constant-time code needs AVX-512 and GFNI, an instruction-set module that /third_party//botan’s minimized build does not load.

    • Botan 3.14.1: doc/api_ref/hash.rst warns that Whirlpool’s baseline implementation uses table lookups indexed by the data and is likely vulnerable to cache-based side channels; its constant-time code needs AVX2 or AVX-512, instruction-set modules that /third_party//botan’s minimized build does not load.

    • Botan 3.14.1: doc/api_ref/message_auth_codes.rst states no constant-time property of this MAC, and its source (src/lib/mac/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man3/EVP_MAC.pod, doc/man7/EVP_MAC-HMAC.pod, EVP_MAC-KMAC.pod, EVP_MAC-BLAKE2.pod, EVP_MAC-Siphash.pod and providers/implementations/macs/ state no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

  • webcrypto: The Web Cryptography API (W3C Recommendation, 2017) states no constant-time property of digest, sign or deriveBits; each JavaScript runtime’s implementation decides, and webcpp reads none.

macs::hmac<digests::keccak_224> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::keccak_256> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::keccak_384> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::keccak_512> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::sm3> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::streebog_256> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::streebog_512> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::whirlpool> has no default backend: the call names one of its backends, as its second template argument (The default backend).

macs::hmac<digests::skein_512> has no default backend: the call names one of its backends, as its second template argument (The default backend).

The default of macs::hmac<digests::md5>, macs::hmac<digests::sha1>, macs::hmac<digests::sha2_224> and macs::hmac<digests::sha2_384>: hash2 on every target, whatever the program links; bearssl, botan, openssl only where the call names it, as its second template argument (The default backend).

The default of macs::hmac<digests::sha2_256> and macs::hmac<digests::sha2_512>: hash2 on every target, whatever the program links; bearssl, botan, openssl, sodium only where the call names it, as its second template argument (The default backend).

The default of macs::hmac<digests::sha2_512_224>: hash2 on every target, whatever the program links; openssl only where the call names it, as its second template argument (The default backend).

The default of macs::hmac<digests::sha2_512_256>, macs::hmac<digests::sha3_224>, macs::hmac<digests::sha3_256>, macs::hmac<digests::sha3_384>, macs::hmac<digests::sha3_512>, macs::hmac<digests::ripemd_160>, macs::hmac<digests::blake2b> and macs::hmac<digests::blake2s_256>: hash2 on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

webcrypto serves the asynchronous family alone, on Emscripten, where the type of its asynchronous call names it (WebCrypto in the browser).

SipHash

SipHash (Aumasson and Bernstein, 2012) is a keyed hash made for one job: protecting hash tables whose keys come from someone else. A hash table puts each key in a bucket chosen by its hash; with an unkeyed hash, FNV or MurmurHash or xxHash, anyone can compute in advance thousands of keys that fall in one bucket, send them as the names in a form, the fields of a JSON document or the ids of peers, and turn every lookup into a scan of a long list: a denial of service called hash flooding. With SipHash keyed by a secret random key per process, the attacker cannot predict the buckets. Python’s dictionaries, Rust’s HashMap and the Linux kernel use it for that reason. siphash_64 is SipHash-2-4 with a 16-byte key and a 64-bit result; siphash_32 is HalfSipHash-2-4, the 32-bit variant for small machines, with an 8-byte key and a 32-bit result.

This section adapts the guidance of libsodium’s documentation on short-input hashing (hashing/short-input_hashing.md of libsodium-doc, ISC licence, kept in NOTICE.md), in hash’s own terms.

#include <webcpp/crypto/random_device.hpp>
#include <webcpp/hash/algorithms.hpp>

#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <string>
#include <unordered_set>

namespace {

// A hasher for a hash table of ids that arrive from the network, keyed with a secret.
struct peer_hasher {
    std::array<std::uint8_t, 16> key;

    std::size_t operator()(std::string const& id) const {
        webcpp::hash::siphash_64 h(key.data(), key.size());
        h.update(id.data(), id.size());
        return static_cast<std::size_t>(h.result());
    }
};

}  // namespace

int main() {
    std::array<std::uint8_t, 16> key{};
    std::array<std::uint8_t, 15> message{};
    for (std::size_t i = 0; i < key.size(); ++i) {
        key[i] = static_cast<std::uint8_t>(i);
    }
    for (std::size_t i = 0; i < message.size(); ++i) {
        message[i] = static_cast<std::uint8_t>(i);
    }

    // The 64-bit hash takes a 16-byte key.
    webcpp::hash::siphash_64 wide(key.data(), key.size());
    wide.update(message.data(), message.size());
    std::uint64_t const wide_value = wide.result();

    // The 32-bit hash takes an 8-byte key: HalfSipHash, for the targets where 32-bit words are
    // the natural size.
    webcpp::hash::siphash_32 narrow(key.data(), 8);
    narrow.update(message.data(), message.size());
    std::uint32_t const narrow_value = narrow.result();

    std::cout << std::hex << std::setfill('0');
    std::cout << "siphash_64 " << std::setw(16) << wide_value << '\n';
    std::cout << "siphash_32 " << std::setw(8) << narrow_value << '\n';
    std::cout << std::dec;
    if (wide_value != 0xa129ca6149be45e5ULL || narrow_value != 0x972bfe74U) {
        return 1;
    }

    // The use. A table keyed by an unkeyed hash (FNV, xxHash) lets an attacker who chooses the
    // keys choose keys that all collide, and the table degrades to a list: hash flooding. A
    // random key, secret and different in every process, takes that choice away from the attacker.
    peer_hasher hasher{};
    auto const filled = webcpp::crypto::random_device{}.fill(hasher.key);
    if (!filled) {
        std::cerr << filled.error().message() << '\n';
        return 1;
    }
    std::unordered_set<std::string, peer_hasher> peers(8, hasher);
    peers.insert("peer-a");
    peers.insert("peer-b");
    peers.insert("peer-c");
    std::cout << "peers " << peers.size() << '\n';
}
siphash_64 a129ca6149be45e5
siphash_32 972bfe74
peers 3

Pitfalls.

  • The key is the protection. A key that an attacker can read or guess (a constant, a seed from the time) gives no protection at all; draw it from webcpp::crypto::random_device when the process starts, and keep it secret.

  • Not a digest and not a MAC for messages. 64 bits are too few to resist collisions found on purpose, and 32 bits far too few: SipHash protects the shape of a table, not the integrity of data. Use HMAC (HMAC) for messages.

  • Use every bit when choosing a bucket. A table that keeps only the low bits of the hash, or reduces it by a power of two, throws away part of what the key protects; a prime number of buckets, or a multiply-and-shift reduction, keeps them.

Table 19. Who implements siphash_32 to macs::siphash_2_4x, 4 names (SipHash-2-4 (siphash_64), HalfSipHash-2-4 (siphash_32) and SipHash-2-4 with a 128-bit output (libsodium’s siphashx24), Aumasson and Bernstein)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

siphash_32

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

siphash_64

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::siphash_2_4

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::siphash_2_4

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

macs::siphash_2_4

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::siphash_2_4

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::siphash_2_4x

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

macs::siphash_2_4x

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/message_auth_codes.rst states no constant-time property of this MAC, and its source (src/lib/mac/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man3/EVP_MAC.pod, doc/man7/EVP_MAC-HMAC.pod, EVP_MAC-KMAC.pod, EVP_MAC-BLAKE2.pod, EVP_MAC-Siphash.pod and providers/implementations/macs/ state no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

The default of macs::siphash_2_4: hash2 on every target, whatever the program links; botan, openssl, sodium only where the call names it, as its second template argument (The default backend).

The default of macs::siphash_2_4x: sodium on every target, whatever the program links; openssl only where the call names it, as its second template argument (The default backend).

KMAC

KMAC (NIST SP 800-185, section 4) is a MAC built on cSHAKE, the SHA-3 family’s own: where HMAC wraps a hash twice around the key to protect it from the hash’s structure, KMAC needs no wrapping, since SHA-3’s sponge already keeps its state hidden. It takes a key, the message and a customisation string that separates one application’s tags from another’s under the same key, and gives a tag of any length; NIST’s key derivation (SP 800-56C) uses it too. Like TupleHash, it has a fixed-length form, which encodes the tag’s length, and an XOF form, KMACXOF, which does not. macs::kmac_128 and macs::kmac_256 are tags of mac (A MAC in one call: mac), on backends::xkcp, their default; a program links /third_party//xkcp. backends::openssl has them too, named in the call, within OpenSSL’s narrower limits (The MACs of OpenSSL: KMAC, keyed BLAKE2, SipHash and HMAC).

#include "hex.hpp"

#include <webcpp/hash/mac.hpp>
#include <webcpp/secure/constant_time_equal.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using webcpp::hash::macs::kmac_128;

    auto const key =
        example::from_hex("404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f");
    auto const message = example::from_hex("00010203");
    auto const application = example::bytes("My Tagged Application");
    std::array<std::uint8_t, 32> tag{};
    if (!hash::mac<kmac_128>(tag, key, message, {.customisation = application})) {
        return 1;
    }
    std::cout << "kmac_128 " << example::hex(tag) << '\n';
    if (example::hex(tag) != "3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5") {
        return 1;
    }

    // The receiver computes the tag again and compares it in constant time, never with ==.
    std::array<std::uint8_t, 32> expected{};
    bool const genuine =
        hash::mac<kmac_128>(expected, key, message, {.customisation = application}).has_value() &&
        webcpp::secure::constant_time_equal(expected, tag);
    std::cout << "genuine: " << (genuine ? "yes" : "no") << '\n';

    // KMACXOF128: the same inputs, another tag.
    std::array<std::uint8_t, 32> xof{};
    if (!hash::mac<kmac_128>(xof, key, message, {.customisation = application, .xof = true})) {
        return 1;
    }
    std::cout << "kmacxof_128 " << example::hex(xof) << '\n';
    if (example::hex(xof) != "31a44527b4ed9f5c6101d11de6d26f0620aa5c341def41299657fe9df1a3b16c") {
        return 1;
    }
    return genuine ? 0 : 1;
}
kmac_128 3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5
genuine: yes
kmacxof_128 31a44527b4ed9f5c6101d11de6d26f0620aa5c341def41299657fe9df1a3b16c

Pitfalls.

  • Compare with webcpp::secure::constant_time_equal. As for every tag (HMAC).

  • The key sets the strength. SP 800-185 (section 8.4.1) forbids a key shorter than the security the application needs: 16 bytes for KMAC128, 32 for KMAC256. mac takes any key, the empty one included, as the standard defines it; choose its size.

  • At least 4 bytes of tag. SP 800-185 (section 8.4.2) forbids a tag of fewer than 32 bits and asks for a careful analysis below 64; mac refuses a tag under 4 bytes with invalid_output_size. Prefer 16 bytes or more.

  • The form is part of the tag. KMAC128 and KMACXOF128 of the same inputs differ, and a fixed-length tag of 16 bytes is not the start of one of 32: the receiver uses the sender’s form and length.

  • Botan’s KMAC is narrower. backends::botan, named in the call, takes a key of at most 192 bytes and has no KMACXOF: mac answers a longer key or .xof = true with unsupported_by_backend before Botan is called (The MACs of Botan: HMAC over its digests, KMAC, SipHash and keyed BLAKE2b). A key of 16 or 32 random bytes, as SP 800-185 asks, is far below that limit.

Table 20. Who implements macs::kmac_128, macs::kmac_256 (NIST SP 800-185 (KMAC, KMACXOF))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

macs::kmac_128

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

macs::kmac_128

openssl (partial: a key under 4 or over 512 bytes, a customisation over 512 bytes, or a tag over 2,097,151 bytes: OpenSSL’s KMAC limits (kmac_prov.c))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::kmac_128

botan (with exceptions only) (partial: a key over 192 bytes, or the XOF form (xof): Botan’s KMAC limits its key to 192 bytes and has no KMACXOF (kmac.cpp))

/third_party//botan

native, emscripten

-

not stated

macs::kmac_256

xkcp

/third_party//xkcp

native, wasip2, wasip3, emscripten

-

not stated

macs::kmac_256

openssl (partial: a key under 4 or over 512 bytes, a customisation over 512 bytes, or a tag over 2,097,151 bytes: OpenSSL’s KMAC limits (kmac_prov.c))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::kmac_256

botan (with exceptions only) (partial: a key over 192 bytes, or the XOF form (xof): Botan’s KMAC limits its key to 192 bytes and has no KMACXOF (kmac.cpp))

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/message_auth_codes.rst states no constant-time property of this MAC, and its source (src/lib/mac/) none.

  • openssl: OpenSSL 3.5.9: doc/man3/EVP_MAC.pod, doc/man7/EVP_MAC-HMAC.pod, EVP_MAC-KMAC.pod, EVP_MAC-BLAKE2.pod, EVP_MAC-Siphash.pod and providers/implementations/macs/ state no constant-time property.

  • xkcp: XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high/Keccak (KeccakSponge, FIPS202/KeccakHash, SP800-185) state no constant-time property.

The default of macs::kmac_128 and macs::kmac_256: xkcp on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

A MAC in one call: mac

mac computes the tag of a message under a key in one call, through a tag of webcpp::hash::macs, as macs::hmac<digests::sha2_256>, HMAC over the digest digests::sha2_256, and a backend: the tag’s default, or the one the call names. Its guards are the same on every backend: an HMAC tag is 10 bytes up to the digest’s size, a shorter one being the digest cut (RFC 2104, section 5); a key of a size the MAC does not take is invalid_key_size. The Hash2 aliases of HMAC stay the way to feed a message in pieces.

#include "hex.hpp"

#include <webcpp/hash/mac.hpp>
#include <webcpp/secure/constant_time_equal.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <vector>

int main() {
    namespace hash = webcpp::hash;
    using hmac_sha256 = hash::macs::hmac<hash::digests::sha2_256>;

    auto const key = example::bytes("Jefe");
    auto const message = example::bytes("what do ya want for nothing?");
    std::array<std::uint8_t, 32> tag{};
    if (!hash::mac<hmac_sha256>(tag, key, message)) {
        return 1;
    }
    std::cout << "mac " << example::hex(tag) << '\n';
    if (example::hex(tag) != "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843") {
        return 1;
    }

    // The receiver computes the tag again and compares it in constant time, never with ==.
    std::array<std::uint8_t, 32> expected{};
    bool const genuine = hash::mac<hmac_sha256>(expected, key, message).has_value() &&
                         webcpp::secure::constant_time_equal(expected, tag);
    std::cout << "genuine: " << (genuine ? "yes" : "no") << '\n';

    // A tag cut to 16 bytes is the digest's first 16 (RFC 2104, section 5); shorter than 10 is
    // refused.
    std::vector<std::uint8_t> const key_5(20, 0x0c);
    std::array<std::uint8_t, 16> cut{};
    if (!hash::mac<hmac_sha256>(cut, key_5, example::bytes("Test With Truncation"))) {
        return 1;
    }
    std::cout << "cut to 16 " << example::hex(cut) << '\n';
    std::array<std::uint8_t, 8> too_short{};
    std::cout << "8-byte tag: " << hash::mac<hmac_sha256>(too_short, key, message).error().message()
              << '\n';
    return genuine ? 0 : 1;
}
mac 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
genuine: yes
cut to 16 a3b6167473100ee06e0c796c2955552b
8-byte tag: the output is not of a size the function produces

Pitfalls.

  • Compare with webcpp::secure::constant_time_equal. As for every tag (HMAC).

  • A cut tag is a weaker tag. Ten bytes, 80 bits, is the shortest mac gives; keep the whole digest unless a protocol fixes a shorter tag.

  • The tag’s name is the digest’s. macs::hmac<digests::sha2_512> cut to 32 bytes is not HMAC over SHA-512/256 (macs::hmac<digests::sha2_512_256>): the two give different tags.

  • BearSSL’s HMAC is reached by name. backends::bearssl has HMAC over MD5, SHA-1 and the four SHA-2s it has, any key and any tag mac accepts, but is never a default: name it, as mac<macs::hmac<digests::sha2_256>, backends::bearssl>, and link /third_party//bearssl.

  • Keyed BLAKE2s on backends::hash2 is 32 bytes. macs::blake2s_mac takes a tag of 1 to 32 bytes, but BLAKE2s’s output size is a parameter of the hash, not a cut: backends::hash2 (Boost.Hash2’s keyed blake2s_256) answers unsupported_by_backend to a shorter tag. macs::siphash_2_4 on it is SipHash-2-4 whole: a 16-byte key and an 8-byte tag.

SipHash on libsodium: macs::siphash_2_4x

mac computes SipHash through two tags: macs::siphash_2_4, SipHash-2-4 with its 8-byte result, on backends::hash2 (Boost.Hash2’s siphash_64, the default) or on backends::sodium (libsodium’s crypto_shorthash_siphash24), which give the same bytes; and macs::siphash_2_4x, the same rounds with a 16-byte result (the SipHash reference implementation’s 128-bit output, libsodium’s crypto_shorthash_siphashx24), on backends::sodium alone, its default. Both take a 16-byte key. The 16-byte result makes collisions between honest keys rare enough for a table or a filter of billions of entries, or for a short identifier keyed against flooding, where 64 bits would collide; it is still a hash for tables, not a MAC for messages (SipHash).

#include "hex.hpp"

#include <webcpp/hash/mac.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    namespace macs = hash::macs;

    auto const key = example::from_hex("000102030405060708090a0b0c0d0e0f");
    auto const message = example::bytes("user:alice");

    std::array<std::uint8_t, 8> on_sodium{};
    std::array<std::uint8_t, 8> on_hash2{};
    if (!hash::mac<macs::siphash_2_4, hash::backends::sodium>(on_sodium, key, message) ||
        !hash::mac<macs::siphash_2_4>(on_hash2, key, message)) {
        return 1;
    }
    std::cout << "siphash_2_4 " << example::hex(on_sodium) << '\n';
    std::cout << "the same on hash2: " << (on_sodium == on_hash2 ? "yes" : "no") << '\n';

    // SipHash-2-4x: 16 bytes, another value than SipHash-2-4's, not two of its tags side by side.
    std::array<std::uint8_t, 16> wide{};
    if (!hash::mac<macs::siphash_2_4x>(wide, key, message)) {
        return 1;
    }
    std::cout << "siphash_2_4x " << example::hex(wide) << '\n';

    // The key is 16 bytes, always.
    std::array<std::uint8_t, 8> const short_key{};
    std::cout << "8-byte key: "
              << hash::mac<macs::siphash_2_4x>(wide, short_key, message).error().message() << '\n';
    return on_sodium == on_hash2 ? 0 : 1;
}
siphash_2_4 9737f8b03db06d4b
the same on hash2: yes
siphash_2_4x e0f98248d7904e01892c15a501078e28
8-byte key: the key is not of a size the function accepts

Pitfalls.

  • The pitfalls of SipHash hold: a random key per process, and not a MAC for messages: use HMAC there.

  • SipHash-2-4x is not two SipHash-2-4 tags. Its 16 bytes are another function’s output, and its first 8 bytes are not SipHash-2-4’s tag: a program that must agree with another names the same tag.

  • The tag is written little-endian. mac writes SipHash-2-4’s 64-bit result as 8 bytes, least significant first, as the reference implementation and libsodium do; the result() of siphash_64 is the number itself.

HMAC on libsodium

mac computes HMAC over SHA-256 and SHA-512 on backends::sodium too, with libsodium’s crypto_auth_hmacsha256 and crypto_auth_hmacsha512 functions, named in the call: the same tags as the default, backends::hash2, for a program that already links libsodium or that wants its implementation. libsodium names a third HMAC, crypto_auth_hmacsha512256, "HMAC-SHA-512-256": it is HMAC-SHA-512 cut to 32 bytes, which mac over digests::sha2_512 gives with a 32-byte output, and not HMAC over SHA-512/256 (macs::hmac<digests::sha2_512_256>), a different function that libsodium does not have.

#include "hex.hpp"

#include <webcpp/hash/mac.hpp>
#include <webcpp/secure/constant_time_equal.hpp>

#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    namespace digests = webcpp::hash::digests;
    using webcpp::hash::backends::sodium;
    using webcpp::hash::macs::hmac;

    // A 32-byte key, as webcpp::crypto::random_device gives it (fixed here, for the output).
    std::array<std::uint8_t, 32> key{};
    for (std::size_t i = 0; i < key.size(); ++i) {
        key[i] = static_cast<std::uint8_t>(i);
    }
    auto const message = example::bytes("hello, world");

    std::array<std::uint8_t, 32> tag{};
    if (!hash::mac<hmac<digests::sha2_256>, sodium>(tag, key, message)) {
        return 1;
    }
    std::cout << "HMAC-SHA-256 " << example::hex(tag) << '\n';

    // The receiver computes the tag again and compares it in constant time.
    std::array<std::uint8_t, 32> again{};
    bool const genuine = hash::mac<hmac<digests::sha2_256>, sodium>(again, key, message) &&
                         webcpp::secure::constant_time_equal(again, tag);
    std::cout << "genuine: " << (genuine ? "yes" : "no") << '\n';

    // libsodium's crypto_auth_hmacsha512256 is HMAC-SHA-512 cut to 32 bytes: the same tag, with a
    // 32-byte output.
    std::array<std::uint8_t, 32> cut{};
    if (!hash::mac<hmac<digests::sha2_512>, sodium>(cut, key, message)) {
        return 1;
    }
    std::cout << "HMAC-SHA-512 cut to 32 " << example::hex(cut) << '\n';

    // HMAC over SHA-512/256 is another function, which libsodium does not have.
    std::array<std::uint8_t, 32> over_512_256{};
    if (!hash::mac<hmac<digests::sha2_512_256>>(over_512_256, key, message)) {
        return 1;
    }
    std::cout << "HMAC over SHA-512/256 " << example::hex(over_512_256) << '\n';
    return genuine ? 0 : 1;
}
HMAC-SHA-256 fe751971276e8bc03a398380b60d4cbfcde5da9a4a834f610fd82bff4daa3257
genuine: yes
HMAC-SHA-512 cut to 32 d8898906eb374195bd7acd21aad5017aedd46d80e5355399c954800c3c5f622c
HMAC over SHA-512/256 1d28354e16fb041be89d848b9f14c1c5188c332d68d95fc0004ed91af7f75619

Pitfalls.

  • The pitfalls of HMAC hold: compare tags with webcpp::secure::constant_time_equal, and use a random key, not a password.

  • "HMAC-SHA-512-256" has two meanings. A program that must agree with libsodium’s crypto_auth_hmacsha512256 names macs::hmac<digests::sha2_512> and a 32-byte output; one that follows a standard naming HMAC over SHA-512/256 names macs::hmac<digests::sha2_512_256>. The two give different tags.

  • A key of any size. libsodium’s one-call functions take a 32-byte key alone; mac on backends::sodium takes a key of any size, hashed first when it is longer than the block, as RFC 2104 says and as every other backend does.

Keyed BLAKE2b on libsodium: macs::blake2b_mac

Keyed BLAKE2b (RFC 7693, section 2.5) is a MAC by itself: the key goes into the hash’s first block, so it needs neither HMAC’s second pass nor its construction. mac<macs::blake2b_mac> computes it on backends::sodium, its default (libsodium’s keyed crypto_generichash_blake2b), with a key of 1 to 64 bytes and a tag of 1 to 64 bytes; a program links /third_party//sodium, on every target. backends::openssl gives the same tags, named in the call (The MACs of OpenSSL: KMAC, keyed BLAKE2, SipHash and HMAC).

#include "hex.hpp"

#include <webcpp/hash/mac.hpp>
#include <webcpp/secure/constant_time_equal.hpp>

#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>

int main() {
    namespace hash = webcpp::hash;
    using webcpp::hash::macs::blake2b_mac;

    // A 32-byte key, as webcpp::crypto::random_device gives it (fixed here, for the output).
    std::array<std::uint8_t, 32> key{};
    for (std::size_t i = 0; i < key.size(); ++i) {
        key[i] = static_cast<std::uint8_t>(i);
    }
    auto const message = example::bytes("order:42,amount:10.00");

    // The default backend of macs::blake2b_mac is backends::sodium: link /third_party//sodium.
    std::array<std::uint8_t, 32> tag{};
    if (!hash::mac<blake2b_mac>(tag, key, message)) {
        return 1;
    }
    std::cout << "BLAKE2b-256 keyed " << example::hex(tag) << '\n';

    // The receiver computes the tag again and compares it in constant time.
    std::array<std::uint8_t, 32> again{};
    bool const genuine = hash::mac<blake2b_mac>(again, key, message) &&
                         webcpp::secure::constant_time_equal(again, tag);
    std::cout << "genuine: " << (genuine ? "yes" : "no") << '\n';

    // The tag's size is a parameter of the hash: a 16-byte tag is not the 32-byte one cut.
    std::array<std::uint8_t, 16> short_tag{};
    if (!hash::mac<blake2b_mac>(short_tag, key, message)) {
        return 1;
    }
    std::cout << "BLAKE2b-128 keyed " << example::hex(short_tag) << '\n';

    // An empty key is the unkeyed hash, a digest (digests::blake2b), not a MAC.
    std::cout
        << "empty key: "
        << hash::mac<blake2b_mac>(tag, std::span<std::uint8_t const>{}, message).error().message()
        << '\n';
    return genuine ? 0 : 1;
}
BLAKE2b-256 keyed f857e744317936fbea0cf4b2354ca9fb0c48cf6dc66b48b07facec64d943c712
genuine: yes
BLAKE2b-128 keyed dcb107ed916a53063ae35186bfb06720
empty key: the key is not of a size the function accepts

Pitfalls.

  • Compare with webcpp::secure::constant_time_equal. As for every tag (HMAC).

  • The length is a parameter, not a cut. The tag’s size goes into the hash: a 16-byte tag is not the first 16 bytes of a 32-byte one, and the receiver uses the sender’s size.

  • Draw a key of 32 random bytes. mac takes every size RFC 7693 gives, from 1 byte (libsodium’s 16-byte minimums are advice its functions do not check), but the key sets the strength: draw 32 bytes from webcpp::crypto::random_device. An empty key is invalid_key_size: unkeyed BLAKE2b is a digest (BLAKE2b with a key, a salt, a personalisation and a length).

  • libsodium’s state is wiped. mac keeps libsodium’s BLAKE2b state, which holds the key, in its own frame and wipes it before it returns.

Table 21. Who implements macs::blake2b_mac, macs::blake2s_mac (RFC 7693, keyed (section 2.5))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

macs::blake2b_mac

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

macs::blake2b_mac

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

macs::blake2b_mac

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

macs::blake2s_mac

hash2 (partial: a tag under 32 bytes: BLAKE2s’s output size is a parameter of the hash, and Boost.Hash2’s keyed blake2s_256 has 32 bytes alone)

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

macs::blake2s_mac

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/message_auth_codes.rst states no constant-time property of this MAC, and its source (src/lib/mac/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man3/EVP_MAC.pod, doc/man7/EVP_MAC-HMAC.pod, EVP_MAC-KMAC.pod, EVP_MAC-BLAKE2.pod, EVP_MAC-Siphash.pod and providers/implementations/macs/ state no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

The default of macs::blake2b_mac: sodium on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

The default of macs::blake2s_mac: hash2 on every target, whatever the program links; openssl only where the call names it, as its second template argument (The default backend).

The MACs of OpenSSL: KMAC, keyed BLAKE2, SipHash and HMAC

backends::openssl computes every tag of webcpp::hash::macs through OpenSSL 3.5.9’s EVP_MAC, on native, wasip2 and wasip3. It is never a default (design D34): a call names it. Its tags are HMAC over every digest of a fixed size it has but MD5-SHA1, over which no standard defines an HMAC, macs::hmac<digests::keccak_256> and macs::hmac<digests::sm3> among them, which no other backend has; KMAC128 and KMAC256 (NIST SP 800-185, section 4), macs::kmac_128 and macs::kmac_256, in their fixed-length and XOF forms, with a customisation string; keyed BLAKE2b and BLAKE2s (RFC 7693), macs::blake2b_mac and macs::blake2s_mac, at every tag size; and SipHash-2-4 with an 8-byte or a 16-byte tag. KMAC encodes the tag’s length in its fixed-length form, so that two tags of different sizes are unrelated; its XOF form (.xof = true) encodes none, and a shorter tag is the start of a longer.

#include "hex.hpp"

#include <webcpp/hash/mac.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <numeric>

int main() {
    namespace hash = webcpp::hash;
    namespace macs = hash::macs;
    using hash::backends::openssl;

    // KMAC128 with a customisation string: NIST's sample #2.
    auto const key =
        example::from_hex("404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f");
    auto const data = example::from_hex("00010203");
    std::array<std::uint8_t, 32> kmac{};
    if (!hash::mac<macs::kmac_128, openssl>(
            kmac, key, data, {.customisation = example::bytes("My Tagged Application")})) {
        return 1;
    }
    std::cout << "kmac_128 " << example::hex(kmac) << '\n';
    if (example::hex(kmac) != "3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5") {
        return 1;
    }

    // The XOF form encodes no length: its 16 bytes are the start of its 32.
    std::array<std::uint8_t, 32> long_xof{};
    std::array<std::uint8_t, 16> short_xof{};
    if (!hash::mac<macs::kmac_128, openssl>(long_xof, key, data, {.xof = true}) ||
        !hash::mac<macs::kmac_128, openssl>(short_xof, key, data, {.xof = true})) {
        return 1;
    }
    bool const prefix = std::equal(short_xof.begin(), short_xof.end(), long_xof.begin());
    std::cout << "kmacxof_128 16 bytes are the start of 32: " << (prefix ? "yes" : "no") << '\n';

    // HMAC over SM3, which has no default backend.
    std::array<std::uint8_t, 32> hmac_sm3{};
    if (!hash::mac<macs::hmac<hash::digests::sm3>, openssl>(
            hmac_sm3, example::bytes("Jefe"), example::bytes("what do ya want for nothing?"))) {
        return 1;
    }
    std::cout << "hmac sm3 " << example::hex(hmac_sm3) << '\n';

    // Keyed BLAKE2b of 32 bytes, its size a parameter of the hash, not a cut.
    std::array<std::uint8_t, 32> blake2b_key{};
    std::iota(blake2b_key.begin(), blake2b_key.end(), std::uint8_t{0});
    std::array<std::uint8_t, 32> blake2b{};
    if (!hash::mac<macs::blake2b_mac, openssl>(blake2b, blake2b_key, example::bytes("abc"))) {
        return 1;
    }
    std::cout << "blake2b_mac " << example::hex(blake2b) << '\n';

    // SipHash-2-4 with a 16-byte tag.
    std::array<std::uint8_t, 16> siphash_key{};
    std::iota(siphash_key.begin(), siphash_key.end(), std::uint8_t{0});
    std::array<std::uint8_t, 16> siphash{};
    if (!hash::mac<macs::siphash_2_4x, openssl>(siphash, siphash_key, {})) {
        return 1;
    }
    std::cout << "siphash_2_4x " << example::hex(siphash) << '\n';

    // OpenSSL's KMAC takes a key of 4 to 512 bytes, narrower than SP 800-185.
    std::array<std::uint8_t, 3> const short_key{1, 2, 3};
    std::cout << "3-byte KMAC key: "
              << hash::mac<macs::kmac_128, openssl>(kmac, short_key, data).error().message()
              << '\n';
    return prefix ? 0 : 1;
}
kmac_128 3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5
kmacxof_128 16 bytes are the start of 32: yes
hmac sm3 2e87f1d16862e6d964b50a5200bf2b10b764faa9680a296a2405f24bec39f882
blake2b_mac d63a32d3e44738d7907f964316c241adaba0abfeabc32349677578a15a203f7f
siphash_2_4x a3817f04ba25a8e66df67214c7550293
3-byte KMAC key: the backend does not take this parameter; name a backend that does

Pitfalls.

  • OpenSSL’s KMAC is narrower than SP 800-185. It takes a key of 4 to 512 bytes, a customisation of at most 512 bytes and a tag of at most 2,097,151 bytes, in either form; mac answers any other unsupported_by_backend before OpenSSL is called. A tag under 4 bytes is invalid_output_size on every backend: SP 800-185, section 8.4.2, forbids a MAC of fewer than 32 bits.

  • The customisation separates applications, the key keeps the secret. Two programs that share a key and differ in their customisation string get unrelated tags; the string itself is not secret.

  • Keyed BLAKE2 takes a key of at least one byte. An empty key is invalid_key_size (RFC 7693’s keyed mode has a key of 1 to 64 bytes, 1 to 32 for BLAKE2s); unkeyed BLAKE2 is a digest (BLAKE2b with a key, a salt, a personalisation and a length).

  • Each call allocates through OpenSSL. The MAC and its context are fetched, made and freed in the call (EVP_MAC_CTX_new), as for every function of this backend (Allocation); OpenSSL documents that it frees them, not that it clears them. Its HMAC, KMAC and BLAKE2 MACs clear their copy of the key when freed (the BLAKE2 MACs’ first block, which holds the key too, only once the tag is computed, not when a call fails before); its SipHash frees its keyed state without clearing it.

  • An HMAC key is at most INT_MAX bytes on OpenSSL, which takes its length as an int; a longer one is unsupported_by_backend.

The backends of each tag are in the tables of KMAC, Keyed BLAKE2b on libsodium: macs::blake2b_mac, SipHash and HMAC.

The MACs of Botan: HMAC over its digests, KMAC, SipHash and keyed BLAKE2b

backends::botan computes the tags of webcpp::hash::macs through Botan 3.14.1’s MessageAuthenticationCode, natively and on Emscripten, in a program built with exceptions that links /third_party//botan. It is never a default (design D34): a call names it. Its tags are HMAC over every digest of a fixed size it has, 21 of them, among which macs::hmac<digests::streebog_256>, streebog_512, whirlpool and skein_512, which no other backend has (HMAC over Streebog is RFC 7836’s HMAC_GOSTR3411_2012_256 and _512, the MAC of the Russian standards); KMAC128 and KMAC256 in their fixed-length form, with a customisation string; SipHash-2-4 with its 8-byte tag; and keyed BLAKE2b (macs::blake2b_mac) at every tag size. It has no HMAC over SHA-512/224, no SipHash-2-4x and no keyed BLAKE2s.

#include "hex.hpp"

#include <webcpp/hash/mac.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <vector>

int main() {
    namespace hash = webcpp::hash;
    namespace macs = hash::macs;
    using hash::backends::botan;

    // HMAC_GOSTR3411_2012_256 of RFC 7836.
    auto const gost_key =
        example::from_hex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
    std::array<std::uint8_t, 32> gost{};
    if (!hash::mac<macs::hmac<hash::digests::streebog_256>, botan>(
            gost, gost_key, example::from_hex("0126bdb87800af214341456563780100"))) {
        return 1;
    }
    std::cout << "hmac streebog_256 " << example::hex(gost) << '\n';
    if (example::hex(gost) != "a1aa5f7de402d7b3d323f2991c8d4534013137010a83754fd0af6d7cd4922ed9") {
        return 1;
    }

    // KMAC128 with a customisation string: NIST's sample #2.
    auto const key =
        example::from_hex("404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f");
    auto const data = example::from_hex("00010203");
    std::array<std::uint8_t, 32> kmac{};
    if (!hash::mac<macs::kmac_128, botan>(
            kmac, key, data, {.customisation = example::bytes("My Tagged Application")})) {
        return 1;
    }
    std::cout << "kmac_128 " << example::hex(kmac) << '\n';

    // A key longer than Botan's HMAC takes is hashed first, as RFC 2104 says: the same tag.
    std::vector<std::uint8_t> const long_key(10000, 0x0b);
    std::array<std::uint8_t, 32> on_botan{};
    std::array<std::uint8_t, 32> on_hash2{};
    using hmac_sha256 = macs::hmac<hash::digests::sha2_256>;
    if (!hash::mac<hmac_sha256, botan>(on_botan, long_key, data) ||
        !hash::mac<hmac_sha256, hash::backends::hash2>(on_hash2, long_key, data)) {
        return 1;
    }
    std::cout << "10,000-byte key: " << (on_botan == on_hash2 ? "same" : "different") << '\n';

    // Botan's KMAC takes a key of at most 192 bytes, narrower than SP 800-185.
    std::vector<std::uint8_t> const kmac_key(193, 0x40);
    std::cout << "193-byte KMAC key: "
              << hash::mac<macs::kmac_128, botan>(kmac, kmac_key, data).error().message() << '\n';
    return on_botan == on_hash2 ? 0 : 1;
}
hmac streebog_256 a1aa5f7de402d7b3d323f2991c8d4534013137010a83754fd0af6d7cd4922ed9
kmac_128 3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5
10,000-byte key: same
193-byte KMAC key: the backend does not take this parameter; name a backend that does

Pitfalls.

  • Botan’s KMAC takes a key of at most 192 bytes and no XOF form. SP 800-185 allows any key; mac answers a longer one, and .xof = true, with unsupported_by_backend before Botan is called. KMAC’s other limits are the family’s: a tag of 4 bytes or more.

  • A key past Botan’s HMAC limit is hashed first. Botan’s HMAC takes a key of at most 8,192 bytes; hash hashes a longer key with the same digest before keying it, as RFC 2104 does with every key longer than the block, so the tag is every other backend’s, as the example shows.

  • Botan reports its failures by throwing. hash catches every exception at the boundary of each call: an allocation that fails is errc::not_enough_memory, anything else backend_failure, the output zeroed. A program built without exceptions has no backends::botan (When the build stops).

  • Each call allocates through Botan. Botan makes its MAC object with operator new and the buffers of its keyed state with the C library’s calloc in each call, outside any allocator of the program; hash clears and frees the object before the call returns, and Botan overwrites each buffer before freeing it (Allocation).

  • Streebog’s and Whirlpool’s tables. Their HMACs run the same code as the digests, which indexes tables by the data, here the key’s blocks: Botan’s documentation warns of cache timing attacks (Streebog, Whirlpool).

Key derivation

A key derivation function (KDF) turns secret material that is not fit to be a key, or is fit to be one key only, into as many keys as an application needs. Two people who agree on a shared secret by Diffie-Hellman get a point of an elliptic curve, whose bytes are not uniformly random; a password manager has one master key and needs a key per vault, per device, per purpose. Using the same key for two purposes, encryption and authentication for example, can let an attack on one break the other; using a raw Diffie-Hellman output as an AES key wastes part of its strength. HKDF fixes both: it concentrates the entropy of its input into a pseudorandom key, then expands it into independent keys, one per label. BLAKE2b subkeys, libsodium’s crypto_kdf, split a master key that is already uniformly random into keys numbered by id. PBKDF2 is the older answer to another problem, a key from a password, which Argon2id now answers better (Password hashing). Standards and formats that predate HKDF, or were written for NIST’s validations, name their own derivations: Kerberos and NIST SP 800-108’s KBKDF, JOSE’s ECDH-ES and NIST SP 800-56C’s one-step KDF, ECIES and ANSI X9.63’s KDF (Key derivations of standards).

The key derivations are the functions of hash that run on a backend, a C library or Boost.Hash2, that the program names or leaves to the default, backends::hash2 (The default backend); BLAKE2b subkeys run on libsodium alone, and the key derivations of standards on OpenSSL or Botan, which are never a default: the call names one (Key derivation on Botan). Each backend gives the same bytes for the same inputs: the tests check them against each other on random inputs on every target.

Every key derivation computes on a secret, and sets DIT (data-independent timing) around each call, on every synchronous backend, on 64-bit ARM under Apple’s systems and Linux where the CPU has FEAT_DIT, leaving the thread’s DIT as it found it (Data-independent timing (DIT)): hkdf_extract, hkdf_expand, hkdf (each also over byte pieces), pbkdf2, blake2b_subkey, kbkdf, sskdf and x963kdf. hkdf enters one guard and runs the whole derivation inside it, and HKDF and PBKDF2 on backends::hash2 run Boost.Hash2’s hmac there too.

Table 22. What each of "Key derivation" is
Name Output Security Standard Status In the browser (WebCrypto)

hkdf_extract

the hmac’s digest size

that of the hmac, given input with enough entropy

RFC 5869

recommended

HKDF (whole only)

hkdf_expand

1 to 255 times the digest size

that of the hmac

RFC 5869

recommended

HKDF (whole only)

hkdf

1 to 255 times the digest size

that of the hmac, given input with enough entropy

RFC 5869

recommended

HKDF

pbkdf2

1 to (2^32 - 1) times the digest size

each guess costs the iterations; no defence against GPUs beyond that

RFC 8018

where a standard names it

PBKDF2

blake2b_subkey

16 to 64 bytes

that of the master key, which must be 32 uniformly random bytes; at most the subkey’s length

libsodium’s crypto_kdf: keyed BLAKE2b (RFC 7693) with the subkey’s id as the salt and the context as the personalisation

recommended

no

kbkdf

1 byte to 2^r - 1 digests (at most 2^29 - 1 bytes with L)

that of the HMAC and of the key-derivation key, which must be a key, not a password

NIST SP 800-108r1, counter mode over HMAC

recommended

no

sskdf

1 byte to 2^32 - 1 digests (backends::openssl: at most 2^30 bytes)

that of the digest and of the shared secret

NIST SP 800-56C Rev. 2, one-step KDF over a hash function (SHA-1, SHA-2, SHA-3)

recommended

no

x963kdf

1 byte to 2^32 - 1 digests less 1 byte (backends::openssl: at most 2^30 bytes)

that of the digest and of the shared secret

ANSI X9.63-2011 and SEC 1 v2, over SHA-1, SHA-224, SHA-256, SHA-384 or SHA-512 (SEC 1 v2, section 3.5)

recommended

no

Table 23. How to choose among "Key derivation"
Name Fastest natively Smallest on Emscripten Where it is used Choose it when

hkdf_extract

480 ns (sodium)

17,499 bytes (hash2)

NIP-44’s conversation key; TLS 1.3’s key schedule

When a protocol names the extract step alone.

hkdf_expand

489 ns (sodium)

24,778 bytes (sodium)

TLS 1.3’s key schedule; Signal’s Double Ratchet

Keys from a key that is already uniform (a master key), one per application info label.

hkdf

980 ns (sodium)

23,281 bytes (bearssl)

TLS 1.3; Signal’s protocols; WireGuard (over HMAC-BLAKE2s)

The default way to turn one secret into several keys. Never for passwords.

pbkdf2

6.1 ms (openssl)

29,235 bytes (hash2)

BIP39’s seeds (2,048 iterations of HMAC-SHA-512); OWASP: 600,000 iterations of HMAC-SHA-256 for passwords

When a standard or FIPS 140 demands it; otherwise Argon2id for passwords.

blake2b_subkey

-

-

libsodium’s key derivation, crypto_kdf_derive_from_key

To derive the keys a libsodium program derives from the same master key, or keys numbered by id from one random master key; hkdf for a secret that is not uniformly random.

kbkdf

-

-

Kerberos’s AES-SHA2 encryption types derive their keys with it (RFC 8009’s KDF-HMAC-SHA2); NIST’s approved key derivation from a key, SP 800-108r1

When a standard, a protocol or a smart card names SP 800-108’s counter mode; hkdf for a new design.

sskdf

-

-

JOSE’s ECDH-ES key agreement (JWE), its Concat KDF; Kerberos’s PKINIT key derivation

To derive the key JOSE’s ECDH-ES, PKINIT or another SP 800-56C protocol derives; hkdf for a new design.

x963kdf

-

-

ECIES, the elliptic-curve integrated encryption scheme of SEC 1; Apple’s ECIES algorithms of its Security framework, as their names say (X963SHA256)

To derive the keys ECIES or a smart card’s key agreement derives by ANSI X9.63; hkdf for a new design.

The measured columns are doc/measurements.json’s, a reference measured on 2026-11-16 on Apple M5 Max that decides nothing: the native throughput over 1 MiB, or the time of one derivation over hmac_sha2_256, of the fastest backend, and the smallest Emscripten program that calls the function; Measured size and throughput has every backend on every target.

HKDF

HKDF (RFC 5869, 2010, Krawczyk) has two steps, both HMACs. Extract takes an optional salt and the input_key_material (RFC 5869’s IKM) and returns a pseudorandom_key (the PRK) of the hmac’s digest size: PRK = HMAC(salt, IKM). Expand takes the pseudorandom_key and the application_info (RFC 5869’s info), the label of one purpose, and returns up to 255 digests of output_key_material, each block an HMAC of the previous block, the info and a counter. hkdf does both; hkdf_extract and hkdf_expand do one each, for a protocol that names a step, or a program that extracts once and expands many times. TLS 1.3, Signal, WireGuard, Noise and Nostr’s NIP-44 derive their keys with it.

This section adapts the guidance of libsodium’s documentation on HKDF (key_derivation/hkdf.md of libsodium-doc, ISC licence, kept in NOTICE.md), in hash’s own terms.

#include "hex.hpp"

#include <webcpp/hash/hkdf.hpp>
#include <webcpp/hash/hmac.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    // RFC 5869, appendix A.1.
    auto const input_key_material =
        example::from_hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
    auto const salt = example::from_hex("000102030405060708090a0b0c");
    auto const application_info = example::from_hex("f0f1f2f3f4f5f6f7f8f9");

    std::array<std::uint8_t, 42> output_key_material{};
    auto done = webcpp::hash::hkdf<webcpp::hash::hmac_sha2_256>(
        output_key_material, salt, input_key_material, application_info);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "okm " << example::hex(output_key_material) << '\n';
    if (example::hex(output_key_material) !=
        "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865") {
        return 1;
    }

    // The two steps of HKDF apart: extract turns the input into a uniform pseudorandom key, and
    // expand stretches it to the length asked, once per context. A program that needs several
    // keys from one secret extracts once and expands as many times as it needs.
    auto pseudorandom_key =
        webcpp::hash::hkdf_extract<webcpp::hash::hmac_sha2_256>(salt, input_key_material);
    if (!pseudorandom_key) {
        std::cerr << pseudorandom_key.error().message() << '\n';
        return 1;
    }
    std::array<std::uint8_t, 42> again{};
    done = webcpp::hash::hkdf_expand<webcpp::hash::hmac_sha2_256>(again, *pseudorandom_key,
                                                                  application_info);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "two steps " << (again == output_key_material ? "same" : "different") << '\n';

    // The use: one shared secret, two keys. Each key has its own application_info, so that the
    // encryption key and the authentication key are independent: a key used for two purposes can
    // let an attack on one purpose break the other. The secret is already uniform (a key
    // agreement's output hashed, say), so an empty salt is fine.
    auto const secret =
        example::from_hex("202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f");
    std::array<std::uint8_t, 32> encryption{};
    std::array<std::uint8_t, 32> authentication{};
    done = webcpp::hash::hkdf<webcpp::hash::hmac_sha2_256>(
        encryption, {}, secret, example::bytes("example chat v1 encryption"));
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    done = webcpp::hash::hkdf<webcpp::hash::hmac_sha2_256>(
        authentication, {}, secret, example::bytes("example chat v1 authentication"));
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "encryption key " << example::hex(encryption) << '\n';
    std::cout << "authentication key " << example::hex(authentication) << '\n';
}
okm 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865
two steps same
encryption key c6add3f301ce39db35b0e8ddf3f3ffdb4a64797225bfc2a6a8a5f19d8915c4eb
authentication key 29748eb5c5ce61740da229c9ed99cdd82376f9f7951c998b79f4e03c7801b709

Choosing the inputs.

  • input_key_material is the secret. It may be non-uniform (a Diffie-Hellman result) but must hold enough entropy: extract concentrates entropy, it never adds any. A password has too little; it goes through Argon2id.

  • salt is optional and public: a random value per session, or a constant that names the application or the protocol (NIP-44 uses nip44-v2). It separates the keys of different applications that might share a secret. An empty salt is RFC 5869’s string of zeros, and fine when the IKM is never reused across applications.

  • application_info names the purpose and is public. Each key gets its own info, written so that no two purposes can produce the same string: an application name, a version and the purpose, as example chat v1 encryption. The info of a single buffer is limited to hkdf_max_application_info_size, 32,768 bytes, on every backend (1,024 in WebCrypto’s async_hkdf, WebCrypto in the browser); the forms over pieces take any length (HKDF over pieces).

  • pseudorandom_key must stay secret, and hkdf_expand takes one of exactly the digest’s size (invalid_key_size otherwise). A key that is already uniform and of that size, such as 32 bytes from webcpp::crypto::random_device, can be expanded without the extract step.

  • HMAC-SHA-256 is the usual choice. HMAC-SHA-512 gives longer blocks and no practical gain in security; use it when a protocol names it.

Pitfalls.

  • Never HKDF for a password. HKDF is fast by design: a key derived from a password with HKDF is guessed as fast as the password’s digest.

  • One info, one purpose. Two keys derived with the same IKM, salt and info are the same key.

  • The output is limited: 255 times the digest size, 8,160 bytes over HMAC-SHA-256; more fails with invalid_output_size, the output untouched.

Table 24. Who implements hkdf_extract, hkdf_expand, hkdf (RFC 5869)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

hkdf_extract

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, any other Hash2 hash (hmac<H>)

not stated

hkdf_extract

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

hmac_sha2_256, hmac_sha2_512

not stated

hkdf_extract

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_extract

botan (with exceptions only)

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_extract

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf_expand

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, any other Hash2 hash (hmac<H>)

not stated

hkdf_expand

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

hmac_sha2_256, hmac_sha2_512

not stated

hkdf_expand

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_expand

botan (with exceptions only)

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_expand

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, any other Hash2 hash (hmac<H>)

not stated

hkdf

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

hmac_sha2_256, hmac_sha2_512

not stated

hkdf

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf

botan (with exceptions only)

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf

webcrypto (asynchronous family only) (partial: an application_info longer than 1,024 bytes, which completes with input_too_long: WebCrypto’s limit as node has it, where the other backends take 32,768)

/webcpp/asio//asio

emscripten

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf_extract over pieces

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, any other Hash2 hash (hmac<H>)

not stated

hkdf_extract over pieces

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

hmac_sha2_256, hmac_sha2_512

not stated

hkdf_extract over pieces

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf_extract over pieces

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_extract over pieces

botan (with exceptions only)

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_extract over pieces

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf_expand over pieces

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, any other Hash2 hash (hmac<H>)

not stated

hkdf_expand over pieces

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

hmac_sha2_256, hmac_sha2_512

not stated

hkdf_expand over pieces

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf_expand over pieces

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_expand over pieces

botan (with exceptions only)

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf_expand over pieces

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf over pieces

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, any other Hash2 hash (hmac<H>)

not stated

hkdf over pieces

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

hmac_sha2_256, hmac_sha2_512

not stated

hkdf over pieces

bearssl

/third_party//bearssl

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

hkdf over pieces

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf over pieces

botan (with exceptions only)

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

hkdf over pieces

webcrypto (asynchronous family only)

/webcpp/asio//asio

emscripten

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

What each backend states on constant time, as the capability table read it:

  • bearssl: BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_hmac.h states constant time for br_hmac_outCT alone; br_hkdf_* (src/kdf/hkdf.c) and HKDF over pieces call br_hmac_out.

  • botan:

    • Botan 3.14.1: doc/api_ref/kdf.rst states no constant-time property of its KDFs, and their source (src/lib/kdf/) none.

    • Botan 3.14.1: doc/api_ref/message_auth_codes.rst states no constant-time property of HMAC, and its source (src/lib/mac/hmac/) none; HKDF over pieces calls its HMAC.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl:

    • OpenSSL 3.5.9: doc/man3/EVP_MAC.pod and doc/man7/EVP_MAC-HMAC.pod state no constant-time property; HKDF over pieces calls EVP_MAC "HMAC".

    • OpenSSL 3.5.9: doc/man7/EVP_KDF-HKDF.pod and EVP_KDF-PBKDF2.pod state no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

  • webcrypto: The Web Cryptography API (W3C Recommendation, 2017) states no constant-time property of digest, sign or deriveBits; each JavaScript runtime’s implementation decides, and webcpp reads none.

The default of hkdf_extract and hkdf_expand: hash2 on every target, whatever the program links; botan, openssl, sodium only where the call names it, as its second template argument (The default backend).

The default of hkdf, hkdf_extract over pieces, hkdf_expand over pieces and hkdf over pieces: hash2 on every target, whatever the program links; bearssl, botan, openssl, sodium only where the call names it, as its second template argument (The default backend).

webcrypto serves the asynchronous family alone, on Emscripten, where the type of its asynchronous call names it (WebCrypto in the browser).

Naming a backend

Most programs never name a backend: the call takes the default, backends::hash2, on every target (The default backend). A program names one as the call’s second template argument, to match the bytes of another program exactly, to share a C library the program already links, or to test one backend against another. backend_has_v<Backend, Kdf, Hmac> says at compile time whether a backend has a function over an hmac; a call on a backend that does not stops the build with a message that names the backends that do.

#include "hex.hpp"

#include <webcpp/hash/hkdf.hpp>
#include <webcpp/hash/hmac.hpp>
#include <webcpp/hash/pbkdf2.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <string>

namespace {

// RFC 5869, appendix A.1, on the backend `Backend`.
template <class Backend>
std::string okm() {
    auto const input_key_material =
        example::from_hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
    auto const salt = example::from_hex("000102030405060708090a0b0c");
    auto const application_info = example::from_hex("f0f1f2f3f4f5f6f7f8f9");
    std::array<std::uint8_t, 42> out{};
    auto const done = webcpp::hash::hkdf<webcpp::hash::hmac_sha2_256, Backend>(
        out, salt, input_key_material, application_info);
    return done ? example::hex(out) : done.error().message();
}

}  // namespace

int main() {
    auto const hash2 = okm<webcpp::hash::backends::hash2>();
    auto const sodium = okm<webcpp::hash::backends::sodium>();
    auto const bearssl = okm<webcpp::hash::backends::bearssl>();

    std::cout << "hash2 " << hash2 << '\n';
    std::cout << "sodium " << (sodium == hash2 ? "same" : sodium) << '\n';
    std::cout << "bearssl " << (bearssl == hash2 ? "same" : bearssl) << '\n';
    if (hash2 !=
        "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865") {
        return 1;
    }

    // A backend that does not have the function is a compile-time fact, not a runtime failure:
    // libsodium has no PBKDF2, and asking for it by name stops the build.
    using webcpp::hash::backend_has_v;
    using webcpp::hash::hmac_sha2_256;
    namespace kdfs = webcpp::hash::kdfs;
    std::cout << "sodium has pbkdf2: "
              << (backend_has_v<webcpp::hash::backends::sodium, kdfs::pbkdf2, hmac_sha2_256> ? "yes"
                                                                                             : "no")
              << '\n';
    std::cout << "bearssl has hkdf: "
              << (backend_has_v<webcpp::hash::backends::bearssl, kdfs::hkdf, hmac_sha2_256> ? "yes"
                                                                                            : "no")
              << '\n';
}
hash2 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865
sodium same
bearssl same
sodium has pbkdf2: no
bearssl has hkdf: yes

HKDF over pieces

Protocols seldom give HKDF one buffer. HPKE (RFC 9180) extracts from HPKE-v1, the suite’s identifier, a label and the secret, one after another; TLS 1.3’s HKDF-Expand-Label builds its info from a length, a label and a context. Joining the parts takes a buffer: on the heap, with a copy of the secret to wipe afterwards, or on the stack, with a size that someone must bound. hkdf_extract, hkdf_expand and hkdf each have a form over byte_pieces (<webcpp/hash/byte_pieces.hpp>, which <webcpp/hash/hkdf.hpp> includes) that takes the input keying material and the application info as a list of spans, read one after another as if joined. On a synchronous backend each piece goes to the backend’s HMAC: no buffer, no copy of the secret. WebCrypto’s asynchronous forms copy the pieces into JavaScript memory instead (WebCrypto in the browser).

  • hkdf_extract<Hmac, Backend>(salt, input_key_material)

  • hkdf_expand<Hmac, Backend>(output_key_material, pseudorandom_key, application_info)

  • hkdf<Hmac, Backend>(output_key_material, salt, input_key_material, application_info)

The salt and the pseudorandom key stay one span each. The bytes are those of the single-buffer form over the parts joined: the tests check them against each other on random inputs and random splits on every backend.

No cap, no heap. The forms over pieces refuse only what RFC 5869 refuses: an output of 0 bytes or of more than 255 digests (invalid_output_size), and for hkdf_expand a pseudorandom key of another size than the digest’s (invalid_key_size); then the limits of the backend’s HMAC key (OpenSSL takes a salt of at most INT_MAX bytes, input_too_long beyond). The input keying material, the application info and the number of pieces have no limit: hkdf_max_application_info_size belongs to the single-buffer forms alone. A piece longer than the backend’s length type holds is fed in slices. On backends::hash2, backends::sodium and backends::bearssl hash allocates nothing, whatever the number and the size of the pieces (test allocation); OpenSSL’s and Botan’s allocations are theirs, counted in Allocation. Every HMAC state, every block and the pseudorandom key between the two steps are wiped, on success and on failure. backends::webcrypto is the exception: its asynchronous forms copy every input, the secret included, into JavaScript buffers in the call, zeroed when their promises settle, and a runtime that will not allocate a buffer that size completes with backend_failure (WebCrypto in the browser, Allocation).

Writing the pieces.

  • A braced list at the call, {a, b, c}: each element converts to std::span<std::uint8_t const> (a std::array, a std::vector, a span). Its array lives until the end of the call’s full expression, after the call returns.

  • One piece is byte_pieces{x}. A braced list of one span, {x}, is that span (the language’s rule), so hkdf_expand(okm, prk, {info}) calls the single-buffer form, with its limit; hkdf_expand(okm, prk, byte_pieces{info}) calls the form over pieces. hkdf takes both inputs as pieces or both as spans: beside a list, one buffer is written byte_pieces{input_key_material}.

  • {} and {x} of another type do not compile. Where both forms take braces, a lone {}, or a braced list of one element that is not exactly a std::span<std::uint8_t const> ({vec}, {array}), matches both forms and the call is ambiguous: hkdf(okm, salt, {}, {}) and hkdf(okm, {}, {}, {}), which compiled before the forms over pieces existed, no longer do. Pass x itself, an empty std::span<std::uint8_t const>, or byte_pieces{...} (byte_pieces{} for no piece). The asynchronous forms follow the same rule (The cheap functions through the event loop).

  • A list kept in a variable is a std::array of spans, as a std::array<std::span<std::uint8_t const>, 3> of prefix, label and secret, passed as it is (a std::vector or a span of spans too); never a byte_pieces variable. byte_pieces parts{a, b}; points to its braced list’s array, which dies at the end of the declaration; where the compiler has the lifetimebound attribute, it warns.

HPKE’s labeled steps (RFC 9180, section 4) are one call each, here running HPKE’s key schedule on test vector A.1.1 of the RFC:

#include "hex.hpp"

#include <webcpp/hash/hkdf.hpp>
#include <webcpp/hash/hmac.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <span>
#include <string_view>
#include <vector>

namespace {

namespace hash = webcpp::hash;

using bytes_view = std::span<std::uint8_t const>;

// RFC 9180's version label, "HPKE-v1".
constexpr std::array<std::uint8_t, 7> hpke_v1{'H', 'P', 'K', 'E', '-', 'v', '1'};

// The suite's identifier: "HPKE", then the KEM (0x0020, DHKEM(X25519, HKDF-SHA256)), the KDF
// (0x0001, HKDF-SHA256) and the AEAD (0x0001, AES-128-GCM), two bytes each.
constexpr std::array<std::uint8_t, 10> suite_id{'H', 'P', 'K', 'E', 0, 0x20, 0, 1, 0, 1};

// LabeledExtract(salt, label, ikm) = Extract(salt, "HPKE-v1" || suite_id || label || ikm): the
// braced list at the call is the input keying material's pieces.
auto labeled_extract(bytes_view salt, std::string_view label, bytes_view ikm) {
    return hash::hkdf_extract<hash::hmac_sha2_256>(salt,
                                                   {hpke_v1, suite_id, example::bytes(label), ikm});
}

// LabeledExpand(prk, label, info, L) = Expand(prk, I2OSP(L, 2) || "HPKE-v1" || suite_id || label
// || info, L), L the output's size.
auto labeled_expand(std::span<std::uint8_t> output, bytes_view pseudorandom_key,
                    std::string_view label, bytes_view info) {
    // I2OSP(L, 2): the size in two bytes, big-endian.
    std::array<std::uint8_t, 2> const length{
        static_cast<std::uint8_t>(output.size() >> 8U),
        static_cast<std::uint8_t>(output.size() & 0xffU),
    };
    return hash::hkdf_expand<hash::hmac_sha2_256>(
        output, pseudorandom_key, {length, hpke_v1, suite_id, example::bytes(label), info});
}

}  // namespace

int main() {
    // RFC 9180, A.1.1: the application's info and the KEM's shared secret; no PSK (base mode).
    auto const info = example::from_hex("4f6465206f6e2061204772656369616e2055726e");
    auto const shared_secret =
        example::from_hex("fe0e18c9f024ce43799ae393c7e8fe8fce9d218875e8227b0187c04e7d2ea1fc");
    bytes_view const no_psk{};

    // KeySchedule: key_schedule_context = mode || psk_id_hash || info_hash.
    auto const psk_id_hash = labeled_extract({}, "psk_id_hash", no_psk);
    auto const info_hash = labeled_extract({}, "info_hash", info);
    auto const secret = labeled_extract(shared_secret, "secret", no_psk);
    if (!psk_id_hash || !info_hash || !secret) {
        std::cerr << "extract failed\n";
        return 1;
    }
    std::vector<std::uint8_t> context{0x00};  // mode_base
    context.insert(context.end(), psk_id_hash->begin(), psk_id_hash->end());
    context.insert(context.end(), info_hash->begin(), info_hash->end());

    std::array<std::uint8_t, 16> key{};
    std::array<std::uint8_t, 12> base_nonce{};
    std::array<std::uint8_t, 32> exporter_secret{};
    if (!labeled_expand(key, *secret, "key", context) ||
        !labeled_expand(base_nonce, *secret, "base_nonce", context) ||
        !labeled_expand(exporter_secret, *secret, "exp", context)) {
        std::cerr << "expand failed\n";
        return 1;
    }
    std::cout << "key " << example::hex(key) << '\n';
    std::cout << "base_nonce " << example::hex(base_nonce) << '\n';
    std::cout << "exporter_secret " << example::hex(exporter_secret) << '\n';
    if (example::hex(key) != "4531685d41d65f03dc48f6b8302c05b0" ||
        example::hex(base_nonce) != "56d890e5accaaf011cff4b7d" ||
        example::hex(exporter_secret) !=
            "45ff1c2e220db587171952c0592d5f5ebe103f1561a2614e38f2ffd47e99e3f8") {
        return 1;
    }

    // The pieces are read as if joined: the same extract over one buffer gives the same key.
    std::vector<std::uint8_t> joined(hpke_v1.begin(), hpke_v1.end());
    joined.insert(joined.end(), suite_id.begin(), suite_id.end());
    auto const label = example::bytes("secret");
    joined.insert(joined.end(), label.begin(), label.end());
    auto const from_joined = hash::hkdf_extract<hash::hmac_sha2_256>(shared_secret, joined);
    std::cout << "pieces and joined "
              << (from_joined && *from_joined == *secret ? "same" : "different") << '\n';
}
key 4531685d41d65f03dc48f6b8302c05b0
base_nonce 56d890e5accaaf011cff4b7d
exporter_secret 45ff1c2e220db587171952c0592d5f5ebe103f1561a2614e38f2ffd47e99e3f8
pieces and joined same

Every backend that has an HKDF function has the three forms over pieces, backends::bearssl included (its hkdf_extract and hkdf_expand exist over pieces alone, on BearSSL’s HMAC), and backends::webcrypto has their asynchronous forms (WebCrypto in the browser): Who implements hkdf_extract, hkdf_expand, hkdf (RFC 5869) lists each form with its backends, targets and hmacs. The default is backends::hash2, as for the single-buffer forms.

PBKDF2

PBKDF2 (RFC 8018, first published in 2000 in PKCS #5 v2.0) derives a key from a password by iterating an HMAC: each block of output is the XOR of thousands or millions of chained HMACs of the password, so that every guess an attacker tries costs as many HMACs as the iteration count. It needs no memory, which is its weakness: a graphics card or a dedicated chip runs thousands of PBKDF2 guesses in parallel, where Argon2id and scrypt force each guess to hold megabytes. PBKDF2 remains where a standard names it: BIP39 derives every Bitcoin wallet’s seed from its words with 2,048 iterations of HMAC-SHA-512, and FIPS 140 validated products accept it when Argon2id is not approved.

#include "hex.hpp"

#include <webcpp/hash/hmac.hpp>
#include <webcpp/hash/pbkdf2.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    std::array<std::uint8_t, 64> vector{};
    auto done = webcpp::hash::pbkdf2<webcpp::hash::hmac_sha2_256>(vector, example::bytes("passwd"),
                                                                  example::bytes("salt"), 1);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "rfc7914 " << example::hex(vector) << '\n';
    if (example::hex(vector) !=
        "55ac046e56e3089fec1691c22544b605f94185216dde0465e68b9d57c20dacbc"
        "49ca9cccf179b645991664b39d77ef317c71b845b1e30bd509112041d3a19783") {
        return 1;
    }

    // A key from a password. The iteration count is the cost an attacker pays for every guess:
    // too few, and a GPU tries billions of passwords a second. In a real program the salt is
    // 16 random bytes per user (webcpp::crypto::random_device), stored beside the result; it is
    // fixed here so that the output is the same on every run.
    auto const salt = example::from_hex("000102030405060708090a0b0c0d0e0f");
    std::array<std::uint8_t, 32> key{};
    done = webcpp::hash::pbkdf2<webcpp::hash::hmac_sha2_256>(
        key, example::bytes("correct horse battery staple"), salt, 600'000);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "600000 iterations " << example::hex(key) << '\n';
}
rfc7914 55ac046e56e3089fec1691c22544b605f94185216dde0465e68b9d57c20dacbc49ca9cccf179b645991664b39d77ef317c71b845b1e30bd509112041d3a19783
600000 iterations ef177144eec9420cbc1093d2a8b344a92bc506d0d4ec9c028dd19f8324d8c1e6

Pitfalls.

  • Iterations are the whole defence. OWASP’s Password Storage Cheat Sheet recommends 600,000 iterations of HMAC-SHA-256, or 210,000 of HMAC-SHA-512, for passwords; BIP39’s 2,048 protect a seed of high entropy, not a password. Measure the time on the slowest device the program runs on (a phone, a browser tab: WebAssembly is slower than native; The measured data has the measured times).

  • A random salt per password, 16 bytes from webcpp::crypto::random_device, stored beside the result: without it, one guess tests every user at once and precomputed tables work.

  • Ask for no more than one digest. Each further block of output costs the defender the full iteration count again, and the attacker, who checks the first block alone, nothing.

  • Prefer Argon2id for a new design (Argon2id).

Table 25. Who implements pbkdf2 (RFC 8018)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

pbkdf2

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, any other Hash2 hash (hmac<H>)

not stated

pbkdf2

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

pbkdf2

botan (with exceptions only) (partial: an iteration count above 2^32 - 1 on wasm32 (invalid_iterations): Botan counts iterations in a size_t; an output of more than 2^32 - 2 digests (invalid_output_size), where RFC 8018 allows 2^32 - 1: Botan’s PBKDF2 derives at most 2^32 - 2 blocks (pbkdf2.cpp))

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

pbkdf2

webcrypto (asynchronous family only) (partial: an iteration count above 2^32 - 1 (invalid_iterations) and an output longer than (2^32 - 1) / 8 bytes (invalid_output_size): WebCrypto’s deriveBits counts iterations and bits in 32 bits)

/webcpp/asio//asio

emscripten

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/pbkdf.rst states no constant-time property of PBKDF2, and its source (src/lib/pbkdf/pbkdf2/) none.

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_KDF-HKDF.pod and EVP_KDF-PBKDF2.pod state no constant-time property.

  • webcrypto: The Web Cryptography API (W3C Recommendation, 2017) states no constant-time property of digest, sign or deriveBits; each JavaScript runtime’s implementation decides, and webcpp reads none.

The default of pbkdf2: hash2 on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

webcrypto serves the asynchronous family alone, on Emscripten, where the type of its asynchronous call names it (WebCrypto in the browser).

BLAKE2b subkeys

blake2b_subkey derives many keys from one master key, each named by a number, the subkey’s id, and an 8-byte context that names the application or the part of it, as libsodium’s crypto_kdf_derive_from_key does. A chat app keeps one 32-byte master key and asks for subkey 1 to encrypt messages and subkey 2 to authenticate them; a backup tool asks for one subkey per archive. A subkey is BLAKE2b (RFC 7693) of the empty message, keyed with the master key, with the id in BLAKE2b’s salt and the context in its personalisation: one fast call, and the bytes a libsodium program derives from the same master key, id and context. It runs on backends::sodium (/third_party//sodium), the one backend that has it.

Unlike HKDF, it does not extract: the master key must already be 32 uniformly random bytes, from webcpp::crypto::random_device or from another KDF. A Diffie-Hellman result or a password goes through HKDF or Argon2id first.

#include "hex.hpp"

#include <webcpp/hash/blake2b_subkey.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;

    auto const master =
        example::from_hex("404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f");
    auto const context = example::bytes("messages");  // exactly 8 bytes

    std::array<std::uint8_t, 32> encryption{};
    std::array<std::uint8_t, 32> authentication{};
    if (!hash::blake2b_subkey(encryption, master, 1, context) ||
        !hash::blake2b_subkey(authentication, master, 2, context)) {
        return 1;
    }
    std::cout << "subkey 1 " << example::hex(encryption) << '\n';
    std::cout << "subkey 2 " << example::hex(authentication) << '\n';

    // The length is part of the derivation: subkey 3 of 16 bytes is not the start of subkey 3 of
    // 32 bytes.
    std::array<std::uint8_t, 16> short_key{};
    std::array<std::uint8_t, 32> long_key{};
    if (!hash::blake2b_subkey(short_key, master, 3, context) ||
        !hash::blake2b_subkey(long_key, master, 3, context)) {
        return 1;
    }
    std::cout << "subkey 3, 16 bytes " << example::hex(short_key) << '\n';
    std::cout << "subkey 3, 32 bytes " << example::hex(long_key) << '\n';

    // The context is 8 bytes, never padded: a shorter one is refused.
    std::cout
        << "7-byte context: "
        << hash::blake2b_subkey(encryption, master, 1, example::bytes("message")).error().message()
        << '\n';
}
subkey 1 5f5d5836a36db28c61f8533d6b3b43643f2ad29e3366dc8bda85e66c646f13b1
subkey 2 5230c2a58d64ae036b7208a8343f2c108dbd81ed7eefcc5e4c9c73eaae87ca26
subkey 3, 16 bytes 3d332066b096df8f327fe54ecea124e0
subkey 3, 32 bytes d631aa557b76c6a23adc134800f1f4061aebf7daefde67fda855cca356131574
7-byte context: a parameter is outside the function's limits

Pitfalls.

  • The master key is random, never a password. blake2b_subkey adds no work per guess: from a password, derive the master key with Argon2id (Argon2id) first.

  • The context is exactly 8 bytes. A shorter or a longer one is invalid_parameters, never padded or cut, so that two programs cannot disagree on its bytes; spell it as a constant of 8 characters, as "vault v1".

  • One id, one purpose. The same id and context always give the same key: keep the ids in one list, and never reuse one for a second purpose.

  • The length is part of the key. A subkey of 16 bytes is not the first half of the one of 32 with the same id: BLAKE2b’s output size is a parameter of the hash. Lengths of 16 to 64 bytes are accepted, others are invalid_output_size.

Table 26. Who implements blake2b_subkey (libsodium’s crypto_kdf: keyed BLAKE2b (RFC 7693) with the subkey’s id as the salt and the context as the personalisation)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

blake2b_subkey

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

The default of blake2b_subkey: sodium on every target, whatever the program links (The default backend).

Key derivations of standards

Three key derivations are here because a standard, a protocol or a device names them, and a program that talks to it must derive the same bytes: a Kerberos client, a JSON Web Encryption library, an ECIES implementation, a smart card’s secure channel. Each repeats a hash or an HMAC with a counter, block after block, over the secret and a description of the key, as HKDF’s expand step does; none of them extracts first, so the secret must already be a key or a key agreement’s shared secret, never a password. For a new design HKDF is the better choice (HKDF): it is as fast, it extracts, and WebCrypto and every library have it.

They run on backends::openssl (OpenSSL 3.5.9’s EVP_KDF implementations "KBKDF", "SSKDF" and "X963KDF"), which a program names in the call and links as /webcpp/hash//openssl, on native, wasip2 and wasip3; and on backends::botan (Botan 3.14.1’s SP800-108-Counter, SP800-56A and KDF2), named likewise and linked as /third_party//botan, natively and on Emscripten, with exceptions (Key derivation on Botan). None of them has a default backend (The default backend), and a call that names none stops the build with "…​ has no default backend. Name one of: backends::openssl, backends::botan.". The tests check each against OpenSSL’s own test files, NIST’s validation vectors among them, Botan’s own, and a second implementation over Boost.Hash2.

KBKDF (NIST SP 800-108)

kbkdf is NIST SP 800-108’s key-based key derivation in counter mode over an HMAC: from a key-derivation key KIN, each block of output is HMAC(K_IN, [i] || Label || 0x00 || Context || [L]), the counter i written in r bits (32 by default), L the output’s length in bits. The label names what the derived key is for and the context who or what it belongs to (the parties, a session). Kerberos’s AES-SHA2 encryption types (RFC 8009) derive their keys this way, and so do validated modules that must use an approved derivation from a key. kbkdf_options sets the label and the context, and can leave out the separator, L or both and narrow the counter to 8, 16 or 24 bits, for a format that fixes another form of the fixed input; NIST’s validation vectors pass their whole fixed input as the context, with neither.

#include "hex.hpp"

#include <webcpp/hash/hmac.hpp>
#include <webcpp/hash/kdf_standards.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    auto const base_key = example::from_hex("3705d96080c17728a0e800eab6e0d23c");
    // The key usage 2 in 4 bytes, then 0x99: the checksum key's label in RFC 8009.
    auto const label = example::from_hex("0000000299");

    std::array<std::uint8_t, 16> checksum_key{};
    auto const done = hash::kbkdf<hash::hmac_sha2_256, hash::backends::openssl>(
        checksum_key, base_key, {.label = label});
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "Kc " << example::hex(checksum_key) << '\n';
    if (example::hex(checksum_key) != "b31a018a48f54776f403e9a396325dc3") {
        return 1;
    }
}
Kc b31a018a48f54776f403e9a396325dc3

Pitfalls.

  • Match every knob of the other side. The counter’s width, the separator and L change every byte of the output: a key derived with L is not the key derived without it. Read the format’s definition, and check one of its test vectors, as the example does with RFC 8009’s.

  • The output’s length is part of the key when L is in the fixed input (the default): 16 bytes are not the first half of 32.

  • The key is a key. A password goes through Argon2id first (Argon2id); kbkdf adds no work per guess. An empty key is invalid_key_size.

  • Approval is the hash’s. SP 800-108 approves HMAC over SHA-1, SHA-2 or SHA-3. kbkdf also takes HMAC over MD5, RIPEMD-160 or BLAKE2, for the formats that use them, and does not stop the build as sskdf and x963kdf do: where an approved derivation is required, pick SHA-2 or SHA-3.

  • Its limits: at most 2r - 1 blocks, and with L at most 536,870,911 bytes (L counts bits in 32 of them), invalid_output_size otherwise; a counter of another width than 8, 16, 24 or 32 bits is invalid_parameters; OpenSSL takes an HMAC key of at most INT_MAX bytes (unsupported_by_backend).

  • Botan writes the separator and L, always. backends::botan computes SP 800-108’s default fixed input alone, with the separator and a 32-bit L: kbkdf_options with .separator = false or .length = false is unsupported_by_backend there: NIST’s validation vectors, written without either, therefore cannot run on Botan (Key derivation on Botan).

Table 27. Who implements kbkdf (NIST SP 800-108r1, counter mode over HMAC)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

kbkdf

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

/webcpp/hash//openssl

native, wasip2, wasip3

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

kbkdf

botan (with exceptions only) (partial: the separator or L turned off: Botan’s SP800-108-Counter always writes both (sp800_108.cpp))

/third_party//botan

native, emscripten

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/kdf.rst states no constant-time property of its KDFs, and their source (src/lib/kdf/) none.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_KDF-KB.pod states no constant-time property.

kbkdf has no default backend: the call names one of its backends, as its second template argument (The default backend).

One-step KDF (NIST SP 800-56C)

sskdf is the one-step key derivation of NIST SP 800-56C over a hash, the "Concat KDF" of SP 800-56A: each block is H(counter || Z || FixedInfo), the counter 32 bits from 1, Z the shared secret of a key agreement (an ECDH result) and FixedInfo the description of the key both parties write the same way. JOSE’s ECDH-ES, the key agreement of JSON Web Encryption (RFC 7518), and Kerberos’s PKINIT (RFC 8636) derive their keys with it. It takes SHA-1, a SHA-2 or a SHA-3 (digests::sha1 to digests::sha3_512), the hash functions SP 800-56C approves; another digest stops the build.

#include "hex.hpp"

#include <webcpp/hash/kdf_standards.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <string_view>
#include <vector>

namespace {

// JOSE's fixed info: each field as its 4-byte big-endian length, then its bytes.
void append_field(std::vector<std::uint8_t>& info, std::string_view field) {
    auto const size = static_cast<std::uint32_t>(field.size());
    for (unsigned const shift : {24U, 16U, 8U, 0U}) {
        info.push_back(static_cast<std::uint8_t>(size >> shift));
    }
    info.insert(info.end(), field.begin(), field.end());
}

}  // namespace

int main() {
    namespace hash = webcpp::hash;
    // Z, the x-coordinate of the ECDH result on P-256.
    auto const shared_secret =
        example::from_hex("9e56d91d817135d372834283bf84269cfb316ea3da806a48f6daa7798cfe90c4");
    std::vector<std::uint8_t> fixed_info;
    append_field(fixed_info, "A128GCM");  // AlgorithmID
    append_field(fixed_info, "Alice");    // PartyUInfo
    append_field(fixed_info, "Bob");      // PartyVInfo
    // SuppPubInfo: the key's length, 128 bits.
    fixed_info.insert(fixed_info.end(), {0x00, 0x00, 0x00, 0x80});

    std::array<std::uint8_t, 16> content_key{};
    auto const done = hash::sskdf<hash::digests::sha2_256, hash::backends::openssl>(
        content_key, shared_secret, fixed_info);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "content key " << example::hex(content_key) << '\n';
    // RFC 7518's "VqqN6vgjbSBcIijNcacQGg", decoded from base64url.
    if (example::hex(content_key) != "56aa8deaf8236d205c2228cd71a7101a") {
        return 1;
    }
}
content key 56aa8deaf8236d205c2228cd71a7101a

Pitfalls.

  • FixedInfo is the protocol’s, byte for byte. JOSE writes each field as its length in 4 bytes and its bytes, and ends with the key’s length in bits: the same fields in another form give another key. Check one of the protocol’s examples, as this one does with RFC 7518’s.

  • Z is the raw shared secret, the x-coordinate of the ECDH result, not a hash of it: an empty one is invalid_key_size.

  • Its limits: at most 232 - 1 blocks (invalid_output_size) and the input the hash takes (input_too_long, past 261 bytes for SHA-1 and SHA-256); OpenSSL takes a secret, a FixedInfo and an output of at most 230 bytes each (unsupported_by_backend). backends::botan has no SHA-512/224: sskdf over it on Botan stops the build, naming backends::openssl.

Table 28. Who implements sskdf (NIST SP 800-56C Rev. 2, one-step KDF over a hash function (SHA-1, SHA-2, SHA-3))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

sskdf

openssl (partial: a secret, an info or an output of more than 2^30 bytes: OpenSSL’s SSKDF_MAX_INLEN (providers/implementations/kdfs/sskdf.c))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

sskdf

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/kdf.rst states no constant-time property of its KDFs, and their source (src/lib/kdf/) none.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_KDF-SS.pod states no constant-time property.

sskdf has no default backend: the call names one of its backends, as its second template argument (The default backend).

X9.63 KDF (ANSI X9.63, SEC 1)

x963kdf is the key derivation of ANSI X9.63, which SEC 1 specifies for ECIES and for elliptic-curve key agreement: each block is H(Z || counter || SharedInfo), the same as SP 800-56C’s but with the counter after the shared secret, so the two never give the same bytes. An ECIES implementation derives the encryption key and the MAC key of a message from the ECDH result with it, in one derivation cut in two; smart cards and the key agreements of BSI TR-03111 use it too. It takes SHA-1, SHA-224, SHA-256, SHA-384 or SHA-512, the hash functions SEC 1 lists (section 3.5) and NIST SP 800-135 approves for it (FIPS 180-3’s); SHA-512/224, SHA-512/256, SHA-3 or another digest stops the build.

#include "hex.hpp"

#include <webcpp/hash/kdf_standards.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <span>

int main() {
    namespace hash = webcpp::hash;
    // Z, the ECDH result's x-coordinate, and the bytes of the sender's ephemeral public key.
    auto const shared_secret =
        example::from_hex("9e56d91d817135d372834283bf84269cfb316ea3da806a48f6daa7798cfe90c4");
    auto const ephemeral_public_key =
        example::from_hex("02d7c5f8f1c5bd2a0a83c0a5b84dbbc1bf1e3b0a8e7dc7cc5b2b8b1d3e8f7a6b5c");

    // 16 bytes of AES-128 key, then 32 bytes of HMAC-SHA-256 key: one derivation, cut in two.
    std::array<std::uint8_t, 48> keys{};
    auto const done = hash::x963kdf<hash::digests::sha2_256, hash::backends::openssl>(
        keys, shared_secret, ephemeral_public_key);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "encryption key " << example::hex(std::span(keys).first(16)) << '\n';
    std::cout << "mac key " << example::hex(std::span(keys).subspan(16)) << '\n';
}
encryption key 4ad858e2f9d7a9888c70163e236dc3ba
mac key 5e5694e2c4ac9e60f72587529bb7f0c25e070a32df14a9f3a52e347f4ad1e9fb

Pitfalls.

  • SharedInfo is the scheme’s. ECIES variants differ in what they put there (nothing, the ephemeral public key, a label): read the variant’s definition.

  • Not interchangeable with sskdf: the counter’s place differs, and so does every byte.

  • Its limits: fewer bytes than 232 - 1 blocks (invalid_output_size) and the input the hash takes (input_too_long); OpenSSL takes a secret, a SharedInfo and an output of at most 230 bytes each (unsupported_by_backend); Botan’s KDF2 derives at most 232 - 2 blocks, one fewer than ANSI X9.63 allows (unsupported_by_backend for the last). An empty secret is invalid_key_size.

Table 29. Who implements x963kdf (ANSI X9.63-2011 and SEC 1 v2, over SHA-1, SHA-224, SHA-256, SHA-384 or SHA-512 (SEC 1 v2, section 3.5))
Function Backend The program’s Jamfile names Targets Hmacs Constant time

x963kdf

openssl (partial: a secret, an info or an output of more than 2^30 bytes: OpenSSL’s SSKDF_MAX_INLEN (providers/implementations/kdfs/sskdf.c))

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

x963kdf

botan (with exceptions only) (partial: an output of more than 2^32 - 2 digests, where ANSI X9.63 allows 2^32 - 1: Botan’s KDF2 derives at most 2^32 - 2 blocks (kdf2.cpp))

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/kdf.rst states no constant-time property of its KDFs, and their source (src/lib/kdf/) none.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_KDF-X963.pod states no constant-time property.

x963kdf has no default backend: the call names one of its backends, as its second template argument (The default backend).

Key derivation on Botan

backends::botan computes HKDF, PBKDF2 and the three key derivations of standards through Botan 3.14.1’s KDF and PasswordHashFamily, natively and on Emscripten, in a program built with exceptions that links /third_party//botan. It is never a default (design D34): a call names it, as the second template argument, hkdf<hmac_sha2_256, backends::botan>. Its HKDF (extract, expand and both), PBKDF2 and KBKDF take every hmac of hmac.hpp but hmac_ripemd_128 and hmac_sha2_512_224, whose digests Botan does not have; its one-step KDF (SP800-56A) takes the digests SP 800-56C approves but SHA-512/224, and its X9.63 KDF (KDF2) the five SEC 1 lists. A call over another stops the build with a message that names the backends that have it. The tests check Botan against the RFCs’ vectors, Botan’s own test files and every other backend, on random inputs.

#include "hex.hpp"

#include <webcpp/hash/hkdf.hpp>
#include <webcpp/hash/hmac.hpp>
#include <webcpp/hash/kdf_standards.hpp>
#include <webcpp/hash/pbkdf2.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::botan;

    // HKDF: RFC 5869, Test Case 1.
    auto const input_key_material =
        example::from_hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
    auto const salt = example::from_hex("000102030405060708090a0b0c");
    auto const application_info = example::from_hex("f0f1f2f3f4f5f6f7f8f9");
    std::array<std::uint8_t, 42> output_key_material{};
    if (!hash::hkdf<hash::hmac_sha2_256, botan>(output_key_material, salt, input_key_material,
                                                application_info)) {
        return 1;
    }
    std::cout << "hkdf " << example::hex(output_key_material) << '\n';
    if (example::hex(output_key_material) !=
        "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf"
        "34007208d5b887185865") {
        return 1;
    }

    // PBKDF2: RFC 6070, 2 iterations.
    std::array<std::uint8_t, 20> key{};
    if (!hash::pbkdf2<hash::hmac_sha1_160, botan>(key, example::bytes("password"),
                                                  example::bytes("salt"), 2)) {
        return 1;
    }
    std::cout << "pbkdf2 " << example::hex(key) << '\n';

    // KBKDF: RFC 8009's Kc, with SP 800-108's separator and L, as Botan writes them.
    auto const base_key = example::from_hex("3705d96080c17728a0e800eab6e0d23c");
    auto const label = example::from_hex("0000000299");
    std::array<std::uint8_t, 16> checksum_key{};
    if (!hash::kbkdf<hash::hmac_sha2_256, botan>(checksum_key, base_key, {.label = label})) {
        return 1;
    }
    std::cout << "kbkdf " << example::hex(checksum_key) << '\n';

    // Without L the fixed input is another one, which Botan's KBKDF cannot write.
    auto const refused = hash::kbkdf<hash::hmac_sha2_256, botan>(checksum_key, base_key,
                                                                 {.label = label, .length = false});
    std::cout << "kbkdf without L: " << refused.error().message() << '\n';
}
hkdf 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865
pbkdf2 ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957
kbkdf b31a018a48f54776f403e9a396325dc3
kbkdf without L: the backend does not take this parameter; name a backend that does

Pitfalls.

  • KBKDF’s fixed input is SP 800-108’s default, always. Botan writes the separator and L (32 bits) whatever kbkdf_options says, so .separator = false or .length = false is unsupported_by_backend there; a format that leaves either out names backends::openssl (KBKDF (NIST SP 800-108)).

  • One block short of the standards. Botan’s PBKDF2 and KDF2 derive at most 232 - 2 blocks, where RFC 8018 and ANSI X9.63 allow 232 - 1: PBKDF2’s last block is invalid_output_size, X9.63’s unsupported_by_backend, before Botan is called. No program asks for 128 GiB of a key.

  • An iteration count in a size_t. On Emscripten (wasm32) Botan’s PBKDF2 takes at most 232 - 1 iterations: more is invalid_iterations.

  • Long HMAC keys are hashed first. Botan’s HMAC takes a key of at most 8,192 bytes; hash hashes a longer one first (an HKDF salt, a PBKDF2 password, a KBKDF key), as RFC 2104 does, so the bytes are every other backend’s.

  • Botan allocates and throws. Each call makes Botan’s objects with operator new and their secret buffers with calloc, overwritten and freed before it returns; an exception is caught at the call’s boundary, errc::not_enough_memory for an allocation, backend_failure for anything else, the output zeroed (Allocation).

Password hashing

Every service that has a login will one day lose its database, through a breach, a backup left open or an insider. What the attacker then holds is what the service stored for each password, and what it costs to recover the passwords from it is the service’s last defence: people reuse passwords, so a recovered password opens their mail and their bank. A password hash is a function made to be slow and to need a lot of memory, so that every guess costs the attacker time and memory too, on a graphics card as on a server, and a random salt per password, so that each guess tests one user and no table can be computed in advance. The same functions turn a password into an encryption key for a password manager or an encrypted backup.

This chapter adapts the guidance of libsodium’s documentation on password hashing (password_hashing/default_phf.md and password_hashing/scrypt.md of libsodium-doc, ISC licence, kept in NOTICE.md), in hash’s own terms; every function here runs on libsodium by default, and on OpenSSL or Botan where the call names backends::openssl or backends::botan. bcrypt and bcrypt_pbkdf, which only Botan has, close the chapter (bcrypt and bcrypt_pbkdf).

Every function of this chapter, bcrypt_verify included, sets DIT (data-independent timing) around each call, on every synchronous backend, on 64-bit ARM under Apple’s systems and Linux where the CPU has FEAT_DIT, and leaves the thread’s DIT as it found it (Data-independent timing (DIT)). DIT makes the time of the instructions Arm lists independent of their data; it does not change what a function reads: Argon2d and scrypt read memory at addresses that depend on the password, and bcrypt’s Blowfish indexes its tables by secret data, as each upstream states (Backends).

Table 30. What each of "Password hashing" is
Name Output Security Standard Status In the browser (WebCrypto)

argon2id

16 to 2^32 - 1 bytes

each guess costs its memory and passes, on a GPU too

RFC 9106, one lane

recommended

no

kdfs::argon2d

4 to 2^32 - 1 bytes

the strongest against trade-offs, open to side channels on a shared machine

RFC 9106, every parameter

where no attacker shares the machine

no

kdfs::argon2i

4 to 2^32 - 1 bytes (16 or more on libsodium)

each guess costs its memory and passes, but with few passes an attacker trades memory for time more cheaply than against Argon2id

RFC 9106, every parameter

legacy

no

kdfs::argon2id

4 to 2^32 - 1 bytes (16 or more on libsodium)

each guess costs its memory and passes, on a GPU too

RFC 9106, every parameter

recommended

no

scrypt

1 to (2^32 - 1) times 32 bytes

each guess costs 128 r N bytes of memory

RFC 7914

recommended

no

bcrypt

60 characters: the version, the cost, the salt and the hash

each guess costs 2^cost rounds of Blowfish’s key schedule in 4 KiB of memory; it reads at most 72 bytes of a password

Provos and Mazieres, A Future-Adaptable Password Scheme (USENIX 1999), as OpenBSD’s bcrypt(3) writes it

legacy

no

bcrypt_pbkdf

1 to 1,024 bytes

each round costs a bcrypt key schedule; its output blocks are interleaved, so that an attacker computes them all

OpenBSD’s bcrypt_pbkdf(3), as OpenSSH’s private keys use it

legacy

no

Table 31. How to choose among "Password hashing"
Name Fastest natively Smallest on Emscripten Where it is used Choose it when

argon2id

38.3 ms (sodium)

39,690 bytes (sodium)

OWASP’s first choice for password storage; the Password Hashing Competition’s winner; Bitwarden’s vault key, as an option

Storing passwords and deriving keys from them.

kdfs::argon2d

-

-

RFC 9106’s variant where no attacker shares the machine, such as proof of work

Never for passwords; only where a format names Argon2d and no attacker shares the machine.

kdfs::argon2i

-

-

libsodium’s crypto_pwhash_argon2i, its password hash before Argon2id; RFC 9106’s variant for memory access independent of the secret, which it recommends only through Argon2id

Only to check tags a system already stored with Argon2i; Argon2id for anything new.

kdfs::argon2id

-

-

RFC 9106’s first recommendation for password hashing; OWASP’s first choice for password storage

Storing passwords and deriving keys from them where a parameter beyond the function argon2id’s is needed (lanes, a pepper, associated data); argon2id otherwise.

scrypt

19.1 ms (sodium)

29,540 bytes (sodium)

Ethereum’s keystore files (Web3 Secret Storage); OWASP: N 2^17, r 8, p 1 when Argon2id is not available

When a format demands scrypt; otherwise Argon2id.

bcrypt

-

-

OpenBSD’s password hashes, and those of the many systems that store its strings; OWASP: for legacy systems where Argon2id and scrypt are not available, a cost of 10 or more

To check or make the bcrypt strings a system already stores; Argon2id for a new design.

bcrypt_pbkdf

-

-

OpenSSH’s private key files, their kdfname bcrypt; OpenBSD’s bcrypt_pbkdf(3)

To read or write OpenSSH’s encrypted private keys; Argon2id for a new design.

The measured columns are doc/measurements.json’s, a reference measured on 2026-11-16 on Apple M5 Max that decides nothing: the native throughput over 1 MiB, or the time of one derivation over hmac_sha2_256, of the fastest backend, and the smallest Emscripten program that calls the function; Measured size and throughput has every backend on every target.

Argon2id

Argon2 won the Password Hashing Competition in 2015 and is RFC 9106 (2021). It fills a large matrix of 1 KiB blocks, each computed from earlier ones with BLAKE2b, over a number of passes; an attacker who keeps less memory must compute blocks again, at a cost that grows fast. Argon2id is its hybrid variant, which resists both the side channels of data-dependent memory access (in its first half pass) and trade-offs between time and memory: RFC 9106 and OWASP name it the first choice. argon2id runs libsodium’s by default, with parallelism 1 (one lane), no secret and no associated data; a program links /third_party//sodium. argon2id<backends::openssl> runs OpenSSL’s, with the same costs and the same tag, on native, wasip2 and wasip3 (a program links /webcpp/hash//openssl); argon2id<backends::botan> runs Botan’s, natively and on Emscripten, with exceptions (a program links /third_party//botan).

#include "hex.hpp"

#include <webcpp/hash/argon2.hpp>
#include <webcpp/hash/error.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <span>

int main() {
    // The salt is 16 random bytes per password in a real program, stored with the tag; it is
    // fixed here so that the output is the same on every run.
    auto const salt = example::from_hex("000102030405060708090a0b0c0d0e0f");

    std::array<std::uint8_t, 32> tag{};
    auto const done = webcpp::hash::argon2id(tag, example::bytes("correct horse battery staple"),
                                             salt, webcpp::hash::argon2id_interactive);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "argon2id " << example::hex(tag) << '\n';

    // A salt of another size is refused before any work, and the output stays as it was.
    auto const refused =
        webcpp::hash::argon2id(tag, example::bytes("correct horse battery staple"),
                               std::span(salt).first(15), webcpp::hash::argon2id_interactive);
    if (refused || refused.error() != webcpp::hash::error::invalid_salt_size) {
        return 1;
    }
    std::cout << "15-byte salt: " << refused.error().message() << '\n';
}
argon2id c05ce4c4dd7e0e45ee6011cc59d068ade47df1b01fc0cf9cd4678bdf68a5b7b0
15-byte salt: the salt is not of a size the function accepts

Choosing the costs. argon2id_parameters has two: memory, in bytes, a multiple of 1 KiB, and passes, the number of passes over it. More of either is never less secure; the limit is the time and memory the program can spend.

  • hash gives libsodium’s three presets: argon2id_interactive, 2 passes over 64 MiB, for a login; argon2id_moderate, 3 passes over 256 MiB, about 0.7 s on libsodium’s reference machine; argon2id_sensitive, 4 passes over 1 GiB, about 3.5 s there, for keys that protect very sensitive data and are derived rarely.

  • To tune for a server, decide first how much memory one hash may take, given how many logins run at once (ideally no more than one per core) and the memory the machine is sure to have; set memory to it and passes to 3, and time one hash. If it is too slow, lower the memory and keep 3 passes; if it is fast enough, raise the passes. About one second is the most a login should take; a desktop application that asks for its password once per session can take about five; a job that runs rarely, such as restoring a backup, can take longer.

  • OWASP’s minimum for a login is 19 MiB with 2 passes; libsodium’s interactive preset is above it.

  • WebAssembly is slower than native (The measured data has the measured times), and a browser tab may not get a gigabyte: measure on the target.

Pitfalls.

  • A random 16-byte salt per password, from webcpp::crypto::random_device; argon2id refuses another size with invalid_salt_size.

  • Store the costs with the salt and the tag. Verifying needs exactly the same memory, passes and salt; a program that raises its costs later must know which costs each stored tag used. hash has no $argon2id$ string format: the program stores the three values in its own record (Storing passwords for a login).

  • Compare the tag with webcpp::secure::constant_time_equal.

  • The memory is the backend’s. libsodium allocates the matrix with mmap where there is one, else from the C heap; OpenSSL from its own allocator, the C heap; both outside any allocator of the program (What each backend does with secrets and memory). errc::not_enough_memory reports a refusal.

  • Keep the password in memory briefly, and overwrite it when done.

  • Not RFC 9106’s other parameters. Parallelism above 1, a secret (pepper) and associated data are those of the family argon2 (Every parameter of Argon2: argon2).

Table 32. Who implements argon2id (RFC 9106, one lane)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

argon2id

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

argon2id

openssl

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

argon2id

botan (with exceptions only)

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/pbkdf.rst states that Argon2i’s memory accesses are independent of the data and Argon2id’s depend on it after the first half of the first pass, and states no constant-time property.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_KDF-ARGON2.pod states that Argon2i’s memory accesses are independent of the data and Argon2d’s depend on it, and states no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

The default of argon2id: sodium on every target, whatever the program links; botan, openssl only where the call names it, as its only template argument (The default backend).

Every parameter of Argon2: argon2

argon2<Variant> is Argon2 with every parameter of RFC 9106, for the cases the function argon2id does not cover: the variant, the passes, the memory, the lanes (parallelism), a secret (a pepper, kept apart from the database, so that a stolen database alone does not let an attacker test guesses) and associated data, in an argon2_parameters. The variants are three:

  • kdfs::argon2id, the hybrid, RFC 9106’s and OWASP’s first choice for passwords. On libsodium it is the Argon2id of the function argon2id, with the family’s parameters.

  • kdfs::argon2i, whose memory access does not depend on the password: an attacker who watches the cache learns nothing of it, but with few passes an attacker who keeps less memory pays less extra time than against Argon2id. It is here to check tags a system already stored with it, such as those of libsodium’s crypto_pwhash_argon2i; new code takes Argon2id.

  • kdfs::argon2d, whose memory access depends on the password: the best against trade-offs between time and memory, but readable through side channels. backends::openssl alone has it, and it has no default: the call names the backend.

The default backend of Argon2id and Argon2i is libsodium (a program links /third_party//sodium), which takes one lane, no secret and no associated data, a 16-byte salt, a tag of 16 bytes or more, and for Argon2i 3 passes or more. The family’s guards are RFC 9106’s; a value they accept that the backend does not take is unsupported_by_backend, before any work, the output left as it was. backends::openssl has every variant with every parameter, on native, wasip2 and wasip3; backends::botan has every variant with every parameter within Botan’s limits, at most 128 lanes and 8 GiB of memory (2 GiB on Emscripten), natively and on Emscripten. Neither is ever a default (design D34), so a call names one.

#include "hex.hpp"

#include <webcpp/hash/argon2.hpp>
#include <webcpp/hash/error.hpp>

#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>

namespace hash = webcpp::hash;

int main() {
    // The salt is 16 random bytes per password in a real program, stored with the tag and the
    // costs; it is fixed here so that the output is the same on every run.
    auto const salt = example::from_hex("000102030405060708090a0b0c0d0e0f");
    auto const password = example::bytes("correct horse battery staple");

    // The family counts memory in KiB, as RFC 9106 does: 19,456 KiB are 19 MiB.
    hash::argon2_parameters const login{.passes = 2, .memory_kibibytes = 19456};
    std::array<std::uint8_t, 32> tag{};
    if (!hash::argon2<hash::kdfs::argon2id>(tag, password, salt, login)) {
        return 1;
    }
    std::cout << "argon2id " << example::hex(tag) << '\n';

    // The function argon2id counts bytes: the same costs give the same tag.
    std::array<std::uint8_t, 32> same{};
    if (!hash::argon2id(same, password, salt, {.passes = 2, .memory = std::size_t{19456} * 1024}) ||
        same != tag) {
        return 1;
    }

    // Argon2i, only to check tags a system already stored with it; libsodium takes 3 passes or
    // more.
    if (!hash::argon2<hash::kdfs::argon2i>(tag, password, salt,
                                           {.passes = 4, .memory_kibibytes = 32768})) {
        return 1;
    }
    std::cout << "argon2i  " << example::hex(tag) << '\n';

    // Four lanes are RFC 9106's, not libsodium's: refused before any work, the tag untouched.
    auto const refused = hash::argon2<hash::kdfs::argon2id>(
        tag, password, salt, {.passes = 2, .memory_kibibytes = 19456, .lanes = 4});
    if (refused || refused.error() != hash::error::unsupported_by_backend) {
        return 1;
    }
    std::cout << "4 lanes: " << refused.error().message() << '\n';
}
argon2id 818259b6310026a8e0dbac5d2e6927abcfdb07b32258fac4f61b18b80f929085
argon2i  99c5bc4aca583cd90b6d91947ac4daed7fb7fde6b965a4b74f2417d061a90e6c
4 lanes: the backend does not take this parameter; name a backend that does
#include "hex.hpp"

#include <webcpp/hash/argon2.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::openssl;

    // RFC 9106, section 5.3: 32 bytes of 0x01, 16 of 0x02, a secret of 8 bytes of 0x03 and
    // associated data of 12 bytes of 0x04.
    std::array<std::uint8_t, 32> password{};
    password.fill(0x01);
    std::array<std::uint8_t, 16> salt{};
    salt.fill(0x02);
    std::array<std::uint8_t, 8> pepper{};
    pepper.fill(0x03);
    std::array<std::uint8_t, 12> context{};
    context.fill(0x04);

    // m counts KiB, as RFC 9106 does: 32 KiB over four lanes, three passes. A password hash takes
    // far more memory; these are the RFC's costs, to check the tag.
    hash::argon2_parameters const costs{
        .passes = 3,
        .memory_kibibytes = 32,
        .lanes = 4,
        .secret = pepper,
        .associated_data = context,
    };

    std::array<std::uint8_t, 32> tag{};
    auto const done = hash::argon2<hash::kdfs::argon2id, openssl>(tag, password, salt, costs);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "argon2id " << example::hex(tag) << '\n';
    if (example::hex(tag) != "0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659") {
        return 1;
    }

    // Argon2d (RFC 9106, section 5.1), for uses where no attacker shares the machine.
    auto const argon2d_done =
        hash::argon2<hash::kdfs::argon2d, openssl>(tag, password, salt, costs);
    if (!argon2d_done) {
        std::cerr << argon2d_done.error().message() << '\n';
        return 1;
    }
    std::cout << "argon2d " << example::hex(tag) << '\n';
}
argon2id 0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659
argon2d 512b391b6f1162975371d30919734294f868e3be3984f3c1a13a4db9fabe4acb

The same tag on Botan, with scrypt beside it, and the costs past Botan’s limits refused:

#include "hex.hpp"

#include <webcpp/hash/argon2.hpp>
#include <webcpp/hash/scrypt.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::botan;

    // RFC 9106, section 5.3: four lanes over 32 KiB, three passes, a secret and associated data.
    std::array<std::uint8_t, 32> password{};
    password.fill(0x01);
    std::array<std::uint8_t, 16> salt{};
    salt.fill(0x02);
    std::array<std::uint8_t, 8> pepper{};
    pepper.fill(0x03);
    std::array<std::uint8_t, 12> context{};
    context.fill(0x04);
    hash::argon2_parameters costs{
        .passes = 3,
        .memory_kibibytes = 32,
        .lanes = 4,
        .secret = pepper,
        .associated_data = context,
    };
    std::array<std::uint8_t, 32> tag{};
    if (!hash::argon2<hash::kdfs::argon2id, botan>(tag, password, salt, costs)) {
        return 1;
    }
    std::cout << "argon2id " << example::hex(tag) << '\n';

    // scrypt: RFC 7914, N 1,024, r 8, p 16.
    std::array<std::uint8_t, 64> key{};
    if (!hash::scrypt<botan>(key, example::bytes("password"), example::bytes("NaCl"),
                             {.cost = 1024, .block_size = 8, .parallelism = 16})) {
        return 1;
    }
    std::cout << "scrypt " << example::hex(key).substr(0, 32) << "...\n";

    // Botan's Argon2 takes at most 128 lanes, which RFC 9106 allows up to 2^24 - 1 of.
    costs.lanes = 129;
    costs.memory_kibibytes = 8 * 129;
    auto const lanes = hash::argon2<hash::kdfs::argon2id, botan>(tag, password, salt, costs);
    std::cout << "129 lanes: " << lanes.error().message() << '\n';
    // Botan's scrypt takes N up to 2^22.
    auto const large = hash::scrypt<botan>(key, example::bytes("password"), example::bytes("NaCl"),
                                           {.cost = 1U << 23U, .block_size = 2, .parallelism = 1});
    std::cout << "N 2^23: " << large.error().message() << '\n';
}
argon2id 0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659
scrypt fdbabe1c9d3472007856e7190d01e9fe...
129 lanes: the backend does not take this parameter; name a backend that does
N 2^23: the backend does not take this parameter; name a backend that does

Pitfalls.

  • Two units of memory. argon2_parameters::memory_kibibytes counts KiB, as RFC 9106’s m does; argon2id_parameters::memory, the parameter of argon2id, counts bytes. The 268,435,456 bytes of argon2id_moderate are 262,144 KiB.

  • Every parameter changes the tag. The lanes, the secret and the associated data are inputs of the hash as the password and the salt are: verifying needs all of them again, so a program stores the lanes with the costs, and keeps the secret where it can read it again.

  • A value RFC 9106 allows may not be the backend’s. libsodium refuses four lanes, a pepper, an 8-byte salt and a 4-byte tag with unsupported_by_backend; check the error, and name a backend that takes the value where one does.

  • Argon2i takes 3 passes or more on libsodium. RFC 9106 allows 1 and 2, which libsodium refuses with unsupported_by_backend: the attacks that trade memory for time against Argon2i are cheapest with few passes.

  • Argon2d is not for passwords. Its memory access depends on the password, which a timing attacker on the same machine can read; Argon2id is the choice for passwords.

  • Lanes are not threads. OpenSSL computes the lanes one after the other, in the calling thread (webcpp builds it without threads): four lanes give the tag RFC 9106 defines for four lanes, in the time of four times the work, not a quarter of it.

  • A secret is a pepper, not a salt. It is the same for every password and kept out of the database (in a key store or the program’s configuration); the salt stays random per password. Store neither with the tag.

  • OpenSSL’s memory on wasm32. m blocks of 1 KiB must fit a 32-bit size_t: at most 4,194,303 KiB, unsupported_by_backend beyond; a WebAssembly runtime may refuse far less, which errc::not_enough_memory reports.

  • Botan’s lanes and memory. Botan’s Argon2 takes at most 128 lanes and m of at most 8 GiB (2 GiB on wasm32), where RFC 9106 allows 224 - 1 lanes and 232 - 1 KiB: a larger value is unsupported_by_backend before Botan is called. Botan computes the lanes one after the other in the calling thread, as OpenSSL does, and takes its matrix from the C heap (calloc), which it overwrites before freeing it (Allocation).

  • The shortest tag. RFC 9106 allows 4 bytes, which OpenSSL and Botan produce; libsodium’s shortest is 16. A password hash wants 16 or more.

Table 33. Who implements kdfs::argon2d, kdfs::argon2i, kdfs::argon2id (RFC 9106, every parameter)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

kdfs::argon2d

openssl (partial: m above 4,194,303 KiB on wasm32: OpenSSL sizes Argon2’s memory, m blocks of 1 KiB, in a size_t)

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

kdfs::argon2d

botan (with exceptions only) (partial: more than 128 lanes, or m above 8 GiB (2 GiB on wasm32): Botan’s Argon2 limits (argon2pwhash.cpp))

/third_party//botan

native, emscripten

-

no

kdfs::argon2i

sodium (partial: fewer than 3 passes, more than one lane, a secret, associated data, a salt other than 16 bytes or a tag under 16 bytes: libsodium’s crypto_pwhash_argon2i takes none of them)

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

kdfs::argon2i

openssl (partial: m above 4,194,303 KiB on wasm32: OpenSSL sizes Argon2’s memory, m blocks of 1 KiB, in a size_t)

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

kdfs::argon2i

botan (with exceptions only) (partial: more than 128 lanes, or m above 8 GiB (2 GiB on wasm32): Botan’s Argon2 limits (argon2pwhash.cpp))

/third_party//botan

native, emscripten

-

not stated

kdfs::argon2id

sodium (partial: more than one lane, a secret, associated data, a salt other than 16 bytes or a tag under 16 bytes: libsodium’s crypto_pwhash_argon2id takes none of them)

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

kdfs::argon2id

openssl (partial: m above 4,194,303 KiB on wasm32: OpenSSL sizes Argon2’s memory, m blocks of 1 KiB, in a size_t)

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

kdfs::argon2id

botan (with exceptions only) (partial: more than 128 lanes, or m above 8 GiB (2 GiB on wasm32): Botan’s Argon2 limits (argon2pwhash.cpp))

/third_party//botan

native, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • botan:

    • Botan 3.14.1: doc/api_ref/pbkdf.rst states that Argon2i’s memory accesses are independent of the data and Argon2id’s depend on it after the first half of the first pass, and states no constant-time property.

    • Botan 3.14.1: doc/api_ref/pbkdf.rst warns that Argon2d accesses memory at addresses which depend on the password, and so may leak information about the password via cache-based side channels.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_KDF-ARGON2.pod states that Argon2i’s memory accesses are independent of the data and Argon2d’s depend on it, and states no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

kdfs::argon2d has no default backend: the call names one of its backends, as its second template argument (The default backend).

The default of kdfs::argon2i and kdfs::argon2id: sodium on every target, whatever the program links; botan, openssl only where the call names it, as its second template argument (The default backend).

scrypt

scrypt (Percival, 2009; RFC 7914) was the first memory-hard password hash: it fills a buffer of 128 r N bytes with Salsa20/8 and then reads it in an order that depends on the data, so that an attacker without the memory recomputes it again and again. Its costs are cost, RFC 7914’s N (the memory and time, a power of two), block_size, its r, and parallelism, its p. Ethereum’s keystore files and many disk and backup encryption tools use it. libsodium, which hash runs, recommends Argon2id unless a format demands scrypt. scrypt runs libsodium’s by default, and OpenSSL’s where the call names backends::openssl (native, wasip2 and wasip3), with OpenSSL’s own memory limit lifted:

#include "hex.hpp"

#include <webcpp/hash/scrypt.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    // N is the CPU and memory cost (a power of two), r the block size and p the parallelism: the
    // memory is 128 r N bytes, 1 MiB here. A real password hash uses a larger N.
    std::array<std::uint8_t, 64> key{};
    auto const done = webcpp::hash::scrypt(key, example::bytes("password"), example::bytes("NaCl"),
                                           {.cost = 1024, .block_size = 8, .parallelism = 16});
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "scrypt " << example::hex(key) << '\n';
    if (example::hex(key) !=
        "fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162"
        "2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640") {
        return 1;
    }
}
scrypt fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640
#include "hex.hpp"

#include <webcpp/hash/scrypt.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    std::array<std::uint8_t, 64> key{};
    auto const done = webcpp::hash::scrypt<webcpp::hash::backends::openssl>(
        key, example::bytes("password"), example::bytes("NaCl"),
        {.cost = 1024, .block_size = 8, .parallelism = 16});
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "scrypt " << example::hex(key) << '\n';
    if (example::hex(key) !=
        "fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162"
        "2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640") {
        return 1;
    }
}
scrypt fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640

Choosing the costs. OWASP’s minimum is N 217, r 8, p 1, which takes 128 MiB; libsodium’s interactive costs are N 214, r 8, p 1 (16 MiB), and it advises never less than 16 MiB. Tune as for Argon2id: fix the memory the program can spend, time one hash, then trade.

Pitfalls.

  • A random salt per password, the costs stored with the result, and the result compared with webcpp::secure::constant_time_equal, as for Argon2id.

  • libsodium’s own limit: N at most 4,294,967,295; hash refuses a larger one with invalid_parameters on backends::sodium.

  • OpenSSL’s own limits: r p below 224 (invalid_parameters), and a password, salt or output of at most INT_MAX bytes (input_too_long, invalid_output_size): its PBKDF2 takes each length as an int. OpenSSL refuses by default a scrypt that needs more than 1,025 MiB; hash lifts that limit, so that backends::openssl computes every cost libsodium does, as far as the memory goes.

  • Botan’s own limits: N at most 222, r at most 256, p at most 1,024 and a buffer of at most 8 GiB and 2 MiB (2 GiB and 2 MiB on wasm32), each unsupported_by_backend on backends::botan before Botan is called; within them it gives libsodium’s and OpenSSL’s bytes (Every parameter of Argon2: argon2 shows a call).

  • Memory on Emscripten. The buffer grows the program’s memory past Emscripten’s 16 MiB; /third_party//sodium and /third_party//botan link with -sALLOW_MEMORY_GROWTH=1 for it.

Table 34. Who implements scrypt (RFC 7914)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

scrypt

sodium

/third_party//sodium

native, wasip2, wasip3, emscripten

-

not stated

scrypt

openssl (partial: r p of 2^24 or more, or a password, salt or output of more than INT_MAX bytes: OpenSSL passes them to PBKDF2, whose lengths are ints)

/webcpp/hash//openssl

native, wasip2, wasip3

-

not stated

scrypt

botan (with exceptions only) (partial: N above 2^22, r above 256, p above 1,024, or more than 8 GiB and 2 MiB of memory (2 GiB and 2 MiB on wasm32): Botan’s scrypt limits (scrypt.cpp))

/third_party//botan

native, emscripten

-

no

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/pbkdf.rst warns that scrypt by design accesses memory at addresses which depend on the password, and so may leak information about the password via cache-based side channels.

  • openssl: OpenSSL 3.5.9: doc/man7/EVP_KDF-SCRYPT.pod states no constant-time property.

  • sodium: libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

The default of scrypt: sodium on every target, whatever the program links; botan, openssl only where the call names it, as its only template argument (The default backend).

bcrypt and bcrypt_pbkdf

bcrypt (Provos and Mazieres, 1999) is OpenBSD’s password hash: 2cost rounds of Blowfish’s key schedule over the password and a 16-byte salt, written as a modular crypt string of 60 characters, $2b$, the cost in two digits, then the salt and the hash in bcrypt’s base 64, which many systems store: web frameworks’ user tables, .htpasswd files, some systems’ password files. Its key schedule needs 4 KiB of fast memory per guess, which makes hardware attacks costlier than against PBKDF2, though far less than Argon2id’s megabytes do. bcrypt_pbkdf is OpenBSD’s key derivation over bcrypt’s hash, with which OpenSSH encrypts its private key files: each round runs bcrypt’s hash over the SHA-512 digests of the password and the salt, and the output’s blocks are interleaved, so that an attacker must compute them all. Both are on backends::botan alone (#include <webcpp/hash/bcrypt.hpp>), with no default: the call names the backend and the program links /third_party//botan, natively or on Emscripten, with exceptions. For a new design Argon2id is the better choice (Argon2id); bcrypt is here to make and check the strings systems already store, and bcrypt_pbkdf to read and write OpenSSH’s keys.

This section adapts the guidance of Botan’s documentation on bcrypt (doc/api_ref/passhash.rst of Botan 3.14.1, BSD-2-Clause licence, kept in NOTICE.md), in hash’s own terms.

#include "hex.hpp"

#include <webcpp/hash/bcrypt.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <string_view>
#include <vector>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::botan;

    // The salt is the caller's: 16 bytes, here those "CCCCCCCCCCCCCCCCCCCCC." encodes.
    auto const salt = example::from_hex("10410410410410410410410410410410");
    std::array<char, hash::bcrypt_hash_size> stored{};
    if (!hash::bcrypt<botan>(stored, example::bytes("U*U"), salt, {.cost = 5, .version = 'a'})) {
        return 1;
    }
    std::string_view const text(stored.data(), stored.size());
    std::cout << "bcrypt " << text << '\n';
    if (text != "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW") {
        return 1;
    }

    // Verifying reads the cost and the salt from the string.
    auto const right = hash::bcrypt_verify<botan>(example::bytes("U*U"), text);
    auto const wrong = hash::bcrypt_verify<botan>(example::bytes("U*V"), text);
    if (!right || !wrong) {
        return 1;
    }
    std::cout << "U*U " << (*right ? "matches" : "does not match") << ", U*V "
              << (*wrong ? "matches" : "does not match") << '\n';

    // bcrypt reads 72 bytes, and OpenBSD's stops at a zero byte: both are refused, never cut.
    std::vector<std::uint8_t> const long_password(73, 'a');
    std::array<std::uint8_t, 3> const with_zero{'a', 0, 'b'};
    std::cout << "73 bytes: " << hash::bcrypt<botan>(stored, long_password, salt).error().message()
              << '\n';
    std::cout << "a zero byte: " << hash::bcrypt<botan>(stored, with_zero, salt).error().message()
              << '\n';

    // bcrypt_pbkdf, the key derivation of OpenSSH's encrypted private keys.
    std::array<std::uint8_t, 32> key{};
    if (!hash::bcrypt_pbkdf<botan>(key, example::bytes("password"), example::bytes("salt"), 12)) {
        return 1;
    }
    std::cout << "bcrypt_pbkdf " << example::hex(key) << '\n';
    return *right && !*wrong ? 0 : 1;
}
bcrypt $2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW
U*U matches, U*V does not match
73 bytes: an input is longer than the function accepts
a zero byte: a parameter is outside the function's limits
bcrypt_pbkdf 1ae42c05d487bc02f64921a4ebe4ea93bcacfe135fda99974c06b7b01fae149a

Choosing the cost. Each step of the cost doubles the work: a cost of 12 takes about twice as long as 11. OWASP asks for 10 or more where bcrypt must be used; the default of bcrypt_parameters is 12. Time one hash on the server, as for Argon2id, and raise the cost as the hardware grows: bcrypt_verify reads the cost from the string, so a program can check an old string and store a new one at a higher cost once the password is right.

Pitfalls.

  • 72 bytes, and no zero byte. bcrypt reads at most 72 bytes of a password: most implementations silently ignore the rest, and many stop at the first zero byte, as OpenBSD’s C does, where Botan reads past it. hash refuses rather than give a string another implementation would not: a longer password is input_too_long, one with a zero byte invalid_parameters, in bcrypt and in bcrypt_verify. To take longer passwords, hash the password first (SHA-256 through digest_of) and give bcrypt the digest written in hexadecimal or base 64, never its raw bytes, which may hold a zero; every side does the same. A program that checks strings another implementation made by cutting a longer password passes the first 72 bytes: the answer is the same.

  • The salt is the caller’s. hash draws no random byte: bcrypt takes the 16 bytes of salt it writes into the string, which a program draws from webcpp::crypto::random_device for each password. A fixed salt lets one guess test every user at once.

  • Botan’s cost stops at 18. The format allows 4 to 31; Botan computes at most 18, and bcrypt or bcrypt_verify answers a higher cost with unsupported_by_backend before Botan is called.

  • Blowfish’s tables are indexed by the password. Botan’s documentation warns that bcrypt’s key schedule reads key-dependent tables, likely open to cache timing attacks by a program on the same machine, and that no constant-time bcrypt is available. Argon2id is the answer where that matters.

  • Compare through bcrypt_verify. It recomputes the hash and compares in constant time; comparing two strings with == leaks how many leading characters match. The versions $2a$, $2b$ and $2y$ are one algorithm for every password hash takes; bcrypt writes the version asked for.

  • bcrypt_pbkdf’s rounds are its cost. Each round costs a bcrypt hash of 64 key-schedule rounds; OpenSSH writes 16 rounds by default, and a passphrase protects the key only as much as those rounds and its own entropy do. The output is at most 1,024 bytes and the salt at most 1 MiB, OpenBSD’s limits.

Table 35. Who implements bcrypt (Provos and Mazieres, A Future-Adaptable Password Scheme (USENIX 1999), as OpenBSD’s bcrypt(3) writes it)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

bcrypt

botan (with exceptions only) (partial: a cost above 18: Botan’s limit (bcrypt.cpp), where bcrypt’s format allows 31)

/third_party//botan

native, emscripten

-

no

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/passhash.rst warns that bcrypt is built on Blowfish, which uses key-dependent tables indexed by secret data, and is thus likely vulnerable to cache-based side channels; no constant-time implementation is available.

bcrypt has no default backend: the call names one of its backends, as its only template argument (The default backend).

Table 36. Who implements bcrypt_pbkdf (OpenBSD’s bcrypt_pbkdf(3), as OpenSSH’s private keys use it)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

bcrypt_pbkdf

botan (with exceptions only)

/third_party//botan

native, emscripten

-

no

What each backend states on constant time, as the capability table read it:

  • botan: Botan 3.14.1: doc/api_ref/pbkdf.rst warns that Bcrypt-PBKDF is built on Blowfish, which uses key-dependent tables indexed by secret data, and is thus likely vulnerable to cache-based side channels; no constant-time implementation is available.

bcrypt_pbkdf has no default backend: the call names one of its backends, as its only template argument (The default backend).

Hashes that are not cryptographic

A hash table, a cache key, a checksum that catches a corrupted disk block and a shard chosen from a user id all need a hash that is fast and spreads its inputs evenly, and none of them needs to resist someone who chooses inputs on purpose. For those uses FNV-1a, xxHash, XXH3, MurmurHash3 and SpookyHash are many times faster than any cryptographic digest. hash re-exports Boost.Hash2’s, and with them hash_append, which feeds a whole value, a struct field by field or a container element by element, to any hash of this page.

Table 37. What each of "Hashes that are not cryptographic" is
Name Output Security Standard Status In the browser (WebCrypto)

fnv1a_32

32 bits

none: an adversary finds collisions at will

FNV-1a

not cryptographic

no

fnv1a_64

64 bits

none: an adversary finds collisions at will

FNV-1a

not cryptographic

no

xxhash_32

32 bits

none

xxHash32

not cryptographic

no

xxhash_64

64 bits

none

XXH64

not cryptographic

no

xxh3_128

128 bits

none

XXH3

not cryptographic

no

murmur3_32

32 bits

none

MurmurHash3

not cryptographic

no

murmur3_128

128 bits

none

MurmurHash3

not cryptographic

no

spooky2_128

128 bits

none

SpookyHash V2

not cryptographic

no

Table 38. How to choose among "Hashes that are not cryptographic"
Name Fastest natively Smallest on Emscripten Where it is used Choose it when

fnv1a_32

1,083 MiB/s (hash2)

5,612 bytes (hash2)

the IETF draft that specifies it

Small tables and identifiers no adversary chooses.

fnv1a_64

1,095 MiB/s (hash2)

5,621 bytes (hash2)

the IETF draft that specifies it

Tables and identifiers no adversary chooses.

xxhash_32

13,514 MiB/s (hash2)

6,369 bytes (hash2)

xxHash’s own repository

Fast checksums against accidents on 32-bit targets.

xxhash_64

26,846 MiB/s (hash2)

6,757 bytes (hash2)

Zstandard’s frame checksum

Fast checksums against accidents, as Zstandard’s.

xxh3_128

33,947 MiB/s (hash2)

10,431 bytes (hash2)

xxHash’s own repository

Checksums and identifiers of large data no adversary chooses.

murmur3_32

3,308 MiB/s (hash2)

6,099 bytes (hash2)

its author’s SMHasher

To match existing data that uses it.

murmur3_128

8,296 MiB/s (hash2)

6,315 bytes (hash2)

its author’s SMHasher

To match existing data that uses it.

spooky2_128

22,325 MiB/s (hash2)

8,388 bytes (hash2)

its author’s page

To match existing data that uses it.

The measured columns are doc/measurements.json’s, a reference measured on 2026-11-16 on Apple M5 Max that decides nothing: the native throughput over 1 MiB, or the time of one derivation over hmac_sha2_256, of the fastest backend, and the smallest Emscripten program that calls the function; Measured size and throughput has every backend on every target.

FNV-1a, xxHash, XXH3, MurmurHash3, SpookyHash

FNV-1a multiplies and XORs a byte at a time: tiny, slow on long inputs, good for short keys. xxHash32 and XXH64 (Collet) read 16 or 32 bytes per step; XXH64 is Zstandard’s frame checksum. XXH3 is xxHash’s newer design; which of them is fastest on large data depends on the target (Measured size and throughput). MurmurHash3 (Appleby) and SpookyHash V2 (Jenkins) are older hashes kept to read data that already uses them.

#include <webcpp/hash/algorithms.hpp>

#include <boost/hash2/flavor.hpp>

#include <cstdint>
#include <iomanip>
#include <iostream>
#include <string>
#include <string_view>

namespace {

struct reading {
    std::uint32_t sensor;
    std::int16_t celsius;
    std::string label;
};

}  // namespace

int main() {
    std::cout << std::hex << std::setfill('0');

    std::string_view const text = "abc";
    webcpp::hash::fnv1a_64 plain;
    plain.update(text.data(), text.size());
    std::cout << "fnv1a_64(abc) " << std::setw(16) << plain.result() << '\n';

    // hash_append feeds a value's bytes, field by field: the struct's padding bytes are never
    // hashed, and a string's size follows it, so that "ab" then "c" differs from "a" then "bc".
    // The flavor fixes the byte order: the same bytes, and the same hash, on every target.
    reading const r{.sensor = 1000, .celsius = -7, .label = "abc"};
    webcpp::hash::fnv1a_64 fields;
    boost::hash2::little_endian_flavor const flavor;
    webcpp::hash::hash_append(fields, flavor, r.sensor);
    webcpp::hash::hash_append(fields, flavor, r.celsius);
    webcpp::hash::hash_append(fields, flavor, r.label);
    std::cout << "reading " << std::setw(16) << fields.result() << '\n';
}
fnv1a_64(abc) e71fa2190541574b
reading 2319bd4b66f554b3

Pitfalls.

  • Never where an adversary chooses the input. Collisions of every function here can be computed at will: a table keyed by them, filled from the network, is open to hash flooding. Use SipHash (SipHash) there.

  • Never as a security check. A checksum detects a flipped bit, not a replaced file: an attacker who changes the file recomputes the checksum. Use a digest, and a MAC or a signature when the attacker could replace the digest too.

  • Fix the byte order of what is hashed. A struct hashed as raw memory includes its padding and the machine’s byte order; hash_append with little_endian_flavor (or big_endian_flavor) gives the same bytes, and the same hash, on every target.

Table 39. Who implements fnv1a_32 to spooky2_128, 8 names (FNV-1a, xxHash, XXH3, MurmurHash3, SpookyHash V2)
Function Backend The program’s Jamfile names Targets Hmacs Constant time

fnv1a_32

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

fnv1a_64

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

xxhash_32

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

xxhash_64

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

xxh3_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

murmur3_32

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

murmur3_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

spooky2_128

hash2

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

-

not stated

What each backend states on constant time, as the capability table read it:

  • hash2: Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

One backend, hash2: the types take no backend.

Asynchronous calls

Many programs are built around an event loop: a server that answers thousands of connections on a few threads, a browser page, a chat client that keeps its window responsive. Such a program must never wait inside a handler, because every other connection, every click and every animation waits with it. A password hash is made to be slow: Argon2id at libsodium’s interactive costs takes a large fraction of a second, and called inside a handler it freezes everything else for that long, once per login. An attacker who sends many logins at once can then stall the whole service.

<webcpp/hash/async.hpp> gives the functions of hash an asynchronous form in webcpp::asio’s model: each starts the work and returns at once, and its completion arrives later through the event loop, with a boost::system::error_code. Each takes any completion token: a callback, use_awaitable for co_await in Asio, Cobalt’s use_op, use_future. A program names /webcpp/asio//asio in its Jamfile and includes the header by itself: <webcpp/hash.hpp> leaves it out, so that a program without an event loop does not build webcpp::asio.

The functions come in two kinds:

  • The heavy functions, async_argon2id, async_argon2, async_scrypt, async_pbkdf2, async_bcrypt, async_bcrypt_pbkdf and async_bcrypt_verify, run the work on another thread, on an executor the program gives (the executor of a webcpp::asio::thread_pool), and complete on the event loop. They exist only where the build has threads.

  • The cheap functions, async_digest, async_hmac, async_hkdf_extract, async_hkdf_expand and async_hkdf (each HKDF function also over byte pieces), cost microseconds: they run at once and complete through the event loop, never inside the call. They exist on every target, for the algorithms the browser’s WebCrypto has (SHA-1, SHA-256, SHA-384, SHA-512, and HMAC and HKDF over them), so that a program written once against WebCrypto’s family builds and runs everywhere.

Each runs, by default, on the synchronous function’s backend (The default backend): backends::webcrypto, the browser’s WebCrypto, is used only when the type names it, on Emscripten (WebCrypto in the browser).

An asynchronous function sets DIT (data-independent timing) where its synchronous function does (Data-independent timing (DIT)), on the thread that computes: a heavy function’s synchronous function runs on a thread of the executor’s pool, inside its own guard, and gives that thread its DIT back when it returns; a cheap one’s runs at once on the calling thread, inside its guard. The initiating function holds no guard of its own, and async_digest computes an unkeyed digest, which sets none. On backends::webcrypto the browser’s JavaScript engine computes, on a target where the guard does nothing, and nothing is added.

The heavy functions on another thread

The program keeps a thread pool for the slow work, and binds the completion to its event loop with bind_executor, so that the handler runs on the loop’s thread. Here a timer of 1 ms on the loop fires while an Argon2id of 64 MiB is outstanding on the pool. The pool’s only thread first waits for a latch that the timer’s handler opens, and the derivation is queued behind that wait, so that the loop runs before the work does and the order is the program’s, never the scheduler’s:

#include "hex.hpp"

#include <webcpp/hash/argon2.hpp>
#include <webcpp/hash/async.hpp>

#include <webcpp/asio/bind_executor.hpp>
#include <webcpp/asio/io_context.hpp>
#include <webcpp/asio/post.hpp>
#include <webcpp/asio/steady_timer.hpp>
#include <webcpp/asio/thread_pool.hpp>

#include <boost/system/error_code.hpp>

#include <array>
#include <chrono>
#include <cstdint>
#include <iostream>
#include <latch>

int main() {
    auto const salt = example::from_hex("000102030405060708090a0b0c0d0e0f");
    auto const password = example::bytes("correct horse battery staple");

    webcpp::asio::io_context loop;
    webcpp::asio::thread_pool pool(1);
    std::array<std::uint8_t, 32> tag{};
    bool ticked = false;

    // The pool's only thread first waits for the timer's handler, so that the derivation, queued
    // behind it, cannot finish before the loop has run, however late the loop's thread is.
    std::latch tick(1);
    webcpp::asio::post(pool.get_executor(), [&tick] { tick.wait(); });

    // The work runs on the pool's thread; bind_executor brings the completion back to the loop's.
    webcpp::hash::async_argon2id(
        pool.get_executor(), tag, password, salt, webcpp::hash::argon2id_interactive,
        webcpp::asio::bind_executor(loop.get_executor(), [&](boost::system::error_code code) {
            if (code) {
                std::cerr << code.message() << '\n';
                return;
            }
            std::cout << "argon2id " << example::hex(tag) << '\n';
            std::cout << "the loop ran meanwhile: " << (ticked ? "yes" : "no") << '\n';
        }));

    webcpp::asio::steady_timer timer(loop, std::chrono::milliseconds(1));
    timer.async_wait([&](boost::system::error_code code) {
        ticked = !code;
        tick.count_down();
    });
    loop.run();  // lint-run: the program's event loop
    pool.join();
}
argon2id c05ce4c4dd7e0e45ee6011cc59d068ade47df1b01fc0cf9cd4678bdf68a5b7b0
the loop ran meanwhile: yes

The function checks its guards first, as argon2id does; a refusal (for async_argon2id, a salt of another size than 16 bytes) is posted to the handler’s executor with its error, and nothing waits for the pool. Then the work runs on a thread of the pool, and the completion is dispatched to the handler’s associated executor; while the operation is pending, the event loop has work, so its run does not return early. The result is the synchronous function’s, byte for byte.

Where the build has threads, WEBCPP_HASH_HAS_THREADS is defined:

Target The heavy functions

Native

Always: every native build has threads, b2’s default threading=single included. A program that must never start work on another thread defines WEBCPP_HASH_NO_THREADS.

Emscripten

With -pthread, which b2’s threading=multi adds: each thread of the pool is a Web Worker. A page needs cross-origin isolation for workers to share memory (MDN, SharedArrayBuffer’s security requirements); under node they run as they are. A program that blocks its main thread (run, join) links -sPTHREAD_POOL_SIZE=<n> so that the workers start before it blocks. The completion reaches the page’s thread through the handler’s executor: an io_context run there, or the executor of webcpp::asio::browser::main_thread_context, whose handlers run as browser callbacks (bind it with bind_executor; the handler must not run an io_context itself).

wasip2, wasip3

Never: wasip2 has no threads, and wasip3’s threads are cooperative, so the work would still block the loop. Call the synchronous function.

Without threads each name still exists, as a template whose call stops the build with "webcpp::hash: async_argon2id runs on another thread and needs a build with threads (…​). Without threads, call argon2id.", so that a program never blocks its loop under an asynchronous name.

Pitfalls.

  • The spans are the caller’s until the completion. The output, the password and the salt are read and written on the pool’s thread after the call has returned: keep them alive, and do not touch the output, until the handler runs. The parameters are copied.

  • Bind the completion to the loop. Without bind_executor the handler runs on the pool’s thread, by Asio’s rule (the handler’s associated executor, else the one the call was given); code that touches the loop’s state from there races with it.

  • Cancellation does not interrupt the work. A cancellation through the handler’s slot before the work starts completes at once with operation_aborted, even when every thread of the pool is busy, and the work never runs (on the handler’s executor: a handler not bound to the loop’s completes on the pool, and so waits for one of its threads); after it starts, a terminal or partial cancellation lets the work run to its end (libsodium cannot be interrupted), then the output is zeroed and the completion is operation_aborted; a total one is then ignored, since zeroing the output is a side effect. The completion runs on the handler’s associated executor, and the signal is emitted there too, as Asio’s slots require: bind the loop’s executor with bind_executor and emit from the loop, never from another thread. The signal must outlive the call until its handler is called or destroyed: the operation clears its slot then, so declare the signal before the io_context and the pool, which are then destroyed first.

  • A call that never completes destroys its handler. A pool destroyed with the work still queued, or an event loop destroyed with the completion queued, destroys the handler without calling it and gives its storage back, as Asio does for any operation: a use_future future then reports a broken promise.

  • A pool sized for the costs. Each Argon2id holds its memory on its thread until it ends: a pool of n threads can hold n times the memory at once. Size the pool to the memory the program may spend, not to the number of logins.

  • use_future without exceptions. An error completes a future with an exception; a program built without exceptions reads errors with a callback or as_tuple.

  • The storage is the handler’s. The operation’s state and its completion are allocated with the handler’s associated allocator (bind_allocator), as every Asio operation’s are, and all of it is given back before the handler runs, a cancellation’s completion included; the pool allocates the job it queues as Asio does. webcpp’s own code calls neither operator new nor the C allocator.

bcrypt on another thread

async_bcrypt, async_bcrypt_pbkdf and async_bcrypt_verify are the heavy forms of bcrypt’s three functions (bcrypt and bcrypt_pbkdf), on backends::botan, the one backend that has them, named in the call as for the synchronous ones. They exist where the build has threads and Botan is built: natively, and on Emscripten with -pthread, in a program built with exceptions that links /third_party//botan. async_bcrypt and async_bcrypt_pbkdf complete with a boost::system::error_code, as the others; async_bcrypt_verify completes with void(boost::system::error_code, bool), the bool true when the password gives the string. A login server makes the string of a new password on its pool, then checks a password typed later against it:

#include "hex.hpp"

#include <webcpp/hash/async.hpp>
#include <webcpp/hash/bcrypt.hpp>

#include <webcpp/asio/bind_executor.hpp>
#include <webcpp/asio/io_context.hpp>
#include <webcpp/asio/thread_pool.hpp>

#include <boost/system/error_code.hpp>

#include <array>
#include <iostream>
#include <string_view>

int main() {
    namespace hash = webcpp::hash;
    using hash::backends::botan;
    auto const salt = example::from_hex("10410410410410410410410410410410");
    auto const password = example::bytes("U*U");

    webcpp::asio::io_context loop;
    webcpp::asio::thread_pool pool(1);
    std::array<char, hash::bcrypt_hash_size> stored{};
    std::string_view const text(stored.data(), stored.size());

    // The work runs on the pool's thread; bind_executor brings each completion back to the loop.
    hash::async_bcrypt<botan>(
        pool.get_executor(), stored, password, salt, {.cost = 5, .version = 'a'},
        webcpp::asio::bind_executor(loop.get_executor(), [&](boost::system::error_code code) {
            if (code) {
                std::cerr << code.message() << '\n';
                return;
            }
            std::cout << "bcrypt " << text << '\n';
            hash::async_bcrypt_verify<botan>(
                pool.get_executor(), password, text,
                webcpp::asio::bind_executor(
                    loop.get_executor(), [](boost::system::error_code checked, bool same) {
                        if (checked) {
                            std::cerr << checked.message() << '\n';
                            return;
                        }
                        std::cout << "verified: " << (same ? "yes" : "no") << '\n';
                    }));
        }));
    loop.run();  // lint-run: the program's event loop
    pool.join();
}
bcrypt $2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW
verified: yes

Pitfalls.

  • The guards run first, on the caller’s thread. A password of more than 72 bytes, one with a zero byte, a salt of another size than 16 bytes, a string not of bcrypt’s form or a cost above Botan’s 18 completes at once through a post with the synchronous function’s error, the output untouched, and nothing waits for the pool.

  • A failed verification is not an error. A wrong password completes with an empty code and false; an error (a refused password, a malformed string, a cancellation) completes with its code and false. Read the code first.

  • The string is the caller’s until the completion. async_bcrypt_verify reads the std::string_view on the pool’s thread: keep its characters alive, as the spans of every heavy function.

  • A cancellation zeroes the output. As for the other heavy functions, a cancellation after the work started lets it run to its end, then zeroes the string or the key and completes with operation_aborted; Botan cannot be interrupted.

The cheap functions through the event loop

async_digest, async_hmac, async_hkdf_extract, async_hkdf_expand and async_hkdf run the synchronous function at once, its guards first, and post the completion, with its error code, to the executor the call gives, whence it reaches the handler’s associated executor. The completion never runs inside the call, so a handler written for the browser’s WebCrypto, which always completes later, behaves the same on every target:

#include "hex.hpp"

#include <webcpp/hash/async.hpp>
#include <webcpp/hash/hmac.hpp>

#include <webcpp/asio/io_context.hpp>

#include <boost/system/error_code.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    auto const input_key_material =
        example::from_hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
    auto const salt = example::from_hex("000102030405060708090a0b0c");
    auto const application_info = example::from_hex("f0f1f2f3f4f5f6f7f8f9");

    webcpp::asio::io_context loop;
    // The spans are the program's until the completion: output_key_material and the inputs outlive
    // the loop's run.
    std::array<std::uint8_t, 42> output_key_material{};
    bool returned = false;
    webcpp::hash::async_hkdf<webcpp::hash::hmac_sha2_256>(
        loop.get_executor(), output_key_material, salt, input_key_material, application_info,
        [&](boost::system::error_code code) {
            if (code) {
                std::cerr << code.message() << '\n';
                return;
            }
            std::cout << "okm " << example::hex(output_key_material) << '\n';
            std::cout << "completed after the call returned: " << (returned ? "yes" : "no") << '\n';
        });
    returned = true;
    loop.run();  // lint-run: the program's event loop
}
okm 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865
completed after the call returned: yes

async_hmac takes a Boost.Hash2 hmac, as async_hkdf does (async_hmac<hmac_sha2_256>), and computes the tag of mac<macs::hmac<digests::sha2_256>>. A digest or an hmac WebCrypto lacks, as async_digest<digests::blake2b>, stops the build: a post would add nothing to the synchronous function.

HKDF’s three asynchronous functions are those of HKDF, the pseudorandom key written into a span of the digest’s size: async_hkdf_extract(completion_executor, pseudorandom_key, salt, input_key_material, completion_token), async_hkdf_expand(completion_executor, output_key_material, pseudorandom_key, application_info, completion_token) and async_hkdf(completion_executor, output_key_material, salt, input_key_material, application_info, completion_token). Each also has a form over byte_pieces (HKDF over pieces), with no limit on the pieces, whose inputs are read in the call: on a synchronous backend the synchronous function over pieces runs in the call itself and only its error code is posted, and on backends::webcrypto the salt, the pseudorandom key and the pieces are copied into JavaScript memory in the call. So a braced list written at the call, whose array dies at the end of the call’s full expression, is safe with every completion token, a lazy one included: async_hkdf(executor, key, salt, {hpke_v1, suite_id, extract_label, ikm}, {length, hpke_v1, suite_id, expand_label, info}, token) runs one HPKE LabeledExtract and one LabeledExpand in one asynchronous call. hkdf_pieces.cpp (HKDF over pieces) calls hkdf_extract and hkdf_expand apart instead, since HPKE’s key schedule expands one secret three times.

Pitfalls.

  • The storage is the handler’s. The post allocates with the handler’s associated allocator (bind_allocator), as every Asio operation does; a program that counts or pools its allocations binds its own.

  • The same spans rule. The output and the inputs are the caller’s until the completion, even though the work runs before the call returns: a backend named in the type may run later (WebCrypto does). The forms over pieces read every input in the call, on every backend: the salt, the pseudorandom key, the pieces and their list. Only the output stays the caller’s until the completion.

  • A lazy token does not delay the forms over pieces. With asio::deferred, or the awaitable of use_awaitable, an operation normally starts when it is launched or awaited. The forms over pieces on a synchronous backend compute and write the output at the call, before the token is used; only the completion waits. A program that must not derive before the launch calls them at the launch.

  • A lone {} is ambiguous. As in the synchronous functions, {}, or a braced list of one element that is not exactly a std::span<std::uint8_t const>, in a pieces position matches both forms: async_hkdf(executor, okm, salt, {}, {}, token) does not compile. Pass an empty span, x itself or byte_pieces{...}.

  • backends::webcrypto is for Emscripten. Named off Emscripten, it stops the build: "webcpp::hash: backends::webcrypto exists only on Emscripten: name a synchronous backend, or leave the default." In a synchronous function it stops the build on every target, naming the asynchronous function to call.

WebCrypto in the browser

Every browser, and node, has a cryptography library of its own, the Web Cryptography API (crypto.subtle, W3C), usually called WebCrypto. It computes SHA-1 and SHA-2 digests, HMAC, HKDF and PBKDF2 in the browser’s native code, off the page’s thread, and answers with a JavaScript promise. A program built with Emscripten reaches it as backends::webcrypto, named in the type of an asynchronous function: nothing of it is compiled into the program, and a PBKDF2 of 600,000 iterations, the work of a login, runs while the page keeps drawing. It is never a default: the same call without it runs the synchronous default backend (The default backend), the same bytes on every target.

A password manager in the browser derives the key of its vault from the master password, then hashes a file from the key’s handler, each completion arriving through the page’s event loop:

#include "hex.hpp"

#include <webcpp/hash/async.hpp>
#include <webcpp/hash/backends/webcrypto.hpp>
#include <webcpp/hash/hmac.hpp>

#include <webcpp/asio/io_context.hpp>

#include <boost/system/error_code.hpp>

#include <array>
#include <cstdint>
#include <iostream>

int main() {
    using webcpp::hash::backends::webcrypto;
    webcpp::asio::io_context loop;

    // The spans are the program's until the completion: they outlive the loop's run.
    auto const password = example::bytes("correct horse battery staple");
    auto const salt = example::bytes("per-user salt 01");
    auto const file = example::bytes("abc");
    std::array<std::uint8_t, 32> vault_key{};
    std::array<std::uint8_t, 32> id{};

    // The vault's key first; the file's hash once the key is there, from the key's handler.
    webcpp::hash::async_pbkdf2<webcpp::hash::hmac_sha2_256, webcrypto>(
        loop.get_executor(), vault_key, password, salt, 600000,
        [&](boost::system::error_code code) {
            if (code) {
                std::cerr << code.message() << '\n';
                return;
            }
            std::cout << "vault key " << example::hex(vault_key) << '\n';
            webcpp::hash::async_digest<webcpp::hash::digests::sha2_256, webcrypto>(
                loop.get_executor(), id, file, [&](boost::system::error_code hashed) {
                    if (hashed) {
                        std::cerr << hashed.message() << '\n';
                        return;
                    }
                    std::cout << "file id " << example::hex(id) << '\n';
                });
        });

    loop.run();  // lint-run: the program's event loop
}
vault key 5010a1c238101d3c7c8b0902a0710234ea5b4853e8776a4b2ef586bb1aa35640
file id ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

Each function checks the synchronous function’s guards first, then WebCrypto’s own limits, then the executor; a refusal is posted to the handler’s executor, the output untouched. Then it calls WebCrypto through emscripten::val (digest; or importKey, then sign or deriveBits) and awaits each promise with webcpp::asio’s browser::async_await, which keeps the operation alive until the promise settles; its bridge to JavaScript takes one block from the C library per promise, outside the handler’s allocator (Allocation). The completion copies the browser’s bytes into the output; a rejected promise, a result of another size, and a JavaScript runtime without WebCrypto are backend_failure, the output zeroed. Include <webcpp/hash/backends/webcrypto.hpp> or <webcpp/hash/async.hpp>: each brings the other.

Pitfalls.

  • The executor is the page’s io_context. The promise settles in the JavaScript event loop, and only an io_context run on the calling thread returns to it while it waits. Given the executor of a thread_pool, whose threads never return to it, the call would never complete: the build stops, or, behind any_io_executor, the call completes with invalid_parameters. Strands and type-erased executors of the io_context are accepted; behind any_io_executor, one rebound to another allocator, or a strand of a strand (make_strand(make_strand(executor))), is not, since the erasure hides its type: pass the inner strand, or the executor of the io_context. That the io_context runs on the calling thread is the program’s duty: it cannot be checked.

  • WebCrypto’s limits are narrower. The single-buffer async_hkdf runs WebCrypto’s own HKDF, deriveBits, and an application_info longer than 1,024 bytes (node’s limit, where the other backends take 32,768) completes with input_too_long. The other HKDF functions run RFC 5869’s steps on WebCrypto’s HMAC: the single-buffer async_hkdf_expand keeps the 32,768 bytes of every backend (Extract has no application info), and the forms over pieces have no limit of hash’s own, so async_hkdf over byte_pieces{input_key_material} and byte_pieces{info} takes a longer info. PBKDF2’s iteration count is at most 2^32 - 1 (invalid_iterations); an output of HKDF or PBKDF2 is at most (2^32 - 1) / 8 bytes. A program that needs more names a synchronous backend.

  • HKDF over HMAC is a promise per block. async_hkdf_extract imports the salt and signs once; async_hkdf_expand imports the pseudorandom key and signs once per digest of output; async_hkdf over pieces does both. The inputs are gathered into JavaScript memory in the call, as long as the runtime will allocate a buffer that size (backend_failure beyond), and every buffer of JavaScript that held a secret is zeroed when its promise settles. The keys WebCrypto imports (CryptoKey) cannot be zeroed, since WebCrypto has no way to, and neither can a tag that arrives after a cancellation, which is dropped unseen.

  • An empty HMAC key is one zero byte. WebCrypto refuses an empty key; HMAC pads every key with zeros to its block (RFC 2104), so the two are the same key, and webcpp passes one zero byte: the tag is the other backends’.

  • A short tag is the tag cut. async_hmac takes a tag of 10 bytes up to the digest’s size, as mac does; WebCrypto computes the whole tag and the output keeps its first bytes.

  • Cancellation does not stop the browser. A terminal or partial cancellation through the handler’s slot completes at once with operation_aborted, the output zeroed; the browser’s work still runs to its end, and its result is dropped. A total one is not honoured.

  • The spans are the caller’s until the completion. The browser reads a copy of the inputs, made when each call starts, and the output is written in the completion.

Use case: a peer-to-peer network

In a peer-to-peer network, a file-sharing app, a social protocol such as Nostr, a sync engine between devices, nobody is trusted: every peer may lie, replay or flood. Hashes are what make that workable. A piece of content named by its digest cannot be swapped by the peer that serves it; an event named by its digest cannot be altered by the relay that forwards it; two peers that agree on a secret derive their keys from it without a server; and a node that keeps tables of what peers send it keeps them in shape when a peer sends thousands of crafted keys. This chapter builds each of those from hash’s primitives.

The steps that a protocol defines (Nostr’s serialization, NIP-44’s labels) are shown as what a domain library, webcpp::nostr for example, would build from these primitives; hash has no such function. JavaScript applications do the same with paulmillr’s noble libraries: the Nostr client library nostr-tools computes event ids and NIP-44 keys with @noble/hashes. The code below is webcpp’s own.

Content addressing

The problem. A file-sharing app fetches the pieces of a file from peers it does not know. A peer that sends a corrupted or malicious piece must be caught before the piece is used.

The idea. Name the content by its digest. The name is published by whoever created the content; anybody who receives the bytes hashes them and compares: a single changed bit gives another name. BLAKE3 suits it best: its tree lets a receiver verify a large file part by part, and natively it is the fastest cryptographic digest measured here (Measured size and throughput). SHA-256 is the choice where a format names it, as Git and IPFS’s default CIDs do.

#include "hex.hpp"

#include <webcpp/hash/blake3.hpp>

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>
#include <string>
#include <vector>

namespace {

// The id of a file: its BLAKE3 hash, fed in chunks as a program reads a file, so that a file
// of any size is hashed with the memory of one chunk.
std::string id_of(std::span<std::uint8_t const> content) {
    constexpr std::size_t chunk = std::size_t{64} * 1024;
    webcpp::hash::blake3 hash;
    for (std::size_t offset = 0; offset < content.size(); offset += chunk) {
        auto const piece = content.subspan(offset, std::min(chunk, content.size() - offset));
        hash.update(piece.data(), piece.size());
    }
    return example::hex(hash.result());
}

}  // namespace

int main() {
    std::vector<std::uint8_t> content(102400);
    for (std::size_t i = 0; i < content.size(); ++i) {
        content[i] = static_cast<std::uint8_t>(i % 251);
    }

    // The sender publishes the id; the content may come from anywhere.
    auto const id = id_of(content);
    std::cout << "id " << id << '\n';
    if (id != "bc3e3d41a1146b069abffad3c0d44860cf664390afce4d9661f7902e7943e085") {
        return 1;
    }

    // A receiver recomputes the id of what it got. The id is public, not a secret, so an
    // ordinary comparison is right here. One flipped byte gives an unrelated id.
    std::cout << "intact " << (id_of(content) == id ? "yes" : "no") << '\n';
    content[5000] ^= 1U;
    std::cout << "corrupted " << (id_of(content) == id ? "undetected" : "detected") << '\n';
}
id bc3e3d41a1146b069abffad3c0d44860cf664390afce4d9661f7902e7943e085
intact yes
corrupted detected

Mistakes. A digest of 64 bits or of a non-cryptographic hash lets a peer craft a piece with the same name; keep 256 bits. Hash the bytes as they will be used, after decompression or parsing, or a peer sends two encodings of different content with one name. The name protects the content, not its freshness: a peer can still serve an old version under its old name, which the application solves by signing the list of current names.

Nostr event ids

The problem. A Nostr event travels through relays its author does not control. A relay that changes the content, the time or the tags of an event must be caught.

The idea. NIP-01 defines the event’s id as the SHA-256 of a canonical serialization, the JSON array [0, pubkey, created_at, kind, tags, content] written with no whitespace and with fixed escaping, and the author signs the id with a BIP340 Schnorr signature (webcpp::crypto’s secp256k1). Any reader recomputes the id from the fields it received and checks the signature over it. The serialization is the protocol’s, a domain library’s job; the digest is hash’s sha2_256.

#include "hex.hpp"

#include <webcpp/hash/algorithms.hpp>

#include <cstdint>
#include <iostream>
#include <string>
#include <string_view>

namespace {

// NIP-01 escapes the line feed, the double quote, the backslash, the carriage return, the tab,
// the backspace and the form feed, and no other character: another escape would change the
// bytes that are hashed, and so the id.
std::string escape(std::string_view content) {
    std::string out;
    for (char const c : content) {
        switch (c) {
            case '\n': out += "\\n"; break;
            case '"': out += "\\\""; break;
            case '\\': out += "\\\\"; break;
            case '\r': out += "\\r"; break;
            case '\t': out += "\\t"; break;
            case '\b': out += "\\b"; break;
            case '\f': out += "\\f"; break;
            default: out += c;
        }
    }
    return out;
}

// The event's serialization for its id, with no tags.
std::string serialize(std::string_view pubkey, std::uint64_t created_at, std::uint32_t kind,
                      std::string_view content) {
    return "[0,\"" + std::string(pubkey) + "\"," + std::to_string(created_at) + "," +
           std::to_string(kind) + ",[],\"" + escape(content) + "\"]";
}

std::string id_of(std::string const& serialization) {
    webcpp::hash::sha2_256 hash;
    hash.update(serialization.data(), serialization.size());
    return example::hex(hash.result());
}

}  // namespace

int main() {
    std::string_view const pubkey =
        "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798";

    auto const text = serialize(pubkey, 1700000000, 1, "hello from webcpp");
    std::cout << "serialization " << text << '\n';
    auto const id = id_of(text);
    std::cout << "id " << id << '\n';

    // A content with a line feed and quotes goes through the escapes.
    auto const quoted = serialize(pubkey, 1700000000, 1, "say \"hi\"\nbye");
    std::cout << "escaped id " << id_of(quoted) << '\n';
}
serialization [0,"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",1700000000,1,[],"hello from webcpp"]
id e2946c8a1edeff28566f13d47c72913abf2b7423f7e0e1b58eee87aa5e72889a
escaped id b1038192ec8d1ae60481b6cff249e5c67ca0b17bfc5828921baa753b50d21c4e

Mistakes. Recomputing the id from a JSON library’s own output, whose whitespace, key order or escaping differs from NIP-01’s, gives another id and rejects valid events, or, worse, accepts an event whose id was never checked. Always recompute the id; never trust the id field a relay sends.

Keys between two peers: NIP-44

The problem. Two Nostr users want to exchange private messages. They each have a secp256k1 key pair, and nothing else in common.

The idea. Each computes the ECDH shared point from their own secret key and the other’s public key (webcpp::crypto) and keeps its x coordinate, 32 bytes that both sides compute alike but that are not a uniform key. NIP-44 version 2 turns them into a conversation key with HKDF-Extract over HMAC-SHA-256, with the salt nip44-v2, then expands a key per message with a random nonce. The salt is NIP-44’s name for its use of the secret: another protocol over the same key pair, with another salt, gets unrelated keys.

#include "hex.hpp"

#include <webcpp/hash/hkdf.hpp>
#include <webcpp/hash/hmac.hpp>

#include <iostream>

int main() {
    auto const shared_x =
        example::from_hex("c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5");

    // The key is the same for both parties of the conversation, whoever of them computes it.
    // NIP-44's later steps (expanding a key per message from a random nonce) are webcpp::nostr's.
    auto key = webcpp::hash::hkdf_extract<webcpp::hash::hmac_sha2_256>(example::bytes("nip44-v2"),
                                                                       shared_x);
    if (!key) {
        std::cerr << key.error().message() << '\n';
        return 1;
    }
    std::cout << "conversation_key " << example::hex(*key) << '\n';
}
conversation_key c41c775356fd92eadc63ff5a0dc1da211b268cbea22316767095b2871ea1412d

The example’s input is the x coordinate the two peers share when one secret key is 1 and the other public key is 2G; its output is computed independently with Python’s hmac. The message keys, the padding and the encryption of NIP-44 are webcpp::nostr’s.

Mistakes. Using the shared x coordinate directly as a key, which wastes its structure and ties every protocol on the key pair together; hashing it with a plain SHA-256 instead of the HKDF the protocol names, which gives keys no other client computes; reusing one message key for two messages.

Tables of what peers send

A node keeps sets of peer ids, of event ids it has seen, of pending requests, each keyed by values that other peers choose. With an unkeyed hash, a peer that sends ids chosen to collide turns every lookup into a scan and stalls the node. A SipHash keyed with random bytes at start-up takes that choice away: SipHash shows the table, in example/siphash.cpp.

Use case: a cryptocurrency wallet

A wallet app holds keys that move money, and its mistakes are paid in coins that no one can return. Its hashes are not chosen: each chain’s standards name them, and a wallet that computes a seed, an address or a checksum differently from every other wallet sends funds where nobody can reach them. This chapter computes the three steps every Bitcoin and Ethereum wallet takes, from the standards’ own test vectors: the seed from the recovery words, the hash of a Bitcoin public key in its address, and an Ethereum address with its checksum.

Each step is a protocol’s (BIP39, BIP141, EIP-55), and is shown as what a domain library, webcpp::bitcoin or webcpp::ethereum, would build from hash’s primitives; hash has no BIP, EIP or address function. JavaScript wallets do the same with paulmillr’s noble libraries: the Ethereum library viem computes Keccak-256 with @noble/hashes, and scure-bip39 derives BIP39 seeds with it. The code below is webcpp’s own.

The seed of a wallet: BIP39

The problem. A wallet must be recoverable from something a person can write on paper. BIP39 encodes 128 to 256 random bits as 12 to 24 words, with a checksum; the wallet then needs a 64-byte seed from the words, from which every key derives (BIP32).

The idea. The seed is PBKDF2-HMAC-SHA-512 of the words, normalised to Unicode NFKD, with the salt mnemonic followed by an optional passphrase, at 2,048 iterations. The passphrase makes a second wallet from the same words: someone who finds the paper without the passphrase finds an empty wallet. The word list, the checksum and the normalisation are webcpp::bitcoin’s; the KDF is hash’s pbkdf2.

#include "hex.hpp"

#include <webcpp/hash/hmac.hpp>
#include <webcpp/hash/pbkdf2.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <string>

int main() {
    std::string const mnemonic =
        "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon "
        "about";
    std::string const passphrase = "TREZOR";

    // The passphrase goes into the salt, so the same mnemonic with another passphrase is another
    // wallet, and nothing says the passphrase was wrong.
    std::string const salt = "mnemonic" + passphrase;

    std::array<std::uint8_t, 64> seed{};
    auto const done = webcpp::hash::pbkdf2<webcpp::hash::hmac_sha2_512>(
        seed, example::bytes(mnemonic), example::bytes(salt), 2048);
    if (!done) {
        std::cerr << done.error().message() << '\n';
        return 1;
    }
    std::cout << "seed " << example::hex(seed) << '\n';
    if (example::hex(seed) !=
        "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e5349553"
        "1f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04") {
        return 1;
    }
}
seed c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04

The words, the passphrase TREZOR and the seed are BIP39’s first English test vector.

Mistakes. 2,048 iterations do not make a weak secret strong: the words carry 128 bits or more of randomness, which is the protection, and a passphrase alone, as a "brain wallet", is guessed. Skipping the NFKD normalisation gives another seed for any word or passphrase with accents. And the seed is as secret as the words: it never leaves the device in clear.

A Bitcoin address: hash160

The problem. A Bitcoin address must be short, and must not reveal the public key until the coins are spent.

The idea. Legacy (P2PKH) and SegWit version 0 (P2WPKH) addresses commit to hash160 of the public key: RIPEMD-160 of SHA-256 of its 33 compressed bytes. The two digests together give 20 bytes, and an attacker would have to break both to substitute a key. The address’s encoding is Base58Check (An address and a key as text: Base58Check) or Bech32, the latter webcpp::bitcoin’s.

#include "hex.hpp"

#include <webcpp/hash/algorithms.hpp>

#include <iostream>

int main() {
    auto const public_key =
        example::from_hex("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798");

    // Two functions in a row: the second hashes the first's digest, not the key. Skipping the
    // SHA-256 gives a 20-byte value that no Bitcoin node computes.
    webcpp::hash::sha2_256 first;
    first.update(public_key.data(), public_key.size());
    auto const inner = first.result();

    webcpp::hash::ripemd_160 second;
    second.update(inner.data(), inner.size());
    auto const hash160 = example::hex(second.result());
    std::cout << "hash160 " << hash160 << '\n';

    if (hash160 != "751e76e8199196d454941c45d1b3a323f1433bd6") {
        return 1;
    }
}
hash160 751e76e8199196d454941c45d1b3a323f1433bd6

The public key is that of the secret key 1, the generator point of secp256k1; its hash160 is the one inside the well-known address of that key, and the example’s value is computed independently with Python.

Mistakes. Hashing the uncompressed key (65 bytes) gives another, valid but different address; wallets must agree on the form. RIPEMD-160 alone is legacy: use it only inside hash160, never for a new design (MD5, SHA-1 and RIPEMD: legacy).

An address and a key as text: Base58Check

The problem. An address or a private key is bytes, and a person copies it from a screen or a sheet of paper. One mistyped character must be caught, not sent to another address or read as another key.

The idea. Base58Check writes a payload, a version byte and the rest of the address or key, in base58 (Bitcoin’s alphabet, without 0, O, I and l) after appending the first 4 bytes of its double SHA-256. A reader recomputes the checksum and refuses the text when it differs: a mistyped text passes only with a chance of about one in four billion. hash::formats::base58_with_checksum is that format, registered into webcpp::codecs for a payload of up to 100 bytes (an address is 21, a WIF key 33 or 34, a BIP-32 extended key 78). The format gives the payload: what its version byte means is webcpp::bitcoin’s.

#include "hex.hpp"

#include <webcpp/hash/base58_with_checksum.hpp>
#include <webcpp/secure/constant_time_equal.hpp>

#include <cstdint>
#include <iostream>
#include <string>

int main() {
    namespace codecs = webcpp::codecs;
    auto const& format = webcpp::hash::formats::base58_with_checksum;

    // An address: the version byte 0 and a hash160, then the checksum is appended.
    auto const payload = example::from_hex("00f54a5851e9372b87810a8e60cdd2e7cfd80b6e31");
    auto const address = codecs::encode(format, payload);
    if (!address) {
        std::cerr << address.error().message() << '\n';
        return 1;
    }
    std::cout << "address " << address.value() << '\n';

    // A WIF key is a secret: the in-place form, a codecs::secret_bytes, holds it in the result
    // itself (no heap) and wipes it when destroyed. Decoding it with codecs::tokens::secret
    // gives a heap vector of the same secret kind.
    std::string const wif = "L5nJeqKmpHp4P7F8ZYyjwc5a7P4d8EabuGAzfGJk7yC1BJyzNaEd";
    auto const key = codecs::decode<codecs::secret_bytes<100>>(format, wif);
    if (!key) {
        std::cerr << key.error().message() << '\n';
        return 1;
    }
    auto const bytes = key.value().view();
    std::cout << "wif payload " << bytes.size() << " bytes, version "
              << example::hex(bytes.first(1)) << ", compressed flag " << example::hex(bytes.last(1))
              << '\n';

    // One character changed is a mistyped key, never another key.
    std::string typo = wif;
    typo[10] = typo[10] == '2' ? '3' : '2';
    auto const refused = codecs::decode<codecs::secret_bytes<100>>(format, typo);
    std::cout << "typo " << (refused ? "accepted" : refused.error().message()) << '\n';

    // The key is compared in place, in constant time, never copied into a text of its own.
    auto const expected_key =
        example::from_hex("ff778740f88ddcf102aeb81daee289c044c4a4571c4b6f287400f4b8e0b843f8");
    if (address.value() != "1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs" || bytes.size() != 34 ||
        !webcpp::secure::constant_time_equal(bytes.subspan(1, 32), expected_key) || refused) {
        return 1;
    }
}
address 1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs
wif payload 34 bytes, version 80, compressed flag 01
typo the checksum does not match

The address is the Bitcoin wiki’s, and the key is one of Bitcoin Core’s key_io_valid.json, whose entries the library’s test also runs.

A WIF key is a secret, and a decode with no secret token gives a public result, so the key is read into a codecs::secret_bytes<100>: it stays in the result itself, with no heap, and is wiped when the result is destroyed. codecs::decode(format, text, codecs::tokens::secret) gives a secret result too, a heap vector (codecs::secret_byte_vector) for a text of dynamic size. The decode wipes its own scratch in both forms.

Mistakes. Reading a key with the plain decode leaves its bytes in a public vector that is never wiped. A payload of more than 100 bytes, or a text of more than 143 characters, is codecs::error::input_too_long, found before any checksum is computed; a mistyped character is codecs::error::checksum_mismatch and a text with 0, O, I or l is codecs::error::invalid_character. A program links /webcpp/hash//base58_with_checksum, which adds codecs to hash’s own target (Using webcpp::hash in your Jamfile).

An Ethereum address: Keccak-256 and EIP-55

The problem. An Ethereum address is 20 bytes, typed or pasted as 40 hexadecimal digits. A single wrong digit sends funds to an address nobody holds.

The idea. The address is the last 20 bytes of the Keccak-256 of the 64-byte public key (x and y, without the prefix byte). EIP-55 adds a checksum without changing the address: each letter of the hexadecimal form is written in upper case where the same position of the Keccak-256 of the lower-case form is 8 or more. A wallet that receives a mixed-case address checks the case and refuses a typo: EIP-55 puts the chance that a mistyped address still passes at about 0.0247 percent.

#include "hex.hpp"

#include <webcpp/hash/keccak.hpp>

#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>
#include <string>

namespace {

std::string keccak_hex(std::span<std::uint8_t const> data) {
    webcpp::hash::keccak_256 hash;
    hash.update(data.data(), data.size());
    return example::hex(hash.result());
}

// EIP-55: a letter of the address is upper case when the same position of the Keccak-256 of the
// lowercase address (as ASCII text, without 0x) is 8 or more. A wallet that finds a letter in
// the wrong case knows that a character was mistyped.
std::string checksummed(std::string const& lower) {
    std::string const digest = keccak_hex(example::bytes(lower));
    std::string out = "0x";
    for (std::size_t i = 0; i < lower.size(); ++i) {
        bool const letter = lower[i] >= 'a' && lower[i] <= 'f';
        bool const upper = digest[i] >= '8';
        out += letter && upper ? static_cast<char>(lower[i] - 'a' + 'A') : lower[i];
    }
    return out;
}

}  // namespace

int main() {
    auto const public_key = example::from_hex(
        "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
        "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8");

    // The last 20 of the 32 bytes: 40 hexadecimal digits from the 24th.
    auto const lower = keccak_hex(public_key).substr(24);
    std::cout << "address 0x" << lower << '\n';

    auto const mixed = checksummed(lower);
    std::cout << "checksummed " << mixed << '\n';
    if (mixed != "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf") {
        return 1;
    }
}
address 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf
checksummed 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf

The public key is again that of the secret key 1; the address is the one every Ethereum tool gives for it, and the example’s values are computed independently with a Python Keccak.

Mistakes. SHA3-256 in place of Keccak-256 (Keccak) gives an address that exists nowhere. Accepting an all-lower-case address without a checksum is allowed by EIP-55, but a wallet should warn: it carries no protection against typos.

Use case: a login and a password manager

Two applications almost everybody uses hold the most personal secret there is, a password: the login of any web service, and the password manager that keeps all the others. Both are attacked the same way, by stealing what they store and guessing offline, as fast as the attacker’s hardware allows. This chapter builds what each stores so that a stolen copy is as costly to attack as possible, and how one key becomes many without one weak use exposing the others.

Storing passwords for a login

The problem. A service must check a user’s password at every login without keeping the password, and a copy of its database must not give the passwords away.

The idea. At registration, draw a random 16-byte salt, compute Argon2id of the password with it, and store the salt, the costs and the tag. At login, compute the tag again with the stored salt and costs, and compare it with the stored tag in constant time.

#include "hex.hpp"

#include <webcpp/crypto/random_device.hpp>
#include <webcpp/hash/argon2.hpp>
#include <webcpp/secure/constant_time_equal.hpp>

#include <boost/system/result.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <span>
#include <string_view>

namespace {

// What the application stores for a user. Without the costs in the record, the service could not
// raise them later: a login verifies an old tag with the costs that made it.
struct credential {
    std::array<std::uint8_t, webcpp::hash::argon2id_salt_size> salt{};
    webcpp::hash::argon2id_parameters costs{};
    std::array<std::uint8_t, 32> tag{};
};

// Without a salt of its own per user, one guess tests every user at once, and two users with the
// same password are visible as such. Without Argon2id's memory cost (a fast hash such as SHA-256
// instead), a GPU tries billions of guesses a second.
boost::system::result<credential> enroll(std::string_view password) {
    credential stored{};
    stored.costs = webcpp::hash::argon2id_interactive;
    auto done = webcpp::crypto::random_device{}.fill(stored.salt);
    if (!done) {
        return done.error();
    }
    done = webcpp::hash::argon2id(stored.tag, example::bytes(password), stored.salt, stored.costs);
    if (!done) {
        return done.error();
    }
    return stored;
}

// Computes the tag again from the salt and the costs that were stored, and compares it with the
// stored one. With == the comparison stops at the first different byte, and the time it takes tells
// an attacker how many leading bytes of a guess's tag are right.
boost::system::result<bool> check(credential const& stored, std::string_view password) {
    std::array<std::uint8_t, 32> candidate{};
    auto const done =
        webcpp::hash::argon2id(candidate, example::bytes(password), stored.salt, stored.costs);
    if (!done) {
        return done.error();
    }
    return webcpp::secure::constant_time_equal(candidate, stored.tag);
}

}  // namespace

int main() {
    auto stored = enroll("correct-password");
    if (!stored) {
        std::cerr << stored.error().message() << '\n';
        return 1;
    }
    std::cout << "stored a " << stored->salt.size() << "-byte salt, " << stored->costs.passes
              << " passes over " << stored->costs.memory << " bytes, and a " << stored->tag.size()
              << "-byte tag\n";

    for (std::string_view const attempt : {"correct-password", "wrong-password"}) {
        auto const ok = check(*stored, attempt);
        if (!ok) {
            std::cerr << ok.error().message() << '\n';
            return 1;
        }
        std::cout << "login " << attempt << ": " << (*ok ? "accepted" : "refused") << '\n';
    }
}
stored a 16-byte salt, 2 passes over 67108864 bytes, and a 32-byte tag
login correct-password: accepted
login wrong-password: refused

What goes wrong without each step.

  • Without a salt, two users with the same password have the same tag, and one guess tests every user; tables of precomputed hashes of common passwords work at once.

  • With a fast hash (SHA-256, MD5) instead of Argon2id, a graphics card tests billions of guesses per second: most human passwords fall in hours.

  • With == instead of webcpp::secure::constant_time_equal, the time of the comparison tells an attacker at the network how much of a guessed tag is right.

  • Without the costs in the record, the service cannot raise them later: the record must say which memory and passes made its tag, so that a login can verify an old tag and store a new one with today’s costs.

hash keeps no $argon2id$ string: the record is the program’s, three fields in its own database.

A password manager’s vault key

A password manager, an encrypted backup or an encrypted notes app turns the master password into the key that encrypts the vault. The function is the same, Argon2id (Argon2id), with heavier costs, since it runs once per session: argon2id_moderate or argon2id_sensitive, measured on the slowest device the app supports. The salt is random per vault and stored with it, in clear; the derived key is never stored. Bitwarden, for example, offers Argon2id for exactly this (its documentation is cited in the table of how to choose among the functions of Password hashing).

One key, many purposes

The problem. The vault key encrypts files, authenticates the sync with the server, and names items in an index. If the same key did all three, a flaw in one use (an index that leaks, a sync protocol with a weakness) would expose the others.

The idea. Key separation: derive one key per purpose from the master key, each bound to a label that names the purpose. HKDF-Expand (HKDF) with an info string per purpose is the standard way; BLAKE3’s derive_key with a context string (BLAKE3) does it in one call; blake2b_subkey, libsodium’s crypto_kdf, numbers the subkeys within an 8-byte context (BLAKE2b subkeys). Each derived key reveals nothing of the master key or of the other keys.

#include "hex.hpp"

#include <webcpp/hash/blake2b_subkey.hpp>
#include <webcpp/hash/hkdf.hpp>
#include <webcpp/hash/hmac.hpp>

#include <array>
#include <cstdint>
#include <iostream>
#include <span>
#include <string_view>

namespace {

// The label names the purpose: a key derived for file encryption is unrelated to the one for
// authentication, though both come from the master key.
std::array<std::uint8_t, 32> from_label(std::span<std::uint8_t const> master,
                                        std::string_view label) {
    std::array<std::uint8_t, 32> key{};
    auto const done =
        webcpp::hash::hkdf<webcpp::hash::hmac_sha2_256>(key, {}, master, example::bytes(label));
    if (!done) {
        std::cerr << done.error().message() << '\n';
        key.fill(0);
    }
    return key;
}

// The id numbers the purpose, and the context, 8 bytes, names the application: the same id in
// another application's context gives an unrelated key.
std::array<std::uint8_t, 32> from_id(std::span<std::uint8_t const> master, std::uint64_t id) {
    std::array<std::uint8_t, 32> key{};
    auto const done = webcpp::hash::blake2b_subkey(key, master, id, example::bytes("vault v1"));
    if (!done) {
        std::cerr << done.error().message() << '\n';
    }
    return key;
}

}  // namespace

int main() {
    auto const master =
        example::from_hex("404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f");

    std::cout << "hkdf file-encryption "
              << example::hex(from_label(master, "vault v1 file-encryption")) << '\n';
    std::cout << "hkdf sync-authentication "
              << example::hex(from_label(master, "vault v1 sync-authentication")) << '\n';
    std::cout << "blake2b subkey 1 " << example::hex(from_id(master, 1)) << '\n';
    std::cout << "blake2b subkey 2 " << example::hex(from_id(master, 2)) << '\n';
}
hkdf file-encryption 2e509a9b0170c0fa44b7096b1bd400b0d4dcf5bd6a981283b3e4b5587a04acb1
hkdf sync-authentication d4959679ea153ff9c3db06f5665b9f87f9081753b7a3ce0339887a914021df37
blake2b subkey 1 8aa2470393bf13f68beaf081047976653ae18a24f24c74b471fd92dc0d5170eb
blake2b subkey 2 e05c31b8eb3c9bd0a8d0c01010de01e08e42f77b99fa5657fac1623d2fbbbabb

The subkeys of part (b) are the bytes libsodium’s crypto_kdf_derive_from_key gives for the same master key, ids and context: an app whose other half uses libsodium, or a libsodium binding, derives the same keys on both sides.

Mistakes. Two purposes with the same label get the same key: write each label once, as a constant, with the application’s name and a version. Never derive a subkey from a password with these functions: the password goes through Argon2id first, and only the key it gives is split.

Domain separation

The labels above are one case of a general rule: whenever one secret, or one hash, serves two purposes, each purpose puts a distinct, fixed prefix in what it hashes, so that a value computed for one purpose is never valid for the other. HKDF’s info, BLAKE3’s context and the salt of NIP-44 do it for keys; a digest that signs two kinds of messages hashes a type tag first; NIST’s cSHAKE (SP 800-185) builds a customization string into SHAKE for the same reason, and comes to hash with XKCP’s family in a later increment.

Choosing a backend

A digest has one implementation, Boost.Hash2’s or a C library’s. A key derivation has several, its backends: the same function, giving the same bytes, in code of different size, speed and pedigree. A tag of the families (digest_of, hasher, mac, argon2) has a backend per cell of its row, and the tests compute each case on every backend that has it, pair by pair: a thousand random inputs per digest and MAC, a hundred per Argon2 variant, a partial cell refusing exactly what its row says it lacks. A call that names no backend takes the default, which is fixed: no measurement, link or define changes it. This chapter says what the default is and why, how a program names another backend, what each backend does with secrets and memory, and, from the committed data, which backend has which function on which target, and what each cost and allocated when it was measured.

The default backend

Function Default Why

hkdf_extract, hkdf_expand, hkdf, pbkdf2

hash2

the one backend that has every hmac, every operation and every target

argon2id, scrypt, blake2b_subkey

sodium

the first of the order that has them (OpenSSL and Botan have argon2id and scrypt too, never a default); a program links /third_party//sodium

kbkdf, sskdf, x963kdf, bcrypt, bcrypt_verify, bcrypt_pbkdf

none

no backend of the order has them: the call names backends::openssl or backends::botan (bcrypt and bcrypt_pbkdf: backends::botan alone)

a tag of digest_of, hasher, mac and argon2

the first of hash2, xkcp, blake3, sodium that has it

one stated rule: the backend that has the whole of the tag, else in part; none when none of the four has it, and the call names its backend

The families’ defaults follow one rule and never change: the first of backends::hash2, backends::xkcp, backends::blake3 and backends::sodium whose capability table, once increments 2 to 7 have landed, has the tag whole (every option and output size the family accepts), else the first of them that has it in part; backends::bearssl, backends::openssl, backends::botan and backends::webcrypto are never a default. SHA-2’s and SHAKE’s default is hash2, Keccak-256’s xkcp, BLAKE3’s blake3, BLAKE2b’s sodium; a tag none of the four has (SM3, Streebog, Whirlpool, Skein-512, their HMACs, Argon2d) has none, and its call names its backend. Every default has its engine: a program that does not link the default’s library gets the message that names the line to add.

The default is the same on every target, whatever the program links: linking libsodium, BearSSL, OpenSSL or Botan makes their backends available to a call that names them, never the default. backends::hash2 is the default because it is the only backend that covers every hmac, operation and target; it is header-only, so a program carries only the functions it calls and shares the SHA code it already uses for its digests; and the differences the reference measurement found for HKDF are nanoseconds natively and a few KB of an isolated program on WebAssembly (Measured size and throughput). No define chooses a default: a program that wants another backend names it in the call, as the second template argument, hkdf<hmac_sha2_256, backends::openssl>; Naming a backend shows a program that does. A backend named in a call that it lacks, or that the program does not link, stops the build with a message that says what to do (When the build stops), and so do OpenSSL on Emscripten, Botan on wasip2 and wasip3, and Botan in a program built without exceptions. default_backend<Algorithm> names the default at compile time.

What each backend does with secrets and memory

webcpp’s own code allocates nothing and wipes every secret intermediate it holds (HKDF’s blocks, PBKDF2’s accumulators, each keyed copy of an hmac, BearSSL’s context) with stores the compiler cannot remove, on success and on failure. What a C library or Boost.Hash2 does inside its own functions is beyond its reach, and this table says what it is:

Backend Its conditions

hash2

Boost.Hash2’s own temporaries are not wiped: the padded key inside the constructor of hmac and the inner digest of its result(). The digest types, and blake3 and keccak_256, do not wipe themselves on destruction.

sodium

Argon2id and scrypt allocate the memory their costs name, with mmap where the system has it, else from the C heap, outside any allocator of the program; libsodium’s sodium_init keeps its process-wide choice of implementations.

bearssl

hash wipes BearSSL’s HKDF, HMAC and hash contexts before each call returns, and the context of a hasher when it ends. BearSSL’s own temporaries on its stack, the pseudorandom key of br_hkdf_flip, the padded keys of its HMAC and the inner digest of br_hmac_out, are not wiped: they stay in the stack memory of the call until it is reused. BearSSL allocates nothing.

openssl

OpenSSL allocates a KDF and a context in every call, through its own allocator, and frees both before the call returns. It clears the key (HKDF’s IKM or PRK, PBKDF2’s password) and the info when it frees the context; it frees the salt without clearing it. A digest allocates an EVP_MD_CTX and the digest’s own context: digest_of frees both before it returns, a hasher owns them from make until it finishes, is destroyed or is moved from. A MAC allocates an EVP_MAC_CTX and the MAC’s context, which mac frees before it returns. OpenSSL documents that it cleans up and frees these contexts, not that it clears them; its HMAC, KMAC and BLAKE2 MACs clear their copy of the key (the BLAKE2 MACs’ first block, which holds it too, only once the tag is computed), and its SipHash frees its keyed state without clearing it. Its Argon2 and scrypt allocate the memory their costs name from OpenSSL’s allocator, the C heap, and free it before the call returns; Argon2 clears its copies of the password, salt, secret and associated data, scrypt its copy of the password but not of the salt. Its scrypt takes r p below 224 and a password, salt and output of at most INT_MAX bytes (invalid_parameters, input_too_long, invalid_output_size otherwise). Its Argon2 sizes the memory in a size_t: the family argon2 takes at most 4,194,303 KiB on wasm32 (unsupported_by_backend), and argon2id at most 4 TiB less 1 KiB natively (invalid_parameters). Its KMAC takes a key of 4 to 512 bytes, a customisation of at most 512 and a tag of at most 2,097,151, and its HMAC a key of at most INT_MAX bytes: mac answers others unsupported_by_backend. Its KBKDF clears its copies of the key, the label and the context when it frees its context, its one-step and X9.63 KDFs their copies of the secret and the info; kbkdf answers a key of more than INT_MAX bytes, sskdf and x963kdf a secret, an info or an output of more than 230 bytes, unsupported_by_backend. Its first call reads OpenSSL’s configuration file. It holds some lengths in an int, so hash refuses, before OpenSSL is called, a PBKDF2 output (invalid_output_size), a PBKDF2 password or salt, or an HKDF salt (input_too_long) of more than INT_MAX bytes. It is not built for Emscripten.

botan

Botan 3.14.1, natively and on Emscripten, in a program built with exceptions: Botan reports its failures by throwing, and hash catches every exception at the boundary of each call (errc::not_enough_memory for an allocation, backend_failure for anything else, the output zeroed), so that no exception leaves hash. Botan makes its objects (a hash, a MAC, a KDF, a password hash) with operator new, and the buffers that hold their state and secrets with the C library’s calloc, through its secure allocator, which overwrites each buffer before freeing it; hash clears each object it holds (the object of a hasher from make until it finishes, is destroyed or is moved from) and frees it before the call returns. Argon2’s matrix and scrypt’s buffer come from calloc too, the memory their costs name. Botan does not state that it wipes its temporaries on the stack. No RNG of Botan’s is loaded: bcrypt’s salt is the caller’s. Its HMAC takes a key of at most 8,192 bytes and its KMAC of at most 192, its Argon2 at most 128 lanes and 8 GiB (2 GiB on wasm32), its scrypt N of at most 222, its bcrypt a cost of at most 18, and its PBKDF2 and KDF2 at most 232 - 2 blocks: hash hashes a longer HMAC key first, as RFC 2104 does, and refuses the others before Botan is called.

xkcp

Allocates nothing. KMAC’s keyed state and every hash’s state live on the call’s stack or in the hasher, and are wiped when the call or the hasher ends. A KangarooTwelve hasher keeps the span of its customisation string, not a copy, and reads it at finish (KangarooTwelve (KT128 and KT256)).

blake3

Allocates nothing. Its keyed and derive_key modes hold the key in the object’s state until it is destroyed, without wiping it (BLAKE3).

webcrypto

The browser computes outside the program’s memory, with the asynchronous family alone, on Emscripten (WebCrypto in the browser). Each input (the key, the password, the IKM) is handed to it as a JavaScript copy, and the result comes back as an ArrayBuffer copied into the output: neither copy can be wiped, and each stays in JavaScript’s heap until its garbage collector frees it. The imported key is not extractable. The operation’s storage is the handler’s associated allocator’s, given back before the handler runs.

No backend states that its key derivations run in constant time; the capability table records each upstream’s statement, or the absence of one, with its source, and the matrices below show it.

The measured data

The chapters that follow are generated from data that tests and measurements produce, never typed: the capability table, doc/capabilities.json, renders which backend has each function on which target, over which hmacs, and its constant time and the default of each function; the measured table, doc/measurements.json, the size of a program per backend and target and the throughput of each, a reference measured once, on 2026-11-16, that decides nothing; the benchmark the owner named, PBKDF2-HMAC-SHA-512 at 1,000,000 iterations, its times; and the counting test, the allocations of each C library.

Backends

Which backend implements each function, over which hmacs, on which targets, and what upstream states about its constant time. The backends:

Backend Library Licence Jamfile Targets Called by

hash2

Boost.Hash2 1.92, and webcpp’s own HKDF and PBKDF2 over its hmac<H>

BSL-1.0

/webcpp/hash//hash

native, wasip2, wasip3, emscripten

every function of its cells

xkcp

XKCP at d20c8fc: its Keccak-p[1600], FIPS 202’s Keccak_Hash, SP 800-185’s functions, KangarooTwelve and TurboSHAKE

CC0-1.0

/third_party//xkcp

native, wasip2, wasip3, emscripten

every function of its cells

blake3

BLAKE3’s C implementation 1.8.7

CC0-1.0 or Apache-2.0

/third_party//blake3

native, wasip2, wasip3, emscripten

every function of its cells

sodium

libsodium 1.0.22

ISC

/third_party//sodium

native, wasip2, wasip3, emscripten

every function of its cells

bearssl

BearSSL at f8a2f3d (webcpporg/bearssl’s branch webcpp-pin: upstream 7bea48e (v0.6-39) and the two fixes submitted upstream, the ECDSA nonce’s and P-256’s scalar check’s, which do not touch hashing)

MIT

/third_party//bearssl

native, wasip2, wasip3, emscripten

every function of its cells

openssl

OpenSSL 3.5.9

Apache-2.0

/webcpp/hash//openssl

native, wasip2, wasip3

every function of its cells

botan

Botan 3.14.1

BSD-2-Clause

/third_party//botan

native, emscripten

every function of its cells, with exceptions only

webcrypto

the JavaScript runtime’s Web Cryptography API (crypto.subtle): the browser’s, or node’s

none (an API of the JavaScript runtime, linked by nothing)

/webcpp/asio//asio

emscripten

asynchronous family only (async.hpp)

Digests

Function Backend Hmacs Constant time Targets

md5_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha1_160

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha2_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha2_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha2_384

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha2_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha2_512_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha2_512_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::md5

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::md5

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::md5

openssl

-

not stated

native, wasip2, wasip3

digests::md5

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha1

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha1

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::sha1

openssl

-

not stated

native, wasip2, wasip3

digests::sha1

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha1

webcrypto (asynchronous family only)

-

not stated

emscripten

digests::sha2_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_224

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_224

openssl

-

not stated

native, wasip2, wasip3

digests::sha2_224

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha2_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_256

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_256

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_256

openssl

-

not stated

native, wasip2, wasip3

digests::sha2_256

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha2_256

webcrypto (asynchronous family only)

-

not stated

emscripten

digests::sha2_384

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_384

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_384

openssl

-

not stated

native, wasip2, wasip3

digests::sha2_384

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha2_384

webcrypto (asynchronous family only)

-

not stated

emscripten

digests::sha2_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_512

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_512

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_512

openssl

-

not stated

native, wasip2, wasip3

digests::sha2_512

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha2_512

webcrypto (asynchronous family only)

-

not stated

emscripten

digests::sha2_512_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_512_224

openssl

-

not stated

native, wasip2, wasip3

digests::sha2_512_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha2_512_256

openssl

-

not stated

native, wasip2, wasip3

digests::sha2_512_256

botan (with exceptions only)

-

not stated

native, emscripten

digests::md5_sha1

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::md5_sha1

openssl

-

not stated

native, wasip2, wasip3

sha3_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha3_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha3_384

hash2

-

not stated

native, wasip2, wasip3, emscripten

sha3_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

shake_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

shake_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_224

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_224

openssl

-

not stated

native, wasip2, wasip3

digests::sha3_224

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha3_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_256

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_256

openssl

-

not stated

native, wasip2, wasip3

digests::sha3_256

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha3_384

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_384

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_384

openssl

-

not stated

native, wasip2, wasip3

digests::sha3_384

botan (with exceptions only)

-

not stated

native, emscripten

digests::sha3_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_512

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_512

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::sha3_512

openssl

-

not stated

native, wasip2, wasip3

digests::sha3_512

botan (with exceptions only)

-

not stated

native, emscripten

digests::shake_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_128

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_128

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_128

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_128

openssl

-

not stated

native, wasip2, wasip3

digests::shake_128

botan (with exceptions only)

-

not stated

native, emscripten

digests::shake_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_256

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_256

bearssl

-

not stated

native, wasip2, wasip3, emscripten

digests::shake_256

openssl

-

not stated

native, wasip2, wasip3

digests::shake_256

botan (with exceptions only)

-

not stated

native, emscripten

digests::turboshake_128

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::turboshake_128

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::turboshake_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::turboshake_256

sodium

-

not stated

native, wasip2, wasip3, emscripten

keccak_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::keccak_224

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::keccak_224

openssl

-

not stated

native, wasip2, wasip3

digests::keccak_224

botan (with exceptions only)

-

not stated

native, emscripten

digests::keccak_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::keccak_256

openssl

-

not stated

native, wasip2, wasip3

digests::keccak_256

botan (with exceptions only)

-

not stated

native, emscripten

digests::keccak_384

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::keccak_384

openssl

-

not stated

native, wasip2, wasip3

digests::keccak_384

botan (with exceptions only)

-

not stated

native, emscripten

digests::keccak_512

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::keccak_512

openssl

-

not stated

native, wasip2, wasip3

digests::keccak_512

botan (with exceptions only)

-

not stated

native, emscripten

digests::cshake_128

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::cshake_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::tuplehash_128

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::tuplehash_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::parallelhash_128

xkcp (partial: a block size that is not a power of two of at least 8 bytes; SP 800-185 takes any from 1)

-

not stated

native, wasip2, wasip3, emscripten

digests::parallelhash_256

xkcp (partial: a block size that is not a power of two of at least 8 bytes; SP 800-185 takes any from 1)

-

not stated

native, wasip2, wasip3, emscripten

digests::kt128

xkcp

-

not stated

native, wasip2, wasip3, emscripten

digests::kt256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

blake2b_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

blake2s_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::blake2b

hash2 (partial: an output under 64 bytes, a key, a salt or a personalisation: BLAKE2b’s output size is a parameter of the hash, and Boost.Hash2’s blake2b_512 has 64 bytes and no option alone)

-

not stated

native, wasip2, wasip3, emscripten

digests::blake2b

sodium

-

not stated

native, wasip2, wasip3, emscripten

digests::blake2b

openssl (partial: a key, a salt or a personalisation: OpenSSL’s BLAKE2B-512 digest is unkeyed BLAKE2b of 1 to 64 bytes (its parameter size), and its keyed BLAKE2b is the MAC BLAKE2BMAC)

-

not stated

native, wasip2, wasip3

digests::blake2b

botan (with exceptions only) (partial: a salt or a personalisation: Botan’s BLAKE2b takes neither (blake2b.h))

-

not stated

native, emscripten

digests::blake2s_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::blake2s_256

openssl

-

not stated

native, wasip2, wasip3

digests::blake2s_256

botan (with exceptions only)

-

not stated

native, emscripten

blake3

blake3

-

not stated

native, wasip2, wasip3, emscripten

digests::blake3

blake3

-

not stated

native, wasip2, wasip3, emscripten

ripemd_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

ripemd_160

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::ripemd_160

hash2

-

not stated

native, wasip2, wasip3, emscripten

digests::ripemd_160

openssl

-

not stated

native, wasip2, wasip3

digests::ripemd_160

botan (with exceptions only)

-

not stated

native, emscripten

digests::sm3

openssl

-

not stated

native, wasip2, wasip3

digests::sm3

botan (with exceptions only)

-

not stated

native, emscripten

digests::streebog_256

botan (with exceptions only)

-

no

native, emscripten

digests::streebog_512

botan (with exceptions only)

-

no

native, emscripten

digests::whirlpool

botan (with exceptions only)

-

no

native, emscripten

digests::skein_512

botan (with exceptions only)

-

not stated

native, emscripten

Macs

Function Backend Hmacs Constant time Targets

siphash_32

hash2

-

not stated

native, wasip2, wasip3, emscripten

siphash_64

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::siphash_2_4

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::siphash_2_4

sodium

-

not stated

native, wasip2, wasip3, emscripten

macs::siphash_2_4

openssl

-

not stated

native, wasip2, wasip3

macs::siphash_2_4

botan (with exceptions only)

-

not stated

native, emscripten

macs::siphash_2_4x

sodium

-

not stated

native, wasip2, wasip3, emscripten

macs::siphash_2_4x

openssl

-

not stated

native, wasip2, wasip3

macs::kmac_128

xkcp

-

not stated

native, wasip2, wasip3, emscripten

macs::kmac_128

openssl (partial: a key under 4 or over 512 bytes, a customisation over 512 bytes, or a tag over 2,097,151 bytes: OpenSSL’s KMAC limits (kmac_prov.c))

-

not stated

native, wasip2, wasip3

macs::kmac_128

botan (with exceptions only) (partial: a key over 192 bytes, or the XOF form (xof): Botan’s KMAC limits its key to 192 bytes and has no KMACXOF (kmac.cpp))

-

not stated

native, emscripten

macs::kmac_256

xkcp

-

not stated

native, wasip2, wasip3, emscripten

macs::kmac_256

openssl (partial: a key under 4 or over 512 bytes, a customisation over 512 bytes, or a tag over 2,097,151 bytes: OpenSSL’s KMAC limits (kmac_prov.c))

-

not stated

native, wasip2, wasip3

macs::kmac_256

botan (with exceptions only) (partial: a key over 192 bytes, or the XOF form (xof): Botan’s KMAC limits its key to 192 bytes and has no KMACXOF (kmac.cpp))

-

not stated

native, emscripten

macs::blake2b_mac

sodium

-

not stated

native, wasip2, wasip3, emscripten

macs::blake2b_mac

openssl

-

not stated

native, wasip2, wasip3

macs::blake2b_mac

botan (with exceptions only)

-

not stated

native, emscripten

macs::blake2s_mac

hash2 (partial: a tag under 32 bytes: BLAKE2s’s output size is a parameter of the hash, and Boost.Hash2’s keyed blake2s_256 has 32 bytes alone)

-

not stated

native, wasip2, wasip3, emscripten

macs::blake2s_mac

openssl

-

not stated

native, wasip2, wasip3

hmac

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_md5_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha1_160

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha2_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha2_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha2_384

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha2_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha2_512_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha2_512_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha3_224

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha3_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha3_384

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_sha3_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_ripemd_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_ripemd_160

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_blake2b_512

hash2

-

not stated

native, wasip2, wasip3, emscripten

hmac_blake2s_256

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::md5>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::md5>

bearssl

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::md5>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::md5>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha1>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha1>

bearssl

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha1>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha1>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha1>

webcrypto (asynchronous family only)

-

not stated

emscripten

macs::hmac<digests::sha2_224>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_224>

bearssl

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha2_224>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha2_256>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_256>

sodium

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_256>

bearssl

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha2_256>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha2_256>

webcrypto (asynchronous family only)

-

not stated

emscripten

macs::hmac<digests::sha2_384>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_384>

bearssl

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_384>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha2_384>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha2_384>

webcrypto (asynchronous family only)

-

not stated

emscripten

macs::hmac<digests::sha2_512>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_512>

sodium

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_512>

bearssl

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_512>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha2_512>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha2_512>

webcrypto (asynchronous family only)

-

not stated

emscripten

macs::hmac<digests::sha2_512_224>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_512_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha2_512_256>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha2_512_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha2_512_256>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha3_224>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha3_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha3_224>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha3_256>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha3_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha3_256>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha3_384>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha3_384>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha3_384>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sha3_512>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::sha3_512>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sha3_512>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::ripemd_160>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::ripemd_160>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::ripemd_160>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::blake2b>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::blake2b>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::blake2b>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::blake2s_256>

hash2

-

not stated

native, wasip2, wasip3, emscripten

macs::hmac<digests::blake2s_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::blake2s_256>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::keccak_224>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::keccak_224>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::keccak_256>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::keccak_256>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::keccak_384>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::keccak_384>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::keccak_512>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::keccak_512>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::sm3>

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

-

not stated

native, wasip2, wasip3

macs::hmac<digests::sm3>

botan (with exceptions only)

-

not stated

native, emscripten

macs::hmac<digests::streebog_256>

botan (with exceptions only)

-

no

native, emscripten

macs::hmac<digests::streebog_512>

botan (with exceptions only)

-

no

native, emscripten

macs::hmac<digests::whirlpool>

botan (with exceptions only)

-

no

native, emscripten

macs::hmac<digests::skein_512>

botan (with exceptions only)

-

not stated

native, emscripten

Non-cryptographic

Function Backend Hmacs Constant time Targets

fnv1a_32

hash2

-

not stated

native, wasip2, wasip3, emscripten

fnv1a_64

hash2

-

not stated

native, wasip2, wasip3, emscripten

xxhash_32

hash2

-

not stated

native, wasip2, wasip3, emscripten

xxhash_64

hash2

-

not stated

native, wasip2, wasip3, emscripten

xxh3_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

murmur3_32

hash2

-

not stated

native, wasip2, wasip3, emscripten

murmur3_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

spooky2_128

hash2

-

not stated

native, wasip2, wasip3, emscripten

Kdfs

Function Backend Hmacs Constant time Targets

hkdf_extract

hash2

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, other

not stated

native, wasip2, wasip3, emscripten

hkdf_extract

sodium

hmac_sha2_256, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf_extract

openssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

hkdf_extract

botan (with exceptions only)

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

hkdf_extract

webcrypto (asynchronous family only)

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

emscripten

hkdf_expand

hash2

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, other

not stated

native, wasip2, wasip3, emscripten

hkdf_expand

sodium

hmac_sha2_256, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf_expand

openssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

hkdf_expand

botan (with exceptions only)

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

hkdf_expand

webcrypto (asynchronous family only)

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

emscripten

hkdf

hash2

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, other

not stated

native, wasip2, wasip3, emscripten

hkdf

sodium

hmac_sha2_256, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf

bearssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf

openssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

hkdf

botan (with exceptions only)

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

hkdf

webcrypto (asynchronous family only) (partial: an application_info longer than 1,024 bytes, which completes with input_too_long: WebCrypto’s limit as node has it, where the other backends take 32,768)

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

emscripten

hkdf_extract over pieces

hash2

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, other

not stated

native, wasip2, wasip3, emscripten

hkdf_extract over pieces

sodium

hmac_sha2_256, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf_extract over pieces

bearssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf_extract over pieces

openssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

hkdf_extract over pieces

botan (with exceptions only)

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

hkdf_extract over pieces

webcrypto (asynchronous family only)

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

emscripten

hkdf_expand over pieces

hash2

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, other

not stated

native, wasip2, wasip3, emscripten

hkdf_expand over pieces

sodium

hmac_sha2_256, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf_expand over pieces

bearssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf_expand over pieces

openssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

hkdf_expand over pieces

botan (with exceptions only)

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

hkdf_expand over pieces

webcrypto (asynchronous family only)

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

emscripten

hkdf over pieces

hash2

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, other

not stated

native, wasip2, wasip3, emscripten

hkdf over pieces

sodium

hmac_sha2_256, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf over pieces

bearssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

native, wasip2, wasip3, emscripten

hkdf over pieces

openssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

hkdf over pieces

botan (with exceptions only)

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

hkdf over pieces

webcrypto (asynchronous family only)

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

emscripten

pbkdf2

hash2

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256, other

not stated

native, wasip2, wasip3, emscripten

pbkdf2

openssl

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

pbkdf2

botan (with exceptions only) (partial: an iteration count above 2^32 - 1 on wasm32 (invalid_iterations): Botan counts iterations in a size_t; an output of more than 2^32 - 2 digests (invalid_output_size), where RFC 8018 allows 2^32 - 1: Botan’s PBKDF2 derives at most 2^32 - 2 blocks (pbkdf2.cpp))

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

pbkdf2

webcrypto (asynchronous family only) (partial: an iteration count above 2^32 - 1 (invalid_iterations) and an output longer than (2^32 - 1) / 8 bytes (invalid_output_size): WebCrypto’s deriveBits counts iterations and bits in 32 bits)

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512

not stated

emscripten

blake2b_subkey

sodium

-

not stated

native, wasip2, wasip3, emscripten

kbkdf

openssl (partial: a key of more than INT_MAX bytes: OpenSSL takes HMAC’s key length as an int (HMAC_Init_ex))

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, wasip2, wasip3

kbkdf

botan (with exceptions only) (partial: the separator or L turned off: Botan’s SP800-108-Counter always writes both (sp800_108.cpp))

hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_160, hmac_blake2b_512, hmac_blake2s_256

not stated

native, emscripten

sskdf

openssl (partial: a secret, an info or an output of more than 2^30 bytes: OpenSSL’s SSKDF_MAX_INLEN (providers/implementations/kdfs/sskdf.c))

-

not stated

native, wasip2, wasip3

sskdf

botan (with exceptions only)

-

not stated

native, emscripten

x963kdf

openssl (partial: a secret, an info or an output of more than 2^30 bytes: OpenSSL’s SSKDF_MAX_INLEN (providers/implementations/kdfs/sskdf.c))

-

not stated

native, wasip2, wasip3

x963kdf

botan (with exceptions only) (partial: an output of more than 2^32 - 2 digests, where ANSI X9.63 allows 2^32 - 1: Botan’s KDF2 derives at most 2^32 - 2 blocks (kdf2.cpp))

-

not stated

native, emscripten

Password hashing

Function Backend Hmacs Constant time Targets

argon2id

sodium

-

not stated

native, wasip2, wasip3, emscripten

argon2id

openssl

-

not stated

native, wasip2, wasip3

argon2id

botan (with exceptions only)

-

not stated

native, emscripten

kdfs::argon2d

openssl (partial: m above 4,194,303 KiB on wasm32: OpenSSL sizes Argon2’s memory, m blocks of 1 KiB, in a size_t)

-

not stated

native, wasip2, wasip3

kdfs::argon2d

botan (with exceptions only) (partial: more than 128 lanes, or m above 8 GiB (2 GiB on wasm32): Botan’s Argon2 limits (argon2pwhash.cpp))

-

no

native, emscripten

kdfs::argon2i

sodium (partial: fewer than 3 passes, more than one lane, a secret, associated data, a salt other than 16 bytes or a tag under 16 bytes: libsodium’s crypto_pwhash_argon2i takes none of them)

-

not stated

native, wasip2, wasip3, emscripten

kdfs::argon2i

openssl (partial: m above 4,194,303 KiB on wasm32: OpenSSL sizes Argon2’s memory, m blocks of 1 KiB, in a size_t)

-

not stated

native, wasip2, wasip3

kdfs::argon2i

botan (with exceptions only) (partial: more than 128 lanes, or m above 8 GiB (2 GiB on wasm32): Botan’s Argon2 limits (argon2pwhash.cpp))

-

not stated

native, emscripten

kdfs::argon2id

sodium (partial: more than one lane, a secret, associated data, a salt other than 16 bytes or a tag under 16 bytes: libsodium’s crypto_pwhash_argon2id takes none of them)

-

not stated

native, wasip2, wasip3, emscripten

kdfs::argon2id

openssl (partial: m above 4,194,303 KiB on wasm32: OpenSSL sizes Argon2’s memory, m blocks of 1 KiB, in a size_t)

-

not stated

native, wasip2, wasip3

kdfs::argon2id

botan (with exceptions only) (partial: more than 128 lanes, or m above 8 GiB (2 GiB on wasm32): Botan’s Argon2 limits (argon2pwhash.cpp))

-

not stated

native, emscripten

scrypt

sodium

-

not stated

native, wasip2, wasip3, emscripten

scrypt

openssl (partial: r p of 2^24 or more, or a password, salt or output of more than INT_MAX bytes: OpenSSL passes them to PBKDF2, whose lengths are ints)

-

not stated

native, wasip2, wasip3

scrypt

botan (with exceptions only) (partial: N above 2^22, r above 256, p above 1,024, or more than 8 GiB and 2 MiB of memory (2 GiB and 2 MiB on wasm32): Botan’s scrypt limits (scrypt.cpp))

-

no

native, emscripten

bcrypt

botan (with exceptions only) (partial: a cost above 18: Botan’s limit (bcrypt.cpp), where bcrypt’s format allows 31)

-

no

native, emscripten

bcrypt_pbkdf

botan (with exceptions only)

-

no

native, emscripten

Data-independent timing (DIT)

64-bit ARM’s DIT (data-independent timing) bit, PSTATE.DIT, makes the instructions Arm lists take a time independent of their data, and Apple requires it of constant-time code (Apple, enable DIT for constant-time cryptographic operations). None of the libraries hash calls sets it, so hash does: every function that computes on a key, a password or a key derivation’s secret input runs its whole body inside webcpp::secure::timing_guard, webcpp::secure’s guard, on every synchronous backend, which on 64-bit ARM under macOS, iOS, Linux, Android and Windows, where the CPU has FEAT_DIT (hw.optional.arm.FEAT_DIT on Apple’s systems, HWCAP_DIT on Linux, one read of the register under structured exception handling on Windows), sets DIT for the call and returns with the thread’s DIT as it found it: clear when it was clear, set when the program set it itself (Apple’s timingsafe_enable_if_supported) or an outer call did. An error leaves it as found too, and so does an exception, while it unwinds the call. After the catch, Windows on ARM64 clears DIT when it resumes the thread: a program there that set DIT itself and catches an exception from a call sets it again after the catch (webcpp::secure’s guide, "Exceptions" of its guard). DIT is a thread’s own state, so a call never changes another thread’s. Otherwise a program does nothing. Elsewhere the guard executes no instruction: on x86 the counterpart, DOITM, is a register only the kernel writes; on WebAssembly the engine decides.

The functions that set DIT, on every synchronous backend of their cells:

  • MACs: mac<macs::siphash_2_4>, mac<macs::siphash_2_4x>, mac<macs::kmac_128>, mac<macs::kmac_256>, mac<macs::blake2b_mac>, mac<macs::blake2s_mac>, mac<macs::hmac<digests::md5>>, mac<macs::hmac<digests::sha1>>, mac<macs::hmac<digests::sha2_224>>, mac<macs::hmac<digests::sha2_256>>, mac<macs::hmac<digests::sha2_384>>, mac<macs::hmac<digests::sha2_512>>, mac<macs::hmac<digests::sha2_512_224>>, mac<macs::hmac<digests::sha2_512_256>>, mac<macs::hmac<digests::sha3_224>>, mac<macs::hmac<digests::sha3_256>>, mac<macs::hmac<digests::sha3_384>>, mac<macs::hmac<digests::sha3_512>>, mac<macs::hmac<digests::ripemd_160>>, mac<macs::hmac<digests::blake2b>>, mac<macs::hmac<digests::blake2s_256>>, mac<macs::hmac<digests::keccak_224>>, mac<macs::hmac<digests::keccak_256>>, mac<macs::hmac<digests::keccak_384>>, mac<macs::hmac<digests::keccak_512>>, mac<macs::hmac<digests::sm3>>, mac<macs::hmac<digests::streebog_256>>, mac<macs::hmac<digests::streebog_512>>, mac<macs::hmac<digests::whirlpool>> and mac<macs::hmac<digests::skein_512>>.

  • Key derivation: hkdf_extract, hkdf_expand, hkdf, hkdf_extract over pieces, hkdf_expand over pieces, hkdf over pieces, pbkdf2, blake2b_subkey, kbkdf, sskdf and x963kdf.

  • Password hashing: argon2id, argon2<kdfs::argon2d>, argon2<kdfs::argon2i>, argon2<kdfs::argon2id>, scrypt, bcrypt, bcrypt_verify and bcrypt_pbkdf.

  • Keyed by their arguments: digest_of<digests::blake2b> and hasher<digests::blake2b> (make, update, finish) when the options carry a key; the blake3 class in its keyed, key-derivation and seeded keyed modes (a non-empty byte seed, a non-zero integer seed: BLAKE3’s keyed hash): keyed, derive_key, those constructors, and update, result, squeeze and reset of such an object. Called without a key, they hold a disengaged guard, which reads its flag and does nothing else.

The functions that do not:

  • Unkeyed digests and extendable-output functions, through digest_of, hasher and the types of Boost.Hash2’s form (keccak_256, blake3 in its plain mode): their input is not a secret by their contract (a program that derives from a secret uses a MAC or a key derivation, which set DIT); they are the streaming case, where a guard per update of every checksum would cost a real fraction of a short chunk for no secret; and the same algorithm is also Boost.Hash2’s own type by alias, which hash cannot guard, so that guarding one spelling would make the protection depend on the spelling.

  • Boost.Hash2’s types by alias, siphash_32, siphash_64, hmac, hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384, hmac_sha2_512, hmac_sha2_512_224, hmac_sha2_512_256, hmac_sha3_224, hmac_sha3_256, hmac_sha3_384, hmac_sha3_512, hmac_ripemd_128, hmac_ripemd_160, hmac_blake2b_512 and hmac_blake2s_256: they are Boost.Hash2’s own classes, and a guard inside them would need a type of hash’s in place of the alias. An HMAC with DIT is mac<macs::hmac<D>>, which runs the same Boost.Hash2 code on backends::hash2 inside its guard, and a SipHash with DIT is mac<macs::siphash_2_4>; a program that calls hmac<H> or siphash_64 directly sets DIT itself. HKDF and PBKDF2 on backends::hash2 run Boost.Hash2’s hmac inside their own guard.

  • The initiating functions of async.hpp: they check sizes and post, and the synchronous function they call sets DIT on the thread that computes, a thread of the work executor’s pool for a heavy function, the caller’s for a cheap one (Asynchronous calls). On backends::webcrypto the browser’s JavaScript engine computes, and nothing is added.

A coverage test per backend (test/timing_coverage_<backend>_test.cpp) reads this table and fails when a keyed cell of its backend has no call, when a call enters no guard, when the first guard it enters is not its own function’s, or when it leaves DIT otherwise than it found it, from a thread with DIT clear and from one that set it; it checks that the unkeyed functions enter none. test/timing_during_test.cpp reads DIT while HKDF, PBKDF2 and mac compute, through a hash that records it at each update, on the calling thread and on an async_pbkdf2 pool’s. The guard is secure’s, shared with webcpp::crypto and webcpp::codecs: secure’s timing_guard_nesting_test nests guards as two libraries do, and crypto’s timing_nested_hash_test runs a keyed call of hash inside a guarded call of crypto.

What the guard adds to a call, measured from a release build, is in The timing guard’s cost.

The default backends

The backend a call that names none uses, on every target, whatever the program links (The default backend):

Function Default

digests::md5

hash2

digests::sha1

hash2

digests::sha2_224

hash2

digests::sha2_256

hash2

digests::sha2_384

hash2

digests::sha2_512

hash2

digests::sha2_512_224

hash2

digests::sha2_512_256

hash2

digests::md5_sha1

none: the call names its backend

digests::sha3_224

hash2

digests::sha3_256

hash2

digests::sha3_384

hash2

digests::sha3_512

hash2

digests::shake_128

hash2

digests::shake_256

hash2

digests::turboshake_128

xkcp

digests::turboshake_256

xkcp

digests::keccak_224

xkcp

digests::keccak_256

xkcp

digests::keccak_384

xkcp

digests::keccak_512

xkcp

digests::cshake_128

xkcp

digests::cshake_256

xkcp

digests::tuplehash_128

xkcp

digests::tuplehash_256

xkcp

digests::parallelhash_128

xkcp

digests::parallelhash_256

xkcp

digests::kt128

xkcp

digests::kt256

xkcp

digests::blake2b

sodium

digests::blake2s_256

hash2

digests::blake3

blake3

digests::ripemd_160

hash2

digests::sm3

none: the call names its backend

digests::streebog_256

none: the call names its backend

digests::streebog_512

none: the call names its backend

digests::whirlpool

none: the call names its backend

digests::skein_512

none: the call names its backend

macs::siphash_2_4

hash2

macs::siphash_2_4x

sodium

macs::kmac_128

xkcp

macs::kmac_256

xkcp

macs::blake2b_mac

sodium

macs::blake2s_mac

hash2

macs::hmac<digests::md5>

hash2

macs::hmac<digests::sha1>

hash2

macs::hmac<digests::sha2_224>

hash2

macs::hmac<digests::sha2_256>

hash2

macs::hmac<digests::sha2_384>

hash2

macs::hmac<digests::sha2_512>

hash2

macs::hmac<digests::sha2_512_224>

hash2

macs::hmac<digests::sha2_512_256>

hash2

macs::hmac<digests::sha3_224>

hash2

macs::hmac<digests::sha3_256>

hash2

macs::hmac<digests::sha3_384>

hash2

macs::hmac<digests::sha3_512>

hash2

macs::hmac<digests::ripemd_160>

hash2

macs::hmac<digests::blake2b>

hash2

macs::hmac<digests::blake2s_256>

hash2

macs::hmac<digests::keccak_224>

none: the call names its backend

macs::hmac<digests::keccak_256>

none: the call names its backend

macs::hmac<digests::keccak_384>

none: the call names its backend

macs::hmac<digests::keccak_512>

none: the call names its backend

macs::hmac<digests::sm3>

none: the call names its backend

macs::hmac<digests::streebog_256>

none: the call names its backend

macs::hmac<digests::streebog_512>

none: the call names its backend

macs::hmac<digests::whirlpool>

none: the call names its backend

macs::hmac<digests::skein_512>

none: the call names its backend

hkdf_extract

hash2

hkdf_expand

hash2

hkdf

hash2

hkdf_extract over pieces

hash2

hkdf_expand over pieces

hash2

hkdf over pieces

hash2

pbkdf2

hash2

blake2b_subkey

sodium

argon2id

sodium

kdfs::argon2d

none: the call names its backend

kdfs::argon2i

sodium

kdfs::argon2id

sodium

scrypt

sodium

Constant time

What each backend’s upstream states, and where:

  • hash2: not stated. Boost.Hash2 1.92: its headers (boost/hash2/) state no constant-time property.

  • xkcp: not stated.

    • XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high/Keccak (KeccakSponge, FIPS202/KeccakHash) state no constant-time property.

    • XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high (KangarooTwelve, TurboSHAKE, Keccak/KeccakSponge) state no constant-time property.

    • XKCP at d20c8fc: README.markdown, lib/low/KeccakP-1600 and lib/high/Keccak (KeccakSponge, FIPS202/KeccakHash, SP800-185) state no constant-time property.

  • blake3: not stated. BLAKE3 1.8.7: README.md and c/README.md state no constant-time property.

  • sodium: not stated. libsodium 1.0.22: its headers state constant time for comparisons (sodium/utils.h) alone, not for its hashing, MAC, key derivation and password hashing functions (crypto_hash_*, crypto_xof_*, crypto_generichash_*, crypto_shorthash_*, crypto_auth_*, crypto_kdf_*, crypto_pwhash_*).

  • bearssl: not stated.

    • BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_hash.h states constant time for its GHASH implementations alone, not for br_md5_*, br_sha1_*, br_sha224_* to br_sha512_* or br_md5sha1_*.

    • BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_kdf.h states no constant-time property for br_shake_*.

    • BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_hmac.h states constant time for br_hmac_outCT alone; mac calls br_hmac_out.

    • BearSSL upstream 7bea48e (v0.6-39), unchanged at webcpp’s pin f8a2f3d: bearssl_hmac.h states constant time for br_hmac_outCT alone; br_hkdf_* (src/kdf/hkdf.c) and HKDF over pieces call br_hmac_out.

  • openssl: not stated.

    • OpenSSL 3.5.9: doc/man7/EVP_MD-*.pod, doc/man3/EVP_DigestInit.pod and providers/implementations/digests/ state no constant-time property.

    • OpenSSL 3.5.9: doc/man3/EVP_MAC.pod, doc/man7/EVP_MAC-HMAC.pod, EVP_MAC-KMAC.pod, EVP_MAC-BLAKE2.pod, EVP_MAC-Siphash.pod and providers/implementations/macs/ state no constant-time property.

    • OpenSSL 3.5.9: doc/man7/EVP_KDF-HKDF.pod and EVP_KDF-PBKDF2.pod state no constant-time property.

    • OpenSSL 3.5.9: doc/man3/EVP_MAC.pod and doc/man7/EVP_MAC-HMAC.pod state no constant-time property; HKDF over pieces calls EVP_MAC "HMAC".

    • OpenSSL 3.5.9: doc/man7/EVP_KDF-KB.pod states no constant-time property.

    • OpenSSL 3.5.9: doc/man7/EVP_KDF-SS.pod states no constant-time property.

    • OpenSSL 3.5.9: doc/man7/EVP_KDF-X963.pod states no constant-time property.

    • OpenSSL 3.5.9: doc/man7/EVP_KDF-ARGON2.pod states that Argon2i’s memory accesses are independent of the data and Argon2d’s depend on it, and states no constant-time property.

    • OpenSSL 3.5.9: doc/man7/EVP_KDF-SCRYPT.pod states no constant-time property.

  • botan: not stated.

    • Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of this hash, and its source (src/lib/hash/) none.

    • Botan 3.14.1: doc/api_ref/hash.rst states no constant-time property of SHAKE or of its XOF interface, and its source (src/lib/xof/shake_xof/) none.

    • Botan 3.14.1: doc/api_ref/message_auth_codes.rst states no constant-time property of this MAC, and its source (src/lib/mac/) none.

    • Botan 3.14.1: doc/api_ref/kdf.rst states no constant-time property of its KDFs, and their source (src/lib/kdf/) none.

    • Botan 3.14.1: doc/api_ref/message_auth_codes.rst states no constant-time property of HMAC, and its source (src/lib/mac/hmac/) none; HKDF over pieces calls its HMAC.

    • Botan 3.14.1: doc/api_ref/pbkdf.rst states no constant-time property of PBKDF2, and its source (src/lib/pbkdf/pbkdf2/) none.

    • Botan 3.14.1: doc/api_ref/pbkdf.rst states that Argon2i’s memory accesses are independent of the data and Argon2id’s depend on it after the first half of the first pass, and states no constant-time property.

  • botan: no.

    • Botan 3.14.1: doc/api_ref/hash.rst warns that Streebog’s baseline implementation uses table lookups indexed by the data and is likely vulnerable to cache-based side channels; its constant-time code needs AVX-512 and GFNI, an instruction-set module that /third_party//botan’s minimized build does not load.

    • Botan 3.14.1: doc/api_ref/hash.rst warns that Whirlpool’s baseline implementation uses table lookups indexed by the data and is likely vulnerable to cache-based side channels; its constant-time code needs AVX2 or AVX-512, instruction-set modules that /third_party//botan’s minimized build does not load.

    • Botan 3.14.1: doc/api_ref/pbkdf.rst warns that Argon2d accesses memory at addresses which depend on the password, and so may leak information about the password via cache-based side channels.

    • Botan 3.14.1: doc/api_ref/pbkdf.rst warns that scrypt by design accesses memory at addresses which depend on the password, and so may leak information about the password via cache-based side channels.

    • Botan 3.14.1: doc/api_ref/passhash.rst warns that bcrypt is built on Blowfish, which uses key-dependent tables indexed by secret data, and is thus likely vulnerable to cache-based side channels; no constant-time implementation is available.

    • Botan 3.14.1: doc/api_ref/pbkdf.rst warns that Bcrypt-PBKDF is built on Blowfish, which uses key-dependent tables indexed by secret data, and is thus likely vulnerable to cache-based side channels; no constant-time implementation is available.

  • webcrypto: not stated. The Web Cryptography API (W3C Recommendation, 2017) states no constant-time property of digest, sign or deriveBits; each JavaScript runtime’s implementation decides, and webcpp reads none.

Measured size and throughput

A reference measured once, on 2026-11-16, that decides nothing: what each backend cost a program on each target, in bytes and in time, when webcpp measured it. Every key derivation’s default is backends::hash2, Argon2id’s and scrypt’s backends::sodium, whatever these tables say (The default backend): hash2 is the only backend that covers every hmac, operation and target; it is header-only, so a program carries only what it calls and shares the SHA code it already uses; and the differences measured here for HKDF are nanoseconds natively and a few KB of an isolated program on WebAssembly. No lane measures these figures again, and a move of a C library’s pin leaves them as they were.

Measured on 2026-11-16 on Apple M5 Max, 18 cores, 128 GiB, Darwin 27.0.0; WebAssembly under wasmtime 47.0.3 (5554cc1a6 2026-07-31) (wasip2, wasip3) and node v26.13.0 (Emscripten). Compilers: native: Apple LLVM 21.0.0 (clang-2100.4.1.1); wasip2: Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141); wasip3: Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141); emscripten: Clang 24.0.0git (https:/github.com/llvm/llvm-project f718ebe873411a562ef6e5c27da36d75b7aaec98).

The native rows hold for Apple LLVM 21.0.0 (clang-2100.4.1.1) on Darwin arm64, stripped with strip; another native toolchain gives other native sizes and times.

Sizes: the bytes of the program built at variant=release optimization=space: natively the executable stripped with strip, on WebAssembly the .wasm file, which carries no debug information. Throughput: the program built at variant=release optimization=speed, run with --time: one computation to warm up, then five timed runs of the workload, each repeated repetitions times; per invocation the median of its five runs, per record the median of its invocations’ medians, with the fastest and slowest run.

Size of a program, in bytes

Function Hmac Backend native wasip2 wasip3 emscripten

md5_128

-

hash2

33768

50712

59828

8039

sha1_160

-

hash2

33776

52959

62075

10285

sha2_224

-

hash2

33776

56882

65998

14116

sha2_256

-

hash2

33776

56880

65996

14108

sha2_384

-

hash2

33776

60353

69469

17579

sha2_512

-

hash2

33776

60363

69479

17582

sha2_512_224

-

hash2

33776

60427

69543

17645

sha2_512_256

-

hash2

33776

60383

69499

17597

sha3_224

-

hash2

33744

49962

59078

7175

sha3_256

-

hash2

33744

49956

59072

7172

sha3_384

-

hash2

33744

49923

59039

7140

sha3_512

-

hash2

33744

49930

59046

7142

shake_128

-

hash2

33744

49943

59059

7151

shake_256

-

hash2

33744

49943

59059

7151

keccak_256

-

xkcp

50896

65628

74913

24057

blake2b_512

-

hash2

33824

54668

63784

11982

blake2s_256

-

hash2

33824

53667

62783

10974

blake3

-

blake3

50888

63102

72363

21252

ripemd_128

-

hash2

33776

52109

61225

9421

ripemd_160

-

hash2

33776

54297

63413

11607

siphash_32

-

hash2

33936

48888

58004

6206

siphash_64

-

hash2

33936

48980

58096

6294

hmac

-

hash2

33896

57672

66788

14437

hmac_md5_128

-

hash2

33904

51341

60457

8330

hmac_sha1_160

-

hash2

33904

53595

62711

10569

hmac_sha2_224

-

hash2

33904

57687

66803

14444

hmac_sha2_256

-

hash2

33904

57681

66797

14437

hmac_sha2_384

-

hash2

33904

61288

70404

17975

hmac_sha2_512

-

hash2

33904

61298

70414

17980

hmac_sha2_512_224

-

hash2

33912

61378

70494

18041

hmac_sha2_512_256

-

hash2

33912

61328

70444

17992

hmac_sha3_224

-

hash2

33904

50519

59635

7427

hmac_sha3_256

-

hash2

33904

50507

59623

7416

hmac_sha3_384

-

hash2

33904

50474

59590

7383

hmac_sha3_512

-

hash2

33904

50484

59600

7386

hmac_ripemd_128

-

hash2

33904

52744

61860

9712

hmac_ripemd_160

-

hash2

33904

54937

64053

11897

hmac_blake2b_512

-

hash2

33944

55303

64419

12262

hmac_blake2s_256

-

hash2

33944

54360

63476

11284

fnv1a_32

-

hash2

33728

48057

57173

5612

fnv1a_64

-

hash2

33728

48066

57182

5621

xxhash_32

-

hash2

33776

49064

58180

6369

xxhash_64

-

hash2

33776

49473

58589

6757

xxh3_128

-

hash2

33792

54157

63289

10431

murmur3_32

-

hash2

33776

48686

57802

6099

murmur3_128

-

hash2

33824

48990

58106

6315

spooky2_128

-

hash2

33824

51313

60437

8388

hkdf_extract

hmac_sha2_256

hash2

34288

59161

68421

17499

hkdf_extract

hmac_sha2_256

sodium

70320

72143

81977

24116

hkdf_extract

hmac_sha2_256

openssl

3049184

2127951

2142453

-

hkdf_extract

hmac_sha2_512

hash2

34288

62750

72010

21083

hkdf_extract

hmac_sha2_512

sodium

70320

72694

82527

24591

hkdf_extract

hmac_sha2_512

openssl

3049184

2127936

2142438

-

hkdf_expand

hmac_sha2_256

hash2

34272

75028

84673

29214

hkdf_expand

hmac_sha2_256

sodium

70176

73410

83243

24778

hkdf_expand

hmac_sha2_256

openssl

3049168

2128177

2142679

-

hkdf_expand

hmac_sha2_512

hash2

34272

78611

88256

32787

hkdf_expand

hmac_sha2_512

sodium

70176

74000

83832

25282

hkdf_expand

hmac_sha2_512

openssl

3049168

2128181

2142683

-

hkdf

hmac_sha2_256

hash2

34392

76046

85692

29549

hkdf

hmac_sha2_256

sodium

86984

74648

84480

25335

hkdf

hmac_sha2_256

bearssl

52664

69317

78961

23281

hkdf

hmac_sha2_256

openssl

3049288

2128412

2142914

-

hkdf

hmac_sha2_512

hash2

34392

79603

89249

33104

hkdf

hmac_sha2_512

sodium

86984

75221

85053

25822

hkdf

hmac_sha2_512

bearssl

52648

69846

79474

23792

hkdf

hmac_sha2_512

openssl

3049288

2128414

2142916

-

pbkdf2

hmac_sha2_256

hash2

34280

75164

84808

29235

pbkdf2

hmac_sha2_256

openssl

3049176

2128358

2142860

-

pbkdf2

hmac_sha2_512

hash2

34280

78699

88343

32747

pbkdf2

hmac_sha2_512

openssl

3049176

2128358

2142860

-

argon2id

-

sodium

87872

90242

99987

39690

scrypt

-

sodium

87384

77592

87332

29540

Throughput

A hash or MAC in MiB per second over 1 MiB, a key derivation in time per derivation: the median, then the range of its runs, the lower figure first. Per function, the workload:

  • md5_128: the hash of 1 MiB.

  • sha1_160: the hash of 1 MiB.

  • sha2_224: the hash of 1 MiB.

  • sha2_256: the hash of 1 MiB.

  • sha2_384: the hash of 1 MiB.

  • sha2_512: the hash of 1 MiB.

  • sha2_512_224: the hash of 1 MiB.

  • sha2_512_256: the hash of 1 MiB.

  • sha3_224: the hash of 1 MiB.

  • sha3_256: the hash of 1 MiB.

  • sha3_384: the hash of 1 MiB.

  • sha3_512: the hash of 1 MiB.

  • shake_128: the hash of 1 MiB.

  • shake_256: the hash of 1 MiB.

  • keccak_256: the hash of 1 MiB.

  • blake2b_512: the hash of 1 MiB.

  • blake2s_256: the hash of 1 MiB.

  • blake3: the hash of 1 MiB.

  • ripemd_128: the hash of 1 MiB.

  • ripemd_160: the hash of 1 MiB.

  • siphash_32: the MAC of 1 MiB under a 32-byte key.

  • siphash_64: the MAC of 1 MiB under a 32-byte key.

  • hmac: the MAC of 1 MiB under a 32-byte key.

  • hmac_md5_128: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha1_160: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha2_224: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha2_256: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha2_384: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha2_512: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha2_512_224: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha2_512_256: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha3_224: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha3_256: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha3_384: the MAC of 1 MiB under a 32-byte key.

  • hmac_sha3_512: the MAC of 1 MiB under a 32-byte key.

  • hmac_ripemd_128: the MAC of 1 MiB under a 32-byte key.

  • hmac_ripemd_160: the MAC of 1 MiB under a 32-byte key.

  • hmac_blake2b_512: the MAC of 1 MiB under a 32-byte key.

  • hmac_blake2s_256: the MAC of 1 MiB under a 32-byte key.

  • fnv1a_32: the hash of 1 MiB.

  • fnv1a_64: the hash of 1 MiB.

  • xxhash_32: the hash of 1 MiB.

  • xxhash_64: the hash of 1 MiB.

  • xxh3_128: the hash of 1 MiB.

  • murmur3_32: the hash of 1 MiB.

  • murmur3_128: the hash of 1 MiB.

  • spooky2_128: the hash of 1 MiB.

  • hkdf_extract: HKDF-Extract of a 32-byte IKM with a 32-byte salt, repeated 1,000 times.

  • hkdf_expand: HKDF-Expand of 32 bytes from a digest-size PRK and a 16-byte info, repeated 1,000 times.

  • hkdf: HKDF of 32 bytes from a 32-byte IKM, a 32-byte salt and a 16-byte info, repeated 1,000 times.

  • pbkdf2: PBKDF2 of 32 bytes from a 16-byte password and salt at 100,000 iterations.

  • argon2id: Argon2id of 32 bytes from a 16-byte password and salt at libsodium’s interactive costs (2 passes over 64 MiB).

  • scrypt: scrypt of 32 bytes from a 16-byte password and salt at N=16384, r=8, p=1 (16 MiB).

Function Hmac Backend native wasip2 wasip3 emscripten

md5_128

-

hash2

933 MiB/s (859 to 936)

747 MiB/s (720 to 781)

778 MiB/s (694 to 783)

769 MiB/s (726 to 778)

sha1_160

-

hash2

1190 MiB/s (1163 to 1248)

829 MiB/s (816 to 853)

831 MiB/s (807 to 851)

889 MiB/s (873 to 907)

sha2_224

-

hash2

606 MiB/s (412 to 618)

453 MiB/s (447 to 482)

453 MiB/s (434 to 480)

465 MiB/s (459 to 483)

sha2_256

-

hash2

593 MiB/s (464 to 618)

466 MiB/s (447 to 481)

453 MiB/s (428 to 481)

471 MiB/s (431 to 479)

sha2_384

-

hash2

913 MiB/s (888 to 970)

690 MiB/s (674 to 737)

692 MiB/s (559 to 728)

687 MiB/s (675 to 703)

sha2_512

-

hash2

940 MiB/s (900 to 972)

689 MiB/s (681 to 727)

689 MiB/s (614 to 731)

696 MiB/s (671 to 725)

sha2_512_224

-

hash2

941 MiB/s (887 to 972)

687 MiB/s (676 to 733)

688 MiB/s (645 to 730)

684 MiB/s (674 to 705)

sha2_512_256

-

hash2

911 MiB/s (891 to 966)

691 MiB/s (675 to 729)

691 MiB/s (675 to 723)

685 MiB/s (675 to 697)

sha3_224

-

hash2

733 MiB/s (721 to 737)

504 MiB/s (493 to 515)

503 MiB/s (429 to 508)

472 MiB/s (468 to 481)

sha3_256

-

hash2

692 MiB/s (676 to 695)

478 MiB/s (468 to 482)

476 MiB/s (322 to 481)

458 MiB/s (329 to 465)

sha3_384

-

hash2

529 MiB/s (523 to 554)

374 MiB/s (356 to 377)

373 MiB/s (367 to 378)

370 MiB/s (365 to 374)

sha3_512

-

hash2

369 MiB/s (364 to 373)

267 MiB/s (263 to 270)

267 MiB/s (264 to 269)

278 MiB/s (186 to 281)

shake_128

-

hash2

848 MiB/s (832 to 854)

575 MiB/s (557 to 584)

573 MiB/s (556 to 585)

523 MiB/s (513 to 532)

shake_256

-

hash2

688 MiB/s (681 to 694)

478 MiB/s (472 to 486)

478 MiB/s (302 to 484)

458 MiB/s (450 to 465)

keccak_256

-

xkcp

998 MiB/s (984 to 1018)

779 MiB/s (761 to 786)

768 MiB/s (754 to 773)

896 MiB/s (871 to 906)

blake2b_512

-

hash2

1617 MiB/s (1536 to 1654)

1478 MiB/s (1442 to 1529)

1472 MiB/s (1439 to 1486)

1490 MiB/s (1463 to 1542)

blake2s_256

-

hash2

921 MiB/s (901 to 981)

855 MiB/s (838 to 891)

847 MiB/s (594 to 868)

878 MiB/s (866 to 910)

blake3

-

blake3

2414 MiB/s (2297 to 2504)

1136 MiB/s (1100 to 1149)

1142 MiB/s (1092 to 1164)

1207 MiB/s (1131 to 1235)

ripemd_128

-

hash2

989 MiB/s (925 to 999)

560 MiB/s (529 to 567)

543 MiB/s (519 to 567)

560 MiB/s (520 to 567)

ripemd_160

-

hash2

610 MiB/s (592 to 644)

358 MiB/s (338 to 361)

359 MiB/s (333 to 361)

357 MiB/s (330 to 361)

siphash_32

-

hash2

1624 MiB/s (1504 to 1634)

1630 MiB/s (1582 to 1735)

1636 MiB/s (1534 to 1704)

216 MiB/s (209 to 224)

siphash_64

-

hash2

3274 MiB/s (2973 to 3285)

3240 MiB/s (3191 to 3491)

3273 MiB/s (3203 to 3457)

424 MiB/s (406 to 444)

hmac

-

hash2

599 MiB/s (562 to 618)

459 MiB/s (446 to 481)

455 MiB/s (347 to 484)

479 MiB/s (467 to 488)

hmac_md5_128

-

hash2

932 MiB/s (865 to 936)

772 MiB/s (712 to 783)

770 MiB/s (727 to 779)

773 MiB/s (726 to 778)

hmac_sha1_160

-

hash2

1185 MiB/s (1146 to 1243)

839 MiB/s (820 to 880)

831 MiB/s (622 to 853)

900 MiB/s (879 to 945)

hmac_sha2_224

-

hash2

582 MiB/s (565 to 619)

465 MiB/s (450 to 479)

453 MiB/s (445 to 480)

481 MiB/s (465 to 496)

hmac_sha2_256

-

hash2

582 MiB/s (567 to 619)

453 MiB/s (441 to 483)

454 MiB/s (451 to 483)

480 MiB/s (465 to 490)

hmac_sha2_384

-

hash2

911 MiB/s (885 to 942)

682 MiB/s (671 to 728)

693 MiB/s (677 to 738)

692 MiB/s (682 to 711)

hmac_sha2_512

-

hash2

930 MiB/s (905 to 973)

687 MiB/s (674 to 728)

692 MiB/s (680 to 736)

690 MiB/s (574 to 715)

hmac_sha2_512_224

-

hash2

939 MiB/s (906 to 971)

687 MiB/s (677 to 730)

684 MiB/s (668 to 731)

690 MiB/s (679 to 707)

hmac_sha2_512_256

-

hash2

904 MiB/s (896 to 972)

687 MiB/s (677 to 735)

689 MiB/s (464 to 731)

691 MiB/s (680 to 719)

hmac_sha3_224

-

hash2

733 MiB/s (721 to 741)

495 MiB/s (489 to 505)

507 MiB/s (498 to 510)

469 MiB/s (458 to 475)

hmac_sha3_256

-

hash2

686 MiB/s (677 to 692)

471 MiB/s (458 to 476)

480 MiB/s (472 to 484)

452 MiB/s (445 to 457)

hmac_sha3_384

-

hash2

526 MiB/s (519 to 548)

371 MiB/s (366 to 378)

374 MiB/s (370 to 377)

371 MiB/s (364 to 380)

hmac_sha3_512

-

hash2

366 MiB/s (361 to 373)

264 MiB/s (257 to 268)

267 MiB/s (208 to 268)

278 MiB/s (268 to 281)

hmac_ripemd_128

-

hash2

959 MiB/s (915 to 998)

556 MiB/s (524 to 568)

564 MiB/s (531 to 568)

562 MiB/s (520 to 567)

hmac_ripemd_160

-

hash2

607 MiB/s (596 to 644)

358 MiB/s (334 to 360)

358 MiB/s (339 to 361)

339 MiB/s (336 to 361)

hmac_blake2b_512

-

hash2

1548 MiB/s (1531 to 1642)

1478 MiB/s (1441 to 1540)

1484 MiB/s (1456 to 1487)

1486 MiB/s (1466 to 1582)

hmac_blake2s_256

-

hash2

922 MiB/s (897 to 975)

849 MiB/s (819 to 856)

849 MiB/s (768 to 857)

875 MiB/s (855 to 926)

fnv1a_32

-

hash2

1083 MiB/s (1026 to 1099)

1086 MiB/s (1000 to 1096)

1088 MiB/s (1051 to 1096)

1067 MiB/s (993 to 1088)

fnv1a_64

-

hash2

1095 MiB/s (1017 to 1099)

1088 MiB/s (1009 to 1095)

1084 MiB/s (1052 to 1095)

1066 MiB/s (994 to 1092)

xxhash_32

-

hash2

13514 MiB/s (12552 to 13567)

12526 MiB/s (12103 to 13333)

12533 MiB/s (11662 to 13363)

4681 MiB/s (4187 to 4864)

xxhash_64

-

hash2

26846 MiB/s (24974 to 27089)

24615 MiB/s (22409 to 26201)

24615 MiB/s (22642 to 26230)

7882 MiB/s (6520 to 8705)

xxh3_128

-

hash2

33947 MiB/s (31915 to 34582)

17647 MiB/s (16393 to 19018)

17857 MiB/s (9677 to 19093)

20408 MiB/s (16997 to 22706)

murmur3_32

-

hash2

3308 MiB/s (3263 to 3494)

2885 MiB/s (2706 to 2910)

2717 MiB/s (2635 to 2910)

1985 MiB/s (934 to 2126)

murmur3_128

-

hash2

8296 MiB/s (7225 to 8683)

6485 MiB/s (5930 to 6946)

6536 MiB/s (6298 to 6942)

4080 MiB/s (3939 to 4369)

spooky2_128

-

hash2

22325 MiB/s (16064 to 22388)

20305 MiB/s (18605 to 21759)

20339 MiB/s (19293 to 21798)

4595 MiB/s (4282 to 4949)

hkdf_extract

hmac_sha2_256

hash2

491 ns (457 ns to 502 ns)

654 ns (619 ns to 665 ns)

656 ns (617 ns to 670 ns)

682 ns (624 ns to 2.53 µs)

hkdf_extract

hmac_sha2_256

sodium

480 ns (460 ns to 498 ns)

880 ns (841 ns to 903 ns)

886 ns (870 ns to 903 ns)

646 ns (579 ns to 1.59 µs)

hkdf_extract

hmac_sha2_256

openssl

812 ns (769 ns to 870 ns)

2.01 µs (1.94 µs to 2.06 µs)

2.06 µs (1.96 µs to 2.12 µs)

-

hkdf_extract

hmac_sha2_512

hash2

652 ns (627 ns to 684 ns)

876 ns (830 ns to 904 ns)

882 ns (832 ns to 915 ns)

923 ns (905 ns to 4.20 µs)

hkdf_extract

hmac_sha2_512

sodium

633 ns (592 ns to 642 ns)

1.41 µs (1.38 µs to 1.43 µs)

1.42 µs (1.41 µs to 1.46 µs)

864 ns (814 ns to 1.81 µs)

hkdf_extract

hmac_sha2_512

openssl

996 ns (932 ns to 1.05 µs)

2.09 µs (1.98 µs to 2.12 µs)

2.13 µs (2.02 µs to 2.18 µs)

-

hkdf_expand

hmac_sha2_256

hash2

554 ns (516 ns to 563 ns)

688 ns (659 ns to 698 ns)

696 ns (657 ns to 737 ns)

706 ns (613 ns to 2.60 µs)

hkdf_expand

hmac_sha2_256

sodium

489 ns (460 ns to 504 ns)

890 ns (875 ns to 913 ns)

865 ns (843 ns to 900 ns)

618 ns (559 ns to 1.52 µs)

hkdf_expand

hmac_sha2_256

openssl

596 ns (554 ns to 645 ns)

1.62 µs (1.52 µs to 1.65 µs)

1.65 µs (1.55 µs to 1.68 µs)

-

hkdf_expand

hmac_sha2_512

hash2

776 ns (723 ns to 811 ns)

940 ns (887 ns to 957 ns)

944 ns (916 ns to 1.01 µs)

916 ns (889 ns to 3.27 µs)

hkdf_expand

hmac_sha2_512

sodium

625 ns (585 ns to 650 ns)

1.51 µs (1.50 µs to 1.55 µs)

1.40 µs (1.40 µs to 1.48 µs)

798 ns (783 ns to 1.78 µs)

hkdf_expand

hmac_sha2_512

openssl

762 ns (730 ns to 845 ns)

1.68 µs (1.58 µs to 1.72 µs)

1.70 µs (1.61 µs to 2.03 µs)

-

hkdf

hmac_sha2_256

hash2

1.00 µs (972 ns to 1.06 µs)

1.34 µs (1.27 µs to 1.36 µs)

1.35 µs (1.30 µs to 1.41 µs)

1.26 µs (1.21 µs to 3.28 µs)

hkdf

hmac_sha2_256

sodium

980 ns (937 ns to 1.01 µs)

1.71 µs (1.63 µs to 1.84 µs)

1.72 µs (1.68 µs to 1.76 µs)

1.12 µs (1.10 µs to 2.16 µs)

hkdf

hmac_sha2_256

bearssl

1.27 µs (1.21 µs to 1.53 µs)

1.53 µs (1.48 µs to 1.60 µs)

1.54 µs (1.49 µs to 1.57 µs)

1.57 µs (1.53 µs to 2.49 µs)

hkdf

hmac_sha2_256

openssl

1.13 µs (1.07 µs to 1.19 µs)

3.09 µs (2.95 µs to 3.14 µs)

3.15 µs (3.07 µs to 3.19 µs)

-

hkdf

hmac_sha2_512

hash2

1.39 µs (1.34 µs to 1.46 µs)

1.80 µs (1.70 µs to 1.81 µs)

1.81 µs (1.78 µs to 1.85 µs)

1.78 µs (1.69 µs to 4.25 µs)

hkdf

hmac_sha2_512

sodium

1.26 µs (1.19 µs to 1.28 µs)

2.84 µs (2.75 µs to 2.88 µs)

2.89 µs (2.84 µs to 2.95 µs)

1.55 µs (1.54 µs to 2.60 µs)

hkdf

hmac_sha2_512

bearssl

1.57 µs (1.48 µs to 1.89 µs)

1.91 µs (1.78 µs to 2.10 µs)

1.90 µs (1.80 µs to 2.08 µs)

1.99 µs (1.95 µs to 2.72 µs)

hkdf

hmac_sha2_512

openssl

1.48 µs (1.41 µs to 1.58 µs)

3.21 µs (3.08 µs to 3.27 µs)

3.27 µs (3.13 µs to 3.54 µs)

-

pbkdf2

hmac_sha2_256

hash2

21.05 ms (20.46 ms to 24.94 ms)

30.42 ms (30.00 ms to 31.70 ms)

30.96 ms (29.97 ms to 36.05 ms)

27.94 ms (27.50 ms to 28.96 ms)

pbkdf2

hmac_sha2_256

openssl

6.09 ms (5.87 ms to 6.18 ms)

36.13 ms (35.74 ms to 45.63 ms)

35.71 ms (35.16 ms to 42.51 ms)

-

pbkdf2

hmac_sha2_512

hash2

27.27 ms (26.79 ms to 28.15 ms)

41.64 ms (40.28 ms to 46.40 ms)

41.32 ms (40.31 ms to 42.32 ms)

39.83 ms (38.96 ms to 41.50 ms)

pbkdf2

hmac_sha2_512

openssl

16.21 ms (15.58 ms to 16.56 ms)

39.17 ms (38.69 ms to 43.46 ms)

38.95 ms (38.34 ms to 41.43 ms)

-

argon2id

-

sodium

38.26 ms (37.17 ms to 39.59 ms)

53.08 ms (51.59 ms to 58.40 ms)

53.36 ms (51.94 ms to 55.93 ms)

49.66 ms (47.56 ms to 51.11 ms)

scrypt

-

sodium

19.05 ms (18.50 ms to 20.49 ms)

19.86 ms (19.32 ms to 21.60 ms)

19.41 ms (19.09 ms to 20.82 ms)

16.84 ms (16.05 ms to 17.65 ms)

Performance

PBKDF2-HMAC-SHA-512’s throughput per backend, and what the timing guard adds to a keyed call, each measured from release builds.

PBKDF2-HMAC-SHA-512 throughput

How long each backend takes to derive 64 bytes by PBKDF2-HMAC-SHA-512 at 1,000,000 iterations, on each target where the backend exists. The figure that matters to a person choosing a backend is how many password guesses an attacker (or a login) can afford per second, which is the reciprocal of these times.

Measured on 2026-11-15 on Apple M5 Max, 18 cores, 128 GiB, Darwin 27.0.0; WebAssembly under wasmtime 47.0.3 (5554cc1a6 2026-07-31) (wasip2, wasip3) and node v26.13.0 (Emscripten); built with variant=release optimization=speed.

Each case is the median of its invocations’ medians, with the fastest and slowest single run beside it: the spread is part of the result.

Warning
the machine was shared and loaded while this was measured (many builds ran at once; 1, 5 and 15 minute load averages 14/19/42 before and 40/28/43 after, on 18 cores; rule: the larger of the two 1-minute load averages exceeds the core count). Read the spread, not a single figure.
Backend Target Median (ms) Fastest run (ms) Slowest run (ms) Compiler

backends::hash2

native

351

342

384

Apple LLVM 21.0.0 (clang-2100.4.1.1)

backends::hash2

wasip2

512

486

855

Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141)

backends::hash2

wasip3

623

502

1092

Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141)

backends::hash2

emscripten

583

501

798

Clang 24.0.0git (https:/github.com/llvm/llvm-project f718ebe873411a562ef6e5c27da36d75b7aaec98)

backends::openssl

native

177

174

244

Apple LLVM 21.0.0 (clang-2100.4.1.1)

backends::openssl

wasip2

686

479

782

Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141)

backends::openssl

wasip3

511

484

658

Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141)

sodium crypto_auth_hmacsha512 loop

native

517

417

625

Apple LLVM 21.0.0 (clang-2100.4.1.1)

sodium crypto_auth_hmacsha512 loop

wasip2

963

876

1697

Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141)

sodium crypto_auth_hmacsha512 loop

wasip3

993

860

1666

Clang 23.1.0-wasi-sdk (https://github.com/llvm/llvm-project 895aa2c896ada719451be2e3673c83da8ddf1141)

sodium crypto_auth_hmacsha512 loop

emscripten

579

509

1005

Clang 24.0.0git (https:/github.com/llvm/llvm-project f718ebe873411a562ef6e5c27da36d75b7aaec98)

Every case derived the independent value (Python’s hashlib.pbkdf2_hmac) on every run; backends::openssl does not exist on Emscripten; libsodium has no PBKDF2, so its row measures its HMAC-SHA-512 in PBKDF2’s loop, written in the benchmark and never part of the library.

The timing guard’s cost

Every keyed function (a MAC, a key derivation, a password hash, a keyed mode of BLAKE2b or BLAKE3) runs inside webcpp::secure::timing_guard, webcpp::secure’s guard, which on 64-bit ARM under macOS, iOS, Linux, Android and Windows, where the CPU has FEAT_DIT, sets DIT (data-independent timing) for the call and restores the thread’s state after it (Data-independent timing (DIT)): one mrs; where DIT was clear, two msr each followed by an isb; where it was set, a second mrs on the way out (and an msr if something inside cleared it). Elsewhere (x86, WebAssembly, ARM64EC) it executes no instruction. A function keyed by its arguments, called without a key, holds a disengaged guard, which reads its flag and does nothing else.

Measured natively on 2026-11-26 (UTC) on Apple M5 Max (arm64), Darwin 27.0.0, built with variant=release optimization=speed by Apple LLVM 21.0.0 (clang-2100.4.1.1) (bench/timing.cpp): each row is the median of 5 runs of 10,000,000 guards around a store, with the fastest and slowest run beside it, each minus the median of the same loop without the guard, in nanoseconds per call; a figure that rounds to zero or below, the loop’s noise, shows as 0.0. The guard sets DIT on this machine. The machine’s 1, 5 and 15 minute load averages were 2/3/3 before and 2/3/3 after, on 18 cores.

The thread’s DIT on entry What the guard does Median (ns) Fastest (ns) Slowest (ns)

clear, as a program that sets nothing has it

reads DIT, sets it, and clears it on the way out

37.0

37.0

39.6

already set, by the program or by an outer guard

reads DIT, and reads it again on the way out

1.2

1.2

1.2

any: a function keyed by its arguments, called without a key

reads its flag and does nothing else

0.0

0.0

0.0

Allocation

hash’s own code allocates nothing: no function of webcpp::hash calls the global operator new, on any target, and none calls the C library’s allocator on the targets where a program can count it. Test allocation proves that hash allocates nothing for Keccak-256, BLAKE3, Boost.Hash2’s digests and hmacs, and HKDF (its three functions over byte pieces too, with inputs of 4 KiB and 1 MiB in four pieces) and PBKDF2 on backends::hash2, backends::sodium and backends::bearssl, the failing calls (every guard’s refusal) included. It counts every form of operator new and the C library’s malloc, calloc, realloc, aligned_alloc and posix_memalign on glibc, macOS, Emscripten and WASI (on WASI through the linker’s --wrap, which sees the calls of the program and of its libraries but not those wasi-libc’s own functions make to one another); a program cannot count them on MSVC, where the proof is operator new alone. A control allocates once through every form and moves the counter, and the test asserts the exact number of calls made per backend, so a backend that silently dropped out fails. What the counter does not see is mmap, which the C libraries below use.

One exception is not hash’s own: on Emscripten, a call on backends::webcrypto awaits each of WebCrypto’s promises through webcpp::asio’s browser::async_await, whose bridge to JavaScript takes a block from the C library per promise awaited: one promise for async_digest; two for async_hmac, async_pbkdf2, the single-buffer async_hkdf and async_hkdf_extract (over pieces too), which import a key first; 1 + n for async_hkdf_expand and 3 + n for async_hkdf over pieces, which sign once per block of output, n the output’s size in digests rounded up. The pieces are gathered into JavaScript memory, not webcpp’s. Test allocation counts a bare await’s blocks, prints them as record operation=async_await, and checks that each WebCrypto call makes exactly that many per promise and nothing more. The table below leaves that block out: it lists the C libraries of hash’s backends, and the block is webcpp::asio’s.

The libraries of the backends are another matter, and the table says so plainly. Their allocations are the library’s, outside the user’s allocator, and hash does not hide them.

  • libsodium’s Argon2id takes its memory matrix (memory bytes, 64 MiB for argon2id_interactive) from mmap where there is one, else posix_memalign, else malloc. The calls the table counts for it are small bookkeeping blocks, not the matrix: the matrix is invisible to the counter wherever mmap supplies it.

  • libsodium’s scrypt takes its 128 r (N + p) bytes from mmap where there is one, else from malloc.

  • libsodium’s first call of a program runs sodium_init, whose allocations are the sodium_init rows.

  • OpenSSL allocates a key-derivation context and its digests through its own allocator on every call; test allocation_openssl replaces that allocator with CRYPTO_set_mem_functions before anything else and counts each call through it. A digest on backends::openssl allocates an EVP_MD_CTX (EVP_MD_CTX_new) and the digest’s context, in each digest_of and in each make of a hasher, and a MAC an EVP_MAC_CTX (EVP_MAC_CTX_new) and the MAC’s context in each mac; the test prints those counts too, and the table below holds the key derivations’ alone. The counts are those of OpenSSL 3.5.9 as webcpp builds it, are measured and never bounded, and change with the version.

  • Botan, a C++ library, makes its objects (a hash, a MAC, a key derivation, a password hash) with the global operator new in every call on backends::botan, and the buffers of their state and secrets with the C library’s calloc, through its secure allocator, which overwrites each buffer before it frees it; Argon2’s matrix and scrypt’s buffer are among them. So on backends::botan the operator new column counts Botan’s calls, not hash’s, and the C library’s column counts every block (the malloc of operator new included). Test allocation_botan counts each call of every entry point Botan has, a first and a steady one, prints each, never bounds them, and asserts that a guard’s refusal, before Botan is reached, allocates nothing; the table gives, per operation, the range over the algorithms Botan has. The counts are those of Botan 3.14.1 as webcpp configures it.

The table is generated from measurements.allocation.json by bench/allocation_collect.py, and only from release builds: the counts are those of allocation_release, allocation_openssl_release and allocation_botan_release of bench/Jamfile, the programs of the three tests built at variant=release, and the collector refuses an output of any other variant. The tests of the lanes keep the lane’s variant. The figures are those of the machine and the day the file records (every row collected on 2026-11-24), to be measured again in the final pass before the release.

Operation Backend Target operator new The C library’s own allocations

sodium_init

sodium

native

0

C library calls: 0

argon2id

sodium

native

0

C library calls: 3

scrypt

sodium

native

0

C library calls: 0

hkdf

openssl

native

0

OpenSSL: 4080 first call (hmac_sha2_256), 30 first call (hmac_sha2_512), 24 steady state

hkdf_extract over pieces

openssl

native

0

OpenSSL: 10 first call (hmac_sha2_256), 10 first call (hmac_sha2_512), 10 steady state

hkdf_expand over pieces

openssl

native

0

OpenSSL: 30 first call (hmac_sha2_256), 20 first call (hmac_sha2_512), 20 steady state

hkdf over pieces

openssl

native

0

OpenSSL: 40 first call (hmac_sha2_256), 30 first call (hmac_sha2_512), 30 steady state

pbkdf2

openssl

native

0

OpenSSL: 30 first call (hmac_sha2_256), 18 first call (hmac_sha2_512), 18 steady state

digest_of

botan

native

1 to 4

Botan: 1 to 13 C library calls (operator new’s included), over its 25 algorithms; the same in a steady call

hasher

botan

native

1 to 4

Botan: 1 to 13 C library calls (operator new’s included), over its 25 algorithms; the same in a steady call

mac

botan

native

3 to 8

Botan: 5 to 26 C library calls (operator new’s included), over its 27 algorithms; the same in a steady call

hkdf_extract

botan

native

16 to 26

Botan: 19 to 29 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf_expand

botan

native

13 to 26

Botan: 16 to 30 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf

botan

native

17 to 30

Botan: 25 to 39 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

pbkdf2

botan

native

16 to 29

Botan: 21 to 34 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

kbkdf

botan

native

18 to 28

Botan: 21 to 32 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf_extract over pieces

botan

native

4 to 7

Botan: 7 to 10 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf_expand over pieces

botan

native

4 to 7

Botan: 7 to 11 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf over pieces

botan

native

8 to 14

Botan: 14 to 20 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

sskdf

botan

native

4 to 7

Botan: 5 to 8 C library calls (operator new’s included), over its 10 algorithms; the same in a steady call

x963kdf

botan

native

4

Botan: 5 to 6 C library calls (operator new’s included), over its 5 algorithms; the same in a steady call

argon2id

botan

native

6

Botan: 9 C library calls (operator new’s included), of kdfs::argon2id; the same in a steady call

argon2

botan

native

6

Botan: 9 C library calls (operator new’s included), over its 3 algorithms; the same in a steady call

scrypt

botan

native

6

Botan: 13 C library calls (operator new’s included), of kdfs::scrypt; the same in a steady call

bcrypt

botan

native

7

Botan: 10 C library calls (operator new’s included), of kdfs::bcrypt; the same in a steady call

bcrypt_verify

botan

native

7

Botan: 11 C library calls (operator new’s included), of kdfs::bcrypt; the same in a steady call

bcrypt_pbkdf

botan

native

3

Botan: 10 C library calls (operator new’s included), of kdfs::bcrypt_pbkdf; the same in a steady call

sodium_init

sodium

wasip2

0

C library calls: 1

argon2id

sodium

wasip2

0

C library calls: 5

scrypt

sodium

wasip2

0

C library calls: 1

hkdf

openssl

wasip2

0

OpenSSL: 3960 first call (hmac_sha2_256), 30 first call (hmac_sha2_512), 24 steady state

hkdf_extract over pieces

openssl

wasip2

0

OpenSSL: 10 first call (hmac_sha2_256), 10 first call (hmac_sha2_512), 10 steady state

hkdf_expand over pieces

openssl

wasip2

0

OpenSSL: 30 first call (hmac_sha2_256), 20 first call (hmac_sha2_512), 20 steady state

hkdf over pieces

openssl

wasip2

0

OpenSSL: 40 first call (hmac_sha2_256), 30 first call (hmac_sha2_512), 30 steady state

pbkdf2

openssl

wasip2

0

OpenSSL: 30 first call (hmac_sha2_256), 18 first call (hmac_sha2_512), 18 steady state

sodium_init

sodium

wasip3

0

C library calls: 1

argon2id

sodium

wasip3

0

C library calls: 5

scrypt

sodium

wasip3

0

C library calls: 1

hkdf

openssl

wasip3

0

OpenSSL: 3960 first call (hmac_sha2_256), 30 first call (hmac_sha2_512), 24 steady state

hkdf_extract over pieces

openssl

wasip3

0

OpenSSL: 10 first call (hmac_sha2_256), 10 first call (hmac_sha2_512), 10 steady state

hkdf_expand over pieces

openssl

wasip3

0

OpenSSL: 30 first call (hmac_sha2_256), 20 first call (hmac_sha2_512), 20 steady state

hkdf over pieces

openssl

wasip3

0

OpenSSL: 40 first call (hmac_sha2_256), 30 first call (hmac_sha2_512), 30 steady state

pbkdf2

openssl

wasip3

0

OpenSSL: 30 first call (hmac_sha2_256), 18 first call (hmac_sha2_512), 18 steady state

sodium_init

sodium

emscripten

0

C library calls: 0

argon2id

sodium

emscripten

0

C library calls: 4

scrypt

sodium

emscripten

0

C library calls: 1

digest_of

botan

emscripten

1 to 6

Botan: 1 to 15 C library calls (operator new’s included), over its 25 algorithms; the same in a steady call

hasher

botan

emscripten

1 to 6

Botan: 1 to 15 C library calls (operator new’s included), over its 25 algorithms; the same in a steady call

mac

botan

emscripten

4 to 15

Botan: 7 to 32 C library calls (operator new’s included), over its 27 algorithms; the same in a steady call

hkdf_extract

botan

emscripten

21 to 41

Botan: 24 to 44 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf_expand

botan

emscripten

21 to 41

Botan: 24 to 45 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf

botan

emscripten

24 to 44

Botan: 32 to 53 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

pbkdf2

botan

emscripten

23 to 43

Botan: 28 to 48 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

kbkdf

botan

emscripten

24 to 43

Botan: 27 to 47 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf_extract over pieces

botan

emscripten

4 to 13

Botan: 7 to 16 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf_expand over pieces

botan

emscripten

4 to 13

Botan: 10 to 17 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

hkdf over pieces

botan

emscripten

8 to 26

Botan: 18 to 32 C library calls (operator new’s included), over its 14 algorithms; the same in a steady call

sskdf

botan

emscripten

7 to 10

Botan: 8 to 11 C library calls (operator new’s included), over its 10 algorithms; the same in a steady call

x963kdf

botan

emscripten

7

Botan: 8 to 9 C library calls (operator new’s included), over its 5 algorithms; the same in a steady call

argon2id

botan

emscripten

10

Botan: 13 C library calls (operator new’s included), of kdfs::argon2id; the same in a steady call

argon2

botan

emscripten

10

Botan: 13 C library calls (operator new’s included), over its 3 algorithms; the same in a steady call

scrypt

botan

emscripten

8

Botan: 15 C library calls (operator new’s included), of kdfs::scrypt; the same in a steady call

bcrypt

botan

emscripten

9

Botan: 12 C library calls (operator new’s included), of kdfs::bcrypt; the same in a steady call

bcrypt_verify

botan

emscripten

10

Botan: 14 C library calls (operator new’s included), of kdfs::bcrypt; the same in a steady call

bcrypt_pbkdf

botan

emscripten

6

Botan: 13 C library calls (operator new’s included), of kdfs::bcrypt_pbkdf; the same in a steady call

The code webcpp writes, and what the C libraries do

webcpp’s rule is that it writes no cryptography of its own: every primitive is an audited library’s. hash departs from it twice, by the owner’s decision of 2026-11-14, each time for a construction over an audited primitive, never for a primitive, and each under conditions that its tests and its review hold it to.

HKDF and PBKDF2 over Boost.Hash2’s hmac

backends::hash2 is webcpp’s own HKDF and PBKDF2, written over Boost.Hash2’s hmac<H>, so that both run on every target and over every Hash2 hmac without a C library. The conditions:

  • the code follows each RFC’s text step by step, with the RFC’s step names in its comments, in under 150 lines for both functions;

  • RFC 5869’s seven HKDF cases, RFC 6070’s six PBKDF2 cases and RFC 7914’s two pass, with further cases computed by an independent implementation (Python’s hmac and hashlib);

  • it agrees with every other backend that has the same function on random inputs, on every target where one exists: natively OpenSSL, libsodium and BearSSL; on WebAssembly libsodium and BearSSL, and the browser’s WebCrypto on Emscripten;

  • every intermediate value that webcpp holds is wiped before the function returns, which a test observes wipe by wipe; Boost.Hash2’s own temporaries (the padded key inside the constructor of hmac and the inner digest of its result()) are not reached, and What each backend does with secrets and memory says so;

  • it never compares a secret.

Keccak-256’s sponge over XKCP’s permutation

keccak_256 runs the Keccak team’s XKCP for the Keccak-p[1600] permutation; webcpp’s code does the absorbing, the padding (the byte 0x01, zeros, the byte 0x80) and the squeezing, line for line as Boost.Hash2’s detail::keccak_base<0x01, 512, 256> does. The conditions: Hash2’s keccak_base is the oracle of a test on random sequences of update and result calls, which must give its results; and the type becomes an alias of Boost.Hash2’s own keccak_256 once a Boost release publishes one (Upstream: Keccak in Boost.Hash2), with no change to any result.

What the C libraries allocate

hash’s own code allocates nothing, but three of its libraries do, outside any allocator of the program, and hash records it rather than hides it:

  • libsodium’s Argon2id and scrypt allocate the memory their costs name, with mmap where the system has it, else malloc (and, for Argon2’s 64-byte alignment, posix_memalign). A program whose memory must come from its own allocator would need the Argon2 reference implementation’s allocation callbacks, a possible later backend; it is not built.

  • OpenSSL allocates its KDF and context in every call, through its own allocator, and webcpp keeps no OpenSSL object between calls, which would be state shared between threads. A digest allocates an EVP_MD_CTX (EVP_MD_CTX_new) and the digest’s context: digest_of frees them before it returns, and a hasher owns them, its own and no other’s, until it finishes or is destroyed. A MAC allocates an EVP_MAC_CTX (EVP_MAC_CTX_new) and the MAC’s context, which mac frees before it returns.

  • Botan makes its objects with the global operator new in every call on backends::botan, and the buffers of their state and secrets with the C library’s calloc, which it overwrites before freeing them; webcpp keeps no Botan object between calls but the one of a hasher, which it owns from make until it finishes, is destroyed or is moved from. Botan also throws: hash catches every exception at each call’s boundary, so that a program sees a value, and a program without exceptions has no backends::botan.

The counting test of allocations proves that hash’s own code allocates nothing, on every backend and target, and measures what these libraries allocate where a program can count it; the measured chapters at the end of Choosing a backend show the counts.

Upstream: Keccak in Boost.Hash2

hash’s keccak_256 exists because Boost.Hash2 has Keccak-256 only under detail: its detail::keccak_base<0x01, 512, 256> is exactly the function, but no public name gives it. This section is the text of a proposal to Boost.Hash2 that gives it one, with Keccak-224, Keccak-384 and Keccak-512, for webcpp’s owner to open as a pull request. When a Boost release has it, webcpp::hash::keccak_256 becomes an alias of boost::hash2::keccak_256, a program no longer links /third_party//xkcp for it, and no result changes, since hash’s sponge is already Hash2’s (Keccak-256’s sponge over XKCP’s permutation).

The proposal

Title: Add keccak_224, keccak_256, keccak_384 and keccak_512.

Motivation. Keccak-256, the Keccak team’s submission to the SHA-3 competition with its original padding, is the hash of Ethereum and of every chain and tool compatible with it: addresses, transaction ids, Solidity selectors, EIP-55 checksums. It differs from SHA3-256 only in its padding byte, 0x01 instead of FIPS 202’s 0x06, and Hash2 already implements both through detail::keccak_base; users who need Keccak-256 today reach into detail or link another library. The four classes below make the existing code public under the names other libraries use (Keccak-256 in OpenSSL’s default provider, keccak_256 in noble-hashes and in Ethereum’s tools).

The change. In boost/hash2/sha3.hpp, after shake_256: a class template detail::keccak_seeded<D> over keccak_base<0x01, 2 * D, D>, with the three constructors every SHA-3 class has (the default, the 64-bit seed and the byte seed, each with the SHA-3 classes’ meaning), and four classes that inherit them, with their HMAC aliases. The seed’s eight bytes are fed little-endian, one at a time, which gives the bytes of detail::write64le without an array.

namespace boost
{
namespace hash2
{
namespace detail
{

// Keccak as submitted to the SHA-3 competition: keccak_base with the padding
// byte 0x01, seeded as the SHA-3 classes are
template<int D>
class keccak_seeded: public keccak_base<0x01, 2 * D, D>
{
public:

    BOOST_HASH2_SHA3_CONSTEXPR keccak_seeded()
    {
    }

    BOOST_HASH2_SHA3_CONSTEXPR explicit keccak_seeded( std::uint64_t seed )
    {
        if( seed != 0 )
        {
            unsigned char byte = 0;

            for( int i = 0; i < 8; ++i )
            {
                byte = static_cast<unsigned char>( seed >> ( 8 * i ) );
                this->update( &byte, 1 );
            }

            this->result();
            this->update( &byte, 0 ); // sets finalized_ to false
        }
    }

    BOOST_HASH2_SHA3_CONSTEXPR keccak_seeded( unsigned char const * p, std::size_t n )
    {
        if( n != 0 )
        {
            this->update( p, n );
            this->result();
            this->update( p, 0 ); // sets finalized_ to false
        }
    }

    keccak_seeded( void const * p, std::size_t n ): keccak_seeded( static_cast<unsigned char const*>( p ), n )
    {
    }
};

} // namespace detail

class keccak_224: public detail::keccak_seeded(224)
{
public:

    using detail::keccak_seeded<224>::keccak_seeded;
};

class keccak_256: public detail::keccak_seeded(256)
{
public:

    using detail::keccak_seeded<256>::keccak_seeded;
};

class keccak_384: public detail::keccak_seeded(384)
{
public:

    using detail::keccak_seeded<384>::keccak_seeded;
};

class keccak_512: public detail::keccak_seeded(512)
{
public:

    using detail::keccak_seeded<512>::keccak_seeded;
};

using hmac_keccak_224 = hmac<keccak_224>;
using hmac_keccak_256 = hmac<keccak_256>;
using hmac_keccak_384 = hmac<keccak_384>;
using hmac_keccak_512 = hmac<keccak_512>;

} // namespace hash2
} // namespace boost

The test, for test/keccak.cpp: the digests of the empty message and of the byte 0xCC are the Len = 0 and Len = 8 entries of the Keccak team’s known-answer files of the SHA-3 competition’s third round (ShortMsgKAT_224.txt to ShortMsgKAT_512.txt); those of "abc" and the HMAC’s were computed with an independent Keccak that reproduces those entries and Python’s SHA-3. It also checks incremental input and the seeds against keccak_base itself.

namespace
{

template<class H> std::string digest( std::string const& s )
{
    H h;
    h.update( s.data(), s.size() );
    return to_string( h.result() );
}

template<class H> std::string digest_in_pieces( std::string const& s )
{
    H h;

    for( char c: s )
    {
        h.update( &c, 1 );
    }

    return to_string( h.result() );
}

void test_published()
{
    using namespace boost::hash2;

    std::string const empty;
    std::string const cc( 1, static_cast<char>( 0xCC ) );
    std::string const abc( "abc" );

    BOOST_TEST_EQ( digest<keccak_224>( empty ), "f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd" );
    BOOST_TEST_EQ( digest<keccak_224>( cc ), "a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802" );
    BOOST_TEST_EQ( digest<keccak_224>( abc ), "c30411768506ebe1c2871b1ee2e87d38df342317300a9b97a95ec6a8" );

    BOOST_TEST_EQ( digest<keccak_256>( empty ), "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" );
    BOOST_TEST_EQ( digest<keccak_256>( cc ), "eead6dbfc7340a56caedc044696a168870549a6a7f6f56961e84a54bd9970b8a" );
    BOOST_TEST_EQ( digest<keccak_256>( abc ), "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45" );

    BOOST_TEST_EQ( digest<keccak_384>( empty ), "2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff" );
    BOOST_TEST_EQ( digest<keccak_384>( cc ), "1b84e62a46e5a201861754af5dc95c4a1a69caf4a796ae405680161e29572641f5fa1e8641d7958336ee7b11c58f73e9" );
    BOOST_TEST_EQ( digest<keccak_384>( abc ), "f7df1165f033337be098e7d288ad6a2f74409d7a60b49c36642218de161b1f99f8c681e4afaf31a34db29fb763e3c28e" );

    BOOST_TEST_EQ( digest<keccak_512>( empty ), "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e" );
    BOOST_TEST_EQ( digest<keccak_512>( cc ), "8630c13cbd066ea74bbe7fe468fec1dee10edc1254fb4c1b7c5fd69b646e44160b8ce01d05a0908ca790dfb080f4b513bc3b6225ece7a810371441a5ac666eb9" );
    BOOST_TEST_EQ( digest<keccak_512>( abc ), "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96" );
}

void test_hmac()
{
    // RFC 4231's second case, over Keccak-256 instead of SHA-256
    boost::hash2::hmac_keccak_256 mac( "Jefe", 4 );
    std::string const message( "what do ya want for nothing?" );
    mac.update( message.data(), message.size() );

    BOOST_TEST_EQ( to_string( mac.result() ), "aa9aed448c7abc8b5e326ffa6a01cdedf7b4b831881468c044ba8dd4566369a1" );
}

template<class H> void test_incremental()
{
    std::string const s( 1000, 'a' );
    BOOST_TEST_EQ( digest<H>( s ), digest_in_pieces<H>( s ) );
}

template<class H, int D> void test_seeded()
{
    // A seed feeds the hash as it feeds the SHA-3 class of the same size: its eight
    // bytes, little-endian, then a result; a key of n bytes, likewise
    boost::hash2::detail::keccak_base<0x01, 2 * D, D> expected;

    std::string const seed( "\x07\0\0\0\0\0\0\0", 8 );
    expected.update( seed.data(), seed.size() );
    expected.result();
    expected.update( seed.data(), 0 );

    H h( 7 );
    BOOST_TEST_EQ( to_string( h.result() ), to_string( expected.result() ) );

    H h0( 0 );
    BOOST_TEST_EQ( to_string( h0.result() ), digest<H>( "" ) );

    boost::hash2::detail::keccak_base<0x01, 2 * D, D> expected_key;

    std::string const key( "key" );
    expected_key.update( key.data(), key.size() );
    expected_key.result();
    expected_key.update( key.data(), 0 );

    H hk( key.data(), key.size() );
    BOOST_TEST_EQ( to_string( hk.result() ), to_string( expected_key.result() ) );
}

} // namespace

The documentation, for the reference’s list of algorithms: "keccak_224, keccak_256, keccak_384, keccak_512: Keccak as submitted to the SHA-3 competition, before FIPS 202 changed its padding; Keccak-256 is Ethereum’s hash. Not interchangeable with sha3_224 to sha3_512, whose digests differ."

The evidence

webcpp builds this text against Boost.Hash2 1.92 in its test upstream_keccak, on every target webcpp has: the digests above pass, and webcpp::hash::keccak_256 gives the results of the proposed keccak_256 for every length up to three blocks and for random sequences of update and result, which is what makes the later alias safe. The proposal is the owner’s to open; nothing here is sent upstream.

An index for language models

llms.txt, published beside this page, lists every function of hash with its header, its standard, what it is for, its status, when to choose it and the backends that implement it, each with the Jamfile line and the targets, then every row of Choose by use case, in the llms.txt form: a model that reads it can answer "which function, which backend, which Jamfile line" without reading the page. It is generated with the tables of this page from the same data, doc/capabilities.json and doc/guide.json, by tools/hash/doc_tables.py, whose check runs when the page is built; the two never disagree.

Reference

Every name hash declares, in the namespaces webcpp::hash and its backends and kdfs, from the Doc Comments of its headers: each class, function, type and enumerator with its declaration, what it does, what it asks of its caller and how it fails. The other sections teach the library; this one is where a name is looked up.

Macros

Name Description

WEBCPP_HASH_HAS_BEARSSL

Defined by /third_party//bearssl when the program links BearSSL; a program built without b2 defines it to 1 itself.

WEBCPP_HASH_HAS_BLAKE3

Defined by /third_party//blake3 when the program links the BLAKE3 C implementation; a program built without b2 defines it to 1 itself.

WEBCPP_HASH_HAS_BOTAN

Defined by /third_party//botan when the program links Botan; a program built without b2 defines it to 1 itself. Botan reports its errors by throwing: in a build without exceptions (WEBCPP_HASH_NO_EXCEPTIONS) backends/botan.hpp declares nothing, and a call on backends::botan stops at compile time. /third_party//botan is built natively and for Emscripten.

WEBCPP_HASH_HAS_OPENSSL

Defined by /webcpp/hash//openssl when the program links OpenSSL; a program built without b2 defines it to 1 itself. Refused on Emscripten, where OpenSSL is not built.

WEBCPP_HASH_HAS_SODIUM

Defined by /third_party//sodium when the program links libsodium; a program built without b2 defines it to 1 itself.

WEBCPP_HASH_HAS_THREADS

Defined where the heavy functions of <webcpp/hash/async.hpp> (async_argon2id, async_argon2, async_scrypt, async_pbkdf2 on a synchronous backend) run on another thread: natively, where Boost.Config’s BOOST_HAS_THREADS is defined (every native build, b2’s threading=single included), and on Emscripten built with -pthread (b2’s threading=multi); never on wasip2 or wasip3, whose cooperative threads do not run in parallel. Without it each of those names refuses at compile time.

WEBCPP_HASH_HAS_XKCP

Defined by /third_party//xkcp when the program links XKCP; a program built without b2 defines it to 1 itself.

WEBCPP_HASH_LIFETIMEBOUND

The attribute that says a parameter’s object must outlive the object a constructor makes from it: [[clang::lifetimebound]] under clang, [[msvc::lifetimebound]] under MSVC where it has it, nothing elsewhere. byte_pieces’ constructors carry it, so that a byte_pieces named from a braced list, whose array dies at the end of its declaration, is a warning where the compiler can tell.

WEBCPP_HASH_NO_EXCEPTIONS

Defined when webcpp::hash is built without exceptions: when webcpp has none (the compiler has none, or the developer defined WEBCPP_NO_EXCEPTIONS for every webcpp library), or when the developer defines it alone.

WEBCPP_HASH_NO_THREADS

Defined by the developer to leave WEBCPP_HASH_HAS_THREADS undefined in a build that has threads: the heavy functions of <webcpp/hash/async.hpp> then refuse at compile time, so that no call of the program can start a thread’s work.

WEBCPP_HASH_WEBASSEMBLY

Defined on the WebAssembly targets, wasip2, wasip3 and Emscripten.

webcpp::hash

Types

Name Description

argon2_parameters

Argon2’s parameters (spec 2.15), defined in argon2.hpp; declared here for the engines.

argon2id_parameters

The costs of Argon2id with one lane, as libsodium’s crypto_pwhash takes them, for argon2id.

bcrypt_parameters

bcrypt’s cost (2^cost rounds, 4 to 31) and the version written, 'a', 'b' or 'y'.

blake3

BLAKE3, its keyed mode, its key derivation and its extendable output, over the official C implementation, in Boost.Hash2’s HashAlgorithm form.

byte_pieces

Byte sequences read one after another, as if concatenated: {a, b, c} at the call.

digest_options

The parameters of a digest (spec 2.15), defined in digest.hpp; declared here for the engines, which take them.

hasher

A hash fed in pieces, with one result: make, update as often as the data comes, then finish once (spec 2.15).

kbkdf_options

The fixed input of SP 800-108’s KBKDF in counter mode, defined in kdf_standards.hpp; declared here for the engines.

keccak_256

Keccak-256 with the original padding, Ethereum’s hash, in Boost.Hash2’s HashAlgorithm form.

mac_options

The parameters of a MAC (spec 2.15), defined in mac.hpp; declared here for the engines.

scrypt_parameters

The costs of scrypt, RFC 7914’s N, r and p.

Type Aliases

Name Description

default_async_backend

The backend of the asynchronous family when a call names none.

default_backend

The backend a function of Algorithm uses when the call names none (spec 4.1).

default_kdf_backend

The backend hkdf_extract, hkdf_expand, hkdf and pbkdf2 use when the program names none: default_backend of Kdf, backends::hash2 on every target.

digest

A digest of N bytes, Boost.Hash2’s.

hmac

HMAC over H, RFC 2104, Boost.Hash2’s.

Enums

Name Description

error

Why an operation of webcpp::hash failed.

Functions

Name Description

argon2

Argon2 version 0x13 (RFC 9106) of the variant Variant with every parameter: fills output_bytes from password_bytes and salt_bytes.

argon2id

Argon2id version 0x13 (RFC 9106) with one lane, no secret and no associated data: fills output_bytes from password_bytes and salt_bytes.

async_argon2

Argon2 of the variant Variant with every parameter (RFC 9106) on a thread of work_executor’s context, as async_argon2id runs.

async_argon2id

Argon2id (RFC 9106, one lane) on a thread of work_executor’s context (spec 11.5).

async_bcrypt

bcrypt on a thread of work_executor’s context (spec 11.5), as async_argon2id runs: the guards of bcrypt first, whose refusal completes through a post, output_characters untouched; then the work.

async_bcrypt_pbkdf

OpenBSD’s bcrypt_pbkdf on a thread of work_executor’s context, as async_argon2id runs.

async_bcrypt_verify

bcrypt_verify on a thread of work_executor’s context, as async_argon2id runs, completing with whether the password gives the string: it computes bcrypt in full, as slow as bcrypt (spec 11.5: every deliberately slow function has its heavy variant).

async_digest

Hashes input_bytes into output_bytes with the digest Digest, asynchronously (spec 11): on a synchronous backend, the default, at once, completing through a post on the handler’s associated executor (completion_executor by default), never inside the call.

async_hkdf

async_hkdf overloads

async_hkdf_expand

async_hkdf_expand overloads

async_hkdf_extract

async_hkdf_extract overloads

async_hmac

The HMAC of input_bytes under key_bytes over the Boost.Hash2 hmac Hmac, asynchronously (spec 11), as async_digest runs: the tag of mac<macs::hmac<...>> over Hmac’s digest.

async_pbkdf2

PBKDF2 (RFC 8018), asynchronously.

async_scrypt

scrypt (RFC 7914) on a thread of work_executor’s context, as async_argon2id runs.

bcrypt

The modular crypt string of password_bytes under the caller’s 16-byte salt_bytes, into 60 chars: "\$2", the version, "\$", the cost in two digits, "$", the salt then the hash in bcrypt’s base 64.

bcrypt_pbkdf

OpenBSD’s bcrypt_pbkdf, as OpenSSH’s keys use it: fills output_bytes from password_bytes and salt_bytes by round_count rounds of bcrypt’s hash over their SHA-512 digests, its blocks interleaved.

bcrypt_verify

Whether password_bytes gives encoded_hash, a modular crypt string of bcrypt, compared in constant time.

blake2b_subkey

The subkey subkey_id of master_key in context_bytes, libsodium’s crypto_kdf_derive_from_key: keys for different purposes from one master key, each unrelated to the others and to the master key without it.

category

The category of every error.

digest_of

Hashes input_bytes into output_bytes with the digest Digest on Backend, in one call.

hkdf

hkdf overloads

hkdf_expand

hkdf_expand overloads

hkdf_extract

hkdf_extract overloads

kbkdf

SP 800-108’s key-based key derivation (NIST SP 800-108r1, section 4.1, counter mode) over the HMAC Hmac: fills output_bytes from the key-derivation key key_bytes, each block an HMAC under key_bytes of the counter, then the fixed input algorithm_options states.

mac

The tag of input_bytes under key_bytes, with the MAC Mac on Backend.

make_error_code

Makes the error_code of an error, as its implicit conversion does.

pbkdf2

PBKDF2 (RFC 8018, section 5.2): fills output_bytes from password_bytes and salt_bytes by iteration_count rounds of Hmac.

scrypt

scrypt (RFC 7914): fills output_bytes from password_bytes and salt_bytes.

sskdf

SP 800-56C’s one-step key derivation over the digest Digest (NIST SP 800-56C revision 2, section 4.1, with H a hash function): fills output_bytes from the shared secret secret_bytes and fixed_info, block after block, each Digest(counter || secret_bytes || fixed_info) with a 32-bit big-endian counter from 1.

x963kdf

ANSI X9.63’s key derivation (ANSI X9.63-2011, section 5.6.3; SEC 1 v2, section 3.6.1) over the digest Digest: fills output_bytes from the shared secret secret_bytes and shared_info, block after block, each Digest(secret_bytes || counter || shared_info) with a 32-bit big-endian counter from 1.

Variables

Name Description

argon2id_interactive

libsodium’s interactive costs: 2 passes over 64 MiB.

argon2id_moderate

libsodium’s moderate costs: 3 passes over 256 MiB.

argon2id_salt_size

The salt’s size, 16 bytes.

argon2id_sensitive

libsodium’s sensitive costs: 4 passes over 1 GiB.

backend_has_v

Whether Backend has the key derivation Kdf over Hmac, or the algorithm of a family’s tag: a property of the library behind it (spec sections 3.2 and 3.5), whether or not the program links it, backends::botan excepted.

backend_has_v

backends::bearssl has digests::md5 (br_md5_*).

backend_has_v

backends::bearssl has digests::md5_sha1 (br_md5sha1_*, TLS 1.0’s MD5 followed by SHA-1).

backend_has_v

backends::bearssl has digests::sha1 (br_sha1_*).

backend_has_v

backends::bearssl has digests::sha2_224 (br_sha224_*).

backend_has_v

backends::bearssl has digests::sha2_256 (br_sha256_*).

backend_has_v

backends::bearssl has digests::sha2_384 (br_sha384_*).

backend_has_v

backends::bearssl has digests::sha2_512 (br_sha512_*).

backend_has_v

backends::bearssl has digests::shake_128 (br_shake_*, any output size).

backend_has_v

backends::bearssl has digests::shake_256 (br_shake_*, any output size).

backend_has_v

backends::bearssl has macs::hmac<digests::md5> (br_hmac_*).

backend_has_v

backends::bearssl has macs::hmac<digests::sha1> (br_hmac_*).

backend_has_v

backends::bearssl has macs::hmac<digests::sha2_224> (br_hmac_*).

backend_has_v

backends::bearssl has macs::hmac<digests::sha2_256> (br_hmac_*).

backend_has_v

backends::bearssl has macs::hmac<digests::sha2_384> (br_hmac_*).

backend_has_v

backends::bearssl has macs::hmac<digests::sha2_512> (br_hmac_*).

backend_has_v

backends::blake3 has digests::blake3 (BLAKE3’s C implementation), with its extendable output.

backend_has_v

backends::botan has Argon2d ("Argon2d"), in part: at most 128 lanes and 8 GiB (2 on wasm32).

backend_has_v

backends::botan has Argon2i ("Argon2i"), in part, as Argon2d.

backend_has_v

backends::botan has Argon2id ("Argon2id"), in part, as Argon2d.

backend_has_v

backends::botan has the function argon2id (Botan 3.14.1’s PasswordHashFamily "Argon2id").

backend_has_v

backends::botan has bcrypt (generate_bcrypt, check_bcrypt), in part: a cost up to 18.

backend_has_v

backends::botan has bcrypt_pbkdf ("Bcrypt-PBKDF").

backend_has_v

backends::botan has digests::blake2b, in part: no salt, no personalisation.

backend_has_v

backends::botan has macs::blake2b_mac.

backend_has_v

backends::botan has digests::blake2s_256.

backend_has_v

backends::botan has digests::keccak_224.

backend_has_v

backends::botan has digests::keccak_256.

backend_has_v

backends::botan has digests::keccak_384.

backend_has_v

backends::botan has digests::keccak_512.

backend_has_v

backends::botan has macs::kmac_128, in part: a key of at most 192 bytes, no KMACXOF.

backend_has_v

backends::botan has macs::kmac_256, in part: a key of at most 192 bytes, no KMACXOF.

backend_has_v

backends::botan has digests::md5 (Botan 3.14.1’s HashFunction).

backend_has_v

backends::botan has digests::ripemd_160.

backend_has_v

backends::botan has scrypt ("Scrypt"), in part: N of at most 2^22, r 256, p 1,024, 8 GiB.

backend_has_v

backends::botan has digests::sha1.

backend_has_v

backends::botan has digests::sha2_224.

backend_has_v

backends::botan has digests::sha2_256.

backend_has_v

backends::botan has digests::sha2_384.

backend_has_v

backends::botan has digests::sha2_512.

backend_has_v

backends::botan has digests::sha2_512_256.

backend_has_v

backends::botan has digests::sha3_224.

backend_has_v

backends::botan has digests::sha3_256.

backend_has_v

backends::botan has digests::sha3_384.

backend_has_v

backends::botan has digests::sha3_512.

backend_has_v

backends::botan has digests::shake_128 (Botan 3.14.1’s XOF), any output size.

backend_has_v

backends::botan has digests::shake_256 (Botan 3.14.1’s XOF), any output size.

backend_has_v

backends::botan has macs::siphash_2_4.

backend_has_v

backends::botan has digests::skein_512.

backend_has_v

backends::botan has digests::sm3.

backend_has_v

backends::botan has sskdf ("SP800-56A(<h>)"), over SP 800-56C’s digests but SHA-512/224.

backend_has_v

backends::botan has digests::streebog_256.

backend_has_v

backends::botan has digests::streebog_512.

backend_has_v

backends::botan has digests::whirlpool.

backend_has_v

backends::botan has x963kdf ("KDF2(<h>)"), in part: at most 2^32 - 2 blocks.

backend_has_v

backends::botan has macs::hmac<digests::blake2b>.

backend_has_v

backends::botan has macs::hmac<digests::blake2s_256>.

backend_has_v

backends::botan has macs::hmac<digests::keccak_224>.

backend_has_v

backends::botan has macs::hmac<digests::keccak_256>.

backend_has_v

backends::botan has macs::hmac<digests::keccak_384>.

backend_has_v

backends::botan has macs::hmac<digests::keccak_512>.

backend_has_v

backends::botan has macs::hmac<digests::md5> (Botan 3.14.1’s MessageAuthenticationCode).

backend_has_v

backends::botan has macs::hmac<digests::ripemd_160>.

backend_has_v

backends::botan has macs::hmac<digests::sha1>.

backend_has_v

backends::botan has macs::hmac<digests::sha2_224>.

backend_has_v

backends::botan has macs::hmac<digests::sha2_256>.

backend_has_v

backends::botan has macs::hmac<digests::sha2_384>.

backend_has_v

backends::botan has macs::hmac<digests::sha2_512>.

backend_has_v

backends::botan has macs::hmac<digests::sha2_512_256>.

backend_has_v

backends::botan has macs::hmac<digests::sha3_224>.

backend_has_v

backends::botan has macs::hmac<digests::sha3_256>.

backend_has_v

backends::botan has macs::hmac<digests::sha3_384>.

backend_has_v

backends::botan has macs::hmac<digests::sha3_512>.

backend_has_v

backends::botan has macs::hmac<digests::skein_512>.

backend_has_v

backends::botan has macs::hmac<digests::sm3>.

backend_has_v

backends::botan has macs::hmac<digests::streebog_256>.

backend_has_v

backends::botan has macs::hmac<digests::streebog_512>.

backend_has_v

backends::botan has macs::hmac<digests::whirlpool>.

backend_has_v

backends::hash2 has digests::blake2b in part: a 64-byte output with no options, Boost.Hash2’s blake2b_512 (ruling R82).

backend_has_v

backends::hash2 has digests::blake2s_256 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has macs::blake2s_mac in part: a 32-byte tag, Boost.Hash2’s keyed blake2s_256 (ruling R82).

backend_has_v

backends::hash2 has digests::md5 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::ripemd_160 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha1 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha2_224 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha2_256 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha2_384 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha2_512 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha2_512_224 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha2_512_256 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha3_224 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha3_256 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha3_384 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::sha3_512 (Boost.Hash2’s type).

backend_has_v

backends::hash2 has digests::shake_128 whole: Boost.Hash2’s shake_128, whose every result() gives the next block of the stream.

backend_has_v

backends::hash2 has digests::shake_256 whole: Boost.Hash2’s shake_256, whose every result() gives the next block of the stream.

backend_has_v

backends::hash2 has macs::siphash_2_4 (Boost.Hash2’s siphash_64).

backend_has_v

backends::hash2 has macs::hmac<digests::blake2b> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::blake2s_256> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::md5> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::ripemd_160> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha1> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha2_224> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha2_256> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha2_384> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha2_512> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha2_512_224> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha2_512_256> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha3_224> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha3_256> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha3_384> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::hash2 has macs::hmac<digests::sha3_512> (Boost.Hash2’s hmac<H>).

backend_has_v

backends::openssl has Argon2d with every parameter (OpenSSL 3.5.9’s EVP_KDF "ARGON2D").

backend_has_v

backends::openssl has Argon2i with every parameter (OpenSSL 3.5.9’s EVP_KDF "ARGON2I").

backend_has_v

backends::openssl has Argon2id with every parameter (OpenSSL 3.5.9’s EVP_KDF "ARGON2ID").

backend_has_v

backends::openssl has the function argon2id (OpenSSL 3.5.9’s EVP_KDF "ARGON2ID").

backend_has_v

backends::openssl has digests::blake2b in part: unkeyed, every output size from 1 to 64 bytes (OpenSSL’s "BLAKE2B-512" with its "size"); no key, salt or personalisation.

backend_has_v

backends::openssl has macs::blake2b_mac (OpenSSL 3.5.9’s EVP_MAC "BLAKE2BMAC").

backend_has_v

backends::openssl has digests::blake2s_256 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has macs::blake2s_mac (OpenSSL 3.5.9’s EVP_MAC "BLAKE2SMAC").

backend_has_v

backends::openssl has digests::keccak_224 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::keccak_256 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::keccak_384 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::keccak_512 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has macs::kmac_128 (OpenSSL 3.5.9’s EVP_MAC "KMAC-128").

backend_has_v

backends::openssl has macs::kmac_256 (OpenSSL 3.5.9’s EVP_MAC "KMAC-256").

backend_has_v

backends::openssl has digests::md5 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::md5_sha1 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::ripemd_160 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has scrypt (OpenSSL 3.5.9’s EVP_KDF "SCRYPT").

backend_has_v

backends::openssl has digests::sha1 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha2_224 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha2_256 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha2_384 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha2_512 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha2_512_224 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha2_512_256 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha3_224 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha3_256 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha3_384 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::sha3_512 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has digests::shake_128 (OpenSSL 3.5.9’s EVP_MD, EVP_DigestFinalXOF), with any output size.

backend_has_v

backends::openssl has digests::shake_256 (OpenSSL 3.5.9’s EVP_MD, EVP_DigestFinalXOF), with any output size.

backend_has_v

backends::openssl has macs::siphash_2_4 (OpenSSL 3.5.9’s EVP_MAC "SIPHASH").

backend_has_v

backends::openssl has macs::siphash_2_4x (OpenSSL 3.5.9’s EVP_MAC "SIPHASH").

backend_has_v

backends::openssl has digests::sm3 (OpenSSL 3.5.9’s EVP_MD).

backend_has_v

backends::openssl has SP 800-56C’s one-step KDF over a digest (OpenSSL 3.5.9’s EVP_KDF "SSKDF"), the function sskdf, which takes a digest, not an hmac.

backend_has_v

backends::openssl has ANSI X9.63’s KDF (OpenSSL 3.5.9’s EVP_KDF "X963KDF"), the function x963kdf, which takes a digest, not an hmac.

backend_has_v

backends::openssl has macs::hmac<digests::blake2b> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::blake2s_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::keccak_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::keccak_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::keccak_384> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::keccak_512> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::md5> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::ripemd_160> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha1> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha2_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha2_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha2_384> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha2_512> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha2_512_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha2_512_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha3_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha3_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha3_384> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sha3_512> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::openssl has macs::hmac<digests::sm3> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

backend_has_v

backends::sodium has Argon2i for argon2 (crypto_pwhash_argon2i), in part: one lane, no secret, no associated data, a 16-byte salt, a tag of 16 bytes or more and at least 3 passes.

backend_has_v

backends::sodium has Argon2id for argon2 (crypto_pwhash_argon2id), in part: one lane, no secret, no associated data, a 16-byte salt and a tag of 16 bytes or more.

backend_has_v

backends::sodium has Argon2id (crypto_pwhash_argon2id), which takes no hmac.

backend_has_v

backends::sodium has digests::blake2b (crypto_generichash_blake2b_*), with its key, salt, personalisation and every output size.

backend_has_v

backends::sodium has macs::blake2b_mac (keyed crypto_generichash_blake2b_*).

backend_has_v

backends::sodium has BLAKE2b subkeys (crypto_kdf_blake2b_derive_from_key), the function blake2b_subkey, which takes no hmac.

backend_has_v

backends::sodium has HKDF over HMAC-SHA-256 (crypto_kdf_hkdf_sha256_*).

backend_has_v

backends::sodium has HKDF over HMAC-SHA-512 (crypto_kdf_hkdf_sha512_*).

backend_has_v

backends::sodium has scrypt (crypto_pwhash_scryptsalsa208sha256_ll), which takes no hmac.

backend_has_v

backends::sodium has digests::sha2_256 (crypto_hash_sha256_*).

backend_has_v

backends::sodium has digests::sha2_512 (crypto_hash_sha512_*).

backend_has_v

backends::sodium has digests::sha3_256 (crypto_hash_sha3256_*).

backend_has_v

backends::sodium has digests::sha3_512 (crypto_hash_sha3512_*).

backend_has_v

backends::sodium has digests::shake_128 (crypto_xof_shake128_*), with its extendable output.

backend_has_v

backends::sodium has digests::shake_256 (crypto_xof_shake256_*), with its extendable output.

backend_has_v

backends::sodium has macs::siphash_2_4 (crypto_shorthash_siphash24).

backend_has_v

backends::sodium has macs::siphash_2_4x (crypto_shorthash_siphashx24).

backend_has_v

backends::sodium has digests::turboshake_128 (crypto_xof_turboshake128_*), with its domain byte.

backend_has_v

backends::sodium has digests::turboshake_256 (crypto_xof_turboshake256_*), with its domain byte.

backend_has_v

backends::sodium has macs::hmac<digests::sha2_256> (crypto_auth_hmacsha256_*), with a key of any size.

backend_has_v

backends::sodium has macs::hmac<digests::sha2_512> (crypto_auth_hmacsha512_*), with a key of any size.

backend_has_v

backends::xkcp has digests::cshake_128 (XKCP’s SP 800-185 cSHAKE128, any output size).

backend_has_v

backends::xkcp has digests::cshake_256 (XKCP’s SP 800-185 cSHAKE256, any output size).

backend_has_v

backends::xkcp has digests::keccak_224 (XKCP’s FIPS 202’s Keccak_Hash with Keccak’s padding).

backend_has_v

backends::xkcp has digests::keccak_256 (webcpp’s keccak_256 over XKCP).

backend_has_v

backends::xkcp has digests::keccak_384 (XKCP’s FIPS 202’s Keccak_Hash with Keccak’s padding).

backend_has_v

backends::xkcp has digests::keccak_512 (XKCP’s FIPS 202’s Keccak_Hash with Keccak’s padding).

backend_has_v

backends::xkcp has macs::kmac_128 (XKCP’s SP 800-185 KMAC128, both forms).

backend_has_v

backends::xkcp has macs::kmac_256 (XKCP’s SP 800-185 KMAC256, both forms).

backend_has_v

backends::xkcp has digests::kt128 (XKCP’s KangarooTwelve at 128 bits, any output size).

backend_has_v

backends::xkcp has digests::kt256 (XKCP’s KangarooTwelve at 256 bits, any output size).

backend_has_v

backends::xkcp has digests::parallelhash_128 (XKCP’s SP 800-185 ParallelHash128, both forms; a block size that is a power of two of at least 8 bytes).

backend_has_v

backends::xkcp has digests::parallelhash_256 (XKCP’s SP 800-185 ParallelHash256, both forms; a block size that is a power of two of at least 8 bytes).

backend_has_v

backends::xkcp has digests::sha3_224 (XKCP’s FIPS 202’s Keccak_Hash).

backend_has_v

backends::xkcp has digests::sha3_256 (XKCP’s FIPS 202’s Keccak_Hash).

backend_has_v

backends::xkcp has digests::sha3_384 (XKCP’s FIPS 202’s Keccak_Hash).

backend_has_v

backends::xkcp has digests::sha3_512 (XKCP’s FIPS 202’s Keccak_Hash).

backend_has_v

backends::xkcp has digests::shake_128 (XKCP’s FIPS 202’s Keccak_Hash, any output size).

backend_has_v

backends::xkcp has digests::shake_256 (XKCP’s FIPS 202’s Keccak_Hash, any output size).

backend_has_v

backends::xkcp has digests::tuplehash_128 (XKCP’s SP 800-185 TupleHash128, both forms).

backend_has_v

backends::xkcp has digests::tuplehash_256 (XKCP’s SP 800-185 TupleHash256, both forms).

backend_has_v

backends::xkcp has digests::turboshake_128 (XKCP’s TurboSHAKE, any output size and D).

backend_has_v

backends::xkcp has digests::turboshake_256 (XKCP’s TurboSHAKE, any output size and D).

backend_has_v

backends::bearssl has hkdf (not its two steps alone) over MD5, SHA-1 and four SHA-2s.

backend_has_v

backends::bearssl has HKDF-Expand over pieces wherever it has HKDF over pieces: its HMAC keyed by the pseudorandom key, while the single-buffer hkdf_expand stays refused.

backend_has_v

backends::bearssl has HKDF-Extract over pieces wherever it has HKDF over pieces: its HMAC keyed by the salt, while the single-buffer hkdf_extract stays refused (br_hkdf_* keeps the pseudorandom key inside its context).

backend_has_v

backends::bearssl has HKDF over pieces over its six hmacs, those of its HMAC cells, over br_hmac_key_init, br_hmac_init, br_hmac_update and br_hmac_out.

backend_has_v

backends::botan has HKDF ("HKDF(HMAC(<h>))") over the hmacs of detail::botan_hmac_v.

backend_has_v

backends::botan has HKDF-Expand over pieces wherever it has HKDF over pieces.

backend_has_v

backends::botan has HKDF-Extract over pieces wherever it has HKDF over pieces.

backend_has_v

backends::botan has HKDF over pieces over the hmacs of detail::botan_hmac_v, those of its HMAC cells it has HKDF over, on its MessageAuthenticationCode "HMAC(<h>)" (its KDF "HKDF" takes the input keying material and the info whole, and is not used).

backend_has_v

backends::botan has KBKDF ("SP800-108-Counter(HMAC(<h>),<r>,32)") over the hmacs of detail::botan_hmac_v, in part: with the separator and L.

backend_has_v

backends::botan has PBKDF2 ("PBKDF2(HMAC(<h>))") over the hmacs of detail::botan_hmac_v, in part: at most 2^32 - 2 blocks of output, and on wasm32 at most 2^32 - 1 iterations.

backend_has_v

backends::hash2 has HKDF over every Boost.Hash2 hmac whose result is a digest.

backend_has_v

backends::hash2 has HKDF-Expand over pieces wherever it has HKDF over pieces.

backend_has_v

backends::hash2 has HKDF-Extract over pieces wherever it has HKDF over pieces.

backend_has_v

backends::hash2 has HKDF over pieces over every hmac it has HKDF over: Boost.Hash2’s hmac<H>, whose update each piece is fed to (design D4 of the change hkdf-pieces: a backend has the pieces forms exactly where it has the HMAC).

backend_has_v

backends::hash2 has PBKDF2 over every Boost.Hash2 hmac whose result is a digest.

backend_has_v

backends::openssl has HKDF over every alias of hmac.hpp but hmac_ripemd_128.

backend_has_v

backends::openssl has HKDF-Expand over pieces wherever it has HKDF over pieces.

backend_has_v

backends::openssl has HKDF-Extract over pieces wherever it has HKDF over pieces.

backend_has_v

backends::openssl has HKDF over pieces over the hmacs of its HMAC cells, those it has HKDF over (every alias of hmac.hpp but hmac_ripemd_128), over EVP_MAC "HMAC" (OpenSSL’s EVP_KDF "HKDF" takes the input keying material and the info whole, and is not used).

backend_has_v

backends::openssl has SP 800-108’s KBKDF in counter mode (OpenSSL 3.5.9’s EVP_KDF "KBKDF") over every alias of hmac.hpp but hmac_ripemd_128.

backend_has_v

backends::openssl has PBKDF2 over every alias of hmac.hpp but hmac_ripemd_128.

backend_has_v

backends::sodium has HKDF-Expand over pieces wherever it has HKDF over pieces.

backend_has_v

backends::sodium has HKDF-Extract over pieces wherever it has HKDF over pieces.

backend_has_v

backends::sodium has HKDF over pieces over the hmacs of its HMAC cells, those it has HKDF over: hmac_sha2_256 and hmac_sha2_512, over crypto_auth_hmacsha256_* and crypto_auth_hmacsha512_* (libsodium’s own HKDF takes Expand’s info whole, and is not used).

backend_has_v

HKDF-Expand alone: as HKDF-Extract, every backend with HKDF but backends::bearssl.

backend_has_v

HKDF-Extract alone: every backend that has HKDF over Hmac but backends::bearssl, whose br_hkdf_* keeps the pseudorandom key inside its context (spec 3.2).

bcrypt_hash_size

bcrypt’s string, 60 characters: "\$2b\$", the cost in two digits, "$", 22 of salt, 31 of hash.

bcrypt_max_password_size

The longest password bcrypt reads, 72 bytes.

bcrypt_salt_size

bcrypt’s salt, 16 bytes (128 bits).

blake2b_subkey_context_size

The size of blake2b_subkey’s context, in bytes (libsodium’s crypto_kdf_CONTEXTBYTES).

blake2b_subkey_key_size

The size of blake2b_subkey’s master key, in bytes (libsodium’s crypto_kdf_KEYBYTES).

blake2b_subkey_max_size

The longest subkey blake2b_subkey derives, in bytes (libsodium’s crypto_kdf_BYTES_MAX).

blake2b_subkey_min_size

The shortest subkey blake2b_subkey derives, in bytes (libsodium’s crypto_kdf_BYTES_MIN).

hkdf_max_application_info_size

The longest application info every backend accepts, 32,768 bytes (OpenSSL 3.5’s limit).

Using Declarations

Name Description

blake2b_512

BLAKE2b with a 512-bit digest, RFC 7693.

blake2s_256

BLAKE2s with a 256-bit digest, RFC 7693.

fnv1a_32

FNV-1a with a 32-bit result, the Fowler-Noll-Vo hash (IETF draft-eastlake-fnv).

fnv1a_64

FNV-1a with a 64-bit result, the Fowler-Noll-Vo hash (IETF draft-eastlake-fnv).

get_integral_result

Boost.Hash2’s get_integral_result: converts a result to an integer type.

hash_append

Boost.Hash2’s hash_append: feeds a value to a hash algorithm.

hash_append_range

Boost.Hash2’s hash_append_range: feeds a range to a hash algorithm.

hash_append_range_and_size

Boost.Hash2’s hash_append_range_and_size: feeds a range and then its size.

hash_append_size

Boost.Hash2’s hash_append_size: feeds a size.

hash_append_unordered_range

Boost.Hash2’s hash_append_unordered_range: feeds an unordered range, order-independently.

hmac_blake2b_512

HMAC, RFC 2104, over BLAKE2b.

hmac_blake2s_256

HMAC, RFC 2104, over BLAKE2s.

hmac_md5_128

HMAC, RFC 2104, over MD5 (legacy, not for new designs).

hmac_ripemd_128

HMAC, RFC 2104, over RIPEMD-128.

hmac_ripemd_160

HMAC, RFC 2104, over RIPEMD-160.

hmac_sha1_160

HMAC, RFC 2104, over SHA-1 (legacy, not for new designs).

hmac_sha2_224

HMAC, RFC 2104, over SHA-224.

hmac_sha2_256

HMAC, RFC 2104, over SHA-256.

hmac_sha2_384

HMAC, RFC 2104, over SHA-384.

hmac_sha2_512

HMAC, RFC 2104, over SHA-512.

hmac_sha2_512_224

HMAC, RFC 2104, over SHA-512/224.

hmac_sha2_512_256

HMAC, RFC 2104, over SHA-512/256.

hmac_sha3_224

HMAC, RFC 2104, over SHA3-224.

hmac_sha3_256

HMAC, RFC 2104, over SHA3-256.

hmac_sha3_384

HMAC, RFC 2104, over SHA3-384.

hmac_sha3_512

HMAC, RFC 2104, over SHA3-512.

md5_128

MD5, RFC 1321, a 128-bit digest.

murmur3_128

MurmurHash3 x64_128, Austin Appleby’s hash.

murmur3_32

MurmurHash3 x86_32, Austin Appleby’s hash.

ripemd_128

RIPEMD-128, ISO/IEC 10118-3, a 128-bit digest.

ripemd_160

RIPEMD-160, ISO/IEC 10118-3, a 160-bit digest.

sha1_160

SHA-1, FIPS 180-4, a 160-bit digest.

sha2_224

SHA-224, FIPS 180-4, a 224-bit digest.

sha2_256

SHA-256, FIPS 180-4, a 256-bit digest.

sha2_384

SHA-384, FIPS 180-4, a 384-bit digest.

sha2_512

SHA-512, FIPS 180-4, a 512-bit digest.

sha2_512_224

SHA-512/224, FIPS 180-4, a 224-bit digest.

sha2_512_256

SHA-512/256, FIPS 180-4, a 256-bit digest.

sha3_224

SHA3-224, FIPS 202, a 224-bit digest.

sha3_256

SHA3-256, FIPS 202, a 256-bit digest.

sha3_384

SHA3-384, FIPS 202, a 384-bit digest.

sha3_512

SHA3-512, FIPS 202, a 512-bit digest.

shake_128

SHAKE128, FIPS 202, an extendable-output function with a 128-bit security strength.

shake_256

SHAKE256, FIPS 202, an extendable-output function with a 256-bit security strength.

siphash_32

HalfSipHash-2-4, Aumasson’s 32-bit variant of SipHash with an 8-byte key and a 32-bit result, as Boost.Hash2 defines it (not SipHash-2-4 truncated).

siphash_64

SipHash-2-4 with a 64-bit result, Aumasson and Bernstein’s keyed hash.

spooky2_128

SpookyHash V2 with a 128-bit result, Bob Jenkins’ hash.

xxh3_128

XXH3 with a 128-bit result, Yann Collet’s hash.

xxhash_32

xxHash32, Yann Collet’s 32-bit hash.

xxhash_64

XXH64, Yann Collet’s 64-bit hash.

webcpp::hash::backends

Types

Name Description

bearssl

BearSSL, built from its sources by /third_party//bearssl.

blake3

BLAKE3’s official C implementation, built from its sources by /third_party//blake3: the backend of digests::blake3.

botan

Botan 3.14.1, built from its pinned sources by /third_party//botan, natively and on Emscripten, with exceptions only.

hash2

Boost.Hash2, on every target: webcpp’s own HKDF and PBKDF2 over its hmac<H>, and the families’ engines (digest_of, hasher, mac) over its algorithms.

openssl

OpenSSL 3.5, built from its pinned sources, named by /webcpp/hash//openssl.

sodium

libsodium, built from its sources by /third_party//sodium.

webcrypto

WebCrypto, the browser’s SubtleCrypto (Emscripten only), a backend of the asynchronous family.

xkcp

XKCP, the Keccak team’s code, built from its sources by /third_party//xkcp: the backend of digests::keccak_256 and of the other Keccak functions: SHA-3, SHAKE, SP 800-185, KangarooTwelve and TurboSHAKE.

webcpp::hash::backends::bearssl

BearSSL, built from its sources by /third_party//bearssl.

Synopsis

struct bearssl;

webcpp::hash::backends::blake3

BLAKE3’s official C implementation, built from its sources by /third_party//blake3: the backend of digests::blake3.

Synopsis

struct blake3;

webcpp::hash::backends::botan

Botan 3.14.1, built from its pinned sources by /third_party//botan, natively and on Emscripten, with exceptions only.

Synopsis

struct botan;

webcpp::hash::backends::hash2

Boost.Hash2, on every target: webcpp’s own HKDF and PBKDF2 over its hmac<H>, and the families’ engines (digest_of, hasher, mac) over its algorithms.

Synopsis

struct hash2;

webcpp::hash::backends::openssl

OpenSSL 3.5, built from its pinned sources, named by /webcpp/hash//openssl.

Synopsis

struct openssl;

webcpp::hash::backends::sodium

libsodium, built from its sources by /third_party//sodium.

Synopsis

struct sodium;

webcpp::hash::backends::webcrypto

WebCrypto, the browser’s SubtleCrypto (Emscripten only), a backend of the asynchronous family.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct webcrypto;

Description

Only the functions of <webcpp/hash/async.hpp> take it, named in the type, never as a default. A synchronous function that names it refuses at compile time, on every target; an asynchronous one refuses off Emscripten.

webcpp::hash::backends::xkcp

XKCP, the Keccak team’s code, built from its sources by /third_party//xkcp: the backend of digests::keccak_256 and of the other Keccak functions: SHA-3, SHAKE, SP 800-185, KangarooTwelve and TurboSHAKE.

Synopsis

struct xkcp;

webcpp::hash::checksums

Types

Name Description

double_sha256

The checksum of Base58Check: the first 4 bytes of SHA-256 of SHA-256 of the payload.

webcpp::hash::checksums::double_sha256

The checksum of Base58Check: the first 4 bytes of SHA-256 of SHA-256 of the payload.

Synopsis

struct double_sha256;

Description

It runs on secrets (a WIF key’s payload is one), so it is constant time: Boost.Hash2’s SHA-256 is a fixed sequence of 32-bit operations with no branch on the data and no table indexed by it, with no backend and no failure, on every target. compute holds secure::timing_guard and wipes both digests and both hashers’ states.

Static Member Functions

Name Description

compute

Writes the first 4 bytes of SHA-256 of SHA-256 of payload_bytes to checksum_bytes.

Static Data Members

Name Description

size

The checksum’s bytes.

webcpp::hash::checksums::double_sha256::compute

Writes the first 4 bytes of SHA-256 of SHA-256 of payload_bytes to checksum_bytes.

Synopsis

static
void
compute(
    std::span<uint8_t const> payload_bytes,
    std::span<uint8_t, size> checksum_bytes) noexcept;

Parameters

Name Description

payload_bytes

The payload, which may be secret.

checksum_bytes

The checksum.

webcpp::hash::checksums::double_sha256::size

The checksum’s bytes.

Synopsis

inline constexpr static
std::size_t size = 4;

webcpp::hash::digests

Types

Name Description

blake2b

BLAKE2b, RFC 7693, with its key, salt, personalisation and output size (1 to 64 bytes).

blake2s_256

BLAKE2s with a 32-byte digest, RFC 7693.

blake3

BLAKE3, an extendable-output function: any output size from 1 byte (32 is its digest).

cshake_128

cSHAKE128, NIST SP 800-185, SHAKE128 with a function name and a customisation: any output size from 1 byte.

cshake_256

cSHAKE256, NIST SP 800-185: any output size from 1 byte.

keccak_224

Keccak-224 with the original padding (the SHA-3 submission), a 28-byte digest.

keccak_256

Keccak-256 with the original padding, Ethereum’s hash, a 32-byte digest.

keccak_384

Keccak-384 with the original padding, a 48-byte digest.

keccak_512

Keccak-512 with the original padding, a 64-byte digest.

kt128

KT128 (KangarooTwelve), RFC 9861, with a customisation: any output size from 1 byte.

kt256

KT256, RFC 9861, with a customisation: any output size from 1 byte.

md5

MD5, RFC 1321, a 16-byte digest.

md5_sha1

MD5 then SHA-1 of the same input, 36 bytes: TLS 1.0 and 1.1’s hash.

parallelhash_128

ParallelHash128, NIST SP 800-185: any output size from 1 byte.

parallelhash_256

ParallelHash256, NIST SP 800-185: any output size from 1 byte.

ripemd_160

RIPEMD-160, ISO/IEC 10118-3, a 20-byte digest.

sha1

SHA-1, FIPS 180-4, a 20-byte digest.

sha2_224

SHA-224, FIPS 180-4, a 28-byte digest.

sha2_256

SHA-256, FIPS 180-4, a 32-byte digest.

sha2_384

SHA-384, FIPS 180-4, a 48-byte digest.

sha2_512

SHA-512, FIPS 180-4, a 64-byte digest.

sha2_512_224

SHA-512/224, FIPS 180-4, a 28-byte digest.

sha2_512_256

SHA-512/256, FIPS 180-4, a 32-byte digest.

sha3_224

SHA3-224, FIPS 202, a 28-byte digest.

sha3_256

SHA3-256, FIPS 202, a 32-byte digest.

sha3_384

SHA3-384, FIPS 202, a 48-byte digest.

sha3_512

SHA3-512, FIPS 202, a 64-byte digest.

shake_128

SHAKE128, FIPS 202, an extendable-output function: any output size from 1 byte.

shake_256

SHAKE256, FIPS 202, an extendable-output function: any output size from 1 byte.

skein_512

Skein-512 with a 64-byte digest.

sm3

SM3, GB/T 32905-2016, a 32-byte digest.

streebog_256

Streebog-256, GOST R 34.11-2012, a 32-byte digest.

streebog_512

Streebog-512, GOST R 34.11-2012, a 64-byte digest.

tuplehash_128

TupleHash128, NIST SP 800-185: any output size from 1 byte.

tuplehash_256

TupleHash256, NIST SP 800-185: any output size from 1 byte.

turboshake_128

TurboSHAKE128, RFC 9861, with a domain byte: any output size from 1 byte.

turboshake_256

TurboSHAKE256, RFC 9861, with a domain byte: any output size from 1 byte.

whirlpool

Whirlpool, ISO/IEC 10118-3, a 64-byte digest.

webcpp::hash::digests::blake2b

BLAKE2b, RFC 7693, with its key, salt, personalisation and output size (1 to 64 bytes).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct blake2b;

Description

A tag, declared and never defined.

webcpp::hash::digests::blake2s_256

BLAKE2s with a 32-byte digest, RFC 7693.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct blake2s_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::blake3

BLAKE3, an extendable-output function: any output size from 1 byte (32 is its digest).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct blake3;

Description

A tag, declared and never defined.

webcpp::hash::digests::cshake_128

cSHAKE128, NIST SP 800-185, SHAKE128 with a function name and a customisation: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct cshake_128;

Description

A tag, declared and never defined.

webcpp::hash::digests::cshake_256

cSHAKE256, NIST SP 800-185: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct cshake_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::keccak_224

Keccak-224 with the original padding (the SHA-3 submission), a 28-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct keccak_224;

Description

A tag, declared and never defined.

webcpp::hash::digests::keccak_256

Keccak-256 with the original padding, Ethereum’s hash, a 32-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct keccak_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::keccak_384

Keccak-384 with the original padding, a 48-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct keccak_384;

Description

A tag, declared and never defined.

webcpp::hash::digests::keccak_512

Keccak-512 with the original padding, a 64-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct keccak_512;

Description

A tag, declared and never defined.

webcpp::hash::digests::kt128

KT128 (KangarooTwelve), RFC 9861, with a customisation: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct kt128;

Description

A tag, declared and never defined.

webcpp::hash::digests::kt256

KT256, RFC 9861, with a customisation: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct kt256;

Description

A tag, declared and never defined.

webcpp::hash::digests::md5

MD5, RFC 1321, a 16-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct md5;

Description

Broken: for compatibility only. A tag, declared and never defined.

webcpp::hash::digests::md5_sha1

MD5 then SHA-1 of the same input, 36 bytes: TLS 1.0 and 1.1’s hash.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct md5_sha1;

Description

Broken: for compatibility only. A tag, declared and never defined.

webcpp::hash::digests::parallelhash_128

ParallelHash128, NIST SP 800-185: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct parallelhash_128;

Description

A tag, declared and never defined.

webcpp::hash::digests::parallelhash_256

ParallelHash256, NIST SP 800-185: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct parallelhash_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::ripemd_160

RIPEMD-160, ISO/IEC 10118-3, a 20-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct ripemd_160;

Description

Legacy. A tag, declared and never defined.

webcpp::hash::digests::sha1

SHA-1, FIPS 180-4, a 20-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha1;

Description

Broken: for compatibility only. A tag, declared and never defined.

webcpp::hash::digests::sha2_224

SHA-224, FIPS 180-4, a 28-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha2_224;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha2_256

SHA-256, FIPS 180-4, a 32-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha2_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha2_384

SHA-384, FIPS 180-4, a 48-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha2_384;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha2_512

SHA-512, FIPS 180-4, a 64-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha2_512;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha2_512_224

SHA-512/224, FIPS 180-4, a 28-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha2_512_224;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha2_512_256

SHA-512/256, FIPS 180-4, a 32-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha2_512_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha3_224

SHA3-224, FIPS 202, a 28-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha3_224;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha3_256

SHA3-256, FIPS 202, a 32-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha3_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha3_384

SHA3-384, FIPS 202, a 48-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha3_384;

Description

A tag, declared and never defined.

webcpp::hash::digests::sha3_512

SHA3-512, FIPS 202, a 64-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sha3_512;

Description

A tag, declared and never defined.

webcpp::hash::digests::shake_128

SHAKE128, FIPS 202, an extendable-output function: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct shake_128;

Description

A tag, declared and never defined.

webcpp::hash::digests::shake_256

SHAKE256, FIPS 202, an extendable-output function: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct shake_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::skein_512

Skein-512 with a 64-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct skein_512;

Description

A tag, declared and never defined.

webcpp::hash::digests::sm3

SM3, GB/T 32905-2016, a 32-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sm3;

Description

A tag, declared and never defined.

webcpp::hash::digests::streebog_256

Streebog-256, GOST R 34.11-2012, a 32-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct streebog_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::streebog_512

Streebog-512, GOST R 34.11-2012, a 64-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct streebog_512;

Description

A tag, declared and never defined.

webcpp::hash::digests::tuplehash_128

TupleHash128, NIST SP 800-185: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct tuplehash_128;

Description

A tag, declared and never defined.

webcpp::hash::digests::tuplehash_256

TupleHash256, NIST SP 800-185: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct tuplehash_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::turboshake_128

TurboSHAKE128, RFC 9861, with a domain byte: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct turboshake_128;

Description

A tag, declared and never defined.

webcpp::hash::digests::turboshake_256

TurboSHAKE256, RFC 9861, with a domain byte: any output size from 1 byte.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct turboshake_256;

Description

A tag, declared and never defined.

webcpp::hash::digests::whirlpool

Whirlpool, ISO/IEC 10118-3, a 64-byte digest.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct whirlpool;

Description

A tag, declared and never defined.

webcpp::hash::formats

Type Aliases

Name Description

base58_with_checksum_t

The type of base58_with_checksum: codecs::formats::basic_base58 of 100 bytes, Bitcoin’s alphabet and the checksum checksums::double_sha256.

Variables

Name Description

base58_with_checksum

Base58Check: Bitcoin’s addresses, WIF keys and BIP-32 keys, a payload of up to 100 bytes.

webcpp::hash::formats::base58_with_checksum_t

The type of base58_with_checksum: codecs::formats::basic_base58 of 100 bytes, Bitcoin’s alphabet and the checksum checksums::double_sha256.

Synopsis

using base58_with_checksum_t = codecs::formats::basic_base58<100, codecs::formats::bitcoin_alphabet, checksums::double_sha256>;

webcpp::hash::formats::base58_with_checksum

Base58Check: Bitcoin’s addresses, WIF keys and BIP-32 keys, a payload of up to 100 bytes.

Synopsis

inline constexpr base58_with_checksum_t base58_with_checksum = {};

webcpp::hash::kdfs

Types

Name Description

argon2d

Argon2d, RFC 9106, for argon2: data-dependent memory access, never for passwords an attacker can time.

argon2i

Argon2i, RFC 9106, for argon2: data-independent memory access.

argon2id

Argon2id, RFC 9106, with one lane, the operation argon2id (on backends::sodium and backends::openssl).

bcrypt

bcrypt, the password hash of OpenBSD (Provos and Mazieres, 1999).

bcrypt_pbkdf

bcrypt-pbkdf, OpenBSD’s key derivation over bcrypt, as OpenSSH’s keys use it.

blake2b_subkey

BLAKE2b subkeys from a master key, as libsodium’s crypto_kdf derives them, the operation blake2b_subkey (on backends::sodium alone).

hkdf

HKDF, RFC 5869.

hkdf_expand

HKDF-Expand alone, the operation hkdf_expand (RFC 5869, section 2.3).

hkdf_expand_pieces

HKDF-Expand over pieces, the operation hkdf_expand whose application info is byte_pieces.

hkdf_extract

HKDF-Extract alone, the operation hkdf_extract (RFC 5869, section 2.2).

hkdf_extract_pieces

HKDF-Extract over pieces, the operation hkdf_extract whose input keying material is byte_pieces.

hkdf_pieces

HKDF over pieces, the operation hkdf whose input keying material and application info are byte_pieces: RFC 5869 on the backend’s streaming HMAC, with no cap on either input.

kbkdf_hmac

KBKDF over HMAC, NIST SP 800-108.

pbkdf2

PBKDF2, RFC 8018, the operation pbkdf2.

scrypt

scrypt, RFC 7914, the operation scrypt (on backends::sodium and backends::openssl).

sskdf

The single-step KDF of NIST SP 800-56C.

x963kdf

The KDF of ANSI X9.63.

webcpp::hash::kdfs::argon2d

Argon2d, RFC 9106, for argon2: data-dependent memory access, never for passwords an attacker can time.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct argon2d;

Description

A tag, declared and never defined.

webcpp::hash::kdfs::argon2i

Argon2i, RFC 9106, for argon2: data-independent memory access.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct argon2i;

Description

A tag, declared and never defined.

webcpp::hash::kdfs::argon2id

Argon2id, RFC 9106, with one lane, the operation argon2id (on backends::sodium and backends::openssl).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct argon2id;

Description

A tag, declared and never defined, for webcpp::hash::backend_has_v (over no hmac: void) and webcpp::hash::default_backend.

webcpp::hash::kdfs::bcrypt

bcrypt, the password hash of OpenBSD (Provos and Mazieres, 1999).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct bcrypt;

Description

A tag, declared and never defined.

webcpp::hash::kdfs::bcrypt_pbkdf

bcrypt-pbkdf, OpenBSD’s key derivation over bcrypt, as OpenSSH’s keys use it.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct bcrypt_pbkdf;

Description

A tag, declared and never defined.

webcpp::hash::kdfs::blake2b_subkey

BLAKE2b subkeys from a master key, as libsodium’s crypto_kdf derives them, the operation blake2b_subkey (on backends::sodium alone).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct blake2b_subkey;

Description

A tag, declared and never defined, for webcpp::hash::backend_has_v (over no hmac: void) and webcpp::hash::default_backend.

webcpp::hash::kdfs::hkdf

HKDF, RFC 5869.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct hkdf;

Description

A tag, declared and never defined: it names the algorithm to webcpp::hash::backend_has_v and webcpp::hash::default_backend; as an operation it is hkdf, both steps at once.

webcpp::hash::kdfs::hkdf_expand

HKDF-Expand alone, the operation hkdf_expand (RFC 5869, section 2.3).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct hkdf_expand;

Description

A tag, declared and never defined, as hkdf_extract is for the first step.

webcpp::hash::kdfs::hkdf_expand_pieces

HKDF-Expand over pieces, the operation hkdf_expand whose application info is byte_pieces.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct hkdf_expand_pieces;

Description

A tag, declared and never defined, as hkdf_pieces is.

webcpp::hash::kdfs::hkdf_extract

HKDF-Extract alone, the operation hkdf_extract (RFC 5869, section 2.2).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct hkdf_extract;

Description

A tag, declared and never defined: webcpp::hash::backend_has_v and webcpp::hash::default_backend answer for the step through it, so that a backend that has HKDF only whole (backends::bearssl) says it lacks the step.

webcpp::hash::kdfs::hkdf_extract_pieces

HKDF-Extract over pieces, the operation hkdf_extract whose input keying material is byte_pieces.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct hkdf_extract_pieces;

Description

A tag, declared and never defined, as hkdf_pieces is.

webcpp::hash::kdfs::hkdf_pieces

HKDF over pieces, the operation hkdf whose input keying material and application info are byte_pieces: RFC 5869 on the backend’s streaming HMAC, with no cap on either input.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct hkdf_pieces;

Description

A tag, declared and never defined: a backend has it exactly where it has the HMAC (design D4 of the change hkdf-pieces), which webcpp::hash::backend_has_v answers through it.

webcpp::hash::kdfs::kbkdf_hmac

KBKDF over HMAC, NIST SP 800-108.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct kbkdf_hmac;

Description

A tag, declared and never defined.

webcpp::hash::kdfs::pbkdf2

PBKDF2, RFC 8018, the operation pbkdf2.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct pbkdf2;

Description

A tag, declared and never defined, for webcpp::hash::backend_has_v and webcpp::hash::default_backend.

webcpp::hash::kdfs::scrypt

scrypt, RFC 7914, the operation scrypt (on backends::sodium and backends::openssl).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct scrypt;

Description

A tag, declared and never defined, for webcpp::hash::backend_has_v (over no hmac: void) and webcpp::hash::default_backend.

webcpp::hash::kdfs::sskdf

The single-step KDF of NIST SP 800-56C.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct sskdf;

Description

A tag, declared and never defined.

webcpp::hash::kdfs::x963kdf

The KDF of ANSI X9.63.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct x963kdf;

Description

A tag, declared and never defined.

webcpp::hash::macs

Types

Name Description

blake2b_mac

BLAKE2b keyed, RFC 7693: a key of 1 to 64 bytes, a tag of 1 to 64 bytes.

blake2s_mac

BLAKE2s keyed, RFC 7693: a key of 1 to 32 bytes, a tag of 1 to 32 bytes.

hmac

HMAC, RFC 2104, over the digest Digest: a tag, declared and never defined.

kmac_128

KMAC128, NIST SP 800-185, with its customisation: a tag of 4 bytes or more (SP 800-185, section 8.4.2).

kmac_256

KMAC256, NIST SP 800-185, with its customisation: a tag of 4 bytes or more (SP 800-185, section 8.4.2).

siphash_2_4

SipHash-2-4, a 16-byte key and an 8-byte tag: for hash tables against flooding.

siphash_2_4x

SipHash-2-4 with a 16-byte tag (libsodium’s siphashx24), a 16-byte key.

webcpp::hash::macs::blake2b_mac

BLAKE2b keyed, RFC 7693: a key of 1 to 64 bytes, a tag of 1 to 64 bytes.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct blake2b_mac;

Description

A tag, declared and never defined.

webcpp::hash::macs::blake2s_mac

BLAKE2s keyed, RFC 7693: a key of 1 to 32 bytes, a tag of 1 to 32 bytes.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct blake2s_mac;

Description

A tag, declared and never defined.

webcpp::hash::macs::hmac

HMAC, RFC 2104, over the digest Digest: a tag, declared and never defined.

Synopsis

Declared in <webcpp/hash/config.hpp>

template<class Digest>
struct hmac;

Template Parameters

Name Description

Digest

A tag of digests whose output has a fixed size, as digests::sha2_256.

webcpp::hash::macs::kmac_128

KMAC128, NIST SP 800-185, with its customisation: a tag of 4 bytes or more (SP 800-185, section 8.4.2).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct kmac_128;

Description

A tag, declared and never defined.

webcpp::hash::macs::kmac_256

KMAC256, NIST SP 800-185, with its customisation: a tag of 4 bytes or more (SP 800-185, section 8.4.2).

Synopsis

Declared in <webcpp/hash/config.hpp>

struct kmac_256;

Description

A tag, declared and never defined.

webcpp::hash::macs::siphash_2_4

SipHash-2-4, a 16-byte key and an 8-byte tag: for hash tables against flooding.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct siphash_2_4;

Description

A tag, declared and never defined.

webcpp::hash::macs::siphash_2_4x

SipHash-2-4 with a 16-byte tag (libsodium’s siphashx24), a 16-byte key.

Synopsis

Declared in <webcpp/hash/config.hpp>

struct siphash_2_4x;

Description

A tag, declared and never defined.

webcpp::hash::default_async_backend

The backend of the asynchronous family when a call names none.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Algorithm,
    class Hmac = void>
using default_async_backend = default_backend<Algorithm, Hmac>;

Description

It is the synchronous function’s, default_backend, on every target (ruling R76, the owner’s decision O2). backends::webcrypto is never a default: a program on Emscripten names it in the type to reach the browser’s WebCrypto.

Template Parameters

Name Description

Algorithm

A tag of digests, macs or kdfs.

Hmac

The hmac of a key derivation that takes one, else void; it does not change the answer.

webcpp::hash::default_backend

The backend a function of Algorithm uses when the call names none (spec 4.1).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<
    class Algorithm,
    class Hmac = void>
using default_backend = /* implementation-defined */::type;

Description

backends::hash2 for hkdf_extract, hkdf_expand, hkdf (each also over pieces) and pbkdf2, on every target and whatever the program links; backends::sodium for argon2id, scrypt (which backends::openssl and backends::botan also have, named in the call) and blake2b_subkey, which stops the build with the line to add to the Jamfile when the program does not link libsodium. A tag of the families defaults to the first of backends::hash2, backends::xkcp, backends::blake3 and backends::sodium that has it (design D34), or to detail::no_default, which refuses: the call names its backend. backends::bearssl, backends::openssl and backends::botan are never a default. No define changes it: another backend is chosen by naming it in the call, as hkdf<hmac_sha2_256, backends::openssl>.

Template Parameters

Name Description

Algorithm

A tag of kdfs (hkdf, hkdf_extract, hkdf_expand, their _pieces forms, pbkdf2, argon2id, scrypt, blake2b_subkey, ...), digests or macs.

Hmac

The hmac of a key derivation that takes one, else void; it does not change the answer.

webcpp::hash::default_kdf_backend

The backend hkdf_extract, hkdf_expand, hkdf and pbkdf2 use when the program names none: default_backend of Kdf, backends::hash2 on every target.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<
    class Hmac,
    class Kdf = kdfs::hkdf>
using default_kdf_backend = default_backend<Kdf, Hmac>;

Template Parameters

Name Description

Hmac

A Boost.Hash2 hmac; it does not change the answer.

Kdf

kdfs::hkdf (the default), kdfs::hkdf_extract, kdfs::hkdf_expand, kdfs::hkdf_pieces, kdfs::hkdf_extract_pieces, kdfs::hkdf_expand_pieces or kdfs::pbkdf2.

webcpp::hash::digest

A digest of N bytes, Boost.Hash2’s.

Synopsis

template<std::size_t N>
using digest = boost::hash2::digest<N>;

Template Parameters

Name Description

N

The size in bytes.

webcpp::hash::hmac

HMAC over H, RFC 2104, Boost.Hash2’s.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

template<class H>
using hmac = boost::hash2::hmac<H>;

Template Parameters

Name Description

H

A Hash2 HashAlgorithm.

webcpp::hash::argon2_parameters

Argon2’s parameters (spec 2.15), defined in argon2.hpp; declared here for the engines.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

struct argon2_parameters;

Data Members

Name Description

associated_data

The associated data, X: at most 4,294,967,295 bytes, empty for none.

lanes

The degree of parallelism, p: 1 to 16,777,215.

memory_kibibytes

The memory in kibibytes (KiB), RFC 9106’s m: at least 8 times the lanes.

passes

The number of passes over the memory, t: at least 1.

secret

The secret, K (a pepper): at most 4,294,967,295 bytes, empty for none.

webcpp::hash::argon2_parameters::associated_data

The associated data, X: at most 4,294,967,295 bytes, empty for none.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

std::span<uint8_t const> associated_data = = {};

webcpp::hash::argon2_parameters::lanes

The degree of parallelism, p: 1 to 16,777,215.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

uint32_t lanes = 1;

webcpp::hash::argon2_parameters::memory_kibibytes

The memory in kibibytes (KiB), RFC 9106’s m: at least 8 times the lanes.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

uint32_t memory_kibibytes = {};

webcpp::hash::argon2_parameters::passes

The number of passes over the memory, t: at least 1.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

uint32_t passes = {};

webcpp::hash::argon2_parameters::secret

The secret, K (a pepper): at most 4,294,967,295 bytes, empty for none.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

std::span<uint8_t const> secret = = {};

webcpp::hash::argon2id_parameters

The costs of Argon2id with one lane, as libsodium’s crypto_pwhash takes them, for argon2id.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

struct argon2id_parameters;

Description

Its memory is in bytes; argon2_parameters, the family’s, counts KiB as RFC 9106 does.

Data Members

Name Description

memory

The memory in bytes, m times 1,024: at least 8,192, a multiple of 1,024, at most 4 TiB less 1 KiB (2 GiB on wasm32).

passes

The number of passes over the memory, t: 1 to 4,294,967,295.

webcpp::hash::argon2id_parameters::memory

The memory in bytes, m times 1,024: at least 8,192, a multiple of 1,024, at most 4 TiB less 1 KiB (2 GiB on wasm32).

Synopsis

Declared in <webcpp/hash/argon2.hpp>

std::size_t memory = {};

webcpp::hash::argon2id_parameters::passes

The number of passes over the memory, t: 1 to 4,294,967,295.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

uint64_t passes = {};

webcpp::hash::bcrypt_parameters

bcrypt’s cost (2^cost rounds, 4 to 31) and the version written, 'a', 'b' or 'y'.

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

struct bcrypt_parameters;

Data Members

Name Description

cost

The cost: 2^cost rounds of the key schedule, 4 to 31 (backends::botan: at most 18).

version

The version of the string, 'a', 'b' or 'y': the three are one algorithm for a password of at most 72 bytes without a zero byte.

webcpp::hash::bcrypt_parameters::cost

The cost: 2^cost rounds of the key schedule, 4 to 31 (backends::botan: at most 18).

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

uint32_t cost = 12;

webcpp::hash::bcrypt_parameters::version

The version of the string, 'a', 'b' or 'y': the three are one algorithm for a password of at most 72 bytes without a zero byte.

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

char version = 'b';

webcpp::hash::blake3

BLAKE3, its keyed mode, its key derivation and its extendable output, over the official C implementation, in Boost.Hash2’s HashAlgorithm form.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

class blake3;

Description

The object holds the C implementation’s state, 1,912 bytes on 64-bit targets, a count of the bytes result() returned and a flag that says whether the object is keyed, 1,928 bytes in all on 64-bit targets (the flag costs one alignment), and allocates nothing. Its destructor does not wipe that state, as Hash2’s own algorithms do not.

The keyed modes compute on a secret, and every call on a keyed object sets the CPU’s data-independent timing (DIT) for the call where the CPU has it, as mac does, and leaves the thread’s state as it found it (design D1): keyed, derive_key, a non-zero integer seed and a seed of bytes, then update, result, squeeze and reset of the object they make, which keeps the flag through copies and moves. The plain mode, a zero integer seed and a seed of no bytes compute on public data and hold no guard (design D2).

Type Aliases

Name Description

result_type

The digest, 32 bytes.

Member Functions

Name Description

blake3 [constructor]

Constructors

reset

Forgets the input, keeping the mode and its key or context.

result

Returns the next 32 bytes of the output: the digest the first time after input was added, then the following 32 bytes of the extendable output at each call.

squeeze

Writes output_bytes.size() bytes of the extendable output, from byte seek_position on, without changing the hash.

update

update overloads

Static Member Functions

Name Description

derive_key

The key derivation, BLAKE3’s derive_key, under context_string.

keyed

The keyed hash, BLAKE3’s keyed_hash.

Static Data Members

Name Description

block_size

BLAKE3’s block, 64 bytes.

key_size

The key of the keyed mode, 32 bytes.

webcpp::hash::blake3::result_type

The digest, 32 bytes.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

using result_type = boost::hash2::digest<32>;

webcpp::hash::blake3::blake3

Constructors

Synopses

Declared in <webcpp/hash/blake3.hpp>

Constructs the plain hash.

blake3() noexcept;

Constructs a hash seeded by seed_value: plain when it is zero, else as from its 8 little-endian bytes.

explicit
blake3(uint64_t seed_value) noexcept;

The same, from bytes.

blake3(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Constructs a hash seeded by input_size bytes: plain when input_size is zero; else BLAKE3’s keyed hash under the first 32 bytes, zero-padded when there are fewer, with the bytes past them absorbed as the start of the input and one result() taken.

blake3(
    void const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

seed_value

The seed.

input_data

The seed.

input_size

Its size.

webcpp::hash::blake3::blake3

Constructs the plain hash.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

blake3() noexcept;

webcpp::hash::blake3::blake3

Constructs a hash seeded by seed_value: plain when it is zero, else as from its 8 little-endian bytes.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

explicit
blake3(uint64_t seed_value) noexcept;

Parameters

Name Description

seed_value

The seed.

webcpp::hash::blake3::blake3

The same, from bytes.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

blake3(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The seed.

input_size

Its size.

webcpp::hash::blake3::blake3

Constructs a hash seeded by input_size bytes: plain when input_size is zero; else BLAKE3’s keyed hash under the first 32 bytes, zero-padded when there are fewer, with the bytes past them absorbed as the start of the input and one result() taken.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

blake3(
    void const* input_data,
    std::size_t input_size) noexcept;

Description

That result() only moves the output’s position, which the next update() starts again: a seed of 32 bytes K and more bytes R, then the input M, hashes as the seed K then the input R and M; with no update() after such a seed, the first result() returns bytes 32 to 63 of the output of K over R, the next 64 to 95, and so on. Two seeds of at most 32 bytes that differ only by trailing zero bytes are the same key.

Parameters

Name Description

input_data

The seed.

input_size

Its size.

webcpp::hash::blake3::reset

Forgets the input, keeping the mode and its key or context.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

void
reset() noexcept;

webcpp::hash::blake3::result

Returns the next 32 bytes of the output: the digest the first time after input was added, then the following 32 bytes of the extendable output at each call.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

blake3::result_type
result() noexcept;

Return Value

32 bytes of output.

webcpp::hash::blake3::squeeze

Writes output_bytes.size() bytes of the extendable output, from byte seek_position on, without changing the hash.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

void
squeeze(
    std::span<uint8_t> output_bytes,
    uint64_t seek_position = 0) const noexcept;

Parameters

Name Description

output_bytes

Where to write.

seek_position

The first byte’s position in the output.

webcpp::hash::blake3::update

update overloads

Synopses

Declared in <webcpp/hash/blake3.hpp>

The same, from bytes.

void
update(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Absorbs input_size bytes.

void
update(
    void const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The bytes.

input_size

Their number.

webcpp::hash::blake3::update

The same, from bytes.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

void
update(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The bytes.

input_size

Their number.

webcpp::hash::blake3::update

Absorbs input_size bytes.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

void
update(
    void const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The bytes.

input_size

Their number.

webcpp::hash::blake3::derive_key

The key derivation, BLAKE3’s derive_key, under context_string.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

static
blake3
derive_key(std::string_view context_string) noexcept;

Return Value

The hash.

Parameters

Name Description

context_string

The context string, any bytes.

webcpp::hash::blake3::keyed

The keyed hash, BLAKE3’s keyed_hash.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

static
blake3
keyed(std::span<uint8_t const, 32> key_bytes) noexcept;

Return Value

The hash.

Parameters

Name Description

key_bytes

The key.

webcpp::hash::blake3::block_size

BLAKE3’s block, 64 bytes.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

inline constexpr static
std::size_t block_size = 64;

webcpp::hash::blake3::key_size

The key of the keyed mode, 32 bytes.

Synopsis

Declared in <webcpp/hash/blake3.hpp>

inline constexpr static
std::size_t key_size = 32;

webcpp::hash::byte_pieces

Byte sequences read one after another, as if concatenated: {a, b, c} at the call.

Synopsis

class byte_pieces;

Description

A view: it holds a pointer to a contiguous list of spans and their count, and the spans point to the caller’s bytes; neither is copied. Write the braced list at the call, where its array lives until the end of the full expression, which outlasts the call; or name a std::array (or a std::vector) of spans and pass it. A byte_pieces variable initialised from a braced list points to an array that dies at the end of its declaration: its constructors carry WEBCPP_HASH_LIFETIMEBOUND, which makes that a warning where the compiler has the attribute.

A braced list of one std::span<std::uint8_t const>, {x}, is that span (the language’s rule): a function with a single-buffer overload takes it there. {}, or a braced list of one element of another type ({vec}, {array}, a std::span<std::uint8_t>), where both overloads take braces is ambiguous: pass x itself, which converts to the span, or write byte_pieces{x} for the list of one piece, byte_pieces{} for no piece, or an empty std::span<std::uint8_t const> for an empty input (the same bytes).

std::array<std::span<std::uint8_t const>, 3> const parts{prefix, label, secret};
auto prk = webcpp::hash::hkdf_extract<webcpp::hash::hmac_sha2_256>(salt, parts);

Type Aliases

Name Description

value_type

A piece: a span of bytes.

Member Functions

Name Description

byte_pieces [constructor]

Constructors

begin

The start of the pieces.

empty

Whether the list is empty.

end

The end of the pieces.

size

The size of the list.

total_size

The length of the input the pieces make.

webcpp::hash::byte_pieces::value_type

A piece: a span of bytes.

Synopsis

using value_type = std::span<uint8_t const>;

webcpp::hash::byte_pieces::byte_pieces

Constructors

Synopses

No piece: the empty input.

constexpr
byte_pieces() noexcept = default;

The pieces of a braced list, {a, b, c}, each element converted to a span of bytes.

constexpr
byte_pieces(std::initializer_list<value_type> piece_list) noexcept;

The pieces of a contiguous range of spans of bytes: a std::array, a std::vector, a std::span of them.

template<std::ranges::contiguous_range Range>
requires std::ranges::sized_range<Range> &&
                     std::same_as<std::ranges::range_value_t<Range>, value_type> &&
                     (!std::same_as<std::remove_cvref_t<Range>, byte_pieces>)
constexpr
byte_pieces(Range const& piece_range) noexcept;

Template Parameters

Name Description

Range

A contiguous, sized range whose value type is std::span<std::uint8_t const>.

Parameters

Name Description

piece_list

The list; its array must outlive this object (it does, written at the call).

piece_range

The range; it must outlive this object.

webcpp::hash::byte_pieces::byte_pieces

No piece: the empty input.

Synopsis

constexpr
byte_pieces() noexcept = default;

webcpp::hash::byte_pieces::byte_pieces

The pieces of a braced list, {a, b, c}, each element converted to a span of bytes.

Synopsis

constexpr
byte_pieces(std::initializer_list<value_type> piece_list) noexcept;

Parameters

Name Description

piece_list

The list; its array must outlive this object (it does, written at the call).

webcpp::hash::byte_pieces::byte_pieces

The pieces of a contiguous range of spans of bytes: a std::array, a std::vector, a std::span of them.

Synopsis

template<std::ranges::contiguous_range Range>
requires std::ranges::sized_range<Range> &&
                     std::same_as<std::ranges::range_value_t<Range>, value_type> &&
                     (!std::same_as<std::remove_cvref_t<Range>, byte_pieces>)
constexpr
byte_pieces(Range const& piece_range) noexcept;

Template Parameters

Name Description

Range

A contiguous, sized range whose value type is std::span<std::uint8_t const>.

Parameters

Name Description

piece_range

The range; it must outlive this object.

webcpp::hash::byte_pieces::begin

The start of the pieces.

Synopsis

[[nodiscard]]
constexpr
value_type const*
begin() const noexcept;

Return Value

A pointer to the first piece.

Note

The return value should not be discarded.

webcpp::hash::byte_pieces::empty

Whether the list is empty.

Synopsis

[[nodiscard]]
constexpr
bool
empty() const noexcept;

Return Value

True when there is no piece.

Note

The return value should not be discarded.

webcpp::hash::byte_pieces::end

The end of the pieces.

Synopsis

[[nodiscard]]
constexpr
value_type const*
end() const noexcept;

Return Value

A pointer past the last piece.

Note

The return value should not be discarded.

webcpp::hash::byte_pieces::size

The size of the list.

Synopsis

[[nodiscard]]
constexpr
std::size_t
size() const noexcept;

Return Value

The number of pieces, empty ones included.

Note

The return value should not be discarded.

webcpp::hash::byte_pieces::total_size

The length of the input the pieces make.

Synopsis

[[nodiscard]]
constexpr
uint64_t
total_size() const noexcept;

Return Value

The bytes of all pieces, summed.

Note

The return value should not be discarded.

webcpp::hash::digest_options

The parameters of a digest (spec 2.15), defined in digest.hpp; declared here for the engines, which take them.

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<class Digest>
struct digest_options;

Specializations

Name Description

digest_options<digests::blake2b>

BLAKE2b’s parameters (RFC 7693, section 2.5): a key, a salt, a personalisation and the output’s size, each part of the parameter block that starts the hash, so that each gives another function.

digest_options<digests::cshake_128>

cSHAKE128’s parameters (NIST SP 800-185, section 3): the function name N, which NIST reserves for functions it defines on cSHAKE, and the customisation string S, which an application chooses to separate its uses of the function from any other’s. With both empty, cSHAKE128 is SHAKE128.

digest_options<digests::cshake_256>

cSHAKE256’s parameters, as cSHAKE128’s (digest_options<digests::cshake_128>).

digest_options<digests::kt128>

KT128’s parameter (RFC 9861, section 3): the customisation string C, which an application chooses to separate its uses of the function from any other’s; empty by default. KT128 is a tree over TurboSHAKE128 that hashes a long input in chunks of 8,192 bytes, which an implementation may hash in parallel; its output is any size from 1 byte, the shorter the start of the longer.

digest_options<digests::kt256>

KT256’s parameter, as KT128’s (digest_options<digests::kt128>), over TurboSHAKE256.

digest_options<digests::parallelhash_128>

ParallelHash128’s parameters (NIST SP 800-185, section 6): the block size B in bytes, the customisation string S and the form, fixed-length or extendable-output (ParallelHashXOF128). ParallelHash cuts its input in blocks of B bytes, hashes each on its own (in parallel where an implementation can) and hashes the results: B is part of the function, and the same input under another B gives another digest.

digest_options<digests::parallelhash_256>

ParallelHash256’s parameters, as ParallelHash128’s (digest_options<digests::parallelhash_128>).

digest_options<digests::tuplehash_128>

TupleHash128’s parameters (NIST SP 800-185, section 5): the customisation string S and the form, fixed-length or extendable-output (TupleHashXOF128). TupleHash hashes a tuple of byte strings so that their bounds count: ("ab", "c") and ("a", "bc") give different digests. hasher::update takes one element of the tuple per call; digest_of hashes the tuple of one element, its input.

digest_options<digests::tuplehash_256>

TupleHash256’s parameters, as TupleHash128’s (digest_options<digests::tuplehash_128>).

digest_options<digests::turboshake_128>

TurboSHAKE’s parameter (RFC 9861, section 2.1): the domain separation byte D, which the sponge absorbs after the message, so that each value gives another function. The standard value is 0x1F; a protocol that builds several functions over TurboSHAKE gives each its own byte.

digest_options<digests::turboshake_256>

TurboSHAKE256’s parameter, as TurboSHAKE128’s (RFC 9861, section 2.1).

Template Parameters

Name Description

Digest

A tag of digests.

webcpp::hash::digest_options<digests::blake2b>

BLAKE2b’s parameters (RFC 7693, section 2.5): a key, a salt, a personalisation and the output’s size, each part of the parameter block that starts the hash, so that each gives another function.

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<>
struct digest_options<digests::blake2b>;

Description

std::array<std::uint8_t, 32> id{};
auto done = webcpp::hash::digest_of<webcpp::hash::digests::blake2b>(
    id, message, {.personalisation = app_tag, .output_size = 32});

The output’s size is an option, not the output span’s alone: BLAKE2b-256 is not BLAKE2b-512 cut to 32 bytes, and a hasher must know it when it starts. digest_of and hasher::finish take an output of exactly output_size bytes (invalid_output_size otherwise).

The spans are read during the call (digest_of, hasher::make) and not kept.

Data Members

Name Description

key

The key, 0 to 64 bytes (invalid_key_size past 64); empty, BLAKE2b unkeyed.

output_size

The output’s size, 1 to 64 bytes (invalid_output_size otherwise); 64 by default.

personalisation

The personalisation, a string that separates one application’s hashes from another’s: empty, or 16 bytes (invalid_parameters otherwise); a shorter tag is padded with zeros by the caller.

salt

The salt: empty, or 16 bytes (invalid_salt_size otherwise).

webcpp::hash::digest_options<digests::blake2b>::key

The key, 0 to 64 bytes (invalid_key_size past 64); empty, BLAKE2b unkeyed.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> key = = {};

Description

A keyed BLAKE2b is a MAC (macs::blake2b_mac names it as one).

webcpp::hash::digest_options<digests::blake2b>::output_size

The output’s size, 1 to 64 bytes (invalid_output_size otherwise); 64 by default.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::size_t output_size = 64;

webcpp::hash::digest_options<digests::blake2b>::personalisation

The personalisation, a string that separates one application’s hashes from another’s: empty, or 16 bytes (invalid_parameters otherwise); a shorter tag is padded with zeros by the caller.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> personalisation = = {};

webcpp::hash::digest_options<digests::blake2b>::salt

The salt: empty, or 16 bytes (invalid_salt_size otherwise).

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> salt = = {};

webcpp::hash::digest_options<digests::cshake_128>

cSHAKE128’s parameters (NIST SP 800-185, section 3): the function name N, which NIST reserves for functions it defines on cSHAKE, and the customisation string S, which an application chooses to separate its uses of the function from any other’s. With both empty, cSHAKE128 is SHAKE128.

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<>
struct digest_options<digests::cshake_128>;

Description

std::array<std::uint8_t, 32> id{};
auto done = webcpp::hash::digest_of<webcpp::hash::digests::cshake_128>(
    id, message, {.customisation = app_name});

The output is any size from 1 byte, the first bytes of one stream: cSHAKE does not encode its length. Each string is at most SIZE_MAX / 8 bytes (input_too_long), and is read during the call (digest_of, hasher::make) and not kept.

Data Members

Name Description

customisation

The customisation string S.

function_name

The function name N: empty unless NIST defines the function.

webcpp::hash::digest_options<digests::cshake_128>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::cshake_128>::function_name

The function name N: empty unless NIST defines the function.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> function_name = = {};

webcpp::hash::digest_options<digests::cshake_256>

cSHAKE256’s parameters, as cSHAKE128’s (digest_options<digests::cshake_128>).

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<>
struct digest_options<digests::cshake_256>;

Data Members

Name Description

customisation

The customisation string S.

function_name

The function name N: empty unless NIST defines the function.

webcpp::hash::digest_options<digests::cshake_256>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::cshake_256>::function_name

The function name N: empty unless NIST defines the function.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> function_name = = {};

webcpp::hash::digest_options<digests::kt128>

KT128’s parameter (RFC 9861, section 3): the customisation string C, which an application chooses to separate its uses of the function from any other’s; empty by default. KT128 is a tree over TurboSHAKE128 that hashes a long input in chunks of 8,192 bytes, which an implementation may hash in parallel; its output is any size from 1 byte, the shorter the start of the longer.

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<>
struct digest_options<digests::kt128>;

Description

std::array<std::uint8_t, 32> digest{};
auto done = webcpp::hash::digest_of<webcpp::hash::digests::kt128>(
    digest, file_bytes, {.customisation = app_name});

KangarooTwelve absorbs C after the message, so hasher keeps the span make took and reads C at finish, not before: the caller keeps those bytes alive and unchanged until then (no copy, so no allocation). digest_of reads C during the call. On backends::xkcp where a size_t has 32 bits (wasm32), the message and C together are at most a little under 32 TiB (input_too_long, a refusal after which a hasher is spent), since XKCP counts the chunks in a size_t.

Data Members

Name Description

customisation

The customisation string C, read at finish by a hasher.

webcpp::hash::digest_options<digests::kt128>::customisation

The customisation string C, read at finish by a hasher.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::kt256>

KT256’s parameter, as KT128’s (digest_options<digests::kt128>), over TurboSHAKE256.

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<>
struct digest_options<digests::kt256>;

Data Members

Name Description

customisation

The customisation string C, read at finish by a hasher.

webcpp::hash::digest_options<digests::kt256>::customisation

The customisation string C, read at finish by a hasher.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::parallelhash_128>

ParallelHash128’s parameters (NIST SP 800-185, section 6): the block size B in bytes, the customisation string S and the form, fixed-length or extendable-output (ParallelHashXOF128). ParallelHash cuts its input in blocks of B bytes, hashes each on its own (in parallel where an implementation can) and hashes the results: B is part of the function, and the same input under another B gives another digest.

Synopsis

Declared in <webcpp/hash/digest.hpp>

Description

std::array<std::uint8_t, 32> digest{};
auto done = webcpp::hash::digest_of<webcpp::hash::digests::parallelhash_128>(
    digest, file_bytes, {.block_size = 8192});

SP 800-185 sets no default B: the call states it, and 0 is invalid_parameters. A backend may take fewer: XKCP takes a power of two of at least 8 bytes, and answers any other with unsupported_by_backend. The whole input, in one call or across a hasher’s updates, is at most SIZE_MAX / 8 bytes (input_too_long), since its length is counted in bits. The fixed-length form encodes the output’s length, as TupleHash’s does (digest_options<digests::tuplehash_128>), and is at most SIZE_MAX / 8 bytes (invalid_output_size), as is S (input_too_long), which is read during the call and not kept.

Data Members

Name Description

block_size

The block size B in bytes; no default (0 is invalid_parameters).

customisation

The customisation string S.

xof

The extendable-output form, ParallelHashXOF128, in place of the fixed-length one.

webcpp::hash::digest_options<digests::parallelhash_128>::block_size

The block size B in bytes; no default (0 is invalid_parameters).

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::size_t block_size = 0;

webcpp::hash::digest_options<digests::parallelhash_128>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::parallelhash_128>::xof

The extendable-output form, ParallelHashXOF128, in place of the fixed-length one.

Synopsis

Declared in <webcpp/hash/digest.hpp>

bool xof = false;

webcpp::hash::digest_options<digests::parallelhash_256>

ParallelHash256’s parameters, as ParallelHash128’s (digest_options<digests::parallelhash_128>).

Synopsis

Declared in <webcpp/hash/digest.hpp>

Data Members

Name Description

block_size

The block size B in bytes; no default (0 is invalid_parameters).

customisation

The customisation string S.

xof

The extendable-output form, ParallelHashXOF256, in place of the fixed-length one.

webcpp::hash::digest_options<digests::parallelhash_256>::block_size

The block size B in bytes; no default (0 is invalid_parameters).

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::size_t block_size = 0;

webcpp::hash::digest_options<digests::parallelhash_256>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::parallelhash_256>::xof

The extendable-output form, ParallelHashXOF256, in place of the fixed-length one.

Synopsis

Declared in <webcpp/hash/digest.hpp>

bool xof = false;

webcpp::hash::digest_options<digests::tuplehash_128>

TupleHash128’s parameters (NIST SP 800-185, section 5): the customisation string S and the form, fixed-length or extendable-output (TupleHashXOF128). TupleHash hashes a tuple of byte strings so that their bounds count: ("ab", "c") and ("a", "bc") give different digests. hasher::update takes one element of the tuple per call; digest_of hashes the tuple of one element, its input.

Synopsis

Declared in <webcpp/hash/digest.hpp>

Description

auto hashing = webcpp::hash::hasher<webcpp::hash::digests::tuplehash_128>::make();
// hashing->update(element) for each element, then hashing->finish(digest), once

The fixed-length form encodes the output’s length L, so that its digests of 32 and 64 bytes are unrelated; the XOF form encodes none, and its shorter output is the start of its longer. The fixed-length output is at most SIZE_MAX / 8 bytes (invalid_output_size), as is S (input_too_long), which is read during the call (digest_of, hasher::make) and not kept.

Data Members

Name Description

customisation

The customisation string S.

xof

The extendable-output form, TupleHashXOF128, in place of the fixed-length one.

webcpp::hash::digest_options<digests::tuplehash_128>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::tuplehash_128>::xof

The extendable-output form, TupleHashXOF128, in place of the fixed-length one.

Synopsis

Declared in <webcpp/hash/digest.hpp>

bool xof = false;

webcpp::hash::digest_options<digests::tuplehash_256>

TupleHash256’s parameters, as TupleHash128’s (digest_options<digests::tuplehash_128>).

Synopsis

Declared in <webcpp/hash/digest.hpp>

Data Members

Name Description

customisation

The customisation string S.

xof

The extendable-output form, TupleHashXOF256, in place of the fixed-length one.

webcpp::hash::digest_options<digests::tuplehash_256>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/digest.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::digest_options<digests::tuplehash_256>::xof

The extendable-output form, TupleHashXOF256, in place of the fixed-length one.

Synopsis

Declared in <webcpp/hash/digest.hpp>

bool xof = false;

webcpp::hash::digest_options<digests::turboshake_128>

TurboSHAKE’s parameter (RFC 9861, section 2.1): the domain separation byte D, which the sponge absorbs after the message, so that each value gives another function. The standard value is 0x1F; a protocol that builds several functions over TurboSHAKE gives each its own byte.

Synopsis

Declared in <webcpp/hash/digest.hpp>

Description

std::array<std::uint8_t, 32> output{};
auto done = webcpp::hash::digest_of<webcpp::hash::digests::turboshake_128>(
    output, message, {.domain = 0x0B});

Data Members

Name Description

domain

D, 0x01 to 0x7F (invalid_parameters otherwise); 0x1F by default.

webcpp::hash::digest_options<digests::turboshake_128>::domain

D, 0x01 to 0x7F (invalid_parameters otherwise); 0x1F by default.

Synopsis

Declared in <webcpp/hash/digest.hpp>

uint8_t domain = 0x1F;

webcpp::hash::digest_options<digests::turboshake_256>

TurboSHAKE256’s parameter, as TurboSHAKE128’s (RFC 9861, section 2.1).

Synopsis

Declared in <webcpp/hash/digest.hpp>

Data Members

Name Description

domain

D, 0x01 to 0x7F (invalid_parameters otherwise); 0x1F by default.

webcpp::hash::digest_options<digests::turboshake_256>::domain

D, 0x01 to 0x7F (invalid_parameters otherwise); 0x1F by default.

Synopsis

Declared in <webcpp/hash/digest.hpp>

uint8_t domain = 0x1F;

webcpp::hash::hasher

A hash fed in pieces, with one result: make, update as often as the data comes, then finish once (spec 2.15).

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<
    class Digest,
    class Backend = default_backend<Digest>>
class hasher;

Description

Unlike Boost.Hash2’s types, the result is final: an update or a finish after finish, or on a hasher moved from, is error::invalid_state.

A hasher made with a key (BLAKE2b’s) holds the timing guard of a MAC in make, update and finish, as digest_of with a key does; one made without a key holds none (design D1, D2).

Move-only. The state is wiped (and what the backend allocated for it freed) by finish, by the destructor, and in the hasher moved from.

auto hashing = webcpp::hash::hasher<webcpp::hash::digests::sha2_256>::make();
if (!hashing) {
    return hashing.error();
}
for (auto piece : pieces) {
    if (auto fed = hashing->update(piece); !fed) {
        return fed.error();
    }
}
std::array<std::uint8_t, 32> id{};
auto done = hashing->finish(id);

Member Functions

Name Description

hasher [constructor]

Constructors

~hasher [destructor]

Wipes the state, and frees what the backend allocated for it.

operator=

Assignment operators

finish

Writes the hash’s result into output_bytes, once.

update

Absorbs input_bytes.

Static Member Functions

Name Description

make

Starts a hash.

Template Parameters

Name Description

Digest

A tag of digests.

Backend

The backend; by default default_backend of Digest.

webcpp::hash::hasher::hasher

Constructors

Synopses

Declared in <webcpp/hash/digest.hpp>

Not copyable: a copy would be a second result of one hash, and a second state to wipe.

hasher(hasher const&) = delete;

Takes the hash of moved_from, which is wiped and then answers invalid_state.

hasher(hasher&& moved_from) noexcept;

Parameters

Name Description

moved_from

The hasher moved from.

webcpp::hash::hasher::hasher

Not copyable: a copy would be a second result of one hash, and a second state to wipe.

Synopsis

Declared in <webcpp/hash/digest.hpp>

hasher(hasher const&) = delete;

webcpp::hash::hasher::hasher

Takes the hash of moved_from, which is wiped and then answers invalid_state.

Synopsis

Declared in <webcpp/hash/digest.hpp>

hasher(hasher&& moved_from) noexcept;

Parameters

Name Description

moved_from

The hasher moved from.

webcpp::hash::hasher::~hasher

Wipes the state, and frees what the backend allocated for it.

Synopsis

Declared in <webcpp/hash/digest.hpp>

~hasher();

webcpp::hash::hasher::operator=

Assignment operators

Synopses

Declared in <webcpp/hash/digest.hpp>

Not copyable.

hasher&
operator=(hasher const&) = delete;

Ends this hash (its state wiped) and takes that of moved_from, which is wiped and then answers invalid_state.

hasher&
operator=(hasher&& moved_from) noexcept;

Return Value

  • Never.

  • This hasher.

Parameters

Name Description

moved_from

The hasher moved from.

webcpp::hash::hasher::operator=

Not copyable.

Synopsis

Declared in <webcpp/hash/digest.hpp>

hasher&
operator=(hasher const&) = delete;

Return Value

Never.

webcpp::hash::hasher::operator=

Ends this hash (its state wiped) and takes that of moved_from, which is wiped and then answers invalid_state.

Synopsis

Declared in <webcpp/hash/digest.hpp>

hasher&
operator=(hasher&& moved_from) noexcept;

Return Value

This hasher.

Parameters

Name Description

moved_from

The hasher moved from.

webcpp::hash::hasher::finish

Writes the hash’s result into output_bytes, once.

Synopsis

Declared in <webcpp/hash/digest.hpp>

[[nodiscard]]
boost::system::result<void>
finish(std::span<uint8_t> output_bytes) noexcept;

Return Value

Success, after which the hasher is spent; invalid_state after finish or once moved from; a guard’s error (invalid_output_size, unsupported_by_backend), output_bytes untouched and the hasher still hashing; or the backend’s failure, output_bytes zeroed and the hasher spent.

Note

The return value should not be discarded.

Parameters

Name Description

output_bytes

The digest: exactly the digest’s size for a fixed-size digest, any size from 1 byte for an extendable-output function.

webcpp::hash::hasher::update

Absorbs input_bytes.

Synopsis

Declared in <webcpp/hash/digest.hpp>

[[nodiscard]]
boost::system::result<void>
update(std::span<uint8_t const> input_bytes) noexcept;

Return Value

Success; invalid_state after finish or once moved from; input_too_long when the input would pass a limit of the tag’s options or of the backend (ParallelHash’s whole input, a TupleHash element, KangarooTwelve’s input on 32-bit XKCP); or the backend’s failure. After either of the last two the hasher is spent (invalid_state).

Note

The return value should not be discarded.

Parameters

Name Description

input_bytes

The next piece of the data, of any size.

webcpp::hash::hasher::make

Starts a hash.

Synopsis

Declared in <webcpp/hash/digest.hpp>

[[nodiscard]]
static
boost::system::result<hasher>
make(digest_options<Digest> const& algorithm_options = {}) noexcept;

Return Value

The hasher; or an option’s error or unsupported_by_backend; or the backend’s failure.

Note

The return value should not be discarded.

Parameters

Name Description

algorithm_options

The digest’s parameters (none for most tags).

webcpp::hash::kbkdf_options

The fixed input of SP 800-108’s KBKDF in counter mode, defined in kdf_standards.hpp; declared here for the engines.

Synopsis

struct kbkdf_options;

Data Members

Name Description

context

The Context, which names the parties or the session; empty for none.

counter_bits

r, the counter’s width in bits, written big-endian before the fixed input: 8, 16, 24 or 32.

label

The Label, which names the derived key’s purpose; empty for none.

length

Whether L, the output’s length in bits, ends the fixed input, in 4 bytes big-endian.

separator

Whether the byte 0x00 separates the label from the context.

webcpp::hash::kbkdf_options::context

The Context, which names the parties or the session; empty for none.

Synopsis

std::span<uint8_t const> context = = {};

webcpp::hash::kbkdf_options::counter_bits

r, the counter’s width in bits, written big-endian before the fixed input: 8, 16, 24 or 32.

Synopsis

uint32_t counter_bits = 32;

webcpp::hash::kbkdf_options::label

The Label, which names the derived key’s purpose; empty for none.

Synopsis

std::span<uint8_t const> label = = {};

webcpp::hash::kbkdf_options::length

Whether L, the output’s length in bits, ends the fixed input, in 4 bytes big-endian.

Synopsis

bool length = true;

webcpp::hash::kbkdf_options::separator

Whether the byte 0x00 separates the label from the context.

Synopsis

bool separator = true;

webcpp::hash::keccak_256

Keccak-256 with the original padding, Ethereum’s hash, in Boost.Hash2’s HashAlgorithm form.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

class keccak_256;

Description

The permutation is XKCP’s Keccak-p[1600]; the sponge follows Boost.Hash2’s detail::keccak_base<0x01, 512, 256> exactly, so that every sequence of calls gives its results.

Type Aliases

Name Description

result_type

The digest, 32 bytes.

Member Functions

Name Description

keccak_256 [constructor]

Constructors

result

Pads, if nothing was padded since the last update, permutes and returns the first 32 bytes of the state; a further call returns the next permutation’s.

update

update overloads

Static Data Members

Name Description

block_size

The rate, 136 bytes.

webcpp::hash::keccak_256::result_type

The digest, 32 bytes.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

using result_type = boost::hash2::digest<32>;

webcpp::hash::keccak_256::keccak_256

Constructors

Synopses

Declared in <webcpp/hash/keccak.hpp>

Constructs the hash of nothing yet.

keccak_256() noexcept;

Constructs a hash seeded by seed_value, as Hash2’s sha3_256 is: nothing when it is zero.

explicit
keccak_256(uint64_t seed_value) noexcept;

The same, from bytes.

keccak_256(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Constructs a hash seeded by the input_size bytes at input_data, as Hash2’s sha3_256 is.

keccak_256(
    void const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

seed_value

The seed.

input_data

The seed.

input_size

Its size.

webcpp::hash::keccak_256::keccak_256

Constructs the hash of nothing yet.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

keccak_256() noexcept;

webcpp::hash::keccak_256::keccak_256

Constructs a hash seeded by seed_value, as Hash2’s sha3_256 is: nothing when it is zero.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

explicit
keccak_256(uint64_t seed_value) noexcept;

Parameters

Name Description

seed_value

The seed.

webcpp::hash::keccak_256::keccak_256

The same, from bytes.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

keccak_256(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The seed.

input_size

Its size.

webcpp::hash::keccak_256::keccak_256

Constructs a hash seeded by the input_size bytes at input_data, as Hash2’s sha3_256 is.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

keccak_256(
    void const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The seed.

input_size

Its size.

webcpp::hash::keccak_256::result

Pads, if nothing was padded since the last update, permutes and returns the first 32 bytes of the state; a further call returns the next permutation’s.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

keccak_256::result_type
result() noexcept;

Return Value

The digest.

webcpp::hash::keccak_256::update

update overloads

Synopses

Declared in <webcpp/hash/keccak.hpp>

The same, from bytes.

void
update(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Absorbs input_size bytes.

void
update(
    void const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The bytes.

input_size

Their number.

webcpp::hash::keccak_256::update

The same, from bytes.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

void
update(
    unsigned char const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The bytes.

input_size

Their number.

webcpp::hash::keccak_256::update

Absorbs input_size bytes.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

void
update(
    void const* input_data,
    std::size_t input_size) noexcept;

Parameters

Name Description

input_data

The bytes.

input_size

Their number.

webcpp::hash::keccak_256::block_size

The rate, 136 bytes.

Synopsis

Declared in <webcpp/hash/keccak.hpp>

inline constexpr static
std::size_t block_size = 136;

webcpp::hash::mac_options

The parameters of a MAC (spec 2.15), defined in mac.hpp; declared here for the engines.

Synopsis

Declared in <webcpp/hash/mac.hpp>

template<class Mac>
struct mac_options;

Specializations

Name Description

mac_options<macs::kmac_128>

KMAC128’s parameters (NIST SP 800-185, section 4): the customisation string S, which separates one application’s tags from another’s under the same key, and the form, fixed-length or extendable-output (KMACXOF128).

mac_options<macs::kmac_256>

KMAC256’s parameters, as KMAC128’s (mac_options<macs::kmac_128>).

Template Parameters

Name Description

Mac

A tag of macs.

webcpp::hash::mac_options<macs::kmac_128>

KMAC128’s parameters (NIST SP 800-185, section 4): the customisation string S, which separates one application’s tags from another’s under the same key, and the form, fixed-length or extendable-output (KMACXOF128).

Synopsis

Declared in <webcpp/hash/mac.hpp>

template<>
struct mac_options<macs::kmac_128>;

Description

std::array<std::uint8_t, 32> tag{};
auto done = webcpp::hash::mac<webcpp::hash::macs::kmac_128>(
    tag, key, message, {.customisation = app_name});

The fixed-length form encodes the tag’s length L, so that its tags of 16 and 32 bytes are unrelated; the XOF form encodes none, and its shorter tag is the start of its longer. S is at most SIZE_MAX / 8 bytes (input_too_long), and is read during the call and not kept.

Data Members

Name Description

customisation

The customisation string S.

xof

The extendable-output form, KMACXOF128, in place of the fixed-length one.

webcpp::hash::mac_options<macs::kmac_128>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/mac.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::mac_options<macs::kmac_128>::xof

The extendable-output form, KMACXOF128, in place of the fixed-length one.

Synopsis

Declared in <webcpp/hash/mac.hpp>

bool xof = false;

webcpp::hash::mac_options<macs::kmac_256>

KMAC256’s parameters, as KMAC128’s (mac_options<macs::kmac_128>).

Synopsis

Declared in <webcpp/hash/mac.hpp>

template<>
struct mac_options<macs::kmac_256>;

Data Members

Name Description

customisation

The customisation string S.

xof

The extendable-output form, KMACXOF256, in place of the fixed-length one.

webcpp::hash::mac_options<macs::kmac_256>::customisation

The customisation string S.

Synopsis

Declared in <webcpp/hash/mac.hpp>

std::span<uint8_t const> customisation = = {};

webcpp::hash::mac_options<macs::kmac_256>::xof

The extendable-output form, KMACXOF256, in place of the fixed-length one.

Synopsis

Declared in <webcpp/hash/mac.hpp>

bool xof = false;

webcpp::hash::scrypt_parameters

The costs of scrypt, RFC 7914’s N, r and p.

Synopsis

Declared in <webcpp/hash/scrypt.hpp>

struct scrypt_parameters;

Data Members

Name Description

block_size

The block size, RFC 7914’s r, at least 1.

cost

The CPU and memory cost, RFC 7914’s N: a power of two, greater than 1, below 2^(16 r).

parallelism

The parallelisation, RFC 7914’s p, at least 1, with r times p below 2^30.

webcpp::hash::scrypt_parameters::block_size

The block size, RFC 7914’s r, at least 1.

Synopsis

Declared in <webcpp/hash/scrypt.hpp>

uint32_t block_size;

webcpp::hash::scrypt_parameters::cost

The CPU and memory cost, RFC 7914’s N: a power of two, greater than 1, below 2^(16 r).

Synopsis

Declared in <webcpp/hash/scrypt.hpp>

uint64_t cost;

webcpp::hash::scrypt_parameters::parallelism

The parallelisation, RFC 7914’s p, at least 1, with r times p below 2^30.

Synopsis

Declared in <webcpp/hash/scrypt.hpp>

uint32_t parallelism;

webcpp::hash::error

Why an operation of webcpp::hash failed.

Synopsis

Declared in <webcpp/hash/error.hpp>

enum class error : int;

Description

The values are fixed and never reused.

Members

Name Description

invalid_output_size

An output that is not of a size the function produces: empty, too short or too long.

invalid_key_size

A key that is not of a size the function accepts: a MAC’s, a derivation’s, HKDF’s PRK.

invalid_salt_size

A salt that is not of a size the function accepts.

invalid_iterations

An iteration count of zero, or above the backend’s limit (backend_limits).

invalid_parameters

A parameter that is outside the function’s limits: a cost, a lane count, an option.

input_too_long

An input that is longer than the function accepts.

backend_failure

A backend failed where its contract says it does not.

unsupported_by_backend

A parameter the chosen backend does not take; name a backend that does.

invalid_state

A hasher used after its finish, once moved from, or after a backend failure spent it.

See Also

"Errors", in the guide.

webcpp::hash::error::invalid_output_size

An output that is not of a size the function produces: empty, too short or too long.

Synopsis

Declared in <webcpp/hash/error.hpp>

invalid_output_size = 1

webcpp::hash::error::invalid_key_size

A key that is not of a size the function accepts: a MAC’s, a derivation’s, HKDF’s PRK.

Synopsis

Declared in <webcpp/hash/error.hpp>

invalid_key_size = 2

webcpp::hash::error::invalid_salt_size

A salt that is not of a size the function accepts.

Synopsis

Declared in <webcpp/hash/error.hpp>

invalid_salt_size = 3

webcpp::hash::error::invalid_iterations

An iteration count of zero, or above the backend’s limit (backend_limits).

Synopsis

Declared in <webcpp/hash/error.hpp>

invalid_iterations = 4

webcpp::hash::error::invalid_parameters

A parameter that is outside the function’s limits: a cost, a lane count, an option.

Synopsis

Declared in <webcpp/hash/error.hpp>

invalid_parameters = 5

webcpp::hash::error::input_too_long

An input that is longer than the function accepts.

Synopsis

Declared in <webcpp/hash/error.hpp>

input_too_long = 6

webcpp::hash::error::backend_failure

A backend failed where its contract says it does not.

Synopsis

Declared in <webcpp/hash/error.hpp>

backend_failure = 7

webcpp::hash::error::unsupported_by_backend

A parameter the chosen backend does not take; name a backend that does.

Synopsis

Declared in <webcpp/hash/error.hpp>

unsupported_by_backend = 8

webcpp::hash::error::invalid_state

A hasher used after its finish, once moved from, or after a backend failure spent it.

Synopsis

Declared in <webcpp/hash/error.hpp>

invalid_state = 9

webcpp::hash::argon2

Argon2 version 0x13 (RFC 9106) of the variant Variant with every parameter: fills output_bytes from password_bytes and salt_bytes.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

template<
    class Variant,
    class Backend = default_backend<Variant>>
[[nodiscard]]
boost::system::result<void>
argon2(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    argon2_parameters const& cost_parameters);

Description

Every guard of RFC 9106 runs first, then the backend’s own limits (unsupported_by_backend), and a refusal leaves output_bytes as it was; a backend’s failure zeroes it.

Return Value

Success; or the first guard’s error (invalid_output_size, invalid_salt_size, input_too_long, invalid_parameters, unsupported_by_backend), output_bytes untouched; or errc::not_enough_memory or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Variant

kdfs::argon2id (recommended for passwords), kdfs::argon2i or kdfs::argon2d.

Backend

The backend; by default default_backend of Variant (spec 4.1): backends::sodium for Argon2id and Argon2i, none for Argon2d, which names its backend (backends::openssl, which has every variant with every parameter, or backends::botan, which has every variant with at most 128 lanes and 8 GiB of memory, 2 GiB on wasm32).

Parameters

Name Description

output_bytes

The tag, 4 to 4,294,967,295 bytes; it must not overlap the inputs.

password_bytes

The password, at most 4,294,967,295 bytes.

salt_bytes

The salt, 8 to 4,294,967,295 bytes (16 random bytes are the usual choice).

cost_parameters

The costs, the lanes, the secret and the associated data.

webcpp::hash::argon2id

Argon2id version 0x13 (RFC 9106) with one lane, no secret and no associated data: fills output_bytes from password_bytes and salt_bytes.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

template<class Backend = default_backend<kdfs::argon2id>>
[[nodiscard]]
boost::system::result<void>
argon2id(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    argon2id_parameters const& cost_parameters);

Description

Note

On backends::openssl the memory is at most 4 TiB less 1 KiB, 4 GiB less 1 KiB on wasm32 (libsodium’s: the same natively, 2 GiB on wasm32; Botan’s: 8 GiB, 2 GiB on wasm32); a larger one is invalid_parameters.

Return Value

Success, or the error of the first guard that fails (invalid_output_size, invalid_salt_size, input_too_long, invalid_parameters), output_bytes untouched; or errc::not_enough_memory when the memory cannot be allocated, or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Backend

The backend; by default default_backend of kdfs::argon2id (spec 4.1), backends::sodium; or backends::openssl or backends::botan, named.

Parameters

Name Description

output_bytes

The tag, 16 to 4,294,967,295 bytes; it must not overlap password_bytes or salt_bytes (libsodium zeroes it before it reads them).

password_bytes

The password, at most 4,294,967,295 bytes.

salt_bytes

The salt, of argon2id_salt_size bytes.

cost_parameters

The costs.

webcpp::hash::async_argon2

Argon2 of the variant Variant with every parameter (RFC 9106) on a thread of work_executor’s context, as async_argon2id runs.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Variant,
    class Backend = default_backend<Variant>,
    class WorkExecutor,
    class CompletionToken>
auto
async_argon2(
    WorkExecutor const& work_executor,
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    argon2_parameters const& cost_parameters,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or argon2’s error, or operation_aborted.

Template Parameters

Name Description

Variant

kdfs::argon2id, kdfs::argon2i or kdfs::argon2d.

Backend

The backend; by default default_backend of Variant.

WorkExecutor

An Asio executor whose context runs on other threads.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

work_executor

The executor of the threads the work runs on.

output_bytes

The tag, 4 to 4,294,967,295 bytes.

password_bytes

The password.

salt_bytes

The salt, 8 to 4,294,967,295 bytes. The spans, and those of cost_parameters, are the caller’s until completion.

cost_parameters

The costs, the lanes, the secret and the associated data, copied.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_argon2id

Argon2id (RFC 9106, one lane) on a thread of work_executor’s context (spec 11.5).

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Backend = default_backend<kdfs::argon2id>,
    class WorkExecutor,
    class CompletionToken>
auto
async_argon2id(
    WorkExecutor const& work_executor,
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    argon2id_parameters const& cost_parameters,
    CompletionToken&& completion_token);

Description

The guards of argon2id first, whose refusal completes through a post; then the work, posted to work_executor (a webcpp::asio::thread_pool’s executor, typically); the completion on the handler’s associated executor (work_executor by default; a program binds its event loop’s with bind_executor), so that the event loop never blocks. Exists only where the build has threads (WEBCPP_HASH_HAS_THREADS).

Cancellation through the handler’s slot: before the work starts, any type completes the operation at once with operation_aborted, the work never runs; during it, a terminal or partial one lets the work end (libsodium cannot be interrupted), then output_bytes is zeroed and the completion is operation_aborted (a total one is then ignored: zeroing is a side effect). "At once" is on the handler’s associated executor: for a handler without one, that is work_executor, so the completion waits for its threads; bind the handler to the event loop’s executor, and emit the signal there too, never from another thread, as Asio’s slots require.

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or argon2id’s error, or operation_aborted.

Template Parameters

Name Description

Backend

The backend; by default default_backend of kdfs::argon2id.

WorkExecutor

An Asio executor whose context runs on other threads.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

work_executor

The executor of the threads the work runs on.

output_bytes

The tag, 16 to 4,294,967,295 bytes.

password_bytes

The password.

salt_bytes

The salt, of argon2id_salt_size bytes. The spans are the caller’s until completion.

cost_parameters

The costs, copied.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_bcrypt

bcrypt on a thread of work_executor’s context (spec 11.5), as async_argon2id runs: the guards of bcrypt first, whose refusal completes through a post, output_characters untouched; then the work.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Backend = default_backend<kdfs::bcrypt>,
    class WorkExecutor,
    class CompletionToken>
auto
async_bcrypt(
    WorkExecutor const& work_executor,
    std::span<char> output_characters,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    bcrypt_parameters const& cost_parameters,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or bcrypt’s error, or operation_aborted (a cancellation during the work zeroes output_characters).

Template Parameters

Name Description

Backend

The backend; default_backend of kdfs::bcrypt has none: the call names backends::botan.

WorkExecutor

An Asio executor whose context runs on other threads.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

work_executor

The executor of the threads the work runs on.

output_characters

The string, exactly bcrypt_hash_size characters.

password_bytes

The password.

salt_bytes

The salt, of bcrypt_salt_size bytes. The spans are the caller’s until completion.

cost_parameters

The cost and the version, copied.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_bcrypt_pbkdf

OpenBSD’s bcrypt_pbkdf on a thread of work_executor’s context, as async_argon2id runs.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Backend = default_backend<kdfs::bcrypt_pbkdf>,
    class WorkExecutor,
    class CompletionToken>
auto
async_bcrypt_pbkdf(
    WorkExecutor const& work_executor,
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    uint32_t round_count,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or bcrypt_pbkdf’s error, or operation_aborted.

Template Parameters

Name Description

Backend

The backend; default_backend of kdfs::bcrypt_pbkdf has none: the call names backends::botan.

WorkExecutor

An Asio executor whose context runs on other threads.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

work_executor

The executor of the threads the work runs on.

output_bytes

The derived key, 1 to 1,024 bytes.

password_bytes

The password, 1 byte or more.

salt_bytes

The salt, 1 to 1,048,576 bytes. The spans are the caller’s until completion.

round_count

The rounds, 1 or more.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_bcrypt_verify

bcrypt_verify on a thread of work_executor’s context, as async_argon2id runs, completing with whether the password gives the string: it computes bcrypt in full, as slow as bcrypt (spec 11.5: every deliberately slow function has its heavy variant).

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Backend = default_backend<kdfs::bcrypt>,
    class WorkExecutor,
    class CompletionToken>
auto
async_bcrypt_verify(
    WorkExecutor const& work_executor,
    std::span<uint8_t const> password_bytes,
    std::string_view encoded_hash,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, its bool then whether the password gives the string; or bcrypt_verify’s error, or operation_aborted, the bool false.

Template Parameters

Name Description

Backend

The backend; the call names backends::botan, as for async_bcrypt.

WorkExecutor

An Asio executor whose context runs on other threads.

CompletionToken

An Asio completion token of signature void(boost::system::error_code, bool).

Parameters

Name Description

work_executor

The executor of the threads the work runs on.

password_bytes

The password.

encoded_hash

The string, of bcrypt’s form. Both are the caller’s until completion.

completion_token

The completion token, of signature void(boost::system::error_code, bool).

webcpp::hash::async_digest

Hashes input_bytes into output_bytes with the digest Digest, asynchronously (spec 11): on a synchronous backend, the default, at once, completing through a post on the handler’s associated executor (completion_executor by default), never inside the call.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Digest,
    class Backend = default_async_backend<Digest>,
    class Executor,
    class CompletionToken>
auto
async_digest(
    Executor const& completion_executor,
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> input_bytes,
    CompletionToken&& completion_token);

Description

webcpp::hash::async_digest<webcpp::hash::digests::sha2_256>(
    loop.get_executor(), id, message, [](boost::system::error_code code) { ... });

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or digest_of’s error, output_bytes untouched by a guard’s refusal and zeroed by a backend’s failure. On backends::webcrypto also invalid_parameters (the executor), output_bytes untouched, backend_failure (a rejected promise, an unexpected result, no WebCrypto), output_bytes zeroed, and operation_aborted (a terminal or partial cancellation, at once), output_bytes zeroed.

Template Parameters

Name Description

Digest

digests::sha1, digests::sha2_256, digests::sha2_384 or digests::sha2_512, the digests WebCrypto has; another refuses at compile time (digest_of has them all).

Backend

The backend; by default default_async_backend of Digest, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_bytes

The digest, of exactly the digest’s size; the caller’s until completion.

input_bytes

The data; the caller’s until completion.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf

async_hkdf overloads

Synopses

Declared in <webcpp/hash/async.hpp>

HKDF (RFC 5869), extract and expand, over pieces, asynchronously (spec 11): the output keying material of the hkdf<Hmac, Backend> over byte_pieces, with no cap on the application info.

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_pieces, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    byte_pieces input_key_material,
    byte_pieces application_info,
    CompletionToken&& completion_token);

HKDF (RFC 5869), extract and expand, asynchronously (spec 11), as async_digest runs: the output keying material of hkdf<Hmac, Backend>.

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material,
    std::span<uint8_t const> application_info,
    CompletionToken&& completion_token);

Return Value

  • What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf’s error over pieces, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure.

  • What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf’s error, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure. On backends::webcrypto also invalid_parameters (the executor), output_key_material untouched, backend_failure (a rejected promise, an unexpected result, no WebCrypto), output_key_material zeroed, and operation_aborted (a terminal or partial cancellation, at once), output_key_material zeroed.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_pieces, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_key_material

The output keying material, 1 to 255 times the digest size; the caller’s until completion.

salt

The salt.

input_key_material

The input keying material’s pieces.

application_info

The context’s pieces. The salt and the pieces are read in the call.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf

HKDF (RFC 5869), extract and expand, over pieces, asynchronously (spec 11): the output keying material of the hkdf<Hmac, Backend> over byte_pieces, with no cap on the application info.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_pieces, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    byte_pieces input_key_material,
    byte_pieces application_info,
    CompletionToken&& completion_token);

Description

On a synchronous backend, the default, the synchronous function runs in the call itself, before the operation is initiated, and only its error code is posted to the handler’s associated executor (completion_executor by default): the pieces and their list are read before the call returns, so that a braced list written at the call, whose array dies at the end of the call’s full-expression, is safe with every completion token, asio::deferred and use_awaitable’s lazy awaitable included (with those, the work is done at the call, not at the launch). On backends::webcrypto the pieces are gathered into JavaScript memory in the call too.

webcpp::hash::async_hkdf<webcpp::hash::hmac_sha2_256>(
    loop.get_executor(), key, salt, {version, suite_id, label, ikm},
    {length, version, suite_id, label, info}, [](boost::system::error_code code) { ... });

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf’s error over pieces, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_pieces, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_key_material

The output keying material, 1 to 255 times the digest size; the caller’s until completion.

salt

The salt.

input_key_material

The input keying material’s pieces.

application_info

The context’s pieces. The salt and the pieces are read in the call.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf

HKDF (RFC 5869), extract and expand, asynchronously (spec 11), as async_digest runs: the output keying material of hkdf<Hmac, Backend>.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material,
    std::span<uint8_t const> application_info,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf’s error, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure. On backends::webcrypto also invalid_parameters (the executor), output_key_material untouched, backend_failure (a rejected promise, an unexpected result, no WebCrypto), output_key_material zeroed, and operation_aborted (a terminal or partial cancellation, at once), output_key_material zeroed.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_key_material

The output keying material, 1 to 255 times the digest size.

salt

The salt.

input_key_material

The input keying material.

application_info

The context, at most hkdf_max_application_info_size bytes; on backends::webcrypto at most 1,024, WebCrypto’s limit (input_too_long beyond). The spans are the caller’s until completion.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf_expand

async_hkdf_expand overloads

Synopses

Declared in <webcpp/hash/async.hpp>

HKDF-Expand (RFC 5869, section 2.3) over pieces, asynchronously (spec 11), as the async_hkdf over pieces runs: the output keying material of hkdf_expand<Hmac, Backend> over byte_pieces, with no cap on the application info, the pieces read in the call.

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_expand_pieces, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_expand(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    byte_pieces application_info,
    CompletionToken&& completion_token);

HKDF-Expand (RFC 5869, section 2.3), asynchronously (spec 11), as async_digest runs: the output keying material of hkdf_expand<Hmac, Backend>.

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_expand, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_expand(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    std::span<uint8_t const> application_info,
    CompletionToken&& completion_token);

Return Value

  • What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf_expand’s error over pieces, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure.

  • What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf_expand’s error, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf_expand has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_expand_pieces, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_key_material

The output keying material, 1 to 255 times the digest size; the caller’s until completion.

pseudorandom_key

The pseudorandom key, of exactly the digest size.

application_info

The context’s pieces. The key and the pieces are read in the call.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf_expand

HKDF-Expand (RFC 5869, section 2.3) over pieces, asynchronously (spec 11), as the async_hkdf over pieces runs: the output keying material of hkdf_expand<Hmac, Backend> over byte_pieces, with no cap on the application info, the pieces read in the call.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_expand_pieces, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_expand(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    byte_pieces application_info,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf_expand’s error over pieces, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf_expand has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_expand_pieces, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_key_material

The output keying material, 1 to 255 times the digest size; the caller’s until completion.

pseudorandom_key

The pseudorandom key, of exactly the digest size.

application_info

The context’s pieces. The key and the pieces are read in the call.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf_expand

HKDF-Expand (RFC 5869, section 2.3), asynchronously (spec 11), as async_digest runs: the output keying material of hkdf_expand<Hmac, Backend>.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_expand, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_expand(
    Executor const& completion_executor,
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    std::span<uint8_t const> application_info,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or hkdf_expand’s error, output_key_material untouched by a guard’s refusal and zeroed by a backend’s failure.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf_expand has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_expand, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_key_material

The output keying material, 1 to 255 times the digest size.

pseudorandom_key

The pseudorandom key, of exactly the digest size.

application_info

The context, at most hkdf_max_application_info_size bytes. The spans are the caller’s until completion.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf_extract

async_hkdf_extract overloads

Synopses

Declared in <webcpp/hash/async.hpp>

HKDF-Extract (RFC 5869, section 2.2) over pieces, asynchronously (spec 11), as the async_hkdf over pieces runs: the pseudorandom key of hkdf_extract<Hmac, Backend> over byte_pieces, written into pseudorandom_key, the pieces read in the call.

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_extract_pieces, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_extract(
    Executor const& completion_executor,
    std::span<uint8_t> pseudorandom_key,
    std::span<uint8_t const> salt,
    byte_pieces input_key_material,
    CompletionToken&& completion_token);

HKDF-Extract (RFC 5869, section 2.2), asynchronously (spec 11), as async_digest runs: the pseudorandom key of hkdf_extract<Hmac, Backend>, written into pseudorandom_key.

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_extract, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_extract(
    Executor const& completion_executor,
    std::span<uint8_t> pseudorandom_key,
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material,
    CompletionToken&& completion_token);

Return Value

  • What the completion token’s async_result gives. The completion’s code is empty on success, or invalid_output_size for a pseudorandom_key of another size than the digest’s, or hkdf_extract’s error over pieces, pseudorandom_key untouched by a guard’s refusal and zeroed by a backend’s failure.

  • What the completion token’s async_result gives. The completion’s code is empty on success, or invalid_output_size for a pseudorandom_key of another size than the digest’s, or hkdf_extract’s error, pseudorandom_key untouched by a guard’s refusal and zeroed by a backend’s failure.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf_extract has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_extract_pieces, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

pseudorandom_key

The pseudorandom key, of exactly the digest size; the caller’s until completion.

salt

The salt.

input_key_material

The input keying material’s pieces. Both read in the call.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf_extract

HKDF-Extract (RFC 5869, section 2.2) over pieces, asynchronously (spec 11), as the async_hkdf over pieces runs: the pseudorandom key of hkdf_extract<Hmac, Backend> over byte_pieces, written into pseudorandom_key, the pieces read in the call.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_extract_pieces, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_extract(
    Executor const& completion_executor,
    std::span<uint8_t> pseudorandom_key,
    std::span<uint8_t const> salt,
    byte_pieces input_key_material,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or invalid_output_size for a pseudorandom_key of another size than the digest’s, or hkdf_extract’s error over pieces, pseudorandom_key untouched by a guard’s refusal and zeroed by a backend’s failure.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf_extract has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_extract_pieces, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

pseudorandom_key

The pseudorandom key, of exactly the digest size; the caller’s until completion.

salt

The salt.

input_key_material

The input keying material’s pieces. Both read in the call.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hkdf_extract

HKDF-Extract (RFC 5869, section 2.2), asynchronously (spec 11), as async_digest runs: the pseudorandom key of hkdf_extract<Hmac, Backend>, written into pseudorandom_key.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::hkdf_extract, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_hkdf_extract(
    Executor const& completion_executor,
    std::span<uint8_t> pseudorandom_key,
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or invalid_output_size for a pseudorandom_key of another size than the digest’s, or hkdf_extract’s error, pseudorandom_key untouched by a guard’s refusal and zeroed by a backend’s failure.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over; another refuses at compile time (hkdf_extract has them all).

Backend

The backend; by default default_async_backend of kdfs::hkdf_extract, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

pseudorandom_key

The pseudorandom key, of exactly the digest size.

salt

The salt.

input_key_material

The input keying material. The spans are the caller’s until completion.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_hmac

The HMAC of input_bytes under key_bytes over the Boost.Hash2 hmac Hmac, asynchronously (spec 11), as async_digest runs: the tag of mac<macs::hmac<...>> over Hmac’s digest.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend</* implementation-defined */>,
    class Executor,
    class CompletionToken>
auto
async_hmac(
    Executor const& completion_executor,
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> key_bytes,
    std::span<uint8_t const> input_bytes,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or mac’s error, output_bytes untouched by a guard’s refusal and zeroed by a backend’s failure. On backends::webcrypto also invalid_parameters (the executor), output_bytes untouched, backend_failure (a rejected promise, an unexpected result, no WebCrypto), output_bytes zeroed, and operation_aborted (a terminal or partial cancellation, at once), output_bytes zeroed.

Template Parameters

Name Description

Hmac

hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has; another refuses at compile time (mac has them all).

Backend

The backend; by default default_async_backend of the HMAC’s tag, the synchronous default. backends::webcrypto only on Emscripten.

Executor

An Asio executor, where the completion is posted.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

completion_executor

The executor the completion is posted to; on backends::webcrypto, that of an io_context run on the calling thread (see async_pbkdf2), and a refusal of another goes to the handler’s associated executor, this one unless the handler is bound to another.

output_bytes

The tag, 10 bytes up to the digest’s size; the caller’s until completion.

key_bytes

The key, of any size.

input_bytes

The message. Both the caller’s until completion.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_pbkdf2

PBKDF2 (RFC 8018), asynchronously.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Hmac,
    class Backend = default_async_backend<kdfs::pbkdf2, Hmac>,
    class Executor,
    class CompletionToken>
auto
async_pbkdf2(
    Executor const& work_executor,
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    uint64_t iteration_count,
    CompletionToken&& completion_token);

Description

On a synchronous backend, the default, a heavy function (spec 11.5): the work runs on a thread of work_executor’s context (a webcpp::asio::thread_pool’s) and completes on the handler’s associated executor (work_executor by default; a program binds its event loop’s with bind_executor), and it exists only where the build has threads (WEBCPP_HASH_HAS_THREADS). On backends::webcrypto, on Emscripten, the browser runs it and no thread is needed: there work_executor must be that of an io_context run on the calling thread, whose run returns to the JavaScript event loop where WebCrypto’s promise settles (ruling R73). The context is checked: a concrete executor of another context (a thread_pool’s) stops the build, and a type-erased one (any_io_executor) whose context is not an io_context, or whose io_context executor it hides behind another allocator or two concrete strands, completes with invalid_parameters, posted to the handler’s associated executor. The calling thread is the program’s duty, not checked. WebCrypto takes at most 2^32 - 1 iterations (invalid_iterations) and an output of at most (2^32 - 1) / 8 bytes (invalid_output_size), over hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 and hmac_sha2_512 alone.

Cancellation through the handler’s slot, on a synchronous backend: before the work starts, any type completes the operation at once with operation_aborted, the work never runs; during it, a terminal or partial one lets the work end, then output_bytes is zeroed and the completion is operation_aborted (a total one is then ignored). "At once" is on the handler’s associated executor: for a handler without one, that is work_executor, so the completion waits for its threads; bind the handler to the event loop’s executor, and emit the signal there too, never from another thread, as Asio’s slots require. On backends::webcrypto a terminal or partial one completes at once with operation_aborted, output_bytes zeroed, while the browser’s work runs to its end unseen; a total one is ignored.

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or pbkdf2’s error, a guard’s refusal completing through a post, output_bytes untouched; or operation_aborted. On backends::webcrypto also invalid_parameters (the executor), output_bytes untouched, and backend_failure (a rejected promise, an unexpected result, no WebCrypto), output_bytes zeroed.

Template Parameters

Name Description

Hmac

The pseudorandom function, as hmac_sha2_512.

Backend

The backend; by default default_async_backend of kdfs::pbkdf2, the synchronous default.

Executor

An Asio executor: of the threads the work runs on, or WebCrypto’s io_context’s.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

work_executor

The work executor, or WebCrypto’s io_context executor.

output_bytes

The derived key, 1 to (2^32 - 1) times the digest size.

password_bytes

The password.

salt_bytes

The salt. The spans are the caller’s until completion.

iteration_count

The iteration count, at least 1.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::async_scrypt

scrypt (RFC 7914) on a thread of work_executor’s context, as async_argon2id runs.

Synopsis

Declared in <webcpp/hash/async.hpp>

template<
    class Backend = default_backend<kdfs::scrypt>,
    class WorkExecutor,
    class CompletionToken>
auto
async_scrypt(
    WorkExecutor const& work_executor,
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    scrypt_parameters const& cost_parameters,
    CompletionToken&& completion_token);

Return Value

What the completion token’s async_result gives. The completion’s code is empty on success, or scrypt’s error, or operation_aborted.

Template Parameters

Name Description

Backend

The backend; by default default_backend of kdfs::scrypt.

WorkExecutor

An Asio executor whose context runs on other threads.

CompletionToken

An Asio completion token of signature void(boost::system::error_code).

Parameters

Name Description

work_executor

The executor of the threads the work runs on.

output_bytes

The derived key.

password_bytes

The password.

salt_bytes

The salt. The spans are the caller’s until completion.

cost_parameters

The costs, copied.

completion_token

The completion token, of signature void(boost::system::error_code).

webcpp::hash::bcrypt

The modular crypt string of password_bytes under the caller’s 16-byte salt_bytes, into 60 chars: "\$2", the version, "\$", the cost in two digits, "$", the salt then the hash in bcrypt’s base 64.

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

template<class Backend = default_backend<kdfs::bcrypt>>
[[nodiscard]]
boost::system::result<void>
bcrypt(
    std::span<char> output_characters,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    bcrypt_parameters const& cost_parameters = {});

Return Value

Success; or the first guard’s error (invalid_output_size, invalid_salt_size, input_too_long, invalid_parameters, then the backend’s unsupported_by_backend: backends::botan’s cost above 18), output_characters untouched; or errc::not_enough_memory or backend_failure, output_characters zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Backend

The backend; default_backend of kdfs::bcrypt has none (design D34): the call names backends::botan.

Parameters

Name Description

output_characters

The string, exactly bcrypt_hash_size characters, not terminated by a zero.

password_bytes

The password, at most bcrypt_max_password_size bytes, without a zero byte.

salt_bytes

The salt, exactly bcrypt_salt_size random bytes.

cost_parameters

The cost (4 to 31) and the version ('a', 'b' or 'y').

webcpp::hash::bcrypt_pbkdf

OpenBSD’s bcrypt_pbkdf, as OpenSSH’s keys use it: fills output_bytes from password_bytes and salt_bytes by round_count rounds of bcrypt’s hash over their SHA-512 digests, its blocks interleaved.

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

template<class Backend = default_backend<kdfs::bcrypt_pbkdf>>
[[nodiscard]]
boost::system::result<void>
bcrypt_pbkdf(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    uint32_t round_count);

Return Value

Success; or the first guard’s error (invalid_output_size, invalid_salt_size, invalid_key_size, invalid_iterations), output_bytes untouched; or errc::not_enough_memory or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Backend

The backend; default_backend of kdfs::bcrypt_pbkdf has none (design D34): the call names backends::botan.

Parameters

Name Description

output_bytes

The derived key, 1 to 1,024 bytes.

password_bytes

The password, 1 byte or more.

salt_bytes

The salt, 1 to 1,048,576 bytes.

round_count

The rounds, 1 or more.

webcpp::hash::bcrypt_verify

Whether password_bytes gives encoded_hash, a modular crypt string of bcrypt, compared in constant time.

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

template<class Backend = default_backend<kdfs::bcrypt>>
[[nodiscard]]
boost::system::result<bool>
bcrypt_verify(
    std::span<uint8_t const> password_bytes,
    std::string_view encoded_hash);

Description

A caller that checks strings made by an implementation that silently cuts a longer password (at 72 bytes, as OpenBSD’s and most others do) passes the first 72 bytes of the password: bcrypt reads no more, so the answer is the same, where the whole password is refused with input_too_long.

Return Value

true when the password gives the string, false otherwise; or the first guard’s error (input_too_long or invalid_parameters for the password, invalid_parameters for a string not of bcrypt’s form, then the backend’s unsupported_by_backend: backends::botan’s cost above 18); or errc::not_enough_memory or backend_failure.

Note

The return value should not be discarded.

Template Parameters

Name Description

Backend

The backend; the call names backends::botan, as for bcrypt.

Parameters

Name Description

password_bytes

The password, at most bcrypt_max_password_size bytes, without a zero byte.

encoded_hash

The string, bcrypt_hash_size characters of bcrypt’s form.

webcpp::hash::blake2b_subkey

The subkey subkey_id of master_key in context_bytes, libsodium’s crypto_kdf_derive_from_key: keys for different purposes from one master key, each unrelated to the others and to the master key without it.

Synopsis

template<class Backend = default_backend<kdfs::blake2b_subkey>>
[[nodiscard]]
boost::system::result<void>
blake2b_subkey(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> master_key,
    uint64_t subkey_id,
    std::span<uint8_t const> context_bytes);

Description

std::array<std::uint8_t, 32> file_key{};
auto done = webcpp::hash::blake2b_subkey(file_key, master_key, 1, context);  // context: 8 bytes

Return Value

Success; or the first guard’s error (invalid_output_size, invalid_key_size, invalid_parameters for the context), output_bytes untouched; or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Backend

The backend; by default default_backend of kdfs::blake2b_subkey (spec 4.1), backends::sodium, the only one that has it. Another backend, or a program that does not link libsodium, refuses at compile time.

Parameters

Name Description

output_bytes

The subkey, 16 to 64 bytes; it must not overlap master_key or context_bytes. Its length is a parameter of BLAKE2b: a subkey of 32 bytes is not the first 32 bytes of the one of 64.

master_key

The master key, 32 bytes, secret and uniformly random.

subkey_id

The subkey’s number, any 64-bit value: one per key the application needs.

context_bytes

8 bytes naming the application or its purpose, as "vault v1": the same id in another context gives an unrelated subkey. Not secret.

webcpp::hash::category

The category of every error.

Synopsis

Declared in <webcpp/hash/error.hpp>

boost::system::error_category const&
category() noexcept;

Description

Its name() is "webcpp.hash", and its message(value) the message of the error, or "unknown webcpp.hash error" for a value error does not define.

Return Value

The category, a constant with a fixed identity.

See Also

"Errors", in the guide.

webcpp::hash::digest_of

Hashes input_bytes into output_bytes with the digest Digest on Backend, in one call.

Synopsis

Declared in <webcpp/hash/digest.hpp>

template<
    class Digest,
    class Backend = default_backend<Digest>>
[[nodiscard]]
boost::system::result<void>
digest_of(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> input_bytes,
    digest_options<Digest> const& algorithm_options = {});

Description

std::array<std::uint8_t, 32> id{};
auto done = webcpp::hash::digest_of<webcpp::hash::digests::sha2_256>(id, message);

Return Value

Success; or the first guard’s error (invalid_output_size, an option’s error, unsupported_by_backend), output_bytes untouched; or the backend’s failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Digest

A tag of digests, as digests::sha2_256.

Backend

The backend; by default default_backend of Digest (spec 4.1). A backend without the tag, or one the program does not link, refuses at compile time, naming those that have it, or the Jamfile line to add.

Parameters

Name Description

output_bytes

The digest: exactly the digest’s size for a fixed-size digest, any size from 1 byte for an extendable-output function.

input_bytes

The data, of any size.

algorithm_options

The digest’s parameters (none for most tags).

webcpp::hash::hkdf

hkdf overloads

Synopses

Declared in <webcpp/hash/hkdf.hpp>

HKDF (RFC 5869, section 2) over pieces: extract, then expand, the pseudorandom key wiped between them.

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_pieces>>
[[nodiscard]]
boost::system::result<void>
hkdf(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    byte_pieces input_key_material,
    byte_pieces application_info);

HKDF (RFC 5869, section 2): extract, then expand.

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac>>
[[nodiscard]]
boost::system::result<void>
hkdf(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material,
    std::span<uint8_t const> application_info);

Return Value

  • Success, or the error of the first guard that fails (invalid_output_size, then input_too_long for a salt longer than the backend’s HMAC takes), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

  • Success, or the error of the first guard that fails (invalid_output_size, input_too_long, then the backend’s own limits: invalid_output_size, input_too_long; for backends::openssl a salt of more than INT_MAX bytes), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_pieces> names, backends::hash2.

Parameters

Name Description

output_key_material

The output keying material, 1 to 255 times the digest size.

salt

The salt, any length the backend’s HMAC takes as a key; empty means Hmac’s digest size of zeros.

input_key_material

The input keying material’s pieces, of any number and length.

application_info

The context’s pieces, of any number and length: no cap.

webcpp::hash::hkdf

HKDF (RFC 5869, section 2) over pieces: extract, then expand, the pseudorandom key wiped between them.

Synopsis

Declared in <webcpp/hash/hkdf.hpp>

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_pieces>>
[[nodiscard]]
boost::system::result<void>
hkdf(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    byte_pieces input_key_material,
    byte_pieces application_info);

Description

// RFC 9180's LabeledExtract and LabeledExpand in one call, no buffer joined.
auto done = webcpp::hash::hkdf<webcpp::hash::hmac_sha2_256>(
    key, salt, {version, suite_id, label, ikm}, {length, version, suite_id, label, info});

Return Value

Success, or the error of the first guard that fails (invalid_output_size, then input_too_long for a salt longer than the backend’s HMAC takes), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_pieces> names, backends::hash2.

Parameters

Name Description

output_key_material

The output keying material, 1 to 255 times the digest size.

salt

The salt, any length the backend’s HMAC takes as a key; empty means Hmac’s digest size of zeros.

input_key_material

The input keying material’s pieces, of any number and length.

application_info

The context’s pieces, of any number and length: no cap.

webcpp::hash::hkdf

HKDF (RFC 5869, section 2): extract, then expand.

Synopsis

Declared in <webcpp/hash/hkdf.hpp>

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac>>
[[nodiscard]]
boost::system::result<void>
hkdf(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material,
    std::span<uint8_t const> application_info);

Return Value

Success, or the error of the first guard that fails (invalid_output_size, input_too_long, then the backend’s own limits: invalid_output_size, input_too_long; for backends::openssl a salt of more than INT_MAX bytes), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac.

Backend

The backend.

Parameters

Name Description

output_key_material

The output keying material, 1 to 255 times the digest size.

salt

The salt, any length the backend takes; empty means Hmac’s digest size of zeros.

input_key_material

The input keying material, any length the backend takes.

application_info

The context, at most hkdf_max_application_info_size bytes.

webcpp::hash::hkdf_expand

hkdf_expand overloads

Synopses

Declared in <webcpp/hash/hkdf.hpp>

HKDF-Expand (RFC 5869, section 2.3) over pieces: fills output_key_material from pseudorandom_key and the concatenation of application_info’s pieces, each piece fed to the backend’s HMAC for each block.

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_expand_pieces>>
[[nodiscard]]
boost::system::result<void>
hkdf_expand(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    byte_pieces application_info);

HKDF-Expand (RFC 5869, section 2.3): fills output_key_material from pseudorandom_key and application_info.

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_expand>>
[[nodiscard]]
boost::system::result<void>
hkdf_expand(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    std::span<uint8_t const> application_info);

Return Value

  • Success, or the error of the first guard that fails (invalid_output_size, invalid_key_size), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

  • Success, or the error of the first guard that fails (invalid_output_size, invalid_key_size, input_too_long, then the backend’s own limits: invalid_output_size, input_too_long), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_expand_pieces> names, backends::hash2.

Parameters

Name Description

output_key_material

The output keying material, 1 to 255 times the digest size.

pseudorandom_key

The pseudorandom key, of exactly the digest size.

application_info

The context’s pieces, of any number and length: no cap.

webcpp::hash::hkdf_expand

HKDF-Expand (RFC 5869, section 2.3) over pieces: fills output_key_material from pseudorandom_key and the concatenation of application_info’s pieces, each piece fed to the backend’s HMAC for each block.

Synopsis

Declared in <webcpp/hash/hkdf.hpp>

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_expand_pieces>>
[[nodiscard]]
boost::system::result<void>
hkdf_expand(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    byte_pieces application_info);

Return Value

Success, or the error of the first guard that fails (invalid_output_size, invalid_key_size), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_expand_pieces> names, backends::hash2.

Parameters

Name Description

output_key_material

The output keying material, 1 to 255 times the digest size.

pseudorandom_key

The pseudorandom key, of exactly the digest size.

application_info

The context’s pieces, of any number and length: no cap.

webcpp::hash::hkdf_expand

HKDF-Expand (RFC 5869, section 2.3): fills output_key_material from pseudorandom_key and application_info.

Synopsis

Declared in <webcpp/hash/hkdf.hpp>

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_expand>>
[[nodiscard]]
boost::system::result<void>
hkdf_expand(
    std::span<uint8_t> output_key_material,
    std::span<uint8_t const> pseudorandom_key,
    std::span<uint8_t const> application_info);

Return Value

Success, or the error of the first guard that fails (invalid_output_size, invalid_key_size, input_too_long, then the backend’s own limits: invalid_output_size, input_too_long), output_key_material untouched; or the backend’s failure, output_key_material zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_expand> names, backends::hash2.

Parameters

Name Description

output_key_material

The output keying material, 1 to 255 times the digest size.

pseudorandom_key

The pseudorandom key, of exactly the digest size.

application_info

The context, at most hkdf_max_application_info_size bytes.

webcpp::hash::hkdf_extract

hkdf_extract overloads

Synopses

Declared in <webcpp/hash/hkdf.hpp>

HKDF-Extract (RFC 5869, section 2.2) over pieces: the pseudorandom key of the concatenation of input_key_material’s pieces under salt, each piece fed to the backend’s HMAC.

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_extract_pieces>>
[[nodiscard]]
boost::system::result</* implementation-defined */::type>
hkdf_extract(
    std::span<uint8_t const> salt,
    byte_pieces input_key_material);

HKDF-Extract (RFC 5869, section 2.2): the pseudorandom key of input_key_material under salt.

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_extract>>
[[nodiscard]]
boost::system::result</* implementation-defined */::type>
hkdf_extract(
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material);

Return Value

  • The pseudorandom key, an Hmac::result_type of the hmac’s digest size; or input_too_long for a salt longer than the backend’s HMAC takes (backends::openssl: more than INT_MAX bytes); or the backend’s failure.

  • The pseudorandom key, an Hmac::result_type of the hmac’s digest size; or input_too_long for a salt or an IKM longer than the backend takes (backends::openssl: a salt of more than INT_MAX bytes); or the backend’s failure.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac, as hmac_sha2_256.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_extract_pieces> names, backends::hash2.

Parameters

Name Description

salt

The salt, any length the backend’s HMAC takes as a key; empty means Hmac’s digest size of zeros.

input_key_material

The input keying material’s pieces, of any number and length.

webcpp::hash::hkdf_extract

HKDF-Extract (RFC 5869, section 2.2) over pieces: the pseudorandom key of the concatenation of input_key_material’s pieces under salt, each piece fed to the backend’s HMAC.

Synopsis

Declared in <webcpp/hash/hkdf.hpp>

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_extract_pieces>>
[[nodiscard]]
boost::system::result</* implementation-defined */::type>
hkdf_extract(
    std::span<uint8_t const> salt,
    byte_pieces input_key_material);

Description

auto prk = webcpp::hash::hkdf_extract<webcpp::hash::hmac_sha2_256>(salt, {prefix, label, ikm});

Return Value

The pseudorandom key, an Hmac::result_type of the hmac’s digest size; or input_too_long for a salt longer than the backend’s HMAC takes (backends::openssl: more than INT_MAX bytes); or the backend’s failure.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac, as hmac_sha2_256.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_extract_pieces> names, backends::hash2.

Parameters

Name Description

salt

The salt, any length the backend’s HMAC takes as a key; empty means Hmac’s digest size of zeros.

input_key_material

The input keying material’s pieces, of any number and length.

webcpp::hash::hkdf_extract

HKDF-Extract (RFC 5869, section 2.2): the pseudorandom key of input_key_material under salt.

Synopsis

Declared in <webcpp/hash/hkdf.hpp>

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::hkdf_extract>>
[[nodiscard]]
boost::system::result</* implementation-defined */::type>
hkdf_extract(
    std::span<uint8_t const> salt,
    std::span<uint8_t const> input_key_material);

Return Value

The pseudorandom key, an Hmac::result_type of the hmac’s digest size; or input_too_long for a salt or an IKM longer than the backend takes (backends::openssl: a salt of more than INT_MAX bytes); or the backend’s failure.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The hmac, as hmac_sha2_256.

Backend

The backend; by default the one default_kdf_backend<Hmac, kdfs::hkdf_extract> names, backends::hash2.

Parameters

Name Description

salt

The salt, any length the backend takes; empty means Hmac’s digest size of zeros.

input_key_material

The input keying material, any length the backend takes.

webcpp::hash::kbkdf

SP 800-108’s key-based key derivation (NIST SP 800-108r1, section 4.1, counter mode) over the HMAC Hmac: fills output_bytes from the key-derivation key key_bytes, each block an HMAC under key_bytes of the counter, then the fixed input algorithm_options states.

Synopsis

template<
    class Hmac,
    class Backend = default_backend<kdfs::kbkdf_hmac, Hmac>>
[[nodiscard]]
boost::system::result<void>
kbkdf(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> key_bytes,
    kbkdf_options const& algorithm_options = {});

Description

std::array<std::uint8_t, 32> derived{};
auto done = webcpp::hash::kbkdf<webcpp::hash::hmac_sha2_256, webcpp::hash::backends::openssl>(
    derived, key, {.label = label, .context = context});

Return Value

Success; or the first guard’s error (invalid_parameters for a counter width other than 8, 16, 24 or 32, invalid_output_size, invalid_key_size, unsupported_by_backend), output_bytes untouched; or errc::not_enough_memory or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The PRF, a Boost.Hash2 hmac, as hmac_sha2_256. SP 800-108r1 approves HMAC over an approved hash function (SHA-1, SHA-2, SHA-3); unlike sskdf and x963kdf, which refuse a digest their standard does not take, kbkdf takes every hmac its backend has, MD5’s, RIPEMD-160’s and BLAKE2’s included, for the protocols outside NIST’s approval that use them. Where approval matters, take HMAC over SHA-2 or SHA-3.

Backend

The backend; by default default_backend of kdfs::kbkdf_hmac, which has none (design D34): the call names backends::openssl, which has every hmac of hmac.hpp but hmac_ripemd_128, or backends::botan, which has every one but hmac_ripemd_128 and hmac_sha2_512_224 and writes the separator and L always (unsupported_by_backend without either).

Parameters

Name Description

output_bytes

K_OUT, its size the length L: 1 byte up to (2^r - 1) digests, and, when algorithm_options.length, at most 536,870,911 bytes (L in bits fits its 32 bits). It must not overlap the inputs.

key_bytes

K_IN, the key-derivation key: at least 1 byte (backends::openssl: at most INT_MAX, HMAC’s key length in OpenSSL, unsupported_by_backend beyond).

algorithm_options

The label, the context, the counter’s width and which parts the fixed input holds.

webcpp::hash::mac

The tag of input_bytes under key_bytes, with the MAC Mac on Backend.

Synopsis

Declared in <webcpp/hash/mac.hpp>

template<
    class Mac,
    class Backend = default_backend<Mac>>
[[nodiscard]]
boost::system::result<void>
mac(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> key_bytes,
    std::span<uint8_t const> input_bytes,
    mac_options<Mac> const& algorithm_options = {});

Description

std::array<std::uint8_t, 32> tag{};
auto done = webcpp::hash::mac<webcpp::hash::macs::hmac<webcpp::hash::digests::sha2_256>>(
    tag, key, message);

Return Value

Success; or the first guard’s error (invalid_output_size, invalid_key_size, an option’s error, unsupported_by_backend), output_bytes untouched; or the backend’s failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Mac

A tag of macs, as macs::hmac<digests::sha2_256>.

Backend

The backend; by default default_backend of Mac (spec 4.1). A backend without the tag, or one the program does not link, refuses at compile time.

Parameters

Name Description

output_bytes

The tag: for HMAC, 10 bytes up to the digest’s size (a shorter tag is the digest cut, RFC 2104 section 5); for the others, the size their traits give.

key_bytes

The key.

input_bytes

The message, of any size.

algorithm_options

The MAC’s parameters (none for most tags).

webcpp::hash::make_error_code

Makes the error_code of an error, as its implicit conversion does.

Synopsis

Declared in <webcpp/hash/error.hpp>

boost::system::error_code
make_error_code(error error_value) noexcept;

Return Value

error_value as an error_code of the category category.

Parameters

Name Description

error_value

The error.

webcpp::hash::pbkdf2

PBKDF2 (RFC 8018, section 5.2): fills output_bytes from password_bytes and salt_bytes by iteration_count rounds of Hmac.

Synopsis

Declared in <webcpp/hash/pbkdf2.hpp>

template<
    class Hmac,
    class Backend = default_kdf_backend<Hmac, kdfs::pbkdf2>>
[[nodiscard]]
boost::system::result<void>
pbkdf2(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    uint64_t iteration_count);

Return Value

Success, or the error of the first guard that fails (invalid_output_size, invalid_iterations, then the backend’s own limits: invalid_output_size, invalid_iterations, input_too_long; for backends::openssl an output, a password or a salt of more than INT_MAX bytes), output_bytes untouched; or the backend’s failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Hmac

The pseudorandom function, as hmac_sha2_512.

Backend

The backend.

Parameters

Name Description

output_bytes

The derived key, 1 to (2^32 - 1) times the digest size.

password_bytes

The password, any bytes the backend takes.

salt_bytes

The salt, likewise.

iteration_count

The iteration count, at least 1.

webcpp::hash::scrypt

scrypt (RFC 7914): fills output_bytes from password_bytes and salt_bytes.

Synopsis

Declared in <webcpp/hash/scrypt.hpp>

template<class Backend = default_backend<kdfs::scrypt>>
[[nodiscard]]
boost::system::result<void>
scrypt(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> password_bytes,
    std::span<uint8_t const> salt_bytes,
    scrypt_parameters const& cost_parameters);

Description

Note

Each backend’s narrower limits are refused as the spec’s are: on backends::sodium an N above 2^32 - 1 (invalid_parameters); on backends::openssl an r p of 2^24 or more (invalid_parameters) and a password, salt or output of more than INT_MAX bytes. On backends::botan, a partial cell, an N above 2^22, an r above 256, a p above 1,024 or more than 8 GiB and 2 MiB of memory (2 GiB and 2 MiB on wasm32) are unsupported_by_backend.

Return Value

Success, or the error of the first guard that fails (invalid_output_size, invalid_parameters, input_too_long, unsupported_by_backend), output_bytes untouched; or errc::not_enough_memory when the 128 r N bytes cannot be allocated, or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Backend

The backend; by default default_backend of kdfs::scrypt (spec 4.1), backends::sodium; or backends::openssl or backends::botan, named.

Parameters

Name Description

output_bytes

The derived key, 1 to (2^32 - 1) times 32 bytes; it must not overlap password_bytes or salt_bytes.

password_bytes

The password.

salt_bytes

The salt.

cost_parameters

The costs.

webcpp::hash::sskdf

SP 800-56C’s one-step key derivation over the digest Digest (NIST SP 800-56C revision 2, section 4.1, with H a hash function): fills output_bytes from the shared secret secret_bytes and fixed_info, block after block, each Digest(counter || secret_bytes || fixed_info) with a 32-bit big-endian counter from 1.

Synopsis

template<
    class Digest,
    class Backend = default_backend<kdfs::sskdf>>
[[nodiscard]]
boost::system::result<void>
sskdf(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> secret_bytes,
    std::span<uint8_t const> fixed_info = {});

Description

std::array<std::uint8_t, 32> derived{};
auto done = webcpp::hash::sskdf<webcpp::hash::digests::sha2_256,
                                webcpp::hash::backends::openssl>(derived, shared_secret, info);

Return Value

Success; or the first guard’s error (invalid_output_size, invalid_key_size, input_too_long past what the digest hashes, unsupported_by_backend past the backend’s limits), output_bytes untouched; or errc::not_enough_memory or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Digest

An approved hash function: digests::sha1, a SHA-2 (sha2_224 to sha2_512_256) or a SHA-3 (sha3_224 to sha3_512); another refuses at compile time.

Backend

The backend; by default default_backend of kdfs::sskdf, which has none (design D34): the call names backends::openssl or backends::botan (every digest but SHA-512/224, which Botan lacks: refused at compile time).

Parameters

Name Description

output_bytes

The derived keying material: 1 byte to 2^32 - 1 digests (backends::openssl: at most 2^30 bytes). It must not overlap the inputs.

secret_bytes

Z, the shared secret: at least 1 byte (backends::openssl: at most 2^30).

fixed_info

FixedInfo, which binds the derived key to its parties and purpose; empty for none (backends::openssl: at most 2^30 bytes).

webcpp::hash::x963kdf

ANSI X9.63’s key derivation (ANSI X9.63-2011, section 5.6.3; SEC 1 v2, section 3.6.1) over the digest Digest: fills output_bytes from the shared secret secret_bytes and shared_info, block after block, each Digest(secret_bytes || counter || shared_info) with a 32-bit big-endian counter from 1.

Synopsis

template<
    class Digest,
    class Backend = default_backend<kdfs::x963kdf>>
[[nodiscard]]
boost::system::result<void>
x963kdf(
    std::span<uint8_t> output_bytes,
    std::span<uint8_t const> secret_bytes,
    std::span<uint8_t const> shared_info = {});

Description

ECIES and the elliptic-curve key agreements of SEC 1, BSI TR-03111 and smart cards use it.

std::array<std::uint8_t, 32> derived{};
auto done = webcpp::hash::x963kdf<webcpp::hash::digests::sha2_256,
                                  webcpp::hash::backends::openssl>(derived, shared_secret, info);

Return Value

Success; or the first guard’s error (invalid_output_size, invalid_key_size, input_too_long past what the digest hashes, unsupported_by_backend past the backend’s limits), output_bytes untouched; or errc::not_enough_memory or backend_failure, output_bytes zeroed.

Note

The return value should not be discarded.

Template Parameters

Name Description

Digest

A hash function SEC 1 v2 lists (section 3.5) and NIST SP 800-135r1 approves for this KDF (section 5.1): digests::sha1, sha2_224, sha2_256, sha2_384 or sha2_512; another, SHA-512/224 and SHA-512/256 included, refuses at compile time.

Backend

The backend; by default default_backend of kdfs::x963kdf, which has none (design D34): the call names backends::openssl or backends::botan.

Parameters

Name Description

output_bytes

The derived keying material: 1 byte to 2^32 - 1 digests less 1 byte (the standard refuses keydatalen >= hashlen (2^32 - 1); backends::openssl: at most 2^30 bytes). It must not overlap the inputs.

secret_bytes

Z, the shared secret: at least 1 byte (backends::openssl: at most 2^30).

shared_info

SharedInfo, the data both parties share; empty for none (backends::openssl: at most 2^30 bytes).

webcpp::hash::argon2id_interactive

libsodium’s interactive costs: 2 passes over 64 MiB.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

inline constexpr argon2id_parameters argon2id_interactive = {.passes = 2, .memory = 67108864};

webcpp::hash::argon2id_moderate

libsodium’s moderate costs: 3 passes over 256 MiB.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

inline constexpr argon2id_parameters argon2id_moderate = {.passes = 3, .memory = 268435456};

webcpp::hash::argon2id_salt_size

The salt’s size, 16 bytes.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

inline constexpr std::size_t argon2id_salt_size = 16;

webcpp::hash::argon2id_sensitive

libsodium’s sensitive costs: 4 passes over 1 GiB.

Synopsis

Declared in <webcpp/hash/argon2.hpp>

inline constexpr argon2id_parameters argon2id_sensitive = {.passes = 4, .memory = 1073741824};

webcpp::hash::backend_has_v

Whether Backend has the key derivation Kdf over Hmac, or the algorithm of a family’s tag: a property of the library behind it (spec sections 3.2 and 3.5), whether or not the program links it, backends::botan excepted.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<
    class Backend,
    class Kdf,
    class Hmac>
inline constexpr bool backend_has_v = false;

Description

A backend that has a tag only in part (a partial cell of doc/capabilities.json, as backends::hash2’s BLAKE2b, its 64-byte output alone) has it.

backends::botan’s cells are declared by <webcpp/hash/backends/botan.hpp>, which every header of the families includes when the program links Botan, and which declares nothing in a build without exceptions: for it the answer is false in a program that cannot have Botan.

Template Parameters

Name Description

Backend

A backend of backends.

Kdf

kdfs::hkdf, kdfs::pbkdf2 or another tag of kdfs; or a tag of digests or macs; or, for argon2, kdfs::argon2d, kdfs::argon2i or kdfs::argon2id.

Hmac

A Boost.Hash2 hmac for a key derivation over one (kdfs::kbkdf_hmac included); void for a function over none, sskdf and x963kdf (over a digest) among them, and for a family’s tag; argon2_parameters for the family argon2, whose tags kdfs::argon2id also names the function argon2id.

webcpp::hash::backend_has_v

backends::bearssl has digests::md5 (br_md5_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::md5_sha1 (br_md5sha1_*, TLS 1.0’s MD5 followed by SHA-1).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::sha1 (br_sha1_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::sha2_224 (br_sha224_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::sha2_256 (br_sha256_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::sha2_384 (br_sha384_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::sha2_512 (br_sha512_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::shake_128 (br_shake_*, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has digests::shake_256 (br_shake_*, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has macs::hmac<digests::md5> (br_hmac_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has macs::hmac<digests::sha1> (br_hmac_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has macs::hmac<digests::sha2_224> (br_hmac_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has macs::hmac<digests::sha2_256> (br_hmac_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has macs::hmac<digests::sha2_384> (br_hmac_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has macs::hmac<digests::sha2_512> (br_hmac_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::blake3 has digests::blake3 (BLAKE3’s C implementation), with its extendable output.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has Argon2d ("Argon2d"), in part: at most 128 lanes and 8 GiB (2 on wasm32).

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has Argon2i ("Argon2i"), in part, as Argon2d.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has Argon2id ("Argon2id"), in part, as Argon2d.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has the function argon2id (Botan 3.14.1’s PasswordHashFamily "Argon2id").

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has bcrypt (generate_bcrypt, check_bcrypt), in part: a cost up to 18.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has bcrypt_pbkdf ("Bcrypt-PBKDF").

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::blake2b, in part: no salt, no personalisation.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::blake2b_mac.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::blake2s_256.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::keccak_224.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::keccak_256.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::keccak_384.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::keccak_512.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::kmac_128, in part: a key of at most 192 bytes, no KMACXOF.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::kmac_256, in part: a key of at most 192 bytes, no KMACXOF.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::md5 (Botan 3.14.1’s HashFunction).

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::ripemd_160.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has scrypt ("Scrypt"), in part: N of at most 2^22, r 256, p 1,024, 8 GiB.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha1.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha2_224.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha2_256.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha2_384.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha2_512.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha2_512_256.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha3_224.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha3_256.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha3_384.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sha3_512.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::shake_128 (Botan 3.14.1’s XOF), any output size.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::shake_256 (Botan 3.14.1’s XOF), any output size.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::siphash_2_4.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::skein_512.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::sm3.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has sskdf ("SP800-56A(<h>)"), over SP 800-56C’s digests but SHA-512/224.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::streebog_256.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::streebog_512.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has digests::whirlpool.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has x963kdf ("KDF2(<h>)"), in part: at most 2^32 - 2 blocks.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::blake2b>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::blake2s_256>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::keccak_224>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::keccak_256>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::keccak_384>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::keccak_512>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::md5> (Botan 3.14.1’s MessageAuthenticationCode).

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::ripemd_160>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha1>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha2_224>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha2_256>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha2_384>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha2_512>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha2_512_256>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha3_224>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha3_256>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha3_384>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sha3_512>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::skein_512>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::sm3>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::streebog_256>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::streebog_512>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::botan has macs::hmac<digests::whirlpool>.

Synopsis

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::blake2b in part: a 64-byte output with no options, Boost.Hash2’s blake2b_512 (ruling R82).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::blake2s_256 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::blake2s_mac in part: a 32-byte tag, Boost.Hash2’s keyed blake2s_256 (ruling R82).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::md5 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::ripemd_160 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha1 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha2_224 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha2_256 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha2_384 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha2_512 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha2_512_224 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha2_512_256 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha3_224 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha3_256 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha3_384 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::sha3_512 (Boost.Hash2’s type).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::shake_128 whole: Boost.Hash2’s shake_128, whose every result() gives the next block of the stream.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has digests::shake_256 whole: Boost.Hash2’s shake_256, whose every result() gives the next block of the stream.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::siphash_2_4 (Boost.Hash2’s siphash_64).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::blake2b> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::blake2s_256> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::md5> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::ripemd_160> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha1> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha2_224> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha2_256> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha2_384> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha2_512> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha2_512_224> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha2_512_256> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha3_224> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha3_256> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha3_384> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::hash2 has macs::hmac<digests::sha3_512> (Boost.Hash2’s hmac<H>).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has Argon2d with every parameter (OpenSSL 3.5.9’s EVP_KDF "ARGON2D").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has Argon2i with every parameter (OpenSSL 3.5.9’s EVP_KDF "ARGON2I").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has Argon2id with every parameter (OpenSSL 3.5.9’s EVP_KDF "ARGON2ID").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has the function argon2id (OpenSSL 3.5.9’s EVP_KDF "ARGON2ID").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::blake2b in part: unkeyed, every output size from 1 to 64 bytes (OpenSSL’s "BLAKE2B-512" with its "size"); no key, salt or personalisation.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::blake2b_mac (OpenSSL 3.5.9’s EVP_MAC "BLAKE2BMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::blake2s_256 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::blake2s_mac (OpenSSL 3.5.9’s EVP_MAC "BLAKE2SMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::keccak_224 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::keccak_256 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::keccak_384 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::keccak_512 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::kmac_128 (OpenSSL 3.5.9’s EVP_MAC "KMAC-128").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::kmac_256 (OpenSSL 3.5.9’s EVP_MAC "KMAC-256").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::md5 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::md5_sha1 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::ripemd_160 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has scrypt (OpenSSL 3.5.9’s EVP_KDF "SCRYPT").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha1 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha2_224 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha2_256 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha2_384 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha2_512 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha2_512_224 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha2_512_256 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha3_224 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha3_256 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha3_384 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sha3_512 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::shake_128 (OpenSSL 3.5.9’s EVP_MD, EVP_DigestFinalXOF), with any output size.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::shake_256 (OpenSSL 3.5.9’s EVP_MD, EVP_DigestFinalXOF), with any output size.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::siphash_2_4 (OpenSSL 3.5.9’s EVP_MAC "SIPHASH").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::siphash_2_4x (OpenSSL 3.5.9’s EVP_MAC "SIPHASH").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has digests::sm3 (OpenSSL 3.5.9’s EVP_MD).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has SP 800-56C’s one-step KDF over a digest (OpenSSL 3.5.9’s EVP_KDF "SSKDF"), the function sskdf, which takes a digest, not an hmac.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has ANSI X9.63’s KDF (OpenSSL 3.5.9’s EVP_KDF "X963KDF"), the function x963kdf, which takes a digest, not an hmac.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::blake2b> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::blake2s_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::keccak_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::keccak_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::keccak_384> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::keccak_512> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::md5> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::ripemd_160> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha1> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha2_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha2_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha2_384> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha2_512> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha2_512_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha2_512_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha3_224> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha3_256> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha3_384> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sha3_512> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::openssl has macs::hmac<digests::sm3> (OpenSSL 3.5.9’s EVP_MAC "HMAC").

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has Argon2i for argon2 (crypto_pwhash_argon2i), in part: one lane, no secret, no associated data, a 16-byte salt, a tag of 16 bytes or more and at least 3 passes.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has Argon2id for argon2 (crypto_pwhash_argon2id), in part: one lane, no secret, no associated data, a 16-byte salt and a tag of 16 bytes or more.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has Argon2id (crypto_pwhash_argon2id), which takes no hmac.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::blake2b (crypto_generichash_blake2b_*), with its key, salt, personalisation and every output size.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has macs::blake2b_mac (keyed crypto_generichash_blake2b_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has BLAKE2b subkeys (crypto_kdf_blake2b_derive_from_key), the function blake2b_subkey, which takes no hmac.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has HKDF over HMAC-SHA-256 (crypto_kdf_hkdf_sha256_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has HKDF over HMAC-SHA-512 (crypto_kdf_hkdf_sha512_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has scrypt (crypto_pwhash_scryptsalsa208sha256_ll), which takes no hmac.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::sha2_256 (crypto_hash_sha256_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::sha2_512 (crypto_hash_sha512_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::sha3_256 (crypto_hash_sha3256_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::sha3_512 (crypto_hash_sha3512_*).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::shake_128 (crypto_xof_shake128_*), with its extendable output.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::shake_256 (crypto_xof_shake256_*), with its extendable output.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has macs::siphash_2_4 (crypto_shorthash_siphash24).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has macs::siphash_2_4x (crypto_shorthash_siphashx24).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::turboshake_128 (crypto_xof_turboshake128_*), with its domain byte.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has digests::turboshake_256 (crypto_xof_turboshake256_*), with its domain byte.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has macs::hmac<digests::sha2_256> (crypto_auth_hmacsha256_*), with a key of any size.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::sodium has macs::hmac<digests::sha2_512> (crypto_auth_hmacsha512_*), with a key of any size.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::cshake_128 (XKCP’s SP 800-185 cSHAKE128, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::cshake_256 (XKCP’s SP 800-185 cSHAKE256, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::keccak_224 (XKCP’s FIPS 202’s Keccak_Hash with Keccak’s padding).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::keccak_256 (webcpp’s keccak_256 over XKCP).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::keccak_384 (XKCP’s FIPS 202’s Keccak_Hash with Keccak’s padding).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::keccak_512 (XKCP’s FIPS 202’s Keccak_Hash with Keccak’s padding).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has macs::kmac_128 (XKCP’s SP 800-185 KMAC128, both forms).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has macs::kmac_256 (XKCP’s SP 800-185 KMAC256, both forms).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::kt128 (XKCP’s KangarooTwelve at 128 bits, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::kt256 (XKCP’s KangarooTwelve at 256 bits, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::parallelhash_128 (XKCP’s SP 800-185 ParallelHash128, both forms; a block size that is a power of two of at least 8 bytes).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::parallelhash_256 (XKCP’s SP 800-185 ParallelHash256, both forms; a block size that is a power of two of at least 8 bytes).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::sha3_224 (XKCP’s FIPS 202’s Keccak_Hash).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::sha3_256 (XKCP’s FIPS 202’s Keccak_Hash).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::sha3_384 (XKCP’s FIPS 202’s Keccak_Hash).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::sha3_512 (XKCP’s FIPS 202’s Keccak_Hash).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::shake_128 (XKCP’s FIPS 202’s Keccak_Hash, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::shake_256 (XKCP’s FIPS 202’s Keccak_Hash, any output size).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::tuplehash_128 (XKCP’s SP 800-185 TupleHash128, both forms).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::tuplehash_256 (XKCP’s SP 800-185 TupleHash256, both forms).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::turboshake_128 (XKCP’s TurboSHAKE, any output size and D).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::xkcp has digests::turboshake_256 (XKCP’s TurboSHAKE, any output size and D).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<>
inline constexpr bool backend_has_v = true;

webcpp::hash::backend_has_v

backends::bearssl has hkdf (not its two steps alone) over MD5, SHA-1 and four SHA-2s.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::bearssl_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::bearssl has HKDF-Expand over pieces wherever it has HKDF over pieces: its HMAC keyed by the pseudorandom key, while the single-buffer hkdf_expand stays refused.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::bearssl, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::bearssl has HKDF-Extract over pieces wherever it has HKDF over pieces: its HMAC keyed by the salt, while the single-buffer hkdf_extract stays refused (br_hkdf_* keeps the pseudorandom key inside its context).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::bearssl, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::bearssl has HKDF over pieces over its six hmacs, those of its HMAC cells, over br_hmac_key_init, br_hmac_init, br_hmac_update and br_hmac_out.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::bearssl_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::botan has HKDF ("HKDF(HMAC(<h>))") over the hmacs of detail::botan_hmac_v.

Synopsis

template<class Hmac>
inline constexpr bool backend_has_v = detail::botan_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::botan has HKDF-Expand over pieces wherever it has HKDF over pieces.

Synopsis

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::botan, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::botan has HKDF-Extract over pieces wherever it has HKDF over pieces.

Synopsis

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::botan, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::botan has HKDF over pieces over the hmacs of detail::botan_hmac_v, those of its HMAC cells it has HKDF over, on its MessageAuthenticationCode "HMAC(<h>)" (its KDF "HKDF" takes the input keying material and the info whole, and is not used).

Synopsis

template<class Hmac>
inline constexpr bool backend_has_v = detail::botan_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::botan has KBKDF ("SP800-108-Counter(HMAC(<h>),<r>,32)") over the hmacs of detail::botan_hmac_v, in part: with the separator and L.

Synopsis

template<class Hmac>
inline constexpr bool backend_has_v = detail::botan_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::botan has PBKDF2 ("PBKDF2(HMAC(<h>))") over the hmacs of detail::botan_hmac_v, in part: at most 2^32 - 2 blocks of output, and on wasm32 at most 2^32 - 1 iterations.

Synopsis

template<class Hmac>
inline constexpr bool backend_has_v = detail::botan_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::hash2 has HKDF over every Boost.Hash2 hmac whose result is a digest.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::is_digest_hmac<Hmac>::value;

webcpp::hash::backend_has_v

backends::hash2 has HKDF-Expand over pieces wherever it has HKDF over pieces.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::hash2, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::hash2 has HKDF-Extract over pieces wherever it has HKDF over pieces.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::hash2, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::hash2 has HKDF over pieces over every hmac it has HKDF over: Boost.Hash2’s hmac<H>, whose update each piece is fed to (design D4 of the change hkdf-pieces: a backend has the pieces forms exactly where it has the HMAC).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::hash2, kdfs::hkdf, Hmac>;

webcpp::hash::backend_has_v

backends::hash2 has PBKDF2 over every Boost.Hash2 hmac whose result is a digest.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::is_digest_hmac<Hmac>::value;

webcpp::hash::backend_has_v

backends::openssl has HKDF over every alias of hmac.hpp but hmac_ripemd_128.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::openssl_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::openssl has HKDF-Expand over pieces wherever it has HKDF over pieces.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::openssl, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::openssl has HKDF-Extract over pieces wherever it has HKDF over pieces.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::openssl, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::openssl has HKDF over pieces over the hmacs of its HMAC cells, those it has HKDF over (every alias of hmac.hpp but hmac_ripemd_128), over EVP_MAC "HMAC" (OpenSSL’s EVP_KDF "HKDF" takes the input keying material and the info whole, and is not used).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::openssl_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::openssl has SP 800-108’s KBKDF in counter mode (OpenSSL 3.5.9’s EVP_KDF "KBKDF") over every alias of hmac.hpp but hmac_ripemd_128.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::openssl_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::openssl has PBKDF2 over every alias of hmac.hpp but hmac_ripemd_128.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = detail::openssl_hmac_v<Hmac>;

webcpp::hash::backend_has_v

backends::sodium has HKDF-Expand over pieces wherever it has HKDF over pieces.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::sodium, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::sodium has HKDF-Extract over pieces wherever it has HKDF over pieces.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::sodium, kdfs::hkdf_pieces, Hmac>;

webcpp::hash::backend_has_v

backends::sodium has HKDF over pieces over the hmacs of its HMAC cells, those it has HKDF over: hmac_sha2_256 and hmac_sha2_512, over crypto_auth_hmacsha256_* and crypto_auth_hmacsha512_* (libsodium’s own HKDF takes Expand’s info whole, and is not used).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<class Hmac>
inline constexpr bool backend_has_v = backend_has_v<backends::sodium, kdfs::hkdf, Hmac>;

webcpp::hash::backend_has_v

HKDF-Expand alone: as HKDF-Extract, every backend with HKDF but backends::bearssl.

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<
    class Backend,
    class Hmac>
inline constexpr bool backend_has_v = backend_has_v<Backend, kdfs::hkdf, Hmac> && !std::is_same_v<Backend, backends::bearssl>;

webcpp::hash::backend_has_v

HKDF-Extract alone: every backend that has HKDF over Hmac but backends::bearssl, whose br_hkdf_* keeps the pseudorandom key inside its context (spec 3.2).

Synopsis

Declared in <webcpp/hash/kdf.hpp>

template<
    class Backend,
    class Hmac>
inline constexpr bool backend_has_v = backend_has_v<Backend, kdfs::hkdf, Hmac> && !std::is_same_v<Backend, backends::bearssl>;

webcpp::hash::bcrypt_hash_size

bcrypt’s string, 60 characters: "\$2b\$", the cost in two digits, "$", 22 of salt, 31 of hash.

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

inline constexpr std::size_t bcrypt_hash_size = 60;

webcpp::hash::bcrypt_max_password_size

The longest password bcrypt reads, 72 bytes.

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

inline constexpr std::size_t bcrypt_max_password_size = 72;

webcpp::hash::bcrypt_salt_size

bcrypt’s salt, 16 bytes (128 bits).

Synopsis

Declared in <webcpp/hash/bcrypt.hpp>

inline constexpr std::size_t bcrypt_salt_size = 16;

webcpp::hash::blake2b_subkey_context_size

The size of blake2b_subkey’s context, in bytes (libsodium’s crypto_kdf_CONTEXTBYTES).

Synopsis

inline constexpr std::size_t blake2b_subkey_context_size = 8;

webcpp::hash::blake2b_subkey_key_size

The size of blake2b_subkey’s master key, in bytes (libsodium’s crypto_kdf_KEYBYTES).

Synopsis

inline constexpr std::size_t blake2b_subkey_key_size = 32;

webcpp::hash::blake2b_subkey_max_size

The longest subkey blake2b_subkey derives, in bytes (libsodium’s crypto_kdf_BYTES_MAX).

Synopsis

inline constexpr std::size_t blake2b_subkey_max_size = 64;

webcpp::hash::blake2b_subkey_min_size

The shortest subkey blake2b_subkey derives, in bytes (libsodium’s crypto_kdf_BYTES_MIN).

Synopsis

inline constexpr std::size_t blake2b_subkey_min_size = 16;

webcpp::hash::hkdf_max_application_info_size

The longest application info every backend accepts, 32,768 bytes (OpenSSL 3.5’s limit).

Synopsis

Declared in <webcpp/hash/hkdf.hpp>

inline constexpr std::size_t hkdf_max_application_info_size = 32768;

webcpp::hash::blake2b_512

BLAKE2b with a 512-bit digest, RFC 7693.

Synopsis

using boost::hash2::blake2b_512;

webcpp::hash::blake2s_256

BLAKE2s with a 256-bit digest, RFC 7693.

Synopsis

using boost::hash2::blake2s_256;

webcpp::hash::fnv1a_32

FNV-1a with a 32-bit result, the Fowler-Noll-Vo hash (IETF draft-eastlake-fnv).

Synopsis

using boost::hash2::fnv1a_32;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

webcpp::hash::fnv1a_64

FNV-1a with a 64-bit result, the Fowler-Noll-Vo hash (IETF draft-eastlake-fnv).

Synopsis

using boost::hash2::fnv1a_64;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

webcpp::hash::get_integral_result

Boost.Hash2’s get_integral_result: converts a result to an integer type.

Synopsis

using boost::hash2::get_integral_result;

webcpp::hash::hash_append

Boost.Hash2’s hash_append: feeds a value to a hash algorithm.

Synopsis

using boost::hash2::hash_append;

webcpp::hash::hash_append_range

Boost.Hash2’s hash_append_range: feeds a range to a hash algorithm.

Synopsis

using boost::hash2::hash_append_range;

webcpp::hash::hash_append_range_and_size

Boost.Hash2’s hash_append_range_and_size: feeds a range and then its size.

Synopsis

using boost::hash2::hash_append_range_and_size;

webcpp::hash::hash_append_size

Boost.Hash2’s hash_append_size: feeds a size.

Synopsis

using boost::hash2::hash_append_size;

webcpp::hash::hash_append_unordered_range

Boost.Hash2’s hash_append_unordered_range: feeds an unordered range, order-independently.

Synopsis

using boost::hash2::hash_append_unordered_range;

webcpp::hash::hmac_blake2b_512

HMAC, RFC 2104, over BLAKE2b.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_blake2b_512;

webcpp::hash::hmac_blake2s_256

HMAC, RFC 2104, over BLAKE2s.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_blake2s_256;

webcpp::hash::hmac_md5_128

HMAC, RFC 2104, over MD5 (legacy, not for new designs).

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_md5_128;

webcpp::hash::hmac_ripemd_128

HMAC, RFC 2104, over RIPEMD-128.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_ripemd_128;

webcpp::hash::hmac_ripemd_160

HMAC, RFC 2104, over RIPEMD-160.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_ripemd_160;

webcpp::hash::hmac_sha1_160

HMAC, RFC 2104, over SHA-1 (legacy, not for new designs).

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha1_160;

webcpp::hash::hmac_sha2_224

HMAC, RFC 2104, over SHA-224.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha2_224;

webcpp::hash::hmac_sha2_256

HMAC, RFC 2104, over SHA-256.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha2_256;

webcpp::hash::hmac_sha2_384

HMAC, RFC 2104, over SHA-384.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha2_384;

webcpp::hash::hmac_sha2_512

HMAC, RFC 2104, over SHA-512.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha2_512;

webcpp::hash::hmac_sha2_512_224

HMAC, RFC 2104, over SHA-512/224.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha2_512_224;

webcpp::hash::hmac_sha2_512_256

HMAC, RFC 2104, over SHA-512/256.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha2_512_256;

webcpp::hash::hmac_sha3_224

HMAC, RFC 2104, over SHA3-224.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha3_224;

webcpp::hash::hmac_sha3_256

HMAC, RFC 2104, over SHA3-256.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha3_256;

webcpp::hash::hmac_sha3_384

HMAC, RFC 2104, over SHA3-384.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha3_384;

webcpp::hash::hmac_sha3_512

HMAC, RFC 2104, over SHA3-512.

Synopsis

Declared in <webcpp/hash/hmac.hpp>

using boost::hash2::hmac_sha3_512;

webcpp::hash::md5_128

MD5, RFC 1321, a 128-bit digest.

Synopsis

using boost::hash2::md5_128;

Description

Broken: not for security, kept for compatibility with existing data and protocols.

webcpp::hash::murmur3_128

MurmurHash3 x64_128, Austin Appleby’s hash.

Synopsis

using boost::hash2::murmur3_128;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

webcpp::hash::murmur3_32

MurmurHash3 x86_32, Austin Appleby’s hash.

Synopsis

using boost::hash2::murmur3_32;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

webcpp::hash::ripemd_128

RIPEMD-128, ISO/IEC 10118-3, a 128-bit digest.

Synopsis

using boost::hash2::ripemd_128;

Description

Legacy: not for security.

webcpp::hash::ripemd_160

RIPEMD-160, ISO/IEC 10118-3, a 160-bit digest.

Synopsis

using boost::hash2::ripemd_160;

Description

Legacy: prefer SHA-2 or SHA-3 in new designs.

webcpp::hash::sha1_160

SHA-1, FIPS 180-4, a 160-bit digest.

Synopsis

using boost::hash2::sha1_160;

Description

Broken: not for security, kept for compatibility with existing data and protocols.

webcpp::hash::sha2_224

SHA-224, FIPS 180-4, a 224-bit digest.

Synopsis

using boost::hash2::sha2_224;

webcpp::hash::sha2_256

SHA-256, FIPS 180-4, a 256-bit digest.

Synopsis

using boost::hash2::sha2_256;

webcpp::hash::sha2_384

SHA-384, FIPS 180-4, a 384-bit digest.

Synopsis

using boost::hash2::sha2_384;

webcpp::hash::sha2_512

SHA-512, FIPS 180-4, a 512-bit digest.

Synopsis

using boost::hash2::sha2_512;

webcpp::hash::sha2_512_224

SHA-512/224, FIPS 180-4, a 224-bit digest.

Synopsis

using boost::hash2::sha2_512_224;

webcpp::hash::sha2_512_256

SHA-512/256, FIPS 180-4, a 256-bit digest.

Synopsis

using boost::hash2::sha2_512_256;

webcpp::hash::sha3_224

SHA3-224, FIPS 202, a 224-bit digest.

Synopsis

using boost::hash2::sha3_224;

webcpp::hash::sha3_256

SHA3-256, FIPS 202, a 256-bit digest.

Synopsis

using boost::hash2::sha3_256;

webcpp::hash::sha3_384

SHA3-384, FIPS 202, a 384-bit digest.

Synopsis

using boost::hash2::sha3_384;

webcpp::hash::sha3_512

SHA3-512, FIPS 202, a 512-bit digest.

Synopsis

using boost::hash2::sha3_512;

webcpp::hash::shake_128

SHAKE128, FIPS 202, an extendable-output function with a 128-bit security strength.

Synopsis

using boost::hash2::shake_128;

webcpp::hash::shake_256

SHAKE256, FIPS 202, an extendable-output function with a 256-bit security strength.

Synopsis

using boost::hash2::shake_256;

webcpp::hash::siphash_32

HalfSipHash-2-4, Aumasson’s 32-bit variant of SipHash with an 8-byte key and a 32-bit result, as Boost.Hash2 defines it (not SipHash-2-4 truncated).

Synopsis

using boost::hash2::siphash_32;

Description

A keyed function for hash tables against flooding on 32-bit targets, not a general-purpose MAC or a digest.

webcpp::hash::siphash_64

SipHash-2-4 with a 64-bit result, Aumasson and Bernstein’s keyed hash.

Synopsis

using boost::hash2::siphash_64;

Description

A keyed function for hash tables against flooding, not a general-purpose MAC or a digest.

webcpp::hash::spooky2_128

SpookyHash V2 with a 128-bit result, Bob Jenkins’ hash.

Synopsis

using boost::hash2::spooky2_128;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

webcpp::hash::xxh3_128

XXH3 with a 128-bit result, Yann Collet’s hash.

Synopsis

using boost::hash2::xxh3_128;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

webcpp::hash::xxhash_32

xxHash32, Yann Collet’s 32-bit hash.

Synopsis

using boost::hash2::xxhash_32;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

webcpp::hash::xxhash_64

XXH64, Yann Collet’s 64-bit hash.

Synopsis

using boost::hash2::xxhash_64;

Description

Not cryptographic: for hash tables, checksums and identifiers, never for security.

WEBCPP_HASH_HAS_BEARSSL

Defined by /third_party//bearssl when the program links BearSSL; a program built without b2 defines it to 1 itself.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_HAS_BEARSSL

WEBCPP_HASH_HAS_BLAKE3

Defined by /third_party//blake3 when the program links the BLAKE3 C implementation; a program built without b2 defines it to 1 itself.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_HAS_BLAKE3

WEBCPP_HASH_HAS_BOTAN

Defined by /third_party//botan when the program links Botan; a program built without b2 defines it to 1 itself. Botan reports its errors by throwing: in a build without exceptions (WEBCPP_HASH_NO_EXCEPTIONS) backends/botan.hpp declares nothing, and a call on backends::botan stops at compile time. /third_party//botan is built natively and for Emscripten.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_HAS_BOTAN

WEBCPP_HASH_HAS_OPENSSL

Defined by /webcpp/hash//openssl when the program links OpenSSL; a program built without b2 defines it to 1 itself. Refused on Emscripten, where OpenSSL is not built.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_HAS_OPENSSL

WEBCPP_HASH_HAS_SODIUM

Defined by /third_party//sodium when the program links libsodium; a program built without b2 defines it to 1 itself.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_HAS_SODIUM

WEBCPP_HASH_HAS_THREADS

Defined where the heavy functions of <webcpp/hash/async.hpp> (async_argon2id, async_argon2, async_scrypt, async_pbkdf2 on a synchronous backend) run on another thread: natively, where Boost.Config’s BOOST_HAS_THREADS is defined (every native build, b2’s threading=single included), and on Emscripten built with -pthread (b2’s threading=multi); never on wasip2 or wasip3, whose cooperative threads do not run in parallel. Without it each of those names refuses at compile time.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_HAS_THREADS

See Also

"Asynchronous calls", in the guide.

WEBCPP_HASH_HAS_XKCP

Defined by /third_party//xkcp when the program links XKCP; a program built without b2 defines it to 1 itself.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_HAS_XKCP

WEBCPP_HASH_LIFETIMEBOUND

The attribute that says a parameter’s object must outlive the object a constructor makes from it: [[clang::lifetimebound]] under clang, [[msvc::lifetimebound]] under MSVC where it has it, nothing elsewhere. byte_pieces’ constructors carry it, so that a byte_pieces named from a braced list, whose array dies at the end of its declaration, is a warning where the compiler can tell.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_LIFETIMEBOUND

WEBCPP_HASH_NO_EXCEPTIONS

Defined when webcpp::hash is built without exceptions: when webcpp has none (the compiler has none, or the developer defined WEBCPP_NO_EXCEPTIONS for every webcpp library), or when the developer defines it alone.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_NO_EXCEPTIONS

Description

webcpp::hash raises no exception of its own: every operation that can fail reports it as a value, whether or not the macro is defined.

See Also

"Exceptions", in the guide.

WEBCPP_HASH_NO_THREADS

Defined by the developer to leave WEBCPP_HASH_HAS_THREADS undefined in a build that has threads: the heavy functions of <webcpp/hash/async.hpp> then refuse at compile time, so that no call of the program can start a thread’s work.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_NO_THREADS

WEBCPP_HASH_WEBASSEMBLY

Defined on the WebAssembly targets, wasip2, wasip3 and Emscripten.

Synopsis

Declared in <webcpp/hash/config.hpp>

#define WEBCPP_HASH_WEBASSEMBLY

Appendix A: Changelog

What changed in hash in each version of webcpp, newest first, one line per change. "Unreleased" is what the next version brings. The release notes of every version are on webcpp’s index page.

Unreleased

  • Breaking change: Changed the public names: hkdf’s input_key_material, pseudorandom_key, application_info, output_key_material and salt, hkdf_max_application_info_size, scrypt_parameters’ cost, block_size and parallelism (from n, r, p) and argon2_parameters::memory_kibibytes.

  • Breaking change: Changed HKDF’s overloads: hkdf(out, {}, {}, {}), async_hkdf(ex, out, salt, {}, {}, token) and {vec} inputs are ambiguous; pass the vector itself, an empty span or byte_pieces{...}.

  • Added the library: Boost.Hash2’s algorithms and HMAC under webcpp::hash’s names, keccak_256 (Ethereum’s), blake3 (keyed, key derivation, extendable output), hash::formats::base58_with_checksum (Base58Check over codecs), every result [[nodiscard]].

  • Added HKDF (RFC 5869) and PBKDF2 (RFC 8018) on hash2, argon2id (RFC 9106), scrypt and Argon2i/Argon2id on sodium; keyed calls hold webcpp::secure’s timing guard (DIT on arm64 Apple, Linux, Windows).

  • Added HKDF over byte pieces (hkdf_extract, hkdf_expand, hkdf and their async forms), with no cap; on the synchronous backends hash makes no buffer, heap or copy of the inputs.

  • Added backends::openssl (OpenSSL 3.5.9; native, wasip2, wasip3) and backends::botan (Botan 3.14.1, with exceptions), named in the call: their digests, MACs, key derivations and, on Botan, bcrypt.

  • Added backends::sodium (HKDF, BLAKE2b with its options, keyed BLAKE2b, SipHash, blake2b_subkey, SHA-2, SHA-3, SHAKE, TurboSHAKE, HMAC) and backends::bearssl (HKDF, MD5, SHA-1, SHA-2, MD5-SHA1, SHAKE, HMAC).

  • Added async.hpp, async_digest, async_hmac, async_hkdf_extract, async_hkdf_expand, async_hkdf, async_pbkdf2, async_argon2id, async_argon2 and async_scrypt over webcpp::asio, and backends::webcrypto, the browser’s WebCrypto, for them on Emscripten.

  • Added each function’s default backend, the first of hash2, xkcp, blake3 and sodium that has it; the guide, doc/capabilities.json, measurements, allocation tests and a keccak_224-512 proposal to Boost.Hash2.

  • Added the families digest_of, hasher, mac and argon2 over digests, macs and kdfs tags on hash2, xkcp (Keccak, SHA-3, SHAKE, SP 800-185, KangarooTwelve, TurboSHAKE), blake3 and sodium, and error::invalid_state.