diff --git a/.gitmodules b/.gitmodules index 70b989a1..9748bccc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -85,3 +85,7 @@ [submodule "libs/webrtc"] path = libs/webrtc url = ../webrtc.git +[submodule "third_party/libs/blake2"] + path = third_party/libs/blake2 + url = https://github.com/BLAKE2/BLAKE2.git + shallow = true diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 47681932..cce79aa6 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -347,9 +347,9 @@ exactly its authors' and the program carries only what it calls. stubs other files call. A single unity source is not used. Three exceptions, each recorded in its row of chapter 10: BLAKE3's intrinsics files compile on their instruction sets alone, each flagged for its own set; XKCP is built - from the one file of Keccak-p[1600] the library calls (and the high-level - files increment 3 of webcpp::hash lists), not from every file of its - package; libsodium is built without its `.S` files. + from the one file of Keccak-p[1600] and the five high-level files + webcpp::hash's adapter calls, not from every file of its package; + libsodium is built without its `.S` files. 3. Every file is compiled with `-ffunction-sections -fdata-sections` (`/Gy /Gw` on MSVC); upstream's warnings are not webcpp's (`off`); each define the library cannot work out for itself on a target sits beside the @@ -958,6 +958,7 @@ update --init third_party/libs/`; a build that needs none never looks. | --- | --- | --- | | `bearssl` | BearSSL from webcpp's unmodified mirror `webcpporg/bearssl` at `7bea48e`; a static library built file by file by `third_party/Jamfile` with webcpp::crypto's and webcpp::hash's canaries (hash's when `libs/hash` is checked out), on every target; `WEBCPP_CRYPTO_HAS_BEARSSL=1`, and `WEBCPP_HASH_HAS_BEARSSL=1` with hash's canary | MIT | | `bips` | `bitcoin/bips` at `927b6de9`, shallow, test data: crypto's tests read BIP340's `bip-0340/test-vectors.csv` and BIP341's `bip-0341/wallet-test-vectors.json` at run time under the directory its define `WEBCPP_TEST_BIPS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | BSD-2-Clause, as BIP340's header states | +| `blake2_vectors` | BLAKE2's reference code package `BLAKE2/BLAKE2` at `ed1974e` (2023-02-12), the submodule `third_party/libs/blake2`, shallow, test data that nothing compiles: hash's tests read `testvectors/blake2b-kat.txt` and `testvectors/blake2-kat.json` at run time under the directory its define `WEBCPP_TEST_BLAKE2_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of them changes | CC0-1.0 | | `blake3` | BLAKE3 1.8.7 at `f3149ec`; `third_party/Jamfile` compiles `c/blake3.c`, `blake3_dispatch.c` and `blake3_portable.c` on every target, the intrinsics files on their instruction sets alone (an exception to chapter 5 rule 2), with webcpp::hash's canary; `WEBCPP_HASH_HAS_BLAKE3=1` | CC0-1.0, Apache-2.0, or Apache-2.0 with LLVM exception | | `blake3_vectors` | BLAKE3's official vectors, `test_vectors/test_vectors.json` of the submodule `third_party/libs/blake3` at `f3149ec`, test data: hash's tests read it at run time under the directory its define `WEBCPP_TEST_BLAKE3_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | CC0-1.0, Apache-2.0, or Apache-2.0 with LLVM exception | | `ca_certificates` | Dated Mozilla/curl CA data snapshot under `third_party/ca_certificates`, verified against its manifest and embedded by a build-generated header; updated explicitly by `tools/ca_certificates/update.py` | MPL-2.0 | @@ -968,8 +969,9 @@ update --init third_party/libs/`; a build that needs none never looks. | `openssl` | OpenSSL 3.5.9 at `45e844fa2a14ec92d146bd8f5778ac130b6625fb`; static libssl/libcrypto and matching generated headers, built by upstream Configure/Make through B2 for native Clang/GCC/MSVC, WASIp2 single and WASIp3 single/cooperative | Apache-2.0 | | `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT | | `sodium` | libsodium 1.0.22 at `77e1ce5`, the submodule `third_party/libs/libsodium`; a static library built file by file by `third_party/Jamfile` (every `.c` of `src/libsodium/`, no assembly, the defines libsodium's configure finds on each target, upstream's `builds/msvc/version.h` copied into the build directory) with webcpp::hash's canary, on every target; `WEBCPP_HASH_HAS_SODIUM=1`; `sodium-test-config` gives a program its private headers and test defines; shared with webcpp::crypto | ISC | +| `sodium_vectors` | libsodium's own tests' expected outputs, `test/default/*.exp` of the submodule `third_party/libs/libsodium` at `77e1ce5`, test data: hash's tests read `generichash3.exp`, `kdf.exp`, `pwhash_argon2i.exp`, `shorthash.exp` and `siphashx24.exp` at run time under the directory its define `WEBCPP_TEST_SODIUM_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | ISC | | `wycheproof` | C2SP's Wycheproof at `12fd3aaf` (2026-10-06), shallow, test data: crypto's tests read its `testvectors_v1/` at run time under the directory its define `WEBCPP_TEST_WYCHEPROOF` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of its files changes | Apache-2.0 | -| `xkcp` | XKCP (the Keccak team's code package) at `d20c8fc` (2026-11-10, no release tags); `third_party/Jamfile` compiles its `KeccakP-1600-opt64.c` alone (Keccak-p[1600], the generic64 profile) with webcpp::hash's adapter, `config.h` and canary, on every target; `WEBCPP_HASH_HAS_XKCP=1` | CC0; `brg_endian.h` under Brian Gladman's terms | +| `xkcp` | XKCP (the Keccak team's code package) at `d20c8fc` (2026-11-10, no release tags); `third_party/Jamfile` compiles its `KeccakP-1600-opt64.c` (Keccak-p[1600], the generic64 profile) and the high-level files over it, `KeccakSponge.c`, `KeccakHash.c` (FIPS 202), `SP800-185.c`, `TurboSHAKE.c` and `KangarooTwelve.c` (serial: no times-N permutation), with webcpp::hash's adapter, `config.h` (`XKCP_has_KeccakP1600`, `_Sponge_Keccak`, `_TurboSHAKE`, `_FIPS202`, `_SP800_185`, `_KangarooTwelve`) and canary, on every target; `WEBCPP_HASH_HAS_XKCP=1` | CC0; `brg_endian.h` under Brian Gladman's terms | OpenSSL builds from a checkout or a source distribution. Before Configure, its builder stages the distributable tree and checks a digest of paths, Git file @@ -9142,7 +9144,7 @@ summary. `organization/openspec/changes/site-increments-4-5/specs/site/spec.md` (proposals). -### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increment 1 built, not merged) +### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, increments 1, 2, 3, 4, 5 and 7 built, not merged) webcpp::hash is one entry point for hashing and key derivation in a C++20 program on every target webcpp has, a wrapper (`"port-of": null`). Increment 1 @@ -9150,21 +9152,40 @@ is built on the library's branch (`libs/hash`, to become `webcpporg/hash`): Boost.Hash2's algorithms and `hmac` re-exported by alias (`algorithms.hpp`, `hmac.hpp`); Keccak-256 with the original padding over XKCP's permutation (`keccak.hpp`) and BLAKE3 over its official C implementation (`blake3.hpp`), -both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 -(RFC 8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and -`openssl` (`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and -scrypt (RFC 7914, `scrypt.hpp`) from libsodium; the profile and the default -backend (`config.hpp`), the capability table (`doc/capabilities.json`), and -the measured table (`doc/measurements*.json`, regenerated by the `measure` -lane). The C libraries are built by `third_party/Jamfile` (`xkcp`, `blake3`, -`sodium`, `bearssl`, each with a canary), their own suites by the `c-suites` -lane (`test/c_suites`), the examples are in `example/` and the documentation -in `doc/`. Every function is synchronous, reports failure as a -`boost::system::result`, takes its data as `std::span` and allocates nothing in -webcpp's own code. Its repository, `webcpporg/hash`, is still to be created by -the owner (gates G1, G2 and G4); the proposal, with the specification, the -design and the plan, is in `libraries/hash/openspec/changes/genesis/` -(proposals). +both in Hash2's HashAlgorithm form; HKDF (RFC 5869, `hkdf.hpp`) and PBKDF2 (RFC +8018, `pbkdf2.hpp`) on the backends `hash2`, `sodium`, `bearssl` and `openssl` +(`backends/`); Argon2id (RFC 9106, parallelism 1, `argon2.hpp`) and scrypt (RFC +7914, `scrypt.hpp`) from libsodium; the default backend (`config.hpp`), the +capability table (`doc/capabilities.json`), and the measured table +(`doc/measurements*.json`), a dated reference of 2026-11-16 that decides +nothing. The families `digest_of`, `hasher`, `mac` and `argon2` take the tags of +`digests`, `macs` and `kdfs`; increment 2 gives them libsodium's whole surface: +BLAKE2b with its key, salt, personalisation and length, SipHash-2-4 and +SipHash-2-4x, BLAKE2b subkeys (`blake2b_subkey.hpp`), SHA-2, SHA-3, SHAKE, +TurboSHAKE, HMAC, and Argon2i and Argon2id with one lane; increment 3 gives them +XKCP's surface: Keccak-224 to Keccak-512, SHA-3, SHAKE, SP 800-185's cSHAKE, +KMAC, TupleHash and ParallelHash, and RFC 9861's KangarooTwelve and TurboSHAKE; +increment 4 gives them OpenSSL's surface, each reached only by naming +`backends::openssl` (native, wasip2 and wasip3): MD5, SHA-1, SHA-2, SHA-3, +SHAKE, Keccak-224 to Keccak-512, BLAKE2, RIPEMD-160, TLS 1.0's MD5-SHA1 and +SM3; HMAC, KMAC, keyed BLAKE2 and SipHash; scrypt, and Argon2d, Argon2i and +Argon2id with every parameter of RFC 9106; and the key derivations of +standards (`kdf_standards.hpp`), SP 800-108's KBKDF, SP 800-56C's one-step KDF +and ANSI X9.63's KDF, which have no default backend; 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 +`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 +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` +included): the password hashes and PBKDF2 on a thread pool where the build has +threads, the digests, HMAC and HKDF through a post, and `backends::webcrypto`, +the browser's WebCrypto on Emscripten, which only that family takes. Its +repository, `webcpporg/hash`, is still to be created by the owner (gates G1, G2 +and G4); the proposal, with the specification, the design and the plan, is in +`libraries/hash/openspec/changes/genesis/` (proposals). - **Two constructions of webcpp's own, over an audited primitive each, and no primitive.** HKDF and PBKDF2 over Boost.Hash2's `hmac` on every target, @@ -9176,13 +9197,15 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` writes no cryptography of its own, as the owner recorded on 2026-11-14. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.3 (proposals). -- **The key derivation functions have backends, as webcpp::crypto's - algorithms do, and a backend that lacks a function refuses at compile - time.** `backends::hash2`, `sodium`, `bearssl` and `openssl` (native, - wasip2 and wasip3); natively the fastest linked backend is the default, on - WebAssembly the one that gives the smallest binary, decided by a measured - table that every pin move regenerates; one setting in `config.hpp` (a - profile) changes every default at once. +- **The key derivation functions and the families have backends, as + webcpp::crypto's algorithms do, and a backend that lacks a function or a tag + refuses at compile time.** `backends::hash2`, `xkcp`, `blake3`, `sodium`, + `bearssl` and `openssl`, and `webcrypto` for the asynchronous family alone; + the default is one stated rule, the same on every target and fixed (designs + D33 and D34): the first of `hash2`, `xkcp`, `blake3` and `sodium` that has the + algorithm whole, else the first of them with a partial cell, else none (the + call names its backend); `bearssl`, `openssl`, `botan` and `webcrypto` are + never a default. No measurement decides it. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.4 (proposals). - **The C libraries of hash (`xkcp`, `blake3`, `sodium`) are built file by @@ -9194,10 +9217,18 @@ design and the plan, is in `libraries/hash/openspec/changes/genesis/` Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 5 (proposals). - **Seven increments, each usable alone.** The first, built, is Hash2 by alias, - `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the profile and the - measured table; the next ones widen the backends' surface (libsodium's, - XKCP's, OpenSSL's, BearSSL's, Botan's) and add the browser backend over - WebCrypto through a parallel asynchronous family. + `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the default backend + and the measured table; the second, built, is the families and libsodium's + whole surface; the third, built, is XKCP's whole surface through the families; + the fourth, built, is OpenSSL's whole surface through the families and the key + 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 + 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/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index ec939e33..0e96ec85 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -285,8 +285,9 @@ could not read and dropped, such as one naming a header that does not exist. * Added ctaes, Bitcoin Core's constant-time AES at v31.1, built from source as /third_party//ctaes, and the fixtures of the user's Jamfiles of webcpp::crypto's block cipher and signing programs. -* Added XKCP's Keccak-p[1600], built from source with webcpp::hash's adapter as -`/third_party//xkcp`. +* Added XKCP's Keccak-p[1600] and its sponge, FIPS 202, SP 800-185, TurboSHAKE and +KangarooTwelve files, built from source with webcpp::hash's adapter as `/third_party//xkcp`, its +test vectors as `/third_party//xkcp_vectors`. * Added libsodium 1.0.22, built from source as /third_party//sodium with the defines its own configure finds on each target, and /third_party//sodium-test-config for a program that compiles against its private headers. @@ -311,6 +312,28 @@ webcpp::hash's and webcpp::crypto's OpenSSL, when libs/hash is checked out. llms.txt from its capability table and measurements, and checks them when its page is built. * Changed tools/hash/doc_tables.py to give each chapter two comparison tables, each under the eight columns from which a table scrolls. +* Changed tools/hash/doc_tables.py to render webcpp::hash's family tags (digest_of, hasher, mac, +argon2): a default of hash2, xkcp, blake3 or sodium, or none, and what a partial cell refuses. +* Fixed tools/hash/doc_tables.py naming, beside a default, backends of functions that do not +share it, calling a tag without a default a type, and scattering constant-time statements. +* Fixed tools/hash/doc_tables.py's llms.txt calling backends::sodium the only backend of +argon2id and scrypt, which backends::openssl has too. +* Changed tools/hash/doc_tables.py to render a function without a default backend, as kbkdf, +sskdf and x963kdf on backends::openssl alone, and to refuse one a backend of the order has. +* Added /third_party//openssl_evp_data, OpenSSL's EVP test files at the pin, which webcpp::hash's +tests read at run time on every target. +* Added /third_party//blake2_vectors, BLAKE2's test vectors at ed1974e (a shallow submodule), and +/third_party//sodium_vectors, libsodium's test outputs, which webcpp::hash's tests read at run time. +* Changed tools/test/hash_jamfiles_test.py to copy libs/asio into its scratch superproject, so that +the messages of webcpp::hash's asynchronous family are built on Emscripten too. +* Changed tools/hash/doc_tables.py to render a backend of webcpp::hash's asynchronous family +alone, backends::webcrypto, with the note "asynchronous family only" in every table. +* Changed tools/hash/doc_tables.py to derive llms.txt's default backends from the capability +table and to give each backend's constant-time sources one bullet. +* Changed tools/hash/doc_tables.py to refuse a default without its cell or of the asynchronous +family alone, and a tag outside its namespace's chapter. +* Fixed tools/hash/doc_tables.py calling backends::openssl argon2id's and scrypt's second +template argument: each sentence reads the Backend's position from the header declaring the template. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/libs/hash b/libs/hash index 624f8161..1b947c64 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit 624f81617b05e691d7417b6033b23e629fa436d4 +Subproject commit 1b947c64f52c42f259293109fd1c24f9270bddcb diff --git a/third_party/Jamfile b/third_party/Jamfile index fb31922d..09643027 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -397,12 +397,18 @@ rule bearssl-hash-usage ( properties * ) # XKCP (CC0; brg_endian.h under Brian Gladman's terms), the Keccak team's code # package at d20c8fc (2026-11-10; XKCP has no release tags): its Keccak-p[1600] -# alone, in the plain-64bits implementation with all rounds unrolled -# ("generic64"), on every target: wasm32 has 64-bit integers, MSVC compiles it -# with _rotl64, and XKCP's faster profiles are GNU assembly. Its config.h, which -# XKCP's build generates, is webcpp's libs/hash/src/xkcp/config.h. A program -# reaches it through webcpp::hash's adapter (libs/hash/src/xkcp_adapter.c), so -# no include directory of XKCP's is a usage requirement. +# in the plain-64bits implementation with all rounds unrolled ("generic64"), +# on every target: wasm32 has 64-bit integers, MSVC compiles it with _rotl64, +# and XKCP's faster profiles are GNU assembly. Over it, the high-level files +# XKCP's lib/HighLevel.build names KeccakSponge, TurboSHAKE, FIPS202 (its +# KeccakHash.c alone: SimpleFIPS202.c's unprefixed SHA3_256 and SHAKE128 are +# never in a user's link), SP800-185 and KangarooTwelve. generic64 has no +# parallel permutation (no XKCP_has_KeccakP1600times2, 4 or 8), so +# KangarooTwelve and ParallelHash take their serial loops and no times-N file +# is compiled. Its config.h, which XKCP's build generates, is webcpp's +# libs/hash/src/xkcp/config.h. A program reaches it through webcpp::hash's +# adapter (libs/hash/src/xkcp_adapter.c), so no include directory of XKCP's +# is a usage requirement. path-constant XKCP : libs/xkcp ; rule xkcp-checked-out ( properties * ) @@ -418,15 +424,37 @@ rule xkcp-checked-out ( properties * ) lib xkcp : libs/xkcp/lib/low/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c + libs/xkcp/lib/high/Keccak/KeccakSponge.c + libs/xkcp/lib/high/Keccak/FIPS202/KeccakHash.c + libs/xkcp/lib/high/Keccak/SP800-185/SP800-185.c + libs/xkcp/lib/high/TurboSHAKE/TurboSHAKE.c + libs/xkcp/lib/high/KangarooTwelve/KangarooTwelve.c $(HASH)/src/xkcp_adapter.c $(HASH)/src/canary_xkcp.c : $(.hash-c-library) @xkcp-checked-out $(HASH)/src/xkcp libs/xkcp/lib/common libs/xkcp/lib/low/common libs/xkcp/lib/low/KeccakP-1600/common libs/xkcp/lib/low/KeccakP-1600/plain-64bits libs/xkcp/lib/low/KeccakP-1600/plain-64bits/SnP + libs/xkcp/lib/high/common libs/xkcp/lib/high/Keccak + libs/xkcp/lib/high/Keccak/FIPS202 + libs/xkcp/lib/high/Keccak/SP800-185 + libs/xkcp/lib/high/TurboSHAKE + libs/xkcp/lib/high/KangarooTwelve : : WEBCPP_HASH_HAS_XKCP=1 $(.gc) ; explicit xkcp ; +# XKCP's test vectors, tests/TestVectors at the pin (ShortMsgKAT_SHA3-*.txt +# and ShortMsgKAT_SHAKE*.txt among them), read at run time from the directory +# WEBCPP_TEST_XKCP_VECTORS gives, on every target. Quoted as wycheproof's +# define is, with forward slashes, so that a path with a space or a backslash +# survives. +.xkcp-vectors = [ regex.replace $(XKCP)/tests/TestVectors "\\\\" "/" ] ; +alias xkcp_vectors : : @xkcp-checked-out : : + "\"WEBCPP_TEST_XKCP_VECTORS=\\\"$(.xkcp-vectors)\\\"\"" + [ webcpp.data $(XKCP)/tests/TestVectors ] + libs/xkcp/tests/TestVectors/ShortMsgKAT_SHA3-256.txt ; +explicit xkcp_vectors ; + # libsodium 1.0.22 (ISC), jedisct1/libsodium at 77e1ce5: every .c of # src/libsodium/, one object per file, with the defines libsodium's own # configure finds on each target (sodium-target-defines), without its @@ -806,3 +834,76 @@ alias blake3_vectors : : @blake3-checked-out : : [ webcpp.data $(BLAKE3)/test_vectors ] libs/blake3/test_vectors/test_vectors.json ; explicit blake3_vectors ; + +# OpenSSL's EVP test data (Apache-2.0), test/recipes/30-test_evp_data at the +# pin, read at run time from the directory WEBCPP_TEST_OPENSSL_EVP_DATA gives, +# on every target, as test data that nothing compiles: webcpp::hash reads the +# Argon2 cases of evpkdf_argon2.txt, the KBKDF, SSKDF and X9.63 KDF cases of +# evpkdf_kbkdf_counter.txt, evpkdf_ss.txt and evpkdf_x963.txt, the keyed BLAKE2 +# cases of evpmac_blake.txt, the KMAC cases of evpmac_common.txt, the SipHash +# cases of evpmac_siphash.txt and the SHAKE cases of evpmd_sha.txt. Quoted as +# wycheproof's define is. +path-constant OPENSSL_EVP_DATA : libs/openssl/test/recipes/30-test_evp_data ; + +rule openssl-evp-data-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(OPENSSL_EVP_DATA)/evpmac_blake.txt ] ] + { + errors.user-error "third_party/libs/openssl is not checked out. Check it out with" + "`git submodule update --init third_party/libs/openssl`." ; + } +} + +.openssl-evp-data = [ regex.replace $(OPENSSL_EVP_DATA) "\\\\" "/" ] ; +alias openssl_evp_data : : @openssl-evp-data-checked-out : : + "\"WEBCPP_TEST_OPENSSL_EVP_DATA=\\\"$(.openssl-evp-data)\\\"\"" + [ webcpp.data $(OPENSSL_EVP_DATA) ] + libs/openssl/test/recipes/30-test_evp_data/evpkdf_argon2.txt + libs/openssl/test/recipes/30-test_evp_data/evpkdf_kbkdf_counter.txt + libs/openssl/test/recipes/30-test_evp_data/evpkdf_ss.txt + libs/openssl/test/recipes/30-test_evp_data/evpkdf_x963.txt + libs/openssl/test/recipes/30-test_evp_data/evpmac_blake.txt + libs/openssl/test/recipes/30-test_evp_data/evpmac_common.txt + libs/openssl/test/recipes/30-test_evp_data/evpmac_siphash.txt + libs/openssl/test/recipes/30-test_evp_data/evpmd_sha.txt ; +explicit openssl_evp_data ; + +# BLAKE2's reference code package (CC0-1.0) at ed1974e, shallow, as test data +# that nothing compiles: webcpp::hash reads testvectors/blake2b-kat.txt (the +# keyed BLAKE2b cases) and testvectors/blake2-kat.json (the unkeyed ones) at +# run time from the directory WEBCPP_TEST_BLAKE2_VECTORS gives, on every +# target. Quoted as wycheproof's define is. +path-constant BLAKE2_VECTORS : libs/blake2/testvectors ; + +rule blake2-vectors-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(BLAKE2_VECTORS)/blake2b-kat.txt ] ] + { + errors.user-error "third_party/libs/blake2 is not checked out. Check it out with" + "`git submodule update --init third_party/libs/blake2`." ; + } +} + +.blake2-vectors = [ regex.replace $(BLAKE2_VECTORS) "\\\\" "/" ] ; +alias blake2_vectors : : @blake2-vectors-checked-out : : + "\"WEBCPP_TEST_BLAKE2_VECTORS=\\\"$(.blake2-vectors)\\\"\"" + [ webcpp.data $(BLAKE2_VECTORS) ] + libs/blake2/testvectors/blake2b-kat.txt + libs/blake2/testvectors/blake2-kat.json ; +explicit blake2_vectors ; + +# libsodium's own tests' expected outputs (ISC), test/default/*.exp at the pin, +# read at run time from the directory WEBCPP_TEST_SODIUM_VECTORS gives, on +# every target, never copied: webcpp::hash reads generichash3.exp, kdf.exp, +# pwhash_argon2i.exp, shorthash.exp and siphashx24.exp. Quoted as wycheproof's +# define is. +.sodium-vectors = [ regex.replace $(SODIUM)/test/default "\\\\" "/" ] ; +alias sodium_vectors : : @sodium-checked-out : : + "\"WEBCPP_TEST_SODIUM_VECTORS=\\\"$(.sodium-vectors)\\\"\"" + [ webcpp.data $(SODIUM)/test/default ] + libs/libsodium/test/default/generichash3.exp + libs/libsodium/test/default/kdf.exp + libs/libsodium/test/default/pwhash_argon2i.exp + libs/libsodium/test/default/shorthash.exp + libs/libsodium/test/default/siphashx24.exp ; +explicit sodium_vectors ; diff --git a/third_party/libs/blake2 b/third_party/libs/blake2 new file mode 160000 index 00000000..ed1974ea --- /dev/null +++ b/third_party/libs/blake2 @@ -0,0 +1 @@ +Subproject commit ed1974ea83433eba7b2d95c5dcd9ac33cb847913 diff --git a/tools/hash/doc_tables.py b/tools/hash/doc_tables.py index e9fa3261..81bc3247 100644 --- a/tools/hash/doc_tables.py +++ b/tools/hash/doc_tables.py @@ -25,7 +25,9 @@ smallest program on Emscripten, then where it is used, each with its source, and when to choose it); - generated/backends-.adoc: the backends of each algorithm, from the capability - table (backend, the Jamfile line, targets, hmacs, constant time), and each function's default; + table (backend, the Jamfile line, targets, hmacs, constant time), and each function's default, + with the template argument a call names another backend as, read from the header that declares + the template (the library's include/); - generated/choose.adoc: the decision table "Choose by use case", whose backend column is the capability table's; - generated/measured.adoc: the includes of the data chapters, backends.adoc and @@ -39,10 +41,17 @@ `python3 tools/hash/doc_tables.py --write`, when one differs from what is committed, is missing, or is left over; the doc build runs it (doc/Jamfile). It also fails when guide.json lacks a public name of the capability table, names one it does not have, or a use case names -an example that example/ does not hold; when a function of the capability table has no default -or a type has one; and when measurements.json's digest does not match its content (a hand edit -of the reference). Nothing in the output depends on the time or the machine, so the files -change only with their data. +an example that example/ does not hold; when a function of the capability table names a +default that is not among its backends, or none (null) though a backend of the order hash2, +xkcp, blake3, sodium has it; when a family's tag (kind digest, mac or kdf) names a default +outside that order (design D34; null for a tag with none) or one without its cell; when any +default is a backend that only the asynchronous family takes, a type has a default, or a row +has an unknown kind; when a tag of digests or macs sits outside its namespace's chapter; 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. """ from __future__ import annotations @@ -50,6 +59,7 @@ import argparse import hashlib import json +import re import sys from pathlib import Path from typing import Any @@ -73,6 +83,19 @@ TARGETS = ('native', 'wasip2', 'wasip3', 'emscripten') # The chapters whose throughput is a rate over 1 MiB (the measured table's workloads). RATE_CHAPTERS = ('digests', 'macs', 'non-cryptographic') +# The kinds of a family's tag (spec 2.15), and the backends that may be its default, in their order +# (design D34): the first that has the tag; never bearssl, openssl, botan or webcrypto. +FAMILY_KINDS = ('digest', 'mac', 'kdf') +FAMILY_DEFAULTS = ('hash2', 'xkcp', 'blake3', 'sodium') +# The chapter each namespace's tags belong in: a tag of macs is listed with the MACs. +NAMESPACE_CHAPTERS = {'digests::': 'digests', 'macs::': 'macs'} +# The templates a family's tag is the first template argument of, by its kind, each declared in +# the tag's header: the position of their Backend is read there. +FAMILY_TEMPLATES = {'digest': ('digest_of', 'hasher'), 'mac': ('mac',), 'kdf': ('argon2',)} +ORDINALS = ('first', 'second', 'third', 'fourth') +# How the guide spells each target in prose. +TARGET_NAMES = {'native': 'native', 'wasip2': 'wasip2', 'wasip3': 'wasip3', + 'emscripten': 'Emscripten'} class Failure(Exception): @@ -116,19 +139,87 @@ def __init__(self, library: Path) -> None: self.functions[function['name']] = (algorithm, function) self.check_guide() self.check_defaults() + self.check_chapters() self.check_digest() + # The template argument each function's and each tag's call names its backend as. + self.arguments = {name: self.backend_argument(function) + for name, (_, function) in self.functions.items() + if function['kind'] == 'function' or function['kind'] in FAMILY_KINDS} + + def backend_argument(self, function: dict) -> str: + """The words "as its template argument", where a call names the backend, + read from the header that declares the template (the function's own, or its family's + templates), so that no sentence states a position the signature does not have.""" + names = FAMILY_TEMPLATES.get(function['kind'], (function['name'],)) + header = function['header'] + path = self.library / 'include' / header + try: + text = path.read_text(encoding='utf-8') + except OSError as error: + raise Failure(f'{path}: {error}') from error + # (position, number of parameters) of the Backend in each declaration of each template. + found = set() + for name in names: + places = {(i, len(parameters)) for parameters in template_parameters(text, name) + for i, parameter in enumerate(parameters) + if re.match(r'(?:class|typename)\s+Backend\b', parameter)} + if not places: + raise Failure(f'{header} declares no template {name} with a Backend parameter ' + f'(doc/capabilities.json, {function["name"]})') + found |= places + indices = {i for i, _ in found} + if len(indices) != 1: + raise Failure(f'{header}: {listed(list(names))} take the Backend at different ' + f'positions (doc/capabilities.json, {function["name"]})') + (index,) = indices + position = 'only' if all(count == 1 for _, count in found) else ORDINALS[index] + return f'as its {position} template argument' def check_defaults(self) -> None: """A function (a template with a Backend parameter) names its default, a backend that - has it; a type has none.""" + has it, or none (null) exactly when no backend of the order hash2, xkcp, blake3, sodium + has it (design D34, as kbkdf); a family's tag names one of the order that has its cell, + or none (null): every default has its engine (ruling R84); no default is a backend only + the asynchronous family takes (design D35); a type has none.""" faults = [] for name, (_, function) in self.functions.items(): default = function.get('default') - if function['kind'] == 'function' and default not in function['backends']: + kind = function['kind'] + ordered = [b for b in FAMILY_DEFAULTS if b in function['backends']] + if kind not in FAMILY_KINDS + ('function', 'type'): + faults.append(f'doc/capabilities.json: {name} has the unknown kind {kind}') + elif kind == 'type' and default is not None: + faults.append(f'doc/capabilities.json: the type {name} has a default, {default}') + elif default is not None and default in self.backends and \ + self.backends[default].get('asynchronous_only'): + faults.append(f'doc/capabilities.json: the {kind} {name} has the default ' + f'{default}, which only the asynchronous family takes') + elif kind == 'function' and default is None and ordered: + faults.append(f'doc/capabilities.json: the function {name} has no default, ' + f'though {ordered[0]}, a backend of the order, has it') + elif kind == 'function' and default is not None and \ + default not in function['backends']: faults.append(f'doc/capabilities.json: the function {name} has no default ' f'among its backends ({default})') - if function['kind'] != 'function' and default is not None: - faults.append(f'doc/capabilities.json: the type {name} has a default, {default}') + elif kind in FAMILY_KINDS and default is not None and default not in FAMILY_DEFAULTS: + faults.append(f'doc/capabilities.json: the tag {name} has the default {default}, ' + f'which is not one of {", ".join(FAMILY_DEFAULTS)}') + elif kind in FAMILY_KINDS and default is not None and \ + default not in function['backends']: + faults.append(f'doc/capabilities.json: the tag {name} has the default {default}, ' + 'which has no cell of it') + if faults: + raise Failure('\n'.join(faults)) + + def check_chapters(self) -> None: + """A tag of digests sits in the digests chapter, a tag of macs in the macs chapter, so + that each chapter's table and llms.txt's section list every tag of its namespace.""" + faults = [] + for name, (algorithm, _) in self.functions.items(): + for prefix, chapter in NAMESPACE_CHAPTERS.items(): + if name.startswith(prefix) and algorithm['chapter'] != chapter: + faults.append(f'doc/capabilities.json: the tag {name} is in the chapter ' + f'{algorithm["chapter"]}, not {chapter}') if faults: raise Failure('\n'.join(faults)) @@ -153,9 +244,9 @@ def check_guide(self) -> None: faults += [f'doc/guide.json describes {name}, which doc/capabilities.json does not ' f'have' for name in extra] chapters = {a['chapter'] for a in self.capabilities['algorithms']} - listed = [c['chapter'] for c in self.guide['chapters']] + chapter_names = [c['chapter'] for c in self.guide['chapters']] faults += [f'doc/guide.json has no chapter {c} of doc/capabilities.json' - for c in sorted(chapters - set(listed))] + for c in sorted(chapters - set(chapter_names))] for case in self.guide['use_cases']: if case['function'] not in self.functions: faults.append(f'doc/guide.json: the use case "{case["need"]}" names ' @@ -273,6 +364,78 @@ def backend_targets(data: Data, backend: str) -> str: return ', '.join(data.backends[backend]['targets']) +def template_parameters(text: str, name: str) -> list[list[str]]: + """The template parameter lists of each declaration of the template `name` (a function or a + class) in a header's text, its comments removed: each list split at its top-level commas.""" + code = re.sub(r'//[^\n]*|/\*.*?\*/', ' ', text, flags=re.DOTALL) + found = [] + for match in re.finditer(r'\btemplate\s*<', code): + depth, end = 1, match.end() + while depth and end < len(code): + depth += {'<': 1, '>': -1}.get(code[end], 0) + end += 1 + head = re.match(r'[^;{(]*', code[end:]) + if head is None or not re.search(rf'(?': -1, ')': -1}.get(code[i], 0) + if code[i] == ',' and depth == 0: + parameters.append(code[start:i].strip()) + start = i + 1 + parameters.append(code[start:end - 1].strip()) + found.append(parameters) + return found + + +def listed(names: list[str]) -> str: + """Names as prose lists them: a, b and c.""" + return names[0] if len(names) == 1 else ', '.join(names[:-1]) + f' and {names[-1]}' + + +def spelled_targets(data: Data, backend: str) -> str: + """A backend's targets as the guide's prose spells them, as "native and Emscripten".""" + return listed([TARGET_NAMES[t] if t in TARGET_NAMES else t + for t in data.backends[backend]['targets']]) + + +def source_bullets(lead: str, sources: list[str]) -> list[str]: + """One bullet led by `lead`: its one source after it, or its sources under it.""" + if len(sources) == 1: + return [f'* {lead} {sources[0]}'] + return [f'* {lead}'] + [f'** {source}' for source in sources] + + +ASYNCHRONOUS_ONLY = 'asynchronous family only' + + +def asynchronous_only(data: Data, backend: str) -> bool: + """Whether only the asynchronous family takes the backend (backends::webcrypto).""" + return bool(data.backends[backend].get('asynchronous_only')) + + +def llms_note(data: Data, backend: str) -> str: + """backend_note in llms.txt's form, after a comma.""" + return f', {ASYNCHRONOUS_ONLY}' if asynchronous_only(data, backend) else '' + + +def backend_note(data: Data, backend: str) -> str: + """What follows a backend's name in a table: that only the asynchronous family takes it.""" + return f' ({ASYNCHRONOUS_ONLY})' if asynchronous_only(data, backend) else '' + + +def partial_text(held: dict) -> str: + """What a partial cell refuses, after its backend's name; nothing for a whole cell.""" + partial = held.get('partial') + return f' (partial: {cell(partial)})' if partial else '' + + +def backend_text(data: Data, backend: str, held: dict) -> str: + """A cell's backend, with what it refuses when it is partial, and whether only the + asynchronous family takes it.""" + return f'`{backend}`{backend_note(data, backend)}{partial_text(held)}' + + def hmacs_text(hmacs: list[str] | None) -> str: if hmacs is None: return '-' @@ -295,38 +458,67 @@ def backends_table(data: Data, algorithm: dict) -> str: for backend, held in function['backends'].items(): out.append('') out.append(f'| `{function["name"]}`') - out.append(f'| `{backend}`') + out.append(f'| {backend_text(data, backend, held)}') out.append(f'| `{data.backends[backend]["jamfile"]}`') out.append(f'| {backend_targets(data, backend)}') out.append(f'| {hmacs_text(held["hmacs"])}') out.append(f'| {held["constant_time"]["value"]}') out.append('|===') out.append('') - sources = sorted({(backend, held['constant_time']['source']) - for function in algorithm['functions'] - for backend, held in function['backends'].items()}) + sources: dict[str, list[str]] = {} + for function in algorithm['functions']: + for backend, held in function['backends'].items(): + known = sources.setdefault(backend, []) + if held['constant_time']['source'] not in known: + known.append(held['constant_time']['source']) out.append('What each backend states on constant time, as the capability table read it:') out.append('') - out.extend(f'* `{backend}`: {cell(source)}' for backend, source in sources) + for backend in sorted(sources): + out.extend(source_bullets(f'`{backend}`:', [cell(s) for s in sorted(sources[backend])])) out.append('') defaults = [(f['name'], f['default']) for f in algorithm['functions'] if f['default']] + # A family's tag, and a function without a default (design D34), each say how its default + # stands. + families = [f for f in algorithm['functions'] + if f['kind'] in FAMILY_KINDS or (f['kind'] == 'function' and f['default'] is None)] + for function in families: + if function['default'] is None: + out.append(f'`{function["name"]}` has no default backend: the call names one of its ' + f'backends, {data.arguments[function["name"]]} ' + '(<>).') + out.append('') if not defaults: - names = sorted({b for f in algorithm['functions'] for b in f['backends']}) - out.append(f'One backend, {", ".join(f"`{n}`" for n in names)}: the types take no backend.') - out.append('') + # Types alone take no backend; a family's tag without a default has said so above. + if not families: + names = sorted({b for f in algorithm['functions'] for b in f['backends']}) + out.append(f'One backend, {", ".join(f"`{n}`" for n in names)}: the types take no ' + 'backend.') + out.append('') return '\n'.join(out) - by_backend: dict[str, list[str]] = {} + # One sentence per default and set of other backends, so that each names, as the backends a + # call may name instead, those of its own functions alone. + by_backend: dict[tuple[str, tuple[str, ...], str], list[str]] = {} for name, default in defaults: - by_backend.setdefault(default, []).append(f'`{name}`') - for default, names in by_backend.items(): + # The backends a call may name instead: those of this function, not of the algorithm's + # others, and never one only the asynchronous family takes. + others = tuple(sorted(b for b in set(data.functions[name][1]['backends']) - {default} + if not asynchronous_only(data, b))) + by_backend.setdefault((default, others, data.arguments[name]), []).append(name) + used = {b for f in algorithm['functions'] for b in f['backends']} + for (default, others, argument), functions in by_backend.items(): + names = [f'`{name}`' for name in functions] named = names[0] if len(names) == 1 else \ ', '.join(names[:-1]) + f' and {names[-1]}' - others = sorted({b for f in algorithm['functions'] for b in f['backends']} - {default}) - tail = (f'; {", ".join(f"`{b}`" for b in others)} only where the call names it, as its ' - 'second template argument') if others else '' + tail = (f'; {", ".join(f"`{b}`" for b in others)} only where the call names it, ' + f'{argument}') if others else '' out.append(f'The default of {named}: `{default}` on every target, whatever the program ' f'links{tail} (<>).') out.append('') + for backend in sorted(b for b in used if asynchronous_only(data, b)): + out.append(f'`{backend}` serves the asynchronous family alone, on ' + f'{spelled_targets(data, backend)}, where the type of its asynchronous call ' + 'names it (<>).') + out.append('') return '\n'.join(out) @@ -339,7 +531,7 @@ def choose_table(data: Data) -> str: '| Example') for case in data.guide['use_cases']: _, function = data.functions[case['function']] - jamfiles = ', '.join(f'`{b}`: `{data.backends[b]["jamfile"]}`' + jamfiles = ', '.join(f'`{b}`{backend_note(data, b)}: `{data.backends[b]["jamfile"]}`' for b in function['backends']) out.append('') out.append(f'| {cell(case["need"])}') @@ -379,17 +571,60 @@ def measured_includes(data: Data) -> str: return '\n'.join(out) +def function_defaults(data: Data) -> str: + """The defaults of the functions with a Backend parameter, as the capability table names + them: one clause per default, per backend a call may name instead (none, one, or several, + never one only the asynchronous family takes) and per template argument the call names it as + (the header's), and one for the functions without a default.""" + clauses: dict[tuple[str | None, str, str], list[str]] = {} + for name, (_, function) in data.functions.items(): + if function['kind'] != 'function': + continue + default = function['default'] + others = sorted(b for b in function['backends'] + if b != default and not asynchronous_only(data, b)) + if default is None: + instead = (f'backends::{others[0]}' if len(others) == 1 + else 'one of its backends') + elif not others: + instead = '' + elif len(others) == 1: + instead = f'backends::{others[0]}' + else: + instead = 'another of its backends' + clauses.setdefault((default, instead, data.arguments[name] if instead else ''), + []).append(name) + sentences = [] + for (default, instead, argument), names in clauses.items(): + many = len(names) > 1 + if default is None: + sentences.append(f'{listed(names)} {"have" if many else "has"} no default backend, ' + f'and the call names {instead} {argument}') + elif not instead: + sentences.append(f'{listed(names)} {"run" if many else "runs"} on ' + f'backends::{default} alone') + else: + sentences.append(f'{listed(names)} {"run" if many else "runs"} on ' + f'backends::{default} unless the call names {instead} ' + f'{argument}') + return f'By default, {"; ".join(sentences)}.' if sentences else '' + + def llms_txt(data: Data) -> str: page = data.guide['page'] lines = ['# webcpp::hash', '', '> Hashing and key derivation for C++20 on every target webcpp has (native, ' 'wasip2, wasip3, Emscripten): Boost.Hash2\'s digests and HMAC, Keccak-256, BLAKE3, ' - 'HKDF, PBKDF2, Argon2id and scrypt over C backends. Every function is synchronous, ' - 'returns boost::system::result and allocates nothing in webcpp\'s own code. A ' - 'program links /webcpp/hash//hash and the library of each backend it uses. Every ' - 'key derivation runs on backends::hash2 unless the call names another backend as ' - 'its second template argument; argon2id and scrypt run on backends::sodium, their ' - 'only backend.', '', + 'HKDF, PBKDF2, Argon2id, scrypt and the KDFs of NIST SP 800-108, SP 800-56C and ' + 'ANSI X9.63 over C backends. Every synchronous function returns ' + 'boost::system::result and allocates nothing in webcpp\'s own code; async.hpp gives ' + 'the slow ones and the ones WebCrypto has an asynchronous form over webcpp::asio, ' + 'and backends::webcrypto, the ' + 'browser\'s WebCrypto, serves that form alone. A program links /webcpp/hash//hash ' + 'and the library of each backend it uses. ' + function_defaults(data) + + ' The families digest_of, hasher, mac and argon2 take a tag of digests, macs or ' + 'kdfs and a backend, by default the first of ' + + listed([f'backends::{b}' for b in FAMILY_DEFAULTS]) + ' that has the tag.', '', 'Primitives only: protocol steps (BIP39, hash160, EIP-55, Nostr ids, NIP-44) ' 'are what a domain library builds from these functions; the guide shows them as ' 'examples, never as this library\'s API.', '', @@ -406,7 +641,7 @@ def llms_txt(data: Data) -> str: continue for function in algorithm['functions']: facts = data.guide['functions'][function['name']] - backends = ', '.join(f'{b} ({data.backends[b]["jamfile"]}; ' + backends = ', '.join(f'{b}{llms_note(data, b)} ({data.backends[b]["jamfile"]}; ' f'{backend_targets(data, b)})' for b in function['backends']) standard = facts.get('standard', algorithm['standard']) @@ -447,11 +682,13 @@ def backends_chapter(data: Data) -> str: lines = chapter_header('Backends', 'hash-backends', 'doc/capabilities.json') lines += ['Which backend implements each function, over which hmacs, on which targets, and ' 'what upstream', 'states about its constant time. The backends:', '', - '[cols="1,3,1,2,3",options="header"]', '|===', - '| Backend | Library | Licence | Jamfile | Targets'] + '[cols="1,3,1,2,2,2",options="header"]', '|===', + '| Backend | Library | Licence | Jamfile | Targets | Called by'] for b in table['backends']: + called = (f'{ASYNCHRONOUS_ONLY} (async.hpp)' if b.get('asynchronous_only') + else 'every function of its cells') lines += ['', f'| {b["name"]}', f'| {b["library"]}', f'| {b["licence"]}', - f'| `{b["jamfile"]}`', f'| {", ".join(b["targets"])}'] + f'| `{b["jamfile"]}`', f'| {", ".join(b["targets"])}', f'| {called}'] lines += ['|===', ''] chapters: dict[str, list[dict]] = {} for algorithm in table['algorithms']: @@ -468,7 +705,9 @@ def backends_chapter(data: Data) -> str: continue hmacs = ', '.join(c['hmacs']) if c['hmacs'] else '-' targets = ', '.join(data.backends[name]['targets']) - lines += ['', f'| {function["name"]}', f'| {name}', f'| {hmacs}', + lines += ['', f'| {function["name"]}', + f'| {name}{backend_note(data, name)}{partial_text(c)}', + f'| {hmacs}', f'| {c["constant_time"]["value"]}', f'| {targets}'] lines += ['|===', ''] lines += ['=== The default backends', '', @@ -478,17 +717,21 @@ def backends_chapter(data: Data) -> str: for _, function in data.functions.values(): if function['default'] is not None: lines += ['', f'| {function["name"]}', f'| {function["default"]}'] + elif function['kind'] in FAMILY_KINDS: + lines += ['', f'| {function["name"]}', '| none: the call names its backend'] lines += ['|===', '', '=== Constant time', '', 'What each backend\'s upstream states, and where:', ''] - seen = set() + # One bullet per backend and value, in the capability table's order of backends, with each + # distinct source of it once. + seen: dict[tuple[str, str], list[str]] = {} for _, function in data.functions.values(): for name, c in function['backends'].items(): - key = (name, c['constant_time']['value'], c['constant_time']['source']) - if key in seen: - continue - seen.add(key) - lines.append(f'* {name}: {c["constant_time"]["value"]}. ' - f'{c["constant_time"]["source"]}') + known = seen.setdefault((name, c['constant_time']['value']), []) + if c['constant_time']['source'] not in known: + known.append(c['constant_time']['source']) + order = list(data.backends) + for (name, value), sources in sorted(seen.items(), key=lambda item: order.index(item[0][0])): + lines.extend(source_bullets(f'{name}: {value}.', sources)) return '\n'.join(lines) + '\n' diff --git a/tools/test/fixtures/hash_jamfiles/argon2_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/argon2_no_default/Jamfile new file mode 100644 index 00000000..b681db05 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_no_default/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/argon2_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/argon2_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2_no_default/app.cpp new file mode 100644 index 00000000..92ee9298 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_no_default/app.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// argon2 over kdfs::argon2d, which has no default backend, on its default, stops (design D34). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array salt{}; + auto done = webcpp::hash::argon2( + output, {}, salt, {.passes = 3, .memory_kib = 65536}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome b/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome new file mode 100644 index 00000000..a9b4cd2b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_no_default/argon2_no_default.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/argon2_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::argon2d has no default backend. Name one of: backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/Jamfile b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/Jamfile new file mode 100644 index 00000000..d469bea2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/argon2_not_a_variant of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/app.cpp new file mode 100644 index 00000000..72577917 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/app.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// argon2 over a type that is not a variant of Argon2 stops with the family's refusal (spec 3.3). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array salt{}; + auto done = webcpp::hash::argon2(output, {}, salt, {.passes = 3, .memory_kib = 65536}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/argon2_not_a_variant.outcome b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/argon2_not_a_variant.outcome new file mode 100644 index 00000000..be87db79 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2_not_a_variant/argon2_not_a_variant.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/argon2_not_a_variant, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: argon2 takes kdfs::argon2d, kdfs::argon2i or kdfs::argon2id. diff --git a/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/Jamfile b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/Jamfile new file mode 100644 index 00000000..6be39489 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/argon2d_on_sodium of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/app.cpp new file mode 100644 index 00000000..5f6baf71 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/app.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// argon2 over kdfs::argon2d on backends::sodium, which has no Argon2d, stops naming the backends +// that have it (spec 3.3, the tag's row of doc/capabilities.json). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array salt{}; + auto done = webcpp::hash::argon2( + output, {}, salt, {.passes = 3, .memory_kib = 65536}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/argon2d_on_sodium.outcome b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/argon2d_on_sodium.outcome new file mode 100644 index 00000000..68f4f7be --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2d_on_sodium/argon2d_on_sodium.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/argon2d_on_sodium, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::argon2d is not in this backend. Name one of: backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome index cab59234..f5961f22 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/argon2id_default_not_linked/argon2id_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id and scrypt need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp index 969844ce..f3d1dfbc 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp @@ -4,7 +4,8 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// argon2id on another backend than backends::sodium stops with spec section 3.3's text. +// argon2id on another backend than backends::sodium and backends::openssl stops with spec section +// 3.3's text. #include #include diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome index f4583172..acecd86d 100644 --- a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome +++ b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: argon2id is in backends::sodium alone. Name backends::sodium and add /third_party//sodium to the program's Jamfile. +contains: webcpp::hash: argon2id is in backends::sodium and backends::openssl alone. Name one, and add /third_party//sodium or /webcpp/hash//openssl to the program's Jamfile. diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/Jamfile new file mode 100644 index 00000000..b2184943 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/async_argon2_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/app.cpp new file mode 100644 index 00000000..8d01fd13 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/app.cpp @@ -0,0 +1,30 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_argon2 in a build without threads stops with spec 11.5's text, which names argon2 (ruling +// R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS removes +// them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + std::array const salt{}; + webcpp::hash::async_argon2( + context.get_executor(), output, {}, salt, + webcpp::hash::argon2_parameters{.passes = 3, .memory_kib = 65536}, + [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/async_argon2_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/async_argon2_without_threads.outcome new file mode 100644 index 00000000..7fdfcdcf --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2_without_threads/async_argon2_without_threads.outcome @@ -0,0 +1,14 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_argon2_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_argon2 runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call argon2. diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/Jamfile new file mode 100644 index 00000000..6e76feb7 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/async_argon2id_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/app.cpp new file mode 100644 index 00000000..0c6dc55d --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/app.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_argon2id in a build without threads stops with spec 11.5's text, which names argon2id +// (ruling R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS +// removes them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + std::array const salt{}; + webcpp::hash::async_argon2id(context.get_executor(), output, {}, salt, + webcpp::hash::argon2id_interactive, + [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/async_argon2id_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/async_argon2id_without_threads.outcome new file mode 100644 index 00000000..93718ceb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_argon2id_without_threads/async_argon2id_without_threads.outcome @@ -0,0 +1,14 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_argon2id_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_argon2id runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call argon2id. diff --git a/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/Jamfile b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/Jamfile new file mode 100644 index 00000000..848ad050 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/async_digest_not_in_webcrypto of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/app.cpp b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/app.cpp new file mode 100644 index 00000000..614992f5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/app.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_digest over a digest WebCrypto lacks stops (spec 11.2): the cheap functions have an +// asynchronous form only for the algorithms the browser has. + +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_digest( + context.get_executor(), output, {}, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/async_digest_not_in_webcrypto.outcome b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/async_digest_not_in_webcrypto.outcome new file mode 100644 index 00000000..45915dbb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_digest_not_in_webcrypto/async_digest_not_in_webcrypto.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_digest_not_in_webcrypto, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_digest takes digests::sha1, digests::sha2_256, digests::sha2_384 or digests::sha2_512, the digests WebCrypto has: call digest_of for the others. diff --git a/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/Jamfile b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/Jamfile new file mode 100644 index 00000000..fd94f30c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/async_hkdf_not_in_webcrypto of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/app.cpp b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/app.cpp new file mode 100644 index 00000000..e4d5e78f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/app.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_hkdf over an hmac WebCrypto has no HKDF over stops (spec 11.2): the cheap functions have +// an asynchronous form only for the algorithms the browser has. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_hkdf( + context.get_executor(), output, {}, {}, {}, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/async_hkdf_not_in_webcrypto.outcome b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/async_hkdf_not_in_webcrypto.outcome new file mode 100644 index 00000000..ddee4036 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hkdf_not_in_webcrypto/async_hkdf_not_in_webcrypto.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_hkdf_not_in_webcrypto, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_hkdf takes hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has HKDF over: call hkdf for the others. diff --git a/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/Jamfile b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/Jamfile new file mode 100644 index 00000000..f65ae712 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/async_hmac_not_in_webcrypto of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/app.cpp b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/app.cpp new file mode 100644 index 00000000..02ed4e85 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/app.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_hmac over an hmac WebCrypto lacks stops (spec 11.2): the cheap functions have an +// asynchronous form only for the algorithms the browser has. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_hmac( + context.get_executor(), output, {}, {}, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/async_hmac_not_in_webcrypto.outcome b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/async_hmac_not_in_webcrypto.outcome new file mode 100644 index 00000000..4e466efe --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_hmac_not_in_webcrypto/async_hmac_not_in_webcrypto.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_hmac_not_in_webcrypto, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_hmac takes hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 or hmac_sha2_512, the hmacs WebCrypto has: call mac for the others. diff --git a/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/Jamfile new file mode 100644 index 00000000..948cefd0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/async_pbkdf2_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/app.cpp new file mode 100644 index 00000000..ec5adce6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/app.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_pbkdf2 in a build without threads stops with spec 11.5's text, which names pbkdf2 (ruling +// R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS removes +// them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_pbkdf2( + context.get_executor(), output, {}, {}, 1, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/async_pbkdf2_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/async_pbkdf2_without_threads.outcome new file mode 100644 index 00000000..577b75a9 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_pbkdf2_without_threads/async_pbkdf2_without_threads.outcome @@ -0,0 +1,14 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_pbkdf2_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_pbkdf2 runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call pbkdf2. diff --git a/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/Jamfile b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/Jamfile new file mode 100644 index 00000000..12b17d5b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/async_scrypt_without_threads of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/app.cpp b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/app.cpp new file mode 100644 index 00000000..a4019f87 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/app.cpp @@ -0,0 +1,28 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_scrypt in a build without threads stops with spec 11.5's text, which names scrypt (ruling +// R70): natively, where every build has threads, the developer's WEBCPP_HASH_NO_THREADS removes +// them; on wasip2 and wasip3 there are none. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_scrypt(context.get_executor(), output, {}, {}, + webcpp::hash::scrypt_parameters{.n = 16, .r = 1, .p = 1}, + [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/async_scrypt_without_threads.outcome b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/async_scrypt_without_threads.outcome new file mode 100644 index 00000000..1487591b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/async_scrypt_without_threads/async_scrypt_without_threads.outcome @@ -0,0 +1,14 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/async_scrypt_without_threads, a compile-diagnostic: Emscripten +# without -pthread has no threads, as wasip2 and wasip3 have none. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: async_scrypt runs on another thread and needs a build with threads (natively, remove WEBCPP_HASH_NO_THREADS; on Emscripten, link with -pthread). Without threads, call scrypt. diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/Jamfile new file mode 100644 index 00000000..5a498fd8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/blake2b_subkey_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/app.cpp new file mode 100644 index 00000000..0c7840c5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/app.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// blake2b_subkey on its default backend, backends::sodium, in a program that does not link +// libsodium stops with the instruction to add /third_party//sodium (spec section 5.7, the third +// row), and with no other error. + +#include + +#include +#include + +int main() { + std::array subkey{}; + std::array master_key{}; + std::array context{}; + auto done = webcpp::hash::blake2b_subkey(subkey, master_key, 1, context); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome new file mode 100644 index 00000000..1086f08f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_default_not_linked/blake2b_subkey_default_not_linked.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/blake2b_subkey_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/Jamfile new file mode 100644 index 00000000..2bbbc601 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/blake2b_subkey_on_hash2 of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/app.cpp new file mode 100644 index 00000000..72d927b3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/app.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// blake2b_subkey on another backend than backends::sodium stops with spec section 3.3's text. + +#include +#include + +#include +#include + +int main() { + std::array subkey{}; + std::array master_key{}; + std::array context{}; + auto done = + webcpp::hash::blake2b_subkey(subkey, master_key, 1, context); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/blake2b_subkey_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/blake2b_subkey_on_hash2.outcome new file mode 100644 index 00000000..565117c0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake2b_subkey_on_hash2/blake2b_subkey_on_hash2.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/blake2b_subkey_on_hash2, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: blake2b_subkey is in backends::sodium alone. Name backends::sodium and add /third_party//sodium to the program's Jamfile. diff --git a/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/Jamfile new file mode 100644 index 00000000..b3615842 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/blake3_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/app.cpp new file mode 100644 index 00000000..f73c1a49 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/app.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// digest_of over digests::blake3, whose default is backends::blake3, in a program that does not +// link BLAKE3, stops with the instruction to add /third_party//blake3 (spec 5.7). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/blake3_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/blake3_default_not_linked.outcome new file mode 100644 index 00000000..f5835d73 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_default_not_linked/blake3_default_not_linked.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/blake3_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::blake3 needs BLAKE3's C implementation. Add /third_party//blake3 to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//blake3 ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/digest_no_default/Jamfile new file mode 100644 index 00000000..f615e533 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_no_default/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/digest_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/digest_no_default/app.cpp new file mode 100644 index 00000000..3c210bab --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_no_default/app.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// digest_of over a tag with no default backend, on its default, stops: the call names its backend +// (design D34). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/digest_no_default/digest_no_default.outcome b/tools/test/fixtures/hash_jamfiles/digest_no_default/digest_no_default.outcome new file mode 100644 index 00000000..afeb8522 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_no_default/digest_no_default.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/digest_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digests::whirlpool has no default backend, and no backend has it yet. diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/Jamfile b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/Jamfile new file mode 100644 index 00000000..d878d9a6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/digest_not_a_tag of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/app.cpp b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/app.cpp new file mode 100644 index 00000000..a93d1838 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/app.cpp @@ -0,0 +1,18 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// digest_of over a type that is not a tag of digests stops with the family's refusal (spec 3.3). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/digest_not_a_tag.outcome b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/digest_not_a_tag.outcome new file mode 100644 index 00000000..77ca2bb2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_a_tag/digest_not_a_tag.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/digest_not_a_tag, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digest_of and hasher take a tag of webcpp::hash::digests, as digests::sha2_256. diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/Jamfile b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/Jamfile new file mode 100644 index 00000000..8c27f5d0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/digest_not_in_backend of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/app.cpp b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/app.cpp new file mode 100644 index 00000000..fa2060c4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/app.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// digest_of over a tag the named backend does not have stops naming the backends that have it +// (spec 3.3, the tag's row of doc/capabilities.json). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = + webcpp::hash::digest_of( + output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/digest_not_in_backend.outcome b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/digest_not_in_backend.outcome new file mode 100644 index 00000000..27ad7c2e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/digest_not_in_backend/digest_not_in_backend.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/digest_not_in_backend, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digests::blake3 is not in this backend. Name one of: backends::blake3. diff --git a/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/Jamfile b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/Jamfile new file mode 100644 index 00000000..d4debfd0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/hasher_not_in_backend of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/app.cpp b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/app.cpp new file mode 100644 index 00000000..5c368aa1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/app.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// A hasher over a tag the named backend does not have stops naming the backends that have it +// (spec 3.3, the tag's row of doc/capabilities.json), with no other error: the class's members +// and make reach the refused engine's members, which it gives for that reason. + +#include + +#include +#include + +int main() { + using hasher = + webcpp::hash::hasher; + auto hashing = hasher::make(); + if (!hashing) { + return 1; + } + std::array output{}; + auto fed = hashing->update(output); + auto done = hashing->finish(output); + return fed && done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/hasher_not_in_backend.outcome b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/hasher_not_in_backend.outcome new file mode 100644 index 00000000..e7b114ca --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/hasher_not_in_backend/hasher_not_in_backend.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/hasher_not_in_backend, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: digests::blake3 is not in this backend. Name one of: backends::blake3. diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/Jamfile new file mode 100644 index 00000000..87783875 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/kdf_standards_digest of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp new file mode 100644 index 00000000..b6fcd28d --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/app.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// sskdf over a digest SP 800-56C does not approve (MD5) and x963kdf over one SEC 1 v2 does not +// list (SHA-512/256) stop, whatever the backend. + +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array const secret{1}; + auto const sskdf = hash::sskdf(output, secret); + auto const x963kdf = hash::x963kdf(output, secret); + return sskdf && x963kdf ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome new file mode 100644 index 00000000..f7fb3b03 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_digest/kdf_standards_digest.outcome @@ -0,0 +1,14 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/kdf_standards_digest, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: sskdf takes a digest of SP 800-56C: digests::sha1, digests::sha2_224, sha2_256, sha2_384, sha2_512, sha2_512_224, sha2_512_256, sha3_224, sha3_256, sha3_384 or sha3_512. +contains: webcpp::hash: x963kdf takes a hash function of SEC 1 v2, section 3.5: digests::sha1, digests::sha2_224, sha2_256, sha2_384 or sha2_512. diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/Jamfile new file mode 100644 index 00000000..3f50e0b8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/kdf_standards_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/app.cpp new file mode 100644 index 00000000..510906cb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/app.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// kbkdf, sskdf and x963kdf on their default, which none of them has, stop (design D34). + +#include +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array const key{1}; + auto const kbkdf = hash::kbkdf(output, key); + auto const sskdf = hash::sskdf(output, key); + auto const x963kdf = hash::x963kdf(output, key); + return kbkdf && sskdf && x963kdf ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/kdf_standards_no_default.outcome b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/kdf_standards_no_default.outcome new file mode 100644 index 00000000..543fff08 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_no_default/kdf_standards_no_default.outcome @@ -0,0 +1,15 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/kdf_standards_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::kbkdf_hmac has no default backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::sskdf has no default backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::x963kdf has no default backend. Name one of: backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/Jamfile new file mode 100644 index 00000000..ee070835 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/kdf_standards_on_hash2 of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/app.cpp new file mode 100644 index 00000000..5b174cb2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/app.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// kbkdf, sskdf and x963kdf named on backends::hash2, which has none of them, stop (spec 3.3). + +#include +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array const key{1}; + auto const kbkdf = hash::kbkdf(output, key); + auto const sskdf = hash::sskdf(output, key); + auto const x963kdf = hash::x963kdf(output, key); + return kbkdf && sskdf && x963kdf ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/kdf_standards_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/kdf_standards_on_hash2.outcome new file mode 100644 index 00000000..4628d6df --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_standards_on_hash2/kdf_standards_on_hash2.outcome @@ -0,0 +1,15 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/kdf_standards_on_hash2, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: kdfs::kbkdf_hmac is not in this backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::sskdf is not in this backend. Name one of: backends::openssl. +contains: webcpp::hash: kdfs::x963kdf is not in this backend. Name one of: backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/Jamfile b/tools/test/fixtures/hash_jamfiles/mac_no_default/Jamfile new file mode 100644 index 00000000..a40d1ee9 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/mac_no_default of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp b/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp new file mode 100644 index 00000000..36e92327 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/app.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// mac over HMAC of a digest no backend has HMAC over, on its default, stops (design D34). + +#include + +#include +#include + +int main() { + std::array output{}; + namespace hash = webcpp::hash; + auto done = hash::mac>(output, {}, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome b/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome new file mode 100644 index 00000000..da653481 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_no_default/mac_no_default.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/mac_no_default, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: macs::hmac over this digest has no default backend: no backend has it. diff --git a/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/Jamfile b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/Jamfile new file mode 100644 index 00000000..cc446df8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/mac_not_a_tag of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/app.cpp b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/app.cpp new file mode 100644 index 00000000..0f37c3af --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/app.cpp @@ -0,0 +1,18 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// mac over a type that is not a tag of macs stops with the family's refusal (spec 3.3). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::mac(output, {}, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/mac_not_a_tag.outcome b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/mac_not_a_tag.outcome new file mode 100644 index 00000000..fc528a0e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/mac_not_a_tag/mac_not_a_tag.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/mac_not_a_tag, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: mac takes a tag of webcpp::hash::macs, as macs::hmac. diff --git a/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/Jamfile new file mode 100644 index 00000000..f3d1f9fb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/openssl_kdf_not_linked of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/app.cpp new file mode 100644 index 00000000..2441146d --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/app.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// argon2id and scrypt on backends::openssl, named without openssl.hpp in a program that does not +// link /webcpp/hash//openssl, stop at their engines with the instruction to add it, as every +// function on backends::openssl does (spec 5.7, the fifth row). + +#include +#include + +#include +#include + +int main() { + namespace hash = webcpp::hash; + std::array output{}; + std::array salt{}; + auto const argon2id = hash::argon2id( + output, {}, salt, hash::argon2id_parameters{.passes = 2, .memory = 19456 * 1024}); + auto const scrypt = hash::scrypt(output, {}, salt, + hash::scrypt_parameters{1024, 8, 1}); + return argon2id && scrypt ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/openssl_kdf_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/openssl_kdf_not_linked.outcome new file mode 100644 index 00000000..d368879b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_kdf_not_linked/openssl_kdf_not_linked.outcome @@ -0,0 +1,14 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so each +# message is a contains: line. Natively and on WASI the same texts are +# test/messages/openssl_kdf_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::openssl needs OpenSSL. Add /webcpp/hash//openssl to the program's Jamfile (native, wasip2 and wasip3): exe app : app.cpp /webcpp/hash//hash /webcpp/hash//openssl ; +contains: webcpp::hash: backends::openssl needs OpenSSL. Add /webcpp/hash//openssl to the program's Jamfile (native, wasip2 and wasip3): exe app : app.cpp /webcpp/hash//hash /webcpp/hash//openssl ; diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome index 99688c29..6b65faa0 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/scrypt_default_not_linked/scrypt_default_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id and scrypt need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp index 6ddaa95b..820a1b9d 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp +++ b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp @@ -4,7 +4,8 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// scrypt on another backend than backends::sodium stops with spec section 3.3's text. +// scrypt on another backend than backends::sodium and backends::openssl stops with spec section +// 3.3's text. #include #include diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome index 79e06c6e..c33e2973 100644 --- a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome +++ b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: scrypt is in backends::sodium alone. Name backends::sodium and add /third_party//sodium to the program's Jamfile. +contains: webcpp::hash: scrypt is in backends::sodium and backends::openssl alone. Name one, and add /third_party//sodium or /webcpp/hash//openssl to the program's Jamfile. diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/Jamfile new file mode 100644 index 00000000..0bda5e5c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/sodium_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/app.cpp new file mode 100644 index 00000000..76bcc7d3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/app.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// mac over a tag whose default is backends::sodium, in a program that does not link libsodium, +// stops with the instruction to add /third_party//sodium (spec 5.7). + +#include + +#include +#include + +int main() { + std::array output{}; + std::array key{}; + auto done = webcpp::hash::mac(output, key, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome new file mode 100644 index 00000000..1a6e0434 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_default_not_linked/sodium_default_not_linked.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/sodium_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome index c0cf3516..ee3d2c6a 100644 --- a/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome +++ b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome @@ -10,4 +10,4 @@ [all] targets: emscripten build: fails -contains: webcpp::hash: backends::sodium, argon2id and scrypt need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; +contains: webcpp::hash: backends::sodium needs libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/Jamfile b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/Jamfile new file mode 100644 index 00000000..126843ee --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/Jamfile @@ -0,0 +1,8 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# async_pbkdf2 on backends::webcrypto over hmac_sha3_256, built for Emscripten. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/app.cpp b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/app.cpp new file mode 100644 index 00000000..3b4cc280 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/app.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// async_pbkdf2 on backends::webcrypto over an hmac WebCrypto lacks stops the build: WebCrypto's +// PBKDF2 is over SHA-1 and SHA-2 alone. + +#include +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::io_context context; + std::array output{}; + webcpp::hash::async_pbkdf2( + context.get_executor(), output, {}, {}, 1, [](boost::system::error_code /*code*/) {}); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/webcrypto_pbkdf2_hmac.outcome b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/webcrypto_pbkdf2_hmac.outcome new file mode 100644 index 00000000..51bef4b2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pbkdf2_hmac/webcrypto_pbkdf2_hmac.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Its only target is Emscripten, where alone the +# asynchronous family takes backends::webcrypto. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::webcrypto has PBKDF2 over hmac_sha1_160, hmac_sha2_256, hmac_sha2_384 and hmac_sha2_512 alone: name a synchronous backend for the others. diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/Jamfile b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/Jamfile new file mode 100644 index 00000000..0cd7872f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/Jamfile @@ -0,0 +1,8 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# backends::webcrypto named with a thread_pool's executor, built for Emscripten. +exe app : app.cpp /webcpp/hash//hash /webcpp/asio//asio ; diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/app.cpp b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/app.cpp new file mode 100644 index 00000000..5ca5c8eb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/app.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// backends::webcrypto given a thread_pool's executor stops the build (ruling R73): WebCrypto's +// promise settles in the JavaScript event loop, to which only an io_context's run returns. + +#include + +#include + +#include + +#include +#include + +int main() { + webcpp::asio::thread_pool pool(0); + std::array output{}; + webcpp::hash::async_digest( + pool.get_executor(), output, {}, [](boost::system::error_code /*code*/) {}); + pool.join(); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/webcrypto_pool_executor.outcome b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/webcrypto_pool_executor.outcome new file mode 100644 index 00000000..49cf04ee --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_pool_executor/webcrypto_pool_executor.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Its only target is Emscripten, where alone the +# asynchronous family takes backends::webcrypto. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::webcrypto completes through an io_context run on the calling thread, whose run returns to the JavaScript event loop where WebCrypto's promise settles: pass that io_context's executor, not a thread_pool's. diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/Jamfile b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/Jamfile new file mode 100644 index 00000000..e1383235 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/webcrypto_synchronous of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/app.cpp b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/app.cpp new file mode 100644 index 00000000..3e96fa62 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/app.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// backends::webcrypto named in a synchronous function stops with spec 11.2's text, on every target +// (ruling R77, C-m4): only the asynchronous family takes it. + +#include +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::hkdf( + output, {}, {}, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/webcrypto_synchronous.outcome b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/webcrypto_synchronous.outcome new file mode 100644 index 00000000..0937a83c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/webcrypto_synchronous/webcrypto_synchronous.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/webcrypto_synchronous, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::webcrypto is asynchronous: call async_hkdf (or async_pbkdf2, async_digest, async_hmac) with a completion token, or name a synchronous backend. diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/Jamfile new file mode 100644 index 00000000..7dbbb356 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/xkcp_default_not_linked of webcpp::hash, built for +# Emscripten by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/app.cpp new file mode 100644 index 00000000..a931a0c4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/app.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// digest_of over a tag whose default is backends::xkcp, in a program that does not link XKCP, +// stops with the instruction to add /third_party//xkcp (spec 5.7). + +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::digest_of(output, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/xkcp_default_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/xkcp_default_not_linked.outcome new file mode 100644 index 00000000..1ea1a510 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_default_not_linked/xkcp_default_not_linked.outcome @@ -0,0 +1,13 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line starts with the header's path on the machine, so the +# message is a contains: line. Natively and on WASI the same text is +# test/messages/xkcp_default_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::xkcp needs XKCP. Add /third_party//xkcp to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//xkcp ; diff --git a/tools/test/hash_allocation_collect_test.py b/tools/test/hash_allocation_collect_test.py new file mode 100755 index 00000000..eb947f83 --- /dev/null +++ b/tools/test/hash_allocation_collect_test.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +"""Checks that libs/hash/bench/allocation_collect.py, which collects the counting programs' records +into doc/measurements.allocation.json and renders doc/allocation.adoc, builds its table only from +release builds: an output of a program whose build directory, b2's +bench/.test///..., names another variant (the lanes' test/ directories +included), or does not say, is refused before anything is written; one at variant=release is +taken and the data records the build and the toolset; `--render-only` and `--check` refuse data +whose build is not variant=release. Run with the names of some cases to run only those.""" + +from __future__ import annotations + +import json +import subprocess +import sys +import tempfile +from collections.abc import Callable +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +COLLECT = ROOT / 'libs/hash/bench/allocation_collect.py' +DATA = ROOT / 'libs/hash/doc/measurements.allocation.json' +PAGE = ROOT / 'libs/hash/doc/allocation.adoc' + +RECORDS = ( + 'record operation=counter c_counted=1\n' + 'record operation=argon2id backend=sodium new=0 c=3 counted=1\n' + 'record operation=hkdf backend=openssl new=0 hmac=hmac_sha2_256 call=1 openssl=7\n' + 'record operation=hkdf backend=openssl new=0 hmac=hmac_sha2_512 call=1 openssl=5\n' + 'record operation=hkdf backend=openssl new=0 hmac=hmac_sha2_512 call=2 openssl=4\n' +) + + +def run(*args: str | Path) -> subprocess.CompletedProcess[str]: + return subprocess.run([sys.executable, str(COLLECT), *map(str, args)], cwd=ROOT, + capture_output=True, text=True, check=False, timeout=120) + + +def lane(scratch: Path, project: str, variant: str) -> Path: + """A build directory with the output of a counting program, where b2 puts it at variant.""" + base = (scratch / 'bin/libs/hash' / project / 'allocation_release.test' / 'clang-darwin-21' + / variant) + out = base / 'cxxstd-20-iso/allocation_release.output' + out.parent.mkdir(parents=True) + out.write_text(RECORDS) + return scratch / 'bin' + + +def expect(done: subprocess.CompletedProcess[str], status: int, *texts: str) -> None: + if done.returncode != status: + raise AssertionError(f'exit {done.returncode}, not {status}\n{done.stdout}{done.stderr}') + for text in texts: + if text not in done.stdout + done.stderr: + raise AssertionError(f'{text!r} is not in the output:\n{done.stdout}{done.stderr}') + + +def test_an_output_not_built_at_variant_release_is_refused(scratch: Path) -> None: + data, page = scratch / 'data.json', scratch / 'page.adoc' + page.write_text(PAGE.read_text()) + for project, variant in (('bench', 'debug'), ('bench', 'profile'), ('test', 'debug'), + ('test', 'release')): + path = lane(scratch / f'{project}-{variant}', project, variant) + done = run('--lane', f'native={path}', '--data', data, '--page', page) + expect(done, 1, 'only from release builds') + if data.exists() or page.read_text() != PAGE.read_text(): + raise AssertionError(f'{project}/{variant}: a file was written') + stray = scratch / 'stray' + stray.mkdir() + (stray / 'allocation.output').write_text(RECORDS) + expect(run('--lane', f'wasip2={stray}', '--data', data, '--page', page), 1, + 'bench/.test//', 'only from release builds') + + +def test_an_output_built_at_variant_release_is_collected(scratch: Path) -> None: + path = lane(scratch, 'bench', 'release') + data, page = scratch / 'data.json', scratch / 'page.adoc' + page.write_text(PAGE.read_text()) + expect(run('--lane', f'native={path}', '--data', data, '--page', page), 0) + written = json.loads(data.read_text()) + if written.get('build') != 'variant=release': + raise AssertionError(f'the data states build {written.get("build")}') + if written.get('toolsets') != {'native': 'clang-darwin-21'}: + raise AssertionError(f'the data states toolsets {written.get("toolsets")}') + expect(run('--check', '--data', data, '--page', page), 0) + + +def test_render_only_and_check_refuse_data_not_built_at_variant_release(scratch: Path) -> None: + committed = json.loads(DATA.read_text()) + page = scratch / 'page.adoc' + page.write_text(PAGE.read_text()) + for build in ('variant=debug', None): + data = dict(committed) + if build is None: + data.pop('build', None) + else: + data['build'] = build + path = scratch / 'data.json' + path.write_text(json.dumps(data)) + for flag in ('--render-only', '--check'): + expect(run(flag, '--data', path, '--page', page), 1, 'only from release builds') + if page.read_text() != PAGE.read_text(): + raise AssertionError(f'{build}: the page was written') + + +def test_the_committed_data_is_from_release_builds_and_renders_the_page(scratch: Path) -> None: + committed = json.loads(DATA.read_text()) + if committed.get('build') != 'variant=release': + raise AssertionError(f'the committed data states build {committed.get("build")}') + expect(run('--check', '--data', DATA, '--page', PAGE), 0) + + +CASES: list[Callable[[Path], None]] = [ + test_an_output_not_built_at_variant_release_is_refused, + test_an_output_built_at_variant_release_is_collected, + test_render_only_and_check_refuse_data_not_built_at_variant_release, + test_the_committed_data_is_from_release_builds_and_renders_the_page, +] + + +def main(argv: list[str]) -> int: + unknown = set(argv) - {case.__name__ for case in CASES} + if unknown: + print(f'hash_allocation_collect_test: no case named {", ".join(sorted(unknown))}', + file=sys.stderr) + return 2 + for case in CASES: + if argv and case.__name__ not in argv: + continue + with tempfile.TemporaryDirectory(prefix='webcpp hash allocation ') as scratch: + case(Path(scratch)) + print(f'{case.__name__}: ok') + print('hash_allocation_collect_test: ok') + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/tools/test/hash_doc_tables_test.py b/tools/test/hash_doc_tables_test.py index e3936b07..ae39c7a2 100644 --- a/tools/test/hash_doc_tables_test.py +++ b/tools/test/hash_doc_tables_test.py @@ -12,8 +12,15 @@ passes on what it wrote, and fails naming `python3 tools/hash/doc_tables.py --write` when a generated file was edited by hand, is missing or is left over. A guide that lacks a function of the capability table, or describes one it does not have, fails, and so does a use case whose -example is not there, and so does a function of the capability table without a default. Every -function's default is the capability table's, `hash2` for HKDF whatever the measurements say. +example is not there, and so does a function of the capability table without a default that a +backend of the order hash2, xkcp, blake3, sodium has (one that none has, as kbkdf, has none). Every +function's default is the capability table's, `hash2` for HKDF whatever the measurements say. A +family's tag (spec 2.15) names a default of the order hash2, xkcp, blake3, sodium, or none, and +one without its cell fails; a partial cell says what it refuses. A tag of `digests` or `macs` +sits in its namespace's chapter. A backend of the asynchronous family alone (backends::webcrypto) +is named so in every table, with its targets as the guide spells them, and is never a default; a +row of an unknown kind fails. Each backend's constant-time statements are one bullet. llms.txt's +defaults are the capability table's, not a text written once. Without doc/measurements.json the tables say so, carry no measured column and render no measurements.adoc; with it (a fixture in its shape) they carry the throughput and the size, and measurements.adoc renders it as the dated reference that decides nothing; a hand edit of the @@ -49,11 +56,12 @@ def expect(condition: bool, message: str) -> None: def scratch_library(scratch: Path) -> Path: - """A library with the real capability table and guide, and an example file for each use - case.""" + """A library with the real capability table, guide and public headers, and an example file + for each use case.""" library = scratch / 'hash' (library / 'doc').mkdir(parents=True) (library / 'example').mkdir() + shutil.copytree(LIBRARY / 'include', library / 'include') for name in ('capabilities.json', 'guide.json'): shutil.copy(LIBRARY / 'doc' / name, library / 'doc' / name) guide = json.loads((library / 'doc/guide.json').read_text(encoding='utf-8')) @@ -206,6 +214,309 @@ def test_every_function_names_its_default(scratch: Path) -> None: expect('the type sha2_256 has a default' in done.stderr, done.stderr) +def test_a_function_without_a_backend_of_the_order_has_no_default(scratch: Path) -> None: + """A function that no backend of the order hash2, xkcp, blake3, sodium has (kbkdf, on + backends::openssl alone) has no default (design D34), and its backends say that the call + names one; given a backend of the order, it must name its default.""" + library = scratch_library(scratch) + kbkdf = write_ok(library)['generated/backends-kbkdf.adoc'] + expect('`kbkdf` has no default backend: the call names one of its backends' in kbkdf, kbkdf) + + def hash2_cell(table: dict) -> None: + family_row(table, 'kbkdf')['backends']['hash2'] = a_cell(4) + edit_capabilities(library, hash2_cell) + done = run(library, '--write') + expect(done.returncode == 1, 'a function of hash2 without a default was rendered') + expect('the function kbkdf has no default, though hash2' in done.stderr, done.stderr) + + +def family_row(table: dict, name: str) -> dict: + for algorithm in table['algorithms']: + for function in algorithm['functions']: + if function['name'] == name: + return function + raise AssertionError(f'no row {name}') + + +def test_a_family_default_is_of_the_order_or_none(scratch: Path) -> None: + library = scratch_library(scratch) + path = library / 'doc/capabilities.json' + table = json.loads(path.read_text(encoding='utf-8')) + family_row(table, 'digests::sha2_256')['default'] = 'openssl' + family_row(table, 'macs::hmac')['default'] = None + path.write_text(json.dumps(table), encoding='utf-8') + done = run(library, '--write') + expect(done.returncode == 1, 'a family default outside the order was rendered') + expect('the tag digests::sha2_256 has the default openssl' in done.stderr, done.stderr) + expect('hmac' not in done.stderr, f'none is a default: {done.stderr}') + + family_row(table, 'digests::sha2_256')['default'] = 'hash2' + path.write_text(json.dumps(table), encoding='utf-8') + files = write_ok(library) + hmac = files['generated/backends-hmac.adoc'] + expect('`macs::hmac` has no default backend: the call names one' in hmac, + hmac) + expect('| macs::hmac\n| none: the call names its backend' + in files['backends.adoc'], 'the default backends do not say none') + + +def test_a_default_without_its_cell_fails_and_a_partial_cell_is_said(scratch: Path) -> None: + # Every default has its engine once increments 2 to 7 have landed (ruling R84): a family's + # default without its cell is a fault of the data, not a cell to come. The partial cells are + # hash2's and backends::webcrypto's. + library = scratch_library(scratch) + files = write_ok(library) + blake2 = files['generated/backends-blake2.adoc'] + expect('`hash2` (partial: an output under 64 bytes' in blake2, blake2) + expect('| hash2 (partial: a tag under 32 bytes' in files['backends.adoc'], + 'the backends chapter does not say what the partial cell refuses') + expect('`webcrypto` (asynchronous family only) (partial: an info longer than 1,024 bytes' + in files['generated/backends-hkdf.adoc'], files['generated/backends-hkdf.adoc']) + expect('| webcrypto (asynchronous family only) (partial: an iteration count above 2^32 - 1' + in files['backends.adoc'], 'webcrypto\'s PBKDF2 limits are not said') + + def drop_cell(table: dict) -> None: + family_row(table, 'digests::blake2b')['backends'].pop('sodium', None) + edit_capabilities(library, drop_cell) + done = run(library, '--write') + expect(done.returncode == 1, 'a default without its cell was rendered') + expect('the tag digests::blake2b has the default sodium, which has no cell of it' + in done.stderr, done.stderr) + + +def test_a_tag_sits_in_its_namespace_s_chapter(scratch: Path) -> None: + # A tag of macs is a MAC, listed with the MACs and under llms.txt's MAC section; a tag of + # digests with the digests. + library = scratch_library(scratch) + files = write_ok(library) + expect('macs::blake2b_mac' in files['generated/compare-macs.adoc'], 'keyed BLAKE2b') + expect('macs::blake2b_mac' not in files['generated/compare-digests.adoc'], + 'keyed BLAKE2b among the digests') + macs = files['llms.txt'].split('## Message authentication')[1].split('\n## ')[0] + expect('webcpp::hash::macs::blake2s_mac' in macs, macs) + + def misplace(table: dict) -> None: + kmac = next(a for a in table['algorithms'] if a['name'] == 'kmac') + sha2 = next(a for a in table['algorithms'] if a['name'] == 'md5_sha1_sha2') + row = next(f for f in kmac['functions'] if f['name'] == 'macs::kmac_128') + kmac['functions'].remove(row) + sha2['functions'].append(row) + edit_capabilities(library, misplace) + done = run(library, '--write') + expect(done.returncode == 1, 'a tag of macs among the digests was rendered') + expect('the tag macs::kmac_128 is in the chapter digests, not macs' in done.stderr, + done.stderr) + + +def test_an_asynchronous_backend_is_never_a_default(scratch: Path) -> None: + library = scratch_library(scratch) + + def webcrypto_default(table: dict) -> None: + family_row(table, 'hkdf')['default'] = 'webcrypto' + family_row(table, 'pbkdf2')['kind'] = 'fixture' + edit_capabilities(library, webcrypto_default) + done = run(library, '--write') + expect(done.returncode == 1, 'an asynchronous-only default was rendered') + expect('the function hkdf has the default webcrypto, which only the asynchronous family ' + 'takes' in done.stderr, done.stderr) + expect('pbkdf2 has the unknown kind fixture' in done.stderr, done.stderr) + + +def test_an_asynchronous_backend_s_targets_are_spelled(scratch: Path) -> None: + library = scratch_library(scratch) + + def two_targets(table: dict) -> None: + webcrypto = next(b for b in table['backends'] if b['name'] == 'webcrypto') + webcrypto['targets'] = ['native', 'wasip2', 'emscripten'] + edit_capabilities(library, two_targets) + hkdf = write_ok(library)['generated/backends-hkdf.adoc'] + expect('serves the asynchronous family alone, on native, wasip2 and Emscripten, where' in hkdf, + hkdf) + + +def test_llms_txt_s_defaults_are_the_table_s(scratch: Path) -> None: + """Each clause whole, its template position the header's: argon2id's and scrypt's backend is + their only template argument, hkdf's and pbkdf2's the second, after the hmac.""" + library = scratch_library(scratch) + llms = write_ok(library)['llms.txt'] + expect('By default, hkdf_extract, hkdf_expand and hkdf run on backends::hash2 unless the ' + 'call names another of its backends as its second template argument; pbkdf2 runs on ' + 'backends::hash2 unless the call names backends::openssl as its second template ' + 'argument; blake2b_subkey runs on backends::sodium alone; kbkdf, sskdf and x963kdf ' + 'have no default backend, and the call names backends::openssl as its second template ' + 'argument; argon2id and scrypt run on backends::sodium unless the call names ' + 'backends::openssl as its only template argument. The families' in llms, + llms.split('\n\n')[1]) + + def scrypt_alone(table: dict) -> None: + family_row(table, 'scrypt')['backends'].pop('openssl') + edit_capabilities(library, scrypt_alone) + llms = write_ok(library)['llms.txt'] + expect('; blake2b_subkey and scrypt run on backends::sodium alone; ' in llms, + llms.split('\n\n')[1]) + expect('; argon2id runs on backends::sodium unless the call names backends::openssl as its ' + 'only template argument. ' in llms, llms.split('\n\n')[1]) + + +def test_a_backend_s_position_is_its_header_s(scratch: Path) -> None: + """The template argument a call names its backend as is read from the header that declares + the template: every generated sentence follows a moved parameter, and a header that does not + declare it fails.""" + library = scratch_library(scratch) + files = write_ok(library) + expect('The default of `argon2id`: `sodium` on every target, whatever the program links; ' + '`openssl` only where the call names it, as its only template argument ' + '(<>).' in files['generated/backends-argon2id.adoc'], + files['generated/backends-argon2id.adoc']) + expect('The default of `scrypt`: `sodium` on every target, whatever the program links; ' + '`openssl` only where the call names it, as its only template argument ' + '(<>).' in files['generated/backends-scrypt.adoc'], + files['generated/backends-scrypt.adoc']) + expect('The default of `kdfs::argon2i` and `kdfs::argon2id`: `sodium` on every target, ' + 'whatever the program links; `openssl` only where the call names it, as its second ' + 'template argument (<>).' + in files['generated/backends-argon2.adoc'], files['generated/backends-argon2.adoc']) + expect('The default of `pbkdf2`: `hash2` on every target, whatever the program links; ' + '`openssl` only where the call names it, as its second template argument ' + '(<>).' in files['generated/backends-pbkdf2.adoc'], + files['generated/backends-pbkdf2.adoc']) + header = library / 'include/webcpp/hash/scrypt.hpp' + text = header.read_text(encoding='utf-8') + moved = 'template >' + expect('template >' in text, text) + header.write_text(text.replace('template >', + moved, 1), encoding='utf-8') + files = write_ok(library) + expect('`openssl` only where the call names it, as its second template argument' + in files['generated/backends-scrypt.adoc'], files['generated/backends-scrypt.adoc']) + expect('argon2id runs on backends::sodium unless the call names backends::openssl as its ' + 'only template argument; scrypt runs on backends::sodium unless the call names ' + 'backends::openssl as its second template argument.' in files['llms.txt'], + files['llms.txt'].split('\n\n')[1]) + header.write_text(text.replace('scrypt(', 'scrypt_gone(').replace('scrypt (', 'gone ('), + encoding='utf-8') + done = run(library, '--write') + expect(done.returncode == 1, 'a header without the template was rendered') + expect('webcpp/hash/scrypt.hpp declares no template scrypt with a Backend parameter' + in done.stderr, done.stderr) + + +def edit_capabilities(library: Path, edit: Callable[[dict], None]) -> None: + """Rewrites the scratch library's capability table through `edit`.""" + path = library / 'doc/capabilities.json' + table = json.loads(path.read_text(encoding='utf-8')) + edit(table) + path.write_text(json.dumps(table, indent=4) + '\n', encoding='utf-8') + + +def a_cell(since: int) -> dict: + return {'since': since, 'hmacs': None, + 'constant_time': {'value': 'not stated', 'source': 'fixture'}} + + +def test_a_default_names_only_its_functions_backends(scratch: Path) -> None: + """An algorithm whose functions have different backends: the sentence of each default + names, as the backends a call may name instead, those of its own functions alone; functions + with one default and the same other backends share a sentence.""" + library = scratch_library(scratch) + + def blake2(table: dict) -> None: + rows = {f['name']: f for a in table['algorithms'] for f in a['functions']} + rows['digests::blake2b']['default'] = 'sodium' + rows['digests::blake2b']['backends'] = {'hash2': a_cell(2), 'sodium': a_cell(2)} + rows['digests::blake2s_256']['backends'] = {'hash2': a_cell(2), 'openssl': a_cell(4)} + rows['macs::blake2s_mac']['backends'] = {'hash2': a_cell(2)} + rows['blake2s_256']['backends'] = {'hash2': a_cell(1)} + edit_capabilities(library, blake2) + files = write_ok(library) + blake2_mac = files['generated/backends-blake2-mac.adoc'] + expect('The default of `macs::blake2s_mac`: `hash2` on every target, whatever the program ' + 'links (<>).' in blake2_mac, blake2_mac) + blake2_file = files['generated/backends-blake2.adoc'] + expect('The default of `digests::blake2s_256`: `hash2` on every target, whatever the ' + 'program links; `openssl` only where the call names it' in blake2_file, blake2_file) + expect('The default of `digests::blake2b`: `sodium` on every target, whatever the program ' + 'links; `hash2` only where the call names it' in blake2_file, blake2_file) + hkdf = files['generated/backends-hkdf.adoc'] + expect('`bearssl`' not in hkdf.split('The default of `hkdf_extract`')[1].split('\n')[0], + hkdf) + + +def test_a_tag_without_a_default_is_not_said_a_type(scratch: Path) -> None: + """An algorithm whose one row is a family's tag without a default says that the call names + a backend, and not that types take none.""" + library = scratch_library(scratch) + + def lone_tag(table: dict) -> None: + table['algorithms'].append({ + 'name': 'fixture_lone', 'macro': 'FIXTURE_LONE', 'tag': None, 'chapter': 'digests', + 'standard': 'a fixture', 'functions': [{ + 'name': 'digests::fixture_lone', 'kind': 'digest', + 'header': 'webcpp/hash/digest.hpp', 'default': None, + 'backends': {'openssl': a_cell(4)}}]}) + edit_capabilities(library, lone_tag) + guide_path = library / 'doc/guide.json' + guide = json.loads(guide_path.read_text(encoding='utf-8')) + guide['functions']['digests::fixture_lone'] = dict(guide['functions']['digests::sha2_256']) + guide_path.write_text(json.dumps(guide, indent=4) + '\n', encoding='utf-8') + lone = write_ok(library)['generated/backends-fixture-lone.adoc'] + expect('`digests::fixture_lone` has no default backend: the call names one of its backends' + in lone, lone) + expect('the types take no backend' not in lone, lone) + + +def test_each_backend_s_constant_time_sources_are_together(scratch: Path) -> None: + # One bullet per backend and value, in the table's order of backends, its sources under it + # when it has several; and one bullet per backend in an algorithm's table. + library = scratch_library(scratch) + files = write_ok(library) + chapter = files['backends.adoc'] + listed = [line.split(':')[0] for line in + chapter.split("What each backend's upstream states, and where:")[1].splitlines() + if line.startswith('* ')] + order = [b['name'] for b in json.loads( + (library / 'doc/capabilities.json').read_text(encoding='utf-8'))['backends']] + expect(listed == sorted(listed, key=lambda b: order.index(b[2:])), '\n'.join(listed)) + expect(len(listed) == len(set(listed)), '\n'.join(listed)) + expect('* openssl: not stated.\n** ' in chapter, 'openssl\'s sources are not under it') + for name, text in files.items(): + if not name.startswith('generated/backends-'): + continue + bullets = [line.split(':')[0] for line in + text.split('What each backend states on constant time')[1].splitlines() + if line.startswith('* ')] + expect(len(bullets) == len(set(bullets)), f'{name}: {bullets}') + + +def test_an_asynchronous_backend_is_said(scratch: Path) -> None: + # backends::webcrypto serves the asynchronous family alone (its "asynchronous_only" field): + # every table names it with that note, and a synchronous call never names it. + library = scratch_library(scratch) + files = write_ok(library) + backends = files['backends.adoc'] + expect('| webcrypto\n| the JavaScript runtime' in backends, backends) + expect('| asynchronous family only (async.hpp)' in backends, backends) + expect('| every function of its cells' in backends, backends) + expect('| hkdf\n| webcrypto (asynchronous family only)' in backends, backends) + hkdf = files['generated/backends-hkdf.adoc'] + expect('| `webcrypto` (asynchronous family only)' in hkdf, hkdf) + expect('`bearssl`, `openssl`, `sodium` only where the call names it' in hkdf, hkdf) + expect('`webcrypto` serves the asynchronous family alone, on Emscripten, where the type of ' + 'its asynchronous call names it (<>).' in hkdf, hkdf) + digests = files['generated/backends-md5-sha1-sha2.adoc'] + expect('`webcrypto` serves the asynchronous family alone' in digests, digests) + expect('webcrypto, asynchronous family only (/webcpp/asio//asio; emscripten)' + in files['llms.txt'], 'llms.txt does not say webcrypto is asynchronous only') + expect('backends::webcrypto, the browser\'s WebCrypto, serves that form alone' + in files['llms.txt'], 'llms.txt does not name the asynchronous form') + table = json.loads((library / 'doc/capabilities.json').read_text(encoding='utf-8')) + for backend in table['backends']: + backend.pop('asynchronous_only', None) + (library / 'doc/capabilities.json').write_text(json.dumps(table), encoding='utf-8') + plain = write_ok(library)['backends.adoc'] + expect('asynchronous family only' not in plain, 'a note without its field') + + def test_without_measurements_the_tables_say_so(scratch: Path) -> None: library = scratch_library(scratch) files = write_ok(library) @@ -215,18 +526,20 @@ def test_without_measurements_the_tables_say_so(scratch: Path) -> None: 'the comparison table does not say its measurements are missing') expect('measurements.adoc' not in files, 'measurements.adoc without its data') hkdf = files['generated/backends-hkdf.adoc'] - expect('The default of `hkdf_extract`, `hkdf_expand` and `hkdf`: `hash2` on every target' - in hkdf, f'the backends of HKDF do not name the default: {hkdf}') + expect('The default of `hkdf_extract` and `hkdf_expand`: `hash2` on every target' in hkdf + and 'The default of `hkdf`: `hash2` on every target' in hkdf, + f'the backends of HKDF do not name the default: {hkdf}') expect('`bearssl`, `openssl`, `sodium` only where the call names it' in hkdf, hkdf) expect('The default of `argon2id`: `sodium` on every target' in files['generated/backends-argon2id.adoc'], 'Argon2id\'s default') expect('One backend, `hash2`: the types take no backend.' - in files['generated/backends-blake2.adoc'], 'a type\'s backend') + in files['generated/backends-non-cryptographic.adoc'], 'a type\'s backend') backends = files['backends.adoc'] expect('| pbkdf2\n| hash2' in backends and '| scrypt\n| sodium' in backends, 'backends.adoc does not list the defaults') expect('Backends: hash2 (/webcpp/hash//hash' in files['llms.txt'], 'llms.txt has no backends') - expect('Every key derivation runs on backends::hash2' in files['llms.txt'], + expect('hkdf_extract, hkdf_expand and hkdf run on backends::hash2 unless the call names ' + 'another of its backends as its second template argument' in files['llms.txt'], 'llms.txt does not say the default') @@ -322,6 +635,18 @@ def test_the_real_library_s_files_are_its_data_s(scratch: Path) -> None: test_the_guide_covers_the_capability_table, test_a_use_case_names_an_example_that_is_there, test_every_function_names_its_default, + test_a_family_default_is_of_the_order_or_none, + test_a_default_without_its_cell_fails_and_a_partial_cell_is_said, + test_a_tag_sits_in_its_namespace_s_chapter, + test_an_asynchronous_backend_is_never_a_default, + test_an_asynchronous_backend_s_targets_are_spelled, + test_llms_txt_s_defaults_are_the_table_s, + test_a_backend_s_position_is_its_header_s, + test_a_default_names_only_its_functions_backends, + test_a_tag_without_a_default_is_not_said_a_type, + test_a_function_without_a_backend_of_the_order_has_no_default, + test_each_backend_s_constant_time_sources_are_together, + test_an_asynchronous_backend_is_said, test_without_measurements_the_tables_say_so, test_with_measurements_the_tables_carry_them, test_a_hand_edit_of_the_measurements_fails, diff --git a/tools/test/hash_jamfiles_test.py b/tools/test/hash_jamfiles_test.py index 50b868f5..69f316a6 100644 --- a/tools/test/hash_jamfiles_test.py +++ b/tools/test/hash_jamfiles_test.py @@ -17,8 +17,9 @@ fixture's app.cpp is the message's source without its expected-error directive, and that its outcome's one contains: line is the directive's text, unless the message is in NO_FIXTURE. -The scratch superproject holds libs/config, libs/hash and libs/crypto (whose canary -/third_party//bearssl compiles). Run with the names of some cases to run only those, and with +The scratch superproject holds libs/config, libs/hash, libs/crypto (whose canary +/third_party//bearssl compiles) and libs/asio (whose /webcpp/asio//asio the asynchronous family's +messages name). Run with the names of some cases to run only those, and with --target to run one target.""" from __future__ import annotations @@ -40,6 +41,10 @@ NO_FIXTURE = { 'ripemd128_on_openssl': 'it names /webcpp/hash//openssl, which Emscripten refuses before ' 'the message (the fixture openssl_on_emscripten)', + 'webcrypto_off_emscripten': 'its message is off Emscripten alone: there the asynchronous ' + 'family takes backends::webcrypto', + 'kbkdf_hmac_on_openssl': 'it names /webcpp/hash//openssl, which Emscripten refuses before ' + 'the message (the fixture openssl_on_emscripten)', } DIRECTIVE = re.compile(r'^// expected-error@\S+ \{\{(.*)\}\}$', re.MULTILINE) @@ -93,8 +98,8 @@ def message_faults(cases: list[Path]) -> list[str]: def main(argv: list[str]) -> int: - return user_jamfiles.main('hash_jamfiles', CASES, ('config', 'hash', 'crypto'), NOT_YET, argv, - message_faults) + return user_jamfiles.main('hash_jamfiles', CASES, ('config', 'hash', 'crypto', 'asio'), NOT_YET, + argv, message_faults) if __name__ == '__main__': diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 8c851ea5..a1f8ab06 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -16,13 +16,15 @@ stops the build that needs it, naming the command; and that loading third_party/Jamfile prints nothing b2 warns of. libsecp256k1, pinned, is built file by file with every module and webcpp::crypto's canary, with the large tables natively and the small ones on request and on -emscripten. XKCP, pinned, is built from its one file of Keccak-p[1600] with webcpp::hash's adapter -and canary, and an XKCP or a libs/hash that is not checked out stops it, naming the command. +emscripten. XKCP, pinned, is built from its file of Keccak-p[1600] and its high-level files with +webcpp::hash's adapter and canary, and an XKCP or a libs/hash that is not checked out stops it, +naming the command. libsodium, pinned, is built file by file with the defines its own configure finds on each target and webcpp::hash's canary, its version.h copied into the build directory and its checkout left as it was. BLAKE3's C implementation, pinned, is built file by file with webcpp::hash's canary: natively with the intrinsics files of the machine's instruction sets, each with its own flag, and on -WebAssembly with the portable code alone. Run with the names of some cases to run only those.""" +WebAssembly with the portable code alone. BLAKE2's test vectors are pinned. Run with the names of +some cases to run only those.""" from __future__ import annotations @@ -86,6 +88,13 @@ # BIP340 and BIP341 (libs/crypto/test/secp256k1_bip340_test.cpp, secp256k1_xonly_tweak_test.cpp). BIPS_COMMIT = '927b6de9915c9262615a6399de51b200f81e5aa4' +BLAKE2 = 'third_party/libs/blake2' + +# The commit BLAKE2's reference repository is pinned at: the test vectors of webcpp::hash's +# BLAKE2b (testvectors/blake2b-kat.txt and blake2-kat.json, read through +# /third_party//blake2_vectors). +BLAKE2_COMMIT = 'ed1974ea83433eba7b2d95c5dcd9ac33cb847913' + SECP256K1 = 'third_party/libs/secp256k1' # libsecp256k1 v0.8.0, the commit it is pinned at. @@ -107,12 +116,25 @@ XKCP_COMMIT = 'd20c8fcaecc543f816a0721d0dfc13b4cf27c14d' # The C files /third_party//xkcp compiles: XKCP's Keccak-p[1600] in the plain-64bits -# implementation, and webcpp::hash's adapter and canary. -XKCP_FILES = ['KeccakP-1600-opt64.c', 'xkcp_adapter.c', 'canary_xkcp.c'] - -# The adapter's four functions (spec section 2.6). +# implementation, its high-level files of the sponge, FIPS 202's Keccak_Hash, SP 800-185, +# TurboSHAKE and KangarooTwelve (serial: no times-N permutation), and webcpp::hash's adapter +# and canary. +XKCP_FILES = ['KeccakP-1600-opt64.c', 'KeccakSponge.c', 'KeccakHash.c', 'SP800-185.c', + 'TurboSHAKE.c', 'KangarooTwelve.c', 'xkcp_adapter.c', 'canary_xkcp.c'] + +# The adapter's functions (spec section 2.6): the permutation's four, and the four phases +# (initialize, update, final, squeeze) of each high-level interface. XKCP_ADAPTER = ['webcpp_hash_xkcp_initialize', 'webcpp_hash_xkcp_add_bytes', - 'webcpp_hash_xkcp_permute', 'webcpp_hash_xkcp_extract_bytes'] + 'webcpp_hash_xkcp_permute', 'webcpp_hash_xkcp_extract_bytes'] + [ + f'webcpp_hash_xkcp_{interface}_{phase}' + for interface in ('sponge', 'keccak_hash', 'turboshake', 'kangarootwelve', 'cshake128', + 'cshake256', 'kmac128', 'kmac256', 'tuplehash128', 'tuplehash256', + 'parallelhash128', 'parallelhash256') + for phase in ('initialize', 'update', 'final', 'squeeze')] + +# XKCP's unprefixed functions of FIPS 202 (SimpleFIPS202.c), which its unit tests compile into +# their own program and /third_party//xkcp never holds, so that they never reach a user's link. +XKCP_NOT_HELD = ['SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512', 'SHAKE128', 'SHAKE256'] # The small tables: window 2 and comb 2x5. SECP256K1_SMALL = ['-DECMULT_WINDOW_SIZE=2', '-DCOMB_BLOCKS=2', '-DCOMB_TEETH=5'] @@ -485,7 +507,7 @@ def test_xkcp_is_built_file_by_file(root: Path) -> None: harness.expect(result, True) lines = C_COMPILE.findall(result.stdout) compiled = sorted(Path(line.rsplit(' ', 1)[-1].strip('"')).name for line in lines) - # XKCP's one file and webcpp::hash's two: nothing else of XKCP's tree. + # XKCP's six files and webcpp::hash's two: nothing else of XKCP's tree. assert compiled == sorted(XKCP_FILES), (compiled, result.stdout[-4000:]) for line in lines: for flag in ('-ffunction-sections', '-fdata-sections'): @@ -499,14 +521,17 @@ def test_xkcp_is_built_file_by_file(root: Path) -> None: canary = 'webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link' for name in [canary, *XKCP_ADAPTER]: assert f'{prefix}{name}' in symbols, (name, symbols[-200:]) + for name in XKCP_NOT_HELD: + assert f'{prefix}{name}' not in symbols, name def test_xkcp_not_checked_out_is_refused(root: Path) -> None: harness.copy_integration_libraries(root, 'config', 'hash') harness.third_party_of_its_own(root, 'xkcp', checked_out=False) - result = harness.run_b2(root, 'third_party//xkcp') - harness.expect(result, False, 'third_party/libs/xkcp is not checked out', - 'git submodule update --init third_party/libs/xkcp') + for target in ('third_party//xkcp', 'third_party//xkcp_vectors'): + result = harness.run_b2(root, target) + harness.expect(result, False, 'third_party/libs/xkcp is not checked out', + 'git submodule update --init third_party/libs/xkcp') # A build that needs no XKCP never looks for it. harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) @@ -707,6 +732,12 @@ def expect_blake3_portable(compiled: dict[str, str], archive: Path) -> None: assert blake3_canary('portable').encode() in archive.read_bytes() +def test_blake2_is_pinned(_: Path) -> None: + listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', BLAKE2], + capture_output=True, text=True, check=True) + assert listed.stdout.split()[:2] == ['160000', BLAKE2_COMMIT], listed.stdout + + def test_blake3_is_pinned(_: Path) -> None: listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', BLAKE3], capture_output=True, text=True, check=True) @@ -828,6 +859,7 @@ def test_hash_not_checked_out_stops_blake3(root: Path) -> None: test_sodium_unknown_architecture_is_refused, test_sodium_not_checked_out_is_refused, test_hash_not_checked_out_is_refused_by_sodium, + test_blake2_is_pinned, test_blake3_is_pinned, test_blake3_natively_has_the_machines_simd_files, test_blake3_on_x86_64_declares_the_intrinsics_files,