From 3c9505a78305856a1c8664bf92f235cb3cc69c63 Mon Sep 17 00:00:00 2001 From: R Date: Mon, 16 Nov 2026 18:05:07 -0300 Subject: [PATCH] hash: every key derivation defaults to backends::hash2, and no measurement or define decides a default The owner's decisions of 2026-11-16. default_backend and default_kdf_backend answer backends::hash2 for hkdf, hkdf_extract, hkdf_expand and pbkdf2 on every target and link set, and backends::sodium for argon2id and scrypt, their only backend; BearSSL, OpenSSL and libsodium's HKDF are reached only by naming them in the type. The profiles, the umbrella profile's reading, the per-algorithm overrides with detail/overrides.hpp, detail/ranking.hpp and the measure lane (test/measure) are removed, with their tests and messages; a former define has no effect (default_backend_former_defines). argon2id and scrypt on the default without libsodium stop with sodium.hpp's own instruction. doc/capabilities.json names each function's default (layout 3); doc/measurements.* stay as a reference measured on 2026-11-16 that decides nothing; the guide's chapter on the profile becomes the chapter on the default backend; bench's correctness program runs in every lane. --- README.md | 11 +- bench/Jamfile | 6 +- doc/backends.adoc | 29 +- doc/capabilities.json | 94 ++- doc/changelog.adoc | 6 +- doc/choosing_backend.adoc | 115 +++ doc/generated/backends-argon2id.adoc | 34 +- doc/generated/backends-blake2.adoc | 4 +- doc/generated/backends-blake3.adoc | 4 +- doc/generated/backends-hkdf.adoc | 94 +-- doc/generated/backends-hmac.adoc | 4 +- doc/generated/backends-keccak-256.adoc | 4 +- doc/generated/backends-md5-sha1-sha2.adoc | 4 +- doc/generated/backends-non-cryptographic.adoc | 4 +- doc/generated/backends-pbkdf2.adoc | 34 +- doc/generated/backends-ripemd.adoc | 4 +- doc/generated/backends-scrypt.adoc | 34 +- doc/generated/backends-sha3-shake.adoc | 4 +- doc/generated/backends-siphash.adoc | 4 +- doc/generated/choose.adoc | 10 +- doc/generated/compare-digests.adoc | 2 +- doc/generated/compare-kdfs.adoc | 2 +- doc/generated/compare-macs.adoc | 2 +- doc/generated/compare-non-cryptographic.adoc | 2 +- doc/generated/compare-password-hashing.adoc | 2 +- doc/guide.json | 38 +- doc/hash.adoc | 2 +- doc/jamfile.adoc | 4 +- doc/kdfs.adoc | 14 +- doc/llms.txt | 9 +- doc/measurements.adoc | 636 +---------------- doc/measurements.json | 10 +- doc/password_hashing.adoc | 2 +- doc/profile.adoc | 136 ---- include/webcpp/hash/argon2.hpp | 8 +- include/webcpp/hash/config.hpp | 230 +----- include/webcpp/hash/detail/engines.hpp | 16 +- include/webcpp/hash/detail/overrides.hpp | 248 ------- include/webcpp/hash/detail/ranking.hpp | 672 ------------------ include/webcpp/hash/hkdf.hpp | 15 +- include/webcpp/hash/kdf.hpp | 170 +---- include/webcpp/hash/pbkdf2.hpp | 11 +- include/webcpp/hash/scrypt.hpp | 8 +- meta/include-boundaries.json | 2 - test/Jamfile | 65 +- test/argon2id_test.cpp | 4 +- test/capabilities_test.cpp | 41 +- test/default_backend_test.cpp | 74 +- test/default_fastest_test.cpp | 31 - test/default_named_test.cpp | 54 -- test/default_override_test.cpp | 39 - test/default_portable_test.cpp | 38 - test/default_smallest_test.cpp | 31 - test/default_umbrella_test.cpp | 72 -- test/hkdf_openssl_test.cpp | 15 +- test/hkdf_sodium_test.cpp | 15 +- test/measure/Jamfile | 220 ------ test/measure/argon2id_sodium.cpp | 27 - test/measure/blake2b_512_hash2.cpp | 17 - test/measure/blake2s_256_hash2.cpp | 17 - test/measure/blake3_blake3.cpp | 17 - test/measure/cells.jam | 157 ---- test/measure/fnv1a_32_hash2.cpp | 17 - test/measure/fnv1a_64_hash2.cpp | 17 - test/measure/hkdf_bearssl.cpp | 26 - test/measure/hkdf_expand_hash2.cpp | 29 - test/measure/hkdf_expand_openssl.cpp | 28 - test/measure/hkdf_expand_sodium.cpp | 28 - test/measure/hkdf_extract_hash2.cpp | 23 - test/measure/hkdf_extract_openssl.cpp | 22 - test/measure/hkdf_extract_sodium.cpp | 22 - test/measure/hkdf_hash2.cpp | 26 - test/measure/hkdf_openssl.cpp | 26 - test/measure/hkdf_sodium.cpp | 26 - test/measure/hmac_blake2b_512_hash2.cpp | 18 - test/measure/hmac_blake2s_256_hash2.cpp | 18 - test/measure/hmac_hash2.cpp | 20 - test/measure/hmac_md5_128_hash2.cpp | 18 - test/measure/hmac_ripemd_128_hash2.cpp | 18 - test/measure/hmac_ripemd_160_hash2.cpp | 18 - test/measure/hmac_sha1_160_hash2.cpp | 18 - test/measure/hmac_sha2_224_hash2.cpp | 18 - test/measure/hmac_sha2_256_hash2.cpp | 18 - test/measure/hmac_sha2_384_hash2.cpp | 18 - test/measure/hmac_sha2_512_224_hash2.cpp | 18 - test/measure/hmac_sha2_512_256_hash2.cpp | 18 - test/measure/hmac_sha2_512_hash2.cpp | 18 - test/measure/hmac_sha3_224_hash2.cpp | 18 - test/measure/hmac_sha3_256_hash2.cpp | 18 - test/measure/hmac_sha3_384_hash2.cpp | 18 - test/measure/hmac_sha3_512_hash2.cpp | 18 - test/measure/keccak_256_xkcp.cpp | 17 - test/measure/md5_128_hash2.cpp | 17 - test/measure/measure.hpp | 191 ----- test/measure/murmur3_128_hash2.cpp | 17 - test/measure/murmur3_32_hash2.cpp | 17 - test/measure/pbkdf2_hash2.cpp | 27 - test/measure/pbkdf2_openssl.cpp | 27 - test/measure/ripemd_128_hash2.cpp | 17 - test/measure/ripemd_160_hash2.cpp | 17 - test/measure/scrypt_sodium.cpp | 27 - test/measure/sha1_160_hash2.cpp | 17 - test/measure/sha2_224_hash2.cpp | 17 - test/measure/sha2_256_hash2.cpp | 17 - test/measure/sha2_384_hash2.cpp | 17 - test/measure/sha2_512_224_hash2.cpp | 17 - test/measure/sha2_512_256_hash2.cpp | 17 - test/measure/sha2_512_hash2.cpp | 17 - test/measure/sha3_224_hash2.cpp | 17 - test/measure/sha3_256_hash2.cpp | 17 - test/measure/sha3_384_hash2.cpp | 17 - test/measure/sha3_512_hash2.cpp | 17 - test/measure/shake_128_hash2.cpp | 17 - test/measure/shake_256_hash2.cpp | 17 - test/measure/siphash_32_hash2.cpp | 18 - test/measure/siphash_64_hash2.cpp | 18 - test/measure/spooky2_128_hash2.cpp | 17 - test/measure/xxh3_128_hash2.cpp | 17 - test/measure/xxhash_32_hash2.cpp | 17 - test/measure/xxhash_64_hash2.cpp | 17 - test/messages/Jamfile | 8 +- .../Jamfile | 5 +- .../argon2id_default_not_linked.cpp} | 9 +- test/messages/argon2id_override_hash2/Jamfile | 14 - test/messages/override_cannot_serve/Jamfile | 14 - .../override_cannot_serve.cpp | 25 - .../Jamfile | 5 +- .../scrypt_default_not_linked.cpp | 25 + test/messages/scrypt_override_hash2/Jamfile | 14 - .../scrypt_override_hash2.cpp | 23 - test/messages/two_overrides/Jamfile | 14 - test/messages/two_overrides/two_overrides.cpp | 17 - test/messages/two_profiles/two_profiles.cpp | 16 - .../two_umbrella_profiles.cpp | 17 - test/msvc/Jamfile | 8 +- .../Jamfile | 4 +- test/msvc/override_cannot_serve/Jamfile | 14 - test/msvc/override_two_files/main.cpp | 21 - test/msvc/override_two_files/with.cpp | 20 - test/msvc/profile_two_files/main.cpp | 21 - test/msvc/profile_two_files/with.cpp | 20 - .../Jamfile | 4 +- test/msvc/two_overrides/Jamfile | 14 - test/msvc/two_profiles/Jamfile | 14 - test/msvc/two_umbrella_profiles/Jamfile | 14 - test/overrides_list_test.cpp | 213 ------ test/pbkdf2_openssl_test.cpp | 8 +- test/scrypt_test.cpp | 4 +- test/support/defaults.hpp | 51 -- 149 files changed, 498 insertions(+), 5113 deletions(-) create mode 100644 doc/choosing_backend.adoc delete mode 100644 doc/profile.adoc delete mode 100644 include/webcpp/hash/detail/overrides.hpp delete mode 100644 include/webcpp/hash/detail/ranking.hpp delete mode 100644 test/default_fastest_test.cpp delete mode 100644 test/default_named_test.cpp delete mode 100644 test/default_override_test.cpp delete mode 100644 test/default_portable_test.cpp delete mode 100644 test/default_smallest_test.cpp delete mode 100644 test/default_umbrella_test.cpp delete mode 100644 test/measure/Jamfile delete mode 100644 test/measure/argon2id_sodium.cpp delete mode 100644 test/measure/blake2b_512_hash2.cpp delete mode 100644 test/measure/blake2s_256_hash2.cpp delete mode 100644 test/measure/blake3_blake3.cpp delete mode 100644 test/measure/cells.jam delete mode 100644 test/measure/fnv1a_32_hash2.cpp delete mode 100644 test/measure/fnv1a_64_hash2.cpp delete mode 100644 test/measure/hkdf_bearssl.cpp delete mode 100644 test/measure/hkdf_expand_hash2.cpp delete mode 100644 test/measure/hkdf_expand_openssl.cpp delete mode 100644 test/measure/hkdf_expand_sodium.cpp delete mode 100644 test/measure/hkdf_extract_hash2.cpp delete mode 100644 test/measure/hkdf_extract_openssl.cpp delete mode 100644 test/measure/hkdf_extract_sodium.cpp delete mode 100644 test/measure/hkdf_hash2.cpp delete mode 100644 test/measure/hkdf_openssl.cpp delete mode 100644 test/measure/hkdf_sodium.cpp delete mode 100644 test/measure/hmac_blake2b_512_hash2.cpp delete mode 100644 test/measure/hmac_blake2s_256_hash2.cpp delete mode 100644 test/measure/hmac_hash2.cpp delete mode 100644 test/measure/hmac_md5_128_hash2.cpp delete mode 100644 test/measure/hmac_ripemd_128_hash2.cpp delete mode 100644 test/measure/hmac_ripemd_160_hash2.cpp delete mode 100644 test/measure/hmac_sha1_160_hash2.cpp delete mode 100644 test/measure/hmac_sha2_224_hash2.cpp delete mode 100644 test/measure/hmac_sha2_256_hash2.cpp delete mode 100644 test/measure/hmac_sha2_384_hash2.cpp delete mode 100644 test/measure/hmac_sha2_512_224_hash2.cpp delete mode 100644 test/measure/hmac_sha2_512_256_hash2.cpp delete mode 100644 test/measure/hmac_sha2_512_hash2.cpp delete mode 100644 test/measure/hmac_sha3_224_hash2.cpp delete mode 100644 test/measure/hmac_sha3_256_hash2.cpp delete mode 100644 test/measure/hmac_sha3_384_hash2.cpp delete mode 100644 test/measure/hmac_sha3_512_hash2.cpp delete mode 100644 test/measure/keccak_256_xkcp.cpp delete mode 100644 test/measure/md5_128_hash2.cpp delete mode 100644 test/measure/measure.hpp delete mode 100644 test/measure/murmur3_128_hash2.cpp delete mode 100644 test/measure/murmur3_32_hash2.cpp delete mode 100644 test/measure/pbkdf2_hash2.cpp delete mode 100644 test/measure/pbkdf2_openssl.cpp delete mode 100644 test/measure/ripemd_128_hash2.cpp delete mode 100644 test/measure/ripemd_160_hash2.cpp delete mode 100644 test/measure/scrypt_sodium.cpp delete mode 100644 test/measure/sha1_160_hash2.cpp delete mode 100644 test/measure/sha2_224_hash2.cpp delete mode 100644 test/measure/sha2_256_hash2.cpp delete mode 100644 test/measure/sha2_384_hash2.cpp delete mode 100644 test/measure/sha2_512_224_hash2.cpp delete mode 100644 test/measure/sha2_512_256_hash2.cpp delete mode 100644 test/measure/sha2_512_hash2.cpp delete mode 100644 test/measure/sha3_224_hash2.cpp delete mode 100644 test/measure/sha3_256_hash2.cpp delete mode 100644 test/measure/sha3_384_hash2.cpp delete mode 100644 test/measure/sha3_512_hash2.cpp delete mode 100644 test/measure/shake_128_hash2.cpp delete mode 100644 test/measure/shake_256_hash2.cpp delete mode 100644 test/measure/siphash_32_hash2.cpp delete mode 100644 test/measure/siphash_64_hash2.cpp delete mode 100644 test/measure/spooky2_128_hash2.cpp delete mode 100644 test/measure/xxh3_128_hash2.cpp delete mode 100644 test/measure/xxhash_32_hash2.cpp delete mode 100644 test/measure/xxhash_64_hash2.cpp rename test/messages/{two_profiles => argon2id_default_not_linked}/Jamfile (61%) rename test/messages/{argon2id_override_hash2/argon2id_override_hash2.cpp => argon2id_default_not_linked/argon2id_default_not_linked.cpp} (54%) delete mode 100644 test/messages/argon2id_override_hash2/Jamfile delete mode 100644 test/messages/override_cannot_serve/Jamfile delete mode 100644 test/messages/override_cannot_serve/override_cannot_serve.cpp rename test/messages/{two_umbrella_profiles => scrypt_default_not_linked}/Jamfile (60%) create mode 100644 test/messages/scrypt_default_not_linked/scrypt_default_not_linked.cpp delete mode 100644 test/messages/scrypt_override_hash2/Jamfile delete mode 100644 test/messages/scrypt_override_hash2/scrypt_override_hash2.cpp delete mode 100644 test/messages/two_overrides/Jamfile delete mode 100644 test/messages/two_overrides/two_overrides.cpp delete mode 100644 test/messages/two_profiles/two_profiles.cpp delete mode 100644 test/messages/two_umbrella_profiles/two_umbrella_profiles.cpp rename test/msvc/{profile_two_files => argon2id_default_not_linked}/Jamfile (66%) delete mode 100644 test/msvc/override_cannot_serve/Jamfile delete mode 100644 test/msvc/override_two_files/main.cpp delete mode 100644 test/msvc/override_two_files/with.cpp delete mode 100644 test/msvc/profile_two_files/main.cpp delete mode 100644 test/msvc/profile_two_files/with.cpp rename test/msvc/{override_two_files => scrypt_default_not_linked}/Jamfile (67%) delete mode 100644 test/msvc/two_overrides/Jamfile delete mode 100644 test/msvc/two_profiles/Jamfile delete mode 100644 test/msvc/two_umbrella_profiles/Jamfile delete mode 100644 test/overrides_list_test.cpp diff --git a/README.md b/README.md index f22f1c3..f1aa179 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ nothing in webcpp's own code. The guide (`doc/hash.adoc`) teaches each family of functions with two comparison tables, an example program of `example/` per section and its pitfalls, then three applications from end to end; its tables and `doc/llms.txt` are generated from `doc/capabilities.json` and the measured data by -`tools/hash/doc_tables.py`. `NOTICE.md` keeps the notice of the documentation it adapts. +`tools/hash/doc_tables.py`. Every key derivation runs on `backends::hash2` unless the call names +another backend; Argon2id and scrypt run on `backends::sodium`, their only backend. The measured +table, `doc/measurements.json`, is a reference measured on 2026-11-16 that decides nothing. `NOTICE.md` keeps the notice of the documentation it adapts. ## Building and testing @@ -25,14 +27,11 @@ b2 -a --build-dir=bin/lane-emscripten toolset=emscripten libs/hash/test libs/has b2 -a --build-dir=bin/lane-gcc-15 toolset=gcc-15 libs/hash/test libs/hash/example ``` -Two own lanes run outside those. `c-suites` builds the C libraries' own test programs on every -target, and `measure` builds one program per cell of the capability table on every target in -one command, then checks the committed measurements; it needs the WebAssembly toolsets -(`clang-wasip2`, `clang-wasip3`, `emscripten`) to be set up beside the native one: +One own lane runs outside those: `c-suites` builds the C libraries' own test programs on every +target: ``` b2 -a --build-dir=bin/lane-c-suites libs/hash/test/c_suites//c-suites -b2 -a --build-dir=bin/lane-measure libs/hash/test/measure//measure ``` The user Jamfiles of the library (each line of the specification's section 5.1, as a user diff --git a/bench/Jamfile b/bench/Jamfile index 45b0ee3..933e825 100644 --- a/bench/Jamfile +++ b/bench/Jamfile @@ -32,8 +32,8 @@ rule with-openssl ( properties * ) speed ; webcpp.run pbkdf2_sha512_key : pbkdf2_sha512.cpp : $(.requirements) ; -# The same program at variant=release, which the own lane measure -# (test/measure/Jamfile) builds on the four targets and tools/hash/measure.py -# --check runs with no argument, its correctness test (on every target). +# The same program at variant=release, the one collect.py measures, run by +# hand (doc/performance.adoc); no lane measures it. pbkdf2_sha512_key runs in +# every lane of test/ (test/Jamfile builds this project). exe pbkdf2_sha512 : pbkdf2_sha512.cpp : $(.requirements) release ; explicit pbkdf2_sha512 ; diff --git a/doc/backends.adoc b/doc/backends.adoc index 6b94d0f..2419d35 100644 --- a/doc/backends.adoc +++ b/doc/backends.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/measure.py from doc/capabilities.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends] == Backends @@ -454,6 +454,33 @@ states about its constant time. The backends: | native, wasip2, wasip3, emscripten |=== +=== The default backends + +The backend a call that names none uses, on every target, whatever the program links (<>): + +[cols="2,1",options="header"] +|=== +| Function | Default + +| hkdf_extract +| hash2 + +| hkdf_expand +| hash2 + +| hkdf +| hash2 + +| pbkdf2 +| hash2 + +| argon2id +| sodium + +| scrypt +| sodium +|=== + === Constant time What each backend's upstream states, and where: diff --git a/doc/capabilities.json b/doc/capabilities.json index aa6d757..c80b7e8 100644 --- a/doc/capabilities.json +++ b/doc/capabilities.json @@ -1,13 +1,13 @@ { - "about": "webcpp::hash's capability table (spec section 3.5): which library implements each public name, over which hmacs, on which targets, and what upstream states about constant time. backend_has_v is the same table for the key derivations: test/capabilities_test.cpp compares them cell by cell, checks each type row against the code and each refusal text against its row; test/overrides_list_test.cpp checks detail/overrides.hpp against the overridable algorithms. The documentation renders from it.", - "version": 2, + "about": "webcpp::hash's capability table (spec section 3.5): which library implements each public name, over which hmacs, on which targets, what upstream states about constant time, and the backend a call that names none uses. backend_has_v is the same table for the key derivations: test/capabilities_test.cpp compares them cell by cell, checks each type row against the code, each function's default against default_backend and each refusal text against its row. The documentation renders from it.", + "version": 3, "layout": { "schema": "This description. The version of the layout is \"version\"; a change of layout raises it.", "targets": "The targets webcpp builds for.", - "backends[]": "Each library a function runs on: name (as cells name it), tag (its webcpp::hash::backends type, or null for a library without one in this increment: xkcp, blake3), macro (the word of WEBCPP_HASH_HAS_, WEBCPP_HASH_PROFILE_BACKEND_ and WEBCPP_HASH_DEFAULT_BACKEND__), library (name and pin), licence, jamfile (the target a program names), targets (where it builds), portable (whether the portable profile may choose it: present on every target).", + "backends[]": "Each library a function runs on: name (as cells name it), tag (its webcpp::hash::backends type, or null for a library without one in this increment: xkcp, blake3), macro (the word of WEBCPP_HASH_HAS_), library (name and pin), licence, jamfile (the target a program names), targets (where it builds).", "hmacs": "The hmac columns of a function over an hmac: the aliases of , and \"other\", hmac over any other Boost.Hash2 hash whose result is a digest.", - "algorithms[]": "One row group of spec 3.5: name, macro (the of an override), tag (its kdfs:: type, or null), chapter (the documentation's chapter: digests, macs, kdfs, password_hashing, non-cryptographic), standard, overridable (whether default_backend chooses its backend, so that it has the overrides of detail/overrides.hpp), functions.", - "functions[]": "One public name: name, kind (\"type\": a Boost.Hash2-form type; \"function\": a function template with a Backend parameter), tag (the kdfs:: type of backend_has_v and default_backend, for a function), header, backends.", + "algorithms[]": "One row group of spec 3.5: name, macro (the algorithm's word in upper case), tag (its kdfs:: type, or null), chapter (the documentation's chapter: digests, macs, kdfs, password_hashing, non-cryptographic), standard, functions.", + "functions[]": "One public name: name, kind (\"type\": a Boost.Hash2-form type; \"function\": a function template with a Backend parameter), header, default (for a function, the backend default_backend names when the call names none; null for a type), backends.", "backends{}": "Per backend name, the cell: since (the increment it came with), hmacs (the columns it has, or null for a function or type that takes no hmac), constant_time {value: \"yes\", \"no\" or \"not stated\", source: where upstream says so, or what was read and says nothing}. A cell holds on every target of its backend." }, "targets": [ @@ -29,8 +29,7 @@ "wasip2", "wasip3", "emscripten" - ], - "portable": true + ] }, { "name": "xkcp", @@ -44,8 +43,7 @@ "wasip2", "wasip3", "emscripten" - ], - "portable": true + ] }, { "name": "blake3", @@ -59,8 +57,7 @@ "wasip2", "wasip3", "emscripten" - ], - "portable": true + ] }, { "name": "sodium", @@ -74,8 +71,7 @@ "wasip2", "wasip3", "emscripten" - ], - "portable": true + ] }, { "name": "bearssl", @@ -89,8 +85,7 @@ "wasip2", "wasip3", "emscripten" - ], - "portable": true + ] }, { "name": "openssl", @@ -103,8 +98,7 @@ "native", "wasip2", "wasip3" - ], - "portable": false + ] } ], "hmacs": [ @@ -133,12 +127,12 @@ "tag": null, "chapter": "digests", "standard": "RFC 1321, RFC 3174, FIPS 180-4", - "overridable": false, "functions": [ { "name": "md5_128", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -154,6 +148,7 @@ "name": "sha1_160", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -169,6 +164,7 @@ "name": "sha2_224", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -184,6 +180,7 @@ "name": "sha2_256", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -199,6 +196,7 @@ "name": "sha2_384", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -214,6 +212,7 @@ "name": "sha2_512", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -229,6 +228,7 @@ "name": "sha2_512_224", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -244,6 +244,7 @@ "name": "sha2_512_256", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -263,12 +264,12 @@ "tag": null, "chapter": "digests", "standard": "FIPS 202", - "overridable": false, "functions": [ { "name": "sha3_224", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -284,6 +285,7 @@ "name": "sha3_256", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -299,6 +301,7 @@ "name": "sha3_384", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -314,6 +317,7 @@ "name": "sha3_512", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -329,6 +333,7 @@ "name": "shake_128", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -344,6 +349,7 @@ "name": "shake_256", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -363,12 +369,12 @@ "tag": null, "chapter": "digests", "standard": "Keccak (the SHA-3 submission's padding), as Ethereum uses it", - "overridable": false, "functions": [ { "name": "keccak_256", "kind": "type", "header": "webcpp/hash/keccak.hpp", + "default": null, "backends": { "xkcp": { "since": 1, @@ -388,12 +394,12 @@ "tag": null, "chapter": "digests", "standard": "RFC 7693", - "overridable": false, "functions": [ { "name": "blake2b_512", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -409,6 +415,7 @@ "name": "blake2s_256", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -428,12 +435,12 @@ "tag": null, "chapter": "digests", "standard": "the BLAKE3 specification (hash, keyed hash, derive_key, extendable output)", - "overridable": false, "functions": [ { "name": "blake3", "kind": "type", "header": "webcpp/hash/blake3.hpp", + "default": null, "backends": { "blake3": { "since": 1, @@ -453,12 +460,12 @@ "tag": null, "chapter": "digests", "standard": "RIPEMD-128 and RIPEMD-160 (Dobbertin, Bosselaers, Preneel)", - "overridable": false, "functions": [ { "name": "ripemd_128", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -474,6 +481,7 @@ "name": "ripemd_160", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -493,12 +501,12 @@ "tag": null, "chapter": "macs", "standard": "SipHash-2-4 (siphash_64) and HalfSipHash-2-4 (siphash_32), Aumasson and Bernstein", - "overridable": false, "functions": [ { "name": "siphash_32", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -514,6 +522,7 @@ "name": "siphash_64", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -533,12 +542,12 @@ "tag": null, "chapter": "macs", "standard": "RFC 2104", - "overridable": false, "functions": [ { "name": "hmac", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -554,6 +563,7 @@ "name": "hmac_md5_128", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -569,6 +579,7 @@ "name": "hmac_sha1_160", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -584,6 +595,7 @@ "name": "hmac_sha2_224", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -599,6 +611,7 @@ "name": "hmac_sha2_256", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -614,6 +627,7 @@ "name": "hmac_sha2_384", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -629,6 +643,7 @@ "name": "hmac_sha2_512", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -644,6 +659,7 @@ "name": "hmac_sha2_512_224", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -659,6 +675,7 @@ "name": "hmac_sha2_512_256", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -674,6 +691,7 @@ "name": "hmac_sha3_224", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -689,6 +707,7 @@ "name": "hmac_sha3_256", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -704,6 +723,7 @@ "name": "hmac_sha3_384", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -719,6 +739,7 @@ "name": "hmac_sha3_512", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -734,6 +755,7 @@ "name": "hmac_ripemd_128", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -749,6 +771,7 @@ "name": "hmac_ripemd_160", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -764,6 +787,7 @@ "name": "hmac_blake2b_512", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -779,6 +803,7 @@ "name": "hmac_blake2s_256", "kind": "type", "header": "webcpp/hash/hmac.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -798,12 +823,12 @@ "tag": null, "chapter": "non-cryptographic", "standard": "FNV-1a, xxHash, XXH3, MurmurHash3, SpookyHash V2", - "overridable": false, "functions": [ { "name": "fnv1a_32", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -819,6 +844,7 @@ "name": "fnv1a_64", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -834,6 +860,7 @@ "name": "xxhash_32", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -849,6 +876,7 @@ "name": "xxhash_64", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -864,6 +892,7 @@ "name": "xxh3_128", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -879,6 +908,7 @@ "name": "murmur3_32", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -894,6 +924,7 @@ "name": "murmur3_128", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -909,6 +940,7 @@ "name": "spooky2_128", "kind": "type", "header": "webcpp/hash/algorithms.hpp", + "default": null, "backends": { "hash2": { "since": 1, @@ -928,13 +960,13 @@ "tag": "kdfs::hkdf", "chapter": "kdfs", "standard": "RFC 5869", - "overridable": true, "functions": [ { "name": "hkdf_extract", "kind": "function", "tag": "kdfs::hkdf_extract", "header": "webcpp/hash/hkdf.hpp", + "default": "hash2", "backends": { "hash2": { "since": 1, @@ -1004,6 +1036,7 @@ "kind": "function", "tag": "kdfs::hkdf_expand", "header": "webcpp/hash/hkdf.hpp", + "default": "hash2", "backends": { "hash2": { "since": 1, @@ -1073,6 +1106,7 @@ "kind": "function", "tag": "kdfs::hkdf", "header": "webcpp/hash/hkdf.hpp", + "default": "hash2", "backends": { "hash2": { "since": 1, @@ -1160,13 +1194,13 @@ "tag": "kdfs::pbkdf2", "chapter": "kdfs", "standard": "RFC 8018", - "overridable": true, "functions": [ { "name": "pbkdf2", "kind": "function", "tag": "kdfs::pbkdf2", "header": "webcpp/hash/pbkdf2.hpp", + "default": "hash2", "backends": { "hash2": { "since": 1, @@ -1228,13 +1262,13 @@ "tag": "kdfs::argon2id", "chapter": "password_hashing", "standard": "RFC 9106, one lane", - "overridable": true, "functions": [ { "name": "argon2id", "kind": "function", "tag": "kdfs::argon2id", "header": "webcpp/hash/argon2.hpp", + "default": "sodium", "backends": { "sodium": { "since": 1, @@ -1254,13 +1288,13 @@ "tag": "kdfs::scrypt", "chapter": "password_hashing", "standard": "RFC 7914", - "overridable": true, "functions": [ { "name": "scrypt", "kind": "function", "tag": "kdfs::scrypt", "header": "webcpp/hash/scrypt.hpp", + "default": "sodium", "backends": { "sodium": { "since": 1, diff --git a/doc/changelog.adoc b/doc/changelog.adoc index 7316dc7..a74b8d5 100644 --- a/doc/changelog.adoc +++ b/doc/changelog.adoc @@ -22,8 +22,8 @@ of every version are on webcpp's index page. * Added argon2id (RFC 9106, one lane) with libsodium's three presets, and scrypt (RFC 7914), on backends::sodium. * Added backends::sodium's HKDF over HMAC-SHA-256 and HMAC-SHA-512, and backends::bearssl's over MD5, SHA-1 and SHA-2 (hkdf alone). * Added backends::openssl, OpenSSL 3.5.9's HKDF and PBKDF2 through /webcpp/hash//openssl on native, wasip2 and wasip3, refusing lengths past OpenSSL's int. -* Added the default backend's profiles (WEBCPP_HASH_PROFILE_FASTEST, _SMALLEST, _PORTABLE, _BACKEND_, webcpp's WEBCPP_PROFILE_*), choosing per function among the backends that have it. -* Added the per-algorithm overrides WEBCPP_HASH_DEFAULT_BACKEND__, of HKDF, PBKDF2, argon2id and scrypt, and the capability table doc/capabilities.json. -* Added the measured tables (doc/measurements.*): each backend's size and throughput per target, which order the defaults, and allocation tests: none in hash's code. +* Added the default backend: backends::hash2 for every key derivation, backends::sodium for argon2id and scrypt; another backend is named in the call's type. +* Added the capability table doc/capabilities.json, with each function's default backend. +* Added the measured tables (doc/measurements.*), a reference of 2026-11-16 that decides nothing, and allocation tests: none in hash's code. * Added the guide: chapters per family and per use case, an example per section, generated tables and llms.txt, and a Boost.Hash2 proposal of keccak_224 to keccak_512. // end::unreleased[] diff --git a/doc/choosing_backend.adoc b/doc/choosing_backend.adoc new file mode 100644 index 0000000..2cedb17 --- /dev/null +++ b/doc/choosing_backend.adoc @@ -0,0 +1,115 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +[#hash-choosing-backend] +== 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 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. + +[#hash-default-backend] +=== The default backend + +[cols="2,1,3"] +|=== +| Function | Default | Why + +| `hkdf_extract`, `hkdf_expand`, `hkdf`, `pbkdf2` +| `hash2` +| the one backend that has every hmac, every operation and every target + +| `argon2id`, `scrypt` +| `sodium` +| the one backend that has them; a program links `/third_party//sodium` +|=== + +The default is the same on every target, whatever the program links: linking +libsodium, BearSSL or OpenSSL 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 (<>). No define chooses a +default: a program that wants another backend names it in the call, as the +second template argument, `hkdf`; +<> 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 (<>), and so does OpenSSL +on Emscripten. `default_backend` names the default at compile time. + +[#hash-backend-conditions] +=== 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: + +[cols="1,4"] +|=== +| 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 context before each call returns. BearSSL's own +temporaries on its stack, the pseudorandom key of `br_hkdf_flip` and the +padded keys of its HMAC, 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. 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. + +| `xkcp` +| Hashes without a secret of their own; it allocates nothing. + +| `blake3` +| Allocates nothing. Its keyed and `derive_key` modes hold the key in the +object's state until it is destroyed, without wiping it (<>). +|=== + +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. + +[#hash-measured] +=== 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. + +include::generated/measured.adoc[] diff --git a/doc/generated/backends-argon2id.adoc b/doc/generated/backends-argon2id.adoc index 93bd6f3..a418e03 100644 --- a/doc/generated/backends-argon2id.adoc +++ b/doc/generated/backends-argon2id.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-argon2id] @@ -25,34 +25,4 @@ 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 crypto_kdf_hkdf_* or crypto_pwhash_*. -.The default backend of `argon2id`: the first linked backend of each order -[cols="1,2,2,2,1",options="header"] -|=== -| Target | auto (no profile) | fastest | smallest | portable - -| native -| sodium -| sodium -| sodium -| sodium - -| wasip2 -| sodium -| sodium -| sodium -| sodium - -| wasip3 -| sodium -| sodium -| sodium -| sodium - -| emscripten -| sodium -| sodium -| sodium -| sodium -|=== - -Each order is measured with every backend linked; a backend the program does not link is skipped. A named profile, `WEBCPP_HASH_PROFILE_BACKEND_`, or an override, `WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_`, takes its backend where it has the function (<>). +The default of `argon2id`: `sodium` on every target, whatever the program links (<>). diff --git a/doc/generated/backends-blake2.adoc b/doc/generated/backends-blake2.adoc index a30ece4..4c91a9d 100644 --- a/doc/generated/backends-blake2.adoc +++ b/doc/generated/backends-blake2.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-blake2] @@ -32,4 +32,4 @@ 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`: no profile or override changes it. +One backend, `hash2`: the types take no backend. diff --git a/doc/generated/backends-blake3.adoc b/doc/generated/backends-blake3.adoc index 40d0b0a..1ac3550 100644 --- a/doc/generated/backends-blake3.adoc +++ b/doc/generated/backends-blake3.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-blake3] @@ -25,4 +25,4 @@ 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. -One backend, `blake3`: no profile or override changes it. +One backend, `blake3`: the types take no backend. diff --git a/doc/generated/backends-hkdf.adoc b/doc/generated/backends-hkdf.adoc index 2f5fe6c..ded0a80 100644 --- a/doc/generated/backends-hkdf.adoc +++ b/doc/generated/backends-hkdf.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-hkdf] @@ -91,94 +91,4 @@ What each backend states on constant time, as the capability table read it: * `openssl`: 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 crypto_kdf_hkdf_* or crypto_pwhash_*. -.The default backend of `hkdf_extract`: the first linked backend of each order -[cols="1,2,2,2,1",options="header"] -|=== -| Target | auto (no profile) | fastest | smallest | portable - -| native -| hash2, sodium, openssl -| hash2, sodium, openssl -| hash2, sodium, openssl -| hash2 - -| wasip2 -| hash2, sodium, openssl -| hash2, sodium, openssl -| hash2, sodium, openssl -| hash2 - -| wasip3 -| hash2, sodium, openssl -| hash2, sodium, openssl -| hash2, sodium, openssl -| hash2 - -| emscripten -| hash2, sodium -| hash2, sodium -| hash2, sodium -| hash2 -|=== - -.The default backend of `hkdf_expand`: the first linked backend of each order -[cols="1,2,2,2,1",options="header"] -|=== -| Target | auto (no profile) | fastest | smallest | portable - -| native -| sodium, hash2, openssl -| sodium, hash2, openssl -| hash2, sodium, openssl -| hash2 - -| wasip2 -| sodium, hash2, openssl -| hash2, sodium, openssl -| sodium, hash2, openssl -| hash2 - -| wasip3 -| sodium, hash2, openssl -| hash2, sodium, openssl -| sodium, hash2, openssl -| hash2 - -| emscripten -| sodium, hash2 -| sodium, hash2 -| sodium, hash2 -| hash2 -|=== - -.The default backend of `hkdf`: the first linked backend of each order -[cols="1,2,2,2,1",options="header"] -|=== -| Target | auto (no profile) | fastest | smallest | portable - -| native -| sodium, hash2, openssl, bearssl -| sodium, hash2, openssl, bearssl -| hash2, bearssl, sodium, openssl -| hash2 - -| wasip2 -| bearssl, sodium, hash2, openssl -| hash2, bearssl, sodium, openssl -| bearssl, sodium, hash2, openssl -| hash2 - -| wasip3 -| bearssl, sodium, hash2, openssl -| hash2, bearssl, sodium, openssl -| bearssl, sodium, hash2, openssl -| hash2 - -| emscripten -| bearssl, sodium, hash2 -| sodium, hash2, bearssl -| bearssl, sodium, hash2 -| hash2 -|=== - -The orders shown are those over `hmac_sha2_256`, and over every hmac the table does not measure; `hmac_sha2_512` has its own orders, which can differ (<>). Each order is measured with every backend linked; a backend the program does not link is skipped. A named profile, `WEBCPP_HASH_PROFILE_BACKEND_`, or an override, `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_`, takes its backend where it has the function (<>). +The default of `hkdf_extract`, `hkdf_expand` and `hkdf`: `hash2` on every target, whatever the program links; `bearssl`, `openssl`, `sodium` only where the call names it, as its second template argument (<>). diff --git a/doc/generated/backends-hmac.adoc b/doc/generated/backends-hmac.adoc index 7366481..b67d04d 100644 --- a/doc/generated/backends-hmac.adoc +++ b/doc/generated/backends-hmac.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-hmac] @@ -137,4 +137,4 @@ 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`: no profile or override changes it. +One backend, `hash2`: the types take no backend. diff --git a/doc/generated/backends-keccak-256.adoc b/doc/generated/backends-keccak-256.adoc index c862c27..a700a21 100644 --- a/doc/generated/backends-keccak-256.adoc +++ b/doc/generated/backends-keccak-256.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-keccak-256] @@ -25,4 +25,4 @@ What each backend states on constant time, as the capability table read it: * `xkcp`: XKCP at d20c8fc: README.markdown and lib/low/KeccakP-1600 state no constant-time property. -One backend, `xkcp`: no profile or override changes it. +One backend, `xkcp`: the types take no backend. diff --git a/doc/generated/backends-md5-sha1-sha2.adoc b/doc/generated/backends-md5-sha1-sha2.adoc index ea0fccd..7470fce 100644 --- a/doc/generated/backends-md5-sha1-sha2.adoc +++ b/doc/generated/backends-md5-sha1-sha2.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-md5-sha1-sha2] @@ -74,4 +74,4 @@ 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`: no profile or override changes it. +One backend, `hash2`: the types take no backend. diff --git a/doc/generated/backends-non-cryptographic.adoc b/doc/generated/backends-non-cryptographic.adoc index 74213fc..6bd73dc 100644 --- a/doc/generated/backends-non-cryptographic.adoc +++ b/doc/generated/backends-non-cryptographic.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-non-cryptographic] @@ -74,4 +74,4 @@ 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`: no profile or override changes it. +One backend, `hash2`: the types take no backend. diff --git a/doc/generated/backends-pbkdf2.adoc b/doc/generated/backends-pbkdf2.adoc index cccba08..822a29b 100644 --- a/doc/generated/backends-pbkdf2.adoc +++ b/doc/generated/backends-pbkdf2.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-pbkdf2] @@ -33,34 +33,4 @@ 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. * `openssl`: OpenSSL 3.5.9: doc/man7/EVP_KDF-HKDF.pod and EVP_KDF-PBKDF2.pod state no constant-time property. -.The default backend of `pbkdf2`: the first linked backend of each order -[cols="1,2,2,2,1",options="header"] -|=== -| Target | auto (no profile) | fastest | smallest | portable - -| native -| openssl, hash2 -| openssl, hash2 -| hash2, openssl -| hash2 - -| wasip2 -| hash2, openssl -| hash2, openssl -| hash2, openssl -| hash2 - -| wasip3 -| hash2, openssl -| hash2, openssl -| hash2, openssl -| hash2 - -| emscripten -| hash2 -| hash2 -| hash2 -| hash2 -|=== - -The orders shown are those over `hmac_sha2_256`, and over every hmac the table does not measure; `hmac_sha2_512` has its own orders, which can differ (<>). Each order is measured with every backend linked; a backend the program does not link is skipped. A named profile, `WEBCPP_HASH_PROFILE_BACKEND_`, or an override, `WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_`, takes its backend where it has the function (<>). +The default of `pbkdf2`: `hash2` on every target, whatever the program links; `openssl` only where the call names it, as its second template argument (<>). diff --git a/doc/generated/backends-ripemd.adoc b/doc/generated/backends-ripemd.adoc index 978cf4e..35ed5dc 100644 --- a/doc/generated/backends-ripemd.adoc +++ b/doc/generated/backends-ripemd.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-ripemd] @@ -32,4 +32,4 @@ 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`: no profile or override changes it. +One backend, `hash2`: the types take no backend. diff --git a/doc/generated/backends-scrypt.adoc b/doc/generated/backends-scrypt.adoc index 9c8f086..625c0e0 100644 --- a/doc/generated/backends-scrypt.adoc +++ b/doc/generated/backends-scrypt.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-scrypt] @@ -25,34 +25,4 @@ 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 crypto_kdf_hkdf_* or crypto_pwhash_*. -.The default backend of `scrypt`: the first linked backend of each order -[cols="1,2,2,2,1",options="header"] -|=== -| Target | auto (no profile) | fastest | smallest | portable - -| native -| sodium -| sodium -| sodium -| sodium - -| wasip2 -| sodium -| sodium -| sodium -| sodium - -| wasip3 -| sodium -| sodium -| sodium -| sodium - -| emscripten -| sodium -| sodium -| sodium -| sodium -|=== - -Each order is measured with every backend linked; a backend the program does not link is skipped. A named profile, `WEBCPP_HASH_PROFILE_BACKEND_`, or an override, `WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_`, takes its backend where it has the function (<>). +The default of `scrypt`: `sodium` on every target, whatever the program links (<>). diff --git a/doc/generated/backends-sha3-shake.adoc b/doc/generated/backends-sha3-shake.adoc index 36b377e..7076806 100644 --- a/doc/generated/backends-sha3-shake.adoc +++ b/doc/generated/backends-sha3-shake.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-sha3-shake] @@ -60,4 +60,4 @@ 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`: no profile or override changes it. +One backend, `hash2`: the types take no backend. diff --git a/doc/generated/backends-siphash.adoc b/doc/generated/backends-siphash.adoc index 9a569fe..8ed8df2 100644 --- a/doc/generated/backends-siphash.adoc +++ b/doc/generated/backends-siphash.adoc @@ -4,7 +4,7 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/doc_tables.py from doc/capabilities.json and doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/capabilities.json: do not edit. [#hash-backends-of-siphash] @@ -32,4 +32,4 @@ 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`: no profile or override changes it. +One backend, `hash2`: the types take no backend. diff --git a/doc/generated/choose.adoc b/doc/generated/choose.adoc index 40e8977..9ce7a66 100644 --- a/doc/generated/choose.adoc +++ b/doc/generated/choose.adoc @@ -10,7 +10,7 @@ [#hash-choose-table] [cols="3,3,2,2,2",options="header"] |=== -| I need to ... | Use | Its backends: the Jamfile names | Profile | Example +| 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 | <> @@ -103,14 +103,14 @@ | `example/sha3_shake.cpp` | build the smallest WebAssembly program -| <> +| <> | `hash2`: `/webcpp/hash//hash`, `sodium`: `/third_party//sodium`, `bearssl`: `/third_party//bearssl`, `openssl`: `/webcpp/hash//openssl` -| WEBCPP_HASH_PROFILE_SMALLEST, or nothing: it is the default on WebAssembly +| the default | `example/hkdf_backends.cpp` | run the same code, with the same results, on every target -| <> +| <> | `hash2`: `/webcpp/hash//hash`, `sodium`: `/third_party//sodium`, `bearssl`: `/third_party//bearssl`, `openssl`: `/webcpp/hash//openssl` -| WEBCPP_HASH_PROFILE_PORTABLE +| the default | `example/hkdf_backends.cpp` |=== diff --git a/doc/generated/compare-digests.adoc b/doc/generated/compare-digests.adoc index 29bba87..e13a87d 100644 --- a/doc/generated/compare-digests.adoc +++ b/doc/generated/compare-digests.adoc @@ -281,4 +281,4 @@ | For Bitcoin's hash160; never in a new design. |=== -The measured columns are doc/measurements.json's (2026-11-16, Apple M5 Max): 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; <> has every backend on every target. +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; <> has every backend on every target. diff --git a/doc/generated/compare-kdfs.adoc b/doc/generated/compare-kdfs.adoc index 171f5d5..a200bb7 100644 --- a/doc/generated/compare-kdfs.adoc +++ b/doc/generated/compare-kdfs.adoc @@ -73,4 +73,4 @@ | When a standard or FIPS 140 demands it; otherwise Argon2id for passwords. |=== -The measured columns are doc/measurements.json's (2026-11-16, Apple M5 Max): 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; <> has every backend on every target. +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; <> has every backend on every target. diff --git a/doc/generated/compare-macs.adoc b/doc/generated/compare-macs.adoc index 0686b68..7d9bd9c 100644 --- a/doc/generated/compare-macs.adoc +++ b/doc/generated/compare-macs.adoc @@ -268,4 +268,4 @@ | For WireGuard-style protocols. |=== -The measured columns are doc/measurements.json's (2026-11-16, Apple M5 Max): 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; <> has every backend on every target. +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; <> has every backend on every target. diff --git a/doc/generated/compare-non-cryptographic.adoc b/doc/generated/compare-non-cryptographic.adoc index 754361b..95be588 100644 --- a/doc/generated/compare-non-cryptographic.adoc +++ b/doc/generated/compare-non-cryptographic.adoc @@ -125,4 +125,4 @@ | To match existing data that uses it. |=== -The measured columns are doc/measurements.json's (2026-11-16, Apple M5 Max): 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; <> has every backend on every target. +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; <> has every backend on every target. diff --git a/doc/generated/compare-password-hashing.adoc b/doc/generated/compare-password-hashing.adoc index 9ec5193..c778e7c 100644 --- a/doc/generated/compare-password-hashing.adoc +++ b/doc/generated/compare-password-hashing.adoc @@ -47,4 +47,4 @@ | When a format demands scrypt; otherwise Argon2id. |=== -The measured columns are doc/measurements.json's (2026-11-16, Apple M5 Max): 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; <> has every backend on every target. +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; <> has every backend on every target. diff --git a/doc/guide.json b/doc/guide.json index 5105c6f..3ca27c7 100644 --- a/doc/guide.json +++ b/doc/guide.json @@ -1,12 +1,12 @@ { "about": "What the guide says of each public name that the tests and measurements do not produce: what it is for, its security, where the world uses it (each fact with its source) and when to choose it; and the decision table of the chapter \"Choose by use case\". tools/hash/doc_tables.py renders the comparison tables, the backend lists, the decision table and doc/llms.txt from it, doc/capabilities.json and the measured data; it fails when a function of the capability table has no entry here. Support, size and speed are never written here: they come from the capability table and the measurements.", - "version": 1, + "version": 2, "layout": { "schema": "This description. The version of the layout is \"version\"; a change of layout raises it.", "page": "The URL the guide is published at, which doc/llms.txt links.", "chapters[]": "One per chapter of doc/capabilities.json, in the guide's order: chapter (its key there), title (the chapter's heading), anchor (its id), file (the .adoc that teaches it), summary (one sentence for doc/llms.txt).", "functions{}": "Per public name of doc/capabilities.json: standard (only where the capability table's algorithm names several standards: this name's own), summary (one sentence), output, security (in plain words, with its source in sources), status (recommended, legacy, broken or not cryptographic), webcrypto (the WebCrypto name, or null when the browser's Web Cryptography API has none), anchor (the guide's section), uses[] ({text, source}: where it is used, each with its source), choose (when to choose it).", - "use_cases[]": "The rows of \"Choose by use case\": need (I need to ...), use (the function, with its parameters), function (the name in doc/capabilities.json whose backends the row lists), profile (what to do about the backend), example (the program of example/ that shows it) and anchor (the guide's section)." + "use_cases[]": "The rows of \"Choose by use case\": need (I need to ...), use (the function, with its parameters), function (the name in doc/capabilities.json whose backends the row lists), backend (what to do about the backend), example (the program of example/ that shows it) and anchor (the guide's section)." }, "page": "https://webcpporg.github.io/libs/hash/", "chapters": [ @@ -724,22 +724,22 @@ } }, "use_cases": [ - {"need": "check that a file or message was not changed by accident or on the way", "use": "sha2_256 (or blake3 for large data)", "function": "sha2_256", "profile": "none: one backend", "example": "sha256.cpp", "anchor": "hash-sha2"}, - {"need": "name content by what it holds (a file-sharing app, a cache, a store of blobs)", "use": "blake3", "function": "blake3", "profile": "link /third_party//blake3", "example": "content_address.cpp", "anchor": "hash-p2p-content"}, - {"need": "prove a message comes from someone who holds a shared secret key (an API request, a cookie, a webhook)", "use": "hmac_sha2_256, checked with webcpp::crypto::equal", "function": "hmac_sha2_256", "profile": "none: one backend", "example": "hmac_sha256.cpp", "anchor": "hash-hmac"}, - {"need": "store users' passwords for a login", "use": "argon2id with argon2id_interactive or stronger, a random 16-byte salt per user", "function": "argon2id", "profile": "link /third_party//sodium", "example": "password_storage.cpp", "anchor": "hash-privacy-passwords"}, - {"need": "turn a password into an encryption key (a password manager, an encrypted backup)", "use": "argon2id with argon2id_moderate or argon2id_sensitive, then hkdf for each purpose", "function": "argon2id", "profile": "link /third_party//sodium", "example": "argon2id.cpp", "anchor": "hash-argon2id"}, - {"need": "turn a shared secret (an ECDH result) into keys", "use": "hkdf over hmac_sha2_256, one info label per key", "function": "hkdf", "profile": "the default; name a backend only to match another program's", "example": "hkdf.cpp", "anchor": "hash-hkdf"}, - {"need": "derive many keys from one master key, one per purpose", "use": "hkdf_expand (or hkdf) with distinct info labels, or blake3::derive_key with a context string", "function": "hkdf_expand", "profile": "the default", "example": "subkeys.cpp", "anchor": "hash-privacy-subkeys"}, - {"need": "build a hash table, set or Bloom filter whose keys come from the network", "use": "siphash_64 keyed with 16 random bytes per process", "function": "siphash_64", "profile": "none: one backend", "example": "siphash.cpp", "anchor": "hash-siphash"}, - {"need": "build a hash table of my own trusted keys, or a fast checksum", "use": "xxh3_128 or fnv1a_64", "function": "xxh3_128", "profile": "none: one backend", "example": "checksums.cpp", "anchor": "hash-non-cryptographic-functions"}, - {"need": "compute a Bitcoin wallet's BIP39 seed from its words", "use": "pbkdf2 over hmac_sha2_512, 2,048 iterations (a domain library's step)", "function": "pbkdf2", "profile": "the default", "example": "bip39_seed.cpp", "anchor": "hash-crypto-bip39"}, - {"need": "compute a Bitcoin address's hash160", "use": "ripemd_160 over sha2_256 (a domain library's step)", "function": "ripemd_160", "profile": "none: one backend", "example": "bitcoin_hash160.cpp", "anchor": "hash-crypto-hash160"}, - {"need": "compute an Ethereum address or a Solidity selector", "use": "keccak_256 (never sha3_256)", "function": "keccak_256", "profile": "link /third_party//xkcp", "example": "ethereum_address.cpp", "anchor": "hash-crypto-ethereum"}, - {"need": "compute a Nostr event id", "use": "sha2_256 over NIP-01's serialization (a domain library's step)", "function": "sha2_256", "profile": "none: one backend", "example": "nostr_event_id.cpp", "anchor": "hash-p2p-nostr"}, - {"need": "derive NIP-44's conversation key", "use": "hkdf_extract over hmac_sha2_256 with the salt nip44-v2 (a domain library's step)", "function": "hkdf_extract", "profile": "the default", "example": "nip44_conversation_key.cpp", "anchor": "hash-p2p-nip44"}, - {"need": "draw a long stream of pseudorandom bytes from a seed", "use": "shake_128 or shake_256, or blake3's squeeze", "function": "shake_128", "profile": "none: one backend", "example": "sha3_shake.cpp", "anchor": "hash-sha3"}, - {"need": "build the smallest WebAssembly program", "use": "the default (on WebAssembly, the smallest linked backend), and link only the libraries the program uses", "function": "hkdf", "profile": "WEBCPP_HASH_PROFILE_SMALLEST, or nothing: it is the default on WebAssembly", "example": "hkdf_backends.cpp", "anchor": "hash-profile"}, - {"need": "run the same code, with the same results, on every target", "use": "the portable profile", "function": "hkdf", "profile": "WEBCPP_HASH_PROFILE_PORTABLE", "example": "hkdf_backends.cpp", "anchor": "hash-profile"} + {"need": "check that a file or message was not changed by accident or on the way", "use": "sha2_256 (or blake3 for large data)", "function": "sha2_256", "backend": "none: one backend", "example": "sha256.cpp", "anchor": "hash-sha2"}, + {"need": "name content by what it holds (a file-sharing app, a cache, a store of blobs)", "use": "blake3", "function": "blake3", "backend": "link /third_party//blake3", "example": "content_address.cpp", "anchor": "hash-p2p-content"}, + {"need": "prove a message comes from someone who holds a shared secret key (an API request, a cookie, a webhook)", "use": "hmac_sha2_256, checked with webcpp::crypto::equal", "function": "hmac_sha2_256", "backend": "none: one backend", "example": "hmac_sha256.cpp", "anchor": "hash-hmac"}, + {"need": "store users' passwords for a login", "use": "argon2id with argon2id_interactive or stronger, a random 16-byte salt per user", "function": "argon2id", "backend": "link /third_party//sodium", "example": "password_storage.cpp", "anchor": "hash-privacy-passwords"}, + {"need": "turn a password into an encryption key (a password manager, an encrypted backup)", "use": "argon2id with argon2id_moderate or argon2id_sensitive, then hkdf for each purpose", "function": "argon2id", "backend": "link /third_party//sodium", "example": "argon2id.cpp", "anchor": "hash-argon2id"}, + {"need": "turn a shared secret (an ECDH result) into keys", "use": "hkdf over hmac_sha2_256, one info label per key", "function": "hkdf", "backend": "the default; name a backend only to match another program's", "example": "hkdf.cpp", "anchor": "hash-hkdf"}, + {"need": "derive many keys from one master key, one per purpose", "use": "hkdf_expand (or hkdf) with distinct info labels, or blake3::derive_key with a context string", "function": "hkdf_expand", "backend": "the default", "example": "subkeys.cpp", "anchor": "hash-privacy-subkeys"}, + {"need": "build a hash table, set or Bloom filter whose keys come from the network", "use": "siphash_64 keyed with 16 random bytes per process", "function": "siphash_64", "backend": "none: one backend", "example": "siphash.cpp", "anchor": "hash-siphash"}, + {"need": "build a hash table of my own trusted keys, or a fast checksum", "use": "xxh3_128 or fnv1a_64", "function": "xxh3_128", "backend": "none: one backend", "example": "checksums.cpp", "anchor": "hash-non-cryptographic-functions"}, + {"need": "compute a Bitcoin wallet's BIP39 seed from its words", "use": "pbkdf2 over hmac_sha2_512, 2,048 iterations (a domain library's step)", "function": "pbkdf2", "backend": "the default", "example": "bip39_seed.cpp", "anchor": "hash-crypto-bip39"}, + {"need": "compute a Bitcoin address's hash160", "use": "ripemd_160 over sha2_256 (a domain library's step)", "function": "ripemd_160", "backend": "none: one backend", "example": "bitcoin_hash160.cpp", "anchor": "hash-crypto-hash160"}, + {"need": "compute an Ethereum address or a Solidity selector", "use": "keccak_256 (never sha3_256)", "function": "keccak_256", "backend": "link /third_party//xkcp", "example": "ethereum_address.cpp", "anchor": "hash-crypto-ethereum"}, + {"need": "compute a Nostr event id", "use": "sha2_256 over NIP-01's serialization (a domain library's step)", "function": "sha2_256", "backend": "none: one backend", "example": "nostr_event_id.cpp", "anchor": "hash-p2p-nostr"}, + {"need": "derive NIP-44's conversation key", "use": "hkdf_extract over hmac_sha2_256 with the salt nip44-v2 (a domain library's step)", "function": "hkdf_extract", "backend": "the default", "example": "nip44_conversation_key.cpp", "anchor": "hash-p2p-nip44"}, + {"need": "draw a long stream of pseudorandom bytes from a seed", "use": "shake_128 or shake_256, or blake3's squeeze", "function": "shake_128", "backend": "none: one backend", "example": "sha3_shake.cpp", "anchor": "hash-sha3"}, + {"need": "build the smallest WebAssembly program", "use": "the default backend, backends::hash2, header-only, and link only the libraries the program uses", "function": "hkdf", "backend": "the default", "example": "hkdf_backends.cpp", "anchor": "hash-default-backend"}, + {"need": "run the same code, with the same results, on every target", "use": "the default backend, backends::hash2, the same code on every target", "function": "hkdf", "backend": "the default", "example": "hkdf_backends.cpp", "anchor": "hash-default-backend"} ] } diff --git a/doc/hash.adoc b/doc/hash.adoc index 989b604..19bc42a 100644 --- a/doc/hash.adoc +++ b/doc/hash.adoc @@ -56,7 +56,7 @@ include::use-cases/cryptocurrencies.adoc[] include::use-cases/privacy.adoc[] -include::profile.adoc[] +include::choosing_backend.adoc[] include::departures.adoc[] diff --git a/doc/jamfile.adoc b/doc/jamfile.adoc index 5d28da6..cc64c04 100644 --- a/doc/jamfile.adoc +++ b/doc/jamfile.adoc @@ -42,7 +42,7 @@ sources, for the program's target: |=== A program that hashes passwords with Argon2id and derives keys with HKDF on -whatever backend is smallest names, for example: +the default backend, `backends::hash2`, names, for example: [source,bash] ---- @@ -108,8 +108,6 @@ one asked for. | A key derivation over a type that is not a Boost.Hash2 hmac of a digest | Pass an hmac, as `hmac_sha2_256`. -| Two profiles, or two overrides of one algorithm, defined at once -| The message names both: keep one (<>). |=== Every message is tested: each is a test of `test/messages/`, which compiles a diff --git a/doc/kdfs.adoc b/doc/kdfs.adoc index cdb7f7f..6194031 100644 --- a/doc/kdfs.adoc +++ b/doc/kdfs.adoc @@ -20,8 +20,8 @@ one per label. PBKDF2 is the older answer to another problem, a key from a password, which Argon2id now answers better (<>). The key derivations are the functions of hash that run on a backend, a C -library or Boost.Hash2, that the program chooses or lets hash choose -(<>). Each backend gives the same bytes for the same inputs: the +library or Boost.Hash2, that the program names or leaves to the default, +`backends::hash2` (<>). Each backend gives the same bytes for the same inputs: the tests check them against each other on random inputs on every target. include::generated/compare-kdfs.adoc[] @@ -89,10 +89,10 @@ include::generated/backends-hkdf.adoc[] [#hash-kdfs-backends] === Naming a backend -Most programs never name a backend: the call takes the default, the first -backend the program links in the order the profile gives (<>). -A program names one as the call's second template argument, to match the bytes -of another program exactly, to keep a smaller binary, or to test one backend +Most programs never name a backend: the call takes the default, +`backends::hash2`, on every target (<>). 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` 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. @@ -136,7 +136,7 @@ include::{examples}/pbkdf2.expected[] 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; <> has the +browser tab: WebAssembly is slower than native; <> 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 diff --git a/doc/llms.txt b/doc/llms.txt index 78af3fa..f99f2f9 100644 --- a/doc/llms.txt +++ b/doc/llms.txt @@ -1,6 +1,6 @@ # webcpp::hash -> Hashing and key derivation for C++20 on every target webcpp has (native, wasip2, wasip3, Emscripten): Boost.Hash2's digests and HMAC, Keccak-256, BLAKE3, HKDF, PBKDF2, Argon2id and scrypt over C backends. Every function is synchronous, returns boost::system::result and allocates nothing in webcpp's own code. A program links /webcpp/hash//hash and the library of each backend it uses. +> Hashing and key derivation for C++20 on every target webcpp has (native, wasip2, wasip3, Emscripten): Boost.Hash2's digests and HMAC, Keccak-256, BLAKE3, HKDF, PBKDF2, Argon2id and scrypt over C backends. Every function is synchronous, returns boost::system::result and allocates nothing in webcpp's own code. A program links /webcpp/hash//hash and the library of each backend it uses. Every key derivation runs on backends::hash2 unless the call names another backend as its second template argument; argon2id and scrypt run on backends::sodium, their only backend. Primitives only: protocol steps (BIP39, hash160, EIP-55, Nostr ids, NIP-44) are what a domain library builds from these functions; the guide shows them as examples, never as this library's API. @@ -102,10 +102,11 @@ Fast hashes for hash tables, checksums against accidents and identifiers that no - I need to compute a Nostr event id: sha2_256 over NIP-01's serialization (a domain library's step); backend: none: one backend; example libs/hash/example/nostr_event_id.cpp. [Section](https://webcpporg.github.io/libs/hash/#hash-p2p-nostr) - I need to derive NIP-44's conversation key: hkdf_extract over hmac_sha2_256 with the salt nip44-v2 (a domain library's step); backend: the default; example libs/hash/example/nip44_conversation_key.cpp. [Section](https://webcpporg.github.io/libs/hash/#hash-p2p-nip44) - I need to draw a long stream of pseudorandom bytes from a seed: shake_128 or shake_256, or blake3's squeeze; backend: none: one backend; example libs/hash/example/sha3_shake.cpp. [Section](https://webcpporg.github.io/libs/hash/#hash-sha3) -- I need to build the smallest WebAssembly program: the default (on WebAssembly, the smallest linked backend), and link only the libraries the program uses; backend: WEBCPP_HASH_PROFILE_SMALLEST, or nothing: it is the default on WebAssembly; example libs/hash/example/hkdf_backends.cpp. [Section](https://webcpporg.github.io/libs/hash/#hash-profile) -- I need to run the same code, with the same results, on every target: the portable profile; backend: WEBCPP_HASH_PROFILE_PORTABLE; example libs/hash/example/hkdf_backends.cpp. [Section](https://webcpporg.github.io/libs/hash/#hash-profile) +- I need to build the smallest WebAssembly program: the default backend, backends::hash2, header-only, and link only the libraries the program uses; backend: the default; example libs/hash/example/hkdf_backends.cpp. [Section](https://webcpporg.github.io/libs/hash/#hash-default-backend) +- I need to run the same code, with the same results, on every target: the default backend, backends::hash2, the same code on every target; backend: the default; example libs/hash/example/hkdf_backends.cpp. [Section](https://webcpporg.github.io/libs/hash/#hash-default-backend) ## Data - doc/capabilities.json: which backend implements each function, on which targets, over which hmacs, and its constant time -- doc/measurements.json: each backend's program size per target and its throughput +- doc/capabilities.json also names each function's default backend +- doc/measurements.json: each backend's program size per target and its throughput, a reference measured on 2026-11-16 that decides nothing diff --git a/doc/measurements.adoc b/doc/measurements.adoc index 6c1f375..24797f1 100644 --- a/doc/measurements.adoc +++ b/doc/measurements.adoc @@ -4,15 +4,19 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Generated by tools/hash/measure.py from doc/measurements.json: do not edit. +// Generated by tools/hash/doc_tables.py from doc/measurements.json: do not edit. [#hash-measurements] == Measured size and throughput -What each backend costs a program on each target, in bytes and in time, as webcpp measured it -(spec section 4.2). The size of a backend is what matters on WebAssembly, where every byte is -downloaded; its throughput is what matters natively. `detail/ranking.hpp`, generated from the -same data, orders the backends of each key derivation by both, and the default backend follows it. +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 +(<>): `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). @@ -21,7 +25,7 @@ Compilers: native: Apple LLVM 21.0.0 (clang-2100.4.1.1); wasip2: Clang 23.1.0-wa 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. Orders: spec 4.2: by size, the smallest program first; by throughput, the lowest median of the invocations' medians first, a committed order changing only where a median is more than 10 percent below the median of the backend ahead of it; on a first measurement, the medians alone (an exact tie keeps the capability table's order of backends). A WebAssembly target orders by its own throughput where every backend of the row ran within the bound, else by the native order. The native orders hold for the native toolchain that measured them (native_toolchain); the lane compares them only on that toolchain. +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 @@ -1261,623 +1265,3 @@ the range of its runs, the lower figure first. Per function, the workload: | 19.41 ms (19.09 ms to 20.82 ms) | 16.84 ms (16.05 ms to 17.65 ms) |=== - -=== The orders of the key derivations - -The rows `detail/ranking.hpp` holds, one per operation: the default of `hkdf_extract`, `hkdf_expand` and `hkdf` each reads its own (spec 4.1). - -[cols="2,2,1,3,3,1",options="header"] -|=== -| Function | Hmac | Target | By size | By throughput | Throughput of - -| hkdf_extract -| hmac_sha2_256 -| native -| hash2, sodium, openssl -| hash2, sodium, openssl -| native - -| hkdf_extract -| hmac_sha2_256 -| wasip2 -| hash2, sodium, openssl -| hash2, sodium, openssl -| wasip2 - -| hkdf_extract -| hmac_sha2_256 -| wasip3 -| hash2, sodium, openssl -| hash2, sodium, openssl -| wasip3 - -| hkdf_extract -| hmac_sha2_256 -| emscripten -| hash2, sodium -| hash2, sodium -| emscripten - -| hkdf_extract -| hmac_sha2_512 -| native -| hash2, sodium, openssl -| sodium, hash2, openssl -| native - -| hkdf_extract -| hmac_sha2_512 -| wasip2 -| hash2, sodium, openssl -| hash2, sodium, openssl -| wasip2 - -| hkdf_extract -| hmac_sha2_512 -| wasip3 -| hash2, sodium, openssl -| hash2, sodium, openssl -| wasip3 - -| hkdf_extract -| hmac_sha2_512 -| emscripten -| hash2, sodium -| hash2, sodium -| emscripten - -| hkdf_expand -| hmac_sha2_256 -| native -| hash2, sodium, openssl -| sodium, hash2, openssl -| native - -| hkdf_expand -| hmac_sha2_256 -| wasip2 -| sodium, hash2, openssl -| hash2, sodium, openssl -| wasip2 - -| hkdf_expand -| hmac_sha2_256 -| wasip3 -| sodium, hash2, openssl -| hash2, sodium, openssl -| wasip3 - -| hkdf_expand -| hmac_sha2_256 -| emscripten -| sodium, hash2 -| sodium, hash2 -| emscripten - -| hkdf_expand -| hmac_sha2_512 -| native -| hash2, sodium, openssl -| sodium, openssl, hash2 -| native - -| hkdf_expand -| hmac_sha2_512 -| wasip2 -| sodium, hash2, openssl -| hash2, sodium, openssl -| wasip2 - -| hkdf_expand -| hmac_sha2_512 -| wasip3 -| sodium, hash2, openssl -| hash2, sodium, openssl -| wasip3 - -| hkdf_expand -| hmac_sha2_512 -| emscripten -| sodium, hash2 -| sodium, hash2 -| emscripten - -| hkdf -| hmac_sha2_256 -| native -| hash2, bearssl, sodium, openssl -| sodium, hash2, openssl, bearssl -| native - -| hkdf -| hmac_sha2_256 -| wasip2 -| bearssl, sodium, hash2, openssl -| hash2, bearssl, sodium, openssl -| wasip2 - -| hkdf -| hmac_sha2_256 -| wasip3 -| bearssl, sodium, hash2, openssl -| hash2, bearssl, sodium, openssl -| wasip3 - -| hkdf -| hmac_sha2_256 -| emscripten -| bearssl, sodium, hash2 -| sodium, hash2, bearssl -| emscripten - -| hkdf -| hmac_sha2_512 -| native -| hash2, bearssl, sodium, openssl -| sodium, openssl, hash2, bearssl -| native - -| hkdf -| hmac_sha2_512 -| wasip2 -| bearssl, sodium, hash2, openssl -| bearssl, hash2, sodium, openssl -| wasip2 - -| hkdf -| hmac_sha2_512 -| wasip3 -| bearssl, sodium, hash2, openssl -| hash2, bearssl, sodium, openssl -| wasip3 - -| hkdf -| hmac_sha2_512 -| emscripten -| bearssl, sodium, hash2 -| sodium, hash2, bearssl -| emscripten - -| pbkdf2 -| hmac_sha2_256 -| native -| hash2, openssl -| openssl, hash2 -| native - -| pbkdf2 -| hmac_sha2_256 -| wasip2 -| hash2, openssl -| hash2, openssl -| wasip2 - -| pbkdf2 -| hmac_sha2_256 -| wasip3 -| hash2, openssl -| hash2, openssl -| wasip3 - -| pbkdf2 -| hmac_sha2_256 -| emscripten -| hash2 -| hash2 -| emscripten - -| pbkdf2 -| hmac_sha2_512 -| native -| hash2, openssl -| openssl, hash2 -| native - -| pbkdf2 -| hmac_sha2_512 -| wasip2 -| hash2, openssl -| openssl, hash2 -| wasip2 - -| pbkdf2 -| hmac_sha2_512 -| wasip3 -| hash2, openssl -| openssl, hash2 -| wasip3 - -| pbkdf2 -| hmac_sha2_512 -| emscripten -| hash2 -| hash2 -| emscripten - -| argon2id -| - -| native -| sodium -| sodium -| native - -| argon2id -| - -| wasip2 -| sodium -| sodium -| wasip2 - -| argon2id -| - -| wasip3 -| sodium -| sodium -| wasip3 - -| argon2id -| - -| emscripten -| sodium -| sodium -| emscripten - -| scrypt -| - -| native -| sodium -| sodium -| native - -| scrypt -| - -| wasip2 -| sodium -| sodium -| wasip2 - -| scrypt -| - -| wasip3 -| sodium -| sodium -| wasip3 - -| scrypt -| - -| emscripten -| sodium -| sodium -| emscripten -|=== - -=== The default of each key derivation - -The owner's rule (spec 4.1, the profile `auto`): natively the fastest backend, on WebAssembly the -smallest, among those the program links. With every backend linked, the default and the size of -its program, beside the smallest program of the function on that target: - -[cols="2,2,1,1,1,1,1",options="header"] -|=== -| Function | Hmac | Target | Default | Its size | Smallest | Its size - -| hkdf_extract -| hmac_sha2_256 -| native -| hash2 -| 34288 -| hash2 -| 34288 - -| hkdf_extract -| hmac_sha2_256 -| wasip2 -| hash2 -| 59161 -| hash2 -| 59161 - -| hkdf_extract -| hmac_sha2_256 -| wasip3 -| hash2 -| 68421 -| hash2 -| 68421 - -| hkdf_extract -| hmac_sha2_256 -| emscripten -| hash2 -| 17499 -| hash2 -| 17499 - -| hkdf_extract -| hmac_sha2_512 -| native -| sodium -| 70320 -| hash2 -| 34288 - -| hkdf_extract -| hmac_sha2_512 -| wasip2 -| hash2 -| 62750 -| hash2 -| 62750 - -| hkdf_extract -| hmac_sha2_512 -| wasip3 -| hash2 -| 72010 -| hash2 -| 72010 - -| hkdf_extract -| hmac_sha2_512 -| emscripten -| hash2 -| 21083 -| hash2 -| 21083 - -| hkdf_expand -| hmac_sha2_256 -| native -| sodium -| 70176 -| hash2 -| 34272 - -| hkdf_expand -| hmac_sha2_256 -| wasip2 -| sodium -| 73410 -| sodium -| 73410 - -| hkdf_expand -| hmac_sha2_256 -| wasip3 -| sodium -| 83243 -| sodium -| 83243 - -| hkdf_expand -| hmac_sha2_256 -| emscripten -| sodium -| 24778 -| sodium -| 24778 - -| hkdf_expand -| hmac_sha2_512 -| native -| sodium -| 70176 -| hash2 -| 34272 - -| hkdf_expand -| hmac_sha2_512 -| wasip2 -| sodium -| 74000 -| sodium -| 74000 - -| hkdf_expand -| hmac_sha2_512 -| wasip3 -| sodium -| 83832 -| sodium -| 83832 - -| hkdf_expand -| hmac_sha2_512 -| emscripten -| sodium -| 25282 -| sodium -| 25282 - -| hkdf -| hmac_sha2_256 -| native -| sodium -| 86984 -| hash2 -| 34392 - -| hkdf -| hmac_sha2_256 -| wasip2 -| bearssl -| 69317 -| bearssl -| 69317 - -| hkdf -| hmac_sha2_256 -| wasip3 -| bearssl -| 78961 -| bearssl -| 78961 - -| hkdf -| hmac_sha2_256 -| emscripten -| bearssl -| 23281 -| bearssl -| 23281 - -| hkdf -| hmac_sha2_512 -| native -| sodium -| 86984 -| hash2 -| 34392 - -| hkdf -| hmac_sha2_512 -| wasip2 -| bearssl -| 69846 -| bearssl -| 69846 - -| hkdf -| hmac_sha2_512 -| wasip3 -| bearssl -| 79474 -| bearssl -| 79474 - -| hkdf -| hmac_sha2_512 -| emscripten -| bearssl -| 23792 -| bearssl -| 23792 - -| pbkdf2 -| hmac_sha2_256 -| native -| openssl -| 3049176 -| hash2 -| 34280 - -| pbkdf2 -| hmac_sha2_256 -| wasip2 -| hash2 -| 75164 -| hash2 -| 75164 - -| pbkdf2 -| hmac_sha2_256 -| wasip3 -| hash2 -| 84808 -| hash2 -| 84808 - -| pbkdf2 -| hmac_sha2_256 -| emscripten -| hash2 -| 29235 -| hash2 -| 29235 - -| pbkdf2 -| hmac_sha2_512 -| native -| openssl -| 3049176 -| hash2 -| 34280 - -| pbkdf2 -| hmac_sha2_512 -| wasip2 -| hash2 -| 78699 -| hash2 -| 78699 - -| pbkdf2 -| hmac_sha2_512 -| wasip3 -| hash2 -| 88343 -| hash2 -| 88343 - -| pbkdf2 -| hmac_sha2_512 -| emscripten -| hash2 -| 32747 -| hash2 -| 32747 - -| argon2id -| - -| native -| sodium -| 87872 -| sodium -| 87872 - -| argon2id -| - -| wasip2 -| sodium -| 90242 -| sodium -| 90242 - -| argon2id -| - -| wasip3 -| sodium -| 99987 -| sodium -| 99987 - -| argon2id -| - -| emscripten -| sodium -| 39690 -| sodium -| 39690 - -| scrypt -| - -| native -| sodium -| 87384 -| sodium -| 87384 - -| scrypt -| - -| wasip2 -| sodium -| 77592 -| sodium -| 77592 - -| scrypt -| - -| wasip3 -| sodium -| 87332 -| sodium -| 87332 - -| scrypt -| - -| emscripten -| sodium -| 29540 -| sodium -| 29540 -|=== diff --git a/doc/measurements.json b/doc/measurements.json index 1f7b4f9..5fe5989 100644 --- a/doc/measurements.json +++ b/doc/measurements.json @@ -1,14 +1,14 @@ { - "about": "webcpp::hash's measured table (spec section 4.2): the size of one program per cell of doc/capabilities.json on each target, and its throughput, which detail/ranking.hpp orders the backends by. Written by tools/hash/measure.py --write; the documentation renders from it.", + "about": "webcpp::hash's measured table, a reference measured once, on 2026-11-16, that decides nothing: the size of one program per cell of doc/capabilities.json on each target, and its throughput. Every key derivation's default is backends::hash2, argon2id's and scrypt's backends::sodium, whatever this table says (spec section 4.1); no lane measures it again. Written by the superproject's tools/hash/measure.py --write (webcpp at 76b1730), from the programs of webcpp::hash's test/measure (hash at 46b1989), both since retired; tools/hash/doc_tables.py renders doc/measurements.adoc from it.", "version": 1, "layout": { - "schema": "This description. The version of the layout is \"version\"; a change of layout raises it. Written only by tools/hash/measure.py; \"digest\" is the SHA-256 of the file without it, which the measure lane checks.", + "schema": "This description. The version of the layout is \"version\"; a change of layout raises it. \"digest\" is the SHA-256 of the file without it, which tools/hash/doc_tables.py --check checks, so that the reference is never edited by hand.", "date, machine, load_average_before_after, loaded, rules.loaded": "when and where the measurements were made; loaded says whether the machine was shared and loaded", "toolchains, runtimes, strip, pins, builds": "the compiler per target, wasmtime and node, the strip of the native sizes, each backend's library and pin (from doc/capabilities.json), and the two builds", - "native_toolchain": "what the native orders were measured with: the compiler, the host's operating system and processor, and the strip; the lane compares the native size orders only where its own is the same", + "native_toolchain": "what the native rows were measured with: the compiler, the host's operating system and processor, and the strip", "workloads": "per function, what one computation does (spec 4.2)", "records[]": "one per cell and target: operation (the function of doc/capabilities.json), hmac (or null), backend, target, size_bytes, result (the hexadecimal output, the same for every backend and target of an operation and hmac), throughput (repetitions, invocations, runs_per_invocation, invocation_medians_ns, median_ns, min_ns, max_ns: nanoseconds per computation) or null with throughput_absent saying why. operation, hmac, backend and target are the keys of doc/measurements.throughput.json's cases too, which the documentation joins on them; constant time is doc/capabilities.json's.", - "orders[]": "per operation, hmac and target: by_size and by_throughput, the backends that have it there in order, and throughput_from, the target whose throughput ordered it; detail/ranking.hpp is generated from the rows of the key derivations, one per operation (hkdf_extract and hkdf_expand their own)", + "orders[]": "per operation, hmac and target: by_size and by_throughput, the backends that have it there in order, and throughput_from, the target whose throughput ordered it, as measured; they order nothing in the library", "rules": "how sizes, throughput and orders are made" }, "date": "2026-11-16", @@ -9790,5 +9790,5 @@ "throughput_from": "emscripten" } ], - "digest": "sha256:3ab7b82c8bf65f3534caa005e1408722de9fc0d72701613fa14032512f028f25" + "digest": "sha256:834694bace38b92003311c79f06c5a3956feb40232b25a801f724c99ea27f48d" } diff --git a/doc/password_hashing.adoc b/doc/password_hashing.adoc index 0c6fd55..023b199 100644 --- a/doc/password_hashing.adoc +++ b/doc/password_hashing.adoc @@ -67,7 +67,7 @@ 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 (<> has the measured times), +* WebAssembly is slower than native (<> has the measured times), and a browser tab may not get a gigabyte: measure on the target. *Pitfalls.* diff --git a/doc/profile.adoc b/doc/profile.adoc deleted file mode 100644 index ed8787b..0000000 --- a/doc/profile.adoc +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -[#hash-choosing-backend] -== 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 call that names no -backend takes the default, which comes from the build: which libraries the -program links, the target, the profile and the overrides it defines, and a -table of webcpp's own measurements. This chapter says how that default is -chosen, what each backend does with secrets and memory, and, from the -committed data, which backend has which function on which target, what each -costs in size and time, and what each allocates. - -[#hash-profile] -=== The profile and the overrides - -One define, the *profile*, changes every default at once. A program sets it -for hash alone, or for every webcpp library through webcpp's own profile: - -[cols="2,1,4"] -|=== -| The program defines | Profile | The default of each function - -| nothing -| auto -| natively the fastest linked backend; on WebAssembly the smallest - -| `WEBCPP_HASH_PROFILE_FASTEST` (or `WEBCPP_PROFILE_FASTEST`) -| fastest -| the linked backend with the best measured throughput on this target - -| `WEBCPP_HASH_PROFILE_SMALLEST` (or `WEBCPP_PROFILE_SMALLEST`) -| smallest -| the linked backend whose measured program is smallest on this target - -| `WEBCPP_HASH_PROFILE_PORTABLE` (or `WEBCPP_PROFILE_PORTABLE`) -| portable -| the first that has the function of `hash2`, `sodium`, `bearssl`: the same -code on every target, never OpenSSL, which Emscripten lacks - -| `WEBCPP_HASH_PROFILE_BACKEND_` (`HASH2`, `SODIUM`, `BEARSSL`, `OPENSSL`) -| a named backend -| that backend for every function it has, if linked; the others as auto -|=== - -Two profiles of hash, or two of webcpp's, stop the build; hash's own wins over -webcpp's. An *override* names the backend of one algorithm, whatever the -profile: `WEBCPP_HASH_DEFAULT_BACKEND__`, as -`WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM` or -`WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2`, for the algorithms `HKDF`, -`PBKDF2`, `ARGON2ID` and `SCRYPT`. An override wins over every profile; an -override of a backend that lacks the function, or that the program does not -link, stops the build with that backend's message, and so does OpenSSL chosen -on Emscripten. A program defines these for every translation unit, in its -Jamfile (`WEBCPP_HASH_PROFILE_SMALLEST`); on MSVC the linker refuses -two translation units that choose differently. - -The default is chosen per function: `hkdf_extract` and `hkdf_expand` each have -their own measured order, never a backend that has HKDF only whole (BearSSL), -so that no profile makes them refuse. `backends::hash2` is always a candidate, -so every function has a default with no library linked. The order of each -profile on each target, for each function, is in the function's section (as -<>), generated from the measured data below; the data is measured -again at every move of a C library's pin, and an order moves only on a clear -difference, so that a default does not flip on noise. - -[#hash-backend-conditions] -=== 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: - -[cols="1,4"] -|=== -| 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 context before each call returns. BearSSL's own -temporaries on its stack, the pseudorandom key of `br_hkdf_flip` and the -padded keys of its HMAC, 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. 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. - -| `xkcp` -| Hashes without a secret of their own; it allocates nothing. - -| `blake3` -| Allocates nothing. Its keyed and `derive_key` modes hold the key in the -object's state until it is destroyed, without wiping it (<>). -|=== - -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. - -[#hash-measured] -=== 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; the measured table, `doc/measurements.json`, the size of a -program per backend and target and the throughput of each; 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. - -include::generated/measured.adoc[] diff --git a/include/webcpp/hash/argon2.hpp b/include/webcpp/hash/argon2.hpp index ccc8882..5c8bd76 100644 --- a/include/webcpp/hash/argon2.hpp +++ b/include/webcpp/hash/argon2.hpp @@ -86,8 +86,7 @@ inline constexpr std::size_t argon2id_memory_unit = 1024; Argon2id version 0x13 (RFC 9106) with one lane, no secret and no associated data: fills `output_bytes` from `password_bytes` and `salt_bytes`. - @tparam Backend The backend; by default @ref default_backend of `kdfs::argon2id` (spec 4.1): - the one an override `WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_` names, else + @tparam Backend The backend; by default @ref default_backend of `kdfs::argon2id` (spec 4.1), `backends::sodium`, the only one that has it. @param 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). @@ -147,9 +146,8 @@ template > // backends::sodium when the program links libsodium, after the presets, which its header checks // against libsodium's macros: a program that includes only this header gets argon2id's default -// backend complete here. Also when an override names libsodium, whose header then stops with its -// "needs" message if the program does not link it (spec 5.7). -#if defined(WEBCPP_HASH_HAS_SODIUM) || defined(WEBCPP_HASH_DETAIL_OVERRIDES_SODIUM) +// backend complete here. +#ifdef WEBCPP_HASH_HAS_SODIUM #include #endif diff --git a/include/webcpp/hash/config.hpp b/include/webcpp/hash/config.hpp index f72451f..f542a2e 100644 --- a/include/webcpp/hash/config.hpp +++ b/include/webcpp/hash/config.hpp @@ -61,50 +61,6 @@ b2 defines it to 1 itself. Refused on Emscripten, where OpenSSL is not built. */ #define WEBCPP_HASH_HAS_OPENSSL 1 -/** Defined by a program to choose the fastest linked backend for every algorithm. */ -#define WEBCPP_HASH_PROFILE_FASTEST -#undef WEBCPP_HASH_PROFILE_FASTEST -/** Defined by a program to choose the backend that gives the smallest binary. */ -#define WEBCPP_HASH_PROFILE_SMALLEST -#undef WEBCPP_HASH_PROFILE_SMALLEST -/** Defined by a program to choose the backend that exists on every target. */ -#define WEBCPP_HASH_PROFILE_PORTABLE -#undef WEBCPP_HASH_PROFILE_PORTABLE -/** Defined by a program to choose backends::hash2 for every algorithm. */ -#define WEBCPP_HASH_PROFILE_BACKEND_HASH2 -#undef WEBCPP_HASH_PROFILE_BACKEND_HASH2 -/** - Defined by a program to choose backends::sodium for every algorithm it has, when the program - links it; the others keep the default without a profile. -*/ -#define WEBCPP_HASH_PROFILE_BACKEND_SODIUM -#undef WEBCPP_HASH_PROFILE_BACKEND_SODIUM -/** - Defined by a program to choose backends::bearssl for every function it has, when the program - links it (`hkdf`, not its two steps alone); the others keep the default without a profile. -*/ -#define WEBCPP_HASH_PROFILE_BACKEND_BEARSSL -#undef WEBCPP_HASH_PROFILE_BACKEND_BEARSSL -/** - Defined by a program to choose backends::openssl for every algorithm it has, when the program - links it; the others keep the default without a profile. Refused on Emscripten. -*/ -#define WEBCPP_HASH_PROFILE_BACKEND_OPENSSL -#undef WEBCPP_HASH_PROFILE_BACKEND_OPENSSL -/** - webcpp's umbrella profile, for every webcpp library: the fastest, as - `WEBCPP_HASH_PROFILE_FASTEST`, unless the program gives webcpp::hash a profile of its own. -*/ -#define WEBCPP_PROFILE_FASTEST -#undef WEBCPP_PROFILE_FASTEST -/** webcpp's umbrella profile: the smallest, as `WEBCPP_HASH_PROFILE_SMALLEST`. */ -#define WEBCPP_PROFILE_SMALLEST -#undef WEBCPP_PROFILE_SMALLEST -/** webcpp's umbrella profile: the portable, as `WEBCPP_HASH_PROFILE_PORTABLE`. */ -#define WEBCPP_PROFILE_PORTABLE -#undef WEBCPP_PROFILE_PORTABLE -// ... and the overrides WEBCPP_HASH_DEFAULT_BACKEND__, one per algorithm of -// doc/capabilities.json and backend, in detail/overrides.hpp, which kdf.hpp includes (spec 4.1). #endif #if !defined(WEBCPP_HAS_EXCEPTIONS) && !defined(WEBCPP_HASH_NO_EXCEPTIONS) @@ -122,84 +78,6 @@ #if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_HAS_OPENSSL) #error "webcpp::hash: OpenSSL is not built for Emscripten. In the program's Jamfile, remove /webcpp/hash//openssl: hkdf and pbkdf2 then run on backends::hash2." #endif -#if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define." -#endif -// The profile's refusals (spec 4.1): two library profiles, or two umbrella profiles, name both -// defines. A library profile beside an umbrella profile is not an error: the library's wins. The -// overrides' refusals are in detail/overrides.hpp, which kdf.hpp includes. -#if defined(WEBCPP_HASH_PROFILE_FASTEST) && defined(WEBCPP_HASH_PROFILE_SMALLEST) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_SMALLEST are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_FASTEST) && defined(WEBCPP_HASH_PROFILE_PORTABLE) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_PORTABLE are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_FASTEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_HASH2) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_BACKEND_HASH2 are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_FASTEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_BACKEND_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_FASTEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_BACKEND_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_FASTEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_BACKEND_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_SMALLEST) && defined(WEBCPP_HASH_PROFILE_PORTABLE) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_SMALLEST and WEBCPP_HASH_PROFILE_PORTABLE are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_SMALLEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_HASH2) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_SMALLEST and WEBCPP_HASH_PROFILE_BACKEND_HASH2 are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_SMALLEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_SMALLEST and WEBCPP_HASH_PROFILE_BACKEND_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_SMALLEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_SMALLEST and WEBCPP_HASH_PROFILE_BACKEND_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_SMALLEST) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_SMALLEST and WEBCPP_HASH_PROFILE_BACKEND_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_PORTABLE) && defined(WEBCPP_HASH_PROFILE_BACKEND_HASH2) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_PORTABLE and WEBCPP_HASH_PROFILE_BACKEND_HASH2 are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_PORTABLE) && defined(WEBCPP_HASH_PROFILE_BACKEND_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_PORTABLE and WEBCPP_HASH_PROFILE_BACKEND_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_PORTABLE) && defined(WEBCPP_HASH_PROFILE_BACKEND_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_PORTABLE and WEBCPP_HASH_PROFILE_BACKEND_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_PORTABLE) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_PORTABLE and WEBCPP_HASH_PROFILE_BACKEND_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_BACKEND_HASH2) && defined(WEBCPP_HASH_PROFILE_BACKEND_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_HASH2 and WEBCPP_HASH_PROFILE_BACKEND_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_BACKEND_HASH2) && defined(WEBCPP_HASH_PROFILE_BACKEND_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_HASH2 and WEBCPP_HASH_PROFILE_BACKEND_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_BACKEND_HASH2) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_HASH2 and WEBCPP_HASH_PROFILE_BACKEND_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_BACKEND_SODIUM) && defined(WEBCPP_HASH_PROFILE_BACKEND_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_SODIUM and WEBCPP_HASH_PROFILE_BACKEND_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_BACKEND_SODIUM) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_SODIUM and WEBCPP_HASH_PROFILE_BACKEND_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_PROFILE_BACKEND_BEARSSL) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_BEARSSL and WEBCPP_HASH_PROFILE_BACKEND_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_PROFILE_FASTEST) && defined(WEBCPP_PROFILE_SMALLEST) -#error "webcpp::hash: WEBCPP_PROFILE_FASTEST and WEBCPP_PROFILE_SMALLEST are both defined. Keep one." -#endif -#if defined(WEBCPP_PROFILE_FASTEST) && defined(WEBCPP_PROFILE_PORTABLE) -#error "webcpp::hash: WEBCPP_PROFILE_FASTEST and WEBCPP_PROFILE_PORTABLE are both defined. Keep one." -#endif -#if defined(WEBCPP_PROFILE_SMALLEST) && defined(WEBCPP_PROFILE_PORTABLE) -#error "webcpp::hash: WEBCPP_PROFILE_SMALLEST and WEBCPP_PROFILE_PORTABLE are both defined. Keep one." -#endif // clang-format on namespace webcpp::hash::backends { @@ -221,9 +99,8 @@ namespace webcpp::hash::kdfs { HKDF, RFC 5869. A tag, declared and never defined: it names the algorithm to - @ref webcpp::hash::backend_has_v, @ref webcpp::hash::default_backend and the overrides - `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_`, which apply to `hkdf_extract`, `hkdf_expand` and - `hkdf`; as an operation it is `hkdf`, both steps at once. + @ref webcpp::hash::backend_has_v and @ref webcpp::hash::default_backend; as an operation it is + `hkdf`, both steps at once. */ struct hkdf; /** @@ -231,8 +108,7 @@ struct hkdf; A tag, declared and never defined: @ref webcpp::hash::backend_has_v and @ref webcpp::hash::default_backend answer for the step through it, so that a backend that has HKDF only - whole (`backends::bearssl`) is never its default. The step has its own measured ranking and - follows HKDF's override. + whole (`backends::bearssl`) says it lacks the step. */ struct hkdf_extract; /** @@ -244,113 +120,25 @@ struct hkdf_expand; /** PBKDF2, RFC 8018, the operation `pbkdf2`. - A tag, declared and never defined, for @ref webcpp::hash::backend_has_v, - @ref webcpp::hash::default_backend and the overrides `WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_`. + A tag, declared and never defined, for @ref webcpp::hash::backend_has_v and + @ref webcpp::hash::default_backend. */ struct pbkdf2; /** Argon2id, RFC 9106, with one lane, the operation `argon2id` (on `backends::sodium` alone). - A tag, declared and never defined, for @ref webcpp::hash::backend_has_v (over no hmac: `void`), - @ref webcpp::hash::default_backend and the overrides - `WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_`. + A tag, declared and never defined, for @ref webcpp::hash::backend_has_v (over no hmac: `void`) + and @ref webcpp::hash::default_backend. */ struct argon2id; /** scrypt, RFC 7914, the operation `scrypt` (on `backends::sodium` alone). - A tag, declared and never defined, for @ref webcpp::hash::backend_has_v (over no hmac: `void`), - @ref webcpp::hash::default_backend and the overrides `WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_`. + A tag, declared and never defined, for @ref webcpp::hash::backend_has_v (over no hmac: `void`) + and @ref webcpp::hash::default_backend. */ struct scrypt; } // namespace webcpp::hash::kdfs -namespace webcpp::hash::detail::profiles { - -/** No profile defined: natively `fastest`, on WebAssembly `smallest` (spec 4.1). */ -struct automatic; -/** The linked backend with the best measured throughput on this target. */ -struct fastest; -/** The linked backend with the smallest measured program on this target. */ -struct smallest; -/** The first of `portable_order` that has the algorithm: the same code on every target. */ -struct portable; -/** - A named backend for every algorithm it has, linked; `automatic`'s choice for the others. - - @tparam Backend A backend of `backends`. -*/ -template -struct named; - -} // namespace webcpp::hash::detail::profiles - -namespace webcpp::hash::detail { - -// The profile in force: the library's, else webcpp's umbrella, else auto (spec 4.1). On MSVC the -// linker refuses two translation units of one program that choose differently. -#ifdef WEBCPP_HASH_PROFILE_FASTEST -/** The profile in force: fastest. */ -using profile = profiles::fastest; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "fastest" -#elif defined(WEBCPP_HASH_PROFILE_SMALLEST) -/** The profile in force: smallest. */ -using profile = profiles::smallest; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "smallest" -#elif defined(WEBCPP_HASH_PROFILE_PORTABLE) -/** The profile in force: portable. */ -using profile = profiles::portable; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "portable" -#elif defined(WEBCPP_HASH_PROFILE_BACKEND_HASH2) -/** The profile in force: backends::hash2 named. */ -using profile = profiles::named; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "hash2" -#elif defined(WEBCPP_HASH_PROFILE_BACKEND_SODIUM) -/** The profile in force: backends::sodium named. */ -using profile = profiles::named; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "sodium" -#elif defined(WEBCPP_HASH_PROFILE_BACKEND_BEARSSL) -/** The profile in force: backends::bearssl named. */ -using profile = profiles::named; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "bearssl" -#elif defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -/** The profile in force: backends::openssl named. */ -using profile = profiles::named; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "openssl" -#elif defined(WEBCPP_PROFILE_FASTEST) -/** The profile in force: fastest, by webcpp's umbrella. */ -using profile = profiles::fastest; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "fastest" -#elif defined(WEBCPP_PROFILE_SMALLEST) -/** The profile in force: smallest, by webcpp's umbrella. */ -using profile = profiles::smallest; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "smallest" -#elif defined(WEBCPP_PROFILE_PORTABLE) -/** The profile in force: portable, by webcpp's umbrella. */ -using profile = profiles::portable; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "portable" -#else -/** The profile in force: none defined, auto. */ -using profile = profiles::automatic; -/** The name of the profile in force, which MSVC's linker compares between translation units. */ -#define WEBCPP_HASH_DETAIL_PROFILE_NAME "auto" -#endif - -#ifdef _MSC_VER -#pragma detect_mismatch("webcpp_hash_profile", WEBCPP_HASH_DETAIL_PROFILE_NAME) -#endif - -} // namespace webcpp::hash::detail - #endif // WEBCPP_HASH_CONFIG_HPP diff --git a/include/webcpp/hash/detail/engines.hpp b/include/webcpp/hash/detail/engines.hpp index 4672575..9c35171 100644 --- a/include/webcpp/hash/detail/engines.hpp +++ b/include/webcpp/hash/detail/engines.hpp @@ -172,7 +172,13 @@ struct scrypt_limits { */ template struct argon2id_engine { - static_assert(always_false, + // backends::sodium, the default, reaches this template only when the program does not link + // libsodium, whose header specialises it: the refusal is then sodium.hpp's own (spec 5.7). + static_assert(!std::is_same_v, + "webcpp::hash: backends::sodium, argon2id and scrypt need libsodium. Add " + "/third_party//sodium to the program's Jamfile: exe app : app.cpp " + "/webcpp/hash//hash /third_party//sodium ;"); + static_assert(std::is_same_v, "webcpp::hash: argon2id is in backends::sodium alone. Name backends::sodium " "and add /third_party//sodium to the program's Jamfile."); @@ -205,7 +211,13 @@ struct argon2id_engine { */ template struct scrypt_engine { - static_assert(always_false, + // backends::sodium, the default, reaches this template only when the program does not link + // libsodium, whose header specialises it: the refusal is then sodium.hpp's own (spec 5.7). + static_assert(!std::is_same_v, + "webcpp::hash: backends::sodium, argon2id and scrypt need libsodium. Add " + "/third_party//sodium to the program's Jamfile: exe app : app.cpp " + "/webcpp/hash//hash /third_party//sodium ;"); + static_assert(std::is_same_v, "webcpp::hash: scrypt is in backends::sodium alone. Name backends::sodium and " "add /third_party//sodium to the program's Jamfile."); diff --git a/include/webcpp/hash/detail/overrides.hpp b/include/webcpp/hash/detail/overrides.hpp deleted file mode 100644 index 2cddde2..0000000 --- a/include/webcpp/hash/detail/overrides.hpp +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -// The per-algorithm overrides of the default backend (spec section 4.1), one block per overridable -// algorithm of doc/capabilities.json and one define per backend of it that has a tag: -// WEBCPP_HASH_DEFAULT_BACKEND__ names the backend of every function of the -// algorithm, whatever the profile. Two overrides of one algorithm, and OpenSSL's on Emscripten, -// are an #error. An override names its backend even where the backend lacks the function over -// the hmac used: the call then stops with that backend's refusal (spec 3.3); and when the -// program does not link it, hkdf.hpp and pbkdf2.hpp include its header, which stops with its -// "needs" message (spec 5.7). Generated by tools/hash/measure.py --overrides from -// doc/capabilities.json: do not edit; test/overrides_list_test.cpp checks it against the table -// too. kdf.hpp includes it, the one reader of override_choice, so the overrides' refusals come -// with every key derivation header. - -#ifndef WEBCPP_HASH_DETAIL_OVERRIDES_HPP -#define WEBCPP_HASH_DETAIL_OVERRIDES_HPP - -#include - -/** The spelling of `x` as a string literal, unexpanded. @param x The tokens. */ -#define WEBCPP_HASH_DETAIL_OVERRIDE_STRING_I(x) #x -/** The spelling of `x` as a string literal, once `x` is expanded. @param x The macro. */ -#define WEBCPP_HASH_DETAIL_OVERRIDE_STRING(x) WEBCPP_HASH_DETAIL_OVERRIDE_STRING_I(x) - -namespace webcpp::hash::detail { - -/** - The backend an override names for `Algorithm`, `void` without one. - - @tparam Algorithm A tag of `kdfs`, the algorithm (not one of its steps). -*/ -template -struct override_choice { - /** No override. */ - using type = void; -}; - -// HKDF: hkdf_extract, hkdf_expand, hkdf. -// clang-format off -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL) && defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define." -#endif -// clang-format on -#ifdef WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2 -#define WEBCPP_HASH_DETAIL_OVERRIDE_HKDF hash2 -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM) -#define WEBCPP_HASH_DETAIL_OVERRIDE_HKDF sodium -#define WEBCPP_HASH_DETAIL_OVERRIDES_SODIUM -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_HKDF bearssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_BEARSSL -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_HKDF openssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_OPENSSL -#endif -#ifdef WEBCPP_HASH_DETAIL_OVERRIDE_HKDF -/** The backend the override of HKDF names. */ -template <> -struct override_choice { - /** The named backend. */ - using type = backends::WEBCPP_HASH_DETAIL_OVERRIDE_HKDF; -}; -#ifdef _MSC_VER -#pragma detect_mismatch("webcpp_hash_default_backend_hkdf", \ - WEBCPP_HASH_DETAIL_OVERRIDE_STRING(WEBCPP_HASH_DETAIL_OVERRIDE_HKDF)) -#endif -#elif defined(_MSC_VER) -#pragma detect_mismatch("webcpp_hash_default_backend_hkdf", "none") -#endif - -// PBKDF2: pbkdf2. -// clang-format off -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL) && defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL and WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define." -#endif -// clang-format on -#ifdef WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2 -#define WEBCPP_HASH_DETAIL_OVERRIDE_PBKDF2 hash2 -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM) -#define WEBCPP_HASH_DETAIL_OVERRIDE_PBKDF2 sodium -#define WEBCPP_HASH_DETAIL_OVERRIDES_SODIUM -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_PBKDF2 bearssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_BEARSSL -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_PBKDF2 openssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_OPENSSL -#endif -#ifdef WEBCPP_HASH_DETAIL_OVERRIDE_PBKDF2 -/** The backend the override of PBKDF2 names. */ -template <> -struct override_choice { - /** The named backend. */ - using type = backends::WEBCPP_HASH_DETAIL_OVERRIDE_PBKDF2; -}; -#ifdef _MSC_VER -#pragma detect_mismatch("webcpp_hash_default_backend_pbkdf2", \ - WEBCPP_HASH_DETAIL_OVERRIDE_STRING(WEBCPP_HASH_DETAIL_OVERRIDE_PBKDF2)) -#endif -#elif defined(_MSC_VER) -#pragma detect_mismatch("webcpp_hash_default_backend_pbkdf2", "none") -#endif - -// ARGON2ID: argon2id. -// clang-format off -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_BEARSSL) && defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_BEARSSL and WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define." -#endif -// clang-format on -#ifdef WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_HASH2 -#define WEBCPP_HASH_DETAIL_OVERRIDE_ARGON2ID hash2 -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_SODIUM) -#define WEBCPP_HASH_DETAIL_OVERRIDE_ARGON2ID sodium -#define WEBCPP_HASH_DETAIL_OVERRIDES_SODIUM -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_BEARSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_ARGON2ID bearssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_BEARSSL -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_ARGON2ID openssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_OPENSSL -#endif -#ifdef WEBCPP_HASH_DETAIL_OVERRIDE_ARGON2ID -/** The backend the override of ARGON2ID names. */ -template <> -struct override_choice { - /** The named backend. */ - using type = backends::WEBCPP_HASH_DETAIL_OVERRIDE_ARGON2ID; -}; -#ifdef _MSC_VER -#pragma detect_mismatch("webcpp_hash_default_backend_argon2id", \ - WEBCPP_HASH_DETAIL_OVERRIDE_STRING(WEBCPP_HASH_DETAIL_OVERRIDE_ARGON2ID)) -#endif -#elif defined(_MSC_VER) -#pragma detect_mismatch("webcpp_hash_default_backend_argon2id", "none") -#endif - -// SCRYPT: scrypt. -// clang-format off -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_SODIUM) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_SODIUM are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_HASH2) && defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_BEARSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_BEARSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_SODIUM) && defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_SODIUM and WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_BEARSSL) && defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_BEARSSL and WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL are both defined. Keep one." -#endif -#if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define." -#endif -// clang-format on -#ifdef WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_HASH2 -#define WEBCPP_HASH_DETAIL_OVERRIDE_SCRYPT hash2 -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_SODIUM) -#define WEBCPP_HASH_DETAIL_OVERRIDE_SCRYPT sodium -#define WEBCPP_HASH_DETAIL_OVERRIDES_SODIUM -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_BEARSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_SCRYPT bearssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_BEARSSL -#elif defined(WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL) -#define WEBCPP_HASH_DETAIL_OVERRIDE_SCRYPT openssl -#define WEBCPP_HASH_DETAIL_OVERRIDES_OPENSSL -#endif -#ifdef WEBCPP_HASH_DETAIL_OVERRIDE_SCRYPT -/** The backend the override of SCRYPT names. */ -template <> -struct override_choice { - /** The named backend. */ - using type = backends::WEBCPP_HASH_DETAIL_OVERRIDE_SCRYPT; -}; -#ifdef _MSC_VER -#pragma detect_mismatch("webcpp_hash_default_backend_scrypt", \ - WEBCPP_HASH_DETAIL_OVERRIDE_STRING(WEBCPP_HASH_DETAIL_OVERRIDE_SCRYPT)) -#endif -#elif defined(_MSC_VER) -#pragma detect_mismatch("webcpp_hash_default_backend_scrypt", "none") -#endif - -} // namespace webcpp::hash::detail - -#endif // WEBCPP_HASH_DETAIL_OVERRIDES_HPP diff --git a/include/webcpp/hash/detail/ranking.hpp b/include/webcpp/hash/detail/ranking.hpp deleted file mode 100644 index b3ad129..0000000 --- a/include/webcpp/hash/detail/ranking.hpp +++ /dev/null @@ -1,672 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -// Generated by tools/hash/measure.py --write from doc/measurements.json: do not edit. Per target -// and key derivation, the backends ordered by their programs' size and by their throughput -// (spec section 4.2); the measure lane fails when this file differs from what the data renders. - -#ifndef WEBCPP_HASH_DETAIL_RANKING_HPP -#define WEBCPP_HASH_DETAIL_RANKING_HPP - -#include -#include - -namespace webcpp::hash::detail { - -/** - An ordered list of backends, the first preferred. - - @tparam B The backends, tags of `backends`. -*/ -template -struct backend_list {}; - -/** - The backends of the portable profile, in its order: those present on every target (spec 4.1). -*/ -using portable_order = backend_list; - -#ifdef WEBCPP_TARGET_WASIP2 - -/** - The measured orders of the backends of a key derivation on wasip2 (spec 4.2): `by_size`, the - smallest program first, and `by_throughput`, the fastest first. This primary template is an - algorithm the table does not measure: the table's order of backends. - - @tparam Algorithm The algorithm's tag, as `kdfs::hkdf`. @tparam Hmac The hmac of a key - derivation, or `void`. -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on wasip2, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2, sodium, openssl; by throughput hash2, sodium, openssl (measured on wasip2). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on wasip2, over hmac_sha2_512: by size hash2, sodium, openssl; by throughput hash2, - sodium, openssl (measured on wasip2). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on wasip2, over hmac_sha2_256, and over every hmac the table does not measure: by size - sodium, hash2, openssl; by throughput hash2, sodium, openssl (measured on wasip2). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on wasip2, over hmac_sha2_512: by size sodium, hash2, openssl; by throughput hash2, - sodium, openssl (measured on wasip2). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on wasip2, over hmac_sha2_256, and over every hmac the table does not measure: by size - bearssl, sodium, hash2, openssl; by throughput hash2, bearssl, sodium, openssl (measured on - wasip2). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on wasip2, over hmac_sha2_512: by size bearssl, sodium, hash2, openssl; by throughput bearssl, - hash2, sodium, openssl (measured on wasip2). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on wasip2, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2, openssl; by throughput hash2, openssl (measured on wasip2). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on wasip2, over hmac_sha2_512: by size hash2, openssl; by throughput openssl, hash2 - (measured on wasip2). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - argon2id on wasip2, which takes no hmac: by size sodium; by throughput sodium (measured on wasip2). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - scrypt on wasip2, which takes no hmac: by size sodium; by throughput sodium (measured on wasip2). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -#elif defined(WEBCPP_TARGET_WASIP3) - -/** - The measured orders of the backends of a key derivation on wasip3 (spec 4.2): `by_size`, the - smallest program first, and `by_throughput`, the fastest first. This primary template is an - algorithm the table does not measure: the table's order of backends. - - @tparam Algorithm The algorithm's tag, as `kdfs::hkdf`. @tparam Hmac The hmac of a key - derivation, or `void`. -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on wasip3, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2, sodium, openssl; by throughput hash2, sodium, openssl (measured on wasip3). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on wasip3, over hmac_sha2_512: by size hash2, sodium, openssl; by throughput hash2, - sodium, openssl (measured on wasip3). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on wasip3, over hmac_sha2_256, and over every hmac the table does not measure: by size - sodium, hash2, openssl; by throughput hash2, sodium, openssl (measured on wasip3). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on wasip3, over hmac_sha2_512: by size sodium, hash2, openssl; by throughput hash2, - sodium, openssl (measured on wasip3). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on wasip3, over hmac_sha2_256, and over every hmac the table does not measure: by size - bearssl, sodium, hash2, openssl; by throughput hash2, bearssl, sodium, openssl (measured on - wasip3). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on wasip3, over hmac_sha2_512: by size bearssl, sodium, hash2, openssl; by throughput hash2, - bearssl, sodium, openssl (measured on wasip3). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on wasip3, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2, openssl; by throughput hash2, openssl (measured on wasip3). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on wasip3, over hmac_sha2_512: by size hash2, openssl; by throughput openssl, hash2 - (measured on wasip3). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - argon2id on wasip3, which takes no hmac: by size sodium; by throughput sodium (measured on wasip3). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - scrypt on wasip3, which takes no hmac: by size sodium; by throughput sodium (measured on wasip3). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -#elif defined(WEBCPP_TARGET_EMSCRIPTEN) - -/** - The measured orders of the backends of a key derivation on emscripten (spec 4.2): `by_size`, the - smallest program first, and `by_throughput`, the fastest first. This primary template is an - algorithm the table does not measure: the table's order of backends. - - @tparam Algorithm The algorithm's tag, as `kdfs::hkdf`. @tparam Hmac The hmac of a key - derivation, or `void`. -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on emscripten, over hmac_sha2_256, and over every hmac the table does not measure: by - size hash2, sodium; by throughput hash2, sodium (measured on emscripten). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on emscripten, over hmac_sha2_512: by size hash2, sodium; by throughput hash2, sodium - (measured on emscripten). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on emscripten, over hmac_sha2_256, and over every hmac the table does not measure: by - size sodium, hash2; by throughput sodium, hash2 (measured on emscripten). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on emscripten, over hmac_sha2_512: by size sodium, hash2; by throughput sodium, hash2 - (measured on emscripten). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on emscripten, over hmac_sha2_256, and over every hmac the table does not measure: by size - bearssl, sodium, hash2; by throughput sodium, hash2, bearssl (measured on emscripten). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on emscripten, over hmac_sha2_512: by size bearssl, sodium, hash2; by throughput sodium, - hash2, bearssl (measured on emscripten). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on emscripten, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2; by throughput hash2 (measured on emscripten). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on emscripten, over hmac_sha2_512: by size hash2; by throughput hash2 (measured on - emscripten). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - argon2id on emscripten, which takes no hmac: by size sodium; by throughput sodium (measured on - emscripten). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - scrypt on emscripten, which takes no hmac: by size sodium; by throughput sodium (measured on - emscripten). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -#else // native - -/** - The measured orders of the backends of a key derivation on native (spec 4.2): `by_size`, the - smallest program first, and `by_throughput`, the fastest first. This primary template is an - algorithm the table does not measure: the table's order of backends. - - @tparam Algorithm The algorithm's tag, as `kdfs::hkdf`. @tparam Hmac The hmac of a key - derivation, or `void`. -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on native, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2, sodium, openssl; by throughput hash2, sodium, openssl (measured on native). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_extract on native, over hmac_sha2_512: by size hash2, sodium, openssl; by throughput sodium, - hash2, openssl (measured on native). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on native, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2, sodium, openssl; by throughput sodium, hash2, openssl (measured on native). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf_expand on native, over hmac_sha2_512: by size hash2, sodium, openssl; by throughput sodium, - openssl, hash2 (measured on native). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on native, over hmac_sha2_256, and over every hmac the table does not measure: by size hash2, - bearssl, sodium, openssl; by throughput sodium, hash2, openssl, bearssl (measured on native). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - hkdf on native, over hmac_sha2_512: by size hash2, bearssl, sodium, openssl; by throughput sodium, - openssl, hash2, bearssl (measured on native). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on native, over hmac_sha2_256, and over every hmac the table does not measure: by size - hash2, openssl; by throughput openssl, hash2 (measured on native). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - pbkdf2 on native, over hmac_sha2_512: by size hash2, openssl; by throughput openssl, hash2 - (measured on native). -*/ -template <> -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - argon2id on native, which takes no hmac: by size sodium; by throughput sodium (measured on native). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -/** - scrypt on native, which takes no hmac: by size sodium; by throughput sodium (measured on native). -*/ -template -struct ranking { - /** The smallest program first. */ - using by_size = - backend_list; - /** The fastest first. */ - using by_throughput = - backend_list; -}; - -#endif - -} // namespace webcpp::hash::detail - -#endif // WEBCPP_HASH_DETAIL_RANKING_HPP diff --git a/include/webcpp/hash/hkdf.hpp b/include/webcpp/hash/hkdf.hpp index 111fa9f..39593bf 100644 --- a/include/webcpp/hash/hkdf.hpp +++ b/include/webcpp/hash/hkdf.hpp @@ -34,16 +34,15 @@ #include #include -// The backends the program links, each under its WEBCPP_HASH_HAS_: default_kdf_backend -// names only a backend whose engines are visible here. A backend an override names comes in too, -// so that an override of a backend the program does not link stops with its header's message. -#if defined(WEBCPP_HASH_HAS_BEARSSL) || defined(WEBCPP_HASH_DETAIL_OVERRIDES_BEARSSL) +// The backends the program links, each under its WEBCPP_HASH_HAS_, so that a call that names +// one finds its engines here; the default, backends::hash2, needs none of them. +#ifdef WEBCPP_HASH_HAS_BEARSSL #include #endif -#if defined(WEBCPP_HASH_HAS_SODIUM) || defined(WEBCPP_HASH_DETAIL_OVERRIDES_SODIUM) +#ifdef WEBCPP_HASH_HAS_SODIUM #include #endif -#if defined(WEBCPP_HASH_HAS_OPENSSL) || defined(WEBCPP_HASH_DETAIL_OVERRIDES_OPENSSL) +#ifdef WEBCPP_HASH_HAS_OPENSSL #include #endif @@ -62,7 +61,7 @@ inline constexpr std::size_t hkdf_max_info_size = 32768; HKDF-Extract (RFC 5869, section 2.2): the pseudorandom key of `ikm_bytes` under `salt_bytes`. @tparam Hmac The hmac, as `hmac_sha2_256`. @tparam Backend The backend; by default the one - `default_kdf_backend` chooses, never one that has HKDF only whole. + `default_kdf_backend` names, `backends::hash2`. @param salt_bytes The salt, any length the backend takes; empty means `Hmac`'s digest size of zeros. @param ikm_bytes The input keying material, any length the backend takes. @@ -89,7 +88,7 @@ template ` chooses, never one that has HKDF only whole. + `default_kdf_backend` names, `backends::hash2`. @param output_bytes The output keying material, 1 to 255 times the digest size. @param prk_bytes The pseudorandom key, of exactly the digest size. @param info_bytes The context, at most `hkdf_max_info_size` bytes. diff --git a/include/webcpp/hash/kdf.hpp b/include/webcpp/hash/kdf.hpp index 9e988ab..53b7f47 100644 --- a/include/webcpp/hash/kdf.hpp +++ b/include/webcpp/hash/kdf.hpp @@ -5,8 +5,8 @@ // https://www.boost.org/LICENSE_1_0.txt) /** - What HKDF and PBKDF2 share: which backend has which key derivation over which hmac, and the - backend a call uses when it names none. + What the key derivations share: which backend has which key derivation over which hmac, and + the backend a call uses when it names none. @see "Key derivation", in the guide. */ @@ -16,8 +16,6 @@ #include #include -#include -#include #include #include @@ -173,170 +171,56 @@ inline constexpr bool linked_v = true; #endif /** - The algorithm whose override `Algorithm` follows (spec 4.1): HKDF for its two steps, which an - override of HKDF applies to both, else `Algorithm` itself. Its ranking is its own: - `ranking` holds a row per operation. + The backend of `Algorithm` when the call names none (spec 4.1): backends::hash2, the one backend + that has every key derivation over every hmac on every target, header-only. @tparam Algorithm A tag of `kdfs`. */ template -struct algorithm_of { - /** The algorithm itself. */ - using type = Algorithm; +struct default_of { + /** backends::hash2. */ + using type = backends::hash2; }; -/** HKDF-Extract follows HKDF's override. */ +/** Argon2id: backends::sodium, the one backend that has it. */ template <> -struct algorithm_of { - /** HKDF. */ - using type = kdfs::hkdf; +struct default_of { + /** backends::sodium. */ + using type = backends::sodium; }; -/** HKDF-Expand follows HKDF's override. */ +/** scrypt: backends::sodium, the one backend that has it. */ template <> -struct algorithm_of { - /** HKDF. */ - using type = kdfs::hkdf; -}; - -/** - The first of `Backends` for which `Keep::value` holds, else `Fallback`. - - @tparam Keep A predicate over a backend. @tparam Fallback The answer when none holds. - @tparam Backends The backends, in order. -*/ -template