From b2e38360afed42498d440f405686cfb57107125f Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 01:45:10 -0300 Subject: [PATCH 01/53] tools: the allocation collector's release-only rule has its test --- tools/test/hash_allocation_collect_test.py | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 tools/test/hash_allocation_collect_test.py diff --git a/tools/test/hash_allocation_collect_test.py b/tools/test/hash_allocation_collect_test.py new file mode 100755 index 00000000..eb947f83 --- /dev/null +++ b/tools/test/hash_allocation_collect_test.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +# 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) + +"""Checks that libs/hash/bench/allocation_collect.py, which collects the counting programs' records +into doc/measurements.allocation.json and renders doc/allocation.adoc, builds its table only from +release builds: an output of a program whose build directory, b2's +bench/.test///..., names another variant (the lanes' test/ directories +included), or does not say, is refused before anything is written; one at variant=release is +taken and the data records the build and the toolset; `--render-only` and `--check` refuse data +whose build is not variant=release. Run with the names of some cases to run only those.""" + +from __future__ import annotations + +import json +import subprocess +import sys +import tempfile +from collections.abc import Callable +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +COLLECT = ROOT / 'libs/hash/bench/allocation_collect.py' +DATA = ROOT / 'libs/hash/doc/measurements.allocation.json' +PAGE = ROOT / 'libs/hash/doc/allocation.adoc' + +RECORDS = ( + 'record operation=counter c_counted=1\n' + 'record operation=argon2id backend=sodium new=0 c=3 counted=1\n' + 'record operation=hkdf backend=openssl new=0 hmac=hmac_sha2_256 call=1 openssl=7\n' + 'record operation=hkdf backend=openssl new=0 hmac=hmac_sha2_512 call=1 openssl=5\n' + 'record operation=hkdf backend=openssl new=0 hmac=hmac_sha2_512 call=2 openssl=4\n' +) + + +def run(*args: str | Path) -> subprocess.CompletedProcess[str]: + return subprocess.run([sys.executable, str(COLLECT), *map(str, args)], cwd=ROOT, + capture_output=True, text=True, check=False, timeout=120) + + +def lane(scratch: Path, project: str, variant: str) -> Path: + """A build directory with the output of a counting program, where b2 puts it at variant.""" + base = (scratch / 'bin/libs/hash' / project / 'allocation_release.test' / 'clang-darwin-21' + / variant) + out = base / 'cxxstd-20-iso/allocation_release.output' + out.parent.mkdir(parents=True) + out.write_text(RECORDS) + return scratch / 'bin' + + +def expect(done: subprocess.CompletedProcess[str], status: int, *texts: str) -> None: + if done.returncode != status: + raise AssertionError(f'exit {done.returncode}, not {status}\n{done.stdout}{done.stderr}') + for text in texts: + if text not in done.stdout + done.stderr: + raise AssertionError(f'{text!r} is not in the output:\n{done.stdout}{done.stderr}') + + +def test_an_output_not_built_at_variant_release_is_refused(scratch: Path) -> None: + data, page = scratch / 'data.json', scratch / 'page.adoc' + page.write_text(PAGE.read_text()) + for project, variant in (('bench', 'debug'), ('bench', 'profile'), ('test', 'debug'), + ('test', 'release')): + path = lane(scratch / f'{project}-{variant}', project, variant) + done = run('--lane', f'native={path}', '--data', data, '--page', page) + expect(done, 1, 'only from release builds') + if data.exists() or page.read_text() != PAGE.read_text(): + raise AssertionError(f'{project}/{variant}: a file was written') + stray = scratch / 'stray' + stray.mkdir() + (stray / 'allocation.output').write_text(RECORDS) + expect(run('--lane', f'wasip2={stray}', '--data', data, '--page', page), 1, + 'bench/.test//', 'only from release builds') + + +def test_an_output_built_at_variant_release_is_collected(scratch: Path) -> None: + path = lane(scratch, 'bench', 'release') + data, page = scratch / 'data.json', scratch / 'page.adoc' + page.write_text(PAGE.read_text()) + expect(run('--lane', f'native={path}', '--data', data, '--page', page), 0) + written = json.loads(data.read_text()) + if written.get('build') != 'variant=release': + raise AssertionError(f'the data states build {written.get("build")}') + if written.get('toolsets') != {'native': 'clang-darwin-21'}: + raise AssertionError(f'the data states toolsets {written.get("toolsets")}') + expect(run('--check', '--data', data, '--page', page), 0) + + +def test_render_only_and_check_refuse_data_not_built_at_variant_release(scratch: Path) -> None: + committed = json.loads(DATA.read_text()) + page = scratch / 'page.adoc' + page.write_text(PAGE.read_text()) + for build in ('variant=debug', None): + data = dict(committed) + if build is None: + data.pop('build', None) + else: + data['build'] = build + path = scratch / 'data.json' + path.write_text(json.dumps(data)) + for flag in ('--render-only', '--check'): + expect(run(flag, '--data', path, '--page', page), 1, 'only from release builds') + if page.read_text() != PAGE.read_text(): + raise AssertionError(f'{build}: the page was written') + + +def test_the_committed_data_is_from_release_builds_and_renders_the_page(scratch: Path) -> None: + committed = json.loads(DATA.read_text()) + if committed.get('build') != 'variant=release': + raise AssertionError(f'the committed data states build {committed.get("build")}') + expect(run('--check', '--data', DATA, '--page', PAGE), 0) + + +CASES: list[Callable[[Path], None]] = [ + test_an_output_not_built_at_variant_release_is_refused, + test_an_output_built_at_variant_release_is_collected, + test_render_only_and_check_refuse_data_not_built_at_variant_release, + test_the_committed_data_is_from_release_builds_and_renders_the_page, +] + + +def main(argv: list[str]) -> int: + unknown = set(argv) - {case.__name__ for case in CASES} + if unknown: + print(f'hash_allocation_collect_test: no case named {", ".join(sorted(unknown))}', + file=sys.stderr) + return 2 + for case in CASES: + if argv and case.__name__ not in argv: + continue + with tempfile.TemporaryDirectory(prefix='webcpp hash allocation ') as scratch: + case(Path(scratch)) + print(f'{case.__name__}: ok') + print('hash_allocation_collect_test: ok') + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) From dc9b72b556018e0d1fe9b14850cf9d86649bd9e4 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 11:09:15 -0300 Subject: [PATCH 02/53] tools: doc_tables.py renders webcpp::hash's family tags, the families' messages are Emscripten fixtures, and /third_party//openssl_evp_data gives OpenSSL's EVP test files to tests --- doc/releases/0.1.0.adoc | 4 ++ third_party/Jamfile | 22 +++++++ tools/hash/doc_tables.py | 60 ++++++++++++++++--- .../hash_jamfiles/argon2_no_default/Jamfile | 9 +++ .../hash_jamfiles/argon2_no_default/app.cpp | 20 +++++++ .../argon2_no_default.outcome | 13 ++++ .../argon2_not_a_variant/Jamfile | 9 +++ .../argon2_not_a_variant/app.cpp | 19 ++++++ .../argon2_not_a_variant.outcome | 13 ++++ .../blake3_default_not_linked/Jamfile | 9 +++ .../blake3_default_not_linked/app.cpp | 19 ++++++ .../blake3_default_not_linked.outcome | 13 ++++ .../hash_jamfiles/digest_no_default/Jamfile | 9 +++ .../hash_jamfiles/digest_no_default/app.cpp | 19 ++++++ .../digest_no_default.outcome | 13 ++++ .../hash_jamfiles/digest_not_a_tag/Jamfile | 9 +++ .../hash_jamfiles/digest_not_a_tag/app.cpp | 18 ++++++ .../digest_not_a_tag/digest_not_a_tag.outcome | 13 ++++ .../digest_not_in_backend/Jamfile | 9 +++ .../digest_not_in_backend/app.cpp | 21 +++++++ .../digest_not_in_backend.outcome | 13 ++++ .../hasher_not_in_backend/Jamfile | 9 +++ .../hasher_not_in_backend/app.cpp | 27 +++++++++ .../hasher_not_in_backend.outcome | 13 ++++ .../hash_jamfiles/mac_no_default/Jamfile | 9 +++ .../hash_jamfiles/mac_no_default/app.cpp | 19 ++++++ .../mac_no_default/mac_no_default.outcome | 13 ++++ .../hash_jamfiles/mac_not_a_tag/Jamfile | 9 +++ .../hash_jamfiles/mac_not_a_tag/app.cpp | 18 ++++++ .../mac_not_a_tag/mac_not_a_tag.outcome | 13 ++++ .../sodium_default_not_linked/Jamfile | 9 +++ .../sodium_default_not_linked/app.cpp | 20 +++++++ .../sodium_default_not_linked.outcome | 13 ++++ .../xkcp_default_not_linked/Jamfile | 9 +++ .../xkcp_default_not_linked/app.cpp | 19 ++++++ .../xkcp_default_not_linked.outcome | 13 ++++ tools/test/hash_doc_tables_test.py | 49 ++++++++++++++- 37 files changed, 585 insertions(+), 11 deletions(-) create mode 100644 tools/test/fixtures/hash_jamfiles/argon2_no_default/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/argon2_no_default/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/argon2_not_a_variant.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/blake3_default_not_linked.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/digest_no_default/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/digest_no_default/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/digest_no_default/digest_no_default.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/digest_not_a_tag/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/digest_not_a_tag/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/digest_not_a_tag/digest_not_a_tag.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/digest_not_in_backend/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/digest_not_in_backend/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/digest_not_in_backend/digest_not_in_backend.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/hasher_not_in_backend.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/mac_no_default/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/mac_not_a_tag/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/mac_not_a_tag/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/mac_not_a_tag/mac_not_a_tag.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/xkcp_default_not_linked.outcome diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 008e4dda..ba2665fd 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -309,6 +309,10 @@ webcpp::hash's and webcpp::crypto's OpenSSL, when libs/hash is checked out. llms.txt from its capability table and measurements, and checks them when its page is built. * Changed tools/hash/doc_tables.py to give each chapter two comparison tables, each under the eight columns from which a table scrolls. +* Changed tools/hash/doc_tables.py to render webcpp::hash's family tags (digest_of, hasher, mac, +argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial cell refuses. +* Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's +tests read at run time on every target. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/third_party/Jamfile b/third_party/Jamfile index 142522c9..f0acde55 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -800,3 +800,25 @@ alias blake3_vectors : : @blake3-checked-out : : [ webcpp.data $(BLAKE3)/test_vectors ] libs/blake3/test_vectors/test_vectors.json ; explicit blake3_vectors ; + +# OpenSSL's EVP test data (Apache-2.0), test/recipes/30-test_evp_data at the +# pin, read at run time from the directory WEBCPP_TEST_OPENSSL_EVP_DATA gives, +# on every target, as test data that nothing compiles: webcpp::hash reads the +# keyed BLAKE2s cases of evpmac_blake.txt. Quoted as wycheproof's define is. +path-constant OPENSSL_EVP_DATA : libs/openssl/test/recipes/30-test_evp_data ; + +rule openssl-evp-data-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(OPENSSL_EVP_DATA)/evpmac_blake.txt ] ] + { + errors.user-error "third_party/libs/openssl is not checked out. Check it out with" + "`git submodule update --init third_party/libs/openssl`." ; + } +} + +.openssl-evp-data = [ regex.replace $(OPENSSL_EVP_DATA) "\\\\" "/" ] ; +alias openssl_evp_data : : @openssl-evp-data-checked-out : : + "\"WEBCPP_TEST_OPENSSL_EVP_DATA=\\\"$(.openssl-evp-data)\\\"\"" + [ webcpp.data $(OPENSSL_EVP_DATA) ] + libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt ; +explicit openssl_evp_data ; diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index e9fa3261..31ee6559 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -40,9 +40,10 @@ missing, or is left over; the doc build runs it (doc/Jamfile). It also fails when guide.json lacks a public name of the capability table, names one it does not have, or a use case names an example that example/ does not hold; when a function of the capability table has no default -or a type has one; and when measurements.json's digest does not match its content (a hand edit -of the reference). Nothing in the output depends on the time or the machine, so the files -change only with their data. +among its backends, a family's tag (kind digest, mac or kdf) a default outside the order hash2, +xkcp, blake3, sodium (design D34; null for a tag with none), or a type has one; and when +measurements.json's digest does not match its content (a hand edit of the reference). Nothing in +the output depends on the time or the machine, so the files change only with their data. """ from __future__ import annotations @@ -73,6 +74,10 @@ TARGETS = ('native', 'wasip2', 'wasip3', 'emscripten') # The chapters whose throughput is a rate over 1 MiB (the measured table's workloads). RATE_CHAPTERS = ('digests', 'macs', 'non-cryptographic') +# The kinds of a family's tag (spec 2.15), and the backends that may be its default, in their order +# (design D34): the first that has the tag; never bearssl, openssl, botan or webcrypto. +FAMILY_KINDS = ('digest', 'mac', 'kdf') +FAMILY_DEFAULTS = ('hash2', 'xkcp', 'blake3', 'sodium') class Failure(Exception): @@ -120,15 +125,22 @@ def __init__(self, library: Path) -> None: def check_defaults(self) -> None: """A function (a template with a Backend parameter) names its default, a backend that - has it; a type has none.""" + has it; a family's tag names one of the order, or none (null), whose cell may come in a + later increment; a type has none.""" faults = [] for name, (_, function) in self.functions.items(): default = function.get('default') - if function['kind'] == 'function' and default not in function['backends']: + kind = function['kind'] + if kind == 'function' and default not in function['backends']: faults.append(f'doc/capabilities.json: the function {name} has no default ' f'among its backends ({default})') - if function['kind'] != 'function' and default is not None: + elif kind in FAMILY_KINDS and default is not None and default not in FAMILY_DEFAULTS: + faults.append(f'doc/capabilities.json: the tag {name} has the default {default}, ' + f'which is not one of {", ".join(FAMILY_DEFAULTS)}') + elif kind == 'type' and default is not None: faults.append(f'doc/capabilities.json: the type {name} has a default, {default}') + elif kind not in FAMILY_KINDS + ('function', 'type'): + faults.append(f'doc/capabilities.json: {name} has the unknown kind {kind}') if faults: raise Failure('\n'.join(faults)) @@ -273,6 +285,17 @@ def backend_targets(data: Data, backend: str) -> str: return ', '.join(data.backends[backend]['targets']) +def partial_text(held: dict) -> str: + """What a partial cell refuses, after its backend's name; nothing for a whole cell.""" + partial = held.get('partial') + return f' (partial: {cell(partial)})' if partial else '' + + +def backend_text(backend: str, held: dict) -> str: + """A cell's backend, with what it refuses when it is partial.""" + return f'`{backend}`{partial_text(held)}' + + def hmacs_text(hmacs: list[str] | None) -> str: if hmacs is None: return '-' @@ -295,7 +318,7 @@ def backends_table(data: Data, algorithm: dict) -> str: for backend, held in function['backends'].items(): out.append('') out.append(f'| `{function["name"]}`') - out.append(f'| `{backend}`') + out.append(f'| {backend_text(backend, held)}') out.append(f'| `{data.backends[backend]["jamfile"]}`') out.append(f'| {backend_targets(data, backend)}') out.append(f'| {hmacs_text(held["hmacs"])}') @@ -310,6 +333,20 @@ def backends_table(data: Data, algorithm: dict) -> str: out.extend(f'* `{backend}`: {cell(source)}' for backend, source in sources) out.append('') defaults = [(f['name'], f['default']) for f in algorithm['functions'] if f['default']] + families = [f for f in algorithm['functions'] if f['kind'] in FAMILY_KINDS] + for function in families: + if function['default'] is None: + out.append(f'`{function["name"]}` has no default backend: the call names one of its ' + 'backends (<>).') + out.append('') + elif function['default'] not in function['backends']: + out.append(f'The default of `{function["name"]}` is `{function["default"]}`, whose ' + 'cell comes with a later increment: until then a call on the default ' + 'stops at compile time, and a call names a backend of the table ' + '(<>).') + out.append('') + defaults = [(name, default) for name, default in defaults + if default in data.functions[name][1]['backends']] if not defaults: names = sorted({b for f in algorithm['functions'] for b in f['backends']}) out.append(f'One backend, {", ".join(f"`{n}`" for n in names)}: the types take no backend.') @@ -389,7 +426,9 @@ def llms_txt(data: Data) -> str: '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.', '', + 'only backend. The families digest_of, hasher, mac and argon2 take a tag of ' + 'digests, macs or kdfs and a backend, by default the first of backends::hash2, ' + 'backends::xkcp, backends::blake3 and backends::sodium that has the tag.', '', '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.', '', @@ -468,7 +507,8 @@ def backends_chapter(data: Data) -> str: continue hmacs = ', '.join(c['hmacs']) if c['hmacs'] else '-' targets = ', '.join(data.backends[name]['targets']) - lines += ['', f'| {function["name"]}', f'| {name}', f'| {hmacs}', + lines += ['', f'| {function["name"]}', f'| {name}{partial_text(c)}', + f'| {hmacs}', f'| {c["constant_time"]["value"]}', f'| {targets}'] lines += ['|===', ''] lines += ['=== The default backends', '', @@ -478,6 +518,8 @@ def backends_chapter(data: Data) -> str: for _, function in data.functions.values(): if function['default'] is not None: lines += ['', f'| {function["name"]}', f'| {function["default"]}'] + elif function['kind'] in FAMILY_KINDS: + lines += ['', f'| {function["name"]}', '| none: the call names its backend'] lines += ['|===', '', '=== Constant time', '', 'What each backend\'s upstream states, and where:', ''] seen = set() diff --git a/tools/test/fixtures/hash_jamfiles/argon2_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/argon2_no_default/Jamfile new file mode 100644 index 00000000..b681db05 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_no_default/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/argon2_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/argon2_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2_no_default/app.cpp new file mode 100644 index 00000000..92ee9298 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_no_default/app.cpp @@ -0,0 +1,20 @@ +// 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) + +// argon2 over kdfs::argon2d, which has no default backend, on its default, stops (design D34). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array salt{}; + auto done = webcpp::hash::argon2( + output, {}, salt, {.passes = 3, .memory_kib = 65536}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome b/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome new file mode 100644 index 00000000..b86b3c42 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/argon2_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::argon2d has no default backend, and no backend has it yet. diff --git a/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/Jamfile b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/Jamfile new file mode 100644 index 00000000..d469bea2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/argon2_not_a_variant of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/app.cpp new file mode 100644 index 00000000..72577917 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/app.cpp @@ -0,0 +1,19 @@ +// 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) + +// argon2 over a type that is not a variant of Argon2 stops with the family's refusal (spec 3.3). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array salt{}; + auto done = webcpp::hash::argon2(output, {}, salt, {.passes = 3, .memory_kib = 65536}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/argon2_not_a_variant.outcome b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/argon2_not_a_variant.outcome new file mode 100644 index 00000000..be87db79 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/argon2_not_a_variant.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/argon2_not_a_variant, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: argon2 takes kdfs::argon2d, kdfs::argon2i or kdfs::argon2id. diff --git a/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/Jamfile new file mode 100644 index 00000000..b3615842 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/blake3_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/app.cpp new file mode 100644 index 00000000..f73c1a49 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/app.cpp @@ -0,0 +1,19 @@ +// 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) + +// digest_of over digests::blake3, whose default is backends::blake3, in a program that does not +// link BLAKE3, stops with the instruction to add /third_party//blake3 (spec 5.7). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/blake3_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/blake3_default_not_linked.outcome new file mode 100644 index 00000000..f5835d73 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/blake3_default_not_linked.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/blake3_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::blake3 needs BLAKE3's C implementation. Add /third_party//blake3 to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//blake3 ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/digest_no_default/Jamfile new file mode 100644 index 00000000..f615e533 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_no_default/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/digest_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/digest_no_default/app.cpp new file mode 100644 index 00000000..3c210bab --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_no_default/app.cpp @@ -0,0 +1,19 @@ +// 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) + +// digest_of over a tag with no default backend, on its default, stops: the call names its backend +// (design D34). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/digest_no_default/digest_no_default.outcome b/tools/test/fixtures/hash_jamfiles/digest_no_default/digest_no_default.outcome new file mode 100644 index 00000000..afeb8522 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_no_default/digest_no_default.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/digest_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digests::whirlpool has no default backend, and no backend has it yet. diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/Jamfile b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/Jamfile new file mode 100644 index 00000000..d878d9a6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/digest_not_a_tag of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/app.cpp b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/app.cpp new file mode 100644 index 00000000..a93d1838 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/app.cpp @@ -0,0 +1,18 @@ +// 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) + +// digest_of over a type that is not a tag of digests stops with the family's refusal (spec 3.3). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/digest_not_a_tag.outcome b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/digest_not_a_tag.outcome new file mode 100644 index 00000000..77ca2bb2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/digest_not_a_tag.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/digest_not_a_tag, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digest_of and hasher take a tag of webcpp::hash::digests, as digests::sha2_256. diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/Jamfile b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/Jamfile new file mode 100644 index 00000000..8c27f5d0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/digest_not_in_backend of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/app.cpp b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/app.cpp new file mode 100644 index 00000000..fa2060c4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/app.cpp @@ -0,0 +1,21 @@ +// 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) + +// digest_of over a tag the named backend does not have stops naming the backends that have it +// (spec 3.3, the tag's row of doc/capabilities.json). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = + webcpp::hash::digest_of( + output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/digest_not_in_backend.outcome b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/digest_not_in_backend.outcome new file mode 100644 index 00000000..27ad7c2e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/digest_not_in_backend.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/digest_not_in_backend, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digests::blake3 is not in this backend. Name one of: backends::blake3. diff --git a/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/Jamfile b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/Jamfile new file mode 100644 index 00000000..d4debfd0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/hasher_not_in_backend of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/app.cpp b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/app.cpp new file mode 100644 index 00000000..5c368aa1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/app.cpp @@ -0,0 +1,27 @@ +// 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) + +// A hasher over a tag the named backend does not have stops naming the backends that have it +// (spec 3.3, the tag's row of doc/capabilities.json), with no other error: the class's members +// and make reach the refused engine's members, which it gives for that reason. + +#include + +#include +#include + +int main() { + using hasher = + webcpp::hash::hasher; + auto hashing = hasher::make(); + if (!hashing) { + return 1; + } + std::array output{}; + auto fed = hashing->update(output); + auto done = hashing->finish(output); + return fed && done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/hasher_not_in_backend.outcome b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/hasher_not_in_backend.outcome new file mode 100644 index 00000000..e7b114ca --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/hasher_not_in_backend.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/hasher_not_in_backend, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digests::blake3 is not in this backend. Name one of: backends::blake3. diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/mac_no_default/Jamfile new file mode 100644 index 00000000..a40d1ee9 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/mac_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp new file mode 100644 index 00000000..36e92327 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp @@ -0,0 +1,19 @@ +// 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) + +// mac over HMAC of a digest no backend has HMAC over, on its default, stops (design D34). + +#include + +#include +#include + +int main() { + std::array output{}; + namespace hash = webcpp::hash; + auto done = hash::mac>(output, {}, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome b/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome new file mode 100644 index 00000000..49def264 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/mac_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: macs::hmac over this digest has no default backend, and no backend has it yet. diff --git a/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/Jamfile b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/Jamfile new file mode 100644 index 00000000..cc446df8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/mac_not_a_tag of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/app.cpp b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/app.cpp new file mode 100644 index 00000000..0f37c3af --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/app.cpp @@ -0,0 +1,18 @@ +// 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) + +// mac over a type that is not a tag of macs stops with the family's refusal (spec 3.3). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::mac(output, {}, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/mac_not_a_tag.outcome b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/mac_not_a_tag.outcome new file mode 100644 index 00000000..fc528a0e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/mac_not_a_tag.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/mac_not_a_tag, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: mac takes a tag of webcpp::hash::macs, as macs::hmac. diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/Jamfile new file mode 100644 index 00000000..0bda5e5c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/sodium_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/app.cpp new file mode 100644 index 00000000..76bcc7d3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/app.cpp @@ -0,0 +1,20 @@ +// 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) + +// mac over a tag whose default is backends::sodium, in a program that does not link libsodium, +// stops with the instruction to add /third_party//sodium (spec 5.7). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array key{}; + auto done = webcpp::hash::mac(output, key, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome new file mode 100644 index 00000000..c5839b23 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/sodium_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: 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 ; diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/Jamfile new file mode 100644 index 00000000..7dbbb356 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/xkcp_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/app.cpp new file mode 100644 index 00000000..a931a0c4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/app.cpp @@ -0,0 +1,19 @@ +// 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) + +// digest_of over a tag whose default is backends::xkcp, in a program that does not link XKCP, +// stops with the instruction to add /third_party//xkcp (spec 5.7). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/xkcp_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/xkcp_default_not_linked.outcome new file mode 100644 index 00000000..1ea1a510 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/xkcp_default_not_linked.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/xkcp_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::xkcp needs XKCP. Add /third_party//xkcp to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//xkcp ; diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index e3936b07..f4960211 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -13,7 +13,9 @@ generated file was edited by hand, is missing or is left over. A guide that lacks a function of the capability table, or describes one it does not have, fails, and so does a use case whose example is not there, and so does a function of the capability table without a default. Every -function's default is the capability table's, `hash2` for HKDF whatever the measurements say. +function's default is the capability table's, `hash2` for HKDF whatever the measurements say. A +family's tag (spec 2.15) names a default of the order hash2, xkcp, blake3, sodium, or none, and +one whose cell comes in a later increment is said so; a partial cell says what it refuses. Without doc/measurements.json the tables say so, carry no measured column and render no measurements.adoc; with it (a fixture in its shape) they carry the throughput and the size, and measurements.adoc renders it as the dated reference that decides nothing; a hand edit of the @@ -206,6 +208,47 @@ def test_every_function_names_its_default(scratch: Path) -> None: expect('the type sha2_256 has a default' in done.stderr, done.stderr) +def family_row(table: dict, name: str) -> dict: + for algorithm in table['algorithms']: + for function in algorithm['functions']: + if function['name'] == name: + return function + raise AssertionError(f'no row {name}') + + +def test_a_family_default_is_of_the_order_or_none(scratch: Path) -> None: + library = scratch_library(scratch) + path = library / 'doc/capabilities.json' + table = json.loads(path.read_text(encoding='utf-8')) + family_row(table, 'digests::sha2_256')['default'] = 'openssl' + family_row(table, 'macs::hmac')['default'] = None + path.write_text(json.dumps(table), encoding='utf-8') + done = run(library, '--write') + expect(done.returncode == 1, 'a family default outside the order was rendered') + expect('the tag digests::sha2_256 has the default openssl' in done.stderr, done.stderr) + expect('hmac' not in done.stderr, f'none is a default: {done.stderr}') + + family_row(table, 'digests::sha2_256')['default'] = 'hash2' + path.write_text(json.dumps(table), encoding='utf-8') + files = write_ok(library) + hmac = files['generated/backends-hmac.adoc'] + expect('`macs::hmac` has no default backend: the call names one' in hmac, + hmac) + expect('| macs::hmac\n| none: the call names its backend' + in files['backends.adoc'], 'the default backends do not say none') + + +def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: + library = scratch_library(scratch) + files = write_ok(library) + shake = files['generated/backends-sha3-shake.adoc'] + expect('The default of `digests::shake_128` is `xkcp`, whose cell comes with a later ' + 'increment' in shake, shake) + expect('`hash2` (partial: an output past 32 bytes, one Boost.Hash2 result)' in shake, shake) + expect('| hash2 (partial: an output past 64 bytes' in files['backends.adoc'], + 'the backends chapter does not say what the partial cell refuses') + + def test_without_measurements_the_tables_say_so(scratch: Path) -> None: library = scratch_library(scratch) files = write_ok(library) @@ -221,7 +264,7 @@ def test_without_measurements_the_tables_say_so(scratch: Path) -> None: expect('The default of `argon2id`: `sodium` on every target' in files['generated/backends-argon2id.adoc'], 'Argon2id\'s default') expect('One backend, `hash2`: the types take no backend.' - in files['generated/backends-blake2.adoc'], 'a type\'s backend') + in files['generated/backends-non-cryptographic.adoc'], 'a type\'s backend') backends = files['backends.adoc'] expect('| pbkdf2\n| hash2' in backends and '| scrypt\n| sodium' in backends, 'backends.adoc does not list the defaults') @@ -322,6 +365,8 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_the_guide_covers_the_capability_table, test_a_use_case_names_an_example_that_is_there, test_every_function_names_its_default, + test_a_family_default_is_of_the_order_or_none, + test_a_later_default_and_a_partial_cell_are_said, test_without_measurements_the_tables_say_so, test_with_measurements_the_tables_carry_them, test_a_hand_edit_of_the_measurements_fails, From 4a482d217654f7e0f2911d1feb9819f563b21a22 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 11:16:49 -0300 Subject: [PATCH 03/53] libs/hash: webcpp::hash with the families digest_of, hasher, mac and argon2, SipHash-2-4, keyed BLAKE2s and BLAKE2b on backends::hash2, and the allocation table from release builds --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 624f8161..f19f2e50 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 624f81617b05e691d7417b6033b23e629fa436d4 +Subproject commit f19f2e507b7ae1cc24c21d562829bebf16f9e275 From 84fd224fb3e86068c3800df7c0e4ff9eacfdf51a Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 11:35:29 -0300 Subject: [PATCH 04/53] tools: doc_tables.py names beside a default only its functions' backends, and lists each backend's constant-time statements together --- doc/releases/0.1.0.adoc | 2 ++ tools/hash/doc_tables.py | 23 ++++++++++++++--------- tools/test/hash_doc_tables_test.py | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index ba2665fd..65167982 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -311,6 +311,8 @@ llms.txt from its capability table and measurements, and checks them when its pa eight columns from which a table scrolls. * Changed tools/hash/doc_tables.py to render webcpp::hash's family tags (digest_of, hasher, mac, argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial cell refuses. +* Fixed tools/hash/doc_tables.py naming, beside a default, backends of an algorithm's other +functions, and scattering a backend's constant-time statements. * Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's tests read at run time on every target. diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index 31ee6559..5885d513 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -354,11 +354,15 @@ def backends_table(data: Data, algorithm: dict) -> str: return '\n'.join(out) by_backend: dict[str, list[str]] = {} for name, default in defaults: - by_backend.setdefault(default, []).append(f'`{name}`') - for default, names in by_backend.items(): + by_backend.setdefault(default, []).append(name) + for default, functions in by_backend.items(): + names = [f'`{name}`' for name in functions] named = names[0] if len(names) == 1 else \ ', '.join(names[:-1]) + f' and {names[-1]}' - others = sorted({b for f in algorithm['functions'] for b in f['backends']} - {default}) + # The backends a call may name instead: those of these functions, not of the algorithm's + # others. + others = sorted({b for name in functions + for b in data.functions[name][1]['backends']} - {default}) tail = (f'; {", ".join(f"`{b}`" for b in others)} only where the call names it, as its ' 'second template argument') if others else '' out.append(f'The default of {named}: `{default}` on every target, whatever the program ' @@ -522,15 +526,16 @@ def backends_chapter(data: Data) -> str: lines += ['', f'| {function["name"]}', '| none: the call names its backend'] lines += ['|===', '', '=== Constant time', '', 'What each backend\'s upstream states, and where:', ''] - seen = set() + # Each backend's statements together, in the capability table's order of backends. + seen: list[tuple[str, str, str]] = [] for _, function in data.functions.values(): for name, c in function['backends'].items(): key = (name, c['constant_time']['value'], c['constant_time']['source']) - if key in seen: - continue - seen.add(key) - lines.append(f'* {name}: {c["constant_time"]["value"]}. ' - f'{c["constant_time"]["source"]}') + if key not in seen: + seen.append(key) + order = list(data.backends) + for name, value, source in sorted(seen, key=lambda key: order.index(key[0])): + lines.append(f'* {name}: {value}. {source}') return '\n'.join(lines) + '\n' diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index f4960211..e8e15ad0 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -249,6 +249,29 @@ def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: 'the backends chapter does not say what the partial cell refuses') +def test_a_default_names_only_its_functions_backends(scratch: Path) -> None: + """An algorithm whose functions have different backends: the sentence of each default + names, as the backends a call may name instead, those of its own functions alone.""" + library = scratch_library(scratch) + files = write_ok(library) + blake2 = files['generated/backends-blake2.adoc'] + expect('The default of `digests::blake2s_256` and `macs::blake2s_mac`: `hash2` on every ' + 'target, whatever the program links (<>).' in blake2, blake2) + expect('The default of `digests::blake2b`: `sodium` on every target, whatever the program ' + 'links; `hash2` only where the call names it' in blake2, blake2) + + +def test_each_backend_s_constant_time_sources_are_together(scratch: Path) -> None: + library = scratch_library(scratch) + chapter = write_ok(library)['backends.adoc'] + listed = [line.split(':')[0] for line in + chapter.split("What each backend's upstream states, and where:")[1].splitlines() + if line.startswith('* ')] + order = [b['name'] for b in json.loads( + (library / 'doc/capabilities.json').read_text(encoding='utf-8'))['backends']] + expect(listed == sorted(listed, key=lambda b: order.index(b[2:])), '\n'.join(listed)) + + def test_without_measurements_the_tables_say_so(scratch: Path) -> None: library = scratch_library(scratch) files = write_ok(library) @@ -367,6 +390,8 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_every_function_names_its_default, test_a_family_default_is_of_the_order_or_none, test_a_later_default_and_a_partial_cell_are_said, + test_a_default_names_only_its_functions_backends, + test_each_backend_s_constant_time_sources_are_together, test_without_measurements_the_tables_say_so, test_with_measurements_the_tables_carry_them, test_a_hand_edit_of_the_measurements_fails, From d2b2f80a619002571a36ea5b887531a10236f0f0 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 11:36:00 -0300 Subject: [PATCH 05/53] third_party: BLAKE2's test vectors --- .gitmodules | 4 ++++ CODING-GUIDELINES.md | 2 ++ doc/releases/0.1.0.adoc | 2 ++ third_party/Jamfile | 35 ++++++++++++++++++++++++++++++++++ third_party/libs/blake2 | 1 + tools/test/third_party_test.py | 12 +++++++++++- 6 files changed, 55 insertions(+), 1 deletion(-) create mode 160000 third_party/libs/blake2 diff --git a/.gitmodules b/.gitmodules index 70b989a1..9748bccc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -85,3 +85,7 @@ [submodule "libs/webrtc"] path = libs/webrtc url = ../webrtc.git +[submodule "third_party/libs/blake2"] + path = third_party/libs/blake2 + url = https://github.com/BLAKE2/BLAKE2.git + shallow = true diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 43264225..2efadcf0 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -958,6 +958,7 @@ update --init third_party/libs/`; a build that needs none never looks. | --- | --- | --- | | `bearssl` | BearSSL from webcpp's unmodified mirror `webcpporg/bearssl` at `7bea48e`; a static library built file by file by `third_party/Jamfile` with webcpp::crypto's and webcpp::hash's canaries (hash's when `libs/hash` is checked out), on every target; `WEBCPP_CRYPTO_HAS_BEARSSL=1`, and `WEBCPP_HASH_HAS_BEARSSL=1` with hash's canary | MIT | | `bips` | `bitcoin/bips` at `927b6de9`, shallow, test data: crypto's tests read BIP340's `bip-0340/test-vectors.csv` and BIP341's `bip-0341/wallet-test-vectors.json` at run time under the directory its define `WEBCPP_TEST_BIPS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | BSD-2-Clause, as BIP340's header states | +| `blake2_vectors` | BLAKE2's reference code package `BLAKE2/BLAKE2` at `ed1974e` (2023-02-12), the submodule `third_party/libs/blake2`, shallow, test data that nothing compiles: hash's tests read `testvectors/blake2b-kat.txt` and `testvectors/blake2-kat.json` at run time under the directory its define `WEBCPP_TEST_BLAKE2_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of them changes | CC0-1.0 | | `blake3` | BLAKE3 1.8.7 at `f3149ec`; `third_party/Jamfile` compiles `c/blake3.c`, `blake3_dispatch.c` and `blake3_portable.c` on every target, the intrinsics files on their instruction sets alone (an exception to chapter 5 rule 2), with webcpp::hash's canary; `WEBCPP_HASH_HAS_BLAKE3=1` | CC0-1.0, Apache-2.0, or Apache-2.0 with LLVM exception | | `blake3_vectors` | BLAKE3's official vectors, `test_vectors/test_vectors.json` of the submodule `third_party/libs/blake3` at `f3149ec`, test data: hash's tests read it at run time under the directory its define `WEBCPP_TEST_BLAKE3_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | CC0-1.0, Apache-2.0, or Apache-2.0 with LLVM exception | | `ca_certificates` | Dated Mozilla/curl CA data snapshot under `third_party/ca_certificates`, verified against its manifest and embedded by a build-generated header; updated explicitly by `tools/ca_certificates/update.py` | MPL-2.0 | @@ -968,6 +969,7 @@ update --init third_party/libs/`; a build that needs none never looks. | `openssl` | OpenSSL 3.5.9 at `45e844fa2a14ec92d146bd8f5778ac130b6625fb`; static libssl/libcrypto and matching generated headers, built by upstream Configure/Make through B2 for native Clang/GCC/MSVC, WASIp2 single and WASIp3 single/cooperative | Apache-2.0 | | `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT | | `sodium` | libsodium 1.0.22 at `77e1ce5`, the submodule `third_party/libs/libsodium`; a static library built file by file by `third_party/Jamfile` (every `.c` of `src/libsodium/`, no assembly, the defines libsodium's configure finds on each target, upstream's `builds/msvc/version.h` copied into the build directory) with webcpp::hash's canary, on every target; `WEBCPP_HASH_HAS_SODIUM=1`; `sodium-test-config` gives a program its private headers and test defines; shared with webcpp::crypto | ISC | +| `sodium_vectors` | libsodium's own tests' expected outputs, `test/default/*.exp` of the submodule `third_party/libs/libsodium` at `77e1ce5`, test data: hash's tests read `generichash3.exp` at run time under the directory its define `WEBCPP_TEST_SODIUM_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | ISC | | `wycheproof` | C2SP's Wycheproof at `12fd3aaf` (2026-10-06), shallow, test data: crypto's tests read its `testvectors_v1/` at run time under the directory its define `WEBCPP_TEST_WYCHEPROOF` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of its files changes | Apache-2.0 | | `xkcp` | XKCP (the Keccak team's code package) at `d20c8fc` (2026-11-10, no release tags); `third_party/Jamfile` compiles its `KeccakP-1600-opt64.c` alone (Keccak-p[1600], the generic64 profile) with webcpp::hash's adapter, `config.h` and canary, on every target; `WEBCPP_HASH_HAS_XKCP=1` | CC0; `brg_endian.h` under Brian Gladman's terms | diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 65167982..a03460d9 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -315,6 +315,8 @@ argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial functions, and scattering a backend's constant-time statements. * Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's tests read at run time on every target. +* Added /third_party//blake2_vectors, BLAKE2's test vectors at ed1974e (a shallow submodule), and +/third_party//sodium_vectors, libsodium's test outputs, which webcpp::hash's tests read at run time. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/third_party/Jamfile b/third_party/Jamfile index f0acde55..2b661b1e 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -822,3 +822,38 @@ alias openssl_evp_data : : @openssl-evp-data-checked-out : : [ webcpp.data $(OPENSSL_EVP_DATA) ] libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt ; explicit openssl_evp_data ; + +# BLAKE2's reference code package (CC0-1.0) at ed1974e, shallow, as test data +# that nothing compiles: webcpp::hash reads testvectors/blake2b-kat.txt (the +# keyed BLAKE2b cases) and testvectors/blake2-kat.json (the unkeyed ones) at +# run time from the directory WEBCPP_TEST_BLAKE2_VECTORS gives, on every +# target. Quoted as wycheproof's define is. +path-constant BLAKE2_VECTORS : libs/blake2/testvectors ; + +rule blake2-vectors-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(BLAKE2_VECTORS)/blake2b-kat.txt ] ] + { + errors.user-error "third_party/libs/blake2 is not checked out. Check it out with" + "`git submodule update --init third_party/libs/blake2`." ; + } +} + +.blake2-vectors = [ regex.replace $(BLAKE2_VECTORS) "\\\\" "/" ] ; +alias blake2_vectors : : @blake2-vectors-checked-out : : + "\"WEBCPP_TEST_BLAKE2_VECTORS=\\\"$(.blake2-vectors)\\\"\"" + [ webcpp.data $(BLAKE2_VECTORS) ] + libs/blake2/testvectors/blake2b-kat.txt + libs/blake2/testvectors/blake2-kat.json ; +explicit blake2_vectors ; + +# libsodium's own tests' expected outputs (ISC), test/default/*.exp at the pin, +# read at run time from the directory WEBCPP_TEST_SODIUM_VECTORS gives, on +# every target, never copied: webcpp::hash reads generichash3.exp. Quoted as +# wycheproof's define is. +.sodium-vectors = [ regex.replace $(SODIUM)/test/default "\\\\" "/" ] ; +alias sodium_vectors : : @sodium-checked-out : : + "\"WEBCPP_TEST_SODIUM_VECTORS=\\\"$(.sodium-vectors)\\\"\"" + [ webcpp.data $(SODIUM)/test/default ] + libs/libsodium/test/default/generichash3.exp ; +explicit sodium_vectors ; diff --git a/third_party/libs/blake2 b/third_party/libs/blake2 new file mode 160000 index 00000000..ed1974ea --- /dev/null +++ b/third_party/libs/blake2 @@ -0,0 +1 @@ +Subproject commit ed1974ea83433eba7b2d95c5dcd9ac33cb847913 diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 8c851ea5..987d2783 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -22,7 +22,8 @@ webcpp::hash's canary, its version.h copied into the build directory and its checkout left as it was. BLAKE3's C implementation, pinned, is built file by file with webcpp::hash's canary: natively with the intrinsics files of the machine's instruction sets, each with its own flag, and on -WebAssembly with the portable code alone. Run with the names of some cases to run only those.""" +WebAssembly with the portable code alone. BLAKE2's test vectors are pinned. Run with the names of +some cases to run only those.""" from __future__ import annotations @@ -85,6 +86,8 @@ # The commit the Bitcoin Improvement Proposals' repository is pinned at: the test vectors of # BIP340 and BIP341 (libs/crypto/test/secp256k1_bip340_test.cpp, secp256k1_xonly_tweak_test.cpp). BIPS_COMMIT = '927b6de9915c9262615a6399de51b200f81e5aa4' +BLAKE2 = 'third_party/libs/blake2' +BLAKE2_COMMIT = 'ed1974ea83433eba7b2d95c5dcd9ac33cb847913' SECP256K1 = 'third_party/libs/secp256k1' @@ -707,6 +710,12 @@ def expect_blake3_portable(compiled: dict[str, str], archive: Path) -> None: assert blake3_canary('portable').encode() in archive.read_bytes() +def test_blake2_is_pinned(_: Path) -> None: + listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', BLAKE2], + capture_output=True, text=True, check=True) + assert listed.stdout.split()[:2] == ['160000', BLAKE2_COMMIT], listed.stdout + + def test_blake3_is_pinned(_: Path) -> None: listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', BLAKE3], capture_output=True, text=True, check=True) @@ -828,6 +837,7 @@ def test_hash_not_checked_out_stops_blake3(root: Path) -> None: test_sodium_unknown_architecture_is_refused, test_sodium_not_checked_out_is_refused, test_hash_not_checked_out_is_refused_by_sodium, + test_blake2_is_pinned, test_blake3_is_pinned, test_blake3_natively_has_the_machines_simd_files, test_blake3_on_x86_64_declares_the_intrinsics_files, From 01073fc37d1241a9f4881a7e996232bd6ed5518f Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 12:37:10 -0300 Subject: [PATCH 06/53] tools: hash_jamfiles_test.py copies libs/asio, and webcpp::hash's asynchronous family's messages are Emscripten fixtures --- doc/releases/0.1.0.adoc | 2 ++ .../async_argon2_without_threads/Jamfile | 9 ++++++ .../async_argon2_without_threads/app.cpp | 30 +++++++++++++++++++ .../async_argon2_without_threads.outcome | 14 +++++++++ .../async_argon2id_without_threads/Jamfile | 9 ++++++ .../async_argon2id_without_threads/app.cpp | 29 ++++++++++++++++++ .../async_argon2id_without_threads.outcome | 14 +++++++++ .../async_digest_not_in_webcrypto/Jamfile | 9 ++++++ .../async_digest_not_in_webcrypto/app.cpp | 25 ++++++++++++++++ .../async_digest_not_in_webcrypto.outcome | 13 ++++++++ .../async_pbkdf2_without_threads/Jamfile | 9 ++++++ .../async_pbkdf2_without_threads/app.cpp | 27 +++++++++++++++++ .../async_pbkdf2_without_threads.outcome | 14 +++++++++ .../async_scrypt_without_threads/Jamfile | 9 ++++++ .../async_scrypt_without_threads/app.cpp | 28 +++++++++++++++++ .../async_scrypt_without_threads.outcome | 14 +++++++++ .../webcrypto_synchronous/Jamfile | 9 ++++++ .../webcrypto_synchronous/app.cpp | 21 +++++++++++++ .../webcrypto_synchronous.outcome | 13 ++++++++ tools/test/hash_jamfiles_test.py | 11 ++++--- 20 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/async_argon2_without_threads.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/async_argon2id_without_threads.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/async_digest_not_in_webcrypto.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/async_pbkdf2_without_threads.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/async_scrypt_without_threads.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/webcrypto_synchronous.outcome diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index ba2665fd..198addd3 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -313,6 +313,8 @@ eight columns from which a table scrolls. argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial cell refuses. * Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's tests read at run time on every target. +* Changed tools/test/hash_jamfiles_test.py to copy libs/asio into its scratch superproject, so that +the messages of webcpp::hash's asynchronous family are built on Emscripten too. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/Jamfile new file mode 100644 index 00000000..b2184943 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/async_argon2_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/app.cpp new file mode 100644 index 00000000..8d01fd13 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/app.cpp @@ -0,0 +1,30 @@ +// 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) + +// async_argon2 in a build without threads stops with spec 11.5's text, which names argon2 (ruling +// R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS removes +// them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + std::array const salt{}; + webcpp::hash::async_argon2( + context.get_executor(), output, {}, salt, + webcpp::hash::argon2_parameters{.passes = 3, .memory_kib = 65536}, + [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/async_argon2_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/async_argon2_without_threads.outcome new file mode 100644 index 00000000..7fdfcdcf --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/async_argon2_without_threads.outcome @@ -0,0 +1,14 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_argon2_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_argon2 runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call argon2. diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/Jamfile new file mode 100644 index 00000000..6e76feb7 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/async_argon2id_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/app.cpp new file mode 100644 index 00000000..0c6dc55d --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/app.cpp @@ -0,0 +1,29 @@ +// 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) + +// async_argon2id in a build without threads stops with spec 11.5's text, which names argon2id +// (ruling R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS +// removes them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + std::array const salt{}; + webcpp::hash::async_argon2id(context.get_executor(), output, {}, salt, + webcpp::hash::argon2id_interactive, + [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/async_argon2id_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/async_argon2id_without_threads.outcome new file mode 100644 index 00000000..93718ceb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/async_argon2id_without_threads.outcome @@ -0,0 +1,14 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_argon2id_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_argon2id runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call argon2id. diff --git a/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/Jamfile b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/Jamfile new file mode 100644 index 00000000..848ad050 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/async_digest_not_in_webcrypto of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/app.cpp b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/app.cpp new file mode 100644 index 00000000..614992f5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/app.cpp @@ -0,0 +1,25 @@ +// 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) + +// async_digest over a digest WebCrypto lacks stops (spec 11.2): the cheap functions have an +// asynchronous form only for the algorithms the browser has. + +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_digest( + context.get_executor(), output, {}, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/async_digest_not_in_webcrypto.outcome b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/async_digest_not_in_webcrypto.outcome new file mode 100644 index 00000000..45915dbb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/async_digest_not_in_webcrypto.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_digest_not_in_webcrypto, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_digest takes digests::sha1, digests::sha2_256, digests::sha2_384 or digests::sha2_512, the digests WebCrypto has: call digest_of for the others. diff --git a/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/Jamfile new file mode 100644 index 00000000..948cefd0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/async_pbkdf2_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/app.cpp new file mode 100644 index 00000000..ec5adce6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/app.cpp @@ -0,0 +1,27 @@ +// 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) + +// async_pbkdf2 in a build without threads stops with spec 11.5's text, which names pbkdf2 (ruling +// R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS removes +// them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_pbkdf2( + context.get_executor(), output, {}, {}, 1, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/async_pbkdf2_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/async_pbkdf2_without_threads.outcome new file mode 100644 index 00000000..577b75a9 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/async_pbkdf2_without_threads.outcome @@ -0,0 +1,14 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_pbkdf2_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_pbkdf2 runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call pbkdf2. diff --git a/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/Jamfile new file mode 100644 index 00000000..12b17d5b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/async_scrypt_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/app.cpp new file mode 100644 index 00000000..a4019f87 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/app.cpp @@ -0,0 +1,28 @@ +// 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) + +// async_scrypt in a build without threads stops with spec 11.5's text, which names scrypt (ruling +// R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS removes +// them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_scrypt(context.get_executor(), output, {}, {}, + webcpp::hash::scrypt_parameters{.n = 16, .r = 1, .p = 1}, + [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/async_scrypt_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/async_scrypt_without_threads.outcome new file mode 100644 index 00000000..1487591b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/async_scrypt_without_threads.outcome @@ -0,0 +1,14 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_scrypt_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_scrypt runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call scrypt. diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/Jamfile b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/Jamfile new file mode 100644 index 00000000..e1383235 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/webcrypto_synchronous of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/app.cpp b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/app.cpp new file mode 100644 index 00000000..3e96fa62 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/app.cpp @@ -0,0 +1,21 @@ +// 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) + +// backends::webcrypto named in a synchronous function stops with spec 11.2's text, on every target +// (ruling R77, C-m4): only the asynchronous family takes it. + +#include +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::hkdf( + output, {}, {}, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/webcrypto_synchronous.outcome b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/webcrypto_synchronous.outcome new file mode 100644 index 00000000..0937a83c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/webcrypto_synchronous.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/webcrypto_synchronous, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::webcrypto is asynchronous: call async_hkdf (or async_pbkdf2, async_digest, async_hmac) with a completion token, or name a synchronous backend. diff --git a/tools/test/hash_jamfiles_test.py b/tools/test/hash_jamfiles_test.py index 50b868f5..feb600d6 100644 --- a/tools/test/hash_jamfiles_test.py +++ b/tools/test/hash_jamfiles_test.py @@ -17,8 +17,9 @@ fixture's app.cpp is the message's source without its expected-error directive, and that its outcome's one contains: line is the directive's text, unless the message is in NO_FIXTURE. -The scratch superproject holds libs/config, libs/hash and libs/crypto (whose canary -/third_party//bearssl compiles). Run with the names of some cases to run only those, and with +The scratch superproject holds libs/config, libs/hash, libs/crypto (whose canary +/third_party//bearssl compiles) and libs/asio (whose /webcpp/asio//asio the asynchronous family's +messages name). Run with the names of some cases to run only those, and with --target to run one target.""" from __future__ import annotations @@ -40,6 +41,8 @@ NO_FIXTURE = { 'ripemd128_on_openssl': 'it names /webcpp/hash//openssl, which Emscripten refuses before ' 'the message (the fixture openssl_on_emscripten)', + 'webcrypto_off_emscripten': 'its message is off Emscripten alone: there the asynchronous ' + 'family takes backends::webcrypto', } DIRECTIVE = re.compile(r'^// expected-error@\S+ \{\{(.*)\}\}$', re.MULTILINE) @@ -93,8 +96,8 @@ def message_faults(cases: list[Path]) -> list[str]: def main(argv: list[str]) -> int: - return user_jamfiles.main('hash_jamfiles', CASES, ('config', 'hash', 'crypto'), NOT_YET, argv, - message_faults) + return user_jamfiles.main('hash_jamfiles', CASES, ('config', 'hash', 'crypto', 'asio'), NOT_YET, + argv, message_faults) if __name__ == '__main__': From 88b9abffb40c1dd94f4692e7a7b8e98b90e72598 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 12:39:44 -0300 Subject: [PATCH 07/53] third_party: XKCP's sponge, SP 800-185, KangarooTwelve and TurboSHAKE --- CODING-GUIDELINES.md | 8 ++++---- doc/releases/0.1.0.adoc | 4 ++-- third_party/Jamfile | 28 ++++++++++++++++++++++------ tools/test/third_party_test.py | 32 ++++++++++++++++++++++++-------- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 43264225..ef2f2db7 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -347,9 +347,9 @@ exactly its authors' and the program carries only what it calls. stubs other files call. A single unity source is not used. Three exceptions, each recorded in its row of chapter 10: BLAKE3's intrinsics files compile on their instruction sets alone, each flagged for its own set; XKCP is built - from the one file of Keccak-p[1600] the library calls (and the high-level - files increment 3 of webcpp::hash lists), not from every file of its - package; libsodium is built without its `.S` files. + from the one file of Keccak-p[1600] and the five high-level files + webcpp::hash's adapter calls, not from every file of its package; + libsodium is built without its `.S` files. 3. Every file is compiled with `-ffunction-sections -fdata-sections` (`/Gy /Gw` on MSVC); upstream's warnings are not webcpp's (`off`); each define the library cannot work out for itself on a target sits beside the @@ -969,7 +969,7 @@ update --init third_party/libs/`; a build that needs none never looks. | `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT | | `sodium` | libsodium 1.0.22 at `77e1ce5`, the submodule `third_party/libs/libsodium`; a static library built file by file by `third_party/Jamfile` (every `.c` of `src/libsodium/`, no assembly, the defines libsodium's configure finds on each target, upstream's `builds/msvc/version.h` copied into the build directory) with webcpp::hash's canary, on every target; `WEBCPP_HASH_HAS_SODIUM=1`; `sodium-test-config` gives a program its private headers and test defines; shared with webcpp::crypto | ISC | | `wycheproof` | C2SP's Wycheproof at `12fd3aaf` (2026-10-06), shallow, test data: crypto's tests read its `testvectors_v1/` at run time under the directory its define `WEBCPP_TEST_WYCHEPROOF` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of its files changes | Apache-2.0 | -| `xkcp` | XKCP (the Keccak team's code package) at `d20c8fc` (2026-11-10, no release tags); `third_party/Jamfile` compiles its `KeccakP-1600-opt64.c` alone (Keccak-p[1600], the generic64 profile) with webcpp::hash's adapter, `config.h` and canary, on every target; `WEBCPP_HASH_HAS_XKCP=1` | CC0; `brg_endian.h` under Brian Gladman's terms | +| `xkcp` | XKCP (the Keccak team's code package) at `d20c8fc` (2026-11-10, no release tags); `third_party/Jamfile` compiles its `KeccakP-1600-opt64.c` (Keccak-p[1600], the generic64 profile) and the high-level files over it, `KeccakSponge.c`, `KeccakHash.c` (FIPS 202), `SP800-185.c`, `TurboSHAKE.c` and `KangarooTwelve.c` (serial: no times-N permutation), with webcpp::hash's adapter, `config.h` (`XKCP_has_KeccakP1600`, `_Sponge_Keccak`, `_TurboSHAKE`, `_FIPS202`, `_SP800_185`, `_KangarooTwelve`) and canary, on every target; `WEBCPP_HASH_HAS_XKCP=1` | CC0; `brg_endian.h` under Brian Gladman's terms | OpenSSL builds from a checkout or a source distribution. Before Configure, its builder stages the distributable tree and checks a digest of paths, Git file diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index ba2665fd..8befb454 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -283,8 +283,8 @@ could not read and dropped, such as one naming a header that does not exist. * Added ctaes, Bitcoin Core's constant-time AES at v31.1, built from source as /third_party//ctaes, and the fixtures of the user's Jamfiles of webcpp::crypto's block cipher and signing programs. -* Added XKCP's Keccak-p[1600], built from source with webcpp::hash's adapter as -`/third_party//xkcp`. +* Added XKCP's Keccak-p[1600] and its sponge, FIPS 202, SP 800-185, TurboSHAKE and +KangarooTwelve files, built from source with webcpp::hash's adapter as `/third_party//xkcp`. * Added libsodium 1.0.22, built from source as /third_party//sodium with the defines its own configure finds on each target, and /third_party//sodium-test-config for a program that compiles against its private headers. diff --git a/third_party/Jamfile b/third_party/Jamfile index f0acde55..3cc05867 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -391,12 +391,18 @@ rule bearssl-hash-usage ( properties * ) # XKCP (CC0; brg_endian.h under Brian Gladman's terms), the Keccak team's code # package at d20c8fc (2026-11-10; XKCP has no release tags): its Keccak-p[1600] -# alone, in the plain-64bits implementation with all rounds unrolled -# ("generic64"), on every target: wasm32 has 64-bit integers, MSVC compiles it -# with _rotl64, and XKCP's faster profiles are GNU assembly. Its config.h, which -# XKCP's build generates, is webcpp's libs/hash/src/xkcp/config.h. A program -# reaches it through webcpp::hash's adapter (libs/hash/src/xkcp_adapter.c), so -# no include directory of XKCP's is a usage requirement. +# in the plain-64bits implementation with all rounds unrolled ("generic64"), +# on every target: wasm32 has 64-bit integers, MSVC compiles it with _rotl64, +# and XKCP's faster profiles are GNU assembly. Over it, the high-level files +# XKCP's lib/HighLevel.build names KeccakSponge, TurboSHAKE, FIPS202 (its +# KeccakHash.c alone: SimpleFIPS202.c's unprefixed SHA3_256 and SHAKE128 are +# never in a user's link), SP800-185 and KangarooTwelve. generic64 has no +# parallel permutation (no XKCP_has_KeccakP1600times2, 4 or 8), so +# KangarooTwelve and ParallelHash take their serial loops and no times-N file +# is compiled. Its config.h, which XKCP's build generates, is webcpp's +# libs/hash/src/xkcp/config.h. A program reaches it through webcpp::hash's +# adapter (libs/hash/src/xkcp_adapter.c), so no include directory of XKCP's +# is a usage requirement. path-constant XKCP : libs/xkcp ; rule xkcp-checked-out ( properties * ) @@ -412,12 +418,22 @@ rule xkcp-checked-out ( properties * ) lib xkcp : libs/xkcp/lib/low/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c + libs/xkcp/lib/high/Keccak/KeccakSponge.c + libs/xkcp/lib/high/Keccak/FIPS202/KeccakHash.c + libs/xkcp/lib/high/Keccak/SP800-185/SP800-185.c + libs/xkcp/lib/high/TurboSHAKE/TurboSHAKE.c + libs/xkcp/lib/high/KangarooTwelve/KangarooTwelve.c $(HASH)/src/xkcp_adapter.c $(HASH)/src/canary_xkcp.c : $(.hash-c-library) @xkcp-checked-out $(HASH)/src/xkcp libs/xkcp/lib/common libs/xkcp/lib/low/common libs/xkcp/lib/low/KeccakP-1600/common libs/xkcp/lib/low/KeccakP-1600/plain-64bits libs/xkcp/lib/low/KeccakP-1600/plain-64bits/SnP + libs/xkcp/lib/high/common libs/xkcp/lib/high/Keccak + libs/xkcp/lib/high/Keccak/FIPS202 + libs/xkcp/lib/high/Keccak/SP800-185 + libs/xkcp/lib/high/TurboSHAKE + libs/xkcp/lib/high/KangarooTwelve : : WEBCPP_HASH_HAS_XKCP=1 $(.gc) ; explicit xkcp ; diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 8c851ea5..1be1c510 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -16,8 +16,9 @@ stops the build that needs it, naming the command; and that loading third_party/Jamfile prints nothing b2 warns of. libsecp256k1, pinned, is built file by file with every module and webcpp::crypto's canary, with the large tables natively and the small ones on request and on -emscripten. XKCP, pinned, is built from its one file of Keccak-p[1600] with webcpp::hash's adapter -and canary, and an XKCP or a libs/hash that is not checked out stops it, naming the command. +emscripten. XKCP, pinned, is built from its file of Keccak-p[1600] and its high-level files with +webcpp::hash's adapter and canary, and an XKCP or a libs/hash that is not checked out stops it, +naming the command. libsodium, pinned, is built file by file with the defines its own configure finds on each target and webcpp::hash's canary, its version.h copied into the build directory and its checkout left as it was. BLAKE3's C implementation, pinned, is built file by file with webcpp::hash's canary: natively @@ -107,12 +108,25 @@ XKCP_COMMIT = 'd20c8fcaecc543f816a0721d0dfc13b4cf27c14d' # The C files /third_party//xkcp compiles: XKCP's Keccak-p[1600] in the plain-64bits -# implementation, and webcpp::hash's adapter and canary. -XKCP_FILES = ['KeccakP-1600-opt64.c', 'xkcp_adapter.c', 'canary_xkcp.c'] - -# The adapter's four functions (spec section 2.6). +# implementation, its high-level files of the sponge, FIPS 202's Keccak_Hash, SP 800-185, +# TurboSHAKE and KangarooTwelve (serial: no times-N permutation), and webcpp::hash's adapter +# and canary. +XKCP_FILES = ['KeccakP-1600-opt64.c', 'KeccakSponge.c', 'KeccakHash.c', 'SP800-185.c', + 'TurboSHAKE.c', 'KangarooTwelve.c', 'xkcp_adapter.c', 'canary_xkcp.c'] + +# The adapter's functions (spec section 2.6): the permutation's four, and the four phases +# (initialize, update, final, squeeze) of each high-level interface. XKCP_ADAPTER = ['webcpp_hash_xkcp_initialize', 'webcpp_hash_xkcp_add_bytes', - 'webcpp_hash_xkcp_permute', 'webcpp_hash_xkcp_extract_bytes'] + 'webcpp_hash_xkcp_permute', 'webcpp_hash_xkcp_extract_bytes'] + [ + f'webcpp_hash_xkcp_{interface}_{phase}' + for interface in ('sponge', 'keccak_hash', 'turboshake', 'kangarootwelve', 'cshake128', + 'cshake256', 'kmac128', 'kmac256', 'tuplehash128', 'tuplehash256', + 'parallelhash128', 'parallelhash256') + for phase in ('initialize', 'update', 'final', 'squeeze')] + +# XKCP's unprefixed functions of FIPS 202 (SimpleFIPS202.c), which its unit tests compile into +# their own program and /third_party//xkcp never holds, so that they never reach a user's link. +XKCP_NOT_HELD = ['SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512', 'SHAKE128', 'SHAKE256'] # The small tables: window 2 and comb 2x5. SECP256K1_SMALL = ['-DECMULT_WINDOW_SIZE=2', '-DCOMB_BLOCKS=2', '-DCOMB_TEETH=5'] @@ -485,7 +499,7 @@ def test_xkcp_is_built_file_by_file(root: Path) -> None: harness.expect(result, True) lines = C_COMPILE.findall(result.stdout) compiled = sorted(Path(line.rsplit(' ', 1)[-1].strip('"')).name for line in lines) - # XKCP's one file and webcpp::hash's two: nothing else of XKCP's tree. + # XKCP's six files and webcpp::hash's two: nothing else of XKCP's tree. assert compiled == sorted(XKCP_FILES), (compiled, result.stdout[-4000:]) for line in lines: for flag in ('-ffunction-sections', '-fdata-sections'): @@ -499,6 +513,8 @@ def test_xkcp_is_built_file_by_file(root: Path) -> None: canary = 'webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link' for name in [canary, *XKCP_ADAPTER]: assert f'{prefix}{name}' in symbols, (name, symbols[-200:]) + for name in XKCP_NOT_HELD: + assert f'{prefix}{name}' not in symbols, name def test_xkcp_not_checked_out_is_refused(root: Path) -> None: From 7af2c54dbee959a71571ab3f4bc7f625325bcd91 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 13:41:38 -0300 Subject: [PATCH 08/53] libs/hash: webcpp::hash with the families' guards [[nodiscard]] and the allocation collector's lint fixes --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index f19f2e50..5a395d4a 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit f19f2e507b7ae1cc24c21d562829bebf16f9e275 +Subproject commit 5a395d4aa4bceeb35f63e7fd120003b82252201e From 67a4c4d0aa7fdb93b5aa6c0751dcc8f69096d024 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 13:49:58 -0300 Subject: [PATCH 09/53] guidelines: hash's entry in chapter 17 states the default rule of designs D33 and D34 and increment 5 as built --- CODING-GUIDELINES.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 43264225..1e5eb9ea 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -9108,10 +9108,10 @@ Boost.Hash2's algorithms and `hmac` re-exported by alias (`algorithms.hpp`, both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 (RFC 8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and `openssl` (`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and -scrypt (RFC 7914, `scrypt.hpp`) from libsodium; the profile and the default -backend (`config.hpp`), the capability table (`doc/capabilities.json`), and -the measured table (`doc/measurements*.json`, regenerated by the `measure` -lane). The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, +scrypt (RFC 7914, `scrypt.hpp`) from libsodium; the default backend +(`config.hpp`), the capability table (`doc/capabilities.json`), and the +measured tables (`doc/measurements*.json`), a dated reference of 2026-11-16 +that decides nothing (design D33). The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, `sodium`, `bearssl`, each with a canary), their own suites by the `c-suites` lane (`test/c_suites`), the examples are in `example/` and the documentation in `doc/`. Every function is synchronous, reports failure as a @@ -9134,10 +9134,13 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` - **The key derivation functions have backends, as webcpp::crypto's algorithms do, and a backend that lacks a function refuses at compile time.** `backends::hash2`, `sodium`, `bearssl` and `openssl` (native, - wasip2 and wasip3); natively the fastest linked backend is the default, on - WebAssembly the one that gives the smallest binary, decided by a measured - table that every pin move regenerates; one setting in `config.hpp` (a - profile) changes every default at once. + wasip2 and wasip3). A call that names no backend takes the default, one + stated rule with no measurement, the same on every target (designs D33 and + D34): `hash2` for HKDF and PBKDF2, `sodium` for Argon2id and scrypt, and for + a tag of the families `digest_of`, `hasher`, `mac` and `argon2` the first of + `hash2`, `xkcp`, `blake3` and `sodium` that has it, or none; `bearssl`, + `openssl` and the later backends are never a default, only named in the + type. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.4 (proposals). - **The C libraries of hash (`xkcp`, `blake3`, `sodium`) are built file by @@ -9152,7 +9155,10 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the profile and the measured table; the next ones widen the backends' surface (libsodium's, XKCP's, OpenSSL's, BearSSL's, Botan's) and add the browser backend over - WebCrypto through a parallel asynchronous family. + WebCrypto through a parallel asynchronous family. The fifth is built: + BearSSL's MD5, SHA-1, SHA-2, TLS 1.0's MD5-SHA1 and SHAKE through + `digest_of` and `hasher`, and its HMAC through `mac`, each reached only by + naming `backends::bearssl`. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.5 (proposals). From 9c04fc38cf516dcd83259760713f56383ceb10d4 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 14:14:47 -0300 Subject: [PATCH 10/53] third_party: sodium_vectors names libsodium's kdf.exp, shorthash.exp and siphashx24.exp, which hash's tests read --- CODING-GUIDELINES.md | 2 +- third_party/Jamfile | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 2efadcf0..b52aea23 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -969,7 +969,7 @@ update --init third_party/libs/`; a build that needs none never looks. | `openssl` | OpenSSL 3.5.9 at `45e844fa2a14ec92d146bd8f5778ac130b6625fb`; static libssl/libcrypto and matching generated headers, built by upstream Configure/Make through B2 for native Clang/GCC/MSVC, WASIp2 single and WASIp3 single/cooperative | Apache-2.0 | | `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT | | `sodium` | libsodium 1.0.22 at `77e1ce5`, the submodule `third_party/libs/libsodium`; a static library built file by file by `third_party/Jamfile` (every `.c` of `src/libsodium/`, no assembly, the defines libsodium's configure finds on each target, upstream's `builds/msvc/version.h` copied into the build directory) with webcpp::hash's canary, on every target; `WEBCPP_HASH_HAS_SODIUM=1`; `sodium-test-config` gives a program its private headers and test defines; shared with webcpp::crypto | ISC | -| `sodium_vectors` | libsodium's own tests' expected outputs, `test/default/*.exp` of the submodule `third_party/libs/libsodium` at `77e1ce5`, test data: hash's tests read `generichash3.exp` at run time under the directory its define `WEBCPP_TEST_SODIUM_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | ISC | +| `sodium_vectors` | libsodium's own tests' expected outputs, `test/default/*.exp` of the submodule `third_party/libs/libsodium` at `77e1ce5`, test data: hash's tests read `generichash3.exp`, `kdf.exp`, `shorthash.exp` and `siphashx24.exp` at run time under the directory its define `WEBCPP_TEST_SODIUM_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | ISC | | `wycheproof` | C2SP's Wycheproof at `12fd3aaf` (2026-10-06), shallow, test data: crypto's tests read its `testvectors_v1/` at run time under the directory its define `WEBCPP_TEST_WYCHEPROOF` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of its files changes | Apache-2.0 | | `xkcp` | XKCP (the Keccak team's code package) at `d20c8fc` (2026-11-10, no release tags); `third_party/Jamfile` compiles its `KeccakP-1600-opt64.c` alone (Keccak-p[1600], the generic64 profile) with webcpp::hash's adapter, `config.h` and canary, on every target; `WEBCPP_HASH_HAS_XKCP=1` | CC0; `brg_endian.h` under Brian Gladman's terms | diff --git a/third_party/Jamfile b/third_party/Jamfile index 2b661b1e..69db22a3 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -849,11 +849,14 @@ explicit blake2_vectors ; # libsodium's own tests' expected outputs (ISC), test/default/*.exp at the pin, # read at run time from the directory WEBCPP_TEST_SODIUM_VECTORS gives, on -# every target, never copied: webcpp::hash reads generichash3.exp. Quoted as -# wycheproof's define is. +# every target, never copied: webcpp::hash reads generichash3.exp, kdf.exp, +# shorthash.exp and siphashx24.exp. Quoted as wycheproof's define is. .sodium-vectors = [ regex.replace $(SODIUM)/test/default "\\\\" "/" ] ; alias sodium_vectors : : @sodium-checked-out : : "\"WEBCPP_TEST_SODIUM_VECTORS=\\\"$(.sodium-vectors)\\\"\"" [ webcpp.data $(SODIUM)/test/default ] - libs/libsodium/test/default/generichash3.exp ; + libs/libsodium/test/default/generichash3.exp + libs/libsodium/test/default/kdf.exp + libs/libsodium/test/default/shorthash.exp + libs/libsodium/test/default/siphashx24.exp ; explicit sodium_vectors ; From d4c95ce8109911eb2b8b88c10b624802b2f0348b Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 14:14:47 -0300 Subject: [PATCH 11/53] tools: the Emscripten fixtures of hash's blake2b_subkey messages --- .../blake2b_subkey_default_not_linked/Jamfile | 9 ++++++++ .../blake2b_subkey_default_not_linked/app.cpp | 22 +++++++++++++++++++ .../blake2b_subkey_default_not_linked.outcome | 13 +++++++++++ .../blake2b_subkey_on_hash2/Jamfile | 9 ++++++++ .../blake2b_subkey_on_hash2/app.cpp | 22 +++++++++++++++++++ .../blake2b_subkey_on_hash2.outcome | 13 +++++++++++ 6 files changed, 88 insertions(+) create mode 100644 tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/blake2b_subkey_on_hash2.outcome diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/Jamfile new file mode 100644 index 00000000..5a498fd8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/blake2b_subkey_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/app.cpp new file mode 100644 index 00000000..0c7840c5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/app.cpp @@ -0,0 +1,22 @@ +// 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) + +// blake2b_subkey on its default backend, backends::sodium, in a program that does not link +// libsodium stops with the instruction to add /third_party//sodium (spec section 5.7, the third +// row), and with no other error. + +#include + +#include +#include + +int main() { + std::array subkey{}; + std::array master_key{}; + std::array context{}; + auto done = webcpp::hash::blake2b_subkey(subkey, master_key, 1, context); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome new file mode 100644 index 00000000..a7cfa4ed --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/blake2b_subkey_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: 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 ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/Jamfile new file mode 100644 index 00000000..2bbbc601 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/blake2b_subkey_on_hash2 of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/app.cpp new file mode 100644 index 00000000..72d927b3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/app.cpp @@ -0,0 +1,22 @@ +// 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) + +// blake2b_subkey on another backend than backends::sodium stops with spec section 3.3's text. + +#include +#include + +#include +#include + +int main() { + std::array subkey{}; + std::array master_key{}; + std::array context{}; + auto done = + webcpp::hash::blake2b_subkey(subkey, master_key, 1, context); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/blake2b_subkey_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/blake2b_subkey_on_hash2.outcome new file mode 100644 index 00000000..565117c0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/blake2b_subkey_on_hash2.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/blake2b_subkey_on_hash2, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: blake2b_subkey is in backends::sodium alone. Name backends::sodium and add /third_party//sodium to the program's Jamfile. From 5dacd5d7ec6ca1a322b4332cc7a746e2538132cf Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 14:31:36 -0300 Subject: [PATCH 12/53] third_party: XKCP's test vectors as /third_party//xkcp_vectors --- doc/releases/0.1.0.adoc | 3 ++- third_party/Jamfile | 12 ++++++++++++ tools/test/third_party_test.py | 7 ++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 8befb454..6a5f6bed 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -284,7 +284,8 @@ could not read and dropped, such as one naming a header that does not exist. /third_party//ctaes, and the fixtures of the user's Jamfiles of webcpp::crypto's block cipher and signing programs. * Added XKCP's Keccak-p[1600] and its sponge, FIPS 202, SP 800-185, TurboSHAKE and -KangarooTwelve files, built from source with webcpp::hash's adapter as `/third_party//xkcp`. +KangarooTwelve files, built from source with webcpp::hash's adapter as `/third_party//xkcp`, its +test vectors as `/third_party//xkcp_vectors`. * Added libsodium 1.0.22, built from source as /third_party//sodium with the defines its own configure finds on each target, and /third_party//sodium-test-config for a program that compiles against its private headers. diff --git a/third_party/Jamfile b/third_party/Jamfile index 3cc05867..8cfaa848 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -437,6 +437,18 @@ lib xkcp : : WEBCPP_HASH_HAS_XKCP=1 $(.gc) ; explicit xkcp ; +# XKCP's test vectors, tests/TestVectors at the pin (ShortMsgKAT_SHA3-*.txt +# and ShortMsgKAT_SHAKE*.txt among them), read at run time from the directory +# WEBCPP_TEST_XKCP_VECTORS gives, on every target. Quoted as wycheproof's +# define is, with forward slashes, so that a path with a space or a backslash +# survives. +.xkcp-vectors = [ regex.replace $(XKCP)/tests/TestVectors "\\\\" "/" ] ; +alias xkcp_vectors : : @xkcp-checked-out : : + "\"WEBCPP_TEST_XKCP_VECTORS=\\\"$(.xkcp-vectors)\\\"\"" + [ webcpp.data $(XKCP)/tests/TestVectors ] + libs/xkcp/tests/TestVectors/ShortMsgKAT_SHA3-256.txt ; +explicit xkcp_vectors ; + # libsodium 1.0.22 (ISC), jedisct1/libsodium at 77e1ce5: every .c of # src/libsodium/, one object per file, with the defines libsodium's own # configure finds on each target (sodium-target-defines), without its diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 1be1c510..ff0e7889 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -520,9 +520,10 @@ def test_xkcp_is_built_file_by_file(root: Path) -> None: def test_xkcp_not_checked_out_is_refused(root: Path) -> None: harness.copy_integration_libraries(root, 'config', 'hash') harness.third_party_of_its_own(root, 'xkcp', checked_out=False) - result = harness.run_b2(root, 'third_party//xkcp') - harness.expect(result, False, 'third_party/libs/xkcp is not checked out', - 'git submodule update --init third_party/libs/xkcp') + for target in ('third_party//xkcp', 'third_party//xkcp_vectors'): + result = harness.run_b2(root, target) + harness.expect(result, False, 'third_party/libs/xkcp is not checked out', + 'git submodule update --init third_party/libs/xkcp') # A build that needs no XKCP never looks for it. harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) From 3c137af3826464562cd9fd7c09f86180b5a2f738 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 14:38:07 -0300 Subject: [PATCH 13/53] tools: openssl_evp_data gives evpmd_sha.txt too, and hash_doc_tables_test reads a partial cell and a later default off BLAKE2b's rows --- third_party/Jamfile | 6 ++++-- tools/test/hash_doc_tables_test.py | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index f0acde55..edded855 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -804,7 +804,8 @@ explicit blake3_vectors ; # OpenSSL's EVP test data (Apache-2.0), test/recipes/30-test_evp_data at the # pin, read at run time from the directory WEBCPP_TEST_OPENSSL_EVP_DATA gives, # on every target, as test data that nothing compiles: webcpp::hash reads the -# keyed BLAKE2s cases of evpmac_blake.txt. Quoted as wycheproof's define is. +# keyed BLAKE2s cases of evpmac_blake.txt and the SHAKE cases of evpmd_sha.txt. +# Quoted as wycheproof's define is. path-constant OPENSSL_EVP_DATA : libs/openssl/test/recipes/30-test_evp_data ; rule openssl-evp-data-checked-out ( properties * ) @@ -820,5 +821,6 @@ rule openssl-evp-data-checked-out ( properties * ) alias openssl_evp_data : : @openssl-evp-data-checked-out : : "\"WEBCPP_TEST_OPENSSL_EVP_DATA=\\\"$(.openssl-evp-data)\\\"\"" [ webcpp.data $(OPENSSL_EVP_DATA) ] - libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt ; + libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt + libs/openssl/test/recipes/30-test_evp_data/evpmd_sha.txt ; explicit openssl_evp_data ; diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index f4960211..1e50bd2d 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -241,11 +241,11 @@ def test_a_family_default_is_of_the_order_or_none(scratch: Path) -> None: def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: library = scratch_library(scratch) files = write_ok(library) - shake = files['generated/backends-sha3-shake.adoc'] - expect('The default of `digests::shake_128` is `xkcp`, whose cell comes with a later ' - 'increment' in shake, shake) - expect('`hash2` (partial: an output past 32 bytes, one Boost.Hash2 result)' in shake, shake) - expect('| hash2 (partial: an output past 64 bytes' in files['backends.adoc'], + blake2 = files['generated/backends-blake2.adoc'] + expect('The default of `digests::blake2b` is `sodium`, whose cell comes with a later ' + 'increment' in blake2, blake2) + expect('`hash2` (partial: an output under 64 bytes' in blake2, blake2) + expect('| hash2 (partial: a tag under 32 bytes' in files['backends.adoc'], 'the backends chapter does not say what the partial cell refuses') From 69a7fef70cefe5319543167b4d90c4d3e71ec6b6 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 14:38:07 -0300 Subject: [PATCH 14/53] libs/hash: webcpp::hash with SHAKE on backends::hash2 whole and its default, and a reference that builds clean --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 5a395d4a..87a4662f 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 5a395d4aa4bceeb35f63e7fd120003b82252201e +Subproject commit 87a4662f3ef2f2a9d1980ba4b4773b6d5b18c4e4 From b2442b7ce8d4e0f2f048a808d784560e46ef05bf Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 15:10:58 -0300 Subject: [PATCH 15/53] tools: doc_tables.py names beside each default only the backends of the functions it shares, and does not call a tag without a default a type --- doc/releases/0.1.0.adoc | 3 +- tools/hash/doc_tables.py | 22 +++++----- tools/test/hash_doc_tables_test.py | 67 ++++++++++++++++++++++++++---- 3 files changed, 74 insertions(+), 18 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index a03460d9..f6e047a4 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -312,7 +312,8 @@ eight columns from which a table scrolls. * Changed tools/hash/doc_tables.py to render webcpp::hash's family tags (digest_of, hasher, mac, argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial cell refuses. * Fixed tools/hash/doc_tables.py naming, beside a default, backends of an algorithm's other -functions, and scattering a backend's constant-time statements. +functions or of functions it shares the default with, saying that a tag without a default is a +type, and scattering a backend's constant-time statements. * Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's tests read at run time on every target. * Added /third_party//blake2_vectors, BLAKE2's test vectors at ed1974e (a shallow submodule), and diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index 5885d513..35dc723f 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -348,21 +348,23 @@ def backends_table(data: Data, algorithm: dict) -> str: defaults = [(name, default) for name, default in defaults if default in data.functions[name][1]['backends']] if not defaults: - names = sorted({b for f in algorithm['functions'] for b in f['backends']}) - out.append(f'One backend, {", ".join(f"`{n}`" for n in names)}: the types take no backend.') - out.append('') + # Types alone take no backend; a family's tag without a default has said so above. + if not families: + names = sorted({b for f in algorithm['functions'] for b in f['backends']}) + out.append(f'One backend, {", ".join(f"`{n}`" for n in names)}: the types take no ' + 'backend.') + out.append('') return '\n'.join(out) - by_backend: dict[str, list[str]] = {} + # One sentence per default and set of other backends, so that each names, as the backends a + # call may name instead, those of its own functions alone. + by_backend: dict[tuple[str, tuple[str, ...]], list[str]] = {} for name, default in defaults: - by_backend.setdefault(default, []).append(name) - for default, functions in by_backend.items(): + others = tuple(sorted(set(data.functions[name][1]['backends']) - {default})) + by_backend.setdefault((default, others), []).append(name) + for (default, others), functions in by_backend.items(): names = [f'`{name}`' for name in functions] named = names[0] if len(names) == 1 else \ ', '.join(names[:-1]) + f' and {names[-1]}' - # The backends a call may name instead: those of these functions, not of the algorithm's - # others. - others = sorted({b for name in functions - for b in data.functions[name][1]['backends']} - {default}) tail = (f'; {", ".join(f"`{b}`" for b in others)} only where the call names it, as its ' 'second template argument') if others else '' out.append(f'The default of {named}: `{default}` on every target, whatever the program ' diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index e8e15ad0..e84429c9 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -249,16 +249,67 @@ def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: 'the backends chapter does not say what the partial cell refuses') +def edit_capabilities(library: Path, edit: Callable[[dict], None]) -> None: + """Rewrites the scratch library's capability table through `edit`.""" + path = library / 'doc/capabilities.json' + table = json.loads(path.read_text(encoding='utf-8')) + edit(table) + path.write_text(json.dumps(table, indent=4) + '\n', encoding='utf-8') + + +def a_cell(since: int) -> dict: + return {'since': since, 'hmacs': None, + 'constant_time': {'value': 'not stated', 'source': 'fixture'}} + + def test_a_default_names_only_its_functions_backends(scratch: Path) -> None: """An algorithm whose functions have different backends: the sentence of each default - names, as the backends a call may name instead, those of its own functions alone.""" + names, as the backends a call may name instead, those of its own functions alone; functions + with one default and the same other backends share a sentence.""" library = scratch_library(scratch) + + def blake2(table: dict) -> None: + rows = {f['name']: f for a in table['algorithms'] for f in a['functions']} + rows['digests::blake2b']['default'] = 'sodium' + rows['digests::blake2b']['backends'] = {'hash2': a_cell(2), 'sodium': a_cell(2)} + rows['digests::blake2s_256']['backends'] = {'hash2': a_cell(2), 'openssl': a_cell(4)} + rows['macs::blake2s_mac']['backends'] = {'hash2': a_cell(2)} + rows['blake2s_256']['backends'] = {'hash2': a_cell(1)} + edit_capabilities(library, blake2) files = write_ok(library) - blake2 = files['generated/backends-blake2.adoc'] - expect('The default of `digests::blake2s_256` and `macs::blake2s_mac`: `hash2` on every ' - 'target, whatever the program links (<>).' in blake2, blake2) + blake2_file = files['generated/backends-blake2.adoc'] + expect('The default of `macs::blake2s_mac`: `hash2` on every target, whatever the program ' + 'links (<>).' in blake2_file, blake2_file) + expect('The default of `digests::blake2s_256`: `hash2` on every target, whatever the ' + 'program links; `openssl` only where the call names it' in blake2_file, blake2_file) expect('The default of `digests::blake2b`: `sodium` on every target, whatever the program ' - 'links; `hash2` only where the call names it' in blake2, blake2) + 'links; `hash2` only where the call names it' in blake2_file, blake2_file) + hkdf = files['generated/backends-hkdf.adoc'] + expect('`bearssl`' not in hkdf.split('The default of `hkdf_extract`')[1].split('\n')[0], + hkdf) + + +def test_a_tag_without_a_default_is_not_said_a_type(scratch: Path) -> None: + """An algorithm whose one row is a family's tag without a default says that the call names + a backend, and not that types take none.""" + library = scratch_library(scratch) + + def lone_tag(table: dict) -> None: + table['algorithms'].append({ + 'name': 'fixture_lone', 'macro': 'FIXTURE_LONE', 'tag': None, 'chapter': 'digests', + 'standard': 'a fixture', 'functions': [{ + 'name': 'digests::fixture_lone', 'kind': 'digest', + 'header': 'webcpp/hash/digest.hpp', 'default': None, + 'backends': {'openssl': a_cell(4)}}]}) + edit_capabilities(library, lone_tag) + guide_path = library / 'doc/guide.json' + guide = json.loads(guide_path.read_text(encoding='utf-8')) + guide['functions']['digests::fixture_lone'] = dict(guide['functions']['digests::sha2_256']) + guide_path.write_text(json.dumps(guide, indent=4) + '\n', encoding='utf-8') + lone = write_ok(library)['generated/backends-fixture-lone.adoc'] + expect('`digests::fixture_lone` has no default backend: the call names one of its backends' + in lone, lone) + expect('the types take no backend' not in lone, lone) def test_each_backend_s_constant_time_sources_are_together(scratch: Path) -> None: @@ -281,8 +332,9 @@ def test_without_measurements_the_tables_say_so(scratch: Path) -> None: 'the comparison table does not say its measurements are missing') expect('measurements.adoc' not in files, 'measurements.adoc without its data') hkdf = files['generated/backends-hkdf.adoc'] - expect('The default of `hkdf_extract`, `hkdf_expand` and `hkdf`: `hash2` on every target' - in hkdf, f'the backends of HKDF do not name the default: {hkdf}') + expect('The default of `hkdf_extract` and `hkdf_expand`: `hash2` on every target' in hkdf + and 'The default of `hkdf`: `hash2` on every target' in hkdf, + f'the backends of HKDF do not name the default: {hkdf}') expect('`bearssl`, `openssl`, `sodium` only where the call names it' in hkdf, hkdf) expect('The default of `argon2id`: `sodium` on every target' in files['generated/backends-argon2id.adoc'], 'Argon2id\'s default') @@ -391,6 +443,7 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_a_family_default_is_of_the_order_or_none, test_a_later_default_and_a_partial_cell_are_said, test_a_default_names_only_its_functions_backends, + test_a_tag_without_a_default_is_not_said_a_type, test_each_backend_s_constant_time_sources_are_together, test_without_measurements_the_tables_say_so, test_with_measurements_the_tables_carry_them, From 0a28d4eb951bee22819fab420aeb0c91c2746cdd Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 16:47:23 -0300 Subject: [PATCH 16/53] tools: webcpp::hash's backends::webcrypto messages and async_hmac's and async_hkdf's are Emscripten fixtures --- .../async_hkdf_not_in_webcrypto/Jamfile | 9 +++++++ .../async_hkdf_not_in_webcrypto/app.cpp | 26 +++++++++++++++++++ .../async_hkdf_not_in_webcrypto.outcome | 13 ++++++++++ .../async_hmac_not_in_webcrypto/Jamfile | 9 +++++++ .../async_hmac_not_in_webcrypto/app.cpp | 26 +++++++++++++++++++ .../async_hmac_not_in_webcrypto.outcome | 13 ++++++++++ .../webcrypto_pbkdf2_hmac/Jamfile | 8 ++++++ .../webcrypto_pbkdf2_hmac/app.cpp | 26 +++++++++++++++++++ .../webcrypto_pbkdf2_hmac.outcome | 13 ++++++++++ .../webcrypto_pool_executor/Jamfile | 8 ++++++ .../webcrypto_pool_executor/app.cpp | 26 +++++++++++++++++++ .../webcrypto_pool_executor.outcome | 13 ++++++++++ 12 files changed, 190 insertions(+) create mode 100644 tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/async_hkdf_not_in_webcrypto.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/async_hmac_not_in_webcrypto.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/webcrypto_pbkdf2_hmac.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/webcrypto_pool_executor.outcome diff --git a/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/Jamfile b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/Jamfile new file mode 100644 index 00000000..fd94f30c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/async_hkdf_not_in_webcrypto of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/app.cpp b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/app.cpp new file mode 100644 index 00000000..e4d5e78f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/app.cpp @@ -0,0 +1,26 @@ +// 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) + +// async_hkdf over an hmac WebCrypto has no HKDF over stops (spec 11.2): the cheap functions have +// an asynchronous form only for the algorithms the browser has. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_hkdf( + context.get_executor(), output, {}, {}, {}, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/async_hkdf_not_in_webcrypto.outcome b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/async_hkdf_not_in_webcrypto.outcome new file mode 100644 index 00000000..ddee4036 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/async_hkdf_not_in_webcrypto.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_hkdf_not_in_webcrypto, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_hkdf takes hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over: call hkdf for the others. diff --git a/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/Jamfile b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/Jamfile new file mode 100644 index 00000000..f65ae712 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/async_hmac_not_in_webcrypto of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/app.cpp b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/app.cpp new file mode 100644 index 00000000..02ed4e85 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/app.cpp @@ -0,0 +1,26 @@ +// 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) + +// async_hmac over an hmac WebCrypto lacks stops (spec 11.2): the cheap functions have an +// asynchronous form only for the algorithms the browser has. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_hmac( + context.get_executor(), output, {}, {}, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/async_hmac_not_in_webcrypto.outcome b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/async_hmac_not_in_webcrypto.outcome new file mode 100644 index 00000000..4e466efe --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/async_hmac_not_in_webcrypto.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_hmac_not_in_webcrypto, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_hmac takes hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has: call mac for the others. diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/Jamfile b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/Jamfile new file mode 100644 index 00000000..126843ee --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/Jamfile @@ -0,0 +1,8 @@ +# 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) + +# async_pbkdf2 on backends::webcrypto over hmac_sha3_256, built for Emscripten. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/app.cpp b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/app.cpp new file mode 100644 index 00000000..3b4cc280 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/app.cpp @@ -0,0 +1,26 @@ +// 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) + +// async_pbkdf2 on backends::webcrypto over an hmac WebCrypto lacks stops the build: WebCrypto's +// PBKDF2 is over SHA-1 and SHA-2 alone. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_pbkdf2( + context.get_executor(), output, {}, {}, 1, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/webcrypto_pbkdf2_hmac.outcome b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/webcrypto_pbkdf2_hmac.outcome new file mode 100644 index 00000000..51bef4b2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/webcrypto_pbkdf2_hmac.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Its only target is Emscripten, where alone the +# asynchronous family takes backends::webcrypto. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::webcrypto has PBKDF2 over hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 and hmac_sha2_512 alone: name a synchronous backend for the others. diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/Jamfile b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/Jamfile new file mode 100644 index 00000000..0cd7872f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/Jamfile @@ -0,0 +1,8 @@ +# 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) + +# backends::webcrypto named with a thread_pool's executor, built for Emscripten. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/app.cpp b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/app.cpp new file mode 100644 index 00000000..5ca5c8eb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/app.cpp @@ -0,0 +1,26 @@ +// 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) + +// backends::webcrypto given a thread_pool's executor stops the build (ruling R73): WebCrypto's +// promise settles in the JavaScript event loop, to which only an io_context's run returns. + +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::thread_pool pool(0); + std::array output{}; + webcpp::hash::async_digest( + pool.get_executor(), output, {}, [](boost::system::error_code /*code*/) {}); + pool.join(); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/webcrypto_pool_executor.outcome b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/webcrypto_pool_executor.outcome new file mode 100644 index 00000000..49cf04ee --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/webcrypto_pool_executor.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Its only target is Emscripten, where alone the +# asynchronous family takes backends::webcrypto. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::webcrypto completes through an io_context run on the calling thread, whose run returns to the JavaScript event loop where WebCrypto's promise settles: pass that io_context's executor, not a thread_pool's. From 79277fb1c7c52a47db43b45c222e3f5229cc0782 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 17:08:16 -0300 Subject: [PATCH 17/53] tools: hash_doc_tables_test.py makes its case of a later default and partial cells itself, as the real table's cells land --- tools/test/hash_doc_tables_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index f4960211..b2b3e95b 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -239,7 +239,18 @@ def test_a_family_default_is_of_the_order_or_none(scratch: Path) -> None: def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: + # The case is made here, not read from the real table, whose cells land increment by + # increment: SHAKE's default xkcp without its cell yet, and hash2's partial cells. library = scratch_library(scratch) + path = library / 'doc/capabilities.json' + table = json.loads(path.read_text(encoding='utf-8')) + for name, size in (('digests::shake_128', 32), ('digests::shake_256', 64)): + row = family_row(table, name) + row['default'] = 'xkcp' + row['backends'].pop('xkcp', None) + row['backends']['hash2']['partial'] = (f'an output past {size} bytes, one Boost.Hash2 ' + 'result') + path.write_text(json.dumps(table), encoding='utf-8') files = write_ok(library) shake = files['generated/backends-sha3-shake.adoc'] expect('The default of `digests::shake_128` is `xkcp`, whose cell comes with a later ' From 51901263a2b1ec58ad048560546203d4c9a05c35 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 17:54:37 -0300 Subject: [PATCH 18/53] third_party: openssl_evp_data names evpmac_common.txt and evpmac_siphash.txt, which hash's tests read --- third_party/Jamfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index 69db22a3..efe03eb0 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -804,7 +804,8 @@ explicit blake3_vectors ; # OpenSSL's EVP test data (Apache-2.0), test/recipes/30-test_evp_data at the # pin, read at run time from the directory WEBCPP_TEST_OPENSSL_EVP_DATA gives, # on every target, as test data that nothing compiles: webcpp::hash reads the -# keyed BLAKE2s cases of evpmac_blake.txt. Quoted as wycheproof's define is. +# keyed BLAKE2 cases of evpmac_blake.txt, the KMAC cases of evpmac_common.txt +# and the SipHash cases of evpmac_siphash.txt. Quoted as wycheproof's define is. path-constant OPENSSL_EVP_DATA : libs/openssl/test/recipes/30-test_evp_data ; rule openssl-evp-data-checked-out ( properties * ) @@ -820,7 +821,9 @@ rule openssl-evp-data-checked-out ( properties * ) alias openssl_evp_data : : @openssl-evp-data-checked-out : : "\"WEBCPP_TEST_OPENSSL_EVP_DATA=\\\"$(.openssl-evp-data)\\\"\"" [ webcpp.data $(OPENSSL_EVP_DATA) ] - libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt ; + libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt + libs/openssl/test/recipes/30-test_evp_data/evpmac_common.txt + libs/openssl/test/recipes/30-test_evp_data/evpmac_siphash.txt ; explicit openssl_evp_data ; # BLAKE2's reference code package (CC0-1.0) at ed1974e, shallow, as test data From f6992e0be6de31a5b30644699ecc00fe6c1607dc Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 18:06:34 -0300 Subject: [PATCH 19/53] tools: the Emscripten fixtures of hash's libsodium refusals name blake2b_subkey --- .../argon2id_default_not_linked.outcome | 2 +- .../blake2b_subkey_default_not_linked.outcome | 2 +- .../scrypt_default_not_linked/scrypt_default_not_linked.outcome | 2 +- .../sodium_default_not_linked/sodium_default_not_linked.outcome | 2 +- .../hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome index cab59234..61ccaa72 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: 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 ; +contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome index a7cfa4ed..53d4b8df 100644 --- a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: 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 ; +contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome index 99688c29..ccdcd981 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: 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 ; +contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome index c5839b23..8eaa7ecf 100644 --- a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: 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 ; +contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome index c0cf3516..134b8e46 100644 --- a/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: 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 ; +contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; From fe738b49616599a1864412d95689e3ff50361dd3 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 18:21:29 -0300 Subject: [PATCH 20/53] tools: the release notes' line on doc_tables.py's fixes keeps to the changelog lint's 30 words --- doc/releases/0.1.0.adoc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index f6e047a4..15d1a5f0 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -311,9 +311,8 @@ llms.txt from its capability table and measurements, and checks them when its pa eight columns from which a table scrolls. * Changed tools/hash/doc_tables.py to render webcpp::hash's family tags (digest_of, hasher, mac, argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial cell refuses. -* Fixed tools/hash/doc_tables.py naming, beside a default, backends of an algorithm's other -functions or of functions it shares the default with, saying that a tag without a default is a -type, and scattering a backend's constant-time statements. +* Fixed tools/hash/doc_tables.py naming, beside a default, backends of functions that do not +share it, calling a tag without a default a type, and scattering constant-time statements. * Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's tests read at run time on every target. * Added /third_party//blake2_vectors, BLAKE2's test vectors at ed1974e (a shallow submodule), and From 9f90908703cc85ce4c12a4134598211280c2c72d Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 18:30:15 -0300 Subject: [PATCH 21/53] third_party: openssl_evp_data names evpkdf_argon2.txt, which hash's tests read --- third_party/Jamfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index efe03eb0..7175b426 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -804,8 +804,9 @@ explicit blake3_vectors ; # OpenSSL's EVP test data (Apache-2.0), test/recipes/30-test_evp_data at the # pin, read at run time from the directory WEBCPP_TEST_OPENSSL_EVP_DATA gives, # on every target, as test data that nothing compiles: webcpp::hash reads the -# keyed BLAKE2 cases of evpmac_blake.txt, the KMAC cases of evpmac_common.txt -# and the SipHash cases of evpmac_siphash.txt. Quoted as wycheproof's define is. +# Argon2 cases of evpkdf_argon2.txt, the keyed BLAKE2 cases of evpmac_blake.txt, +# the KMAC cases of evpmac_common.txt and the SipHash cases of +# evpmac_siphash.txt. Quoted as wycheproof's define is. path-constant OPENSSL_EVP_DATA : libs/openssl/test/recipes/30-test_evp_data ; rule openssl-evp-data-checked-out ( properties * ) @@ -821,6 +822,7 @@ rule openssl-evp-data-checked-out ( properties * ) alias openssl_evp_data : : @openssl-evp-data-checked-out : : "\"WEBCPP_TEST_OPENSSL_EVP_DATA=\\\"$(.openssl-evp-data)\\\"\"" [ webcpp.data $(OPENSSL_EVP_DATA) ] + libs/openssl/test/recipes/30-test_evp_data/evpkdf_argon2.txt libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt libs/openssl/test/recipes/30-test_evp_data/evpmac_common.txt libs/openssl/test/recipes/30-test_evp_data/evpmac_siphash.txt ; From 54f53ccc63457f69d781684c81f736db661e1989 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 18:30:16 -0300 Subject: [PATCH 22/53] tools: hash's Argon2 and scrypt messages name backends::openssl, a fixture for Argon2d on libsodium, and llms.txt no longer calls libsodium their only backend --- doc/releases/0.1.0.adoc | 2 ++ tools/hash/doc_tables.py | 9 ++++---- .../argon2_no_default.outcome | 2 +- .../hash_jamfiles/argon2d_on_sodium/Jamfile | 9 ++++++++ .../hash_jamfiles/argon2d_on_sodium/app.cpp | 21 +++++++++++++++++++ .../argon2d_on_sodium.outcome | 13 ++++++++++++ .../hash_jamfiles/argon2id_on_hash2/app.cpp | 3 ++- .../argon2id_on_hash2.outcome | 2 +- .../hash_jamfiles/scrypt_on_hash2/app.cpp | 3 ++- .../scrypt_on_hash2/scrypt_on_hash2.outcome | 2 +- 10 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/argon2d_on_sodium.outcome diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 15d1a5f0..f95e103f 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -313,6 +313,8 @@ eight columns from which a table scrolls. argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial cell refuses. * Fixed tools/hash/doc_tables.py naming, beside a default, backends of functions that do not share it, calling a tag without a default a type, and scattering constant-time statements. +* Fixed tools/hash/doc_tables.py's llms.txt calling backends::sodium the only backend of +argon2id and scrypt, which backends::openssl has too. * Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's tests read at run time on every target. * Added /third_party//blake2_vectors, BLAKE2's test vectors at ed1974e (a shallow submodule), and diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index 35dc723f..57c2e1da 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -431,10 +431,11 @@ def llms_txt(data: Data) -> str: '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. The families digest_of, hasher, mac and argon2 take a tag of ' - 'digests, macs or kdfs and a backend, by default the first of backends::hash2, ' - 'backends::xkcp, backends::blake3 and backends::sodium that has the tag.', '', + 'its second template argument; argon2id and scrypt run on backends::sodium unless ' + 'the call names backends::openssl. The families digest_of, hasher, mac and argon2 ' + 'take a tag of digests, macs or kdfs and a backend, by default the first of ' + 'backends::hash2, backends::xkcp, backends::blake3 and backends::sodium that has ' + 'the tag.', '', '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.', '', diff --git a/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome b/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome index b86b3c42..a9b4cd2b 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome +++ b/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: kdfs::argon2d has no default backend, and no backend has it yet. +contains: webcpp::hash: kdfs::argon2d has no default backend. Name one of: backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/Jamfile b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/Jamfile new file mode 100644 index 00000000..6be39489 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/argon2d_on_sodium of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/app.cpp new file mode 100644 index 00000000..5f6baf71 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/app.cpp @@ -0,0 +1,21 @@ +// 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) + +// argon2 over kdfs::argon2d on backends::sodium, which has no Argon2d, stops naming the backends +// that have it (spec 3.3, the tag's row of doc/capabilities.json). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array salt{}; + auto done = webcpp::hash::argon2( + output, {}, salt, {.passes = 3, .memory_kib = 65536}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/argon2d_on_sodium.outcome b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/argon2d_on_sodium.outcome new file mode 100644 index 00000000..68f4f7be --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/argon2d_on_sodium.outcome @@ -0,0 +1,13 @@ +# 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 compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/argon2d_on_sodium, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::argon2d is not in this backend. Name one of: backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp index 969844ce..f3d1dfbc 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp @@ -4,7 +4,8 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// argon2id on another backend than backends::sodium stops with spec section 3.3's text. +// argon2id on another backend than backends::sodium and backends::openssl stops with spec section +// 3.3's text. #include #include diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome index f4583172..acecd86d 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome +++ b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: argon2id is in backends::sodium alone. Name backends::sodium and add /third_party//sodium to the program's Jamfile. +contains: webcpp::hash: argon2id is in backends::sodium and backends::openssl alone. Name one, and add /third_party//sodium or /webcpp/hash//openssl to the program's Jamfile. diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp index 6ddaa95b..820a1b9d 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp @@ -4,7 +4,8 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// scrypt on another backend than backends::sodium stops with spec section 3.3's text. +// scrypt on another backend than backends::sodium and backends::openssl stops with spec section +// 3.3's text. #include #include diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome index 79e06c6e..c33e2973 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome +++ b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: scrypt is in backends::sodium alone. Name backends::sodium and add /third_party//sodium to the program's Jamfile. +contains: webcpp::hash: scrypt is in backends::sodium and backends::openssl alone. Name one, and add /third_party//sodium or /webcpp/hash//openssl to the program's Jamfile. From c8d87e10d6d0691dbeece106fccd70029a8b08ae Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 18:48:29 -0300 Subject: [PATCH 23/53] third_party: sodium_vectors names libsodium's pwhash_argon2i.exp, which hash's tests read --- third_party/Jamfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index 69db22a3..aaf9e573 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -850,13 +850,15 @@ explicit blake2_vectors ; # libsodium's own tests' expected outputs (ISC), test/default/*.exp at the pin, # read at run time from the directory WEBCPP_TEST_SODIUM_VECTORS gives, on # every target, never copied: webcpp::hash reads generichash3.exp, kdf.exp, -# shorthash.exp and siphashx24.exp. Quoted as wycheproof's define is. +# pwhash_argon2i.exp, shorthash.exp and siphashx24.exp. Quoted as wycheproof's +# define is. .sodium-vectors = [ regex.replace $(SODIUM)/test/default "\\\\" "/" ] ; alias sodium_vectors : : @sodium-checked-out : : "\"WEBCPP_TEST_SODIUM_VECTORS=\\\"$(.sodium-vectors)\\\"\"" [ webcpp.data $(SODIUM)/test/default ] libs/libsodium/test/default/generichash3.exp libs/libsodium/test/default/kdf.exp + libs/libsodium/test/default/pwhash_argon2i.exp libs/libsodium/test/default/shorthash.exp libs/libsodium/test/default/siphashx24.exp ; explicit sodium_vectors ; From 720b8c43e9cbce06c5ea2d2eceeaa21941c8c290 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 18:48:29 -0300 Subject: [PATCH 24/53] guidelines: hash's entry describes increments 1 and 2 as built, with the default rule of designs D33 and D34 --- CODING-GUIDELINES.md | 63 ++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index b52aea23..b3e25c42 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -969,7 +969,7 @@ update --init third_party/libs/`; a build that needs none never looks. | `openssl` | OpenSSL 3.5.9 at `45e844fa2a14ec92d146bd8f5778ac130b6625fb`; static libssl/libcrypto and matching generated headers, built by upstream Configure/Make through B2 for native Clang/GCC/MSVC, WASIp2 single and WASIp3 single/cooperative | Apache-2.0 | | `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT | | `sodium` | libsodium 1.0.22 at `77e1ce5`, the submodule `third_party/libs/libsodium`; a static library built file by file by `third_party/Jamfile` (every `.c` of `src/libsodium/`, no assembly, the defines libsodium's configure finds on each target, upstream's `builds/msvc/version.h` copied into the build directory) with webcpp::hash's canary, on every target; `WEBCPP_HASH_HAS_SODIUM=1`; `sodium-test-config` gives a program its private headers and test defines; shared with webcpp::crypto | ISC | -| `sodium_vectors` | libsodium's own tests' expected outputs, `test/default/*.exp` of the submodule `third_party/libs/libsodium` at `77e1ce5`, test data: hash's tests read `generichash3.exp`, `kdf.exp`, `shorthash.exp` and `siphashx24.exp` at run time under the directory its define `WEBCPP_TEST_SODIUM_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | ISC | +| `sodium_vectors` | libsodium's own tests' expected outputs, `test/default/*.exp` of the submodule `third_party/libs/libsodium` at `77e1ce5`, test data: hash's tests read `generichash3.exp`, `kdf.exp`, `pwhash_argon2i.exp`, `shorthash.exp` and `siphashx24.exp` at run time under the directory its define `WEBCPP_TEST_SODIUM_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | ISC | | `wycheproof` | C2SP's Wycheproof at `12fd3aaf` (2026-10-06), shallow, test data: crypto's tests read its `testvectors_v1/` at run time under the directory its define `WEBCPP_TEST_WYCHEPROOF` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of its files changes | Apache-2.0 | | `xkcp` | XKCP (the Keccak team's code package) at `d20c8fc` (2026-11-10, no release tags); `third_party/Jamfile` compiles its `KeccakP-1600-opt64.c` alone (Keccak-p[1600], the generic64 profile) with webcpp::hash's adapter, `config.h` and canary, on every target; `WEBCPP_HASH_HAS_XKCP=1` | CC0; `brg_endian.h` under Brian Gladman's terms | @@ -9099,7 +9099,7 @@ summary. `organization/openspec/changes/site-increments-4-5/specs/site/spec.md` (proposals). -### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increment 1 built, not merged) +### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increments 1 and 2 built, not merged) webcpp::hash is one entry point for hashing and key derivation in a C++20 program on every target webcpp has, a wrapper (`"port-of": null`). Increment 1 @@ -9107,21 +9107,25 @@ is built on the library's branch (`libs/hash`, to become `webcpporg/hash`): Boost.Hash2's algorithms and `hmac` re-exported by alias (`algorithms.hpp`, `hmac.hpp`); Keccak-256 with the original padding over XKCP's permutation (`keccak.hpp`) and BLAKE3 over its official C implementation (`blake3.hpp`), -both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 -(RFC 8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and -`openssl` (`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and -scrypt (RFC 7914, `scrypt.hpp`) from libsodium; the profile and the default -backend (`config.hpp`), the capability table (`doc/capabilities.json`), and -the measured table (`doc/measurements*.json`, regenerated by the `measure` -lane). The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, -`sodium`, `bearssl`, each with a canary), their own suites by the `c-suites` -lane (`test/c_suites`), the examples are in `example/` and the documentation -in `doc/`. Every function is synchronous, reports failure as a -`boost::system::result`, takes its data as `std::span` and allocates nothing in -webcpp's own code. Its repository, `webcpporg/hash`, is still to be created by -the owner (gates G1, G2 and G4); the proposal, with the specification, the -design and the plan, is in `libraries/hash/openspec/changes/genesis/` -(proposals). +both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 (RFC +8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and `openssl` +(`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and scrypt (RFC +7914, `scrypt.hpp`) from libsodium; the default backend (`config.hpp`), the +capability table (`doc/capabilities.json`), and the measured table +(`doc/measurements*.json`), a dated reference of 2026-11-16 that decides +nothing. The families `digest_of`, `hasher`, `mac` and `argon2` take the tags of +`digests`, `macs` and `kdfs`; increment 2 gives them libsodium's whole surface: +BLAKE2b with its key, salt, personalisation and length, SipHash-2-4 and +SipHash-2-4x, BLAKE2b subkeys (`blake2b_subkey.hpp`), SHA-2, SHA-3, SHAKE, +TurboSHAKE, HMAC, and Argon2i and Argon2id with one lane. The C libraries are +built by `third_party/Jamfile` (`xkcp`, `blake3`, `sodium`, `bearssl`, each with +a canary), their own suites by the `c-suites` lane (`test/c_suites`), the +examples are in `example/` and the documentation in `doc/`. Every function is +synchronous, reports failure as a `boost::system::result`, takes its data as +`std::span` and allocates nothing in webcpp's own code. Its repository, +`webcpporg/hash`, is still to be created by the owner (gates G1, G2 and G4); the +proposal, with the specification, the design and the plan, is in +`libraries/hash/openspec/changes/genesis/` (proposals). - **Two constructions of webcpp's own, over an audited primitive each, and no primitive.** HKDF and PBKDF2 over Boost.Hash2's `hmac` on every target, @@ -9133,13 +9137,15 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` writes no cryptography of its own, as the owner recorded on 2026-11-14. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.3 (proposals). -- **The key derivation functions have backends, as webcpp::crypto's - algorithms do, and a backend that lacks a function refuses at compile - time.** `backends::hash2`, `sodium`, `bearssl` and `openssl` (native, - wasip2 and wasip3); natively the fastest linked backend is the default, on - WebAssembly the one that gives the smallest binary, decided by a measured - table that every pin move regenerates; one setting in `config.hpp` (a - profile) changes every default at once. +- **The key derivation functions and the families have backends, as + webcpp::crypto's algorithms do, and a backend that lacks a function or a + tag refuses at compile time.** `backends::hash2`, `xkcp`, `blake3`, + `sodium`, `bearssl` and `openssl`; the default is one stated rule, the same + on every target and fixed (designs D33 and D34): the first of `hash2`, + `xkcp`, `blake3` and `sodium` that has the algorithm whole, else the first + of them with a partial cell, else none (the call names its backend); + `bearssl`, `openssl`, `botan` and `webcrypto` are never a default. No + measurement decides it. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.4 (proposals). - **The C libraries of hash (`xkcp`, `blake3`, `sodium`) are built file by @@ -9151,10 +9157,11 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 5 (proposals). - **Seven increments, each usable alone.** The first, built, is Hash2 by alias, - `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the profile and the - measured table; the next ones widen the backends' surface (libsodium's, - XKCP's, OpenSSL's, BearSSL's, Botan's) and add the browser backend over - WebCrypto through a parallel asynchronous family. + `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the default backend + and the measured table; the second, built, is the families and libsodium's + whole surface; the next ones widen the other backends' surface (XKCP's, + OpenSSL's, BearSSL's, Botan's) and add the browser backend over WebCrypto + through a parallel asynchronous family. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.5 (proposals). From 75ccb773701a9e6e856888586ec38567115b39a9 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 19:00:48 -0300 Subject: [PATCH 25/53] tools: third_party_test.py states BLAKE2's pin as its neighbours do --- tools/test/third_party_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 987d2783..d04eacfc 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -86,7 +86,12 @@ # The commit the Bitcoin Improvement Proposals' repository is pinned at: the test vectors of # BIP340 and BIP341 (libs/crypto/test/secp256k1_bip340_test.cpp, secp256k1_xonly_tweak_test.cpp). BIPS_COMMIT = '927b6de9915c9262615a6399de51b200f81e5aa4' + BLAKE2 = 'third_party/libs/blake2' + +# The commit BLAKE2's reference repository is pinned at: the test vectors of webcpp::hash's +# BLAKE2b (testvectors/blake2b-kat.txt and blake2-kat.json, read through +# /third_party//blake2_vectors). BLAKE2_COMMIT = 'ed1974ea83433eba7b2d95c5dcd9ac33cb847913' SECP256K1 = 'third_party/libs/secp256k1' From 3bec8971d6a8ab97fd5bead311910c6ba7401442 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 19:52:04 -0300 Subject: [PATCH 26/53] tools: doc_tables.py renders webcpp::hash's backends::webcrypto as a backend of the asynchronous family only --- doc/releases/0.1.0.adoc | 2 ++ tools/hash/doc_tables.py | 54 +++++++++++++++++++++++------- tools/test/hash_doc_tables_test.py | 33 +++++++++++++++++- 3 files changed, 76 insertions(+), 13 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 198addd3..ec12faff 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -315,6 +315,8 @@ argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial tests read at run time on every target. * Changed tools/test/hash_jamfiles_test.py to copy libs/asio into its scratch superproject, so that the messages of webcpp::hash's asynchronous family are built on Emscripten too. +* Changed tools/hash/doc_tables.py to render a backend of webcpp::hash's asynchronous family +alone, backends::webcrypto, with the note "asynchronous family only" in every table. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index 31ee6559..be0d78ba 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -285,15 +285,34 @@ def backend_targets(data: Data, backend: str) -> str: return ', '.join(data.backends[backend]['targets']) +ASYNCHRONOUS_ONLY = 'asynchronous family only' + + +def asynchronous_only(data: Data, backend: str) -> bool: + """Whether only the asynchronous family takes the backend (backends::webcrypto).""" + return bool(data.backends[backend].get('asynchronous_only')) + + +def llms_note(data: Data, backend: str) -> str: + """backend_note in llms.txt's form, after a comma.""" + return f', {ASYNCHRONOUS_ONLY}' if asynchronous_only(data, backend) else '' + + +def backend_note(data: Data, backend: str) -> str: + """What follows a backend's name in a table: that only the asynchronous family takes it.""" + return f' ({ASYNCHRONOUS_ONLY})' if asynchronous_only(data, backend) else '' + + def partial_text(held: dict) -> str: """What a partial cell refuses, after its backend's name; nothing for a whole cell.""" partial = held.get('partial') return f' (partial: {cell(partial)})' if partial else '' -def backend_text(backend: str, held: dict) -> str: - """A cell's backend, with what it refuses when it is partial.""" - return f'`{backend}`{partial_text(held)}' +def backend_text(data: Data, backend: str, held: dict) -> str: + """A cell's backend, with what it refuses when it is partial, and whether only the + asynchronous family takes it.""" + return f'`{backend}`{backend_note(data, backend)}{partial_text(held)}' def hmacs_text(hmacs: list[str] | None) -> str: @@ -318,7 +337,7 @@ def backends_table(data: Data, algorithm: dict) -> str: for backend, held in function['backends'].items(): out.append('') out.append(f'| `{function["name"]}`') - out.append(f'| {backend_text(backend, held)}') + out.append(f'| {backend_text(data, backend, held)}') out.append(f'| `{data.backends[backend]["jamfile"]}`') out.append(f'| {backend_targets(data, backend)}') out.append(f'| {hmacs_text(held["hmacs"])}') @@ -355,15 +374,21 @@ def backends_table(data: Data, algorithm: dict) -> str: by_backend: dict[str, list[str]] = {} for name, default in defaults: by_backend.setdefault(default, []).append(f'`{name}`') + used = {b for f in algorithm['functions'] for b in f['backends']} for default, names in by_backend.items(): named = names[0] if len(names) == 1 else \ ', '.join(names[:-1]) + f' and {names[-1]}' - others = sorted({b for f in algorithm['functions'] for b in f['backends']} - {default}) + others = sorted(b for b in used - {default} if not asynchronous_only(data, b)) tail = (f'; {", ".join(f"`{b}`" for b in others)} only where the call names it, as its ' 'second template argument') if others else '' out.append(f'The default of {named}: `{default}` on every target, whatever the program ' f'links{tail} (<>).') out.append('') + for backend in sorted(b for b in used if asynchronous_only(data, b)): + out.append(f'`{backend}` serves the asynchronous family alone, on ' + f'{backend_targets(data, backend).replace(", ", " and ").capitalize()}, where ' + 'the type of its asynchronous call names it (<>).') + out.append('') return '\n'.join(out) @@ -376,7 +401,7 @@ def choose_table(data: Data) -> str: '| Example') for case in data.guide['use_cases']: _, function = data.functions[case['function']] - jamfiles = ', '.join(f'`{b}`: `{data.backends[b]["jamfile"]}`' + jamfiles = ', '.join(f'`{b}`{backend_note(data, b)}: `{data.backends[b]["jamfile"]}`' for b in function['backends']) out.append('') out.append(f'| {cell(case["need"])}') @@ -422,7 +447,9 @@ def llms_txt(data: Data) -> str: '> 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 ' + 'returns boost::system::result and allocates nothing in webcpp\'s own code; ' + 'async.hpp gives them an asynchronous form over webcpp::asio, and ' + 'backends::webcrypto, the browser\'s WebCrypto, serves that form alone. 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 ' @@ -445,7 +472,7 @@ def llms_txt(data: Data) -> str: continue for function in algorithm['functions']: facts = data.guide['functions'][function['name']] - backends = ', '.join(f'{b} ({data.backends[b]["jamfile"]}; ' + backends = ', '.join(f'{b}{llms_note(data, b)} ({data.backends[b]["jamfile"]}; ' f'{backend_targets(data, b)})' for b in function['backends']) standard = facts.get('standard', algorithm['standard']) @@ -486,11 +513,13 @@ def backends_chapter(data: Data) -> str: lines = chapter_header('Backends', 'hash-backends', 'doc/capabilities.json') lines += ['Which backend implements each function, over which hmacs, on which targets, and ' 'what upstream', 'states about its constant time. The backends:', '', - '[cols="1,3,1,2,3",options="header"]', '|===', - '| Backend | Library | Licence | Jamfile | Targets'] + '[cols="1,3,1,2,2,2",options="header"]', '|===', + '| Backend | Library | Licence | Jamfile | Targets | Called by'] for b in table['backends']: + called = (f'{ASYNCHRONOUS_ONLY} (async.hpp)' if b.get('asynchronous_only') + else 'every function of its cells') lines += ['', f'| {b["name"]}', f'| {b["library"]}', f'| {b["licence"]}', - f'| `{b["jamfile"]}`', f'| {", ".join(b["targets"])}'] + f'| `{b["jamfile"]}`', f'| {", ".join(b["targets"])}', f'| {called}'] lines += ['|===', ''] chapters: dict[str, list[dict]] = {} for algorithm in table['algorithms']: @@ -507,7 +536,8 @@ def backends_chapter(data: Data) -> str: continue hmacs = ', '.join(c['hmacs']) if c['hmacs'] else '-' targets = ', '.join(data.backends[name]['targets']) - lines += ['', f'| {function["name"]}', f'| {name}{partial_text(c)}', + lines += ['', f'| {function["name"]}', + f'| {name}{backend_note(data, name)}{partial_text(c)}', f'| {hmacs}', f'| {c["constant_time"]["value"]}', f'| {targets}'] lines += ['|===', ''] diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index f4960211..037ea713 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -15,7 +15,8 @@ example is not there, and so does a function of the capability table without a default. Every function's default is the capability table's, `hash2` for HKDF whatever the measurements say. A family's tag (spec 2.15) names a default of the order hash2, xkcp, blake3, sodium, or none, and -one whose cell comes in a later increment is said so; a partial cell says what it refuses. +one whose cell comes in a later increment is said so; a partial cell says what it refuses. A +backend of the asynchronous family alone (backends::webcrypto) is named so in every table. Without doc/measurements.json the tables say so, carry no measured column and render no measurements.adoc; with it (a fixture in its shape) they carry the throughput and the size, and measurements.adoc renders it as the dated reference that decides nothing; a hand edit of the @@ -249,6 +250,35 @@ def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: 'the backends chapter does not say what the partial cell refuses') +def test_an_asynchronous_backend_is_said(scratch: Path) -> None: + # backends::webcrypto serves the asynchronous family alone (its "asynchronous_only" field): + # every table names it with that note, and a synchronous call never names it. + library = scratch_library(scratch) + files = write_ok(library) + backends = files['backends.adoc'] + expect('| webcrypto\n| the JavaScript runtime' in backends, backends) + expect('| asynchronous family only (async.hpp)' in backends, backends) + expect('| every function of its cells' in backends, backends) + expect('| hkdf\n| webcrypto (asynchronous family only)' in backends, backends) + hkdf = files['generated/backends-hkdf.adoc'] + expect('| `webcrypto` (asynchronous family only)' in hkdf, hkdf) + expect('`bearssl`, `openssl`, `sodium` only where the call names it' in hkdf, hkdf) + expect('`webcrypto` serves the asynchronous family alone, on Emscripten, where the type of ' + 'its asynchronous call names it (<>).' in hkdf, hkdf) + digests = files['generated/backends-md5-sha1-sha2.adoc'] + expect('`webcrypto` serves the asynchronous family alone' in digests, digests) + expect('webcrypto, asynchronous family only (/webcpp/asio//asio; emscripten)' + in files['llms.txt'], 'llms.txt does not say webcrypto is asynchronous only') + expect('backends::webcrypto, the browser\'s WebCrypto, serves that form alone' + in files['llms.txt'], 'llms.txt does not name the asynchronous form') + table = json.loads((library / 'doc/capabilities.json').read_text(encoding='utf-8')) + for backend in table['backends']: + backend.pop('asynchronous_only', None) + (library / 'doc/capabilities.json').write_text(json.dumps(table), encoding='utf-8') + plain = write_ok(library)['backends.adoc'] + expect('asynchronous family only' not in plain, 'a note without its field') + + def test_without_measurements_the_tables_say_so(scratch: Path) -> None: library = scratch_library(scratch) files = write_ok(library) @@ -367,6 +397,7 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_every_function_names_its_default, test_a_family_default_is_of_the_order_or_none, test_a_later_default_and_a_partial_cell_are_said, + test_an_asynchronous_backend_is_said, test_without_measurements_the_tables_say_so, test_with_measurements_the_tables_carry_them, test_a_hand_edit_of_the_measurements_fails, From 25c3f4f32b8bbf43ceced3883ef522d344b80e0c Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 19:52:04 -0300 Subject: [PATCH 27/53] guidelines: hash's entry in chapter 17 states increment 7, the asynchronous family and backends::webcrypto, built --- CODING-GUIDELINES.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 43264225..9c1a460d 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -9097,7 +9097,7 @@ summary. `organization/openspec/changes/site-increments-4-5/specs/site/spec.md` (proposals). -### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increment 1 built, not merged) +### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increments 1 and 7 built, not merged) webcpp::hash is one entry point for hashing and key derivation in a C++20 program on every target webcpp has, a wrapper (`"port-of": null`). Increment 1 @@ -9116,7 +9116,12 @@ lane). The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, lane (`test/c_suites`), the examples are in `example/` and the documentation in `doc/`. Every function is synchronous, reports failure as a `boost::system::result`, takes its data as `std::span` and allocates nothing in -webcpp's own code. Its repository, `webcpporg/hash`, is still to be created by +webcpp's own code; increment 7, built, gives them an asynchronous family in +`async.hpp` over webcpp::asio (any completion token, Cobalt's `use_op` +included): the password hashes and PBKDF2 on a thread pool where the build +has threads, the digests, HMAC and HKDF through a post, and +`backends::webcrypto`, the browser's WebCrypto on Emscripten, which only that +family takes. Its repository, `webcpporg/hash`, is still to be created by the owner (gates G1, G2 and G4); the proposal, with the specification, the design and the plan, is in `libraries/hash/openspec/changes/genesis/` (proposals). @@ -9151,8 +9156,9 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` - **Seven increments, each usable alone.** The first, built, is Hash2 by alias, `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the profile and the measured table; the next ones widen the backends' surface (libsodium's, - XKCP's, OpenSSL's, BearSSL's, Botan's) and add the browser backend over - WebCrypto through a parallel asynchronous family. + XKCP's, OpenSSL's, BearSSL's, Botan's), and the seventh, built, adds the + browser backend over WebCrypto through a parallel asynchronous family, whose + cells `doc/capabilities.json` marks asynchronous only. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.5 (proposals). From ab76c402dd78946a109c5e40ef9bd433eb82d342 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 20:21:55 -0300 Subject: [PATCH 28/53] guidelines: hash's entry describes increments 1 and 3 as built, with the default rule of designs D33 and D34 --- CODING-GUIDELINES.md | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index ef2f2db7..635e4f01 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -9097,7 +9097,7 @@ summary. `organization/openspec/changes/site-increments-4-5/specs/site/spec.md` (proposals). -### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increment 1 built, not merged) +### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increments 1 and 3 built, not merged) webcpp::hash is one entry point for hashing and key derivation in a C++20 program on every target webcpp has, a wrapper (`"port-of": null`). Increment 1 @@ -9108,10 +9108,14 @@ Boost.Hash2's algorithms and `hmac` re-exported by alias (`algorithms.hpp`, both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 (RFC 8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and `openssl` (`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and -scrypt (RFC 7914, `scrypt.hpp`) from libsodium; the profile and the default -backend (`config.hpp`), the capability table (`doc/capabilities.json`), and -the measured table (`doc/measurements*.json`, regenerated by the `measure` -lane). The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, +scrypt (RFC 7914, `scrypt.hpp`) from libsodium; the default backend +(`config.hpp`), the capability table (`doc/capabilities.json`), and the +measured table (`doc/measurements*.json`), a dated reference of 2026-11-16 that +decides nothing. The families `digest_of`, `hasher`, `mac` and `argon2` take +the tags of `digests`, `macs` and `kdfs`; increment 3 gives them XKCP's +surface: Keccak-224 to Keccak-512, SHA-3, SHAKE, SP 800-185's cSHAKE, KMAC, +TupleHash and ParallelHash, and RFC 9861's KangarooTwelve and TurboSHAKE. The +C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, `sodium`, `bearssl`, each with a canary), their own suites by the `c-suites` lane (`test/c_suites`), the examples are in `example/` and the documentation in `doc/`. Every function is synchronous, reports failure as a @@ -9131,13 +9135,15 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` writes no cryptography of its own, as the owner recorded on 2026-11-14. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.3 (proposals). -- **The key derivation functions have backends, as webcpp::crypto's - algorithms do, and a backend that lacks a function refuses at compile - time.** `backends::hash2`, `sodium`, `bearssl` and `openssl` (native, - wasip2 and wasip3); natively the fastest linked backend is the default, on - WebAssembly the one that gives the smallest binary, decided by a measured - table that every pin move regenerates; one setting in `config.hpp` (a - profile) changes every default at once. +- **The key derivation functions and the families have backends, as + webcpp::crypto's algorithms do, and a backend that lacks a function or a + tag refuses at compile time.** `backends::hash2`, `xkcp`, `blake3`, + `sodium`, `bearssl` and `openssl`; the default is one stated rule, the same + on every target and fixed (designs D33 and D34): the first of `hash2`, + `xkcp`, `blake3` and `sodium` that has the algorithm whole, else the first + of them with a partial cell, else none (the call names its backend); + `bearssl`, `openssl`, `botan` and `webcrypto` are never a default. No + measurement decides it. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.4 (proposals). - **The C libraries of hash (`xkcp`, `blake3`, `sodium`) are built file by @@ -9149,10 +9155,11 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 5 (proposals). - **Seven increments, each usable alone.** The first, built, is Hash2 by alias, - `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the profile and the - measured table; the next ones widen the backends' surface (libsodium's, - XKCP's, OpenSSL's, BearSSL's, Botan's) and add the browser backend over - WebCrypto through a parallel asynchronous family. + `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the default backend + and the measured table; the third, built, is XKCP's whole surface through + the families; the others widen the other backends' surface (libsodium's, + OpenSSL's, BearSSL's, Botan's) and add the browser backend over WebCrypto + through a parallel asynchronous family. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.5 (proposals). From 1d31b3c848fea4a35debb52fc337c2bf661e4f81 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 20:35:44 -0300 Subject: [PATCH 29/53] tools: hash_doc_tables_test makes its case of a later default itself, BLAKE2b's sodium cell having landed --- tools/test/hash_doc_tables_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index f9803d1e..8cfb97c2 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -239,7 +239,13 @@ def test_a_family_default_is_of_the_order_or_none(scratch: Path) -> None: def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: + # The later default is made here, not read from the real table, whose cells land increment + # by increment: BLAKE2b's default sodium without its cell yet. The partial cells are hash2's. library = scratch_library(scratch) + path = library / 'doc/capabilities.json' + table = json.loads(path.read_text(encoding='utf-8')) + family_row(table, 'digests::blake2b')['backends'].pop('sodium', None) + path.write_text(json.dumps(table), encoding='utf-8') files = write_ok(library) blake2 = files['generated/backends-blake2.adoc'] expect('The default of `digests::blake2b` is `sodium`, whose cell comes with a later ' From 2b5f62053826b79588b441d546fa0bcdc21be063 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 20:35:48 -0300 Subject: [PATCH 30/53] libs/hash: increment 2 on the integration branch: BLAKE2b with its options, SipHash, blake2b_subkey, Argon2i, XOFs, SHA-2, SHA-3 and HMACs on libsodium --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 87a4662f..6fb96c58 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 87a4662f3ef2f2a9d1980ba4b4773b6d5b18c4e4 +Subproject commit 6fb96c58b533e95c1b1cb30da4f22972c15dcbb9 From 8b8e6d58ed4e9425d6fee6574ef2b9c23896355b Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 20:42:51 -0300 Subject: [PATCH 31/53] libs/hash: increment 3 on the integration branch: the Keccak family, SHA-3, SHAKE, SP 800-185, KMAC, KangarooTwelve and TurboSHAKE on XKCP --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 6fb96c58..52b40ed9 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 6fb96c58b533e95c1b1cb30da4f22972c15dcbb9 +Subproject commit 52b40ed9a217a06c57afd2a057c40e310db65a16 From 69ab6909cf49db08e19c57c0123fe037bf601d56 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 20:46:21 -0300 Subject: [PATCH 32/53] libs/hash: increment 5 on the integration branch: BearSSL's MD5, SHA-1, SHA-2, MD5-SHA1, SHAKE and HMAC as digests and MACs --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 52b40ed9..fcd6f0f6 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 52b40ed9a217a06c57afd2a057c40e310db65a16 +Subproject commit fcd6f0f653498402b215759771e7eb6a5767895b From f4a942469f4294edd37f89857e1248a455bb47d5 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 22:39:42 -0300 Subject: [PATCH 33/53] libs/hash: increments 2, 3 and 5 on the integration branch with a clean lint and reference, and review minors --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index fcd6f0f6..56683604 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit fcd6f0f653498402b215759771e7eb6a5767895b +Subproject commit 5668360488e4aa3b8d9aa4e7e9bf57343be0608b From c1aa0e60de15361072e0319af416b47d30f6b262 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 23:34:32 -0300 Subject: [PATCH 34/53] third_party: openssl_evp_data names evpkdf_kbkdf_counter.txt, evpkdf_ss.txt and evpkdf_x963.txt, which hash's tests read --- third_party/Jamfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index 7175b426..006edfa7 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -804,9 +804,10 @@ explicit blake3_vectors ; # OpenSSL's EVP test data (Apache-2.0), test/recipes/30-test_evp_data at the # pin, read at run time from the directory WEBCPP_TEST_OPENSSL_EVP_DATA gives, # on every target, as test data that nothing compiles: webcpp::hash reads the -# Argon2 cases of evpkdf_argon2.txt, the keyed BLAKE2 cases of evpmac_blake.txt, -# the KMAC cases of evpmac_common.txt and the SipHash cases of -# evpmac_siphash.txt. Quoted as wycheproof's define is. +# Argon2 cases of evpkdf_argon2.txt, the KBKDF, SSKDF and X9.63 KDF cases of +# evpkdf_kbkdf_counter.txt, evpkdf_ss.txt and evpkdf_x963.txt, the keyed BLAKE2 +# cases of evpmac_blake.txt, the KMAC cases of evpmac_common.txt and the SipHash +# cases of evpmac_siphash.txt. Quoted as wycheproof's define is. path-constant OPENSSL_EVP_DATA : libs/openssl/test/recipes/30-test_evp_data ; rule openssl-evp-data-checked-out ( properties * ) @@ -823,6 +824,9 @@ alias openssl_evp_data : : @openssl-evp-data-checked-out : : "\"WEBCPP_TEST_OPENSSL_EVP_DATA=\\\"$(.openssl-evp-data)\\\"\"" [ webcpp.data $(OPENSSL_EVP_DATA) ] libs/openssl/test/recipes/30-test_evp_data/evpkdf_argon2.txt + libs/openssl/test/recipes/30-test_evp_data/evpkdf_kbkdf_counter.txt + libs/openssl/test/recipes/30-test_evp_data/evpkdf_ss.txt + libs/openssl/test/recipes/30-test_evp_data/evpkdf_x963.txt libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt libs/openssl/test/recipes/30-test_evp_data/evpmac_common.txt libs/openssl/test/recipes/30-test_evp_data/evpmac_siphash.txt ; From e67ad76e5b4e9177c1bb0a877d293cf6c158c8dd Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 23:43:57 -0300 Subject: [PATCH 35/53] tools: doc_tables.py renders a function without a default backend, and hash's messages of kbkdf, sskdf and x963kdf have their Emscripten fixtures --- doc/releases/0.1.0.adoc | 2 + tools/hash/doc_tables.py | 37 +++++++++++++------ .../kdf_standards_digest/Jamfile | 9 +++++ .../kdf_standards_digest/app.cpp | 22 +++++++++++ .../kdf_standards_digest.outcome | 14 +++++++ .../kdf_standards_no_default/Jamfile | 9 +++++ .../kdf_standards_no_default/app.cpp | 23 ++++++++++++ .../kdf_standards_no_default.outcome | 15 ++++++++ .../kdf_standards_on_hash2/Jamfile | 9 +++++ .../kdf_standards_on_hash2/app.cpp | 23 ++++++++++++ .../kdf_standards_on_hash2.outcome | 15 ++++++++ tools/test/hash_doc_tables_test.py | 20 +++++++++- tools/test/hash_jamfiles_test.py | 2 + 13 files changed, 187 insertions(+), 13 deletions(-) create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_digest/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/kdf_standards_no_default.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/kdf_standards_on_hash2.outcome diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index f95e103f..b40a98b4 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -315,6 +315,8 @@ argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial share it, calling a tag without a default a type, and scattering constant-time statements. * Fixed tools/hash/doc_tables.py's llms.txt calling backends::sodium the only backend of argon2id and scrypt, which backends::openssl has too. +* Changed tools/hash/doc_tables.py to render a function without a default backend, as kbkdf, +sskdf and x963kdf on backends::openssl alone, and to refuse one a backend of the order has. * Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's tests read at run time on every target. * Added /third_party//blake2_vectors, BLAKE2's test vectors at ed1974e (a shallow submodule), and diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index 57c2e1da..761f0443 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -39,9 +39,11 @@ `python3 tools/hash/doc_tables.py --write`, when one differs from what is committed, is missing, or is left over; the doc build runs it (doc/Jamfile). It also fails when guide.json lacks a public name of the capability table, names one it does not have, or a use case names -an example that example/ does not hold; when a function of the capability table has no default -among its backends, a family's tag (kind digest, mac or kdf) a default outside the order hash2, -xkcp, blake3, sodium (design D34; null for a tag with none), or a type has one; and when +an example that example/ does not hold; when a function of the capability table names a default +that is not among its backends, or none (null) though a backend of the order hash2, xkcp, blake3, +sodium has it, a family's tag (kind digest, mac +or kdf) a default outside the order hash2, xkcp, blake3, sodium (design D34; null for a tag with +none), or a type has one; and when measurements.json's digest does not match its content (a hand edit of the reference). Nothing in the output depends on the time or the machine, so the files change only with their data. """ @@ -125,13 +127,19 @@ def __init__(self, library: Path) -> None: def check_defaults(self) -> None: """A function (a template with a Backend parameter) names its default, a backend that - has it; a family's tag names one of the order, or none (null), whose cell may come in a - later increment; a type has none.""" + has it, or none (null) exactly when no backend of the order hash2, xkcp, blake3, sodium + has it (design D34, as kbkdf); a family's tag names one of the order, or none (null), + whose cell may come in a later increment; a type has none.""" faults = [] for name, (_, function) in self.functions.items(): default = function.get('default') kind = function['kind'] - if kind == 'function' and default not in function['backends']: + ordered = [b for b in FAMILY_DEFAULTS if b in function['backends']] + if kind == 'function' and default is None and ordered: + faults.append(f'doc/capabilities.json: the function {name} has no default, ' + f'though {ordered[0]}, a backend of the order, has it') + elif kind == 'function' and default is not None and \ + default not in function['backends']: faults.append(f'doc/capabilities.json: the function {name} has no default ' f'among its backends ({default})') elif kind in FAMILY_KINDS and default is not None and default not in FAMILY_DEFAULTS: @@ -333,7 +341,10 @@ def backends_table(data: Data, algorithm: dict) -> str: out.extend(f'* `{backend}`: {cell(source)}' for backend, source in sources) out.append('') defaults = [(f['name'], f['default']) for f in algorithm['functions'] if f['default']] - families = [f for f in algorithm['functions'] if f['kind'] in FAMILY_KINDS] + # A family's tag, and a function without a default (design D34), each say how its default + # stands. + families = [f for f in algorithm['functions'] + if f['kind'] in FAMILY_KINDS or (f['kind'] == 'function' and f['default'] is None)] for function in families: if function['default'] is None: out.append(f'`{function["name"]}` has no default backend: the call names one of its ' @@ -427,11 +438,13 @@ def llms_txt(data: Data) -> str: lines = ['# 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. 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 unless ' + 'HKDF, PBKDF2, Argon2id, scrypt and the KDFs of NIST SP 800-108, SP 800-56C and ' + 'ANSI X9.63 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. HKDF and PBKDF2 ' + 'run on backends::hash2 unless the call names another backend as its second ' + 'template argument; argon2id and scrypt run on backends::sodium unless the call ' + 'names backends::openssl; kbkdf, sskdf and x963kdf have no default backend, and ' 'the call names backends::openssl. The families digest_of, hasher, mac and argon2 ' 'take a tag of digests, macs or kdfs and a backend, by default the first of ' 'backends::hash2, backends::xkcp, backends::blake3 and backends::sodium that has ' diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/Jamfile new file mode 100644 index 00000000..87783875 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/kdf_standards_digest of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp new file mode 100644 index 00000000..a4746f94 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp @@ -0,0 +1,22 @@ +// 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) + +// sskdf over a digest SP 800-56C does not approve (MD5) and x963kdf over one outside FIPS 180-4 +// (SHA3-256) stop, whatever the backend. + +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array const secret{1}; + auto const sskdf = hash::sskdf(output, secret); + auto const x963kdf = hash::x963kdf(output, secret); + return sskdf && x963kdf ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome new file mode 100644 index 00000000..e93810b3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome @@ -0,0 +1,14 @@ +# 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 compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/kdf_standards_digest, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: sskdf takes a digest of SP 800-56C: digests::sha1, digests::sha2_224, sha2_256, sha2_384, sha2_512, sha2_512_224, sha2_512_256, sha3_224, sha3_256, sha3_384 or sha3_512. +contains: webcpp::hash: x963kdf takes a digest of FIPS 180-4: digests::sha1, digests::sha2_224, sha2_256, sha2_384, sha2_512, sha2_512_224 or sha2_512_256. diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/Jamfile new file mode 100644 index 00000000..3f50e0b8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/kdf_standards_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/app.cpp new file mode 100644 index 00000000..510906cb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/app.cpp @@ -0,0 +1,23 @@ +// 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) + +// kbkdf, sskdf and x963kdf on their default, which none of them has, stop (design D34). + +#include +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array const key{1}; + auto const kbkdf = hash::kbkdf(output, key); + auto const sskdf = hash::sskdf(output, key); + auto const x963kdf = hash::x963kdf(output, key); + return kbkdf && sskdf && x963kdf ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/kdf_standards_no_default.outcome b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/kdf_standards_no_default.outcome new file mode 100644 index 00000000..543fff08 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/kdf_standards_no_default.outcome @@ -0,0 +1,15 @@ +# 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 compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/kdf_standards_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::kbkdf_hmac has no default backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::sskdf has no default backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::x963kdf has no default backend. Name one of: backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/Jamfile new file mode 100644 index 00000000..ee070835 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/kdf_standards_on_hash2 of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/app.cpp new file mode 100644 index 00000000..5b174cb2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/app.cpp @@ -0,0 +1,23 @@ +// 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) + +// kbkdf, sskdf and x963kdf named on backends::hash2, which has none of them, stop (spec 3.3). + +#include +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array const key{1}; + auto const kbkdf = hash::kbkdf(output, key); + auto const sskdf = hash::sskdf(output, key); + auto const x963kdf = hash::x963kdf(output, key); + return kbkdf && sskdf && x963kdf ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/kdf_standards_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/kdf_standards_on_hash2.outcome new file mode 100644 index 00000000..4628d6df --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/kdf_standards_on_hash2.outcome @@ -0,0 +1,15 @@ +# 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 compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/kdf_standards_on_hash2, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::kbkdf_hmac is not in this backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::sskdf is not in this backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::x963kdf is not in this backend. Name one of: backends::openssl. diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index e84429c9..c3e0294c 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -12,7 +12,8 @@ passes on what it wrote, and fails naming `python3 tools/hash/doc_tables.py --write` when a generated file was edited by hand, is missing or is left over. A guide that lacks a function of the capability table, or describes one it does not have, fails, and so does a use case whose -example is not there, and so does a function of the capability table without a default. Every +example is not there, and so does a function of the capability table without a default that a +backend of the order hash2, xkcp, blake3, sodium has (one that none has, as kbkdf, has none). Every function's default is the capability table's, `hash2` for HKDF whatever the measurements say. A family's tag (spec 2.15) names a default of the order hash2, xkcp, blake3, sodium, or none, and one whose cell comes in a later increment is said so; a partial cell says what it refuses. @@ -208,6 +209,22 @@ def test_every_function_names_its_default(scratch: Path) -> None: expect('the type sha2_256 has a default' in done.stderr, done.stderr) +def test_a_function_without_a_backend_of_the_order_has_no_default(scratch: Path) -> None: + """A function that no backend of the order hash2, xkcp, blake3, sodium has (kbkdf, on + backends::openssl alone) has no default (design D34), and its backends say that the call + names one; given a backend of the order, it must name its default.""" + library = scratch_library(scratch) + kbkdf = write_ok(library)['generated/backends-kbkdf.adoc'] + expect('`kbkdf` has no default backend: the call names one of its backends' in kbkdf, kbkdf) + + def hash2_cell(table: dict) -> None: + family_row(table, 'kbkdf')['backends']['hash2'] = a_cell(4) + edit_capabilities(library, hash2_cell) + done = run(library, '--write') + expect(done.returncode == 1, 'a function of hash2 without a default was rendered') + expect('the function kbkdf has no default, though hash2' in done.stderr, done.stderr) + + def family_row(table: dict, name: str) -> dict: for algorithm in table['algorithms']: for function in algorithm['functions']: @@ -444,6 +461,7 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_a_later_default_and_a_partial_cell_are_said, test_a_default_names_only_its_functions_backends, test_a_tag_without_a_default_is_not_said_a_type, + test_a_function_without_a_backend_of_the_order_has_no_default, test_each_backend_s_constant_time_sources_are_together, test_without_measurements_the_tables_say_so, test_with_measurements_the_tables_carry_them, diff --git a/tools/test/hash_jamfiles_test.py b/tools/test/hash_jamfiles_test.py index 50b868f5..d4f08c57 100644 --- a/tools/test/hash_jamfiles_test.py +++ b/tools/test/hash_jamfiles_test.py @@ -40,6 +40,8 @@ NO_FIXTURE = { 'ripemd128_on_openssl': 'it names /webcpp/hash//openssl, which Emscripten refuses before ' 'the message (the fixture openssl_on_emscripten)', + 'kbkdf_hmac_on_openssl': 'it names /webcpp/hash//openssl, which Emscripten refuses before ' + 'the message (the fixture openssl_on_emscripten)', } DIRECTIVE = re.compile(r'^// expected-error@\S+ \{\{(.*)\}\}$', re.MULTILINE) From 973c0aca334e021bd7704d02ccb08b7cf6a27cd9 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 23:56:16 -0300 Subject: [PATCH 36/53] libs/hash: increment 7 on the integration branch: the asynchronous family over webcpp::asio and backends::webcrypto, async_argon2 on libsodium tested --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 56683604..047ee237 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 5668360488e4aa3b8d9aa4e7e9bf57343be0608b +Subproject commit 047ee237fec05698c3d20d4823e1ff7cce8480a0 From 904ee7836b3affe92263b63052010ef179ce2b98 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 23:58:31 -0300 Subject: [PATCH 37/53] tools: the Emscripten fixtures of hash's x963kdf digest refusal and of argon2id and scrypt on backends::openssl unlinked --- .../kdf_standards_digest/app.cpp | 6 ++--- .../kdf_standards_digest.outcome | 2 +- .../openssl_kdf_not_linked/Jamfile | 9 +++++++ .../openssl_kdf_not_linked/app.cpp | 26 +++++++++++++++++++ .../openssl_kdf_not_linked.outcome | 14 ++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/openssl_kdf_not_linked.outcome diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp index a4746f94..b6fcd28d 100644 --- a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp @@ -4,8 +4,8 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// sskdf over a digest SP 800-56C does not approve (MD5) and x963kdf over one outside FIPS 180-4 -// (SHA3-256) stop, whatever the backend. +// sskdf over a digest SP 800-56C does not approve (MD5) and x963kdf over one SEC 1 v2 does not +// list (SHA-512/256) stop, whatever the backend. #include @@ -17,6 +17,6 @@ int main() { std::array output{}; std::array const secret{1}; auto const sskdf = hash::sskdf(output, secret); - auto const x963kdf = hash::x963kdf(output, secret); + auto const x963kdf = hash::x963kdf(output, secret); return sskdf && x963kdf ? 0 : 1; } diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome index e93810b3..f7fb3b03 100644 --- a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome @@ -11,4 +11,4 @@ targets: emscripten build: fails contains: webcpp::hash: sskdf takes a digest of SP 800-56C: digests::sha1, digests::sha2_224, sha2_256, sha2_384, sha2_512, sha2_512_224, sha2_512_256, sha3_224, sha3_256, sha3_384 or sha3_512. -contains: webcpp::hash: x963kdf takes a digest of FIPS 180-4: digests::sha1, digests::sha2_224, sha2_256, sha2_384, sha2_512, sha2_512_224 or sha2_512_256. +contains: webcpp::hash: x963kdf takes a hash function of SEC 1 v2, section 3.5: digests::sha1, digests::sha2_224, sha2_256, sha2_384 or sha2_512. diff --git a/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/Jamfile new file mode 100644 index 00000000..f3d1f9fb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/Jamfile @@ -0,0 +1,9 @@ +# 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) + +# test/messages/openssl_kdf_not_linked of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/app.cpp new file mode 100644 index 00000000..2441146d --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/app.cpp @@ -0,0 +1,26 @@ +// 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) + +// argon2id and scrypt on backends::openssl, named without openssl.hpp in a program that does not +// link /webcpp/hash//openssl, stop at their engines with the instruction to add it, as every +// function on backends::openssl does (spec 5.7, the fifth row). + +#include +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array salt{}; + auto const argon2id = hash::argon2id( + output, {}, salt, hash::argon2id_parameters{.passes = 2, .memory = 19456 * 1024}); + auto const scrypt = hash::scrypt(output, {}, salt, + hash::scrypt_parameters{1024, 8, 1}); + return argon2id && scrypt ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/openssl_kdf_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/openssl_kdf_not_linked.outcome new file mode 100644 index 00000000..d368879b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/openssl_kdf_not_linked.outcome @@ -0,0 +1,14 @@ +# 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 compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/openssl_kdf_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::openssl needs OpenSSL. Add /webcpp/hash//openssl to the program's Jamfile (native, wasip2 and wasip3): exe app : app.cpp /webcpp/hash//hash /webcpp/hash//openssl ; +contains: webcpp::hash: backends::openssl needs OpenSSL. Add /webcpp/hash//openssl to the program's Jamfile (native, wasip2 and wasip3): exe app : app.cpp /webcpp/hash//hash /webcpp/hash//openssl ; From a39051e7a584688f9a638326f843610dad9a267c Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 00:08:30 -0300 Subject: [PATCH 38/53] tools: hash_doc_tables_test reads llms.txt's sentence on the default backend as doc_tables.py now writes it --- tools/test/hash_doc_tables_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index c3e0294c..2a41c6ec 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -361,8 +361,8 @@ def test_without_measurements_the_tables_say_so(scratch: Path) -> None: expect('| pbkdf2\n| hash2' in backends and '| scrypt\n| sodium' in backends, 'backends.adoc does not list the defaults') expect('Backends: hash2 (/webcpp/hash//hash' in files['llms.txt'], 'llms.txt has no backends') - expect('Every key derivation runs on backends::hash2' in files['llms.txt'], - 'llms.txt does not say the default') + expect('HKDF and PBKDF2 run on backends::hash2 unless the call names another backend' + in files['llms.txt'], 'llms.txt does not say the default') def test_with_measurements_the_tables_carry_them(scratch: Path) -> None: From 6baaf7b612366b707c54ae50d809c16cd113125a Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 00:47:18 -0300 Subject: [PATCH 39/53] guidelines: hash's entry describes increments 1 and 4 as built, with the default rule of designs D33 and D34 --- CODING-GUIDELINES.md | 52 ++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index b52aea23..74c03db4 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -9099,7 +9099,7 @@ summary. `organization/openspec/changes/site-increments-4-5/specs/site/spec.md` (proposals). -### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increment 1 built, not merged) +### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increments 1 and 4 built, not merged) webcpp::hash is one entry point for hashing and key derivation in a C++20 program on every target webcpp has, a wrapper (`"port-of": null`). Increment 1 @@ -9107,13 +9107,21 @@ is built on the library's branch (`libs/hash`, to become `webcpporg/hash`): Boost.Hash2's algorithms and `hmac` re-exported by alias (`algorithms.hpp`, `hmac.hpp`); Keccak-256 with the original padding over XKCP's permutation (`keccak.hpp`) and BLAKE3 over its official C implementation (`blake3.hpp`), -both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 -(RFC 8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and -`openssl` (`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and -scrypt (RFC 7914, `scrypt.hpp`) from libsodium; the profile and the default -backend (`config.hpp`), the capability table (`doc/capabilities.json`), and -the measured table (`doc/measurements*.json`, regenerated by the `measure` -lane). The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, +both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 (RFC +8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and `openssl` +(`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and scrypt (RFC +7914, `scrypt.hpp`) from libsodium; the default backend (`config.hpp`), the +capability table (`doc/capabilities.json`), and the measured table +(`doc/measurements*.json`), a dated reference of 2026-11-16 that decides +nothing. The families `digest_of`, `hasher`, `mac` and `argon2` take the tags of +`digests`, `macs` and `kdfs`; increment 4 gives them OpenSSL's surface, each +reached only by naming `backends::openssl` (native, wasip2 and wasip3): MD5, +SHA-1, SHA-2, SHA-3, SHAKE, Keccak-224 to Keccak-512, BLAKE2, RIPEMD-160, TLS +1.0's MD5-SHA1 and SM3; HMAC, KMAC, keyed BLAKE2 and SipHash; scrypt, and +Argon2d, Argon2i and Argon2id with every parameter of RFC 9106; and the key +derivations of standards (`kdf_standards.hpp`), SP 800-108's KBKDF, SP +800-56C's one-step KDF and ANSI X9.63's KDF, which have no default backend. +The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, `sodium`, `bearssl`, each with a canary), their own suites by the `c-suites` lane (`test/c_suites`), the examples are in `example/` and the documentation in `doc/`. Every function is synchronous, reports failure as a @@ -9133,13 +9141,15 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` writes no cryptography of its own, as the owner recorded on 2026-11-14. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.3 (proposals). -- **The key derivation functions have backends, as webcpp::crypto's - algorithms do, and a backend that lacks a function refuses at compile - time.** `backends::hash2`, `sodium`, `bearssl` and `openssl` (native, - wasip2 and wasip3); natively the fastest linked backend is the default, on - WebAssembly the one that gives the smallest binary, decided by a measured - table that every pin move regenerates; one setting in `config.hpp` (a - profile) changes every default at once. +- **The key derivation functions and the families have backends, as + webcpp::crypto's algorithms do, and a backend that lacks a function or a + tag refuses at compile time.** `backends::hash2`, `xkcp`, `blake3`, + `sodium`, `bearssl` and `openssl`; the default is one stated rule, the same + on every target and fixed (designs D33 and D34): the first of `hash2`, + `xkcp`, `blake3` and `sodium` that has the algorithm whole, else the first + of them with a partial cell, else none (the call names its backend); + `bearssl`, `openssl`, `botan` and `webcrypto` are never a default. No + measurement decides it. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.4 (proposals). - **The C libraries of hash (`xkcp`, `blake3`, `sodium`) are built file by @@ -9151,10 +9161,14 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 5 (proposals). - **Seven increments, each usable alone.** The first, built, is Hash2 by alias, - `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the profile and the - measured table; the next ones widen the backends' surface (libsodium's, - XKCP's, OpenSSL's, BearSSL's, Botan's) and add the browser backend over - WebCrypto through a parallel asynchronous family. + `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the default backend + and the measured table; the fourth, built, is OpenSSL's whole surface + through the families and the key derivations of standards, each reached + only by naming `backends::openssl`, and every pair of an OpenSSL cell with + another backend's cell of the same tag checked to agree; the others widen + the other backends' surface (libsodium's, XKCP's, BearSSL's, Botan's) and + add the browser backend over WebCrypto through a parallel asynchronous + family. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.5 (proposals). From 88520d801b80a4e156fd382984a133bbacc197be Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 01:47:12 -0300 Subject: [PATCH 40/53] libs/hash: increment 7 on the integration branch with the review minors, a clean lint and reference --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 047ee237..db66e9f9 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 047ee237fec05698c3d20d4823e1ff7cce8480a0 +Subproject commit db66e9f9e88cf6ec396a1f9bdcdf1018960e6ca9 From 830d3f33752c5620d26ac8426cefe407c0db9783 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 02:04:58 -0300 Subject: [PATCH 41/53] libs/hash: increment 4 on the integration branch: OpenSSL's digests, MACs, scrypt, Argon2 and the key derivations of standards --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index db66e9f9..0ce53259 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit db66e9f9e88cf6ec396a1f9bdcdf1018960e6ca9 +Subproject commit 0ce53259cece5daaddb3c1102bf4a4c1167aa1e6 From c24fc928463bdb48396d7e1b020b539aaa6b333b Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 02:11:21 -0300 Subject: [PATCH 42/53] guidelines: hash's entry says every pair of backends of a tag is checked to agree across the built increments --- CODING-GUIDELINES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 5d72c70a..cbddae44 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -9182,7 +9182,8 @@ and G4); the proposal, with the specification, the design and the plan, is in only by naming `backends::bearssl`; the seventh, built, adds the browser backend over WebCrypto through a parallel asynchronous family, whose cells `doc/capabilities.json` marks asynchronous only; the sixth widens Botan's - surface. + surface. Across the built increments every tag that two backends or more + have is checked to give the same bytes on each pair of them, on random cases. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.5 (proposals). From dee3e2da02601a889390e35b8b1aa126346870a2 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 04:11:05 -0300 Subject: [PATCH 43/53] libs/hash: increment 4 on the integration branch with the agreement across increments, the review minors, a clean lint and reference --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 0ce53259..74bd130f 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 0ce53259cece5daaddb3c1102bf4a4c1167aa1e6 +Subproject commit 74bd130f72352a36ee8bc13cb395fbc4212fb826 From a094151a3f0fc13a7dd88520ba65d599218e1525 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 05:03:31 -0300 Subject: [PATCH 44/53] libs/hash: keyed BLAKE2b as macs::blake2b_mac on libsodium, its default (ruling R95) --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 74bd130f..fff7417e 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 74bd130f72352a36ee8bc13cb395fbc4212fb826 +Subproject commit fff7417e45396f18882fac196811948ab7ea762b From 0dc130c3c665b000b3a089804d0c0be1b2b6e085 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 06:18:58 -0300 Subject: [PATCH 45/53] libs/hash: the final review's fixes: the error reference, the overview, keyed BLAKE2 as MACs, XKCP's storage in one header, libsodium's and HMAC's refusal texts, WebCrypto's partial cells; doc_tables.py derives llms.txt's defaults and checks defaults and chapters --- doc/releases/0.1.0.adoc | 3 + libs/hash | 2 +- tools/hash/doc_tables.py | 171 +++++++++++++----- .../argon2id_default_not_linked.outcome | 2 +- .../blake2b_subkey_default_not_linked.outcome | 2 +- .../mac_no_default/mac_no_default.outcome | 2 +- .../scrypt_default_not_linked.outcome | 2 +- .../sodium_default_not_linked.outcome | 2 +- .../sodium_not_linked.outcome | 2 +- tools/test/hash_doc_tables_test.py | 130 +++++++++++-- 10 files changed, 248 insertions(+), 70 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 75001730..64fcb8d4 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -326,6 +326,9 @@ tests read at run time on every target. the messages of webcpp::hash's asynchronous family are built on Emscripten too. * Changed tools/hash/doc_tables.py to render a backend of webcpp::hash's asynchronous family alone, backends::webcrypto, with the note "asynchronous family only" in every table. +* Changed tools/hash/doc_tables.py to derive llms.txt's default backends from the capability +table, to give each backend's constant-time sources one bullet, and to refuse a default without +its cell or only the asynchronous family takes, and a tag outside its namespace's chapter. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/libs/hash b/libs/hash index fff7417e..fb562339 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit fff7417e45396f18882fac196811948ab7ea762b +Subproject commit fb5623395de28e39ef588e6a07e1eae752a030fe diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index aa4b43b2..7fa9dc52 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -39,13 +39,15 @@ `python3 tools/hash/doc_tables.py --write`, when one differs from what is committed, is missing, or is left over; the doc build runs it (doc/Jamfile). It also fails when guide.json lacks a public name of the capability table, names one it does not have, or a use case names -an example that example/ does not hold; when a function of the capability table names a default -that is not among its backends, or none (null) though a backend of the order hash2, xkcp, blake3, -sodium has it, a family's tag (kind digest, mac -or kdf) a default outside the order hash2, xkcp, blake3, sodium (design D34; null for a tag with -none), or a type has one; and when -measurements.json's digest does not match its content (a hand edit of the reference). Nothing in -the output depends on the time or the machine, so the files change only with their data. +an example that example/ does not hold; when a function of the capability table names a +default that is not among its backends, or none (null) though a backend of the order hash2, +xkcp, blake3, sodium has it; when a family's tag (kind digest, mac or kdf) names a default +outside that order (design D34; null for a tag with none) or one without its cell; when any +default is a backend that only the asynchronous family takes, a type has a default, or a row +has an unknown kind; when a tag of digests or macs sits outside its namespace's chapter; and +when measurements.json's digest does not match its content (a hand edit of the reference). +Nothing in the output depends on the time or the machine, so the files change only with their +data. """ from __future__ import annotations @@ -80,6 +82,11 @@ # (design D34): the first that has the tag; never bearssl, openssl, botan or webcrypto. FAMILY_KINDS = ('digest', 'mac', 'kdf') FAMILY_DEFAULTS = ('hash2', 'xkcp', 'blake3', 'sodium') +# The chapter each namespace's tags belong in: a tag of macs is listed with the MACs. +NAMESPACE_CHAPTERS = {'digests::': 'digests', 'macs::': 'macs'} +# How the guide spells each target in prose. +TARGET_NAMES = {'native': 'native', 'wasip2': 'wasip2', 'wasip3': 'wasip3', + 'emscripten': 'Emscripten'} class Failure(Exception): @@ -123,19 +130,29 @@ def __init__(self, library: Path) -> None: self.functions[function['name']] = (algorithm, function) self.check_guide() self.check_defaults() + self.check_chapters() self.check_digest() def check_defaults(self) -> None: """A function (a template with a Backend parameter) names its default, a backend that has it, or none (null) exactly when no backend of the order hash2, xkcp, blake3, sodium - has it (design D34, as kbkdf); a family's tag names one of the order, or none (null), - whose cell may come in a later increment; a type has none.""" + has it (design D34, as kbkdf); a family's tag names one of the order that has its cell, + or none (null): every default has its engine (ruling R84); no default is a backend only + the asynchronous family takes (design D35); a type has none.""" faults = [] for name, (_, function) in self.functions.items(): default = function.get('default') kind = function['kind'] ordered = [b for b in FAMILY_DEFAULTS if b in function['backends']] - if kind == 'function' and default is None and ordered: + if kind not in FAMILY_KINDS + ('function', 'type'): + faults.append(f'doc/capabilities.json: {name} has the unknown kind {kind}') + elif kind == 'type' and default is not None: + faults.append(f'doc/capabilities.json: the type {name} has a default, {default}') + elif default is not None and default in self.backends and \ + self.backends[default].get('asynchronous_only'): + faults.append(f'doc/capabilities.json: the {kind} {name} has the default ' + f'{default}, which only the asynchronous family takes') + elif kind == 'function' and default is None and ordered: faults.append(f'doc/capabilities.json: the function {name} has no default, ' f'though {ordered[0]}, a backend of the order, has it') elif kind == 'function' and default is not None and \ @@ -145,10 +162,22 @@ def check_defaults(self) -> None: elif kind in FAMILY_KINDS and default is not None and default not in FAMILY_DEFAULTS: faults.append(f'doc/capabilities.json: the tag {name} has the default {default}, ' f'which is not one of {", ".join(FAMILY_DEFAULTS)}') - elif kind == 'type' and default is not None: - faults.append(f'doc/capabilities.json: the type {name} has a default, {default}') - elif kind not in FAMILY_KINDS + ('function', 'type'): - faults.append(f'doc/capabilities.json: {name} has the unknown kind {kind}') + elif kind in FAMILY_KINDS and default is not None and \ + default not in function['backends']: + faults.append(f'doc/capabilities.json: the tag {name} has the default {default}, ' + 'which has no cell of it') + if faults: + raise Failure('\n'.join(faults)) + + def check_chapters(self) -> None: + """A tag of digests sits in the digests chapter, a tag of macs in the macs chapter, so + that each chapter's table and llms.txt's section list every tag of its namespace.""" + faults = [] + for name, (algorithm, _) in self.functions.items(): + for prefix, chapter in NAMESPACE_CHAPTERS.items(): + if name.startswith(prefix) and algorithm['chapter'] != chapter: + faults.append(f'doc/capabilities.json: the tag {name} is in the chapter ' + f'{algorithm["chapter"]}, not {chapter}') if faults: raise Failure('\n'.join(faults)) @@ -173,9 +202,9 @@ def check_guide(self) -> None: faults += [f'doc/guide.json describes {name}, which doc/capabilities.json does not ' f'have' for name in extra] chapters = {a['chapter'] for a in self.capabilities['algorithms']} - listed = [c['chapter'] for c in self.guide['chapters']] + chapter_names = [c['chapter'] for c in self.guide['chapters']] faults += [f'doc/guide.json has no chapter {c} of doc/capabilities.json' - for c in sorted(chapters - set(listed))] + for c in sorted(chapters - set(chapter_names))] for case in self.guide['use_cases']: if case['function'] not in self.functions: faults.append(f'doc/guide.json: the use case "{case["need"]}" names ' @@ -293,6 +322,23 @@ def backend_targets(data: Data, backend: str) -> str: return ', '.join(data.backends[backend]['targets']) +def listed(names: list[str]) -> str: + """Names as prose lists them: a, b and c.""" + return names[0] if len(names) == 1 else ', '.join(names[:-1]) + f' and {names[-1]}' + + +def spelled_targets(data: Data, backend: str) -> str: + """A backend's targets as the guide's prose spells them, as "native and Emscripten".""" + return listed([TARGET_NAMES.get(t, t) for t in data.backends[backend]['targets']]) + + +def source_bullets(lead: str, sources: list[str]) -> list[str]: + """One bullet led by `lead`: its one source after it, or its sources under it.""" + if len(sources) == 1: + return [f'* {lead} {sources[0]}'] + return [f'* {lead}'] + [f'** {source}' for source in sources] + + ASYNCHRONOUS_ONLY = 'asynchronous family only' @@ -352,12 +398,16 @@ def backends_table(data: Data, algorithm: dict) -> str: out.append(f'| {held["constant_time"]["value"]}') out.append('|===') out.append('') - sources = sorted({(backend, held['constant_time']['source']) - for function in algorithm['functions'] - for backend, held in function['backends'].items()}) + sources: dict[str, list[str]] = {} + for function in algorithm['functions']: + for backend, held in function['backends'].items(): + known = sources.setdefault(backend, []) + if held['constant_time']['source'] not in known: + known.append(held['constant_time']['source']) out.append('What each backend states on constant time, as the capability table read it:') out.append('') - out.extend(f'* `{backend}`: {cell(source)}' for backend, source in sources) + for backend in sorted(sources): + out.extend(source_bullets(f'`{backend}`:', [cell(s) for s in sorted(sources[backend])])) out.append('') defaults = [(f['name'], f['default']) for f in algorithm['functions'] if f['default']] # A family's tag, and a function without a default (design D34), each say how its default @@ -369,14 +419,6 @@ def backends_table(data: Data, algorithm: dict) -> str: out.append(f'`{function["name"]}` has no default backend: the call names one of its ' 'backends (<>).') out.append('') - elif function['default'] not in function['backends']: - out.append(f'The default of `{function["name"]}` is `{function["default"]}`, whose ' - 'cell comes with a later increment: until then a call on the default ' - 'stops at compile time, and a call names a backend of the table ' - '(<>).') - out.append('') - defaults = [(name, default) for name, default in defaults - if default in data.functions[name][1]['backends']] if not defaults: # Types alone take no backend; a family's tag without a default has said so above. if not families: @@ -406,8 +448,8 @@ def backends_table(data: Data, algorithm: dict) -> str: out.append('') for backend in sorted(b for b in used if asynchronous_only(data, b)): out.append(f'`{backend}` serves the asynchronous family alone, on ' - f'{backend_targets(data, backend).replace(", ", " and ").capitalize()}, where ' - 'the type of its asynchronous call names it (<>).') + f'{spelled_targets(data, backend)}, where the type of its asynchronous call ' + 'names it (<>).') out.append('') return '\n'.join(out) @@ -461,23 +503,59 @@ def measured_includes(data: Data) -> str: return '\n'.join(out) +def function_defaults(data: Data) -> str: + """The defaults of the functions with a Backend parameter, as the capability table names + them: one clause per default and per backend a call may name instead (none, one, or several, + never one only the asynchronous family takes), and one for the functions without a + default.""" + clauses: dict[tuple[str | None, str], list[str]] = {} + for name, (_, function) in data.functions.items(): + if function['kind'] != 'function': + continue + default = function['default'] + others = sorted(b for b in function['backends'] + if b != default and not asynchronous_only(data, b)) + if default is None: + instead = (f'backends::{others[0]}' if len(others) == 1 + else 'one of its backends') + elif not others: + instead = '' + elif len(others) == 1: + instead = f'backends::{others[0]}' + else: + instead = 'another of its backends' + clauses.setdefault((default, instead), []).append(name) + sentences = [] + for (default, instead), names in clauses.items(): + many = len(names) > 1 + if default is None: + sentences.append(f'{listed(names)} {"have" if many else "has"} no default backend, ' + f'and the call names {instead}') + elif not instead: + sentences.append(f'{listed(names)} {"run" if many else "runs"} on ' + f'backends::{default} alone') + else: + sentences.append(f'{listed(names)} {"run" if many else "runs"} on ' + f'backends::{default} unless the call names {instead} as its ' + 'second template argument') + return f'By default, {"; ".join(sentences)}.' if sentences else '' + + def llms_txt(data: Data) -> str: page = data.guide['page'] lines = ['# 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, scrypt and the KDFs of NIST SP 800-108, SP 800-56C and ' - 'ANSI X9.63 over C backends. Every function is synchronous, returns ' + 'ANSI X9.63 over C backends. Every synchronous function returns ' 'boost::system::result and allocates nothing in webcpp\'s own code; async.hpp gives ' - 'them an asynchronous form over webcpp::asio, and backends::webcrypto, the ' + 'the slow ones and the ones WebCrypto has an asynchronous form over webcpp::asio, ' + 'and backends::webcrypto, the ' 'browser\'s WebCrypto, serves that form alone. A program links /webcpp/hash//hash ' - 'and the library of each backend it uses. HKDF and PBKDF2 run on backends::hash2 ' - 'unless the call names another backend as its second template argument; argon2id ' - 'and scrypt run on backends::sodium unless the call names backends::openssl; ' - 'kbkdf, sskdf and x963kdf have no default backend, and the call names ' - 'backends::openssl. The families digest_of, hasher, mac and argon2 take a tag of ' - 'digests, macs or kdfs and a backend, by default the first of backends::hash2, ' - 'backends::xkcp, backends::blake3 and backends::sodium that has the tag.', '', + 'and the library of each backend it uses. ' + function_defaults(data) + + ' The families digest_of, hasher, mac and argon2 take a tag of digests, macs or ' + 'kdfs and a backend, by default the first of ' + + listed([f'backends::{b}' for b in FAMILY_DEFAULTS]) + ' that has the tag.', '', '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.', '', @@ -574,16 +652,17 @@ def backends_chapter(data: Data) -> str: lines += ['', f'| {function["name"]}', '| none: the call names its backend'] lines += ['|===', '', '=== Constant time', '', 'What each backend\'s upstream states, and where:', ''] - # Each backend's statements together, in the capability table's order of backends. - seen: list[tuple[str, str, str]] = [] + # One bullet per backend and value, in the capability table's order of backends, with each + # distinct source of it once. + seen: dict[tuple[str, str], list[str]] = {} for _, function in data.functions.values(): for name, c in function['backends'].items(): - key = (name, c['constant_time']['value'], c['constant_time']['source']) - if key not in seen: - seen.append(key) + known = seen.setdefault((name, c['constant_time']['value']), []) + if c['constant_time']['source'] not in known: + known.append(c['constant_time']['source']) order = list(data.backends) - for name, value, source in sorted(seen, key=lambda key: order.index(key[0])): - lines.append(f'* {name}: {value}. {source}') + for (name, value), sources in sorted(seen.items(), key=lambda item: order.index(item[0][0])): + lines.extend(source_bullets(f'{name}: {value}.', sources)) return '\n'.join(lines) + '\n' diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome index 61ccaa72..f5961f22 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome index 53d4b8df..1086f08f 100644 --- a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome b/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome index 49def264..da653481 100644 --- a/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: macs::hmac over this digest has no default backend, and no backend has it yet. +contains: webcpp::hash: macs::hmac over this digest has no default backend: no backend has it. diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome index ccdcd981..6b65faa0 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome index 8eaa7ecf..1a6e0434 100644 --- a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome index 134b8e46..ee3d2c6a 100644 --- a/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id, scrypt and blake2b_subkey need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index 64a86b8f..ce15647c 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -16,8 +16,11 @@ backend of the order hash2, xkcp, blake3, sodium has (one that none has, as kbkdf, has none). Every function's default is the capability table's, `hash2` for HKDF whatever the measurements say. A family's tag (spec 2.15) names a default of the order hash2, xkcp, blake3, sodium, or none, and -one whose cell comes in a later increment is said so; a partial cell says what it refuses. A -backend of the asynchronous family alone (backends::webcrypto) is named so in every table. +one without its cell fails; a partial cell says what it refuses. A tag of `digests` or `macs` +sits in its namespace's chapter. A backend of the asynchronous family alone (backends::webcrypto) +is named so in every table, with its targets as the guide spells them, and is never a default; a +row of an unknown kind fails. Each backend's constant-time statements are one bullet. llms.txt's +defaults are the capability table's, not a text written once. Without doc/measurements.json the tables say so, carry no measured column and render no measurements.adoc; with it (a fixture in its shape) they carry the throughput and the size, and measurements.adoc renders it as the dated reference that decides nothing; a hand edit of the @@ -256,21 +259,96 @@ def test_a_family_default_is_of_the_order_or_none(scratch: Path) -> None: in files['backends.adoc'], 'the default backends do not say none') -def test_a_later_default_and_a_partial_cell_are_said(scratch: Path) -> None: - # The later default is made here, not read from the real table, whose cells land increment - # by increment: BLAKE2b's default sodium without its cell yet. The partial cells are hash2's. +def test_a_default_without_its_cell_fails_and_a_partial_cell_is_said(scratch: Path) -> None: + # Every default has its engine once increments 2 to 7 have landed (ruling R84): a family's + # default without its cell is a fault of the data, not a cell to come. The partial cells are + # hash2's and backends::webcrypto's. library = scratch_library(scratch) - path = library / 'doc/capabilities.json' - table = json.loads(path.read_text(encoding='utf-8')) - family_row(table, 'digests::blake2b')['backends'].pop('sodium', None) - path.write_text(json.dumps(table), encoding='utf-8') files = write_ok(library) blake2 = files['generated/backends-blake2.adoc'] - expect('The default of `digests::blake2b` is `sodium`, whose cell comes with a later ' - 'increment' in blake2, blake2) expect('`hash2` (partial: an output under 64 bytes' in blake2, blake2) expect('| hash2 (partial: a tag under 32 bytes' in files['backends.adoc'], 'the backends chapter does not say what the partial cell refuses') + expect('`webcrypto` (asynchronous family only) (partial: an info longer than 1,024 bytes' + in files['generated/backends-hkdf.adoc'], files['generated/backends-hkdf.adoc']) + expect('| webcrypto (asynchronous family only) (partial: an iteration count above 2^32 - 1' + in files['backends.adoc'], 'webcrypto\'s PBKDF2 limits are not said') + + def drop_cell(table: dict) -> None: + family_row(table, 'digests::blake2b')['backends'].pop('sodium', None) + edit_capabilities(library, drop_cell) + done = run(library, '--write') + expect(done.returncode == 1, 'a default without its cell was rendered') + expect('the tag digests::blake2b has the default sodium, which has no cell of it' + in done.stderr, done.stderr) + + +def test_a_tag_sits_in_its_namespace_s_chapter(scratch: Path) -> None: + # A tag of macs is a MAC, listed with the MACs and under llms.txt's MAC section; a tag of + # digests with the digests. + library = scratch_library(scratch) + files = write_ok(library) + expect('macs::blake2b_mac' in files['generated/compare-macs.adoc'], 'keyed BLAKE2b') + expect('macs::blake2b_mac' not in files['generated/compare-digests.adoc'], + 'keyed BLAKE2b among the digests') + macs = files['llms.txt'].split('## Message authentication')[1].split('\n## ')[0] + expect('webcpp::hash::macs::blake2s_mac' in macs, macs) + + def misplace(table: dict) -> None: + kmac = next(a for a in table['algorithms'] if a['name'] == 'kmac') + sha2 = next(a for a in table['algorithms'] if a['name'] == 'md5_sha1_sha2') + row = next(f for f in kmac['functions'] if f['name'] == 'macs::kmac_128') + kmac['functions'].remove(row) + sha2['functions'].append(row) + edit_capabilities(library, misplace) + done = run(library, '--write') + expect(done.returncode == 1, 'a tag of macs among the digests was rendered') + expect('the tag macs::kmac_128 is in the chapter digests, not macs' in done.stderr, + done.stderr) + + +def test_an_asynchronous_backend_is_never_a_default(scratch: Path) -> None: + library = scratch_library(scratch) + + def webcrypto_default(table: dict) -> None: + family_row(table, 'hkdf')['default'] = 'webcrypto' + family_row(table, 'pbkdf2')['kind'] = 'fixture' + edit_capabilities(library, webcrypto_default) + done = run(library, '--write') + expect(done.returncode == 1, 'an asynchronous-only default was rendered') + expect('the function hkdf has the default webcrypto, which only the asynchronous family ' + 'takes' in done.stderr, done.stderr) + expect('pbkdf2 has the unknown kind fixture' in done.stderr, done.stderr) + + +def test_an_asynchronous_backend_s_targets_are_spelled(scratch: Path) -> None: + library = scratch_library(scratch) + + def two_targets(table: dict) -> None: + webcrypto = next(b for b in table['backends'] if b['name'] == 'webcrypto') + webcrypto['targets'] = ['native', 'wasip2', 'emscripten'] + edit_capabilities(library, two_targets) + hkdf = write_ok(library)['generated/backends-hkdf.adoc'] + expect('serves the asynchronous family alone, on native, wasip2 and Emscripten, where' in hkdf, + hkdf) + + +def test_llms_txt_s_defaults_are_the_table_s(scratch: Path) -> None: + library = scratch_library(scratch) + llms = write_ok(library)['llms.txt'] + expect('argon2id and scrypt run on backends::sodium unless the call names ' + 'backends::openssl' in llms, llms.split('\n\n')[1]) + expect('kbkdf, sskdf and x963kdf have no default backend, and the call names ' + 'backends::openssl' in llms, llms.split('\n\n')[1]) + + def scrypt_alone(table: dict) -> None: + family_row(table, 'scrypt')['backends'].pop('openssl') + edit_capabilities(library, scrypt_alone) + llms = write_ok(library)['llms.txt'] + expect('argon2id runs on backends::sodium unless the call names backends::openssl' in llms, + llms.split('\n\n')[1]) + expect('blake2b_subkey and scrypt run on backends::sodium alone' in llms, + llms.split('\n\n')[1]) def edit_capabilities(library: Path, edit: Callable[[dict], None]) -> None: @@ -301,9 +379,10 @@ def blake2(table: dict) -> None: rows['blake2s_256']['backends'] = {'hash2': a_cell(1)} edit_capabilities(library, blake2) files = write_ok(library) - blake2_file = files['generated/backends-blake2.adoc'] + blake2_mac = files['generated/backends-blake2-mac.adoc'] expect('The default of `macs::blake2s_mac`: `hash2` on every target, whatever the program ' - 'links (<>).' in blake2_file, blake2_file) + 'links (<>).' in blake2_mac, blake2_mac) + blake2_file = files['generated/backends-blake2.adoc'] expect('The default of `digests::blake2s_256`: `hash2` on every target, whatever the ' 'program links; `openssl` only where the call names it' in blake2_file, blake2_file) expect('The default of `digests::blake2b`: `sodium` on every target, whatever the program ' @@ -337,14 +416,26 @@ def lone_tag(table: dict) -> None: def test_each_backend_s_constant_time_sources_are_together(scratch: Path) -> None: + # One bullet per backend and value, in the table's order of backends, its sources under it + # when it has several; and one bullet per backend in an algorithm's table. library = scratch_library(scratch) - chapter = write_ok(library)['backends.adoc'] + files = write_ok(library) + chapter = files['backends.adoc'] listed = [line.split(':')[0] for line in chapter.split("What each backend's upstream states, and where:")[1].splitlines() if line.startswith('* ')] order = [b['name'] for b in json.loads( (library / 'doc/capabilities.json').read_text(encoding='utf-8'))['backends']] expect(listed == sorted(listed, key=lambda b: order.index(b[2:])), '\n'.join(listed)) + expect(len(listed) == len(set(listed)), '\n'.join(listed)) + expect('* openssl: not stated.\n** ' in chapter, 'openssl\'s sources are not under it') + for name, text in files.items(): + if not name.startswith('generated/backends-'): + continue + bullets = [line.split(':')[0] for line in + text.split('What each backend states on constant time')[1].splitlines() + if line.startswith('* ')] + expect(len(bullets) == len(set(bullets)), f'{name}: {bullets}') def test_an_asynchronous_backend_is_said(scratch: Path) -> None: @@ -397,8 +488,9 @@ def test_without_measurements_the_tables_say_so(scratch: Path) -> None: expect('| pbkdf2\n| hash2' in backends and '| scrypt\n| sodium' in backends, 'backends.adoc does not list the defaults') expect('Backends: hash2 (/webcpp/hash//hash' in files['llms.txt'], 'llms.txt has no backends') - expect('HKDF and PBKDF2 run on backends::hash2 unless the call names another backend' - in files['llms.txt'], 'llms.txt does not say the default') + expect('hkdf_extract, hkdf_expand and hkdf run on backends::hash2 unless the call names ' + 'another of its backends as its second template argument' in files['llms.txt'], + 'llms.txt does not say the default') def test_with_measurements_the_tables_carry_them(scratch: Path) -> None: @@ -494,7 +586,11 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_a_use_case_names_an_example_that_is_there, test_every_function_names_its_default, test_a_family_default_is_of_the_order_or_none, - test_a_later_default_and_a_partial_cell_are_said, + test_a_default_without_its_cell_fails_and_a_partial_cell_is_said, + test_a_tag_sits_in_its_namespace_s_chapter, + test_an_asynchronous_backend_is_never_a_default, + test_an_asynchronous_backend_s_targets_are_spelled, + test_llms_txt_s_defaults_are_the_table_s, test_a_default_names_only_its_functions_backends, test_a_tag_without_a_default_is_not_said_a_type, test_a_function_without_a_backend_of_the_order_has_no_default, From db976325bcb4097ad851f0da3681f62e83f4fa22 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 07:36:26 -0300 Subject: [PATCH 46/53] libs/hash: the final review's fixes: XKCP's storage sizes as one lower-case enumeration, as clang-tidy asks; doc_tables.py's target names typed for Pyright, its release notes within 30 words a line --- doc/releases/0.1.0.adoc | 5 +++-- libs/hash | 2 +- tools/hash/doc_tables.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 64fcb8d4..ca7b5c4f 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -327,8 +327,9 @@ the messages of webcpp::hash's asynchronous family are built on Emscripten too. * Changed tools/hash/doc_tables.py to render a backend of webcpp::hash's asynchronous family alone, backends::webcrypto, with the note "asynchronous family only" in every table. * Changed tools/hash/doc_tables.py to derive llms.txt's default backends from the capability -table, to give each backend's constant-time sources one bullet, and to refuse a default without -its cell or only the asynchronous family takes, and a tag outside its namespace's chapter. +table and to give each backend's constant-time sources one bullet. +* Changed tools/hash/doc_tables.py to refuse a default without its cell or of the asynchronous +family alone, and a tag outside its namespace's chapter. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/libs/hash b/libs/hash index fb562339..62cc2fc5 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit fb5623395de28e39ef588e6a07e1eae752a030fe +Subproject commit 62cc2fc5482bfd2707fe6c56a8f2d277d9c462cb diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index 7fa9dc52..a493a6aa 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -329,7 +329,8 @@ def listed(names: list[str]) -> str: def spelled_targets(data: Data, backend: str) -> str: """A backend's targets as the guide's prose spells them, as "native and Emscripten".""" - return listed([TARGET_NAMES.get(t, t) for t in data.backends[backend]['targets']]) + return listed([TARGET_NAMES[t] if t in TARGET_NAMES else t + for t in data.backends[backend]['targets']]) def source_bullets(lead: str, sources: list[str]) -> list[str]: From a4235128a5ecee931335af38f45521f9b2af43d8 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 08:33:51 -0300 Subject: [PATCH 47/53] tools: doc_tables.py reads the template argument a call names its backend as from the header declaring the template, so argon2id's and scrypt's backend is their only one, not the second (final review N1) --- doc/releases/0.1.0.adoc | 2 + tools/hash/doc_tables.py | 102 ++++++++++++++++++++++++----- tools/test/hash_doc_tables_test.py | 69 ++++++++++++++++--- 3 files changed, 147 insertions(+), 26 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index ca7b5c4f..2e723c5c 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -330,6 +330,8 @@ alone, backends::webcrypto, with the note "asynchronous family only" in every ta table and to give each backend's constant-time sources one bullet. * Changed tools/hash/doc_tables.py to refuse a default without its cell or of the asynchronous family alone, and a tag outside its namespace's chapter. +* Fixed tools/hash/doc_tables.py calling backends::openssl argon2id's and scrypt's second +template argument: each sentence reads the Backend's position from the header declaring the template. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index a493a6aa..81bc3247 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -25,7 +25,9 @@ smallest program on Emscripten, then where it is used, each with its source, and when to choose it); - generated/backends-.adoc: the backends of each algorithm, from the capability - table (backend, the Jamfile line, targets, hmacs, constant time), and each function's default; + table (backend, the Jamfile line, targets, hmacs, constant time), and each function's default, + with the template argument a call names another backend as, read from the header that declares + the template (the library's include/); - generated/choose.adoc: the decision table "Choose by use case", whose backend column is the capability table's; - generated/measured.adoc: the includes of the data chapters, backends.adoc and @@ -44,7 +46,9 @@ xkcp, blake3, sodium has it; when a family's tag (kind digest, mac or kdf) names a default outside that order (design D34; null for a tag with none) or one without its cell; when any default is a backend that only the asynchronous family takes, a type has a default, or a row -has an unknown kind; when a tag of digests or macs sits outside its namespace's chapter; and +has an unknown kind; when a tag of digests or macs sits outside its namespace's chapter; when +the header a row names declares no template of it (or of its family) with a Backend parameter; +and when measurements.json's digest does not match its content (a hand edit of the reference). Nothing in the output depends on the time or the machine, so the files change only with their data. @@ -55,6 +59,7 @@ import argparse import hashlib import json +import re import sys from pathlib import Path from typing import Any @@ -84,6 +89,10 @@ FAMILY_DEFAULTS = ('hash2', 'xkcp', 'blake3', 'sodium') # The chapter each namespace's tags belong in: a tag of macs is listed with the MACs. NAMESPACE_CHAPTERS = {'digests::': 'digests', 'macs::': 'macs'} +# The templates a family's tag is the first template argument of, by its kind, each declared in +# the tag's header: the position of their Backend is read there. +FAMILY_TEMPLATES = {'digest': ('digest_of', 'hasher'), 'mac': ('mac',), 'kdf': ('argon2',)} +ORDINALS = ('first', 'second', 'third', 'fourth') # How the guide spells each target in prose. TARGET_NAMES = {'native': 'native', 'wasip2': 'wasip2', 'wasip3': 'wasip3', 'emscripten': 'Emscripten'} @@ -132,6 +141,39 @@ def __init__(self, library: Path) -> None: self.check_defaults() self.check_chapters() self.check_digest() + # The template argument each function's and each tag's call names its backend as. + self.arguments = {name: self.backend_argument(function) + for name, (_, function) in self.functions.items() + if function['kind'] == 'function' or function['kind'] in FAMILY_KINDS} + + def backend_argument(self, function: dict) -> str: + """The words "as its template argument", where a call names the backend, + read from the header that declares the template (the function's own, or its family's + templates), so that no sentence states a position the signature does not have.""" + names = FAMILY_TEMPLATES.get(function['kind'], (function['name'],)) + header = function['header'] + path = self.library / 'include' / header + try: + text = path.read_text(encoding='utf-8') + except OSError as error: + raise Failure(f'{path}: {error}') from error + # (position, number of parameters) of the Backend in each declaration of each template. + found = set() + for name in names: + places = {(i, len(parameters)) for parameters in template_parameters(text, name) + for i, parameter in enumerate(parameters) + if re.match(r'(?:class|typename)\s+Backend\b', parameter)} + if not places: + raise Failure(f'{header} declares no template {name} with a Backend parameter ' + f'(doc/capabilities.json, {function["name"]})') + found |= places + indices = {i for i, _ in found} + if len(indices) != 1: + raise Failure(f'{header}: {listed(list(names))} take the Backend at different ' + f'positions (doc/capabilities.json, {function["name"]})') + (index,) = indices + position = 'only' if all(count == 1 for _, count in found) else ORDINALS[index] + return f'as its {position} template argument' def check_defaults(self) -> None: """A function (a template with a Backend parameter) names its default, a backend that @@ -322,6 +364,30 @@ def backend_targets(data: Data, backend: str) -> str: return ', '.join(data.backends[backend]['targets']) +def template_parameters(text: str, name: str) -> list[list[str]]: + """The template parameter lists of each declaration of the template `name` (a function or a + class) in a header's text, its comments removed: each list split at its top-level commas.""" + code = re.sub(r'//[^\n]*|/\*.*?\*/', ' ', text, flags=re.DOTALL) + found = [] + for match in re.finditer(r'\btemplate\s*<', code): + depth, end = 1, match.end() + while depth and end < len(code): + depth += {'<': 1, '>': -1}.get(code[end], 0) + end += 1 + head = re.match(r'[^;{(]*', code[end:]) + if head is None or not re.search(rf'(?': -1, ')': -1}.get(code[i], 0) + if code[i] == ',' and depth == 0: + parameters.append(code[start:i].strip()) + start = i + 1 + parameters.append(code[start:end - 1].strip()) + found.append(parameters) + return found + + def listed(names: list[str]) -> str: """Names as prose lists them: a, b and c.""" return names[0] if len(names) == 1 else ', '.join(names[:-1]) + f' and {names[-1]}' @@ -418,7 +484,8 @@ def backends_table(data: Data, algorithm: dict) -> str: for function in families: if function['default'] is None: out.append(f'`{function["name"]}` has no default backend: the call names one of its ' - 'backends (<>).') + f'backends, {data.arguments[function["name"]]} ' + '(<>).') out.append('') if not defaults: # Types alone take no backend; a family's tag without a default has said so above. @@ -430,20 +497,20 @@ def backends_table(data: Data, algorithm: dict) -> str: return '\n'.join(out) # One sentence per default and set of other backends, so that each names, as the backends a # call may name instead, those of its own functions alone. - by_backend: dict[tuple[str, tuple[str, ...]], list[str]] = {} + by_backend: dict[tuple[str, tuple[str, ...], str], list[str]] = {} for name, default in defaults: # The backends a call may name instead: those of this function, not of the algorithm's # others, and never one only the asynchronous family takes. others = tuple(sorted(b for b in set(data.functions[name][1]['backends']) - {default} if not asynchronous_only(data, b))) - by_backend.setdefault((default, others), []).append(name) + by_backend.setdefault((default, others, data.arguments[name]), []).append(name) used = {b for f in algorithm['functions'] for b in f['backends']} - for (default, others), functions in by_backend.items(): + for (default, others, argument), functions in by_backend.items(): names = [f'`{name}`' for name in functions] named = names[0] if len(names) == 1 else \ ', '.join(names[:-1]) + f' and {names[-1]}' - tail = (f'; {", ".join(f"`{b}`" for b in others)} only where the call names it, as its ' - 'second template argument') if others else '' + tail = (f'; {", ".join(f"`{b}`" for b in others)} only where the call names it, ' + f'{argument}') if others else '' out.append(f'The default of {named}: `{default}` on every target, whatever the program ' f'links{tail} (<>).') out.append('') @@ -506,10 +573,10 @@ def measured_includes(data: Data) -> str: def function_defaults(data: Data) -> str: """The defaults of the functions with a Backend parameter, as the capability table names - them: one clause per default and per backend a call may name instead (none, one, or several, - never one only the asynchronous family takes), and one for the functions without a - default.""" - clauses: dict[tuple[str | None, str], list[str]] = {} + them: one clause per default, per backend a call may name instead (none, one, or several, + never one only the asynchronous family takes) and per template argument the call names it as + (the header's), and one for the functions without a default.""" + clauses: dict[tuple[str | None, str, str], list[str]] = {} for name, (_, function) in data.functions.items(): if function['kind'] != 'function': continue @@ -525,20 +592,21 @@ def function_defaults(data: Data) -> str: instead = f'backends::{others[0]}' else: instead = 'another of its backends' - clauses.setdefault((default, instead), []).append(name) + clauses.setdefault((default, instead, data.arguments[name] if instead else ''), + []).append(name) sentences = [] - for (default, instead), names in clauses.items(): + for (default, instead, argument), names in clauses.items(): many = len(names) > 1 if default is None: sentences.append(f'{listed(names)} {"have" if many else "has"} no default backend, ' - f'and the call names {instead}') + f'and the call names {instead} {argument}') elif not instead: sentences.append(f'{listed(names)} {"run" if many else "runs"} on ' f'backends::{default} alone') else: sentences.append(f'{listed(names)} {"run" if many else "runs"} on ' - f'backends::{default} unless the call names {instead} as its ' - 'second template argument') + f'backends::{default} unless the call names {instead} ' + f'{argument}') return f'By default, {"; ".join(sentences)}.' if sentences else '' diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index ce15647c..ae39c7a2 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -56,11 +56,12 @@ def expect(condition: bool, message: str) -> None: def scratch_library(scratch: Path) -> Path: - """A library with the real capability table and guide, and an example file for each use - case.""" + """A library with the real capability table, guide and public headers, and an example file + for each use case.""" library = scratch / 'hash' (library / 'doc').mkdir(parents=True) (library / 'example').mkdir() + shutil.copytree(LIBRARY / 'include', library / 'include') for name in ('capabilities.json', 'guide.json'): shutil.copy(LIBRARY / 'doc' / name, library / 'doc' / name) guide = json.loads((library / 'doc/guide.json').read_text(encoding='utf-8')) @@ -334,21 +335,70 @@ def two_targets(table: dict) -> None: def test_llms_txt_s_defaults_are_the_table_s(scratch: Path) -> None: + """Each clause whole, its template position the header's: argon2id's and scrypt's backend is + their only template argument, hkdf's and pbkdf2's the second, after the hmac.""" library = scratch_library(scratch) llms = write_ok(library)['llms.txt'] - expect('argon2id and scrypt run on backends::sodium unless the call names ' - 'backends::openssl' in llms, llms.split('\n\n')[1]) - expect('kbkdf, sskdf and x963kdf have no default backend, and the call names ' - 'backends::openssl' in llms, llms.split('\n\n')[1]) + expect('By default, hkdf_extract, hkdf_expand and hkdf run on backends::hash2 unless the ' + 'call names another of its backends as its second template argument; pbkdf2 runs on ' + 'backends::hash2 unless the call names backends::openssl as its second template ' + 'argument; blake2b_subkey runs on backends::sodium alone; kbkdf, sskdf and x963kdf ' + 'have no default backend, and the call names backends::openssl as its second template ' + 'argument; argon2id and scrypt run on backends::sodium unless the call names ' + 'backends::openssl as its only template argument. The families' in llms, + llms.split('\n\n')[1]) def scrypt_alone(table: dict) -> None: family_row(table, 'scrypt')['backends'].pop('openssl') edit_capabilities(library, scrypt_alone) llms = write_ok(library)['llms.txt'] - expect('argon2id runs on backends::sodium unless the call names backends::openssl' in llms, - llms.split('\n\n')[1]) - expect('blake2b_subkey and scrypt run on backends::sodium alone' in llms, + expect('; blake2b_subkey and scrypt run on backends::sodium alone; ' in llms, llms.split('\n\n')[1]) + expect('; argon2id runs on backends::sodium unless the call names backends::openssl as its ' + 'only template argument. ' in llms, llms.split('\n\n')[1]) + + +def test_a_backend_s_position_is_its_header_s(scratch: Path) -> None: + """The template argument a call names its backend as is read from the header that declares + the template: every generated sentence follows a moved parameter, and a header that does not + declare it fails.""" + library = scratch_library(scratch) + files = write_ok(library) + expect('The default of `argon2id`: `sodium` on every target, whatever the program links; ' + '`openssl` only where the call names it, as its only template argument ' + '(<>).' in files['generated/backends-argon2id.adoc'], + files['generated/backends-argon2id.adoc']) + expect('The default of `scrypt`: `sodium` on every target, whatever the program links; ' + '`openssl` only where the call names it, as its only template argument ' + '(<>).' in files['generated/backends-scrypt.adoc'], + files['generated/backends-scrypt.adoc']) + expect('The default of `kdfs::argon2i` and `kdfs::argon2id`: `sodium` on every target, ' + 'whatever the program links; `openssl` only where the call names it, as its second ' + 'template argument (<>).' + in files['generated/backends-argon2.adoc'], files['generated/backends-argon2.adoc']) + expect('The default of `pbkdf2`: `hash2` on every target, whatever the program links; ' + '`openssl` only where the call names it, as its second template argument ' + '(<>).' in files['generated/backends-pbkdf2.adoc'], + files['generated/backends-pbkdf2.adoc']) + header = library / 'include/webcpp/hash/scrypt.hpp' + text = header.read_text(encoding='utf-8') + moved = 'template >' + expect('template >' in text, text) + header.write_text(text.replace('template >', + moved, 1), encoding='utf-8') + files = write_ok(library) + expect('`openssl` only where the call names it, as its second template argument' + in files['generated/backends-scrypt.adoc'], files['generated/backends-scrypt.adoc']) + expect('argon2id runs on backends::sodium unless the call names backends::openssl as its ' + 'only template argument; scrypt runs on backends::sodium unless the call names ' + 'backends::openssl as its second template argument.' in files['llms.txt'], + files['llms.txt'].split('\n\n')[1]) + header.write_text(text.replace('scrypt(', 'scrypt_gone(').replace('scrypt (', 'gone ('), + encoding='utf-8') + done = run(library, '--write') + expect(done.returncode == 1, 'a header without the template was rendered') + expect('webcpp/hash/scrypt.hpp declares no template scrypt with a Backend parameter' + in done.stderr, done.stderr) def edit_capabilities(library: Path, edit: Callable[[dict], None]) -> None: @@ -591,6 +641,7 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_an_asynchronous_backend_is_never_a_default, test_an_asynchronous_backend_s_targets_are_spelled, test_llms_txt_s_defaults_are_the_table_s, + test_a_backend_s_position_is_its_header_s, test_a_default_names_only_its_functions_backends, test_a_tag_without_a_default_is_not_said_a_type, test_a_function_without_a_backend_of_the_order_has_no_default, From f9e78414afa0f7c67e8ca585dce88e22d374c84d Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 08:39:38 -0300 Subject: [PATCH 48/53] libs/hash: the final review's residuals: the backend's template argument in the generated tables and llms.txt, every default with its cell, XKCP's storage header out of C++'s global namespace, the allocation and overview texts (ruling R97) --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index 62cc2fc5..d2b77732 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 62cc2fc5482bfd2707fe6c56a8f2d277d9c462cb +Subproject commit d2b7773279ef139cb30dcd5b3775a6fc15aca089 From 57b0bf26c2bb4e8b9dbb436106aefe6df6ffd333 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 09:22:44 -0300 Subject: [PATCH 49/53] doc: the release notes write libc++ as inline code, since a literal ++ in prose is an Asciidoctor passthrough that doc-check refuses --- doc/releases/0.1.0.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 2e723c5c..67e288ec 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -67,7 +67,7 @@ None. == Tools and build * Fixed emscripten release programs linking unoptimized; they now link at `-O3`. -* Fixed WASI release programs carrying wasi-sdk's libc++ debug information, most of their size; they now link with `--strip-debug`. +* Fixed WASI release programs carrying wasi-sdk's `libc++` debug information, most of their size; they now link with `--strip-debug`. * Fixed clean CMake consumer audits rejecting system libraries and phony dependency rules. * Changed CI to consume verified prepared environments without rebuilding images in PR jobs. * Added verified archive caches and isolated container availability from unrelated CI lanes. From d09145f21fa6c9351060f7d00230a414d2f985a5 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 12:33:06 -0300 Subject: [PATCH 50/53] libs/hash: XKCP's storage enumeration with Doc Comments and its C89 last enumerator told to clang-tidy --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index d2b77732..b545ea13 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit d2b7773279ef139cb30dcd5b3775a6fc15aca089 +Subproject commit b545ea13391f2c03cce06a789abeae5bddeb0091 From af1bc712dc830750f86e48ebd7a400ae14ff20d4 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 14:32:42 -0300 Subject: [PATCH 51/53] libs/hash: MSVC's warnings in four tests and an example, and a test the Wine lane's compiler stopped on --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index b545ea13..f516d512 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit b545ea13391f2c03cce06a789abeae5bddeb0091 +Subproject commit f516d5121264e3cc6bdc893d75ff4876520862df From a6719c2eac8e038efd1a19648253c7ee8eb9573f Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 15:12:30 -0300 Subject: [PATCH 52/53] libs/hash: xkcp_sp800_185_test within clang-tidy's cognitive complexity --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index f516d512..e55ada42 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit f516d5121264e3cc6bdc893d75ff4876520862df +Subproject commit e55ada427299da16a56524321e8199a123fb4ed2 From 39d6f7d8b3bcf282400acf086a53d950cd4aaa40 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 18:28:15 -0300 Subject: [PATCH 53/53] libs/hash: increments 2 to 7 with crypto/hash-forward-declarations, whose shared backend tags stay exempt from bugprone-forward-declaration-namespace --- libs/hash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/hash b/libs/hash index e55ada42..1b947c64 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit e55ada427299da16a56524321e8199a123fb4ed2 +Subproject commit 1b947c64f52c42f259293109fd1c24f9270bddcb