diff --git a/.gitmodules b/.gitmodules index 0f4ca6fb..7a031b31 100644 --- a/.gitmodules +++ b/.gitmodules @@ -93,3 +93,6 @@ path = third_party/libs/ed25519-speccheck url = https://github.com/novifinancial/ed25519-speccheck.git shallow = true +[submodule "third_party/libs/botan"] + path = third_party/libs/botan + url = https://github.com/randombit/botan.git diff --git a/AGENTS.md b/AGENTS.md index d2c58bd9..9745386a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -271,6 +271,11 @@ Jamroot is its build configuration, and `libs/` is its repository. third_party/libs/bips third_party/libs/ed25519-speccheck`, and `third_party/libs/openssl` for its OpenSSL backend (below); b2 builds every backend from its sources; +- for Botan (`/third_party//botan`, webcpp::hash's `backends::botan` and + later webcpp::crypto's): nothing installed, with the pinned submodule + initialised (`git submodule update --init third_party/libs/botan`); b2 runs + Botan's own `configure.py` with Python 3 once per target and compiles its + sources; native and Emscripten, with exceptions; - for native Trystero: CMake and Make (nmake on Windows), and the pinned `third_party/libs/libdatachannel` checkout with its required nested sources. Initialize it, and the libsecp256k1 every room links, with `git submodule diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 4496305d..690a6155 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -349,7 +349,9 @@ exactly its authors' and the program carries only what it calls. their instruction sets alone, each flagged for its own set; XKCP is built 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. + libsodium is built without its `.S` files. Two libraries are not built + file by file from webcpp's list at all: OpenSSL (rule 7) and Botan (rule + 13), whose sources upstream selects. 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 @@ -391,6 +393,7 @@ exactly its authors' and the program carries only what it calls. WASIp3 single and cooperative profiles must agree with the consumer's threading choice. Keep explicit host entropy seeding and fail-closed tests. Other libraries with external dependencies still use `webcpp.external`. + Botan's configuration is upstream's too, its compilation b2's (rule 13). 8. The webcpp library's `config.hpp` chooses the default backend from the target and the `HAS` defines, and refuses impossible combinations with `#error`. The backend is named after the C library (`backends::bearssl`), @@ -407,6 +410,18 @@ exactly its authors' and the program carries only what it calls. the submodule's. 12. Moving a pin is a change of its own: the submodule, the canary's commit, the tests on every target and the size table. +13. Botan is configured by upstream and compiled by b2, as + `tools/webcpp-botan.jam` does: Botan's own `configure.py` chooses the + modules (`tools/botan/modules.txt`, one list for every webcpp library, each + module with who needs it) and writes `build.h` and the list of sources for + each target into the build directory, `bin/third_party/botan/config-`, + never into the checkout; b2 compiles each listed source as an object of its + own with the program's properties. This is rule 2's kind of exception, as + OpenSSL's rule 7 is: the selection is upstream's, the compilation b2's. + Never the amalgamation, never a patch, never a module that seeds a + generator from the system (`system_rng`, `auto_rng`), which the helper + refuses. A library adds its own canary and define to the target; the + provisioning carries none. ## 6. Exceptions and RTTI @@ -961,6 +976,8 @@ update --init third_party/libs/`; a build that needs none never looks. | `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 | +| `botan` | Botan 3.14.1 at `01af88c`, the submodule `third_party/libs/botan`; configured by upstream's `configure.py` per target (`--minimized-build`, the modules of `tools/botan/modules.txt`) into `bin/third_party/botan/config-`, the library sources its `configure.py` lists compiled by b2 one object each (chapter 5, rule 13), natively and on Emscripten, with exceptions; `botan_test`, Botan's own test program; webcpp::hash's canary (`src/canary_botan.cpp`, compiled with Botan's own properties and build.h, and `WEBCPP_HASH_HAS_BOTAN` in the usage requirements, when `libs/hash` is checked out); no canary of the provisioning's own | BSD-2-Clause | +| `botan_vectors` | Botan's own test data, `src/tests/data` of the submodule `third_party/libs/botan` at `01af88c`, test data: hash's tests read `hash/whirlpool.vec`, `hash/skein.vec`, `passhash/bcrypt.vec`, `bcrypt_pbkdf.vec` and `kdf/sp800_108_ctr.vec` at run time under the directory its define `WEBCPP_TEST_BOTAN_VECTORS` gives, natively and on Emscripten (`webcpp.data`), and run again when they change | BSD-2-Clause | | `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 | | `ctaes` | `src/crypto/ctaes` of `bitcoin/bitcoin` v31.1 at `9be056a` (commit `9be056a8a72b624dae9623b2f7bded92c2a21c91`), the submodule `third_party/libs/bitcoin`, shallow; `third_party/Jamfile` compiles its `ctaes.c` alone, with webcpp::crypto's canary, on every target (`WEBCPP_CRYPTO_HAS_CTAES=1`); the tree's `src/secp256k1/` subtree is never on an include path and no glob over `third_party/libs` reaches it | MIT | | `ed25519-speccheck` | `novifinancial/ed25519-speccheck` at `65519336` (2021-02-26), shallow, test data: crypto's tests read the twelve Ed25519 edge cases of "Taming the many EdDSAs", its `cases.json`, at run time under the directory its define `WEBCPP_TEST_ED25519_SPECCHECK` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | Apache-2.0 | @@ -9309,7 +9326,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, increments 1, 2, 3, 4, 5 and 7 built, not merged) +### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increments 1 to 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 @@ -9338,10 +9355,18 @@ 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; increment 5 gives them BearSSL's MD5, SHA-1, SHA-2, TLS 1.0's MD5-SHA1, SHAKE and HMAC, each reached -only by naming `backends::bearssl`. The C libraries are built by +only by naming `backends::bearssl`; increment 6 gives them Botan 3.14.1's +surface, each reached only by naming `backends::botan` (natively and on +Emscripten, in a program built with exceptions): its digests, Streebog, +Whirlpool and Skein-512 among them, its MACs, HKDF, PBKDF2, Argon2, scrypt and +the key derivations of standards, and bcrypt and bcrypt_pbkdf +(`bcrypt.hpp`), with their heavy forms `async_bcrypt`, `async_bcrypt_pbkdf` +and `async_bcrypt_verify`. 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 +canary), Botan by `tools/webcpp-botan.jam` as `/third_party//botan` (hash's +canary in `src/canary_botan.cpp`; designs D43 to D45), their own suites, and +Botan's, by the `c-suites` lane (`test/c_suites`), the examples are in +`example/` and the documentation in `doc/`. Every function reports failure as a `boost::system::result`, takes its data as `std::span` and allocates nothing in webcpp's own code; increment 7 adds an asynchronous family in `async.hpp` over webcpp::asio (any completion token, Cobalt's `use_op` @@ -9389,10 +9414,14 @@ and G4); the proposal, with the specification, the design and the plan, is in derivations of standards, each reached only by naming `backends::openssl`; the fifth, built, is 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`; 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. Across the built increments every tag that two backends or more + only by naming `backends::bearssl`; the sixth, built, is Botan's surface + through the families, the key derivations and bcrypt, each reached only by + naming `backends::botan`, which the stream provisions itself (design D43), + whose column is read at 3.14.1 (design D44) and which needs exceptions, + natively and on Emscripten, its lanes MSVC's included (design D45); the + seventh, built, adds the browser backend over WebCrypto through a parallel + asynchronous family, whose cells `doc/capabilities.json` marks asynchronous + only. 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). diff --git a/Jamroot b/Jamroot index 8421c5c6..d41cf210 100644 --- a/Jamroot +++ b/Jamroot @@ -31,6 +31,7 @@ import tools/webcpp-lint-headers ; import tools/webcpp-openssl ; import tools/webcpp-libdatachannel ; import tools/webcpp-ca-certificates ; +import tools/webcpp-botan ; # A shell with CPATH (Homebrew sets it) puts its headers before the # configured Boost, and the compiler would use them without a word. diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index f1a1335f..fd4ada5a 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -337,6 +337,12 @@ family alone, and a tag outside its namespace's chapter. template argument: each sentence reads the Backend's position from the header declaring the template. * Fixed an interrupted OpenSSL or libdatachannel build leaving a configuration later builds took as complete: its build record is published last, and one without it is built again. +* Added /third_party//botan, Botan 3.14.1 configured by upstream and compiled by b2, natively and on +Emscripten. +* Added /third_party//botan_vectors, Botan's own test data at its pin, which webcpp::hash's tests read +at run time. +* Changed tools/hash/doc_tables.py to mark backends::botan "with exceptions only" in every table, and +to refuse a function's default outside hash2, xkcp, blake3 and sodium. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/libs/hash b/libs/hash index 302c8334..03aec9da 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 302c833480897476128d635fb39385f5919521d8 +Subproject commit 03aec9da0c3061df157148b5cb418d858055d703 diff --git a/third_party/Jamfile b/third_party/Jamfile index 6152f7ec..e4e90316 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -196,6 +196,25 @@ webcpp-openssl.declare $(WEBCPP_ROOT) tools/openssl/msvc.conf tools/openssl/pin.json ; explicit openssl ; +# Botan 3.14.1 (BSD-2-Clause), randombit/botan at 01af88c: upstream's +# configure.py chooses the modules (tools/botan/modules.txt, webcpp::hash's and +# webcpp::crypto's) and writes build.h and the list of sources for each target +# into bin/third_party/botan/config-; b2 compiles each listed source as +# an object of its own, with the consumer's properties, never the amalgamation +# and never a patch (CODING-GUIDELINES.md chapter 5, rule 13). Natively and on +# Emscripten, with exceptions. A library adds its own canary and define +# through webcpp-botan.declare's requirements and usage requirements here, +# as webcpp::hash's do (botan-hash-canary and botan-hash-usage, after the C +# libraries of webcpp::hash below; webcpp::crypto's join at its increment 7); +# the provisioning carries none. +import webcpp-botan ; +webcpp-botan.declare $(WEBCPP_ROOT) + : tools/botan/configure.py tools/botan/source.py tools/botan/pin.json + tools/botan/modules.txt tools/webcpp-botan.jam + : @botan-hash-canary + : @botan-hash-usage ; +explicit botan botan_test ; + # libdatachannel and its pinned nested dependencies use upstream CMake, with # the exact OpenSSL archives above. Each archive reaches the program once. Its # configurations are named as OpenSSL's are, by the bytes of the inputs below, @@ -437,6 +456,27 @@ rule bearssl-hash-usage ( properties * ) } } +# Botan, /third_party//botan above, carries webcpp::hash's canary as BearSSL +# does: src/canary_botan.cpp, a source of the library, compiled with Botan's +# own properties and its configured build.h, which the library gains only when +# libs/hash holds it, so that a checkout without libs/hash builds Botan as +# before; WEBCPP_HASH_HAS_BOTAN then joins the usage requirements. +rule botan-hash-canary ( properties * ) +{ + if [ path.exists [ path.native $(HASH)/src/canary_botan.cpp ] ] + { + return $(HASH)/src/canary_botan.cpp $(HASH)/include ; + } +} + +rule botan-hash-usage ( properties * ) +{ + if [ path.exists [ path.native $(HASH)/src/canary_botan.cpp ] ] + { + return WEBCPP_HASH_HAS_BOTAN=1 ; + } +} + # 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] # in the plain-64bits implementation with all rounds unrolled ("generic64"), @@ -936,6 +976,35 @@ alias openssl_evp_data : : @openssl-evp-data-checked-out : : libs/openssl/test/recipes/30-test_evp_data/evpmd_sha.txt ; explicit openssl_evp_data ; +# Botan's own test data (BSD-2-Clause), src/tests/data of the submodule +# third_party/libs/botan at the pin, read at run time from the directory +# WEBCPP_TEST_BOTAN_VECTORS gives, on every target it is built for, never +# copied: webcpp::hash reads hash/whirlpool.vec, hash/skein.vec, +# passhash/bcrypt.vec, bcrypt_pbkdf.vec and kdf/sp800_108_ctr.vec, and its +# c-suites lane runs Botan's own test program over the directory. Quoted as +# wycheproof's define is. +path-constant BOTAN_VECTORS : libs/botan/src/tests/data ; + +rule botan-vectors-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(BOTAN_VECTORS)/hash/whirlpool.vec ] ] + { + errors.user-error "third_party/libs/botan is not checked out. Check it out with" + "`git submodule update --init third_party/libs/botan`." ; + } +} + +.botan-vectors = [ regex.replace $(BOTAN_VECTORS) "\\\\" "/" ] ; +alias botan_vectors : : @botan-vectors-checked-out : : + "\"WEBCPP_TEST_BOTAN_VECTORS=\\\"$(.botan-vectors)\\\"\"" + [ webcpp.data $(BOTAN_VECTORS) ] + libs/botan/src/tests/data/hash/whirlpool.vec + libs/botan/src/tests/data/hash/skein.vec + libs/botan/src/tests/data/passhash/bcrypt.vec + libs/botan/src/tests/data/bcrypt_pbkdf.vec + libs/botan/src/tests/data/kdf/sp800_108_ctr.vec ; +explicit botan_vectors ; + # 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 diff --git a/third_party/libs/botan b/third_party/libs/botan new file mode 160000 index 00000000..01af88c0 --- /dev/null +++ b/third_party/libs/botan @@ -0,0 +1 @@ +Subproject commit 01af88c039fcfaedc418b1af4d6d3a139674e591 diff --git a/tools/botan/configure.py b/tools/botan/configure.py new file mode 100644 index 00000000..15f3563e --- /dev/null +++ b/tools/botan/configure.py @@ -0,0 +1,227 @@ +#!/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) +"""Configures Botan for one target with upstream's configure.py, and lists its sources. + + configure.py --source CHECKOUT --modules MODULES --output DIRECTORY --os OS --cc CC --cpu CPU + +runs CHECKOUT's own configure.py (CODING-GUIDELINES.md chapter 5, rule 13) with +--minimized-build and the modules MODULES lists (tools/botan/modules.txt), for OS, CC and CPU, +into DIRECTORY, unless DIRECTORY already holds a complete configuration, its +webcpp-configure.json. Upstream writes build/build.h, build/target_info.h, the public and internal +headers under build/include and build/build_config.json; nothing is written into CHECKOUT. Each +run writes into a sibling of its own, DIRECTORY.partial-, and renames it into place once +complete, so that an interrupted run leaves no half configuration, and runs that need the same +configuration at once (two b2 processes) never undo each other: the first rename wins, the others +discard theirs and use it. A partial no run has touched for an hour is removed. The configuration +gets the mode the umask gives a new directory. Upstream records the directory it configured into, +the partial's name, in a comment of target_info.h and in build/build_config.json, +build/compile_commands.json, build/botan.doxy and build.ninja; after the rename those name a +directory that no longer exists, and nothing reads them: b2 takes the sources from +webcpp-configure.json, and the comment changes no object. + +It then prints one line per source, `lib ` for the library's and `test ` for its test +program's, each path relative to CHECKOUT with forward slashes, sorted. b2 compiles each as an +object of its own (tools/webcpp-botan.jam). + +Upstream's configure.py is run with python3 -I, its working directory DIRECTORY's parent, +without the environment variables it reads compiler settings from (CXX, CXXFLAGS, AR, AR_OPTIONS +and LDFLAGS) and with a GIT_DIR that is no repository, so that a configuration is a function of +the arguments alone: --disable-cc-tests keeps it from running a compiler, and its `git rev-parse +HEAD` finds no repository around its working directory (the superproject's, in a build), whose +commit would otherwise reach build/version_info.h, and through it Botan's version.cpp. It refuses +a configuration that loads a module seeding a generator from the system (system_rng, auto_rng and +the entropy sources): webcpp's libraries take their randomness elsewhere. + +Exit 0 on success; 1, with the reason on standard output, for a module upstream does not know, a +failed configure.py (its last lines printed), a source outside CHECKOUT, or a refused module. +""" +from __future__ import annotations + +import argparse +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import time + +# The modules that seed a generator from the system, which no configuration may load. +REFUSED = ('system_rng', 'auto_rng', 'entropy', 'jitter_rng', 'processor_rng', 'esdm_rng') + +# The environment variables upstream's configure.py takes compiler settings from. +COMPILER_VARIABLES = ('CXX', 'CXXFLAGS', 'AR', 'AR_OPTIONS', 'LDFLAGS') + +# The file that makes a configuration directory complete, written last. +RECORD = 'webcpp-configure.json' + +# The lines of upstream's output printed when it fails. +FAILURE_LINES = 20 + +# The age after which a partial configuration no run touches is an interrupted run's: a +# configuration takes seconds natively and a few minutes under emulation. +STALE_SECONDS = 3600 + + +class ConfigureError(Exception): + """A configuration that cannot be made, with the reason to print.""" + + +def read_modules(path: Path) -> list[str]: + """The modules path lists, in the file's order: words, a # starting a comment.""" + modules: list[str] = [] + for line in path.read_text().splitlines(): + modules += line.split('#', 1)[0].split() + return modules + + +def upstream_command(checkout: Path, modules: list[str], build: Path, output: Path, + target: tuple[str, str, str]) -> list[str]: + """The command line of upstream's configure.py writing into build, for output's prefix.""" + system, compiler, cpu = target + return [sys.executable, '-I', str(checkout / 'configure.py'), '--minimized-build', + f'--enable-modules={",".join(modules)}', f'--os={system}', f'--cc={compiler}', + f'--cpu={cpu}', '--cc-min-version=0.0', '--disable-cc-tests', + '--disable-shared-library', '--without-documentation', '--link-method=copy', + '--build-tool=ninja', f'--prefix={output / "prefix"}', f'--with-build-dir={build}'] + + +def relative_sources(checkout: Path, sources: list[str]) -> list[str]: + """sources, absolute paths, relative to checkout with forward slashes, sorted.""" + relative: list[str] = [] + for source in sources: + path = Path(source).resolve() + try: + relative.append(path.relative_to(checkout).as_posix()) + except ValueError: + raise ConfigureError(f'Botan source {source} is outside the checkout {checkout}') \ + from None + return sorted(relative) + + +def current_umask() -> int: + """The process's umask, which reading changes: set back at once (this helper has one + thread).""" + mask = os.umask(0) + os.umask(mask) + return mask + + +def remove_stale_partials(output: Path) -> None: + """Removes, best-effort, the partial configurations of output that no run is writing: those + untouched for STALE_SECONDS, left by an interrupted run.""" + for partial in output.parent.glob(f'{output.name}.partial-*'): + try: + if time.time() - partial.stat().st_mtime > STALE_SECONDS: + shutil.rmtree(partial) + except OSError: + pass + + +def install(partial: Path, output: Path) -> dict: + """Renames partial, complete, to output and returns its record; when another run completed + output first, discards partial and returns the winner's record.""" + record = output / RECORD + if not record.is_file(): + try: + partial.rename(output) + return json.loads(record.read_text()) + except OSError as error: + if not record.is_file(): + raise ConfigureError(f'{output} exists without {RECORD}, as no run of this ' + f'helper leaves it; remove it ({error})') from None + shutil.rmtree(partial, ignore_errors=True) + return json.loads(record.read_text()) + + +def run_upstream(checkout: Path, modules: list[str], output: Path, + target: tuple[str, str, str]) -> dict: + """Configures into a partial directory of this run's own, a sibling of output, checks it and + renames it to output; returns its record. Runs that make one configuration at once each + write their own partial, and the first rename wins: a complete output is never removed.""" + output.parent.mkdir(parents=True, exist_ok=True) + remove_stale_partials(output) + partial = Path(tempfile.mkdtemp(dir=output.parent, prefix=f'{output.name}.partial-')) + try: + # mkdtemp makes the partial 0700, which the rename would keep: the configuration gets the + # mode of any directory the build makes, readable by another user (a lane in a container). + os.chmod(partial, 0o777 & ~current_umask()) + record = configure_partial(checkout, modules, partial, output, target) + (partial / RECORD).write_text(json.dumps(record, indent=1) + '\n') + return install(partial, output) + finally: + if partial.exists(): + shutil.rmtree(partial, ignore_errors=True) + + +def configure_partial(checkout: Path, modules: list[str], partial: Path, output: Path, + target: tuple[str, str, str]) -> dict: + """Runs upstream's configure.py into partial, for output's prefix, and returns the record of + the configuration, checked.""" + environment = {name: value for name, value in os.environ.items() + if name not in COMPILER_VARIABLES} + # Upstream asks git for its revision from its working directory, which in a build is inside + # the superproject: a GIT_DIR that is no repository leaves it "unknown", as in a release. + environment['GIT_DIR'] = str(partial / 'no-repository') + result = subprocess.run(upstream_command(checkout, modules, partial, output, target), + cwd=partial.parent, env=environment, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, text=True) + if result.returncode != 0: + last = '\n'.join(result.stdout.rstrip().splitlines()[-FAILURE_LINES:]) + raise ConfigureError(f"Botan's configure.py failed ({result.returncode}):\n{last}") + configuration = json.loads((partial / 'build' / 'build_config.json').read_text()) + loaded = set(configuration['mod_list']) + refused = sorted(loaded.intersection(REFUSED)) + if refused: + raise ConfigureError('Botan modules that seed a generator from the system are loaded: ' + f'{" ".join(refused)}; remove what pulls them in from ' + 'tools/botan/modules.txt') + missing = [module for module in modules if module not in loaded] + if missing: + raise ConfigureError(f'Botan did not load the modules {" ".join(missing)}') + return {'target': list(target), 'modules': modules, + 'lib': relative_sources(checkout, configuration['lib_srcs']), + 'test': relative_sources(checkout, configuration['test_srcs'])} + + +def configure(checkout: Path, modules: list[str], output: Path, + target: tuple[str, str, str]) -> dict: + """The record of output's configuration, made first unless output is complete.""" + record = output / RECORD + if record.is_file(): + return json.loads(record.read_text()) + return run_upstream(checkout, modules, output, target) + + +def main(arguments: list[str]) -> int: + parser = argparse.ArgumentParser( + description="Configures Botan for one target with upstream's configure.py, and lists " + 'its sources.') + parser.add_argument('--source', type=Path, required=True) + parser.add_argument('--modules', type=Path, required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--os', required=True) + parser.add_argument('--cc', required=True) + parser.add_argument('--cpu', required=True) + options = parser.parse_args(arguments) + try: + record = configure(options.source.resolve(), read_modules(options.modules), + options.output.resolve(), (options.os, options.cc, options.cpu)) + except ConfigureError as error: + print(error) + return 1 + lines = [f'lib {path}' for path in record['lib']] + \ + [f'test {path}' for path in record['test']] + # Bytes, so that a Windows console adds no carriage return b2 would read into a path. + sys.stdout.flush() + sys.stdout.buffer.write(''.join(f'{line}\n' for line in lines).encode()) + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/tools/botan/configure_test.py b/tools/botan/configure_test.py new file mode 100644 index 00000000..3bc6bae2 --- /dev/null +++ b/tools/botan/configure_test.py @@ -0,0 +1,240 @@ +#!/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 tools/botan/configure.py over the real checkout, third_party/libs/botan: each target of +/third_party//botan configures, with the same sources everywhere and the modules of modules.txt +loaded, none that seeds a generator from the system; a complete configuration is never made again, +an interrupted one is; runs that make one configuration at once all succeed; a configuration's +directory has the mode a new directory gets; an unknown module, and one that seeds a generator from +the system, is refused, naming it; the compiler settings of the environment change nothing, and +neither does a git repository around the configuration's directory. Run as `python3 +tools/botan/configure_test.py`.""" +from __future__ import annotations + +import json +import os +import re +from pathlib import Path +import shutil +import stat +import subprocess +import sys +import tempfile +import time +import unittest + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +CHECKOUT = ROOT / 'third_party/libs/botan' +MODULES = HERE / 'modules.txt' +SCRIPT = HERE / 'configure.py' + +# The targets of tools/webcpp-botan.jam's table: --os, --cc and --cpu. +TARGETS = {'macos-clang-arm64': ('macos', 'clang', 'arm64'), + 'linux-gcc-x86_64': ('linux', 'gcc', 'x86_64'), + 'linux-clang-arm64': ('linux', 'clang', 'arm64'), + 'windows-msvc-x86_64': ('windows', 'msvc', 'x86_64'), + 'emscripten': ('emscripten', 'emcc', 'wasm')} + +# What --minimized-build with modules.txt gives at 3.14.1, on every target. +LIB_SOURCES = 208 +TEST_SOURCES = 152 + +REFUSED = ('system_rng', 'auto_rng', 'entropy', 'jitter_rng', 'processor_rng', 'esdm_rng') + + +def configure(output: Path, target: tuple[str, str, str], modules: Path = MODULES, + environment: dict[str, str] | None = None) -> subprocess.CompletedProcess: + system, compiler, cpu = target + return subprocess.run([sys.executable, str(SCRIPT), '--source', str(CHECKOUT), + '--modules', str(modules), '--output', str(output), '--os', system, + '--cc', compiler, '--cpu', cpu], + capture_output=True, text=True, env=environment) + + +def listed(result: subprocess.CompletedProcess) -> tuple[list[str], list[str]]: + """The library's and the test program's sources the helper printed, in its order.""" + lib: list[str] = [] + test: list[str] = [] + for line in result.stdout.splitlines(): + kind, _, path = line.partition(' ') + {'lib': lib, 'test': test}[kind].append(path) + return lib, test + + +def module_names() -> list[str]: + modules: list[str] = [] + for line in MODULES.read_text().splitlines(): + modules += line.split('#', 1)[0].split() + return modules + + +def without_directory(directory: Path, header: str) -> str: + """The text of directory's build/
, with directory's name (and its partial's) as DIR.""" + text = (directory / 'build' / header).read_text() + return re.sub(re.escape(str(directory)) + r'(\.partial-\w+)?', 'DIR', text) + + +def times(directory: Path) -> dict[str, int]: + return {str(path.relative_to(directory)): path.stat().st_mtime_ns + for path in directory.rglob('*')} + + +class ConfigureTest(unittest.TestCase): + """One scratch directory for the whole class, so that each target configures once.""" + + scratch: Path + results: dict[str, subprocess.CompletedProcess] + + @classmethod + def setUpClass(cls) -> None: + cls.scratch = Path(tempfile.mkdtemp(prefix='botan configure ')).resolve() + cls.results = {name: configure(cls.scratch / name, target) + for name, target in TARGETS.items()} + + @classmethod + def tearDownClass(cls) -> None: + shutil.rmtree(cls.scratch) + + def test_every_target_configures(self) -> None: + for name, result in self.results.items(): + self.assertEqual(result.returncode, 0, (name, result.stdout, result.stderr)) + lib, test = listed(result) + self.assertEqual((len(lib), len(test)), (LIB_SOURCES, TEST_SOURCES), name) + self.assertEqual(lib, sorted(lib), name) + self.assertEqual(test, sorted(test), name) + self.assertTrue(all((CHECKOUT / path).is_file() for path in lib + test), name) + self.assertTrue((self.scratch / name / 'build/build.h').is_file(), name) + + def test_the_sources_are_the_same_on_every_target(self) -> None: + lists = {name: listed(result) for name, result in self.results.items()} + first = lists['macos-clang-arm64'] + for name, sources in lists.items(): + self.assertEqual(sources, first, name) + + def test_the_modules_are_loaded_and_no_system_generator(self) -> None: + wanted = module_names() + for name in TARGETS: + loaded = json.loads((self.scratch / name / 'build/build_config.json') + .read_text())['mod_list'] + self.assertEqual([module for module in wanted if module not in loaded], [], name) + self.assertEqual([module for module in REFUSED if module in loaded], [], name) + + def test_nothing_is_written_into_the_checkout(self) -> None: + status = subprocess.run(['git', '-C', str(CHECKOUT), 'status', '--porcelain'], + capture_output=True, text=True, check=True) + self.assertEqual(status.stdout, '') + + def test_a_complete_configuration_is_not_made_again(self) -> None: + output = self.scratch / 'macos-clang-arm64' + before = times(output) + again = configure(output, TARGETS['macos-clang-arm64']) + self.assertEqual(again.returncode, 0, again.stdout) + self.assertEqual(again.stdout, self.results['macos-clang-arm64'].stdout) + self.assertEqual(times(output), before) + + def test_an_interrupted_configuration_is_made_again(self) -> None: + output = self.scratch / 'interrupted' + # An interrupted run's partial, untouched for two hours, and a running one's, just made. + stale = self.scratch / 'interrupted.partial-stale' + running = self.scratch / 'interrupted.partial-running' + for partial in (stale, running): + partial.mkdir() + (partial / 'build.h').write_text('half\n') + hours_ago = time.time() - 7200 + os.utime(stale, (hours_ago, hours_ago)) + result = configure(output, TARGETS['linux-gcc-x86_64']) + self.assertEqual(result.returncode, 0, result.stdout) + self.assertEqual(listed(result), listed(self.results['linux-gcc-x86_64'])) + self.assertFalse(stale.exists()) + self.assertTrue(running.exists()) + self.assertTrue((output / 'webcpp-configure.json').is_file()) + + def test_concurrent_runs_of_one_configuration_all_succeed(self) -> None: + output = self.scratch / 'concurrent' + system, compiler, cpu = TARGETS['windows-msvc-x86_64'] + command = [sys.executable, str(SCRIPT), '--source', str(CHECKOUT), '--modules', + str(MODULES), '--output', str(output), '--os', system, '--cc', compiler, + '--cpu', cpu] + # Three rounds of four runs at once, each round from no configuration. + for _ in range(3): + if output.exists(): + shutil.rmtree(output) + runs = [subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + text=True) for _ in range(4)] + outputs = [run.communicate()[0] for run in runs] + for run, text in zip(runs, outputs): + self.assertEqual(run.returncode, 0, text) + self.assertEqual(text, self.results['windows-msvc-x86_64'].stdout) + self.assertTrue((output / 'webcpp-configure.json').is_file()) + self.assertTrue((output / 'build/build.h').is_file()) + self.assertEqual(sorted(self.scratch.glob('concurrent.partial-*')), []) + + def test_an_unknown_module_is_refused(self) -> None: + modules = self.scratch / 'unknown.txt' + modules.write_text('sha2_32 no_such_module # one Botan does not know\n') + output = self.scratch / 'unknown' + result = configure(output, TARGETS['linux-gcc-x86_64'], modules) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertIn('no_such_module', result.stdout) + self.assertFalse(output.exists()) + + def test_a_system_generator_is_refused(self) -> None: + modules = self.scratch / 'system.txt' + modules.write_text('sha2_32 system_rng # seeds from the system, which no build may\n') + output = self.scratch / 'system' + result = configure(output, TARGETS['linux-gcc-x86_64'], modules) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertIn('seed a generator from the system are loaded: system_rng', result.stdout) + self.assertFalse(output.exists()) + self.assertEqual(sorted(self.scratch.glob('system.partial-*')), []) + + @unittest.skipIf(os.name == 'nt', 'Windows keeps no POSIX mode') + def test_the_configuration_has_a_directory_s_usual_mode(self) -> None: + # A private temporary directory is made 0700; renamed into place, the configuration + # would be unreadable to another user, as a lane in a container may run. + mask = os.umask(0) + os.umask(mask) + for name in TARGETS: + mode = stat.S_IMODE((self.scratch / name).stat().st_mode) + self.assertEqual(oct(mode), oct(0o777 & ~mask), name) + + def test_the_compiler_settings_of_the_environment_change_nothing(self) -> None: + output = self.scratch / 'environment' + environment = dict(os.environ, CXX='false', CXXFLAGS='-DWRONG', AR='false', + AR_OPTIONS='x', LDFLAGS='-lwrong') + result = configure(output, TARGETS['linux-gcc-x86_64'], environment=environment) + self.assertEqual(result.returncode, 0, result.stdout) + reference = self.scratch / 'linux-gcc-x86_64' + self.assertEqual(result.stdout, self.results['linux-gcc-x86_64'].stdout) + for header in ('build.h', 'target_info.h'): + # target_info.h names the directory it was configured into, which differs. + self.assertEqual(without_directory(output, header), + without_directory(reference, header), header) + + def test_no_enclosing_repository_reaches_the_configuration(self) -> None: + # In a build the configuration directory is inside the superproject's checkout, whose + # commit upstream's configure.py would take as Botan's revision: a configuration made + # inside a repository, of a commit of its own, is the one made outside any. + repository = self.scratch / 'repository' + repository.mkdir() + git = ['git', '-C', str(repository), '-c', 'user.name=webcpp', + '-c', 'user.email=webcpp@example.invalid', '-c', 'commit.gpgsign=false'] + subprocess.run(git[:3] + ['init', '-q'], check=True) + subprocess.run(git + ['commit', '-q', '--allow-empty', '-m', 'enclosing'], check=True) + output = repository / 'bin' / 'emscripten' + result = configure(output, TARGETS['emscripten']) + self.assertEqual(result.returncode, 0, result.stdout) + self.assertEqual(result.stdout, self.results['emscripten'].stdout) + reference = self.scratch / 'emscripten' + for header in ('version_info.h', 'build.h', 'target_info.h'): + text = without_directory(output, header) + self.assertNotIn('git:', text, header) + self.assertEqual(text, without_directory(reference, header), header) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/botan/modules.txt b/tools/botan/modules.txt new file mode 100644 index 00000000..7e4e8081 --- /dev/null +++ b/tools/botan/modules.txt @@ -0,0 +1,31 @@ +# The modules of Botan 3.14.1 that /third_party//botan configures with +# --minimized-build (tools/botan/configure.py, CODING-GUIDELINES.md chapter 5, +# rule 13): one list for every webcpp library, each module with who needs it +# and why. A # starts a comment; the names are those of +# `configure.py --list-modules`, public ones only (an internal module, such as +# cshake_xof or xmd, is loaded by a module that needs it). +# +# webcpp::hash (design D42's list, corrected at 3.14.1): +md5 sha1 sha2_32 sha2_64 # digests::md5 to sha2_512_256, and their HMACs; D42 left them out +sha3 shake shake_xof keccak # SHA-3, SHAKE of any length (shake_xof, missing from D42), Keccak +blake2 blake2s blake2mac # BLAKE2b of 1 to 64 bytes and keyed, BLAKE2s-256 +rmd160 sm3 streebog whirlpool skein +hmac kmac siphash # kmac pulls the internal cshake_xof, which D42 named +hkdf pbkdf2 scrypt argon2 bcrypt bcrypt_pbkdf +sp800_108 # kbkdf, SP800-108-Counter +sp800_56a # sskdf, SP800-56A(): SP 800-56C's one-step KDF +kdf2 # x963kdf, KDF2(): ANSI X9.63's construction +# webcpp::crypto (its design D2's Botan row, its spec's SPKI, PKCS#8 and PEM, hash-to-curve, HPKE): +ed25519 ed448 x25519 x448 +ecdsa ecdh rfc6979 # rfc6979: deterministic ECDSA nonces, as crypto's ECDSA family has +pcurves_secp256r1 pcurves_secp384r1 pcurves_secp521r1 +pcurves_brainpool256r1 pcurves_brainpool384r1 pcurves_brainpool512r1 +rsa emsa_pssr emsa_pkcs1 eme_oaep +ml_kem ml_dsa slh_dsa_sha2 slh_dsa_shake +aes gcm siv gcm_siv ccm ocb eax nist_keywrap cmac +chacha20poly1305 # ChaCha20-Poly1305 and XChaCha20-Poly1305 (a 24-byte nonce) +camellia aria sm4 serpent twofish +bls12_381 # only for the internal xmd that ec_group's RFC 9380 hash-to-curve + # on the P-curves needs; crypto never exposes BLS12-381 (blst's) +hpke +pubkey pem # SPKI (x509_key.h), PKCS#8 (pkcs8.h) and PEM diff --git a/tools/botan/pin.json b/tools/botan/pin.json new file mode 100644 index 00000000..d288cd4a --- /dev/null +++ b/tools/botan/pin.json @@ -0,0 +1,5 @@ +{ + "version": "3.14.1", + "commit": "01af88c039fcfaedc418b1af4d6d3a139674e591", + "repository": "https://github.com/randombit/botan.git" +} diff --git a/tools/botan/source.py b/tools/botan/source.py new file mode 100644 index 00000000..10cd23b1 --- /dev/null +++ b/tools/botan/source.py @@ -0,0 +1,34 @@ +# 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 check of the Botan checkout that /third_party//botan configures and compiles. + +tools/third_party_build.py key applies check_checkout before it keys Botan's configurations +(tools/webcpp-third-party.jam), so that b2 never configures a checkout other than its pin: its +HEAD must be tools/botan/pin.json's commit and its tracked files unchanged. A source distribution, +which holds no .git, carries the files of the commit its release recorded, and is taken as it is. +""" +from __future__ import annotations + +import os +from pathlib import Path +import subprocess + + +def check_checkout(checkout: Path, pin: dict) -> None: + """Raises RuntimeError unless checkout, a Git checkout, is at pin's commit and clean.""" + if not os.path.lexists(checkout / '.git'): + return + revision = subprocess.run(['git', '-C', str(checkout), 'rev-parse', 'HEAD'], + capture_output=True, text=True) + if revision.returncode != 0 or revision.stdout.strip() != pin['commit']: + raise RuntimeError(f'Botan checkout {checkout} is not at {pin["commit"]} ' + '(tools/botan/pin.json); run `git submodule update --init ' + 'third_party/libs/botan`') + status = subprocess.run(['git', '-C', str(checkout), 'status', '--porcelain', + '--untracked-files=no'], capture_output=True, text=True) + if status.returncode != 0 or status.stdout.strip(): + raise RuntimeError(f'Botan checkout {checkout} has changed files; restore them:\n' + f'{status.stdout.rstrip()}') diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index 81bc3247..6cdd2c5d 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -42,14 +42,14 @@ 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; 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; 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). +default that is not among its backends or outside the order hash2, xkcp, blake3, sodium +(design D33), or none (null) though a backend of that order 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; 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. """ @@ -84,7 +84,8 @@ # 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. +# (design D34): the first that has the tag; never bearssl, openssl, botan or webcrypto. A +# function's default is of the same order (design D33). 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. @@ -177,8 +178,9 @@ def backend_argument(self, function: dict) -> str: 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 that has its cell, + has it, of the order hash2, xkcp, blake3, sodium (designs D33 and D34: never bearssl, + openssl or botan), or none (null) exactly when no backend of the order has it (as kbkdf + and bcrypt); 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 = [] @@ -197,6 +199,9 @@ def check_defaults(self) -> None: 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 default not in FAMILY_DEFAULTS: + faults.append(f'doc/capabilities.json: the function {name} has the default ' + f'{default}, which is not one of {", ".join(FAMILY_DEFAULTS)}') 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 ' @@ -414,14 +419,34 @@ def asynchronous_only(data: Data, backend: str) -> bool: return bool(data.backends[backend].get('asynchronous_only')) +EXCEPTIONS_ONLY = 'with exceptions only' + + +def exceptions_only(data: Data, backend: str) -> bool: + """Whether a build without exceptions cannot have the backend (backends::botan).""" + return bool(data.backends[backend].get('exceptions_only')) + + +def backend_notes(data: Data, backend: str) -> list[str]: + """What a backend's name is followed by: that only the asynchronous family takes it, that only + a build with exceptions has it.""" + notes = [] + if asynchronous_only(data, backend): + notes.append(ASYNCHRONOUS_ONLY) + if exceptions_only(data, backend): + notes.append(EXCEPTIONS_ONLY) + return notes + + 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 '' + return ''.join(f', {note}' for note in backend_notes(data, backend)) 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 '' + """What follows a backend's name in a table: that only the asynchronous family takes it, or + that only a build with exceptions has it.""" + return ''.join(f' ({note})' for note in backend_notes(data, backend)) def partial_text(held: dict) -> str: @@ -687,6 +712,8 @@ def backends_chapter(data: Data) -> str: for b in table['backends']: called = (f'{ASYNCHRONOUS_ONLY} (async.hpp)' if b.get('asynchronous_only') else 'every function of its cells') + if b.get('exceptions_only'): + called += f', {EXCEPTIONS_ONLY}' lines += ['', f'| {b["name"]}', f'| {b["library"]}', f'| {b["licence"]}', f'| `{b["jamfile"]}`', f'| {", ".join(b["targets"])}', f'| {called}'] lines += ['|===', ''] diff --git a/tools/lint/lint_test.py b/tools/lint/lint_test.py index 44fd5d1e..f56b2420 100755 --- a/tools/lint/lint_test.py +++ b/tools/lint/lint_test.py @@ -2545,7 +2545,8 @@ def test_changelog(root): '#define WEBCPP_HASH_XKCP_COMMIT {xkcp}\n#endif\n' '#define WEBCPP_HASH_SODIUM_COMMIT {sodium}\n' '#define WEBCPP_HASH_BLAKE3_COMMIT {blake3}\n' - '#define WEBCPP_HASH_BEARSSL_COMMIT {bearssl}\n#endif\n') + '#define WEBCPP_HASH_BEARSSL_COMMIT {bearssl}\n' + '#define WEBCPP_HASH_BOTAN_COMMIT {botan}\n#endif\n') HASH_CANARY_HEADER = 'libs/hash/include/webcpp/hash/detail/canary.h' @@ -2605,26 +2606,36 @@ def test_canary_pins(root): f'{CANARY_HEADER}: a pin is not of the form #define WEBCPP_CRYPTO__COMMIT <7 hex>: ' '#define WEBCPP_CRYPTO_CTAES_COMMIT 123456']) # hash's detail/canary.h is read beside crypto's: sodium's submodule is libsodium, xkcp's, - # blake3's and bearssl's are their own names; a wrong pin fails at the header, naming both. + # blake3's, bearssl's and botan's are their own names; a wrong pin fails at the header, naming + # both. write(root, CANARY_HEADER, CANARY.format(bearssl='1234567', ctaes='1234567')) xkcp = 'aaaaaaa' + '0' * 33 libsodium = 'bbbbbbb' + '0' * 33 blake3 = 'ccccccc' + '0' * 33 + botan = 'ddddddd' + '0' * 33 + record_submodule(root, 'botan', botan) record_submodule(root, 'xkcp', xkcp) record_submodule(root, 'libsodium', libsodium) record_submodule(root, 'blake3', blake3) write(root, HASH_CANARY_HEADER, HASH_CANARY.format(xkcp='aaaaaaa', sodium='bbbbbbb', blake3='ccccccc', - bearssl='1234567')) + bearssl='1234567', botan='ddddddd')) commit_recorded(root, 'Hash canaries at the recorded commits') expect_clean(lint(root)) write(root, HASH_CANARY_HEADER, HASH_CANARY.format(xkcp='aaaaaaa', sodium='bbbbbba', blake3='ccccccc', - bearssl='1234567')) + bearssl='1234567', botan='ddddddd')) commit_recorded(root, 'A wrong hash pin') expect_alone(lint(root), 'canary pins', [ f'{HASH_CANARY_HEADER}: sodium is pinned at bbbbbba and ' 'third_party/libs/libsodium is at bbbbbbb']) + write(root, HASH_CANARY_HEADER, + HASH_CANARY.format(xkcp='aaaaaaa', sodium='bbbbbbb', blake3='ccccccc', + bearssl='1234567', botan='dddddde')) + commit_recorded(root, 'A wrong Botan pin') + expect_alone(lint(root), 'canary pins', [ + f'{HASH_CANARY_HEADER}: botan is pinned at dddddde and ' + 'third_party/libs/botan is at ddddddd']) def test_pyright(root): 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 a9b4cd2b..e4a923e5 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. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::argon2d has no default backend. Name one of: backends::openssl, backends::botan. 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 index 68f4f7be..802ed094 100644 --- 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 @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: kdfs::argon2d is not in this backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::argon2d is not in this backend. Name one of: backends::openssl, backends::botan. 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 f3d1dfbc..86300a2a 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp @@ -4,8 +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 and backends::openssl stops with spec section -// 3.3's text. +// argon2id on another backend than backends::sodium, backends::openssl and backends::botan 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 acecd86d..65e9b93e 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 and backends::openssl alone. Name one, and add /third_party//sodium or /webcpp/hash//openssl to the program's Jamfile. +contains: webcpp::hash: argon2id is in backends::sodium, backends::openssl and backends::botan alone. Name one, and add /third_party//sodium, /webcpp/hash//openssl or /third_party//botan to the program's Jamfile. diff --git a/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_without_threads/Jamfile new file mode 100644 index 00000000..34ed1334 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_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_bcrypt_pbkdf_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_bcrypt_pbkdf_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_without_threads/app.cpp new file mode 100644 index 00000000..06d855fc --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_without_threads/app.cpp @@ -0,0 +1,31 @@ +// 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_bcrypt_pbkdf in a build without threads stops with spec 11.5's text, which names +// bcrypt_pbkdf: natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS +// removes them; on wasip2 and wasip3 there are none. No Botan is needed: the refusal precedes any +// engine. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + std::array const password{1}; + std::array const salt{2}; + webcpp::hash::async_bcrypt_pbkdf( + context.get_executor(), output, password, salt, 16, + [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_without_threads/async_bcrypt_pbkdf_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_without_threads/async_bcrypt_pbkdf_without_threads.outcome new file mode 100644 index 00000000..6530fa1d --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_pbkdf_without_threads/async_bcrypt_pbkdf_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_bcrypt_pbkdf_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_bcrypt_pbkdf runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call bcrypt_pbkdf. diff --git a/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_without_threads/Jamfile new file mode 100644 index 00000000..66f9e907 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_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_bcrypt_verify_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_bcrypt_verify_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_without_threads/app.cpp new file mode 100644 index 00000000..79c601ca --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_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_bcrypt_verify in a build without threads stops with spec 11.5's text, which names +// bcrypt_verify: natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS +// removes them; on wasip2 and wasip3 there are none. No Botan is needed: the refusal precedes any +// engine. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array const password{1}; + webcpp::hash::async_bcrypt_verify( + context.get_executor(), password, "$2b$04$......................", + [](boost::system::error_code /*code*/, bool /*same*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_without_threads/async_bcrypt_verify_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_without_threads/async_bcrypt_verify_without_threads.outcome new file mode 100644 index 00000000..604b863c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_verify_without_threads/async_bcrypt_verify_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_bcrypt_verify_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_bcrypt_verify runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call bcrypt_verify. diff --git a/tools/test/fixtures/hash_jamfiles/async_bcrypt_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_bcrypt_without_threads/Jamfile new file mode 100644 index 00000000..84f8b72b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_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_bcrypt_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_bcrypt_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_bcrypt_without_threads/app.cpp new file mode 100644 index 00000000..6d1d0196 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_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_bcrypt in a build without threads stops with spec 11.5's text, which names bcrypt: +// natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS removes them; on +// wasip2 and wasip3 there are none. No Botan is needed: the refusal precedes any engine. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + std::array const salt{}; + webcpp::hash::async_bcrypt( + context.get_executor(), output, {}, salt, {}, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_bcrypt_without_threads/async_bcrypt_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_bcrypt_without_threads/async_bcrypt_without_threads.outcome new file mode 100644 index 00000000..f87bc378 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_bcrypt_without_threads/async_bcrypt_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_bcrypt_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_bcrypt runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call bcrypt. diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/bcrypt_no_default/Jamfile new file mode 100644 index 00000000..a5ca17dc --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_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/bcrypt_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/bcrypt_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/bcrypt_no_default/app.cpp new file mode 100644 index 00000000..f1138128 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_no_default/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) + +// bcrypt and bcrypt_verify on their default, which kdfs::bcrypt has none of, stop (design D34). + +#include + +#include +#include +#include + +int main() { + std::array output{}; + std::array const salt{}; + auto const made = webcpp::hash::bcrypt(output, {}, salt); + auto const same = + webcpp::hash::bcrypt_verify({}, std::string_view(output.data(), output.size())); + return made && same ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_no_default/bcrypt_no_default.outcome b/tools/test/fixtures/hash_jamfiles/bcrypt_no_default/bcrypt_no_default.outcome new file mode 100644 index 00000000..0b02c90e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_no_default/bcrypt_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/bcrypt_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::bcrypt has no default backend. Name one of: backends::botan. diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/bcrypt_on_hash2/Jamfile new file mode 100644 index 00000000..4f1f6aa4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_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/bcrypt_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/bcrypt_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/bcrypt_on_hash2/app.cpp new file mode 100644 index 00000000..97e3b5ed --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_on_hash2/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) + +// bcrypt named on backends::hash2, which has no bcrypt, stops naming the backend that has it +// (spec 3.3, the row of doc/capabilities.json). + +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array const salt{}; + auto const done = webcpp::hash::bcrypt(output, {}, salt); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_on_hash2/bcrypt_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/bcrypt_on_hash2/bcrypt_on_hash2.outcome new file mode 100644 index 00000000..7a19e3ee --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_on_hash2/bcrypt_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/bcrypt_on_hash2, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::bcrypt is not in this backend. Name one of: backends::botan. diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_no_default/Jamfile new file mode 100644 index 00000000..bfca68b0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_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/bcrypt_pbkdf_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/bcrypt_pbkdf_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_no_default/app.cpp new file mode 100644 index 00000000..dbb45dde --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_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) + +// bcrypt_pbkdf on its default, which kdfs::bcrypt_pbkdf has none of, stops (design D34). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array const password{1}; + std::array const salt{2}; + auto const done = webcpp::hash::bcrypt_pbkdf(output, password, salt, 16); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_no_default/bcrypt_pbkdf_no_default.outcome b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_no_default/bcrypt_pbkdf_no_default.outcome new file mode 100644 index 00000000..0b7961d5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_no_default/bcrypt_pbkdf_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/bcrypt_pbkdf_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::bcrypt_pbkdf has no default backend. Name one of: backends::botan. diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_on_hash2/Jamfile new file mode 100644 index 00000000..252e2388 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_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/bcrypt_pbkdf_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/bcrypt_pbkdf_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_on_hash2/app.cpp new file mode 100644 index 00000000..3ff7c1cd --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_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) + +// bcrypt_pbkdf named on backends::hash2, which has no bcrypt_pbkdf, stops naming the backend that +// has it (spec 3.3). + +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array const password{1}; + std::array const salt{2}; + auto const done = + webcpp::hash::bcrypt_pbkdf(output, password, salt, 16); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_on_hash2/bcrypt_pbkdf_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_on_hash2/bcrypt_pbkdf_on_hash2.outcome new file mode 100644 index 00000000..a0a30c35 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bcrypt_pbkdf_on_hash2/bcrypt_pbkdf_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/bcrypt_pbkdf_on_hash2, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::bcrypt_pbkdf is not in this backend. Name one of: backends::botan. diff --git a/tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_hmac.outcome b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_hmac.outcome index d53c765f..c07d48d8 100644 --- a/tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_hmac.outcome +++ b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_hmac.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::bearssl has HKDF over hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384 and hmac_sha2_512 alone. Over this hmac, name backends::hash2 (every hmac) or backends::openssl (every hmac but hmac_ripemd_128). +contains: webcpp::hash: backends::bearssl has HKDF over hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384 and hmac_sha2_512 alone. Over this hmac, name backends::hash2 (every hmac), backends::openssl (every hmac but hmac_ripemd_128) or backends::botan (every hmac but hmac_ripemd_128 and hmac_sha2_512_224). diff --git a/tools/test/fixtures/hash_jamfiles/botan/Jamfile b/tools/test/fixtures/hash_jamfiles/botan/Jamfile new file mode 100644 index 00000000..d0e16d64 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan/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) + +# A user's Jamfile over Botan (spec 5.1): the library's one line. +exe app : app.cpp /webcpp/hash//hash /third_party//botan ; diff --git a/tools/test/fixtures/hash_jamfiles/botan/app.cpp b/tools/test/fixtures/hash_jamfiles/botan/app.cpp new file mode 100644 index 00000000..bcfbf562 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan/app.cpp @@ -0,0 +1,50 @@ +// 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 user's program over backends::botan: Whirlpool of "abc" (its authors' vector), and HMAC over +// Streebog-256 of RFC 7836 section 4.1.1's example, natively and on Emscripten. + +#include + +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; + std::array const abc{0x61, 0x62, 0x63}; + std::array digest{}; + if (!hash::digest_of(digest, abc)) { + return 1; + } + print_hex("whirlpool", digest); + std::array key{}; + std::iota(key.begin(), key.end(), std::uint8_t{0}); + std::array const message{0x01, 0x26, 0xbd, 0xb8, 0x78, 0x00, 0xaf, 0x21, + 0x43, 0x41, 0x45, 0x65, 0x63, 0x78, 0x01, 0x00}; + std::array tag{}; + if (!hash::mac, hash::backends::botan>(tag, key, + message)) { + return 1; + } + print_hex("hmac_streebog_256", tag); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/botan/botan.outcome b/tools/test/fixtures/hash_jamfiles/botan/botan.outcome new file mode 100644 index 00000000..0cabbb3c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan/botan.outcome @@ -0,0 +1,12 @@ +# 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) + +[all] +targets: native emscripten +build: succeeds +run: app +whirlpool 4e2448a4c6f486bb16b6562c73b4020bf3043e3a731bce721ae1b303d97e6d4c7181eebdb6c57e277d0e34957114cbd6c797fc9d95d8b582d225292076d4eef5 +hmac_streebog_256 a1aa5f7de402d7b3d323f2991c8d4534013137010a83754fd0af6d7cd4922ed9 diff --git a/tools/test/fixtures/hash_jamfiles/botan_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/botan_not_linked/Jamfile new file mode 100644 index 00000000..48023ad2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_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/botan_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/botan_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/botan_not_linked/app.cpp new file mode 100644 index 00000000..1ce4122b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_not_linked/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 on backends::botan in a program that does not link Botan stops with the instruction to +// add /third_party//botan (spec section 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/botan_not_linked/botan_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/botan_not_linked/botan_not_linked.outcome new file mode 100644 index 00000000..73cefc80 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_not_linked/botan_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 the same text is +# test/messages/botan_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::botan needs Botan. Add /third_party//botan to the program's Jamfile (native and Emscripten, with exceptions): exe app : app.cpp /webcpp/hash//hash /third_party//botan ; diff --git a/tools/test/fixtures/hash_jamfiles/botan_on_wasi/Jamfile b/tools/test/fixtures/hash_jamfiles/botan_on_wasi/Jamfile new file mode 100644 index 00000000..d0e16d64 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_on_wasi/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) + +# A user's Jamfile over Botan (spec 5.1): the library's one line. +exe app : app.cpp /webcpp/hash//hash /third_party//botan ; diff --git a/tools/test/fixtures/hash_jamfiles/botan_on_wasi/app.cpp b/tools/test/fixtures/hash_jamfiles/botan_on_wasi/app.cpp new file mode 100644 index 00000000..bcfbf562 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_on_wasi/app.cpp @@ -0,0 +1,50 @@ +// 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 user's program over backends::botan: Whirlpool of "abc" (its authors' vector), and HMAC over +// Streebog-256 of RFC 7836 section 4.1.1's example, natively and on Emscripten. + +#include + +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; + std::array const abc{0x61, 0x62, 0x63}; + std::array digest{}; + if (!hash::digest_of(digest, abc)) { + return 1; + } + print_hex("whirlpool", digest); + std::array key{}; + std::iota(key.begin(), key.end(), std::uint8_t{0}); + std::array const message{0x01, 0x26, 0xbd, 0xb8, 0x78, 0x00, 0xaf, 0x21, + 0x43, 0x41, 0x45, 0x65, 0x63, 0x78, 0x01, 0x00}; + std::array tag{}; + if (!hash::mac, hash::backends::botan>(tag, key, + message)) { + return 1; + } + print_hex("hmac_streebog_256", tag); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/botan_on_wasi/botan_on_wasi.outcome b/tools/test/fixtures/hash_jamfiles/botan_on_wasi/botan_on_wasi.outcome new file mode 100644 index 00000000..a7778fca --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_on_wasi/botan_on_wasi.outcome @@ -0,0 +1,16 @@ +# 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) + +# /third_party//botan is built natively and for Emscripten alone (plan Task +# 40b): on WASI the build stops with the target's text. +[all] +targets: wasip2 wasip3 +build: fails +same-as: botan/app.cpp app.cpp +[wasip2] +contains: /third_party//botan is built natively and for Emscripten. On clang-wasip2 it is not built yet +[wasip3] +contains: /third_party//botan is built natively and for Emscripten. On clang-wasip3 it is not built yet diff --git a/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/Jamfile b/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/Jamfile new file mode 100644 index 00000000..8e2723e5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/Jamfile @@ -0,0 +1,10 @@ +# 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/botan_without_exceptions of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /third_party//botan + : WEBCPP_HASH_NO_EXCEPTIONS ; diff --git a/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/app.cpp b/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/app.cpp new file mode 100644 index 00000000..4c0f97a1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/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) + +// digest_of on backends::botan in a build without exceptions (WEBCPP_HASH_NO_EXCEPTIONS), Botan +// linked, stops: Botan reports its errors by throwing, and backends/botan.hpp declares nothing +// without exceptions (ruling P4). + +#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/botan_without_exceptions/botan_without_exceptions.outcome b/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/botan_without_exceptions.outcome new file mode 100644 index 00000000..8cbe360d --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/botan_without_exceptions/botan_without_exceptions.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 the same text is +# test/messages/botan_without_exceptions, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::botan needs exceptions: Botan reports its errors by throwing, and its header declares nothing without them. Build with exception-handling=on, or name another backend. diff --git a/tools/test/fixtures/hash_jamfiles/canary_botan_missing/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_botan_missing/Jamfile new file mode 100644 index 00000000..65c95d28 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_botan_missing/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) + +# Botan's headers and define taken from its usage requirements (), the +# library not linked. +exe app : app.cpp /webcpp/hash//hash : /third_party//botan ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_botan_missing/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_botan_missing/app.cpp new file mode 100644 index 00000000..b7b9e6c1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_botan_missing/app.cpp @@ -0,0 +1,24 @@ +// 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) + +// Hashes "abc" with Whirlpool on backends::botan: the program reads the canary of +// /third_party//botan, so that a library missing from the link, or built at another commit, fails +// to link with the canary's name (spec 5.4). + +#include +#include + +#include +#include + +int main() { + std::array const abc{0x61, 0x62, 0x63}; + std::array digest{}; + auto const done = + webcpp::hash::digest_of( + digest, abc); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_botan_missing/canary_botan_missing.outcome b/tools/test/fixtures/hash_jamfiles/canary_botan_missing/canary_botan_missing.outcome new file mode 100644 index 00000000..1a5997de --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_botan_missing/canary_botan_missing.outcome @@ -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) + +[all] +targets: native emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_botan_01af88c_configured__add_third_party_botan_to_your_link +[native-linux] +contains: webcpp_hash_botan_01af88c_configured__add_third_party_botan_to_your_link +contains: undefined reference to `webcpp_hash_botan_01af88c_configured__add_third_party_botan_to_your_link' +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_botan_01af88c_configured__add_third_party_botan_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/Jamfile new file mode 100644 index 00000000..a36b8bc7 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/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) + +exe app : app.cpp /webcpp/hash//hash /third_party//botan + : WEBCPP_HASH_BOTAN_CANARY_COMMIT=0000000 ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/app.cpp new file mode 100644 index 00000000..b7b9e6c1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/app.cpp @@ -0,0 +1,24 @@ +// 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) + +// Hashes "abc" with Whirlpool on backends::botan: the program reads the canary of +// /third_party//botan, so that a library missing from the link, or built at another commit, fails +// to link with the canary's name (spec 5.4). + +#include +#include + +#include +#include + +int main() { + std::array const abc{0x61, 0x62, 0x63}; + std::array digest{}; + auto const done = + webcpp::hash::digest_of( + digest, abc); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/canary_botan_other_commit.outcome b/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/canary_botan_other_commit.outcome new file mode 100644 index 00000000..02d087be --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_botan_other_commit/canary_botan_other_commit.outcome @@ -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) + +[all] +targets: native emscripten +build: fails +same-as: canary_botan_missing/app.cpp app.cpp +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_botan_0000000_configured__add_third_party_botan_to_your_link +[native-linux] +contains: webcpp_hash_botan_0000000_configured__add_third_party_botan_to_your_link +contains: undefined reference to `webcpp_hash_botan_0000000_configured__add_third_party_botan_to_your_link' +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_botan_0000000_configured__add_third_party_botan_to_your_link +contains: em++: error: 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 index afeb8522..2226fca1 100644 --- 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 @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: digests::whirlpool has no default backend, and no backend has it yet. +contains: webcpp::hash: digests::whirlpool has no default backend. Name one of: backends::botan. diff --git a/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.outcome b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.outcome index c66de0b6..b2d94df5 100644 --- a/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.outcome +++ b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: hkdf_extract and hkdf_expand are not in backends::bearssl, whose HKDF does both steps together: call hkdf, or name backends::hash2, backends::sodium or backends::openssl. +contains: webcpp::hash: hkdf_extract and hkdf_expand are not in backends::bearssl, whose HKDF does both steps together: call hkdf, or name backends::hash2, backends::sodium, backends::openssl or backends::botan. 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 index 543fff08..d4d0287c 100644 --- 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 @@ -10,6 +10,6 @@ [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. +contains: webcpp::hash: kdfs::kbkdf_hmac has no default backend. Name one of: backends::openssl, backends::botan. +contains: webcpp::hash: kdfs::sskdf has no default backend. Name one of: backends::openssl, backends::botan. +contains: webcpp::hash: kdfs::x963kdf has no default backend. Name one of: backends::openssl, backends::botan. 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 index 4628d6df..b78ab6ec 100644 --- 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 @@ -10,6 +10,6 @@ [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. +contains: webcpp::hash: kdfs::kbkdf_hmac is not in this backend. Name one of: backends::openssl, backends::botan. +contains: webcpp::hash: kdfs::sskdf is not in this backend. Name one of: backends::openssl, backends::botan. +contains: webcpp::hash: kdfs::x963kdf is not in this backend. Name one of: backends::openssl, backends::botan. diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp index 36e92327..32bda4d9 100644 --- a/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp @@ -14,6 +14,6 @@ int main() { std::array output{}; namespace hash = webcpp::hash; - auto done = hash::mac>(output, {}, {}); + auto done = hash::mac>(output, {}, {}); return done ? 0 : 1; } diff --git a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.outcome b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.outcome index 66b9833b..1ae758f6 100644 --- a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.outcome +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: pbkdf2 is not in backends::bearssl: BearSSL has no PBKDF2. The backends that have pbkdf2: backends::hash2 (every hmac) and backends::openssl (every hmac but hmac_ripemd_128). +contains: webcpp::hash: pbkdf2 is not in backends::bearssl: BearSSL has no PBKDF2. The backends that have pbkdf2: backends::hash2 (every hmac), backends::openssl (every hmac but hmac_ripemd_128) and backends::botan (every hmac but hmac_ripemd_128 and hmac_sha2_512_224). diff --git a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_on_sodium.outcome b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_on_sodium.outcome index 031900fc..53c91761 100644 --- a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_on_sodium.outcome +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_on_sodium.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: pbkdf2 is not in backends::sodium: libsodium has no PBKDF2. The backends that have pbkdf2: backends::hash2 (every hmac) and backends::openssl (every hmac but hmac_ripemd_128). +contains: webcpp::hash: pbkdf2 is not in backends::sodium: libsodium has no PBKDF2. The backends that have pbkdf2: backends::hash2 (every hmac), backends::openssl (every hmac but hmac_ripemd_128) and backends::botan (every hmac but hmac_ripemd_128 and hmac_sha2_512_224). 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 820a1b9d..d4e73b61 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp @@ -4,8 +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 and backends::openssl stops with spec section -// 3.3's text. +// scrypt on another backend than backends::sodium, backends::openssl and backends::botan 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 c33e2973..19a5a78b 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 and backends::openssl alone. Name one, and add /third_party//sodium or /webcpp/hash//openssl to the program's Jamfile. +contains: webcpp::hash: scrypt is in backends::sodium, backends::openssl and backends::botan alone. Name one, and add /third_party//sodium, /webcpp/hash//openssl or /third_party//botan to the program's Jamfile. diff --git a/tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_hmac.outcome b/tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_hmac.outcome index 9747cbbc..26f9fabe 100644 --- a/tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_hmac.outcome +++ b/tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_hmac.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium has HKDF over hmac_sha2_256 and hmac_sha2_512 alone. Over this hmac, name backends::hash2 (every hmac), backends::openssl (every hmac but hmac_ripemd_128) or backends::bearssl (MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512; hkdf alone). +contains: webcpp::hash: backends::sodium has HKDF over hmac_sha2_256 and hmac_sha2_512 alone. Over this hmac, name backends::hash2 (every hmac), backends::bearssl (MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512; hkdf alone), backends::openssl (every hmac but hmac_ripemd_128) or backends::botan (every hmac but hmac_ripemd_128 and hmac_sha2_512_224). diff --git a/tools/test/hash_allocation_collect_test.py b/tools/test/hash_allocation_collect_test.py index eb947f83..6897c132 100755 --- a/tools/test/hash_allocation_collect_test.py +++ b/tools/test/hash_allocation_collect_test.py @@ -10,8 +10,9 @@ 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.""" +taken and the data records the build and the toolset; backends::botan's records give one row per +operation and target; `--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 @@ -89,6 +90,53 @@ def test_an_output_built_at_variant_release_is_collected(scratch: Path) -> None: expect(run('--check', '--data', data, '--page', page), 0) +BOTAN_RECORDS = ( + 'record operation=counter c_counted=1\n' + 'record operation=digest_of tag=digests::md5 backend=botan target=native call=1 new=1 c=2 ' + 'counted=1\n' + 'record operation=digest_of tag=digests::md5 backend=botan target=native call=2 new=1 c=2 ' + 'counted=1\n' + 'record operation=digest_of tag=digests::sm3 backend=botan target=native call=1 new=4 c=13 ' + 'counted=1\n' + 'record operation=digest_of tag=digests::sm3 backend=botan target=native call=2 new=4 c=13 ' + 'counted=1\n' + 'record operation=argon2id tag=kdfs::argon2id backend=botan target=native call=1 new=6 c=9 ' + 'counted=1\n' + 'record operation=argon2id tag=kdfs::argon2id backend=botan target=native call=2 new=5 c=8 ' + 'counted=1\n' + 'record operation=scrypt tag=kdfs::scrypt backend=botan target=native call=1 new=3 c=0 ' + 'counted=0\n' + 'record operation=scrypt tag=kdfs::scrypt backend=botan target=native call=2 new=3 c=0 ' + 'counted=0\n' +) + + +def test_botan_s_records_give_one_row_per_operation(scratch: Path) -> None: + """backends::botan's records, one per call of each tag, become one row per operation and + target: the range over its tags, and a steady call's counts where they differ; a record whose + C library is not counted (MSVC's) says so; Botan's argon2id is not libsodium's.""" + base = (scratch / 'bin/libs/hash/bench/allocation_botan_release.test/clang-darwin-21/release' + / 'cxxstd-20-iso') + base.mkdir(parents=True) + (base / 'allocation_botan_release.output').write_text(BOTAN_RECORDS) + data, page = scratch / 'data.json', scratch / 'page.adoc' + page.write_text(PAGE.read_text()) + expect(run('--lane', f'native={scratch / "bin"}', '--data', data, '--page', page), 0) + table = page.read_text() + for row in ('| `digest_of` | `botan` | native | 1 to 4 | Botan: 2 to 13 C library calls ' + "(operator new's included), over its 2 algorithms; the same in a steady call", + '| `argon2id` | `botan` | native | 6 | Botan: 9 C library calls (operator ' + "new's included), of kdfs::argon2id; a steady call: 5 operator new, 8 C library " + 'calls', + '| `scrypt` | `botan` | native | 3 | Botan: C library not counted, of ' + 'kdfs::scrypt; the same in a steady call'): + if row not in table: + raise AssertionError(f'{row!r} is not in the table:\n{table}') + if '| `argon2id` | `sodium`' in table: + raise AssertionError(f"Botan's argon2id was rendered as libsodium's:\n{table}") + 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' @@ -117,6 +165,7 @@ def test_the_committed_data_is_from_release_builds_and_renders_the_page(scratch: 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_botan_s_records_give_one_row_per_operation, test_render_only_and_check_refuse_data_not_built_at_variant_release, test_the_committed_data_is_from_release_builds_and_renders_the_page, ] diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index ae39c7a2..cdbe6868 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -13,7 +13,8 @@ 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 that a -backend of the order hash2, xkcp, blake3, sodium has (one that none has, as kbkdf, has none). Every +backend of the order hash2, xkcp, blake3, sodium has (one that none has, as kbkdf, has none), or +with a default outside that order (bcrypt given botan, kbkdf given openssl). 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 without its cell fails; a partial cell says what it refuses. A tag of `digests` or `macs` @@ -238,6 +239,23 @@ def family_row(table: dict, name: str) -> dict: raise AssertionError(f'no row {name}') +def test_a_function_s_default_is_of_the_order(scratch: Path) -> None: + """No measurement or backend outside the order decides a function's default (designs D33 and + D34): bcrypt, which botan alone has, keeps none; given botan as its default, or kbkdf given + openssl, each is refused, as a family's tag is.""" + library = scratch_library(scratch) + + def outside_the_order(table: dict) -> None: + family_row(table, 'bcrypt')['default'] = 'botan' + family_row(table, 'kbkdf')['default'] = 'openssl' + edit_capabilities(library, outside_the_order) + done = run(library, '--write') + expect(done.returncode == 1, 'a function default outside the order was rendered') + expect('the function bcrypt has the default botan, which is not one of hash2, xkcp, blake3, ' + 'sodium' in done.stderr, done.stderr) + expect('the function kbkdf has the default openssl' in done.stderr, done.stderr) + + def test_a_family_default_is_of_the_order_or_none(scratch: Path) -> None: library = scratch_library(scratch) path = library / 'doc/capabilities.json' @@ -339,23 +357,24 @@ def test_llms_txt_s_defaults_are_the_table_s(scratch: Path) -> None: 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('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]) + expect('By default, hkdf_extract, hkdf_expand, hkdf and pbkdf2 run on backends::hash2 unless ' + 'the call names another of its backends as its second template argument; ' + 'blake2b_subkey runs on backends::sodium alone; kbkdf, sskdf and x963kdf have no ' + 'default backend, and the call names one of its backends as its second template ' + 'argument; argon2id and scrypt run on backends::sodium unless the call names another ' + 'of its backends as its only template argument; bcrypt and bcrypt_pbkdf have no ' + 'default backend, and the call names backends::botan 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') + family_row(table, 'scrypt')['backends'].pop('botan') edit_capabilities(library, scrypt_alone) llms = write_ok(library)['llms.txt'] 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]) + expect('; argon2id runs on backends::sodium unless the call names another of its backends 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: @@ -365,19 +384,19 @@ def test_a_backend_s_position_is_its_header_s(scratch: Path) -> None: 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 ' + '`botan`, `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 ' + '`botan`, `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 (<>).' + 'whatever the program links; `botan`, `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 ' + '`botan`, `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' @@ -387,11 +406,11 @@ def test_a_backend_s_position_is_its_header_s(scratch: Path) -> None: 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' + expect('`botan`, `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'], + expect('argon2id runs on backends::sodium unless the call names another of its backends as ' + 'its only template argument; scrypt runs on backends::sodium unless the call names ' + 'another of its backends 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') @@ -477,7 +496,12 @@ def test_each_backend_s_constant_time_sources_are_together(scratch: Path) -> Non 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)) + # A backend whose cells state two values (botan: "no" for Streebog and Whirlpool, "not + # stated" elsewhere) has one bullet for each. + stated = [line.split('.')[0] for line in + chapter.split("What each backend's upstream states, and where:")[1].splitlines() + if line.startswith('* ')] + expect(len(stated) == len(set(stated)), '\n'.join(stated)) 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-'): @@ -500,7 +524,7 @@ def test_an_asynchronous_backend_is_said(scratch: Path) -> None: 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('`bearssl`, `botan`, `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'] @@ -517,6 +541,27 @@ def test_an_asynchronous_backend_is_said(scratch: Path) -> None: expect('asynchronous family only' not in plain, 'a note without its field') +def test_an_exceptions_only_backend_is_said(scratch: Path) -> None: + # backends::botan has no cell in a build without exceptions (its "exceptions_only" field): + # every table and llms.txt name it with "with exceptions only", and without the field nothing + # does. + library = scratch_library(scratch) + files = write_ok(library) + backends = files['backends.adoc'] + expect('| botan\n| Botan 3.14.1' in backends, backends) + expect('| every function of its cells, with exceptions only' in backends, backends) + expect('| digests::whirlpool\n| botan (with exceptions only)' in backends, backends) + expect('botan, with exceptions only (/third_party//botan; ' in files['llms.txt'], + 'llms.txt does not say botan is with exceptions only') + table = json.loads((library / 'doc/capabilities.json').read_text(encoding='utf-8')) + for backend in table['backends']: + backend.pop('exceptions_only', None) + (library / 'doc/capabilities.json').write_text(json.dumps(table), encoding='utf-8') + plain = write_ok(library) + expect('with exceptions only' not in plain['backends.adoc'], 'a note without its field') + expect('with exceptions only' not in plain['llms.txt'], 'a note without its field') + + def test_without_measurements_the_tables_say_so(scratch: Path) -> None: library = scratch_library(scratch) files = write_ok(library) @@ -529,7 +574,7 @@ def test_without_measurements_the_tables_say_so(scratch: Path) -> None: 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('`bearssl`, `botan`, `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') expect('One backend, `hash2`: the types take no backend.' @@ -538,8 +583,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('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'], + expect('hkdf_extract, hkdf_expand, hkdf and pbkdf2 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') @@ -645,8 +690,10 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: 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_a_function_s_default_is_of_the_order, test_each_backend_s_constant_time_sources_are_together, test_an_asynchronous_backend_is_said, + test_an_exceptions_only_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, diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 25d0bb6e..b59a31f3 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -24,7 +24,12 @@ 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. BLAKE2's -test vectors are pinned. Run with the names of some cases to run only those.""" +test vectors are pinned. Botan, pinned, is configured by upstream's configure.py once per target, +shared by the variants, and compiled by b2 one object per source, its checkout left as it was; a +program hashes with it natively and on emscripten, and Botan's own test program passes its hash +tests; a Botan not checked out, a WASI toolset and a build without exceptions each stop the build +that needs it, with its message, and no other. Run with the names of some cases to run only +those.""" from __future__ import annotations @@ -911,6 +916,228 @@ def test_hash_not_checked_out_stops_blake3(root: Path) -> None: 'git submodule update --init libs/hash') +BOTAN = 'third_party/libs/botan' + +# Botan 3.14.1, the commit its tag names. +BOTAN_COMMIT = '01af88c039fcfaedc418b1af4d6d3a139674e591' + +# The library's sources tools/botan/modules.txt configures, on every target. +BOTAN_SOURCES = 208 + +# A program that hashes "abc" with Botan, under the project's warnings. +BOTAN_USER_SOURCE = r"""#include +#include + +#include + +int main() { + auto const hash = Botan::HashFunction::create_or_throw("SHA-256"); + hash->update("abc"); + std::cout << Botan::hex_encode(hash->final(), false) << "\n"; + return 0; +} +""" + +# SHA-256 of "abc", FIPS 180-4's example. +ABC_SHA256 = 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' + + +def add_botan_user(root: Path, targets: str = 'native emscripten') -> None: + """Adds the library botan_user, whose one test hashes "abc" with /third_party//botan.""" + harness.add_library(root, 'botan_user', ( + 'import webcpp ;\n\n' + f'webcpp.targets {targets} ;\n\n' + 'webcpp.run hashes_abc : hashes_abc.cpp : /third_party//botan ;\n'), + {'hashes_abc.cpp': BOTAN_USER_SOURCE}) + + +def botan_compiles(result: subprocess.CompletedProcess) -> list[str]: + """The compile lines of Botan's library sources b2 printed at -d+2.""" + return [line for line in result.stdout.splitlines() + if '-DBOTAN_IS_BEING_BUILT' in line and ' -c ' in line + and '/src/lib/' in line] + + +def expect_botan_checkout_unchanged() -> None: + status = subprocess.run(['git', '-C', str(harness.ROOT / BOTAN), 'status', '--porcelain'], + capture_output=True, text=True, check=True) + assert status.stdout == '', status.stdout + + +def botan_configurations(root: Path) -> list[Path]: + return sorted((root / 'bin/third_party/botan').glob('config-*[0-9a-f]')) + + +def test_botan_is_pinned(_: Path) -> None: + listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', BOTAN], + capture_output=True, text=True, check=True) + assert listed.stdout.split()[:2] == ['160000', BOTAN_COMMIT], listed.stdout + + +def test_botan_is_built_object_by_object(root: Path) -> None: + add_botan_user(root) + result = harness.run_b2(root, '-n', '-a', '-d+2', 'libs/botan_user/test') + harness.expect(result, True) + compiles = botan_compiles(result) + assert len(compiles) == BOTAN_SOURCES, (len(compiles), result.stdout[-4000:]) + configurations = botan_configurations(root) + assert len(configurations) == 1, configurations + configuration = configurations[0].resolve().as_posix() + objects = set() + for line in compiles: + for directory in ('public', 'internal'): + assert f'{configuration}/build/include/{directory}' in line, (directory, line) + found = re.search(r' -o "?([^" ]+\.o)"?', line) + assert found is not None, line + objects.add(found.group(1)) + assert len(objects) == BOTAN_SOURCES, len(objects) + archives = [line for line in result.stdout.splitlines() + if re.search(r'\bar\b|libtool', line) and 'libbotan' in line] + assert archives, result.stdout[-4000:] + expect_botan_checkout_unchanged() + + +def botan_hash_canary() -> str: + prefix = '_' if sys.platform == 'darwin' else '' + return f'{prefix}webcpp_hash_botan_01af88c_configured__add_third_party_botan_to_your_link' + + +def test_botan_carries_hashs_canary(root: Path) -> None: + # With libs/hash checked out, /third_party//botan compiles webcpp::hash's canary with Botan's + # own properties (its configured build.h: configured), beside the 208 sources, and gives a + # program WEBCPP_HASH_HAS_BOTAN. + harness.copy_integration_libraries(root, 'config', 'hash') + add_botan_user(root) + result = harness.run_b2(root, '-a', '-d+2', 'libs/botan_user/test') + harness.expect(result, True) + assert len(botan_compiles(result)) == BOTAN_SOURCES, result.stdout[-4000:] + canary = [line for line in result.stdout.splitlines() + if 'canary_botan.cpp' in line and ' -c ' in line] + assert len(canary) == 1, canary + assert '-DBOTAN_IS_BEING_BUILT' in canary[0], canary[0] + user = [line for line in result.stdout.splitlines() + if 'hashes_abc.cpp' in line and ' -c ' in line] + assert len(user) == 1 and '-DWEBCPP_HASH_HAS_BOTAN=1' in user[0], user + archive = sorted((root / 'bin').rglob('libbotan.a')) + assert len(archive) == 1, archive + symbols = subprocess.run(['nm', str(archive[0])], capture_output=True, text=True, check=True) + assert botan_hash_canary() in symbols.stdout.split(), symbols.stdout[-2000:] + expect_botan_checkout_unchanged() + + +def test_botan_without_hash_has_no_canary(root: Path) -> None: + # A checkout without libs/hash builds Botan as before: its 208 sources, no canary, no define. + add_botan_user(root) + result = harness.run_b2(root, '-n', '-a', '-d+2', 'libs/botan_user/test') + harness.expect(result, True) + assert len(botan_compiles(result)) == BOTAN_SOURCES, result.stdout[-4000:] + assert 'canary_botan' not in result.stdout, result.stdout[-4000:] + assert 'WEBCPP_HASH_HAS_BOTAN' not in result.stdout, result.stdout[-4000:] + + +def test_botan_vectors_target(root: Path) -> None: + # /third_party//botan_vectors gives a program Botan's src/tests/data at the pin, by its + # define, and the files webcpp::hash reads are there. + harness.add_library(root, 'botan_data', ( + 'import webcpp ;\n\n' + 'webcpp.targets native ;\n\n' + 'webcpp.run reads : reads.cpp : /third_party//botan_vectors ;\n'), + {'reads.cpp': '#include \n\nint main() {\n' + ' std::ifstream in(WEBCPP_TEST_BOTAN_VECTORS "/hash/whirlpool.vec");\n' + ' std::ifstream skein(WEBCPP_TEST_BOTAN_VECTORS "/hash/skein.vec");\n' + ' return in && skein ? 0 : 1;\n}\n'}) + result = harness.run_b2(root, '-a', 'libs/botan_data/test') + harness.expect(result, True) + assert '**passed**' in result.stdout, result.stdout[-4000:] + + +def test_botan_runs_natively(root: Path) -> None: + add_botan_user(root) + result = harness.run_b2(root, '-a', 'libs/botan_user/test') + harness.expect(result, True) + assert passed(result) == {'hashes_abc'}, (passed(result), result.stdout[-4000:]) + assert output_of(root, 'hashes_abc.output').splitlines()[0] == ABC_SHA256 + expect_botan_checkout_unchanged() + + +def test_botan_runs_on_emscripten(root: Path) -> None: + harness.link_emsdk(root) + add_botan_user(root) + result = harness.run_b2(root, '-a', *EMSCRIPTEN, 'libs/botan_user/test') + harness.expect(result, True) + assert passed(result) == {'hashes_abc'}, (passed(result), result.stdout[-4000:]) + assert output_of(root, 'hashes_abc.output').splitlines()[0] == ABC_SHA256 + + +def test_botan_configuration_is_shared(root: Path) -> None: + add_botan_user(root) + result = harness.run_b2(root, '-n', '-a', '-d+2', 'variant=debug,release', + 'libs/botan_user/test') + harness.expect(result, True) + assert len(botan_configurations(root)) == 1, botan_configurations(root) + compiles = botan_compiles(result) + objects = {found.group(1) for line in compiles + if (found := re.search(r' -o "?([^" ]+\.o)"?', line))} + assert len(compiles) == len(objects) == 2 * BOTAN_SOURCES, (len(compiles), len(objects)) + for variant in ('debug', 'release'): + assert sum(f'/{variant}/' in path for path in objects) == BOTAN_SOURCES, variant + + +def test_botan_not_checked_out_is_refused(root: Path) -> None: + harness.third_party_of_its_own(root, 'botan', checked_out=False) + result = harness.run_b2(root, 'third_party//botan') + harness.expect(result, False, 'third_party/libs/botan is not checked out: it holds no ' + 'configure.py. Check it out with `git submodule update --init ' + 'third_party/libs/botan`.') + # A build that needs no Botan never looks for it. + harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) + + +def expect_botan_refused_on_wasi(root: Path, request: tuple[str, ...], target: str) -> None: + add_botan_user(root, 'native wasip2 wasip3 emscripten') + result = harness.run_b2(root, *request, 'libs/botan_user/test') + harness.expect(result, False, '/third_party//botan is built natively and for Emscripten. ' + f'On clang-{target} it is not built yet: webcpp::crypto\'s increment 7 ' + 'decides it. Remove /third_party//botan from this program\'s Jamfile, or ' + 'build it natively or with toolset=emscripten.') + harness.expect(harness.run_b2(root, *request, 'libs/demo/test//pass'), True) + + +def test_botan_on_wasip2_is_refused(root: Path) -> None: + expect_botan_refused_on_wasi(root, WASIP2, 'wasip2') + + +def test_botan_on_wasip3_is_refused(root: Path) -> None: + expect_botan_refused_on_wasi(root, WASIP3, 'wasip3') + + +def test_botan_without_exceptions_is_refused(root: Path) -> None: + result = harness.run_b2(root, 'exception-handling=off', 'third_party//botan') + harness.expect(result, False, '/third_party//botan needs exceptions: Botan reports its ' + 'errors by throwing. Build this program with exception-handling=on, or ' + 'remove /third_party//botan from its Jamfile.') + harness.expect(harness.run_b2(root, 'exception-handling=off', 'libs/demo/test//pass'), True) + + +def test_botan_on_an_unknown_target_is_refused(root: Path) -> None: + result = harness.run_b2(root, 'target-os=freebsd', 'third_party//botan') + harness.expect(result, False, "/third_party//botan: Botan's configuration is known for clang " + 'and gcc on macOS and Linux, MSVC on Windows and Emscripten; this request is ' + 'clang on freebsd.') + + +def test_botan_test_program_runs(root: Path) -> None: + result = harness.run_b2(root, '-a', 'third_party//botan_test') + harness.expect(result, True) + programs = [path for path in (root / 'bin').rglob('botan_test') + if path.is_file() and os.access(path, os.X_OK)] + assert len(programs) == 1, programs + run = subprocess.run([str(programs[0]), f'--data-dir={harness.ROOT / BOTAN}/src/tests/data', + 'hash'], capture_output=True, text=True, timeout=harness.TIMEOUT) + assert run.returncode == 0, (run.stdout[-4000:], run.stderr[-4000:]) + assert 'all tests ok' in run.stdout, run.stdout[-4000:] + + CASES = [ test_the_suite_is_pinned, test_wycheproof_is_pinned, @@ -959,6 +1186,20 @@ def test_hash_not_checked_out_stops_blake3(root: Path) -> None: test_blake3_on_emscripten_is_portable, test_blake3_not_checked_out_is_refused, test_hash_not_checked_out_stops_blake3, + test_botan_is_pinned, + test_botan_is_built_object_by_object, + test_botan_carries_hashs_canary, + test_botan_without_hash_has_no_canary, + test_botan_vectors_target, + test_botan_runs_natively, + test_botan_runs_on_emscripten, + test_botan_configuration_is_shared, + test_botan_not_checked_out_is_refused, + test_botan_on_wasip2_is_refused, + test_botan_on_wasip3_is_refused, + test_botan_without_exceptions_is_refused, + test_botan_on_an_unknown_target_is_refused, + test_botan_test_program_runs, ] diff --git a/tools/webcpp-botan.jam b/tools/webcpp-botan.jam new file mode 100644 index 00000000..fbaf1b92 --- /dev/null +++ b/tools/webcpp-botan.jam @@ -0,0 +1,283 @@ +# 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) + +# Botan, configured by upstream and compiled by b2 (CODING-GUIDELINES.md +# chapter 5, rule 13): /third_party//botan and its test program, botan_test. +# +# Botan's own configure.py chooses the modules (tools/botan/modules.txt) and +# writes build.h, the configured headers and the list of sources of a target +# into the directory of its configuration, bin/third_party/botan/config-, +# named, as OpenSSL's is (tools/webcpp-third-party.jam), by the key of the +# inputs declare is given and by the values of its command line: --os, --cc +# and --cpu. tools/botan/configure.py runs it, at b2's generation, once per +# configuration and b2 run, and does nothing for a directory that is +# complete. b2 then compiles each listed source as an object of its own, in +# the consumer's variant directory, with the consumer's properties (toolset, +# variant, cxxstd, runtime, threading, exceptions): two consumers that differ +# in them share one configuration and get two sets of objects. Nothing of +# upstream's compile flags is used, except, on MSVC, the three language flags +# that change no ABI. The configured headers exist before b2 scans a source. + +import configure ; +import errors ; +import feature ; +import modules ; +import path ; +import project ; +import targets ; +import virtual-target ; +import webcpp-target ; +import webcpp-third-party ; + +class botan-target : basic-target +{ + import generators ; + import modules ; + import property-set ; + + rule construct ( name : source-targets * : properties ) + { + local configured = [ modules.call-in webcpp-botan : configuration + $(properties) : $(self.project) ] ; + local directory = $(configured[1]) ; + local sources = [ modules.call-in webcpp-botan : sources $(directory) + : lib : $(self.project) ] ; + local built = [ property-set.create [ $(properties).raw ] + LIB + [ modules.call-in webcpp-botan : compile-properties $(directory) ] ] ; + local result = [ generators.construct $(self.project) $(name) : LIB + : $(built) : $(sources) $(source-targets) : true ] ; + if ! $(result) + { + return ; + } + return [ $(result[1]).add-raw [ modules.call-in webcpp-botan : usage + $(directory) : $(properties) ] ] $(result[2-]) ; + } +} + +class botan-test-target : basic-target +{ + import generators ; + import modules ; + import property-set ; + + rule construct ( name : source-targets * : properties ) + { + local configured = [ modules.call-in webcpp-botan : configuration + $(properties) : $(self.project) ] ; + local directory = $(configured[1]) ; + local sources = [ modules.call-in webcpp-botan : sources $(directory) + : test : $(self.project) ] ; + local built = [ property-set.create [ $(properties).raw ] + EXE + [ modules.call-in webcpp-botan : compile-properties $(directory) ] ] ; + return [ generators.construct $(self.project) $(name) : EXE : $(built) + : $(sources) $(source-targets) : true ] ; + } +} + +# Declares botan and botan_test in the current project: the checkout of +# third_party/libs/botan under root, configured per target and compiled object +# by object, and Botan's own test program linked with it. inputs, relative to +# root, are the files whose bytes make a configuration what it is, the key of +# its directory. requirements and usage-requirements are added to the +# library's own: a webcpp library's canary, as a conditional , and its +# define, as a conditional usage requirement. The provisioning carries none. +rule declare ( root : inputs * : requirements * : usage-requirements * ) +{ + .root = $(root) ; + .inputs = $(inputs) ; + local own = + static off off + # Every function and datum in a section of its own, as the C + # libraries of third_party/Jamfile are compiled, so that a program + # keeps only what it calls. + clang:"-ffunction-sections -fdata-sections" + gcc:"-ffunction-sections -fdata-sections" + emscripten:"-ffunction-sections -fdata-sections" + msvc:"/Gy /Gw" + # Upstream's MSVC language flags that change no ABI; /EHs and /GR + # are b2's exception-handling and rtti. + msvc:"/Zc:preprocessor /Zc:inline /bigobj" ; + # The linker's removal of unused sections, and, on Emscripten, a memory + # that grows: Argon2, scrypt and RSA outgrow the fixed 16 MiB. + local usage = + darwin:-Wl,-dead_strip + linux:-Wl,--gc-sections + windows:"/OPT:REF" + emscripten:-sALLOW_MEMORY_GROWTH=1 ; + local project = [ project.current ] ; + targets.create-metatarget botan-target : $(project) : botan + : : $(own) $(requirements) : : $(usage) $(usage-requirements) ; + # Botan's own test program reads its data directory (--data-dir) from the + # host: on Emscripten node gives it the host's file system, and the + # program's status is main's. + local test-own = + emscripten:-sNODERAWFS=1 + emscripten:-sEXIT_RUNTIME=1 ; + targets.create-metatarget botan-test-target : $(project) : botan_test + : botan : $(own) $(test-own) : ; +} + +# The values of the command line of tools/botan/configure.py for properties, +# --os, --cc and --cpu, after the stops of a request Botan is not configured +# for. +rule command-values ( properties * ) +{ + local checkout = $(.root)/third_party/libs/botan ; + if ! [ path.exists [ path.native $(checkout)/configure.py ] ] + { + errors.user-error "third_party/libs/botan is not checked out: it holds no" + "configure.py. Check it out with `git submodule update --init" + "third_party/libs/botan`." ; + } + local target = [ webcpp-target.target-of $(properties) ] ; + if $(target) in wasip2 wasip3 + { + errors.user-error "/third_party//botan is built natively and for Emscripten. On" + "clang-$(target) it is not built yet: webcpp::crypto's increment 7 decides it." + "Remove /third_party//botan from this program's Jamfile, or build it natively" + "or with toolset=emscripten." ; + } + if [ feature.get-values : $(properties) ] = off + { + errors.user-error "/third_party//botan needs exceptions: Botan reports its errors" + "by throwing. Build this program with exception-handling=on, or remove" + "/third_party//botan from its Jamfile." ; + } + if $(target) = emscripten + { + return emscripten emcc wasm ; + } + local toolset = [ feature.get-values : $(properties) ] ; + local system = [ feature.get-values : $(properties) ] ; + switch $(toolset:E=none)-$(system:E=none) + { + case clang-darwin : return macos clang [ architecture $(properties) ] ; + case clang-linux : return linux clang [ architecture $(properties) ] ; + case gcc-darwin : return macos gcc [ architecture $(properties) ] ; + case gcc-linux : return linux gcc [ architecture $(properties) ] ; + case msvc-windows : return windows msvc [ architecture $(properties) ] ; + } + errors.user-error "/third_party//botan: Botan's configuration is known for clang and" + "gcc on macOS and Linux, MSVC on Windows and Emscripten; this request is" + "$(toolset:E=no toolset) on $(system:E=no target-os)." ; +} + +# The architecture a native build is for, as Botan's --cpu names it: +# with when the request names both; else the +# compiler is asked, through third_party/Jamfile's probes, which compile only +# when the compiler's own macros say x86-64 (__x86_64__, _M_X64) or arm64 +# (__aarch64__, _M_ARM64), since b2 sets neither feature on a native toolset +# unless the request does; else generic, Botan's portable code, which is what +# every configuration compiles: --minimized-build loads no instruction-set +# module. +rule architecture ( properties * ) +{ + local architecture = [ feature.get-values : $(properties) ] ; + local model = [ feature.get-values : $(properties) ] ; + if $(architecture) && $(model) + { + switch $(architecture)-$(model) + { + case x86-64 : return x86_64 ; + case arm-64 : return arm64 ; + } + return generic ; + } + if [ configure.builds /webcpp/third_party//blake3_probe_x86_64 : $(properties) + : "Botan's compiler targets x86-64" ] + { + return x86_64 ; + } + if [ configure.builds /webcpp/third_party//blake3_probe_arm64 : $(properties) + : "Botan's compiler targets arm64" ] + { + return arm64 ; + } + return generic ; +} + +# The directory of the configuration of ps, a property set, in project, made +# by tools/botan/configure.py unless it is complete, once per b2 run; its +# sources are then those of sources. +rule configuration ( ps : project ) +{ + local values = [ command-values [ $(ps).raw ] ] ; + local key = [ webcpp-third-party.inputs-key $(.root) : botan + : third_party/libs/botan : $(.inputs) ] ; + local directory = [ webcpp-third-party.directory $(project) : botan + : $(key) --os=$(values[1]) --cc=$(values[2]) --cpu=$(values[3]) ] ; + if ! $(.configured.$(directory)) + { + local script = [ path.native $(.root)/tools/botan/configure.py ] ; + local checkout = [ path.native $(.root)/third_party/libs/botan ] ; + local modules = [ path.native $(.root)/tools/botan/modules.txt ] ; + local output = [ path.native $(directory) ] ; + local command = python3 \"$(script)\" --source \"$(checkout)\" + --modules \"$(modules)\" --output \"$(output)\" + --os $(values[1]) --cc $(values[2]) --cpu $(values[3]) ; + local result = [ SHELL $(command:J=" ") : exit-status ] ; + if $(result[2]) != 0 + { + errors.user-error "Botan's configuration for --os=$(values[1])" + "--cc=$(values[2]) --cpu=$(values[3]) failed:" $(result[1]) ; + } + for local line in [ SPLIT_BY_CHARACTERS $(result[1]) : "\r\n" ] + { + local kind = [ MATCH "^(lib|test) " : $(line) ] ; + .$(kind).$(directory) += [ MATCH "^[a-z]+ (.*)$" : $(line) ] ; + } + .configured.$(directory) = true ; + } + return $(directory) ; +} + +# The virtual targets of the sources of kind, lib or test, of the +# configuration in directory, files of the checkout, in project. +rule sources ( directory : kind : project ) +{ + local checkout = $(.root)/third_party/libs/botan ; + local result ; + for local source in $(.$(kind).$(directory)) + { + result += [ virtual-target.from-file $(source) : $(checkout) : $(project) ] ; + } + return $(result) ; +} + +# What compiles a source of Botan's in the configuration in directory: +# upstream's define and its two include directories, the public and the +# internal. +rule compile-properties ( directory ) +{ + return BOTAN_IS_BEING_BUILT $(directory)/build/include/public + $(directory)/build/include/internal ; +} + +# What a consumer of the configuration in directory gets: its public include +# directory, whose headers are system ones, so that Botan's warnings are never +# webcpp's. GCC takes a directory given both ways, -I and -isystem, for a +# system one; clang and emcc keep the -I and mark the headers +# names; MSVC searches /external:I directories as external, under +# /external:W0. Each quoted as the Jamroot quotes Boost's, for a path that +# holds a space. +rule usage ( directory : ps ) +{ + local public = $(directory)/build/include/public ; + local result = $(public) ; + switch [ $(ps).get ] + { + case gcc : result += "-isystem\"$(public)\"" ; + case clang : result += "--system-header-prefix=\"botan/\"" ; + case emscripten : result += "--system-header-prefix=\"botan/\"" ; + case msvc : + local native = [ path.native $(public) ] ; + result += "/external:I\"$(native)\"" "/external:W0" ; + } + return $(result) ; +}