From d4ea1d4ce3b5c50af8a152fca51aa72d005bd350 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 00:25:01 -0300 Subject: [PATCH 01/47] third_party: the shared block of webcpp::hash's C libraries --- third_party/Jamfile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/third_party/Jamfile b/third_party/Jamfile index 2bd8fbb9..249dc856 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -330,3 +330,32 @@ lib secp256k1 emscripten,auto:WEBCPP_CRYPTO_SECP256K1_SMALL_TABLES=1 $(.gc) ; explicit secp256k1 ; + +# The C libraries of webcpp::hash: each a static library compiled file by file +# in the library's own C dialect (no -std), every function and datum in a +# section of its own, so that a program keeps only what it calls +# (CODING-GUIDELINES.md chapter 5, "Bringing a C library into webcpp"). +# Upstream's warnings are not ours. webcpp's libs/hash/include/webcpp/hash/ +# detail/canary.h is the header of the canaries each of them defines. +path-constant HASH : ../libs/hash ; + +# The canaries' header is webcpp::hash's: a checkout without libs/hash stops +# the build of a C library of hash's, naming the command, and leaves the other +# targets of this Jamfile as they are. +rule hash-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(HASH)/build.jam ] ] + { + errors.user-error "libs/hash is not checked out: it holds no build.jam," + "which the C libraries of webcpp::hash are built with. Check it out" + "with `git submodule update --init libs/hash`." ; + } +} + +.hash-c-library = static off off + @hash-checked-out + clang:"-ffunction-sections -fdata-sections" + gcc:"-ffunction-sections -fdata-sections" + emscripten:"-ffunction-sections -fdata-sections" + msvc:"/Gy /Gw" + $(HASH)/include ; From b26519dc40f2b0780f4c0582ff16ed1e3556819b Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 00:25:01 -0300 Subject: [PATCH 02/47] guidelines: hash is accepted, in chapter 17 --- CODING-GUIDELINES.md | 51 +++++++++++++++++++++++++++++++++++++++++ doc/releases/0.1.0.adoc | 3 +++ 2 files changed, 54 insertions(+) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index f28833f3..11a8a631 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -8385,6 +8385,57 @@ created from one import commit of `reference/source/`. Source: `libraries/webrtc/openspec/changes/genesis/design.md` Open Questions (proposals). +### hash (hashing and key derivation over Boost.Hash2 and C backends; wrapper; accepted 2026-11-14, not built) + +webcpp::hash will be one entry point for hashing and key derivation in a +C++20 program on every target webcpp has, a wrapper (`"port-of": null`): +Boost.Hash2's algorithms and `hmac` re-exported by alias; Keccak-256 with the +original padding over XKCP's permutation and BLAKE3 over its official C +implementation, both in Hash2's HashAlgorithm form; HKDF (RFC 5869) and PBKDF2 +(RFC 8018) on a backend (`backends::hash2`, `sodium`, `bearssl`, `openssl`); +Argon2id (RFC 9106, parallelism 1) and scrypt (RFC 7914) from libsodium. 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. The owner +accepted it on 2026-11-14. Its repository, `webcpporg/hash`, is still to be +created by the owner; the library's skeleton, with its configuration header and +its test rule, is the first commit the work branches from. 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, + the RFC's text step by step in under 150 lines with every intermediate value + wiped; and Keccak-256's sponge (absorbing, the `0x01 ... 0x80` padding and + squeezing) over XKCP's Keccak-p[1600], line for line as Boost.Hash2's + `detail::keccak_base<0x01, 512, 256>`, which is its oracle, until Boost + publishes a `keccak_256`. This departs from chapter 4's rule that webcpp + 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. + Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section + 1.4 (proposals). +- **One `/third_party//sodium`, and + the C libraries of hash (`xkcp`, `blake3`, `sodium`) built file by file by + `third_party/Jamfile` with a link-time canary each.** The shared block of + that Jamfile (`HASH`, `.hash-c-library`, `hash-checked-out`) is the one every + C library of hash uses. + Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section + 5 (proposals). +- **Seven increments, each usable alone.** The first 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. + Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section + 1.5 (proposals). + ## 18. Proposed, not decided The proposals not yet decided, each briefly, with the questions they leave diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 240668dc..3378b995 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -27,6 +27,9 @@ secp256k1 over C libraries built from source, from R. * link:{library-pages}document/{library-page}[document]: a header-only JSON document for {cpp}20 that behaves as JavaScript does, exact in decimal, in one relocatable binary image, with a JavaScript module, from R. +* link:{library-pages}hash/{library-page}[hash]: hashing and key derivation for +{cpp}20 over Boost.Hash2 and C backends: Keccak-256, BLAKE3, HKDF, PBKDF2, +Argon2id and scrypt, from R. * link:{library-pages}idna/{library-page}[idna]: a header-only library of internationalized domain names for {cpp}20: Punycode, UTS 46 and IDNA2008 validity over Unicode 17.0.0 tables, from R. From 62dfde0a7d4d0f8ab1f3cd7d3056bc3f4ec02aab Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 00:27:24 -0300 Subject: [PATCH 03/47] guidelines: hash's chapter 17 entry names its C libraries in one sentence --- CODING-GUIDELINES.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 11a8a631..431b2c1c 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -8421,11 +8421,10 @@ the specification, the design and the plan, is in profile) changes every default at once. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 1.4 (proposals). -- **One `/third_party//sodium`, and - the C libraries of hash (`xkcp`, `blake3`, `sodium`) built file by file by - `third_party/Jamfile` with a link-time canary each.** The shared block of - that Jamfile (`HASH`, `.hash-c-library`, `hash-checked-out`) is the one every - C library of hash uses. +- **The C libraries of hash (`xkcp`, `blake3`, `sodium`) are built file by + file by `third_party/Jamfile`, with a link-time canary each.** The shared + block of that Jamfile (`HASH`, `.hash-c-library`, `hash-checked-out`) is + the one every C library of hash uses. Source: `libraries/hash/openspec/changes/genesis/reference/spec.md` section 5 (proposals). - **Seven increments, each usable alone.** The first is Hash2 by alias, From bc1d5533c6be8001d9f9f505c42af7c3418a30fe Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 00:34:14 -0300 Subject: [PATCH 04/47] third_party: XKCP's Keccak-p[1600], built with webcpp::hash's adapter and canary --- .gitmodules | 3 ++ CODING-GUIDELINES.md | 1 + doc/releases/0.1.0.adoc | 2 ++ third_party/Jamfile | 32 +++++++++++++++++ third_party/libs/xkcp | 1 + tools/test/third_party_test.py | 66 +++++++++++++++++++++++++++++++++- 6 files changed, 104 insertions(+), 1 deletion(-) create mode 160000 third_party/libs/xkcp diff --git a/.gitmodules b/.gitmodules index 20c0dc58..fd46d2e1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -70,3 +70,6 @@ [submodule "libs/crypto"] path = libs/crypto url = ../crypto.git +[submodule "third_party/libs/xkcp"] + path = third_party/libs/xkcp + url = https://github.com/XKCP/XKCP.git diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 431b2c1c..e1d84f5f 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -957,6 +957,7 @@ update --init third_party/libs/`; a build that needs none never looks. | `openssl` | OpenSSL 3.5.9 at `45e844fa2a14ec92d146bd8f5778ac130b6625fb`; static libssl/libcrypto and matching generated headers, built by upstream Configure/Make through B2 for native Clang/GCC/MSVC, WASIp2 single and WASIp3 single/cooperative | Apache-2.0 | | `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT | | `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 | OpenSSL builds from a checkout or a source distribution. Before Configure, its builder stages the distributable tree and checks a digest of paths, Git file diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 3378b995..ee502543 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -269,6 +269,8 @@ could not read and dropped, such as one naming a header that does not exist. * Added ctaes, Bitcoin Core's constant-time AES at v31.1, built from source as /third_party//ctaes, and the fixtures of the user's Jamfiles of webcpp::crypto's block cipher and signing programs. +* Added XKCP's Keccak-p[1600], built from source with webcpp::hash's adapter as +`/third_party//xkcp`. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/third_party/Jamfile b/third_party/Jamfile index 249dc856..4d52754e 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -359,3 +359,35 @@ rule hash-checked-out ( properties * ) emscripten:"-ffunction-sections -fdata-sections" msvc:"/Gy /Gw" $(HASH)/include ; + +# 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. +path-constant XKCP : libs/xkcp ; + +rule xkcp-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native + $(XKCP)/lib/low/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c ] ] + { + errors.user-error "third_party/libs/xkcp is not checked out: it holds no" + "lib/low/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c. Check it out" + "with `git submodule update --init third_party/libs/xkcp`." ; + } +} + +lib xkcp + : libs/xkcp/lib/low/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.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 + : : WEBCPP_HASH_HAS_XKCP=1 $(.gc) ; +explicit xkcp ; diff --git a/third_party/libs/xkcp b/third_party/libs/xkcp new file mode 160000 index 00000000..d20c8fca --- /dev/null +++ b/third_party/libs/xkcp @@ -0,0 +1 @@ +Subproject commit d20c8fcaecc543f816a0721d0dfc13b4cf27c14d diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 893513ca..8f564300 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -16,7 +16,9 @@ stops the build that needs it, naming the command; and that loading third_party/Jamfile prints nothing b2 warns of. libsecp256k1, pinned, is built file by file with every module and webcpp::crypto's canary, with the large tables natively and the small ones on request and on -emscripten. Run with the names of some cases to run only those.""" +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. Run with the names of some cases to run only those.""" from __future__ import annotations @@ -77,6 +79,19 @@ ('ECDH', 'RECOVERY', 'EXTRAKEYS', 'SCHNORRSIG', 'MUSIG', 'ELLSWIFT', 'SILENTPAYMENTS')] +XKCP = 'third_party/libs/xkcp' + +# The commit XKCP is pinned at, of 2026-11-10 (XKCP has no release tags). +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). +XKCP_ADAPTER = ['webcpp_hash_xkcp_initialize', 'webcpp_hash_xkcp_add_bytes', + 'webcpp_hash_xkcp_permute', 'webcpp_hash_xkcp_extract_bytes'] + # The small tables: window 2 and comb 2x5. SECP256K1_SMALL = ['-DECMULT_WINDOW_SIZE=2', '-DCOMB_BLOCKS=2', '-DCOMB_TEETH=5'] @@ -363,6 +378,51 @@ def test_secp256k1_not_checked_out_is_refused(root: Path) -> None: 'git submodule update --init third_party/libs/secp256k1') +def test_xkcp_is_pinned(_: Path) -> None: + listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', XKCP], + capture_output=True, text=True, check=True) + assert listed.stdout.split()[:2] == ['160000', XKCP_COMMIT], listed.stdout + + +def test_xkcp_is_built_file_by_file(root: Path) -> None: + harness.copy_integration_libraries(root, 'config', 'hash') + result = harness.run_b2(root, '-a', '-d+2', 'third_party//xkcp') + 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. + assert compiled == sorted(XKCP_FILES), (compiled, result.stdout[-4000:]) + for line in lines: + for flag in ('-ffunction-sections', '-fdata-sections'): + assert flag in line.split(), (flag, line) + assert '-std=' not in line, line + archive = sorted((root / 'bin').rglob('libxkcp.a')) + assert len(archive) == 1, archive + symbols = subprocess.run(['nm', '-g', str(archive[0])], capture_output=True, text=True, + check=True).stdout.split() + prefix = '_' if sys.platform == 'darwin' else '' + 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:]) + + +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') + # A build that needs no XKCP never looks for it. + harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) + + +def test_hash_not_checked_out_is_refused(root: Path) -> None: + # No libs/hash in the scratch superproject: XKCP's adapter and canary are missing. + result = harness.run_b2(root, 'third_party//xkcp') + harness.expect(result, False, 'libs/hash is not checked out', + 'git submodule update --init libs/hash') + + CASES = [ test_the_suite_is_pinned, test_wycheproof_is_pinned, @@ -385,6 +445,10 @@ def test_secp256k1_not_checked_out_is_refused(root: Path) -> None: test_secp256k1_small_tables_on_request, test_secp256k1_on_emscripten_has_the_small_tables, test_secp256k1_not_checked_out_is_refused, + test_xkcp_is_pinned, + test_xkcp_is_built_file_by_file, + test_xkcp_not_checked_out_is_refused, + test_hash_not_checked_out_is_refused, ] From faab9ffa48e0f45d50851415aae03390775e7c08 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 01:19:45 -0300 Subject: [PATCH 05/47] tools: webcpp.run's off links NODEFS, for a test that mounts the host's directories under node --- AGENTS.md | 9 ++++- doc/releases/0.1.0.adoc | 2 + tools/test/emscripten_test.py | 72 +++++++++++++++++++++++++++++++---- tools/webcpp.jam | 25 +++++++++++- 4 files changed, 98 insertions(+), 10 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 2a14e444..1bec69b4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -910,7 +910,12 @@ testing.launcher on emscripten", chapter 6). Every program that node runs (`webcpp.run`, `webcpp.run-fail`, `webcpp.example`) links `-sNODERAWFS=1`, so that it reads the host's files and its standard input: without it, node gives it an empty file system of Emscripten's own, and a -test reads its input file as empty. No other program gets it. +test reads its input file as empty. No other program gets it. A test of +`webcpp.run` or `webcpp.run-fail` that reads a fixed path, as a C library's +own tests read theirs (libsodium's `/test-data`), asks for +`off`: it links Emscripten's NODEFS (`-lnodefs.js`) in +place of `-sNODERAWFS=1`, under which nothing can be mounted, and mounts the +host's directories itself where it reads them (`FS.mount`). **A program on emscripten links at its compile's level of optimization** (the Jamroot's region `emscripten-link-optimization`): `-O0` for @@ -1057,7 +1062,7 @@ webcpp.source-only + ; (reference source trees) | Rule | Passes when | Notes | | --- | --- | --- | | `webcpp.targets t ...` | | the Jamfile's default targets; before its first program, once; each is `native`, `emscripten`, `wasip2` or `wasip3`, or the build stops naming it | -| `webcpp.run` | the program exits with 0 | built once per target it declares; a user's `exception-handling=off` links `tools/throw_exception.cpp`; on emscripten, run by node, linked with `-sNODERAWFS=1`; links `/webcpp//node-test` on every target (Targets, above) | +| `webcpp.run` | the program exits with 0 | built once per target it declares; a user's `exception-handling=off` links `tools/throw_exception.cpp`; on emscripten, run by node, linked with `-sNODERAWFS=1`, or with NODEFS, which the program mounts itself, under `off`; links `/webcpp//node-test` on every target (Targets, above) | | `webcpp.run-fail` | the program exits with another status | built and run as `webcpp.run`'s, and links `/webcpp//node-test` likewise | | `webcpp.compile` | the sources compile | no program is linked; takes `/webcpp//node-test` for its header | | `webcpp.compile-fail` | the sources do not compile | left out of clang-tidy; any error passes it, the wrong one included; takes `/webcpp//node-test` for its header | diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index ee502543..df933688 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -271,6 +271,8 @@ could not read and dropped, such as one naming a header that does not exist. and signing programs. * Added XKCP's Keccak-p[1600], built from source with webcpp::hash's adapter as `/third_party//xkcp`. +* Added `off`, for a test of webcpp.run that mounts on emscripten the host's +directories it reads, where it reads them, as libsodium's own tests read `/test-data`. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/tools/test/emscripten_test.py b/tools/test/emscripten_test.py index 1cfc1ca0..5e40f61b 100644 --- a/tools/test/emscripten_test.py +++ b/tools/test/emscripten_test.py @@ -8,13 +8,14 @@ """Checks emscripten as a target of the build, on the fixture library browser_demo: its tests and examples run under node, which b2's emscripten toolset runs itself, and a testing.launcher is refused there; a program that node runs reads the host's files and standard input (-sNODERAWFS=1), -and no other program gets the flag; every program is wasm32, whatever address model is asked for; a -program links at the level of optimization it compiles at, -O3 in a release build, which b2's -toolset leaves to em++'s default, -O0, and before its own linkflags; a failure reaches the report; -a program of webcpp.link is linked and never run, and fails on a symbol nothing defines; a test of -webcpp.drive runs its program through a script of node's on each of its targets, in an own lane, a -driver or a program that hangs fails it within its bound and leaves no process behind, and one that -no own lane names is refused; and a native build needs no Emscripten. +and no other program gets the flag, but one that asks for off, which links +Emscripten's NODEFS and mounts the host's directories itself; every program is wasm32, whatever +address model is asked for; a program links at the level of optimization it compiles at, -O3 in a +release build, which b2's toolset leaves to em++'s default, -O0, and before its own linkflags; a +failure reaches the report; a program of webcpp.link is linked and never run, and fails on a symbol +nothing defines; a test of webcpp.drive runs its program through a script of node's on each of its +targets, in an own lane, a driver or a program that hangs fails it within its bound and leaves no +process behind, and one that no own lane names is refused; and a native build needs no Emscripten. The suspension variant, jspi by default and asyncify on request, builds with the exceptions each needs, asyncify in a directory of its own, and natively adds nothing. Every program node runs links the test support (/webcpp//node-test), whose fixture library node_test_demo pins each case's exact @@ -180,6 +181,62 @@ def test_input_file_is_read_from_the_host(root): assert '-sENVIRONMENT=web' in link_line(root, result, 'page') +# A program that mounts a directory of the host where it reads it, as libsodium's tests read their +# expected results at /test-data: the fixture's test directory, by its absolute path. +MOUNTS_JAMFILE = """ +path-constant MOUNTED : . ; +webcpp.run mounts : mounts_test.cpp + : off "\\"WEBCPP_TEST_MOUNTED=\\\\\\"$(MOUNTED)\\\\\\"\\"" + : emscripten ; +""" + +MOUNTS_SOURCE = r'''// 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) + +// Mounts the host's directory WEBCPP_TEST_MOUNTED at /data, then reads input.txt there. + +#include + +#include +#include +#include + +int main() { + EM_ASM( + { + FS.mkdir('/data'); + FS.mount(NODEFS, {root : UTF8ToString($0)}, '/data'); + }, + WEBCPP_TEST_MOUNTED); + std::ifstream file("/data/input.txt"); + std::string line; + std::getline(file, line); + std::cout << "read " << line << "\n"; + return line == "hello" ? 0 : 1; +} +''' + + +def test_a_program_mounts_the_host_s_directories_itself(root): + # off: no -sNODERAWFS=1, under which a path is the host's and nothing can + # be mounted, but Emscripten's NODEFS, so that the program mounts a directory of the host + # where it reads it. + test = root / 'libs/browser_demo/test' + (test / 'Jamfile').write_text((test / 'Jamfile').read_text() + MOUNTS_JAMFILE) + (test / 'mounts_test.cpp').write_text(MOUNTS_SOURCE) + result = harness.run_b2(root, '-a', '-d+2', *EMSCRIPTEN, 'libs/browser_demo/test//mounts') + harness.expect(result, True) + assert passed(result) == {'mounts'}, (passed(result), result.stdout[-4000:]) + line = link_line(root, result, 'mounts') + assert '-sNODERAWFS=1' not in line, line + assert '-lnodefs.js' in line, line + output = built(root, 'mounts.output') + assert len(output) == 1 and output[0].read_text().startswith('read hello\n'), output + + def test_programs_are_wasm32(root): # Browsers do not all run memory64: a program is wasm32 even when address-model=64 is asked # for, which b2's toolset would build with -sMEMORY64=1. @@ -640,6 +697,7 @@ def run(root): test_size_table_ignores_linked_source_dependencies, test_a_launcher_is_refused_on_emscripten, test_input_file_is_read_from_the_host, + test_a_program_mounts_the_host_s_directories_itself, test_programs_are_wasm32, test_a_link_is_optimized_as_its_compile, test_suspend_variants_build_apart, diff --git a/tools/webcpp.jam b/tools/webcpp.jam index e6c29449..c78616a1 100644 --- a/tools/webcpp.jam +++ b/tools/webcpp.jam @@ -159,7 +159,30 @@ feature.compose asyncify : js ; # input file, or an example its standard input, as empty, and pass or fail # for the wrong reason. A program of webcpp.link, which a browser runs, never # gets it, nor does one a driver runs (webcpp.drive). -.node-raw-fs = emscripten:-sNODERAWFS=1 ; +.node-raw-fs = @webcpp%node-file-system ; + +# off: a test of webcpp.run or webcpp.run-fail that +# mounts, on emscripten, the host's directories it reads where it reads them +# (FS.mount of Emscripten's NODEFS), as a C library's own tests read a fixed +# path such as /test-data. Under -sNODERAWFS=1 every path is the host's and +# nothing can be mounted, so such a program links NODEFS in its place. +# Incidental: the program's build directory stays the same. +feature.feature webcpp-node-raw-fs : off : optional incidental ; + +# The file system node gives a program of webcpp.run, webcpp.run-fail and +# webcpp.example on emscripten: the host's (-sNODERAWFS=1), or NODEFS, which +# the program mounts itself, when it asks for off. +rule node-file-system ( properties * ) +{ + if [ webcpp-target.target-of $(properties) ] = emscripten + { + if off in $(properties) + { + return -lnodefs.js ; + } + return -sNODERAWFS=1 ; + } +} # What every test and example links (Jamroot's node-test): no library's # Jamfile can leave it out, and one that links -sJSPI or -sASYNCIFY gets it From 33a1f0117e44cedbaf8c81c1e8ffd585594ef84a Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 01:19:52 -0300 Subject: [PATCH 06/47] third_party: libsodium 1.0.22, built file by file with webcpp::hash's canary --- .gitmodules | 3 + CODING-GUIDELINES.md | 1 + doc/releases/0.1.0.adoc | 3 + third_party/Jamfile | 230 +++++++++++++++++++++++++++++++++ third_party/libs/libsodium | 1 + tools/test/third_party_test.py | 168 +++++++++++++++++++++++- 6 files changed, 405 insertions(+), 1 deletion(-) create mode 160000 third_party/libs/libsodium diff --git a/.gitmodules b/.gitmodules index fd46d2e1..c37b23ae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -73,3 +73,6 @@ [submodule "third_party/libs/xkcp"] path = third_party/libs/xkcp url = https://github.com/XKCP/XKCP.git +[submodule "third_party/libs/libsodium"] + path = third_party/libs/libsodium + url = https://github.com/jedisct1/libsodium.git diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index e1d84f5f..fa5b909c 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -958,6 +958,7 @@ update --init third_party/libs/`; a build that needs none never looks. | `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 | | `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 | +| `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 | OpenSSL builds from a checkout or a source distribution. Before Configure, its builder stages the distributable tree and checks a digest of paths, Git file diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index df933688..35cbf7be 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -271,6 +271,9 @@ could not read and dropped, such as one naming a header that does not exist. and signing programs. * Added XKCP's Keccak-p[1600], built from source with webcpp::hash's adapter as `/third_party//xkcp`. +* Added libsodium 1.0.22, built from source as /third_party//sodium with the defines +its own configure finds on each target, and /third_party//sodium-test-config for a +program that compiles against its private headers. * Added `off`, for a test of webcpp.run that mounts on emscripten the host's directories it reads, where it reads them, as libsodium's own tests read `/test-data`. diff --git a/third_party/Jamfile b/third_party/Jamfile index 4d52754e..4c2862be 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -13,9 +13,11 @@ # webcpp::crypto's backends are built here from their own sources, file by file. import errors ; import feature ; +import modules ; import path ; import regex ; import webcpp ; +import webcpp-target ; project /webcpp/third_party ; @@ -391,3 +393,231 @@ lib xkcp libs/xkcp/lib/low/KeccakP-1600/plain-64bits/SnP : : WEBCPP_HASH_HAS_XKCP=1 $(.gc) ; explicit xkcp ; + +# 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 +# assembly: HAVE_AMD64_ASM and HAVE_AVX_ASM stay off, as configure's +# --disable-asm leaves them, so that the seven .S files are not needed and +# the C code is used (design D11); the C files of the assembly's paths +# compile to nothing. Shared by webcpp::hash and, later, webcpp::crypto: one +# copy per program. +path-constant SODIUM : libs/libsodium ; + +rule sodium-checked-out ( properties * ) +{ + local core = $(SODIUM)/src/libsodium/include/sodium/core.h ; + if ! [ path.exists [ path.native $(core) ] ] + { + errors.user-error "third_party/libs/libsodium is not checked out. Check it" + "out with `git submodule update --init third_party/libs/libsodium`." ; + } +} + +# version.h is written by libsodium's configure, from version.h.in; upstream +# ships it generated, as builds/msvc/version.h. b2 copies that file, unchanged, +# into the build directory, as sodium/version.h, for sodium.h's +# "sodium/version.h", and as version.h, for sodium/version.c's "version.h": +# the submodule is never written. Each is a generated header, whose directory +# b2 puts on the include path of whatever names it as an +# ; the library also depends on sodium/version.h, which +# none of its own files includes, so that a program that includes sodium.h +# finds it built. +make sodium/version.h : libs/libsodium/builds/msvc/version.h : common.copy + : @sodium-checked-out ; +make version.h : libs/libsodium/builds/msvc/version.h : common.copy + : @sodium-checked-out ; +explicit sodium/version.h version.h ; + +# libsodium's configuration on each target, as libsodium's own configure finds +# it at the pin, run once per target in a scratch copy (never the submodule): +# +# ./configure --disable-shared --enable-static --disable-asm +# +# natively, and, as dist-build/wasm32-wasi.sh and dist-build/emscripten.sh run +# it at the pin, with --without-pthreads --disable-ssp and, on WASI, +# CC=/bin/clang CFLAGS=--target=wasm32-wasip2 (or wasip3) +# --host=wasm32-wasi, on Emscripten under emconfigure. Each group below is the +# DEFS of `./config.status --config` and the generated Makefile that libsodium's +# C files read, on the targets whose configure found it. A define that no C +# file of src/libsodium/ reads is recorded here and left out: the package's +# strings (PACKAGE*, VERSION, LT_OBJDIR), the headers' (HAVE_STDIO_H, +# HAVE_STDLIB_H, HAVE_STRING_H, HAVE_STRINGS_H, HAVE_INTTYPES_H, HAVE_STDINT_H, +# HAVE_SYS_STAT_H, HAVE_SYS_TYPES_H, HAVE_UNISTD_H, HAVE_WCHAR_H, HAVE_DLFCN_H, +# STDC_HEADERS, HAVE_COMMONCRYPTO_COMMONRANDOM_H), HAVE_ARC4RANDOM_BUF, +# HAVE_PTHREAD_PRIO_INHERIT, the system's extension macros (_GNU_SOURCE, +# _DARWIN_C_SOURCE, _ALL_SOURCE, __EXTENSIONS__ and the rest of +# AC_USE_SYSTEM_EXTENSIONS, which these toolchains' defaults already give), +# and HAVE_CET_H, which only the .S files read. DEV_MODE is off everywhere. +# Four that only libsodium's tests read (HAVE_ARC4RANDOM, HAVE_CATCHABLE_ABRT, +# HAVE_CATCHABLE_SEGV, HAVE_CLOCK_GETTIME) are sodium-test-config's. + +# Every target's: webcpp's three, which the canary reads (CONFIGURED, +# SODIUM_STATIC, NATIVE_LITTLE_ENDIAN), and those configure finds on every +# run. +.sodium-common = CONFIGURED=1 SODIUM_STATIC=1 + NATIVE_LITTLE_ENDIAN=1 HAVE_ALLOCA=1 HAVE_ALLOCA_H=1 + HAVE_ATOMIC_OPS=1 HAVE_C11_MEMORY_FENCES=1 + HAVE_C_VARARRAYS=1 HAVE_GCC_MEMORY_FENCES=1 + HAVE_INLINE_ASM=1 HAVE_NANOSLEEP=1 + HAVE_POSIX_MEMALIGN=1 HAVE_SYS_PARAM_H=1 + HAVE_SYS_RANDOM_H=1 ; + +# wasip2 and wasip3 (wasi-sdk 34, wasm32-wasi; the two runs agree): no mmap, +# no threads, getentropy. +.sodium-wasi = HAVE_GETENTROPY=1 HAVE_THREADS_H=1 ; + +# Emscripten 6.0.11: no getentropy (randombytes calls JavaScript's), no TI +# mode. +.sodium-emscripten = HAVE_EXPLICIT_BZERO=1 HAVE_GETPID=1 + HAVE_SYS_MMAN_H=1 HAVE_THREADS_H=1 ; + +# Native, on macOS and Linux alike (macOS 27 arm64 with Apple Clang 21, and +# x86-64 by a run with CC="cc -arch x86_64" --host=x86_64-apple-darwin; +# Ubuntu 24.04 x86-64 with GCC 14 and Clang 18; Ubuntu 24.04 arm64 with GCC +# 14 and Clang 18). TLS, the thread-local storage class, is _Thread_local: +# autoconf 2.72 runs configure's checks under -std=gnu23 wherever the +# compiler has it, where its check takes thread_local, a keyword only from +# C23; Clang 18, which has no gnu23, gives _Thread_local, the keyword of +# every dialect from C11, which webcpp's build (no -std) compiles in. +.sodium-posix = HAVE_GETENTROPY=1 HAVE_GETPID=1 + HAVE_MADVISE=1 HAVE_MLOCK=1 HAVE_MMAP=1 + HAVE_MPROTECT=1 HAVE_PTHREAD=1 HAVE_RAISE=1 + HAVE_SYSCONF=1 HAVE_SYS_MMAN_H=1 HAVE_TI_MODE=1 + HAVE_WEAK_SYMBOLS=1 TLS=_Thread_local ; + +# macOS: memset_s. +.sodium-darwin = HAVE_MEMSET_S=1 ; + +# Linux: glibc's getrandom, getauxval and explicit_bzero, on x86-64 and arm64 +# alike. +.sodium-linux = HAVE_EXPLICIT_BZERO=1 HAVE_GETAUXVAL=1 + HAVE_GETRANDOM=1 HAVE_SYS_AUXV_H=1 + HAVE_THREADS_H=1 ; + +# The architecture's, natively: x86-64's intrinsics' headers and RDRAND, +# whose C files enable each instruction set by a target attribute of their +# own, so that no file needs a flag (configure's CFLAGS_SSE2 and the rest are +# empty on every run); arm64's crypto extensions, the same. +.sodium-x86_64 = HAVE_MMINTRIN_H=1 HAVE_EMMINTRIN_H=1 + HAVE_PMMINTRIN_H=1 HAVE_TMMINTRIN_H=1 + HAVE_SMMINTRIN_H=1 HAVE_AVXINTRIN_H=1 + HAVE_AVX2INTRIN_H=1 HAVE_AVX512FINTRIN_H=1 + HAVE_WMMINTRIN_H=1 HAVE_RDRAND=1 ; +.sodium-arm64 = HAVE_ARMCRYPTO=1 ; + +# MSVC has no configure: builds/msvc/vs2022/libsodium/libsodium.props at the +# pin defines inline=__inline, NATIVE_LITTLE_ENDIAN, SODIUM_STATIC (a static +# library) and _CRT_SECURE_NO_WARNINGS (left out: the CRT's headers read it, +# no C file of libsodium's), and libsodium's private/common.h defines the +# intrinsics' HAVE_* itself under _MSC_VER. CONFIGURED is webcpp's, as on +# every target; common.h does not require it under MSVC. +.sodium-msvc = CONFIGURED=1 SODIUM_STATIC=1 + NATIVE_LITTLE_ENDIAN=1 inline=__inline ; + +# The defines only libsodium's tests read, by the same configure runs. The +# x86-64 macOS run, cross-compiled, could not run the checks of the catchable +# signals, which every native run that could finds. +.sodium-test-common = HAVE_CLOCK_GETTIME=1 ; +.sodium-test-arc4random = HAVE_ARC4RANDOM=1 ; +.sodium-test-catchable = HAVE_CATCHABLE_ABRT=1 + HAVE_CATCHABLE_SEGV=1 ; + +# The architecture a native build is for, x86_64 or arm64, as configure's +# runs name them: and when the build asks for +# them, else the machine b2 runs on (b2's OSPLAT). Any other is returned as +# -, which sodium-target-defines refuses. +local rule sodium-architecture ( properties * ) +{ + local architecture = [ feature.get-values : $(properties) ] ; + local model = [ feature.get-values : $(properties) ] ; + architecture ?= [ modules.peek : OSPLAT ] ; + model ?= 64 ; + switch $(architecture:L)-$(model) + { + case x86-64 : return x86_64 ; + case x86_64-64 : return x86_64 ; + case arm-64 : return arm64 ; + case arm64-64 : return arm64 ; + } + return $(architecture:L)-$(model) ; +} + +# The defines of a build: the groups above by its target, its system, its +# toolset and its architecture. A native build none of the configure runs +# covers (another system, or another architecture) stops, naming it, rather +# than build libsodium with a guessed configuration. +rule sodium-target-defines ( properties * ) +{ + local target = [ webcpp-target.target-of $(properties) ] ; + local toolset = [ feature.get-values : $(properties) ] ; + local system = [ feature.get-values : $(properties) ] ; + switch $(target) + { + case wasip2 : return $(.sodium-common) $(.sodium-wasi) ; + case wasip3 : return $(.sodium-common) $(.sodium-wasi) ; + case emscripten : return $(.sodium-common) $(.sodium-emscripten) ; + } + if $(toolset) = msvc + { + return $(.sodium-msvc) ; + } + local architecture = [ sodium-architecture $(properties) ] ; + local defines = $(.sodium-common) $(.sodium-posix) + $(.sodium-$(architecture)) ; + switch $(system)-$(architecture) + { + case darwin-x86_64 : return $(defines) $(.sodium-darwin) ; + case darwin-arm64 : return $(defines) $(.sodium-darwin) ; + case linux-x86_64 : return $(defines) $(.sodium-linux) ; + case linux-arm64 : return $(defines) $(.sodium-linux) ; + } + errors.user-error "/third_party//sodium: libsodium's configuration is" + "derived for macOS and Linux on x86-64 and arm64, WASI, Emscripten and" + "MSVC; this build is for $(system:E=no system) on $(architecture)" ; +} + +# What libsodium's own tests add on each target: the four defines only they +# read, as configure found them (HAVE_ARC4RANDOM natively and on WASI, the +# catchable signals natively, not on MSVC, whose build defines none of them). +rule sodium-test-defines ( properties * ) +{ + local target = [ webcpp-target.target-of $(properties) ] ; + if [ feature.get-values : $(properties) ] = msvc + { + return ; + } + switch $(target) + { + case native : return $(.sodium-test-common) $(.sodium-test-arc4random) + $(.sodium-test-catchable) ; + case emscripten : return $(.sodium-test-common) ; + } + return $(.sodium-test-common) $(.sodium-test-arc4random) ; +} + +lib sodium + : [ glob-tree-ex libs/libsodium/src/libsodium : *.c ] + $(HASH)/src/canary_sodium.c + : $(.hash-c-library) @sodium-checked-out + @sodium-target-defines + sodium/version.h version.h + sodium/version.h libs/libsodium/src/libsodium/include + libs/libsodium/src/libsodium/include/sodium + : : libs/libsodium/src/libsodium/include + sodium/version.h SODIUM_STATIC=1 + WEBCPP_HASH_HAS_SODIUM=1 $(.gc) ; +explicit sodium ; + +# What a program that compiles against libsodium's private headers adds, as +# libsodium's own tests and webcpp::hash's RFC 9106 test do: the library's +# include directories, the directory of include/sodium/private, argon2's, the +# copied version.h's, and the library's defines, with those only the tests +# read. +alias sodium-test-config : : @sodium-checked-out : : + libs/libsodium/src/libsodium/include + libs/libsodium/src/libsodium/include/sodium + libs/libsodium/src/libsodium/crypto_pwhash/argon2 + sodium/version.h version.h + @sodium-target-defines @sodium-test-defines ; +explicit sodium-test-config ; diff --git a/third_party/libs/libsodium b/third_party/libs/libsodium new file mode 160000 index 00000000..77e1ce5d --- /dev/null +++ b/third_party/libs/libsodium @@ -0,0 +1 @@ +Subproject commit 77e1ce5d6dee871c49ef211222ba18ef0c486bda diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 8f564300..205a5bfe 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -18,11 +18,14 @@ 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. Run with the names of some cases to run only those.""" +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. Run with the names of some cases to run only those.""" from __future__ import annotations import os +import platform import re import shutil import subprocess @@ -95,6 +98,60 @@ # The small tables: window 2 and comb 2x5. SECP256K1_SMALL = ['-DECMULT_WINDOW_SIZE=2', '-DCOMB_BLOCKS=2', '-DCOMB_TEETH=5'] +SODIUM = 'third_party/libs/libsodium' + +# libsodium 1.0.22, the commit it is pinned at. +SODIUM_COMMIT = '77e1ce5d6dee871c49ef211222ba18ef0c486bda' + +# The canary /third_party//sodium defines when its defines are the ones third_party/Jamfile derives +# from libsodium's configure. +SODIUM_CANARY = ('webcpp_hash_sodium_77e1ce5_configured__add_third_party_sodium_to_your_link') + +# The defines of every target: webcpp's three, then those libsodium's configure finds on every +# target and its C files read. +SODIUM_COMMON = {'CONFIGURED=1', 'SODIUM_STATIC=1', 'NATIVE_LITTLE_ENDIAN=1', 'HAVE_ALLOCA=1', + 'HAVE_ALLOCA_H=1', 'HAVE_ATOMIC_OPS=1', 'HAVE_C11_MEMORY_FENCES=1', + 'HAVE_C_VARARRAYS=1', 'HAVE_GCC_MEMORY_FENCES=1', 'HAVE_INLINE_ASM=1', + 'HAVE_NANOSLEEP=1', 'HAVE_POSIX_MEMALIGN=1', 'HAVE_SYS_PARAM_H=1', + 'HAVE_SYS_RANDOM_H=1'} + +# What configure finds natively, on macOS and Linux alike. +SODIUM_POSIX = {'HAVE_GETENTROPY=1', 'HAVE_GETPID=1', 'HAVE_MADVISE=1', 'HAVE_MLOCK=1', + 'HAVE_MMAP=1', 'HAVE_MPROTECT=1', 'HAVE_PTHREAD=1', 'HAVE_RAISE=1', + 'HAVE_SYSCONF=1', 'HAVE_SYS_MMAN_H=1', 'HAVE_TI_MODE=1', 'HAVE_WEAK_SYMBOLS=1', + 'TLS=_Thread_local'} + +# The intrinsics' headers and RDRAND, which configure finds on x86-64 alone; ARM's crypto +# extensions, on arm64 alone. +SODIUM_X86_64 = {'HAVE_MMINTRIN_H=1', 'HAVE_EMMINTRIN_H=1', 'HAVE_PMMINTRIN_H=1', + 'HAVE_TMMINTRIN_H=1', 'HAVE_SMMINTRIN_H=1', 'HAVE_AVXINTRIN_H=1', + 'HAVE_AVX2INTRIN_H=1', 'HAVE_AVX512FINTRIN_H=1', 'HAVE_WMMINTRIN_H=1', + 'HAVE_RDRAND=1'} +SODIUM_ARM64 = {'HAVE_ARMCRYPTO=1'} + +SODIUM_DEFINES = { + 'wasi': SODIUM_COMMON | {'HAVE_GETENTROPY=1', 'HAVE_THREADS_H=1'}, + 'emscripten': SODIUM_COMMON | {'HAVE_EXPLICIT_BZERO=1', 'HAVE_GETPID=1', + 'HAVE_SYS_MMAN_H=1', 'HAVE_THREADS_H=1'}, + 'darwin': SODIUM_COMMON | SODIUM_POSIX | {'HAVE_MEMSET_S=1'}, + 'linux': SODIUM_COMMON | SODIUM_POSIX | {'HAVE_EXPLICIT_BZERO=1', 'HAVE_GETAUXVAL=1', + 'HAVE_GETRANDOM=1', 'HAVE_SYS_AUXV_H=1', + 'HAVE_THREADS_H=1'}, +} + + +def sodium_native_defines() -> set[str]: + """The defines libsodium's configure finds on this machine.""" + found = SODIUM_DEFINES[sys.platform if sys.platform == 'darwin' else 'linux'] + machine = platform.machine().lower() + return found | (SODIUM_ARM64 if machine in ('arm64', 'aarch64') else SODIUM_X86_64) + + +def defines_of(line: str) -> set[str]: + """The -D options of a compile line, without -D, unquoted.""" + return {word[2:].strip('"\'') for word in line.split() if word.startswith('-D')} + + # The compile line of a C file, as b2 prints it at -d+2. C_COMPILE = re.compile(r'^\s*"?\S*(?:clang|gcc|emcc|em\+\+)\S*"? -x c .*$', re.MULTILINE) @@ -419,6 +476,108 @@ def test_xkcp_not_checked_out_is_refused(root: Path) -> None: def test_hash_not_checked_out_is_refused(root: Path) -> None: # No libs/hash in the scratch superproject: XKCP's adapter and canary are missing. result = harness.run_b2(root, 'third_party//xkcp') + +def compiled_sodium(result: subprocess.CompletedProcess) -> list[str]: + """The C compile lines of /third_party//sodium that b2 printed at -d+2.""" + return [line for line in C_COMPILE.findall(result.stdout) + if '/libsodium/' in line or 'canary_sodium.c' in line] + + +def expect_sodium_defines(lines: list[str], expected: set[str] | None) -> None: + """Asserts that every line compiles in the library's own dialect, without assembly, with the + expected defines (this machine's natively, when expected is None) and no other of + libsodium's.""" + for line in lines: + assert '-std=' not in line, line + # NDEBUG is the variant's, BOOST_ALL_NO_LIB the Jamroot's, for every program. + defines = {define for define in defines_of(line) + if define.split('=')[0] not in ('NDEBUG', 'BOOST_ALL_NO_LIB')} + wanted = expected if expected is not None else sodium_native_defines() + assert defines == wanted, (sorted(defines ^ wanted), line) + assert 'HAVE_AMD64_ASM' not in line and 'HAVE_AVX_ASM' not in line, line + + +def test_sodium_is_pinned(_: Path) -> None: + listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', SODIUM], + capture_output=True, text=True, check=True) + assert listed.stdout.split()[:2] == ['160000', SODIUM_COMMIT], listed.stdout + + +def test_sodium_is_built_file_by_file(root: Path) -> None: + harness.copy_integration_libraries(root, 'config', 'hash') + result = harness.run_b2(root, '-a', '-d+2', 'third_party//sodium') + harness.expect(result, True) + lines = compiled_sodium(result) + # The 141 C files of libsodium's src/libsodium and webcpp::hash's canary. + assert len(lines) == 142, (len(lines), result.stdout[-4000:]) + for line in lines: + for flag in ('-ffunction-sections', '-fdata-sections'): + assert flag in line, (flag, line) + expect_sodium_defines(lines, None) + copies = sorted((root / 'bin').rglob('version.h')) + upstream = (harness.ROOT / SODIUM / 'builds/msvc/version.h').read_bytes() + assert copies and all(copy.read_bytes() == upstream for copy in copies), copies + assert any(copy.parent.name == 'sodium' for copy in copies), copies + status = subprocess.run(['git', '-C', str(harness.ROOT / SODIUM), 'status', '--porcelain'], + capture_output=True, text=True, check=True) + assert status.stdout == '', status.stdout + archive = sorted((root / 'bin').rglob('libsodium.a')) + assert len(archive) == 1, archive + symbols = subprocess.run(['nm', str(archive[0])], capture_output=True, text=True, check=True) + prefix = '_' if sys.platform == 'darwin' else '' + assert f'{prefix}{SODIUM_CANARY}' in symbols.stdout.split(), symbols.stdout[-2000:] + + +def test_sodium_defines_on_each_webassembly_target(root: Path) -> None: + # -n prints each command without running it: the defines, not the build, are the case's. + harness.link_emsdk(root) + harness.copy_integration_libraries(root, 'config', 'hash') + for request, defines in ((WASIP2, SODIUM_DEFINES['wasi']), (WASIP3, SODIUM_DEFINES['wasi']), + (EMSCRIPTEN, SODIUM_DEFINES['emscripten'])): + result = harness.run_b2(root, '-a', '-n', '-d+2', *request, 'third_party//sodium') + harness.expect(result, True) + lines = compiled_sodium(result) + assert len(lines) == 142, (request, len(lines), result.stdout[-4000:]) + expect_sodium_defines(lines, defines) + + +def test_sodium_test_config_reaches_the_private_headers(root: Path) -> None: + harness.copy_integration_libraries(root, 'config', 'hash') + harness.add_library(root, 'sodium_private', 'import webcpp ;\n' + '\n' + 'webcpp.run private : private.c : /third_party//sodium-test-config\n' + ' /third_party//sodium ;\n', + {'private.c': '#include \n' + '#include "private/common.h"\n' + '#include "argon2.h"\n' + '#include "version.h"\n' + '\n' + 'int main(void) {\n' + ' return sodium_init() < 0 ||\n' + ' sodium_library_version_major() !=\n' + ' SODIUM_LIBRARY_VERSION_MAJOR;\n' + '}\n'}) + result = harness.run_b2(root, '-a', '-d+2', 'libs/sodium_private/test') + harness.expect(result, True, '**passed**') + # The program compiles with the library's defines, the test-only ones too. + line = [line for line in C_COMPILE.findall(result.stdout) if 'private.c' in line] + assert len(line) == 1, result.stdout[-4000:] + assert {'CONFIGURED=1', 'SODIUM_STATIC=1', 'HAVE_CLOCK_GETTIME=1'} <= defines_of(line[0]), line + + +def test_sodium_not_checked_out_is_refused(root: Path) -> None: + harness.copy_integration_libraries(root, 'config', 'hash') + harness.third_party_of_its_own(root, 'libsodium', checked_out=False) + result = harness.run_b2(root, 'third_party//sodium') + harness.expect(result, False, 'third_party/libs/libsodium is not checked out', + 'git submodule update --init third_party/libs/libsodium') + # A build that needs no libsodium never looks for it. + harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) + + +def test_hash_not_checked_out_is_refused_by_sodium(root: Path) -> None: + # No libs/hash in the scratch superproject: the canary is missing. + result = harness.run_b2(root, 'third_party//sodium') harness.expect(result, False, 'libs/hash is not checked out', 'git submodule update --init libs/hash') @@ -449,6 +608,13 @@ def test_hash_not_checked_out_is_refused(root: Path) -> None: test_xkcp_is_built_file_by_file, test_xkcp_not_checked_out_is_refused, test_hash_not_checked_out_is_refused, + + test_sodium_is_pinned, + test_sodium_is_built_file_by_file, + test_sodium_defines_on_each_webassembly_target, + test_sodium_test_config_reaches_the_private_headers, + test_sodium_not_checked_out_is_refused, + test_hash_not_checked_out_is_refused_by_sodium, ] From 712bf67730ea4b17936bad719a755107452625db Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 01:46:41 -0300 Subject: [PATCH 07/47] tools: off is documented for every rule it reaches --- AGENTS.md | 12 +++++++----- doc/releases/0.1.0.adoc | 5 +++-- tools/webcpp.jam | 14 ++++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1bec69b4..13624ccb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -910,12 +910,14 @@ testing.launcher on emscripten", chapter 6). Every program that node runs (`webcpp.run`, `webcpp.run-fail`, `webcpp.example`) links `-sNODERAWFS=1`, so that it reads the host's files and its standard input: without it, node gives it an empty file system of Emscripten's own, and a -test reads its input file as empty. No other program gets it. A test of -`webcpp.run` or `webcpp.run-fail` that reads a fixed path, as a C library's -own tests read theirs (libsodium's `/test-data`), asks for +test reads its input file as empty. No other program gets it. A program of +`webcpp.run`, `webcpp.run-fail` or `webcpp.example` that reads a fixed path, +as a C library's own tests read theirs (libsodium's `/test-data`), asks for `off`: it links Emscripten's NODEFS (`-lnodefs.js`) in place of `-sNODERAWFS=1`, under which nothing can be mounted, and mounts the -host's directories itself where it reads them (`FS.mount`). +host's directories itself where it reads them (`FS.mount`); it then reads no +standard input of the host's, so an example with a `.input` does not +ask for it. **A program on emscripten links at its compile's level of optimization** (the Jamroot's region `emscripten-link-optimization`): `-O0` for @@ -1070,7 +1072,7 @@ webcpp.source-only + ; (reference source trees) | `webcpp.compile-diagnostic` | the sources stop with every error they state in clang's `-verify` comments, `// expected-error@:* {{}}` for a header they include or `// expected-error@+1 {{}}` for the next line | compiled with `-Xclang -verify -Xclang -verify-ignore-unexpected=error,note`, so an error not stated and a note are ignored, the cascade that follows a header's `#error` among them; then `tools/compile_diagnostic/check.py` runs the compile again with clang's diagnostic log and fails on any error located in a comment (a `//` one or a `/* */` one over several lines) after an `expected-` of that comment, which is `-verify`'s own report on a directive it could not read and so dropped (a header it names that cannot be located, a `{{...}}` whose `}}` is not on its line), and on a compile that reports no error at all: each directive clang reads, every one outside a branch the preprocessor skips, must be read whole, the header it names found and included, and its error raised in that header; built on b2's `clang` toolset only (native clang, `clang-wasip2`, `clang-wasip3`) and skipped elsewhere, since `-verify` is clang's: a refusal would turn every gcc and msvc lane red for a declaration that holds; left out of clang-tidy; takes `/webcpp//node-test` for its header | | `webcpp.boost-test` | every case of the Boost.Test suite passes | native only, whatever the Jamfile declares; the header-only framework, `tools/boost_test_runner.cpp`, is one object of the suite's, always compiled with exceptions | | `webcpp.source-only` | | declares child source directories whose original Jamfiles are not WebCPP projects; use in `build.jam` before discovery; it changes neither explicit compilation nor lint | -| `webcpp.example` | the program exits with 0, and its standard output, carriage returns removed, equals `.expected` beside it | its standard input is `.input` beside it, else empty, never the terminal, on every target (wasmtime passes it through, and node under `-sNODERAWFS=1`); run through `testing.launcher` for WASI, and on emscripten with the node on `PATH`, not the one b2's toolset registered, which b2 gives only to its own testing rules, by `tools/example/run_example.py`, which names a failing exit status (or the signal) before the diff; always run again, and `.input` is a source of the run; links `/webcpp//node-test` on every target (Targets, above) | +| `webcpp.example` | the program exits with 0, and its standard output, carriage returns removed, equals `.expected` beside it | its standard input is `.input` beside it, else empty, never the terminal, on every target (wasmtime passes it through, and node under `-sNODERAWFS=1`, which `off` replaces with NODEFS); run through `testing.launcher` for WASI, and on emscripten with the node on `PATH`, not the one b2's toolset registered, which b2 gives only to its own testing rules, by `tools/example/run_example.py`, which names a failing exit status (or the signal) before the diff; always run again, and `.input` is a source of the run; links `/webcpp//node-test` on every target (Targets, above) | | `webcpp.link` | the program links | never run: a program for a browser, which node refuses to run (`-sENVIRONMENT=web`), or one that needs the network; b2's `link` test, which `--dump-tests` lists and the report shows as a link test; never linked with `-sNODERAWFS=1`. The explicit target `-program` is the same program, an `exe` of the same sources and requirements, `-program.js` on emscripten, for a target that needs its files, such as a page that loads it. An example Jamfile's is shown on the page by its code, and has no `.expected` (chapter 3) | | `webcpp.headers-alone` | each public header compiles alone | one test per header, `alone-` with `/` as `-` (`alone-xactor-scheduler`), against `/webcpp///` and the requirements given, for the targets given or the Jamfile's; `only` restricts a call to the public headers its globs match, relative to `/webcpp/` (`wasi/http/response.hpp`), a glob that matches none stopping the build; a library may call it several times, and a header two calls take stops the build, naming it | | `webcpp.data` | | requirements, or usage requirements, that give a program of `webcpp.run` or `webcpp.run-fail` the absolute directories, each read at the same path on every target: on wasip2 and wasip3 wasmtime preopens it (`wasmtime --dir="" `); natively and on emscripten (`-sNODERAWFS=1`) the program reads the host's files already. A relative directory stops the build, as does one whose path holds `"`, `$` or a backquote, which the shell would read inside `--dir="..."`, naming the character | diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 35cbf7be..0c859e58 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -274,8 +274,9 @@ and signing programs. * 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. -* Added `off`, for a test of webcpp.run that mounts on emscripten the host's -directories it reads, where it reads them, as libsodium's own tests read `/test-data`. +* Added `off`, for a program of webcpp.run, webcpp.run-fail or webcpp.example +that mounts on emscripten the host's directories it reads, where it reads them, as libsodium's own +tests read `/test-data`. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/tools/webcpp.jam b/tools/webcpp.jam index c78616a1..0448b015 100644 --- a/tools/webcpp.jam +++ b/tools/webcpp.jam @@ -161,12 +161,14 @@ feature.compose asyncify : js ; # gets it, nor does one a driver runs (webcpp.drive). .node-raw-fs = @webcpp%node-file-system ; -# off: a test of webcpp.run or webcpp.run-fail that -# mounts, on emscripten, the host's directories it reads where it reads them -# (FS.mount of Emscripten's NODEFS), as a C library's own tests read a fixed -# path such as /test-data. Under -sNODERAWFS=1 every path is the host's and -# nothing can be mounted, so such a program links NODEFS in its place. -# Incidental: the program's build directory stays the same. +# off: a program of webcpp.run, webcpp.run-fail or +# webcpp.example that mounts, on emscripten, the host's directories it reads +# where it reads them (FS.mount of Emscripten's NODEFS), as a C library's own +# tests read a fixed path such as /test-data. Under -sNODERAWFS=1 every path +# is the host's and nothing can be mounted, so such a program links NODEFS in +# its place; it then reads no standard input of the host's, so an example +# with a .input does not ask for it. Incidental: the program's build +# directory stays the same. feature.feature webcpp-node-raw-fs : off : optional incidental ; # The file system node gives a program of webcpp.run, webcpp.run-fail and From d39bc760458ce873ccd9e759e665bcff7a036323 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 01:46:41 -0300 Subject: [PATCH 08/47] third_party: libsodium's inline=__inline reaches MSVC's C alone, its version.h has one fixed place, and an unknown model stops --- third_party/Jamfile | 66 ++++++++++++++++++++-------------- tools/test/third_party_test.py | 50 ++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 27 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index 4c2862be..da312df2 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -15,6 +15,7 @@ import errors ; import feature ; import modules ; import path ; +import project ; import regex ; import webcpp ; import webcpp-target ; @@ -416,18 +417,17 @@ rule sodium-checked-out ( properties * ) # version.h is written by libsodium's configure, from version.h.in; upstream # ships it generated, as builds/msvc/version.h. b2 copies that file, unchanged, -# into the build directory, as sodium/version.h, for sodium.h's -# "sodium/version.h", and as version.h, for sodium/version.c's "version.h": -# the submodule is never written. Each is a generated header, whose directory -# b2 puts on the include path of whatever names it as an -# ; the library also depends on sodium/version.h, which -# none of its own files includes, so that a program that includes sodium.h -# finds it built. +# into the build directory, as sodium-version/sodium/version.h: its directory +# sodium-version gives sodium.h its "sodium/version.h", and sodium-version/ +# sodium gives sodium/version.c its "version.h". The submodule is never +# written. The copy's place is fixed (), so that both directories +# are known here; it is the same file for every build. +.sodium-version = [ project.current ] ; +.sodium-version = [ path.root [ $(.sodium-version).build-dir ] [ path.pwd ] ] ; +.sodium-version = $(.sodium-version)/sodium-version ; make sodium/version.h : libs/libsodium/builds/msvc/version.h : common.copy - : @sodium-checked-out ; -make version.h : libs/libsodium/builds/msvc/version.h : common.copy - : @sodium-checked-out ; -explicit sodium/version.h version.h ; + : @sodium-checked-out $(.sodium-version) ; +explicit sodium/version.h ; # libsodium's configuration on each target, as libsodium's own configure finds # it at the pin, run once per target in a scratch copy (never the submodule): @@ -511,9 +511,13 @@ explicit sodium/version.h version.h ; # library) and _CRT_SECURE_NO_WARNINGS (left out: the CRT's headers read it, # no C file of libsodium's), and libsodium's private/common.h defines the # intrinsics' HAVE_* itself under _MSC_VER. CONFIGURED is webcpp's, as on -# every target; common.h does not require it under MSVC. +# every target; common.h does not require it under MSVC. inline=__inline is +# for C alone, a (MSVC's C++ compile never reads ): the C++ +# translation units of a program that uses sodium-test-config, among them, +# include the standard library's headers, which refuse a macro named after a +# keyword. .sodium-msvc = CONFIGURED=1 SODIUM_STATIC=1 - NATIVE_LITTLE_ENDIAN=1 inline=__inline ; + NATIVE_LITTLE_ENDIAN=1 /Dinline=__inline ; # The defines only libsodium's tests read, by the same configure runs. The # x86-64 macOS run, cross-compiled, could not run the checks of the catchable @@ -524,23 +528,30 @@ explicit sodium/version.h version.h ; HAVE_CATCHABLE_SEGV=1 ; # The architecture a native build is for, x86_64 or arm64, as configure's -# runs name them: and when the build asks for -# them, else the machine b2 runs on (b2's OSPLAT). Any other is returned as -# -, which sodium-target-defines refuses. +# runs name them: with , else the machine b2 +# runs on (b2's OSPLAT, X86_64 or ARM64, which names its model). A build that +# gives one of and without the other, or any +# other pair, is returned as -, which +# sodium-target-defines refuses: no model is guessed. local rule sodium-architecture ( properties * ) { local architecture = [ feature.get-values : $(properties) ] ; local model = [ feature.get-values : $(properties) ] ; - architecture ?= [ modules.peek : OSPLAT ] ; - model ?= 64 ; - switch $(architecture:L)-$(model) + if ! $(architecture) && ! $(model) + { + switch [ modules.peek : OSPLAT ] + { + case X86_64 : return x86_64 ; + case ARM64 : return arm64 ; + } + return [ modules.peek : OSPLAT ] ; + } + switch $(architecture:E=unknown)-$(model:E=unknown) { case x86-64 : return x86_64 ; - case x86_64-64 : return x86_64 ; case arm-64 : return arm64 ; - case arm64-64 : return arm64 ; } - return $(architecture:L)-$(model) ; + return $(architecture:E=unknown)-$(model:E=unknown) ; } # The defines of a build: the groups above by its target, its system, its @@ -601,10 +612,11 @@ lib sodium $(HASH)/src/canary_sodium.c : $(.hash-c-library) @sodium-checked-out @sodium-target-defines - sodium/version.h version.h - sodium/version.h libs/libsodium/src/libsodium/include + sodium/version.h sodium/version.h + libs/libsodium/src/libsodium/include libs/libsodium/src/libsodium/include/sodium - : : libs/libsodium/src/libsodium/include + $(.sodium-version) $(.sodium-version)/sodium + : : libs/libsodium/src/libsodium/include $(.sodium-version) sodium/version.h SODIUM_STATIC=1 WEBCPP_HASH_HAS_SODIUM=1 $(.gc) ; explicit sodium ; @@ -618,6 +630,6 @@ alias sodium-test-config : : @sodium-checked-out : : libs/libsodium/src/libsodium/include libs/libsodium/src/libsodium/include/sodium libs/libsodium/src/libsodium/crypto_pwhash/argon2 - sodium/version.h version.h - @sodium-target-defines @sodium-test-defines ; + $(.sodium-version) $(.sodium-version)/sodium + sodium/version.h @sodium-target-defines @sodium-test-defines ; explicit sodium-test-config ; diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 205a5bfe..3c20545a 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -565,6 +565,54 @@ def test_sodium_test_config_reaches_the_private_headers(root: Path) -> None: assert {'CONFIGURED=1', 'SODIUM_STATIC=1', 'HAVE_CLOCK_GETTIME=1'} <= defines_of(line[0]), line +def test_sodium_msvc_inline_reaches_c_alone(root: Path) -> None: + # MSVC's build of libsodium defines inline as __inline for its C files; a C++ translation unit + # of a program that uses sodium-test-config never gets it, since the standard library's headers + # refuse a macro named after a keyword. A dry run with a stand-in MSVC prints the commands. + harness.copy_integration_libraries(root, 'config', 'hash') + harness.add_library(root, 'sodium_msvc', 'import webcpp ;\n' + '\n' + 'webcpp.run both : both.cpp private.c\n' + ' : /third_party//sodium-test-config /third_party//sodium ;\n', + {'both.cpp': 'int main() { return 0; }\n', + 'private.c': 'int sodium_private(void) { return 0; }\n'}) + config = harness.user_config(root).read_text() + harness.configure(root, config + f'\nusing msvc : 14.3 : "{sys.executable}"' + ' : off ;\n') + jamroot = root / 'Jamroot' + original = jamroot.read_text() + # A foreign-toolset dry run cannot run cmd.exe for the configuration checks. + jamroot.write_text(original.replace('@boost-check', 'off')) + try: + result = harness.run_b2(root, '-a', '-n', '-d+2', 'toolset=msvc-14.3', + 'target-os=windows', 'architecture=x86', 'address-model=64', + 'libs/sodium_msvc/test') + finally: + jamroot.write_text(original) + harness.configure(root, config) + harness.expect(result, True) + lines = result.stdout.splitlines() + c_files = [line for line in lines if ' -TC ' in line and ('/libsodium/' in line + or 'private.c' in line)] + cpp_files = [line for line in lines if ' -TP ' in line and 'both.cpp' in line] + # The 141 files of libsodium, the canary and the program's own C file. + assert len(c_files) == 143, (len(c_files), result.stdout[-4000:]) + assert len(cpp_files) == 1, result.stdout[-4000:] + for line in c_files: + assert '/Dinline=__inline' in line, line + assert 'inline=' not in cpp_files[0], cpp_files[0] + + +def test_sodium_unknown_architecture_is_refused(root: Path) -> None: + # No configure run covers a 32-bit build, and a model is never guessed for an architecture + # given alone: each stops, naming what it is for. + harness.copy_integration_libraries(root, 'config', 'hash') + for request, named in ((('address-model=32',), 'on unknown-32'), + (('architecture=arm',), 'on arm-unknown')): + result = harness.run_b2(root, '-n', *request, 'third_party//sodium') + harness.expect(result, False, "libsodium's configuration is derived for", named) + + def test_sodium_not_checked_out_is_refused(root: Path) -> None: harness.copy_integration_libraries(root, 'config', 'hash') harness.third_party_of_its_own(root, 'libsodium', checked_out=False) @@ -613,6 +661,8 @@ def test_hash_not_checked_out_is_refused_by_sodium(root: Path) -> None: test_sodium_is_built_file_by_file, test_sodium_defines_on_each_webassembly_target, test_sodium_test_config_reaches_the_private_headers, + test_sodium_msvc_inline_reaches_c_alone, + test_sodium_unknown_architecture_is_refused, test_sodium_not_checked_out_is_refused, test_hash_not_checked_out_is_refused_by_sodium, ] From 65c742cb2597fec7047fb4621464c74f75b4100d Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 02:21:29 -0300 Subject: [PATCH 09/47] tools: third_party_test's list of cases without a stray blank line --- tools/test/third_party_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 3c20545a..d49eb58c 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -656,7 +656,6 @@ def test_hash_not_checked_out_is_refused_by_sodium(root: Path) -> None: test_xkcp_is_built_file_by_file, test_xkcp_not_checked_out_is_refused, test_hash_not_checked_out_is_refused, - test_sodium_is_pinned, test_sodium_is_built_file_by_file, test_sodium_defines_on_each_webassembly_target, From d260499227433ffc72dbc5740107eee555ae5af4 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 00:39:34 -0300 Subject: [PATCH 10/47] third_party: BLAKE3's C implementation, portable on WebAssembly and dispatched natively --- .gitmodules | 3 + CODING-GUIDELINES.md | 2 + doc/releases/0.1.0.adoc | 4 + third_party/Jamfile | 123 ++++++++++++++ third_party/libs/blake3 | 1 + tools/test/blake3_c_suite.py | 155 ++++++++++++++++++ tools/test/fixtures/blake3_c_suite/Jamfile | 19 +++ .../fixtures/blake3_c_suite/cpu_features.c | 26 +++ tools/test/third_party_test.py | 153 ++++++++++++++++- 9 files changed, 481 insertions(+), 5 deletions(-) create mode 160000 third_party/libs/blake3 create mode 100644 tools/test/blake3_c_suite.py create mode 100644 tools/test/fixtures/blake3_c_suite/Jamfile create mode 100644 tools/test/fixtures/blake3_c_suite/cpu_features.c diff --git a/.gitmodules b/.gitmodules index c37b23ae..a0542428 100644 --- a/.gitmodules +++ b/.gitmodules @@ -76,3 +76,6 @@ [submodule "third_party/libs/libsodium"] path = third_party/libs/libsodium url = https://github.com/jedisct1/libsodium.git +[submodule "third_party/libs/blake3"] + path = third_party/libs/blake3 + url = https://github.com/BLAKE3-team/BLAKE3.git diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index fa5b909c..5b4ef3b9 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -959,6 +959,8 @@ update --init third_party/libs/`; a build that needs none never looks. | `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 | | `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 | +| `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 | OpenSSL builds from a checkout or a source distribution. Before Configure, its builder stages the distributable tree and checks a digest of paths, Git file diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 0c859e58..0559a1c6 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -277,6 +277,10 @@ program that compiles against its private headers. * Added `off`, for a program of webcpp.run, webcpp.run-fail or webcpp.example that mounts on emscripten the host's directories it reads, where it reads them, as libsodium's own tests read `/test-data`. +* Added BLAKE3's C implementation 1.8.7, built from source as /third_party//blake3, +portable on WebAssembly and dispatched to its intrinsics files natively, its vectors as +/third_party//blake3_vectors, and tools/test/blake3_c_suite.py, which runs BLAKE3's own +test program on that build on every target. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/third_party/Jamfile b/third_party/Jamfile index da312df2..46aea4b6 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -633,3 +633,126 @@ alias sodium-test-config : : @sodium-checked-out : : $(.sodium-version) $(.sodium-version)/sodium sodium/version.h @sodium-target-defines @sodium-test-defines ; explicit sodium-test-config ; + +# BLAKE3's C implementation (CC0-1.0, or Apache-2.0, or Apache-2.0 with LLVM +# exception), c/ of BLAKE3-team/BLAKE3. blake3.c, blake3_dispatch.c and +# blake3_portable.c on every target; the intrinsics files only on the targets +# of their instruction sets, each with its flag, as BLAKE3's own CMake builds +# them where it has no assembler: they include x86 or Arm headers that no +# WebAssembly sysroot has (a recorded exception to CODING-GUIDELINES.md +# chapter 5 rule 2). BLAKE3's dispatcher chooses at run time. On WebAssembly +# the four BLAKE3_NO_* leave the portable code alone. Never BLAKE3_USE_TBB. +path-constant BLAKE3 : libs/blake3 ; + +rule blake3-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(BLAKE3)/c/blake3.h ] ] + { + errors.user-error "third_party/libs/blake3 is not checked out. Check it out with" + "`git submodule update --init third_party/libs/blake3`." ; + } +} + +# The instruction set a build of BLAKE3 is for: wasm on WebAssembly; natively +# x86-64 or arm64 from b2's and , as +# tools/webcpp-openssl.jam reads them; other for any other native target. b2 +# sets no on a native toolset unless the build request names +# one (clang and gcc compile for the machine then): each missing feature is +# then the machine's, from the platform b2 itself was built for (OSPLAT, +# X86_64 or ARM64), which the compiler of that machine targets by default. +rule blake3-architecture ( properties * ) +{ + if [ webcpp-target.target-of $(properties) ] != native + { + return wasm ; + } + local architecture = [ feature.get-values : $(properties) ] ; + local address-model = [ feature.get-values : $(properties) ] ; + switch [ modules.peek : OSPLAT ] + { + case X86_64 : architecture ?= x86 ; address-model ?= 64 ; + case ARM64 : architecture ?= arm ; address-model ?= 64 ; + } + if $(architecture) = x86 && $(address-model) = 64 + { + return x86-64 ; + } + if $(architecture) = arm && $(address-model) = 64 + { + return arm64 ; + } + return other ; +} + +# Each intrinsics file is an object of its own, so that its flag reaches it +# alone; on a target without its instruction set the object is empty of +# sources (b2's no), which the third_party test checks. +rule blake3-x86 ( properties * ) +{ + if [ blake3-architecture $(properties) ] = x86-64 + { + return ; + } + return no ; +} + +obj blake3_sse2 : libs/blake3/c/blake3_sse2.c + : $(.hash-c-library) @blake3-x86 clang:-msse2 + gcc:-msse2 ; +obj blake3_sse41 : libs/blake3/c/blake3_sse41.c + : $(.hash-c-library) @blake3-x86 clang:-msse4.1 + gcc:-msse4.1 ; +obj blake3_avx2 : libs/blake3/c/blake3_avx2.c + : $(.hash-c-library) @blake3-x86 clang:-mavx2 + gcc:-mavx2 msvc:/arch:AVX2 ; +obj blake3_avx512 : libs/blake3/c/blake3_avx512.c + : $(.hash-c-library) @blake3-x86 + clang:"-mavx512f -mavx512vl" + gcc:"-mavx512f -mavx512vl" + msvc:/arch:AVX512 ; +explicit blake3_sse2 blake3_sse41 blake3_avx2 blake3_avx512 ; + +# What each instruction set adds: on WebAssembly, and on a native target that +# is neither x86-64 nor arm64, the four BLAKE3_NO_*, the portable code alone; +# on x86-64 the four intrinsics objects; on arm64 the NEON file, which +# BLAKE3_USE_NEON=1 makes blake3_dispatch.c call. +rule blake3-profile ( properties * ) +{ + switch [ blake3-architecture $(properties) ] + { + case x86-64 : + return blake3_sse2 blake3_sse41 blake3_avx2 + blake3_avx512 ; + case arm64 : + return libs/blake3/c/blake3_neon.c BLAKE3_USE_NEON=1 ; + case * : + return BLAKE3_NO_SSE2 BLAKE3_NO_SSE41 + BLAKE3_NO_AVX2 BLAKE3_NO_AVX512 ; + } +} + +# BLAKE3's own test program (tools/test/blake3_c_suite.py) needs +# blake3_dispatch.c compiled with BLAKE3_TESTING, which makes the dispatcher's +# choice of instruction sets a global it sets, so that one run checks each. +# Propagated, so that the program's request reaches the library; off, the +# default, everywhere else. +feature.feature webcpp-blake3-testing : off on : propagated ; + +lib blake3 + : libs/blake3/c/blake3.c libs/blake3/c/blake3_dispatch.c + libs/blake3/c/blake3_portable.c $(HASH)/src/canary_blake3.c + : $(.hash-c-library) @blake3-checked-out libs/blake3/c + @blake3-profile on:BLAKE3_TESTING + : : libs/blake3/c WEBCPP_HASH_HAS_BLAKE3=1 $(.gc) ; +explicit blake3 ; + +# BLAKE3's official vectors, test_vectors/test_vectors.json at the pin, read at +# run time from the directory WEBCPP_TEST_BLAKE3_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. +.blake3-vectors = [ regex.replace $(BLAKE3)/test_vectors "\\\\" "/" ] ; +alias blake3_vectors : : @blake3-checked-out : : + "\"WEBCPP_TEST_BLAKE3_VECTORS=\\\"$(.blake3-vectors)\\\"\"" + [ webcpp.data $(BLAKE3)/test_vectors ] + libs/blake3/test_vectors/test_vectors.json ; +explicit blake3_vectors ; diff --git a/third_party/libs/blake3 b/third_party/libs/blake3 new file mode 160000 index 00000000..f3149ec5 --- /dev/null +++ b/third_party/libs/blake3 @@ -0,0 +1 @@ +Subproject commit f3149ec5bb5449af877ba20377a11008ff499fa2 diff --git a/tools/test/blake3_c_suite.py b/tools/test/blake3_c_suite.py new file mode 100644 index 00000000..57aa6df7 --- /dev/null +++ b/tools/test/blake3_c_suite.py @@ -0,0 +1,155 @@ +#!/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) + +"""Runs BLAKE3's own C test on webcpp's build of BLAKE3, on every target. + +BLAKE3's c/test.py runs c/blake3, a program built inside the submodule, where webcpp builds +nothing; and a library's test Jamfile may not declare b2's raw exe. So this test of the tools +builds the fixture tools/test/fixtures/blake3_c_suite, c/main.c linked with /third_party//blake3 +(with BLAKE3_TESTING, so that one run checks each instruction set the machine has), on a scratch +superproject for each target, and runs it over every case of test_vectors/test_vectors.json as +c/test.py does: the input of a case is i % 251 for each i below input_len, on standard input; +the program runs with no argument, with --length , with --keyed and with +--derive-key , each also with the output's whole length, and every line it prints is +compared with the file's. Natively the program runs directly, on wasip2 and wasip3 through +tools/boost/asio-wasip/run.sh, on Emscripten through node. It prints +"blake3 c suite: : cases ok" per target, or the first difference, and exits non-zero +on a difference. Run with --target to run one target.""" + +from __future__ import annotations + +import concurrent.futures +import json +import platform +import shutil +import subprocess +import sys +from pathlib import Path + +import harness + +FIXTURE = 'tools/test/fixtures/blake3_c_suite' +VECTORS = harness.ROOT / 'third_party/libs/blake3/test_vectors/test_vectors.json' +TOOLSETS = {'native': [], 'wasip2': ['toolset=clang-wasip2'], 'wasip3': ['toolset=clang-wasip3'], + 'emscripten': ['toolset=emscripten']} +WINDOWS = platform.system() == 'Windows' + +# The programs of a target run at once, each a process of its own. +WORKERS = 8 + + +class Difference(Exception): + """A line the program printed that is not the file's, or a run that failed.""" + + +def node() -> str: + """The node the emscripten toolset of user-config.jam runs, this checkout's + .local/emscripten/node, else the one on PATH.""" + local = harness.ROOT / '.local/emscripten/node' + return str(local) if local.exists() else 'node' + + +def program_command(build_dir: Path, target: str) -> list[str]: + """The command that runs blake3_main, which the build made under build_dir, as its lane runs + a program.""" + suffix = {'native': '.exe' if WINDOWS else '', 'wasip2': '.wasm', 'wasip3': '.wasm', + 'emscripten': '.js'}[target] + found = [p for p in build_dir.rglob('blake3_main' + suffix) if p.is_file()] + if len(found) != 1: + raise AssertionError(f'the build made {len(found)} files named blake3_main{suffix}') + if target == 'emscripten': + return [node(), str(found[0])] + if target.startswith('wasi'): + return [str(harness.ROOT / f'tools/boost/asio-{target}/run.sh'), str(found[0])] + return [str(found[0])] + + +def make_input(length: int) -> bytes: + """c/test.py's input: the bytes i % 251 for each i below length.""" + return bytes(i % 251 for i in range(length)) + + +def runs(vectors: dict) -> list[tuple[str, list[str], bytes, str]]: + """Every run of the suite, c/test.py's six per case: its name, the program's arguments, its + input, and the line each of its output lines must equal.""" + key = vectors['key'].encode().hex() + context = vectors['context_string'] + result = [] + for case in vectors['cases']: + length = case['input_len'] + data = make_input(length) + for mode, arguments in (('hash', []), ('keyed_hash', ['--keyed', key]), + ('derive_key', ['--derive-key', context])): + expected = case[mode] + result.append((f'{mode}({length})', arguments, data, expected[:64])) + result.append((f'{mode}_xof({length})', + arguments + ['--length', str(len(expected) // 2)], data, expected)) + return result + + +def run_one(command: list[str], name: str, arguments: list[str], data: bytes, + expected: str) -> None: + """Runs the program once and raises Difference unless it succeeds and every line it prints + is expected.""" + ran = subprocess.run(command + arguments, input=data, capture_output=True, check=False) + if ran.returncode != 0: + raise Difference(f'{name}: {" ".join(arguments)} exited {ran.returncode}: ' + f'{ran.stderr.decode(errors="replace")[-2000:]}') + lines = ran.stdout.decode(errors='replace').split() + if not lines: + raise Difference(f'{name}: {" ".join(arguments)} printed nothing') + for line in lines: + if line != expected: + raise Difference(f'{name}: {expected} != {line}') + + +def run_target(target: str, vectors: dict) -> int: + """Builds the fixture for target on a scratch superproject, runs the suite with it and returns + the number of cases; raises Difference at the first difference.""" + root = harness.scratch_superproject() + try: + harness.copy_integration_libraries(root, 'config', 'hash') + if target == 'emscripten': + harness.link_emsdk(root) + elif target.startswith('wasi'): + harness.link_wasi_tools(root) + build_dir = root / 'bin' / f'blake3-{target}' + built = harness.run_b2(root, '-j4', f'--build-dir={build_dir}', *TOOLSETS[target], + FIXTURE) + if built.returncode != 0: + raise Difference(f'the build failed:\n{built.stdout[-4000:]}') + command = program_command(build_dir, target) + with concurrent.futures.ThreadPoolExecutor(WORKERS) as pool: + futures = [pool.submit(run_one, command, *run) for run in runs(vectors)] + for future in futures: + future.result() + return len(vectors['cases']) + finally: + shutil.rmtree(root) + + +def main(argv: list[str]) -> int: + targets = list(TOOLSETS) + if argv: + if len(argv) != 2 or argv[0] != '--target' or argv[1] not in TOOLSETS: + print(f'blake3 c suite: the one option is --target ', + file=sys.stderr) + return 2 + targets = [argv[1]] + vectors = json.loads(VECTORS.read_text()) + for target in targets: + try: + cases = run_target(target, vectors) + except Difference as difference: + print(f'blake3 c suite: {target}: {difference}') + return 1 + print(f'blake3 c suite: {target}: {cases} cases ok') + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/tools/test/fixtures/blake3_c_suite/Jamfile b/tools/test/fixtures/blake3_c_suite/Jamfile new file mode 100644 index 00000000..9e7748d9 --- /dev/null +++ b/tools/test/fixtures/blake3_c_suite/Jamfile @@ -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) + +# BLAKE3's own test program, c/main.c with BLAKE3_TESTING, on webcpp's build of +# BLAKE3; tools/test/blake3_c_suite.py drives it as c/test.py drives c/blake3. +# BLAKE3_TESTING must reach blake3_dispatch.c, which declares the global +# main.c sets: on, propagated, builds the library so. +# Off x86 the dispatcher has neither, and cpu_features.c defines them. On +# Emscripten node reads standard input through the host's file descriptor +# (-sNODERAWFS=1, as webcpp.run links a program node runs): Emscripten's +# default terminal decodes it as UTF-8, which changes every byte above 127. +path-constant BLAKE3 : ../../../../third_party/libs/blake3 ; +exe blake3_main : $(BLAKE3)/c/main.c cpu_features.c + : /third_party//blake3 on + BLAKE3_TESTING off off + emscripten:-sNODERAWFS=1 ; diff --git a/tools/test/fixtures/blake3_c_suite/cpu_features.c b/tools/test/fixtures/blake3_c_suite/cpu_features.c new file mode 100644 index 00000000..228f17ac --- /dev/null +++ b/tools/test/fixtures/blake3_c_suite/cpu_features.c @@ -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) + * + * BLAKE3's c/main.c sets g_cpu_features and reads get_cpu_features(), which + * blake3_dispatch.c defines under BLAKE3_TESTING only on x86 (upstream runs its + * C test on x86 alone). Off x86 the dispatcher reads no CPU features: it calls + * NEON when built with BLAKE3_USE_NEON=1, else the portable code. So there the + * two are defined here, as the dispatcher would: no feature to choose, one run + * of each case. On x86 this file defines nothing and BLAKE3's own are linked. */ +#include "blake3_impl.h" + +#if !defined(IS_X86) +enum cpu_feature { UNDEFINED = 1 << 30 }; + +enum cpu_feature g_cpu_features = UNDEFINED; + +enum cpu_feature get_cpu_features(void) { + return (enum cpu_feature)0; +} +#else +/* ISO C wants a declaration in every translation unit. */ +typedef int webcpp_blake3_c_suite_on_x86; +#endif diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index d49eb58c..f09749c7 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -16,11 +16,13 @@ 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. 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. Run with the names of some cases to run only those.""" +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. +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.""" from __future__ import annotations @@ -49,6 +51,23 @@ # The commit ctaes's submodule, Bitcoin Core v31.1, is pinned at. BITCOIN_COMMIT = '9be056a8a72b624dae9623b2f7bded92c2a21c91' +BLAKE3 = 'third_party/libs/blake3' + +# BLAKE3 1.8.7, the commit it is pinned at. +BLAKE3_COMMIT = 'f3149ec5bb5449af877ba20377a11008ff499fa2' + +# The C files /third_party//blake3 compiles on every target: BLAKE3's three and webcpp::hash's +# canary. +BLAKE3_FILES = ['blake3.c', 'blake3_dispatch.c', 'blake3_portable.c', 'canary_blake3.c'] + +# The intrinsics files of x86-64, each with the flags of its instruction set. +BLAKE3_X86 = {'blake3_sse2.c': ['-msse2'], 'blake3_sse41.c': ['-msse4.1'], + 'blake3_avx2.c': ['-mavx2'], 'blake3_avx512.c': ['-mavx512f', '-mavx512vl']} + +# What leaves BLAKE3's portable code alone, on WebAssembly. +BLAKE3_PORTABLE = ['-DBLAKE3_NO_SSE2', '-DBLAKE3_NO_SSE41', '-DBLAKE3_NO_AVX2', + '-DBLAKE3_NO_AVX512'] + PASSED = re.compile(r'^\*\*passed\*\* (.*)$', re.MULTILINE) SUITE = 'third_party/libs/JSON-Schema-Test-Suite' @@ -626,6 +645,123 @@ def test_sodium_not_checked_out_is_refused(root: Path) -> None: def test_hash_not_checked_out_is_refused_by_sodium(root: Path) -> None: # No libs/hash in the scratch superproject: the canary is missing. result = harness.run_b2(root, 'third_party//sodium') + +def build_blake3(root: Path, *request: str) -> tuple[dict[str, str], Path]: + """Builds /third_party//blake3 with every action shown, from libs/hash's real canary, and + returns its C compile lines by file name and its archive.""" + harness.copy_integration_libraries(root, 'config', 'hash') + result = harness.run_b2(root, '-a', '-d+2', *request, 'third_party//blake3') + harness.expect(result, True) + lines = C_COMPILE.findall(result.stdout) + compiled = {Path(line.rsplit(' ', 1)[-1].strip('"')).name: line for line in lines} + assert len(compiled) == len(lines), lines + archives = sorted((root / 'bin').rglob('libblake3.a')) + assert len(archives) == 1, archives + return compiled, archives[0] + + +def blake3_canary(configuration: str) -> str: + """The symbol of BLAKE3's canary for configuration.""" + return (f'webcpp_hash_blake3_f3149ec_{configuration}' + '__add_third_party_blake3_to_your_link') + + +def expect_blake3_portable(compiled: dict[str, str], archive: Path) -> None: + """Asserts that the three portable files and the canary alone were compiled, each with the + four BLAKE3_NO_* and no flag of an instruction set, and that the archive holds the canary of + the portable configuration.""" + assert sorted(compiled) == sorted(BLAKE3_FILES), sorted(compiled) + for line in compiled.values(): + for define in BLAKE3_PORTABLE: + assert define in line.split(), (define, line) + assert '-DBLAKE3_USE_NEON=1' not in line.split(), line + assert not re.search(r' -m(sse|avx)', line), line + assert '-std=' not in line, line + assert blake3_canary('portable').encode() in archive.read_bytes() + + +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) + assert listed.stdout.split()[:2] == ['160000', BLAKE3_COMMIT], listed.stdout + + +def test_blake3_natively_has_the_machines_simd_files(root: Path) -> None: + compiled, archive = build_blake3(root) + machine = platform.machine().lower() + if machine in ('arm64', 'aarch64'): + expected = BLAKE3_FILES + ['blake3_neon.c'] + configuration = 'neon' + else: + assert machine in ('x86_64', 'amd64'), machine + expected = BLAKE3_FILES + list(BLAKE3_X86) + configuration = 'x86' + assert sorted(compiled) == sorted(expected), sorted(compiled) + for name, line in compiled.items(): + words = line.split() + for flag in ('-ffunction-sections', '-fdata-sections'): + assert flag in words, (flag, line) + assert '-std=' not in line, line + for define in BLAKE3_PORTABLE: + assert define not in words, (define, line) + assert ('-DBLAKE3_USE_NEON=1' in words) == (configuration == 'neon'), line + # Each intrinsics file has its own flags, and no other file has any. + own = BLAKE3_X86.get(name, []) + for flags in BLAKE3_X86.values(): + for flag in flags: + assert (flag in words) == (flag in own), (flag, line) + symbols = subprocess.run(['nm', str(archive)], capture_output=True, text=True, check=True) + prefix = '_' if sys.platform == 'darwin' else '' + canary = prefix + blake3_canary(configuration) + assert canary in symbols.stdout.split(), symbols.stdout[-2000:] + + +def test_blake3_on_x86_64_declares_the_intrinsics_files(root: Path) -> None: + # Whatever the machine, a native x86-64 build, shown and not run, compiles the four + # intrinsics files, each with its own flags. + harness.copy_integration_libraries(root, 'config', 'hash') + result = harness.run_b2(root, '-n', '-a', 'architecture=x86', 'address-model=64', + 'third_party//blake3') + harness.expect(result, True) + lines = C_COMPILE.findall(result.stdout) + compiled = {Path(line.rsplit(' ', 1)[-1].strip('"')).name: line for line in lines} + assert sorted(compiled) == sorted(BLAKE3_FILES + list(BLAKE3_X86)), sorted(compiled) + for name, line in compiled.items(): + words = line.split() + own = BLAKE3_X86.get(name, []) + for flags in BLAKE3_X86.values(): + for flag in flags: + assert (flag in words) == (flag in own), (flag, line) + assert '-DBLAKE3_USE_NEON=1' not in words, line + for define in BLAKE3_PORTABLE: + assert define not in words, (define, line) + + +def test_blake3_on_wasi_is_portable(root: Path) -> None: + for request in (WASIP2, WASIP3): + expect_blake3_portable(*build_blake3(root, *request)) + shutil.rmtree(root / 'bin') + + +def test_blake3_on_emscripten_is_portable(root: Path) -> None: + harness.link_emsdk(root) + expect_blake3_portable(*build_blake3(root, *EMSCRIPTEN)) + + +def test_blake3_not_checked_out_is_refused(root: Path) -> None: + harness.third_party_of_its_own(root, 'blake3', checked_out=False) + harness.copy_integration_libraries(root, 'config', 'hash') + for target in ('third_party//blake3', 'third_party//blake3_vectors'): + result = harness.run_b2(root, target) + harness.expect(result, False, 'third_party/libs/blake3 is not checked out', + 'git submodule update --init third_party/libs/blake3') + # A build that needs no BLAKE3 never looks for it. + harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) + + +def test_hash_not_checked_out_stops_blake3(root: Path) -> None: + # No libs/hash in the scratch superproject: the canary is missing. + result = harness.run_b2(root, 'third_party//blake3') harness.expect(result, False, 'libs/hash is not checked out', 'git submodule update --init libs/hash') @@ -664,6 +800,13 @@ def test_hash_not_checked_out_is_refused_by_sodium(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_blake3_is_pinned, + test_blake3_natively_has_the_machines_simd_files, + test_blake3_on_x86_64_declares_the_intrinsics_files, + test_blake3_on_wasi_is_portable, + test_blake3_on_emscripten_is_portable, + test_blake3_not_checked_out_is_refused, + test_hash_not_checked_out_stops_blake3, ] From f7541c12fa3a8c63090ee0dcfa6d3288c863413c Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 01:42:44 -0300 Subject: [PATCH 11/47] third_party: BLAKE3's instruction set from a probe of the configured compiler --- doc/releases/0.1.0.adoc | 5 +- third_party/Jamfile | 40 +++-- third_party/probes/blake3_arm64.c | 19 +++ third_party/probes/blake3_x86_64.c | 19 +++ tools/test/blake3_c_suite.py | 155 ------------------ tools/test/fixtures/blake3_c_suite/Jamfile | 19 --- .../fixtures/blake3_c_suite/cpu_features.c | 26 --- 7 files changed, 68 insertions(+), 215 deletions(-) create mode 100644 third_party/probes/blake3_arm64.c create mode 100644 third_party/probes/blake3_x86_64.c delete mode 100644 tools/test/blake3_c_suite.py delete mode 100644 tools/test/fixtures/blake3_c_suite/Jamfile delete mode 100644 tools/test/fixtures/blake3_c_suite/cpu_features.c diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 0559a1c6..9e4033be 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -279,8 +279,9 @@ that mounts on emscripten the host's directories it reads, where it reads them, tests read `/test-data`. * Added BLAKE3's C implementation 1.8.7, built from source as /third_party//blake3, portable on WebAssembly and dispatched to its intrinsics files natively, its vectors as -/third_party//blake3_vectors, and tools/test/blake3_c_suite.py, which runs BLAKE3's own -test program on that build on every target. +/third_party//blake3_vectors, and the feature webcpp-blake3-testing, which builds it +with BLAKE3_TESTING for BLAKE3's own test program. On a native toolset whose build request +names no architecture, the configured compiler is probed for x86-64 or arm64. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/third_party/Jamfile b/third_party/Jamfile index 46aea4b6..2a0694b9 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -11,9 +11,9 @@ # checked out stops the build that needs it, naming the command that checks # it out; a build that needs none never looks. The C libraries of # webcpp::crypto's backends are built here from their own sources, file by file. +import configure ; import errors ; import feature ; -import modules ; import path ; import project ; import regex ; @@ -654,12 +654,20 @@ rule blake3-checked-out ( properties * ) } # The instruction set a build of BLAKE3 is for: wasm on WebAssembly; natively -# x86-64 or arm64 from b2's and , as -# tools/webcpp-openssl.jam reads them; other for any other native target. b2 -# sets no on a native toolset unless the build request names -# one (clang and gcc compile for the machine then): each missing feature is -# then the machine's, from the platform b2 itself was built for (OSPLAT, -# X86_64 or ARM64), which the compiler of that machine targets by default. +# x86-64, arm64 or other. A request that names both and +# is taken as it names them. Else the configured compiler is +# asked, as tools/openssl/build.py asks it for OpenSSL's target: b2 sets +# neither feature on a native toolset unless the request does, and the +# compiler then builds for whatever it defaults to (MSVC for the host's +# PROCESSOR_ARCHITECTURE, whatever b2 itself was built for). Each probe, +# probes/blake3_.c, compiles only when the macros that blake3.hpp and +# src/canary_blake3.c read say x86-64 (__x86_64__, _M_X64) or arm64 +# (__aarch64__, _M_ARM64), so that the build, the canary and the header +# cannot disagree. +obj blake3_probe_x86_64 : probes/blake3_x86_64.c : off ; +obj blake3_probe_arm64 : probes/blake3_arm64.c : off ; +explicit blake3_probe_x86_64 blake3_probe_arm64 ; + rule blake3-architecture ( properties * ) { if [ webcpp-target.target-of $(properties) ] != native @@ -668,16 +676,22 @@ rule blake3-architecture ( properties * ) } local architecture = [ feature.get-values : $(properties) ] ; local address-model = [ feature.get-values : $(properties) ] ; - switch [ modules.peek : OSPLAT ] + if $(architecture) && $(address-model) { - case X86_64 : architecture ?= x86 ; address-model ?= 64 ; - case ARM64 : architecture ?= arm ; address-model ?= 64 ; + switch $(architecture)-$(address-model) + { + case x86-64 : return x86-64 ; + case arm-64 : return arm64 ; + case * : return other ; + } } - if $(architecture) = x86 && $(address-model) = 64 + if [ configure.builds /webcpp/third_party//blake3_probe_x86_64 : $(properties) + : "BLAKE3's compiler targets x86-64" ] { return x86-64 ; } - if $(architecture) = arm && $(address-model) = 64 + if [ configure.builds /webcpp/third_party//blake3_probe_arm64 : $(properties) + : "BLAKE3's compiler targets arm64" ] { return arm64 ; } @@ -731,7 +745,7 @@ rule blake3-profile ( properties * ) } } -# BLAKE3's own test program (tools/test/blake3_c_suite.py) needs +# BLAKE3's own test program (libs/hash/test/c_suites, the lane c-suites) needs # blake3_dispatch.c compiled with BLAKE3_TESTING, which makes the dispatcher's # choice of instruction sets a global it sets, so that one run checks each. # Propagated, so that the program's request reaches the library; off, the diff --git a/third_party/probes/blake3_arm64.c b/third_party/probes/blake3_arm64.c new file mode 100644 index 00000000..8cf38c36 --- /dev/null +++ b/third_party/probes/blake3_arm64.c @@ -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) + * + * third_party/Jamfile's probe of the configured compiler: it compiles only for + * arm64, read from the macros that webcpp::hash's blake3.hpp and + * src/canary_blake3.c read, so that the build of /third_party//blake3, its + * canary and the header agree on the instruction set. */ +#if !(defined(__aarch64__) || defined(_M_ARM64)) +#error "not arm64" +#endif + +int webcpp_blake3_probe_arm64(void); + +int webcpp_blake3_probe_arm64(void) { + return 0; +} diff --git a/third_party/probes/blake3_x86_64.c b/third_party/probes/blake3_x86_64.c new file mode 100644 index 00000000..83226b35 --- /dev/null +++ b/third_party/probes/blake3_x86_64.c @@ -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) + * + * third_party/Jamfile's probe of the configured compiler: it compiles only for + * x86-64, read from the macros that webcpp::hash's blake3.hpp and + * src/canary_blake3.c read, so that the build of /third_party//blake3, its + * canary and the header agree on the instruction set. */ +#if !(defined(__x86_64__) || defined(_M_X64)) +#error "not x86-64" +#endif + +int webcpp_blake3_probe_x86_64(void); + +int webcpp_blake3_probe_x86_64(void) { + return 0; +} diff --git a/tools/test/blake3_c_suite.py b/tools/test/blake3_c_suite.py deleted file mode 100644 index 57aa6df7..00000000 --- a/tools/test/blake3_c_suite.py +++ /dev/null @@ -1,155 +0,0 @@ -#!/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) - -"""Runs BLAKE3's own C test on webcpp's build of BLAKE3, on every target. - -BLAKE3's c/test.py runs c/blake3, a program built inside the submodule, where webcpp builds -nothing; and a library's test Jamfile may not declare b2's raw exe. So this test of the tools -builds the fixture tools/test/fixtures/blake3_c_suite, c/main.c linked with /third_party//blake3 -(with BLAKE3_TESTING, so that one run checks each instruction set the machine has), on a scratch -superproject for each target, and runs it over every case of test_vectors/test_vectors.json as -c/test.py does: the input of a case is i % 251 for each i below input_len, on standard input; -the program runs with no argument, with --length , with --keyed and with ---derive-key , each also with the output's whole length, and every line it prints is -compared with the file's. Natively the program runs directly, on wasip2 and wasip3 through -tools/boost/asio-wasip/run.sh, on Emscripten through node. It prints -"blake3 c suite: : cases ok" per target, or the first difference, and exits non-zero -on a difference. Run with --target to run one target.""" - -from __future__ import annotations - -import concurrent.futures -import json -import platform -import shutil -import subprocess -import sys -from pathlib import Path - -import harness - -FIXTURE = 'tools/test/fixtures/blake3_c_suite' -VECTORS = harness.ROOT / 'third_party/libs/blake3/test_vectors/test_vectors.json' -TOOLSETS = {'native': [], 'wasip2': ['toolset=clang-wasip2'], 'wasip3': ['toolset=clang-wasip3'], - 'emscripten': ['toolset=emscripten']} -WINDOWS = platform.system() == 'Windows' - -# The programs of a target run at once, each a process of its own. -WORKERS = 8 - - -class Difference(Exception): - """A line the program printed that is not the file's, or a run that failed.""" - - -def node() -> str: - """The node the emscripten toolset of user-config.jam runs, this checkout's - .local/emscripten/node, else the one on PATH.""" - local = harness.ROOT / '.local/emscripten/node' - return str(local) if local.exists() else 'node' - - -def program_command(build_dir: Path, target: str) -> list[str]: - """The command that runs blake3_main, which the build made under build_dir, as its lane runs - a program.""" - suffix = {'native': '.exe' if WINDOWS else '', 'wasip2': '.wasm', 'wasip3': '.wasm', - 'emscripten': '.js'}[target] - found = [p for p in build_dir.rglob('blake3_main' + suffix) if p.is_file()] - if len(found) != 1: - raise AssertionError(f'the build made {len(found)} files named blake3_main{suffix}') - if target == 'emscripten': - return [node(), str(found[0])] - if target.startswith('wasi'): - return [str(harness.ROOT / f'tools/boost/asio-{target}/run.sh'), str(found[0])] - return [str(found[0])] - - -def make_input(length: int) -> bytes: - """c/test.py's input: the bytes i % 251 for each i below length.""" - return bytes(i % 251 for i in range(length)) - - -def runs(vectors: dict) -> list[tuple[str, list[str], bytes, str]]: - """Every run of the suite, c/test.py's six per case: its name, the program's arguments, its - input, and the line each of its output lines must equal.""" - key = vectors['key'].encode().hex() - context = vectors['context_string'] - result = [] - for case in vectors['cases']: - length = case['input_len'] - data = make_input(length) - for mode, arguments in (('hash', []), ('keyed_hash', ['--keyed', key]), - ('derive_key', ['--derive-key', context])): - expected = case[mode] - result.append((f'{mode}({length})', arguments, data, expected[:64])) - result.append((f'{mode}_xof({length})', - arguments + ['--length', str(len(expected) // 2)], data, expected)) - return result - - -def run_one(command: list[str], name: str, arguments: list[str], data: bytes, - expected: str) -> None: - """Runs the program once and raises Difference unless it succeeds and every line it prints - is expected.""" - ran = subprocess.run(command + arguments, input=data, capture_output=True, check=False) - if ran.returncode != 0: - raise Difference(f'{name}: {" ".join(arguments)} exited {ran.returncode}: ' - f'{ran.stderr.decode(errors="replace")[-2000:]}') - lines = ran.stdout.decode(errors='replace').split() - if not lines: - raise Difference(f'{name}: {" ".join(arguments)} printed nothing') - for line in lines: - if line != expected: - raise Difference(f'{name}: {expected} != {line}') - - -def run_target(target: str, vectors: dict) -> int: - """Builds the fixture for target on a scratch superproject, runs the suite with it and returns - the number of cases; raises Difference at the first difference.""" - root = harness.scratch_superproject() - try: - harness.copy_integration_libraries(root, 'config', 'hash') - if target == 'emscripten': - harness.link_emsdk(root) - elif target.startswith('wasi'): - harness.link_wasi_tools(root) - build_dir = root / 'bin' / f'blake3-{target}' - built = harness.run_b2(root, '-j4', f'--build-dir={build_dir}', *TOOLSETS[target], - FIXTURE) - if built.returncode != 0: - raise Difference(f'the build failed:\n{built.stdout[-4000:]}') - command = program_command(build_dir, target) - with concurrent.futures.ThreadPoolExecutor(WORKERS) as pool: - futures = [pool.submit(run_one, command, *run) for run in runs(vectors)] - for future in futures: - future.result() - return len(vectors['cases']) - finally: - shutil.rmtree(root) - - -def main(argv: list[str]) -> int: - targets = list(TOOLSETS) - if argv: - if len(argv) != 2 or argv[0] != '--target' or argv[1] not in TOOLSETS: - print(f'blake3 c suite: the one option is --target ', - file=sys.stderr) - return 2 - targets = [argv[1]] - vectors = json.loads(VECTORS.read_text()) - for target in targets: - try: - cases = run_target(target, vectors) - except Difference as difference: - print(f'blake3 c suite: {target}: {difference}') - return 1 - print(f'blake3 c suite: {target}: {cases} cases ok') - return 0 - - -if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) diff --git a/tools/test/fixtures/blake3_c_suite/Jamfile b/tools/test/fixtures/blake3_c_suite/Jamfile deleted file mode 100644 index 9e7748d9..00000000 --- a/tools/test/fixtures/blake3_c_suite/Jamfile +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2026 WebCpp.org -# -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# https://www.boost.org/LICENSE_1_0.txt) - -# BLAKE3's own test program, c/main.c with BLAKE3_TESTING, on webcpp's build of -# BLAKE3; tools/test/blake3_c_suite.py drives it as c/test.py drives c/blake3. -# BLAKE3_TESTING must reach blake3_dispatch.c, which declares the global -# main.c sets: on, propagated, builds the library so. -# Off x86 the dispatcher has neither, and cpu_features.c defines them. On -# Emscripten node reads standard input through the host's file descriptor -# (-sNODERAWFS=1, as webcpp.run links a program node runs): Emscripten's -# default terminal decodes it as UTF-8, which changes every byte above 127. -path-constant BLAKE3 : ../../../../third_party/libs/blake3 ; -exe blake3_main : $(BLAKE3)/c/main.c cpu_features.c - : /third_party//blake3 on - BLAKE3_TESTING off off - emscripten:-sNODERAWFS=1 ; diff --git a/tools/test/fixtures/blake3_c_suite/cpu_features.c b/tools/test/fixtures/blake3_c_suite/cpu_features.c deleted file mode 100644 index 228f17ac..00000000 --- a/tools/test/fixtures/blake3_c_suite/cpu_features.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (c) 2026 WebCpp.org - * - * Distributed under the Boost Software License, Version 1.0. (See - * accompanying file LICENSE_1_0.txt or copy at - * https://www.boost.org/LICENSE_1_0.txt) - * - * BLAKE3's c/main.c sets g_cpu_features and reads get_cpu_features(), which - * blake3_dispatch.c defines under BLAKE3_TESTING only on x86 (upstream runs its - * C test on x86 alone). Off x86 the dispatcher reads no CPU features: it calls - * NEON when built with BLAKE3_USE_NEON=1, else the portable code. So there the - * two are defined here, as the dispatcher would: no feature to choose, one run - * of each case. On x86 this file defines nothing and BLAKE3's own are linked. */ -#include "blake3_impl.h" - -#if !defined(IS_X86) -enum cpu_feature { UNDEFINED = 1 << 30 }; - -enum cpu_feature g_cpu_features = UNDEFINED; - -enum cpu_feature get_cpu_features(void) { - return (enum cpu_feature)0; -} -#else -/* ISO C wants a declaration in every translation unit. */ -typedef int webcpp_blake3_c_suite_on_x86; -#endif From 7c6a45c6220d5b259e4615821f97905564349b5e Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 02:20:40 -0300 Subject: [PATCH 12/47] third_party: BLAKE3's MSVC flags quoted, as b2 reads a colon --- third_party/Jamfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index 2a0694b9..f484c4cf 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -718,12 +718,12 @@ obj blake3_sse41 : libs/blake3/c/blake3_sse41.c gcc:-msse4.1 ; obj blake3_avx2 : libs/blake3/c/blake3_avx2.c : $(.hash-c-library) @blake3-x86 clang:-mavx2 - gcc:-mavx2 msvc:/arch:AVX2 ; + gcc:-mavx2 msvc:"/arch:AVX2" ; obj blake3_avx512 : libs/blake3/c/blake3_avx512.c : $(.hash-c-library) @blake3-x86 clang:"-mavx512f -mavx512vl" gcc:"-mavx512f -mavx512vl" - msvc:/arch:AVX512 ; + msvc:"/arch:AVX512" ; explicit blake3_sse2 blake3_sse41 blake3_avx2 blake3_avx512 ; # What each instruction set adds: on WebAssembly, and on a native target that From f3ff21d48e714793ff052606e567750ef9b05dc9 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 02:45:19 -0300 Subject: [PATCH 13/47] third_party: BearSSL carries webcpp::hash's canary --- CODING-GUIDELINES.md | 8 ++++---- doc/releases/0.1.0.adoc | 2 ++ third_party/Jamfile | 32 +++++++++++++++++++++++++++++++- tools/test/third_party_test.py | 34 +++++++++++++++++++++++++++------- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 5b4ef3b9..8412b0bf 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -947,8 +947,10 @@ update --init third_party/libs/`; a build that needs none never looks. | Target | What it is | Licence | | --- | --- | --- | -| `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 canary, on every target; `WEBCPP_CRYPTO_HAS_BEARSSL=1` | MIT | +| `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 | +| `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 | | `ctaes` | `src/crypto/ctaes` of `bitcoin/bitcoin` v31.1 at `9be056a` (commit `9be056a8a72b624dae9623b2f7bded92c2a21c91`), the submodule `third_party/libs/bitcoin`, shallow; `third_party/Jamfile` compiles its `ctaes.c` alone, with webcpp::crypto's canary, on every target (`WEBCPP_CRYPTO_HAS_CTAES=1`); the tree's `src/secp256k1/` subtree is never on an include path and no glob over `third_party/libs` reaches it | MIT | | `json-schema-test-suite` | the JSON Schema Test Suite at `5b0ee16` (2026-09-21), test data: a test that names it reads the suite at run time from the directory its define `WEBCPP_TEST_JSON_SCHEMA_TEST_SUITE` gives, on every target (wasmtime is given it, `webcpp.data`), and runs again when a file of the suite changes | MIT | @@ -956,11 +958,9 @@ update --init third_party/libs/`; a build that needs none never looks. | `nativejson-benchmark` | Milo Yip's nativejson-benchmark at `478d572` (2022-10-28), test data: document's benchmarks (`libs/document/bench`) read its `data/canada.json`, `data/citm_catalog.json` and `data/twitter.json` at run time under the directory its define `WEBCPP_TEST_NATIVEJSON_BENCHMARK` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of them changes; its own submodules are never checked out | MIT | | `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 | | `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 | -| `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 | -| `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 | OpenSSL builds from a checkout or a source distribution. Before Configure, its builder stages the distributable tree and checks a digest of paths, Git file diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 9e4033be..ef599dc1 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -282,6 +282,8 @@ portable on WebAssembly and dispatched to its intrinsics files natively, its vec /third_party//blake3_vectors, and the feature webcpp-blake3-testing, which builds it with BLAKE3_TESTING for BLAKE3's own test program. On a native toolset whose build request names no architecture, the configured compiler is probed for x86-64 or arm64. +* Changed /third_party//bearssl to carry webcpp::hash's canary beside webcpp::crypto's, +and WEBCPP_HASH_HAS_BEARSSL, when libs/hash is checked out. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/third_party/Jamfile b/third_party/Jamfile index f484c4cf..de39248e 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -248,11 +248,15 @@ rule bearssl-seeder ( properties * ) alias bearssl-test-config : : : : $(.bearssl-config) libs/bearssl/src ; explicit bearssl-test-config ; +# webcpp::hash's canary joins crypto's when libs/hash is checked out +# (bearssl-hash-canary, after the C libraries of webcpp::hash below). lib bearssl : [ glob libs/bearssl/src/*.c libs/bearssl/src/*/*.c ] $(CRYPTO)/src/canary_bearssl.c : $(.c-library) @bearssl-checked-out libs/bearssl/inc libs/bearssl/src $(.bearssl-config) - : : libs/bearssl/inc WEBCPP_CRYPTO_HAS_BEARSSL=1 $(.gc) ; + @bearssl-hash-canary + : : libs/bearssl/inc WEBCPP_CRYPTO_HAS_BEARSSL=1 $(.gc) + @bearssl-hash-usage ; explicit bearssl ; # ctaes (MIT), Pieter Wuille's constant-time AES as Bitcoin Core v31.1 ships it @@ -363,6 +367,32 @@ rule hash-checked-out ( properties * ) msvc:"/Gy /Gw" $(HASH)/include ; +# BearSSL, /third_party//bearssl above, is webcpp::crypto's target and carries +# webcpp::hash's canary too: an object of its own, compiled with BearSSL's +# defines, which the library's sources gain only when libs/hash holds it, so +# that a checkout without libs/hash builds crypto's BearSSL as before. The +# check runs at build time; WEBCPP_HASH_HAS_BEARSSL then joins the usage +# requirements. +obj bearssl_hash_canary : $(HASH)/src/canary_bearssl.c + : $(.hash-c-library) $(.bearssl-config) ; +explicit bearssl_hash_canary ; + +rule bearssl-hash-canary ( properties * ) +{ + if [ path.exists [ path.native $(HASH)/src/canary_bearssl.c ] ] + { + return bearssl_hash_canary ; + } +} + +rule bearssl-hash-usage ( properties * ) +{ + if [ path.exists [ path.native $(HASH)/src/canary_bearssl.c ] ] + { + return WEBCPP_HASH_HAS_BEARSSL=1 ; + } +} + # XKCP (CC0; brg_endian.h under Brian Gladman's terms), the Keccak team's code # package at d20c8fc (2026-11-10; XKCP has no release tags): its Keccak-p[1600] # alone, in the plain-64bits implementation with all rounds unrolled diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index f09749c7..e4cfe3b5 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -302,14 +302,14 @@ def test_bearssl_is_pinned(_: Path) -> None: assert listed.stdout.split()[:2] == ['160000', BEARSSL_COMMIT], listed.stdout -def test_bearssl_is_built_file_by_file(root: Path) -> None: - harness.copy_integration_libraries(root, 'config', 'crypto') +def bearssl_compiles(root: Path, expected: int) -> str: + """Builds /third_party//bearssl in the scratch superproject, checks that each of its + `expected` compiles has BearSSL's flags, and returns the symbols of its archive.""" result = harness.run_b2(root, '-a', '-d+2', 'third_party//bearssl') harness.expect(result, True) compiles = [line for line in result.stdout.splitlines() if re.search(r'(clang|gcc)\S* .*-x c ', line) and ' -c ' in line] - # The 294 files of BearSSL's src/ and webcpp::crypto's canary. - assert len(compiles) == 295, (len(compiles), result.stdout[-4000:]) + assert len(compiles) == expected, (len(compiles), result.stdout[-4000:]) required = ['-ffunction-sections', '-fdata-sections', '-DBR_RDRAND=0', '-DBR_USE_URANDOM=0', '-DBR_USE_GETENTROPY=1', '-D_DEFAULT_SOURCE'] if sys.platform == 'darwin': @@ -321,10 +321,29 @@ def test_bearssl_is_built_file_by_file(root: Path) -> None: archive = sorted((root / 'bin').rglob('libbearssl.a')) assert len(archive) == 1, archive symbols = subprocess.run(['nm', str(archive[0])], capture_output=True, text=True, check=True) + return symbols.stdout + + +def bearssl_canary(library: str) -> str: prefix = '_' if sys.platform == 'darwin' else '' - canary = (f'{prefix}webcpp_crypto_bearssl_7bea48e_getentropy__add_third_party_bearssl' - '_to_your_link') - assert canary in symbols.stdout.split(), symbols.stdout[-2000:] + return (f'{prefix}webcpp_{library}_bearssl_7bea48e_getentropy__add_third_party_bearssl' + '_to_your_link') + + +def test_bearssl_is_built_file_by_file(root: Path) -> None: + harness.copy_integration_libraries(root, 'config', 'crypto', 'hash') + # The 294 files of BearSSL's src/, webcpp::crypto's canary and webcpp::hash's. + symbols = bearssl_compiles(root, 296) + for library in ('crypto', 'hash'): + assert bearssl_canary(library) in symbols.split(), symbols[-2000:] + + +def test_bearssl_without_hash_has_cryptos_canary_alone(root: Path) -> None: + # A checkout without libs/hash builds crypto's BearSSL as before: 294 files and one canary. + harness.copy_integration_libraries(root, 'config', 'crypto') + symbols = bearssl_compiles(root, 295) + assert bearssl_canary('crypto') in symbols.split(), symbols[-2000:] + assert 'webcpp_hash_' not in symbols, symbols[-2000:] def test_third_party_jamfile_loads_without_noise(root: Path) -> None: @@ -777,6 +796,7 @@ def test_hash_not_checked_out_stops_blake3(root: Path) -> None: test_bips_is_pinned, test_bearssl_is_pinned, test_bearssl_is_built_file_by_file, + test_bearssl_without_hash_has_cryptos_canary_alone, test_third_party_jamfile_loads_without_noise, test_bearssl_not_checked_out_is_refused, test_crypto_not_checked_out_is_refused, From 3567cc7e42b0338f2d40dca5a8f68360206c4236 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 02:48:04 -0300 Subject: [PATCH 14/47] tools: openssl_one_copy_test.py counts webcpp::hash's OpenSSL program with webcpp::crypto's --- doc/releases/0.1.0.adoc | 2 ++ tools/test/openssl_one_copy_test.py | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index ef599dc1..b6f825fb 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -284,6 +284,8 @@ with BLAKE3_TESTING for BLAKE3's own test program. On a native toolset whose bui names no architecture, the configured compiler is probed for x86-64 or arm64. * Changed /third_party//bearssl to carry webcpp::hash's canary beside webcpp::crypto's, and WEBCPP_HASH_HAS_BEARSSL, when libs/hash is checked out. +* Changed the check that a program links OpenSSL's archives once to cover a program naming +webcpp::hash's and webcpp::crypto's OpenSSL, when libs/hash is checked out. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/tools/test/openssl_one_copy_test.py b/tools/test/openssl_one_copy_test.py index 3b96200d..cb365f14 100644 --- a/tools/test/openssl_one_copy_test.py +++ b/tools/test/openssl_one_copy_test.py @@ -4,12 +4,14 @@ # 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 asio's and crypto's OpenSSL aliases in one program link libssl.a and libcrypto.a -once each, from one directory (CODING-GUIDELINES.md chapter 5 rule 10). +"""Checks that the OpenSSL aliases of several libraries in one program link libssl.a and +libcrypto.a once each, from one directory (CODING-GUIDELINES.md chapter 5 rule 10): asio's and +crypto's in libs/crypto/test//openssl_one_copy, and, when libs/hash is checked out, hash's and +crypto's in libs/hash/test//openssl_one_copy. -It reads the link line b2 prints (-d+2 with -n, so nothing is rebuilt) for -libs/crypto/test//openssl_one_copy and its _no_exceptions twin, and fails on any archive count -other than one per program, or on archives from two directories. +It reads the link line b2 prints (-d+2 with -n, so nothing is rebuilt) for each program and its +_no_exceptions twin, and fails on any archive count other than one per program, or on archives +from two directories. """ import os import re @@ -46,14 +48,20 @@ def self_test() -> None: assert check_link_line('-o "x/openssl_one_copy"') != [] +def programs() -> list[str]: + """The b2 targets checked: crypto's pair always, hash's when its library is checked out.""" + libraries = ['crypto'] + (['hash'] if (ROOT / 'libs/hash/build.jam').is_file() else []) + return [f'libs/{library}/test//openssl_one_copy{suffix}' + for library in libraries for suffix in ('', '_no_exceptions')] + + def main() -> int: self_test() + targets = programs() unset = ('CPATH', 'CPLUS_INCLUDE_PATH', 'C_INCLUDE_PATH') env = {k: v for k, v in os.environ.items() if k not in unset} command = ['b2', f'--user-config={ROOT}/.local/user-config.jam', '-a', '-n', '-d+2', '-j3', - '--build-dir=' + str(ROOT / 'bin/lane-onecopy'), *sys.argv[1:], - 'libs/crypto/test//openssl_one_copy', - 'libs/crypto/test//openssl_one_copy_no_exceptions'] + '--build-dir=' + str(ROOT / 'bin/lane-onecopy'), *sys.argv[1:], *targets] result = subprocess.run(command, cwd=ROOT, env=env, capture_output=True, text=True, check=False) if result.returncode != 0: print(result.stdout + result.stderr, file=sys.stderr) @@ -65,8 +73,8 @@ def main() -> int: text = result.stdout commands = [chunk for chunk in re.split(r'\n\s*\n', text) if LINK.search(chunk) and ARCHIVE.search(chunk)] - if len(commands) != 2: - print(f'openssl_one_copy: expected 2 link commands, found {len(commands)} ' + if len(commands) != len(targets): + print(f'openssl_one_copy: expected {len(targets)} link commands, found {len(commands)} ' f'({len(lines)} lines)', file=sys.stderr) return 1 faults = [fault for chunk in commands for fault in check_link_line(chunk)] From 9d0a6ce55e33035ede6a4ed3294cabc25cebee0a Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 02:59:35 -0300 Subject: [PATCH 15/47] tools: openssl_one_copy_test.py reads the link lines of WASI programs --- doc/releases/0.1.0.adoc | 1 + tools/test/openssl_one_copy_test.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index b6f825fb..3d67de75 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -286,6 +286,7 @@ names no architecture, the configured compiler is probed for x86-64 or arm64. and WEBCPP_HASH_HAS_BEARSSL, when libs/hash is checked out. * Changed the check that a program links OpenSSL's archives once to cover a program naming webcpp::hash's and webcpp::crypto's OpenSSL, when libs/hash is checked out. +* Fixed the check that a program links OpenSSL's archives once finding no link line on WASI. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/tools/test/openssl_one_copy_test.py b/tools/test/openssl_one_copy_test.py index cb365f14..ceed6234 100644 --- a/tools/test/openssl_one_copy_test.py +++ b/tools/test/openssl_one_copy_test.py @@ -21,7 +21,8 @@ ROOT = Path(__file__).resolve().parents[2] ARCHIVE = re.compile(r'[^\s"]*/lib(ssl|crypto)\.a') -LINK = re.compile(r'-o "?[^\s"]*/openssl_one_copy(_no_exceptions)?"?(\s|$)') +# A program's name, with .wasm on WASI. +LINK = re.compile(r'-o "?[^\s"]*/openssl_one_copy(_no_exceptions)?(\.wasm)?"?(\s|$)') def check_link_line(line: str) -> list[str]: @@ -46,6 +47,8 @@ def self_test() -> None: split = '-o "x/openssl_one_copy" /a/config-1/libssl.a /b/config-2/libcrypto.a' assert 'different directories' in ' '.join(check_link_line(split)) assert check_link_line('-o "x/openssl_one_copy"') != [] + assert LINK.search('-o "x/openssl_one_copy.wasm" y') and LINK.search('-o x/openssl_one_copy z') + assert not LINK.search('-o "x/openssl_one_copy_test.o"') def programs() -> list[str]: From e864c83197d6ffd239cc95c11748085e3e444b5e Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 03:55:50 -0300 Subject: [PATCH 16/47] third_party: libsodium's programs grow their memory on Emscripten --- doc/releases/0.1.0.adoc | 2 ++ third_party/Jamfile | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 3d67de75..9d818879 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -287,6 +287,8 @@ and WEBCPP_HASH_HAS_BEARSSL, when libs/hash is checked out. * Changed the check that a program links OpenSSL's archives once to cover a program naming webcpp::hash's and webcpp::crypto's OpenSSL, when libs/hash is checked out. * Fixed the check that a program links OpenSSL's archives once finding no link line on WASI. +* Changed /third_party//sodium to link its programs on Emscripten with +-sALLOW_MEMORY_GROWTH=1, for the memory Argon2id and scrypt allocate. [#webcpp-0-1-0-compilers-tested] == Compilers tested diff --git a/third_party/Jamfile b/third_party/Jamfile index de39248e..53c8d4a7 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -432,7 +432,10 @@ explicit xkcp ; # --disable-asm leaves them, so that the seven .S files are not needed and # the C code is used (design D11); the C files of the assembly's paths # compile to nothing. Shared by webcpp::hash and, later, webcpp::crypto: one -# copy per program. +# copy per program. On Emscripten a program that links it links with +# -sALLOW_MEMORY_GROWTH=1: Argon2id and scrypt allocate the memory their costs +# name (64 MiB for crypto_pwhash's interactive costs), past Emscripten's +# fixed 16 MiB, as libsodium's own tests link. path-constant SODIUM : libs/libsodium ; rule sodium-checked-out ( properties * ) @@ -648,7 +651,8 @@ lib sodium $(.sodium-version) $(.sodium-version)/sodium : : libs/libsodium/src/libsodium/include $(.sodium-version) sodium/version.h SODIUM_STATIC=1 - WEBCPP_HASH_HAS_SODIUM=1 $(.gc) ; + WEBCPP_HASH_HAS_SODIUM=1 $(.gc) + emscripten:-sALLOW_MEMORY_GROWTH=1 ; explicit sodium ; # What a program that compiles against libsodium's private headers adds, as From f4a9cb58292c2299a9b719f76680f9171d187ae0 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 07:13:55 -0300 Subject: [PATCH 17/47] tools: third_party_test.py checks libs/hash's refusal again, within the lint's form The merge of the libsodium and BLAKE3 cases dropped the expectations of the XKCP and libsodium cases, which left each unchecked and its variable unread; two Jamfile literals of the libsodium cases are split under 100 columns. --- tools/test/third_party_test.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index e4cfe3b5..8c851ea5 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -514,6 +514,9 @@ def test_xkcp_not_checked_out_is_refused(root: Path) -> None: def test_hash_not_checked_out_is_refused(root: Path) -> None: # No libs/hash in the scratch superproject: XKCP's adapter and canary are missing. result = harness.run_b2(root, 'third_party//xkcp') + harness.expect(result, False, 'libs/hash is not checked out', + 'git submodule update --init libs/hash') + def compiled_sodium(result: subprocess.CompletedProcess) -> list[str]: """The C compile lines of /third_party//sodium that b2 printed at -d+2.""" @@ -583,8 +586,9 @@ def test_sodium_test_config_reaches_the_private_headers(root: Path) -> None: harness.copy_integration_libraries(root, 'config', 'hash') harness.add_library(root, 'sodium_private', 'import webcpp ;\n' '\n' - 'webcpp.run private : private.c : /third_party//sodium-test-config\n' - ' /third_party//sodium ;\n', + 'webcpp.run private : private.c\n' + ' : /third_party//sodium-test-config\n' + ' /third_party//sodium ;\n', {'private.c': '#include \n' '#include "private/common.h"\n' '#include "argon2.h"\n' @@ -611,7 +615,8 @@ def test_sodium_msvc_inline_reaches_c_alone(root: Path) -> None: harness.add_library(root, 'sodium_msvc', 'import webcpp ;\n' '\n' 'webcpp.run both : both.cpp private.c\n' - ' : /third_party//sodium-test-config /third_party//sodium ;\n', + ' : /third_party//sodium-test-config\n' + ' /third_party//sodium ;\n', {'both.cpp': 'int main() { return 0; }\n', 'private.c': 'int sodium_private(void) { return 0; }\n'}) config = harness.user_config(root).read_text() @@ -664,6 +669,9 @@ def test_sodium_not_checked_out_is_refused(root: Path) -> None: def test_hash_not_checked_out_is_refused_by_sodium(root: Path) -> None: # No libs/hash in the scratch superproject: the canary is missing. result = harness.run_b2(root, 'third_party//sodium') + harness.expect(result, False, 'libs/hash is not checked out', + 'git submodule update --init libs/hash') + def build_blake3(root: Path, *request: str) -> tuple[dict[str, str], Path]: """Builds /third_party//blake3 with every action shown, from libs/hash's real canary, and From 5fdd0c2286db93bbb0019c86dedf87165e0c363c Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 07:14:07 -0300 Subject: [PATCH 18/47] third_party: the release notes give BLAKE3's build in lines of at most 30 words --- doc/releases/0.1.0.adoc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 9d818879..0b802ebf 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -279,9 +279,11 @@ that mounts on emscripten the host's directories it reads, where it reads them, tests read `/test-data`. * Added BLAKE3's C implementation 1.8.7, built from source as /third_party//blake3, portable on WebAssembly and dispatched to its intrinsics files natively, its vectors as -/third_party//blake3_vectors, and the feature webcpp-blake3-testing, which builds it -with BLAKE3_TESTING for BLAKE3's own test program. On a native toolset whose build request -names no architecture, the configured compiler is probed for x86-64 or arm64. +/third_party//blake3_vectors. +* Added the feature webcpp-blake3-testing, which builds /third_party//blake3 with +BLAKE3_TESTING for BLAKE3's own test program. +* Added a probe of the configured compiler for x86-64 or arm64, on a native toolset whose +build request names no architecture, which picks BLAKE3's intrinsics files. * Changed /third_party//bearssl to carry webcpp::hash's canary beside webcpp::crypto's, and WEBCPP_HASH_HAS_BEARSSL, when libs/hash is checked out. * Changed the check that a program links OpenSSL's archives once to cover a program naming From 63d1a4c80045f6233d15a3509eacc0f70337e95d Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 06:35:35 -0300 Subject: [PATCH 19/47] tools: the user's Jamfiles of webcpp::hash as fixtures --- doc/releases/0.1.0.adoc | 1 + tools/test/fixtures/hash_jamfiles/app/Jamfile | 8 ++ tools/test/fixtures/hash_jamfiles/app/app.cpp | 75 +++++++++++ .../fixtures/hash_jamfiles/app/app.outcome | 14 +++ .../hash_jamfiles/argon2id_on_hash2/Jamfile | 9 ++ .../hash_jamfiles/argon2id_on_hash2/app.cpp | 21 ++++ .../argon2id_on_hash2.outcome | 13 ++ tools/test/fixtures/hash_jamfiles/b3/Jamfile | 8 ++ tools/test/fixtures/hash_jamfiles/b3/b3.cpp | 37 ++++++ .../test/fixtures/hash_jamfiles/b3/b3.outcome | 12 ++ .../hash_jamfiles/bearssl_hmac/Jamfile | 9 ++ .../hash_jamfiles/bearssl_hmac/app.cpp | 24 ++++ .../bearssl_hmac/bearssl_hmac.outcome | 13 ++ .../hash_jamfiles/bearssl_not_linked/Jamfile | 9 ++ .../hash_jamfiles/bearssl_not_linked/app.cpp | 14 +++ .../bearssl_not_linked.outcome | 13 ++ .../hash_jamfiles/blake3_not_linked/Jamfile | 9 ++ .../hash_jamfiles/blake3_not_linked/app.cpp | 14 +++ .../blake3_not_linked.outcome | 13 ++ .../canary_bearssl_missing/Jamfile | 10 ++ .../canary_bearssl_missing/app.cpp | 25 ++++ .../canary_bearssl_missing.outcome | 25 ++++ .../canary_bearssl_other_commit/Jamfile | 9 ++ .../canary_bearssl_other_commit/app.cpp | 25 ++++ .../canary_bearssl_other_commit.outcome | 25 ++++ .../canary_blake3_missing/Jamfile | 10 ++ .../canary_blake3_missing/app.cpp | 17 +++ .../canary_blake3_missing.outcome | 25 ++++ .../canary_blake3_other_commit/Jamfile | 9 ++ .../canary_blake3_other_commit/app.cpp | 17 +++ .../canary_blake3_other_commit.outcome | 25 ++++ .../canary_sodium_missing/Jamfile | 10 ++ .../canary_sodium_missing/app.cpp | 25 ++++ .../canary_sodium_missing.outcome | 25 ++++ .../canary_sodium_other_commit/Jamfile | 9 ++ .../canary_sodium_other_commit/app.cpp | 25 ++++ .../canary_sodium_other_commit.outcome | 25 ++++ .../hash_jamfiles/canary_xkcp_missing/Jamfile | 9 ++ .../hash_jamfiles/canary_xkcp_missing/app.cpp | 17 +++ .../canary_xkcp_missing.outcome | 25 ++++ .../canary_xkcp_other_commit/Jamfile | 9 ++ .../canary_xkcp_other_commit/app.cpp | 17 +++ .../canary_xkcp_other_commit.outcome | 25 ++++ tools/test/fixtures/hash_jamfiles/eth/Jamfile | 8 ++ tools/test/fixtures/hash_jamfiles/eth/eth.cpp | 37 ++++++ .../fixtures/hash_jamfiles/eth/eth.outcome | 12 ++ .../hash_jamfiles/every_library/Jamfile | 9 ++ .../hash_jamfiles/every_library/app.cpp | 61 +++++++++ .../every_library/every_library.outcome | 17 +++ .../every_library_emscripten/Jamfile | 10 ++ .../every_library_emscripten/app.cpp | 61 +++++++++ .../every_library_emscripten.outcome | 16 +++ .../hash_jamfiles/expand_on_bearssl/Jamfile | 9 ++ .../hash_jamfiles/expand_on_bearssl/app.cpp | 24 ++++ .../expand_on_bearssl.outcome | 13 ++ tools/test/fixtures/hash_jamfiles/kdf/Jamfile | 8 ++ tools/test/fixtures/hash_jamfiles/kdf/kdf.cpp | 65 ++++++++++ .../fixtures/hash_jamfiles/kdf/kdf.outcome | 13 ++ .../test/fixtures/hash_jamfiles/kdf2/Jamfile | 8 ++ .../test/fixtures/hash_jamfiles/kdf2/kdf.cpp | 51 ++++++++ .../fixtures/hash_jamfiles/kdf2/kdf2.outcome | 11 ++ .../hash_jamfiles/kdf_not_digest/Jamfile | 9 ++ .../hash_jamfiles/kdf_not_digest/app.cpp | 24 ++++ .../kdf_not_digest/kdf_not_digest.outcome | 13 ++ .../hash_jamfiles/kdf_not_hmac/Jamfile | 9 ++ .../hash_jamfiles/kdf_not_hmac/app.cpp | 19 +++ .../kdf_not_hmac/kdf_not_hmac.outcome | 13 ++ .../hash_jamfiles/openssl_not_linked/Jamfile | 9 ++ .../hash_jamfiles/openssl_not_linked/app.cpp | 14 +++ .../openssl_not_linked.outcome | 13 ++ .../openssl_on_emscripten/Jamfile | 8 ++ .../openssl_on_emscripten/kdf.cpp | 65 ++++++++++ .../openssl_on_emscripten.outcome | 12 ++ .../override_cannot_serve/Jamfile | 10 ++ .../override_cannot_serve/app.cpp | 22 ++++ .../override_cannot_serve.outcome | 13 ++ .../overrides_openssl_on_emscripten/Jamfile | 12 ++ .../overrides_openssl_on_emscripten/app.cpp | 21 ++++ .../overrides_openssl_on_emscripten.outcome | 16 +++ .../hash_jamfiles/pbkdf2_on_bearssl/Jamfile | 9 ++ .../hash_jamfiles/pbkdf2_on_bearssl/app.cpp | 23 ++++ .../pbkdf2_on_bearssl.outcome | 13 ++ .../hash_jamfiles/pbkdf2_on_sodium/Jamfile | 9 ++ .../hash_jamfiles/pbkdf2_on_sodium/app.cpp | 20 +++ .../pbkdf2_on_sodium/pbkdf2_on_sodium.outcome | 13 ++ .../profile_openssl_on_emscripten/Jamfile | 8 ++ .../profile_openssl_on_emscripten/app.cpp | 21 ++++ .../profile_openssl_on_emscripten.outcome | 12 ++ tools/test/fixtures/hash_jamfiles/pw/Jamfile | 8 ++ tools/test/fixtures/hash_jamfiles/pw/pw.cpp | 82 +++++++++++++ .../test/fixtures/hash_jamfiles/pw/pw.outcome | 13 ++ .../hash_jamfiles/scrypt_on_hash2/Jamfile | 9 ++ .../hash_jamfiles/scrypt_on_hash2/app.cpp | 19 +++ .../scrypt_on_hash2/scrypt_on_hash2.outcome | 13 ++ .../hash_jamfiles/sodium_hmac/Jamfile | 9 ++ .../hash_jamfiles/sodium_hmac/app.cpp | 21 ++++ .../sodium_hmac/sodium_hmac.outcome | 13 ++ .../hash_jamfiles/sodium_not_linked/Jamfile | 9 ++ .../hash_jamfiles/sodium_not_linked/app.cpp | 14 +++ .../sodium_not_linked.outcome | 13 ++ .../hash_jamfiles/two_overrides/Jamfile | 11 ++ .../hash_jamfiles/two_overrides/app.cpp | 14 +++ .../two_overrides/two_overrides.outcome | 13 ++ .../hash_jamfiles/two_profiles/Jamfile | 11 ++ .../hash_jamfiles/two_profiles/app.cpp | 13 ++ .../two_profiles/two_profiles.outcome | 13 ++ .../two_umbrella_profiles/Jamfile | 11 ++ .../two_umbrella_profiles/app.cpp | 14 +++ .../two_umbrella_profiles.outcome | 13 ++ .../hash_jamfiles/xkcp_not_linked/Jamfile | 9 ++ .../hash_jamfiles/xkcp_not_linked/app.cpp | 14 +++ .../xkcp_not_linked/xkcp_not_linked.outcome | 13 ++ tools/test/hash_jamfiles_test.py | 116 ++++++++++++++++++ 113 files changed, 2110 insertions(+) create mode 100644 tools/test/fixtures/hash_jamfiles/app/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/app/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/app/app.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_on_hash2.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/b3/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/b3/b3.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/b3/b3.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/bearssl_hmac/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/bearssl_hmac/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_hmac.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/bearssl_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/bearssl_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/bearssl_not_linked/bearssl_not_linked.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/blake3_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/blake3_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/blake3_not_linked/blake3_not_linked.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/canary_bearssl_other_commit.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_blake3_missing/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_blake3_missing/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_sodium_missing/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_sodium_missing/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_sodium_missing/canary_sodium_missing.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/canary_sodium_other_commit.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/canary_xkcp_missing.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/canary_xkcp_other_commit.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/eth/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/eth/eth.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/eth/eth.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/every_library/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/every_library/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/every_library/every_library.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/every_library_emscripten/every_library_emscripten.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/expand_on_bearssl/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/expand_on_bearssl/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/kdf/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/kdf/kdf.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/kdf/kdf.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/kdf2/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/kdf2/kdf.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/kdf2/kdf2.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_not_digest/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_not_digest/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_not_digest/kdf_not_digest.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_not_hmac/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_not_hmac/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/kdf_not_hmac/kdf_not_hmac.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_not_linked/openssl_not_linked.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/openssl_on_emscripten.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/override_cannot_serve/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/override_cannot_serve/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/override_cannot_serve/override_cannot_serve.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/overrides_openssl_on_emscripten.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_on_sodium.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/profile_openssl_on_emscripten.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/pw/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/pw/pw.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/pw/pw.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_on_hash2.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_hmac/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_hmac/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_hmac.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_not_linked.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/two_overrides/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/two_overrides/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/two_overrides/two_overrides.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/two_profiles/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/two_profiles/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/two_profiles/two_profiles.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/two_umbrella_profiles.outcome create mode 100644 tools/test/fixtures/hash_jamfiles/xkcp_not_linked/Jamfile create mode 100644 tools/test/fixtures/hash_jamfiles/xkcp_not_linked/app.cpp create mode 100644 tools/test/fixtures/hash_jamfiles/xkcp_not_linked/xkcp_not_linked.outcome create mode 100644 tools/test/hash_jamfiles_test.py diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 0b802ebf..9eab2387 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -87,6 +87,7 @@ None. * Fixed links over code hiding the underscores of names under their underline. * Fixed the header cells of a table with a header column lacking their scope, which the site's HTML check refuses. * Changed the references to leave out detail macros, WEBCPP_*_DETAIL_*. +* Added the user's Jamfiles of webcpp::hash, tested as fixtures of a test of the tools. * Fixed the WASIp2 test launcher interrupting large finite workloads after 60 seconds. * Fixed Chrome provisioning and browser/TLS profile coverage in Asio CI lanes. * Added source-built OpenSSL and Cobalt SSL targets for WASIp2. diff --git a/tools/test/fixtures/hash_jamfiles/app/Jamfile b/tools/test/fixtures/hash_jamfiles/app/Jamfile new file mode 100644 index 00000000..5fea12fe --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/app/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) + +# Spec 5.1: Hash2's algorithms, HMAC, hkdf and pbkdf2 on backends::hash2. +exe app : app.cpp /webcpp/hash//hash ; diff --git a/tools/test/fixtures/hash_jamfiles/app/app.cpp b/tools/test/fixtures/hash_jamfiles/app/app.cpp new file mode 100644 index 00000000..24ea84da --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/app/app.cpp @@ -0,0 +1,75 @@ +// 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 program that names /webcpp/hash//hash alone: SHA-256 of "abc" (FIPS 180-2), HMAC-SHA-256 +// (RFC 4231, case 2), HKDF (RFC 5869, A.1) and PBKDF2-HMAC-SHA-256 (RFC 7914, section 11, its +// first case), each on Boost.Hash2 (backends::hash2, the default without a C library). + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +// RFC 5869, appendix A.1: SHA-256, a 22-byte IKM, a 13-byte salt, a 10-byte info, 42 bytes. +std::array rfc5869_a1_okm() { + std::array ikm{}; + ikm.fill(0x0b); + std::array salt{}; + std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); + std::array info{}; + std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); + std::array okm{}; + if (!webcpp::hash::hkdf( + okm, salt, ikm, info)) { + okm.fill(0); + } + return okm; +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; + std::string_view const abc = "abc"; + hash::sha2_256 sha; + sha.update(abc.data(), abc.size()); + print_hex("sha2_256", sha.result()); + + std::string_view const key = "Jefe"; + std::string_view const data = "what do ya want for nothing?"; + hash::hmac_sha2_256 mac(key.data(), key.size()); + mac.update(data.data(), data.size()); + print_hex("hmac_sha2_256", mac.result()); + + print_hex("hkdf", rfc5869_a1_okm()); + + std::string_view const password = "password"; + std::string_view const salt = "salt"; + std::array derived{}; + auto const done = hash::pbkdf2( + derived, std::span(reinterpret_cast(password.data()), password.size()), + std::span(reinterpret_cast(salt.data()), salt.size()), 1); + print_hex("pbkdf2", derived); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/app/app.outcome b/tools/test/fixtures/hash_jamfiles/app/app.outcome new file mode 100644 index 00000000..d45cd913 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/app/app.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) + +[all] +targets: native wasip2 wasip3 emscripten +build: succeeds +run: app +sha2_256 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad +hmac_sha2_256 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843 +hkdf 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +pbkdf2 120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b diff --git a/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/Jamfile new file mode 100644 index 00000000..6164276a --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2id_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/argon2id_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/argon2id_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp new file mode 100644 index 00000000..969844ce --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/app.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// argon2id on another backend than backends::sodium stops with spec section 3.3's text. + +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array salt{}; + auto done = webcpp::hash::argon2id( + output, {}, salt, webcpp::hash::argon2id_interactive); + return done ? 0 : 1; +} 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 new file mode 100644 index 00000000..f4583172 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/argon2id_on_hash2/argon2id_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/argon2id_on_hash2, a compile-diagnostic. +[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. diff --git a/tools/test/fixtures/hash_jamfiles/b3/Jamfile b/tools/test/fixtures/hash_jamfiles/b3/Jamfile new file mode 100644 index 00000000..92bfdef6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/b3/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) + +# Spec 5.1: blake3. +exe b3 : b3.cpp /webcpp/hash//hash /third_party//blake3 ; diff --git a/tools/test/fixtures/hash_jamfiles/b3/b3.cpp b/tools/test/fixtures/hash_jamfiles/b3/b3.cpp new file mode 100644 index 00000000..a9bd3069 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/b3/b3.cpp @@ -0,0 +1,37 @@ +// 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 program over BLAKE3's C implementation: the digests of BLAKE3's official vectors of length 0 +// and 1 (test_vectors.json, whose input is the bytes 0, 1, 2, ... modulo 251). + +#include + +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +} // namespace + +int main() { + webcpp::hash::blake3 empty; + print_hex("blake3", empty.result()); + std::uint8_t const zero = 0; + webcpp::hash::blake3 hasher; + hasher.update(&zero, 1); + print_hex("blake3", hasher.result()); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/b3/b3.outcome b/tools/test/fixtures/hash_jamfiles/b3/b3.outcome new file mode 100644 index 00000000..a498fd92 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/b3/b3.outcome @@ -0,0 +1,12 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +[all] +targets: native wasip2 wasip3 emscripten +build: succeeds +run: b3 +blake3 af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262 +blake3 2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213 diff --git a/tools/test/fixtures/hash_jamfiles/bearssl_hmac/Jamfile b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/Jamfile new file mode 100644 index 00000000..3f363b5e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/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/bearssl_hmac of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /third_party//bearssl ; diff --git a/tools/test/fixtures/hash_jamfiles/bearssl_hmac/app.cpp b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/app.cpp new file mode 100644 index 00000000..497092a9 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/app.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// hkdf on backends::bearssl over an hmac BearSSL has no hash for (SHA-512/256) stops with spec +// section 3.3's text, and with no other error. + +#include +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array input{}; + auto done = + webcpp::hash::hkdf( + output, input, input, input); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_hmac.outcome b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_hmac.outcome new file mode 100644 index 00000000..d53c765f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bearssl_hmac/bearssl_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. Natively and on WASI the same text is +# test/messages/bearssl_hmac, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::bearssl has HKDF over hmac_md5_128, hmac_sha1_160, hmac_sha2_224, hmac_sha2_256, hmac_sha2_384 and hmac_sha2_512 alone. Over this hmac, name backends::hash2 (every hmac) or backends::openssl (every hmac but hmac_ripemd_128). diff --git a/tools/test/fixtures/hash_jamfiles/bearssl_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/bearssl_not_linked/Jamfile new file mode 100644 index 00000000..7673453c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bearssl_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/bearssl_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/bearssl_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/bearssl_not_linked/app.cpp new file mode 100644 index 00000000..19e67a17 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bearssl_not_linked/app.cpp @@ -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) + +// A program that names backends::bearssl and does not link BearSSL stops with the instruction to +// add /third_party//bearssl (spec section 5.7). + +#include + +int main() { + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/bearssl_not_linked/bearssl_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/bearssl_not_linked/bearssl_not_linked.outcome new file mode 100644 index 00000000..f0d000d4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/bearssl_not_linked/bearssl_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/bearssl_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::bearssl needs BearSSL. Add /third_party//bearssl to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//bearssl ; diff --git a/tools/test/fixtures/hash_jamfiles/blake3_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/blake3_not_linked/Jamfile new file mode 100644 index 00000000..a4111661 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_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_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_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/blake3_not_linked/app.cpp new file mode 100644 index 00000000..b14c8427 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_not_linked/app.cpp @@ -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) + +// A program that uses blake3 without linking /third_party//blake3 stops with the instruction to +// add it (spec 5.7, the second row). + +#include + +int main() { + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/blake3_not_linked/blake3_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/blake3_not_linked/blake3_not_linked.outcome new file mode 100644 index 00000000..ba5850ea --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/blake3_not_linked/blake3_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_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: 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/canary_bearssl_missing/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/Jamfile new file mode 100644 index 00000000..c48463c9 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/Jamfile @@ -0,0 +1,10 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The header found, the library not linked. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_HAS_BEARSSL=1 + ../../third_party/libs/bearssl/inc ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/app.cpp new file mode 100644 index 00000000..6ca19480 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/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) + +// Derives 42 bytes with HKDF on backends::bearssl: the program reads the canary of +// /third_party//bearssl, so that a library missing from the link, or built at another commit, fails +// to link with the canary's name (spec 5.4). + +#include +#include +#include + +#include +#include + +int main() { + std::array okm{}; + std::array const ikm{}; + auto const done = + webcpp::hash::hkdf(okm, {}, + ikm, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome new file mode 100644 index 00000000..108021fa --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_bearssl_7bea48e_getentropy__add_third_party_bearssl_to_your_link +[native-linux] +contains: webcpp_hash_bearssl_7bea48e_getentropy__add_third_party_bearssl_to_your_link +contains: undefined reference to `webcpp_hash_bearssl_7bea48e_getentropy__add_third_party_bearssl_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_bearssl_7bea48e_getentropy__add_third_party_bearssl_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_bearssl_7bea48e_getentropy__add_third_party_bearssl_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_bearssl_7bea48e_getentropy__add_third_party_bearssl_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/Jamfile new file mode 100644 index 00000000..a11d0ba6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/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) + +# The library linked, and a program that names another commit of it. +exe app : app.cpp /webcpp/hash//hash /third_party//bearssl + : WEBCPP_HASH_BEARSSL_CANARY_COMMIT=0000000 ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/app.cpp new file mode 100644 index 00000000..6ca19480 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/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) + +// Derives 42 bytes with HKDF on backends::bearssl: the program reads the canary of +// /third_party//bearssl, so that a library missing from the link, or built at another commit, fails +// to link with the canary's name (spec 5.4). + +#include +#include +#include + +#include +#include + +int main() { + std::array okm{}; + std::array const ikm{}; + auto const done = + webcpp::hash::hkdf(okm, {}, + ikm, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/canary_bearssl_other_commit.outcome b/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/canary_bearssl_other_commit.outcome new file mode 100644 index 00000000..876dee5e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_bearssl_other_commit/canary_bearssl_other_commit.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_bearssl_0000000_getentropy__add_third_party_bearssl_to_your_link +[native-linux] +contains: webcpp_hash_bearssl_0000000_getentropy__add_third_party_bearssl_to_your_link +contains: undefined reference to `webcpp_hash_bearssl_0000000_getentropy__add_third_party_bearssl_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_bearssl_0000000_getentropy__add_third_party_bearssl_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_bearssl_0000000_getentropy__add_third_party_bearssl_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_bearssl_0000000_getentropy__add_third_party_bearssl_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/Jamfile new file mode 100644 index 00000000..6ae1bc34 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/Jamfile @@ -0,0 +1,10 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The header found, the library not linked. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_HAS_BLAKE3=1 + ../../third_party/libs/blake3/c ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/app.cpp new file mode 100644 index 00000000..97c42d55 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/app.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Hashes "abc" with BLAKE3: the program reads the canary of /third_party//blake3, so that a +// library missing from the link, or built at another commit, fails to link with the +// canary's name (spec 5.4). + +#include + +int main() { + webcpp::hash::blake3 hasher; + hasher.update("abc", 3); + return hasher.result()[0] == 0x64 ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome new file mode 100644 index 00000000..569fcf14 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_blake3_f3149ec_neon__add_third_party_blake3_to_your_link +[native-linux] +contains: webcpp_hash_blake3_f3149ec_x86__add_third_party_blake3_to_your_link +contains: undefined reference to `webcpp_hash_blake3_f3149ec_x86__add_third_party_blake3_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_blake3_f3149ec_portable__add_third_party_blake3_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_blake3_f3149ec_portable__add_third_party_blake3_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_blake3_f3149ec_portable__add_third_party_blake3_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/Jamfile new file mode 100644 index 00000000..c426e980 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/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) + +# The library linked, and a program that names another commit of it. +exe app : app.cpp /webcpp/hash//hash /third_party//blake3 + : WEBCPP_HASH_BLAKE3_CANARY_COMMIT=0000000 ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/app.cpp new file mode 100644 index 00000000..97c42d55 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/app.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Hashes "abc" with BLAKE3: the program reads the canary of /third_party//blake3, so that a +// library missing from the link, or built at another commit, fails to link with the +// canary's name (spec 5.4). + +#include + +int main() { + webcpp::hash::blake3 hasher; + hasher.update("abc", 3); + return hasher.result()[0] == 0x64 ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome new file mode 100644 index 00000000..05172ac3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_blake3_0000000_neon__add_third_party_blake3_to_your_link +[native-linux] +contains: webcpp_hash_blake3_0000000_x86__add_third_party_blake3_to_your_link +contains: undefined reference to `webcpp_hash_blake3_0000000_x86__add_third_party_blake3_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_blake3_0000000_portable__add_third_party_blake3_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_blake3_0000000_portable__add_third_party_blake3_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_blake3_0000000_portable__add_third_party_blake3_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/Jamfile new file mode 100644 index 00000000..40f192e2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/Jamfile @@ -0,0 +1,10 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The header found, the library not linked. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_HAS_SODIUM=1 + ../../third_party/libs/libsodium/src/libsodium/include ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/app.cpp new file mode 100644 index 00000000..3a81a88e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/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) + +// Derives 42 bytes with HKDF on backends::sodium: the program reads the canary of +// /third_party//sodium, so that a library missing from the link, or built at another commit, fails +// to link with the canary's name (spec 5.4). + +#include +#include +#include + +#include +#include + +int main() { + std::array okm{}; + std::array const ikm{}; + auto const done = + webcpp::hash::hkdf(okm, {}, + ikm, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/canary_sodium_missing.outcome b/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/canary_sodium_missing.outcome new file mode 100644 index 00000000..644a0b40 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_sodium_missing/canary_sodium_missing.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_sodium_77e1ce5_configured__add_third_party_sodium_to_your_link +[native-linux] +contains: webcpp_hash_sodium_77e1ce5_configured__add_third_party_sodium_to_your_link +contains: undefined reference to `webcpp_hash_sodium_77e1ce5_configured__add_third_party_sodium_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_sodium_77e1ce5_configured__add_third_party_sodium_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_sodium_77e1ce5_configured__add_third_party_sodium_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_sodium_77e1ce5_configured__add_third_party_sodium_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/Jamfile new file mode 100644 index 00000000..1f6c3e56 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/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) + +# The library linked, and a program that names another commit of it. +exe app : app.cpp /webcpp/hash//hash /third_party//sodium + : WEBCPP_HASH_SODIUM_CANARY_COMMIT=0000000 ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/app.cpp new file mode 100644 index 00000000..3a81a88e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/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) + +// Derives 42 bytes with HKDF on backends::sodium: the program reads the canary of +// /third_party//sodium, so that a library missing from the link, or built at another commit, fails +// to link with the canary's name (spec 5.4). + +#include +#include +#include + +#include +#include + +int main() { + std::array okm{}; + std::array const ikm{}; + auto const done = + webcpp::hash::hkdf(okm, {}, + ikm, {}); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/canary_sodium_other_commit.outcome b/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/canary_sodium_other_commit.outcome new file mode 100644 index 00000000..7fe546c1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_sodium_other_commit/canary_sodium_other_commit.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_sodium_0000000_configured__add_third_party_sodium_to_your_link +[native-linux] +contains: webcpp_hash_sodium_0000000_configured__add_third_party_sodium_to_your_link +contains: undefined reference to `webcpp_hash_sodium_0000000_configured__add_third_party_sodium_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_sodium_0000000_configured__add_third_party_sodium_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_sodium_0000000_configured__add_third_party_sodium_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_sodium_0000000_configured__add_third_party_sodium_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/Jamfile new file mode 100644 index 00000000..09cb78f0 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/Jamfile @@ -0,0 +1,9 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The header found, the library not linked. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_HAS_XKCP=1 ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/app.cpp new file mode 100644 index 00000000..9a83efff --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/app.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Hashes "abc" with Keccak-256: the program reads the canary of /third_party//xkcp, so that a +// library missing from the link, or built at another commit, fails to link with the +// canary's name (spec 5.4). + +#include + +int main() { + webcpp::hash::keccak_256 hasher; + hasher.update("abc", 3); + return hasher.result()[0] == 0x4e ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/canary_xkcp_missing.outcome b/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/canary_xkcp_missing.outcome new file mode 100644 index 00000000..5d7c48b2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_xkcp_missing/canary_xkcp_missing.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link +[native-linux] +contains: webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link +contains: undefined reference to `webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_xkcp_d20c8fc_generic64__add_third_party_xkcp_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/Jamfile b/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/Jamfile new file mode 100644 index 00000000..ad25b86f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/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) + +# The library linked, and a program that names another commit of it. +exe app : app.cpp /webcpp/hash//hash /third_party//xkcp + : WEBCPP_HASH_XKCP_CANARY_COMMIT=0000000 ; diff --git a/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/app.cpp b/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/app.cpp new file mode 100644 index 00000000..9a83efff --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/app.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Hashes "abc" with Keccak-256: the program reads the canary of /third_party//xkcp, so that a +// library missing from the link, or built at another commit, fails to link with the +// canary's name (spec 5.4). + +#include + +int main() { + webcpp::hash::keccak_256 hasher; + hasher.update("abc", 3); + return hasher.result()[0] == 0x4e ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/canary_xkcp_other_commit.outcome b/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/canary_xkcp_other_commit.outcome new file mode 100644 index 00000000..2fd089fc --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/canary_xkcp_other_commit/canary_xkcp_other_commit.outcome @@ -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) + +[all] +targets: native wasip2 wasip3 emscripten +build: fails +[native-darwin] +contains: Undefined symbols for architecture +contains: _webcpp_hash_xkcp_0000000_generic64__add_third_party_xkcp_to_your_link +[native-linux] +contains: webcpp_hash_xkcp_0000000_generic64__add_third_party_xkcp_to_your_link +contains: undefined reference to `webcpp_hash_xkcp_0000000_generic64__add_third_party_xkcp_to_your_link' +[wasip2] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_xkcp_0000000_generic64__add_third_party_xkcp_to_your_link +[wasip3] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_xkcp_0000000_generic64__add_third_party_xkcp_to_your_link +[emscripten] +contains: wasm-ld: error: +contains: undefined symbol: webcpp_hash_xkcp_0000000_generic64__add_third_party_xkcp_to_your_link +contains: em++: error: diff --git a/tools/test/fixtures/hash_jamfiles/eth/Jamfile b/tools/test/fixtures/hash_jamfiles/eth/Jamfile new file mode 100644 index 00000000..d6aba81f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/eth/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) + +# Spec 5.1: keccak_256. +exe eth : eth.cpp /webcpp/hash//hash /third_party//xkcp ; diff --git a/tools/test/fixtures/hash_jamfiles/eth/eth.cpp b/tools/test/fixtures/hash_jamfiles/eth/eth.cpp new file mode 100644 index 00000000..50a7fb86 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/eth/eth.cpp @@ -0,0 +1,37 @@ +// 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 program over XKCP: Keccak-256 (Ethereum's, the original padding) of nothing and of "abc". + +#include + +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +} // namespace + +int main() { + webcpp::hash::keccak_256 empty; + print_hex("keccak_256", empty.result()); + std::string_view const abc = "abc"; + webcpp::hash::keccak_256 hasher; + hasher.update(abc.data(), abc.size()); + print_hex("keccak_256", hasher.result()); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/eth/eth.outcome b/tools/test/fixtures/hash_jamfiles/eth/eth.outcome new file mode 100644 index 00000000..79abc6d4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/eth/eth.outcome @@ -0,0 +1,12 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +[all] +targets: native wasip2 wasip3 emscripten +build: succeeds +run: eth +keccak_256 c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 +keccak_256 4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 diff --git a/tools/test/fixtures/hash_jamfiles/every_library/Jamfile b/tools/test/fixtures/hash_jamfiles/every_library/Jamfile new file mode 100644 index 00000000..aa13b996 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/every_library/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) + +# Every C library of webcpp::hash, and OpenSSL, in one program. +exe app : app.cpp /webcpp/hash//hash /third_party//xkcp /third_party//blake3 + /third_party//sodium /third_party//bearssl /webcpp/hash//openssl ; diff --git a/tools/test/fixtures/hash_jamfiles/every_library/app.cpp b/tools/test/fixtures/hash_jamfiles/every_library/app.cpp new file mode 100644 index 00000000..b92cf047 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/every_library/app.cpp @@ -0,0 +1,61 @@ +// 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) + +// One program over every C library of webcpp::hash its target has: Keccak-256 and BLAKE3 of +// nothing, then HKDF (RFC 5869, A.1) on each linked backend and on the default backend. Each +// library is one archive, linked once; their symbols do not collide. + +#include + +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +template +std::array rfc5869_a1_okm() { + std::array ikm{}; + ikm.fill(0x0b); + std::array salt{}; + std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); + std::array info{}; + std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); + std::array okm{}; + if (!webcpp::hash::hkdf(okm, salt, ikm, info)) { + okm.fill(0); + } + return okm; +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; + hash::keccak_256 keccak; + print_hex("keccak_256", keccak.result()); + hash::blake3 blake; + print_hex("blake3", blake.result()); + print_hex("hkdf hash2", rfc5869_a1_okm()); + print_hex("hkdf sodium", rfc5869_a1_okm()); + print_hex("hkdf bearssl", rfc5869_a1_okm()); +#if defined(WEBCPP_HASH_HAS_OPENSSL) + print_hex("hkdf openssl", rfc5869_a1_okm()); +#endif + print_hex("hkdf default", rfc5869_a1_okm>()); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/every_library/every_library.outcome b/tools/test/fixtures/hash_jamfiles/every_library/every_library.outcome new file mode 100644 index 00000000..5a0452a1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/every_library/every_library.outcome @@ -0,0 +1,17 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +[all] +targets: native wasip2 wasip3 +build: succeeds +run: app +keccak_256 c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 +blake3 af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262 +hkdf hash2 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +hkdf sodium 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +hkdf bearssl 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +hkdf openssl 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +hkdf default 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 diff --git a/tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile new file mode 100644 index 00000000..129f56f9 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile @@ -0,0 +1,10 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# Every C library of webcpp::hash in one program, on Emscripten, where webcpp +# builds no OpenSSL. +exe app : app.cpp /webcpp/hash//hash /third_party//xkcp /third_party//blake3 + /third_party//sodium /third_party//bearssl ; diff --git a/tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp new file mode 100644 index 00000000..b92cf047 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp @@ -0,0 +1,61 @@ +// 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) + +// One program over every C library of webcpp::hash its target has: Keccak-256 and BLAKE3 of +// nothing, then HKDF (RFC 5869, A.1) on each linked backend and on the default backend. Each +// library is one archive, linked once; their symbols do not collide. + +#include + +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +template +std::array rfc5869_a1_okm() { + std::array ikm{}; + ikm.fill(0x0b); + std::array salt{}; + std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); + std::array info{}; + std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); + std::array okm{}; + if (!webcpp::hash::hkdf(okm, salt, ikm, info)) { + okm.fill(0); + } + return okm; +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; + hash::keccak_256 keccak; + print_hex("keccak_256", keccak.result()); + hash::blake3 blake; + print_hex("blake3", blake.result()); + print_hex("hkdf hash2", rfc5869_a1_okm()); + print_hex("hkdf sodium", rfc5869_a1_okm()); + print_hex("hkdf bearssl", rfc5869_a1_okm()); +#if defined(WEBCPP_HASH_HAS_OPENSSL) + print_hex("hkdf openssl", rfc5869_a1_okm()); +#endif + print_hex("hkdf default", rfc5869_a1_okm>()); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/every_library_emscripten/every_library_emscripten.outcome b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/every_library_emscripten.outcome new file mode 100644 index 00000000..2fba948f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/every_library_emscripten.outcome @@ -0,0 +1,16 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +[all] +targets: emscripten +build: succeeds +run: app +keccak_256 c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 +blake3 af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262 +hkdf hash2 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +hkdf sodium 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +hkdf bearssl 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +hkdf default 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 diff --git a/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/Jamfile b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/Jamfile new file mode 100644 index 00000000..e350c3ce --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/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/expand_on_bearssl of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /third_party//bearssl ; diff --git a/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/app.cpp b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/app.cpp new file mode 100644 index 00000000..5603dc06 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/app.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// hkdf_expand on backends::bearssl, whose br_hkdf_* keeps the PRK inside its context, stops with +// spec section 3.3's text, and with no other error. + +#include +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array prk{}; + auto done = + webcpp::hash::hkdf_expand( + output, prk, prk); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.outcome b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.outcome new file mode 100644 index 00000000..c66de0b6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/expand_on_bearssl/expand_on_bearssl.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/expand_on_bearssl, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: hkdf_extract and hkdf_expand are not in backends::bearssl, whose HKDF does both steps together: call hkdf, or name backends::hash2, backends::sodium or backends::openssl. diff --git a/tools/test/fixtures/hash_jamfiles/kdf/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf/Jamfile new file mode 100644 index 00000000..7ba97aa2 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf/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) + +# Spec 5.1: backends::openssl, where webcpp builds OpenSSL. +exe kdf : kdf.cpp /webcpp/hash//hash /webcpp/hash//openssl ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf/kdf.cpp b/tools/test/fixtures/hash_jamfiles/kdf/kdf.cpp new file mode 100644 index 00000000..6bf70c08 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf/kdf.cpp @@ -0,0 +1,65 @@ +// 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 program over OpenSSL: HKDF (RFC 5869, A.1) and, where the backend has it, +// PBKDF2-HMAC-SHA-256 (RFC 7914, section 11, its first case). + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +// RFC 5869, appendix A.1: SHA-256, a 22-byte IKM, a 13-byte salt, a 10-byte info, 42 bytes. +std::array rfc5869_a1_okm() { + std::array ikm{}; + ikm.fill(0x0b); + std::array salt{}; + std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); + std::array info{}; + std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); + std::array okm{}; + if (!webcpp::hash::hkdf( + okm, salt, ikm, info)) { + okm.fill(0); + } + return okm; +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; +#if defined(WEBCPP_HASH_HAS_OPENSSL) + std::printf("HAS_OPENSSL=%d\n", WEBCPP_HASH_HAS_OPENSSL); +#endif + print_hex("hkdf", rfc5869_a1_okm()); + std::string_view const password = "password"; + std::string_view const salt = "salt"; + std::array derived{}; + auto const done = hash::pbkdf2( + derived, std::span(reinterpret_cast(password.data()), password.size()), + std::span(reinterpret_cast(salt.data()), salt.size()), 1); + print_hex("pbkdf2", derived); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf/kdf.outcome b/tools/test/fixtures/hash_jamfiles/kdf/kdf.outcome new file mode 100644 index 00000000..d9be34a6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf/kdf.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) + +[all] +targets: native wasip2 wasip3 +build: succeeds +run: kdf +HAS_OPENSSL=1 +hkdf 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 +pbkdf2 120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b diff --git a/tools/test/fixtures/hash_jamfiles/kdf2/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf2/Jamfile new file mode 100644 index 00000000..6d03ea60 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf2/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) + +# Spec 5.1: backends::bearssl. +exe kdf2 : kdf.cpp /webcpp/hash//hash /third_party//bearssl ; diff --git a/tools/test/fixtures/hash_jamfiles/kdf2/kdf.cpp b/tools/test/fixtures/hash_jamfiles/kdf2/kdf.cpp new file mode 100644 index 00000000..8c4eb976 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf2/kdf.cpp @@ -0,0 +1,51 @@ +// 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 program over BearSSL: HKDF (RFC 5869, A.1); BearSSL has no PBKDF2. + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +// RFC 5869, appendix A.1: SHA-256, a 22-byte IKM, a 13-byte salt, a 10-byte info, 42 bytes. +std::array rfc5869_a1_okm() { + std::array ikm{}; + ikm.fill(0x0b); + std::array salt{}; + std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); + std::array info{}; + std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); + std::array okm{}; + if (!webcpp::hash::hkdf( + okm, salt, ikm, info)) { + okm.fill(0); + } + return okm; +} + +} // namespace + +int main() { + print_hex("hkdf", rfc5869_a1_okm()); + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf2/kdf2.outcome b/tools/test/fixtures/hash_jamfiles/kdf2/kdf2.outcome new file mode 100644 index 00000000..ce7a1a35 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf2/kdf2.outcome @@ -0,0 +1,11 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +[all] +targets: native wasip2 wasip3 emscripten +build: succeeds +run: kdf2 +hkdf 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 diff --git a/tools/test/fixtures/hash_jamfiles/kdf_not_digest/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_not_digest/Jamfile new file mode 100644 index 00000000..06b1036f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_not_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_not_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_not_digest/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_not_digest/app.cpp new file mode 100644 index 00000000..03605f0e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_not_digest/app.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// A key derivation over an hmac whose result is not a digest (FNV-1a's is a 64-bit integer) +// stops with spec section 3.3's text, and with no other error. + +#include + +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array input{}; + auto done = + webcpp::hash::hkdf>(output, input, input, input); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_not_digest/kdf_not_digest.outcome b/tools/test/fixtures/hash_jamfiles/kdf_not_digest/kdf_not_digest.outcome new file mode 100644 index 00000000..122cd977 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_not_digest/kdf_not_digest.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/kdf_not_digest, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: the key derivations take a Boost.Hash2 hmac whose result is a digest, as hmac_sha2_256. diff --git a/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/Jamfile b/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/Jamfile new file mode 100644 index 00000000..44db733b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/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_not_hmac 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_not_hmac/app.cpp b/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/app.cpp new file mode 100644 index 00000000..27363870 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/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) + +// hkdf_extract, whose result is the hmac's result_type, over a type that has none stops with +// spec section 3.3's text too, and with no "no matching function" error. + +#include + +#include +#include + +int main() { + std::array input{}; + auto prk = webcpp::hash::hkdf_extract(input, input); + return prk ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/kdf_not_hmac.outcome b/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/kdf_not_hmac.outcome new file mode 100644 index 00000000..411a84c1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/kdf_not_hmac/kdf_not_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. Natively and on WASI the same text is +# test/messages/kdf_not_hmac, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: the key derivations take a Boost.Hash2 hmac whose result is a digest, as hmac_sha2_256. diff --git a/tools/test/fixtures/hash_jamfiles/openssl_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/openssl_not_linked/Jamfile new file mode 100644 index 00000000..e47f7403 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_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_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_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/openssl_not_linked/app.cpp new file mode 100644 index 00000000..33065efe --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_not_linked/app.cpp @@ -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) + +// A program that names backends::openssl without linking /webcpp/hash//openssl stops with the +// instruction to add it (spec 5.7, the fifth row). + +#include + +int main() { + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/openssl_not_linked/openssl_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/openssl_not_linked/openssl_not_linked.outcome new file mode 100644 index 00000000..feca07d8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_not_linked/openssl_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/openssl_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 ; diff --git a/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/Jamfile b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/Jamfile new file mode 100644 index 00000000..2722c8ed --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/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) + +# Spec 5.1's line for OpenSSL, built for Emscripten (spec 5.6). +exe kdf : kdf.cpp /webcpp/hash//hash /webcpp/hash//openssl ; diff --git a/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp new file mode 100644 index 00000000..6bf70c08 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp @@ -0,0 +1,65 @@ +// 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 program over OpenSSL: HKDF (RFC 5869, A.1) and, where the backend has it, +// PBKDF2-HMAC-SHA-256 (RFC 7914, section 11, its first case). + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +// RFC 5869, appendix A.1: SHA-256, a 22-byte IKM, a 13-byte salt, a 10-byte info, 42 bytes. +std::array rfc5869_a1_okm() { + std::array ikm{}; + ikm.fill(0x0b); + std::array salt{}; + std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); + std::array info{}; + std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); + std::array okm{}; + if (!webcpp::hash::hkdf( + okm, salt, ikm, info)) { + okm.fill(0); + } + return okm; +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; +#if defined(WEBCPP_HASH_HAS_OPENSSL) + std::printf("HAS_OPENSSL=%d\n", WEBCPP_HASH_HAS_OPENSSL); +#endif + print_hex("hkdf", rfc5869_a1_okm()); + std::string_view const password = "password"; + std::string_view const salt = "salt"; + std::array derived{}; + auto const done = hash::pbkdf2( + derived, std::span(reinterpret_cast(password.data()), password.size()), + std::span(reinterpret_cast(salt.data()), salt.size()), 1); + print_hex("pbkdf2", derived); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/openssl_on_emscripten.outcome b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/openssl_on_emscripten.outcome new file mode 100644 index 00000000..ff059600 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/openssl_on_emscripten.outcome @@ -0,0 +1,12 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line of the #error starts with the forced header's path on the +# machine, so the message is a contains: line. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: OpenSSL is not built for Emscripten. In the program's Jamfile, remove /webcpp/hash//openssl: hkdf and pbkdf2 then run on backends::hash2. diff --git a/tools/test/fixtures/hash_jamfiles/override_cannot_serve/Jamfile b/tools/test/fixtures/hash_jamfiles/override_cannot_serve/Jamfile new file mode 100644 index 00000000..f04831bb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/override_cannot_serve/Jamfile @@ -0,0 +1,10 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# test/messages/override_cannot_serve of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /third_party//sodium + : WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM ; diff --git a/tools/test/fixtures/hash_jamfiles/override_cannot_serve/app.cpp b/tools/test/fixtures/hash_jamfiles/override_cannot_serve/app.cpp new file mode 100644 index 00000000..dd732576 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/override_cannot_serve/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) + +// An override whose backend lacks the function over the hmac used (spec 4.1): +// WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM and hkdf over hmac_sha2_384 stop with libsodium's +// text of spec 3.3, and with no other error. + +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array input{}; + auto done = webcpp::hash::hkdf(output, input, input, input); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/override_cannot_serve/override_cannot_serve.outcome b/tools/test/fixtures/hash_jamfiles/override_cannot_serve/override_cannot_serve.outcome new file mode 100644 index 00000000..b4e4a986 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/override_cannot_serve/override_cannot_serve.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/override_cannot_serve, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::sodium has HKDF over hmac_sha2_256 and hmac_sha2_512 alone. Over this hmac, name backends::hash2 (every hmac), backends::openssl (every hmac but hmac_ripemd_128) or backends::bearssl (MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512; hkdf alone). diff --git a/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/Jamfile b/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/Jamfile new file mode 100644 index 00000000..dbc65be8 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/Jamfile @@ -0,0 +1,12 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# Each operation's override, each selecting OpenSSL. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL + WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL + WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL + WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL ; diff --git a/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/app.cpp b/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/app.cpp new file mode 100644 index 00000000..d3159418 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/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) + +// A program that derives with HKDF on the default backend: the define its Jamfile gives stops +// it on Emscripten, where webcpp builds no OpenSSL. + +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array const input{}; + auto const done = webcpp::hash::hkdf(output, input, input, input); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/overrides_openssl_on_emscripten.outcome b/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/overrides_openssl_on_emscripten.outcome new file mode 100644 index 00000000..ad427d37 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/overrides_openssl_on_emscripten/overrides_openssl_on_emscripten.outcome @@ -0,0 +1,16 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's lines of the #errors start with the header's path on the machine, +# so the messages are contains: lines; clang goes on after an #error, so each is +# printed. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define. +contains: webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define. +contains: webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_ARGON2ID_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define. +contains: webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_SCRYPT_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define. diff --git a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/Jamfile b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/Jamfile new file mode 100644 index 00000000..444dea05 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/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/pbkdf2_on_bearssl of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash /third_party//bearssl ; diff --git a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/app.cpp b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/app.cpp new file mode 100644 index 00000000..f2912ab6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/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) + +// pbkdf2 on backends::bearssl, which has no PBKDF2, stops with spec section 3.3's text for +// BearSSL, not the primary template's, and with no other error. + +#include +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array input{}; + auto done = webcpp::hash::pbkdf2( + output, input, input, 1); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.outcome b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.outcome new file mode 100644 index 00000000..66b9833b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_bearssl/pbkdf2_on_bearssl.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/pbkdf2_on_bearssl, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: pbkdf2 is not in backends::bearssl: BearSSL has no PBKDF2. The backends that have pbkdf2: backends::hash2 (every hmac) and backends::openssl (every hmac but hmac_ripemd_128). diff --git a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/Jamfile b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/Jamfile new file mode 100644 index 00000000..42ff3a8c --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_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/pbkdf2_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/pbkdf2_on_sodium/app.cpp b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/app.cpp new file mode 100644 index 00000000..9abfd279 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/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) + +// pbkdf2 on backends::sodium stops with spec section 3.3's text: libsodium has no PBKDF2. + +#include + +#include +#include + +int main() { + std::array output{}; + std::array input{}; + auto done = webcpp::hash::pbkdf2( + output, input, input, 1); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_on_sodium.outcome b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_on_sodium.outcome new file mode 100644 index 00000000..031900fc --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pbkdf2_on_sodium/pbkdf2_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/pbkdf2_on_sodium, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: pbkdf2 is not in backends::sodium: libsodium has no PBKDF2. The backends that have pbkdf2: backends::hash2 (every hmac) and backends::openssl (every hmac but hmac_ripemd_128). diff --git a/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/Jamfile b/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/Jamfile new file mode 100644 index 00000000..11a1d4c5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/Jamfile @@ -0,0 +1,8 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_PROFILE_BACKEND_OPENSSL ; diff --git a/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/app.cpp b/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/app.cpp new file mode 100644 index 00000000..d3159418 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/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) + +// A program that derives with HKDF on the default backend: the define its Jamfile gives stops +// it on Emscripten, where webcpp builds no OpenSSL. + +#include +#include + +#include +#include + +int main() { + std::array output{}; + std::array const input{}; + auto const done = webcpp::hash::hkdf(output, input, input, input); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/profile_openssl_on_emscripten.outcome b/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/profile_openssl_on_emscripten.outcome new file mode 100644 index 00000000..64e29172 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/profile_openssl_on_emscripten/profile_openssl_on_emscripten.outcome @@ -0,0 +1,12 @@ +# Copyright (c) 2026 WebCpp.org +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# The compiler's line of the #error starts with the header's path on the machine, +# so the message is a contains: line. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define. diff --git a/tools/test/fixtures/hash_jamfiles/pw/Jamfile b/tools/test/fixtures/hash_jamfiles/pw/Jamfile new file mode 100644 index 00000000..b40ffcb6 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pw/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) + +# Spec 5.1: argon2id, scrypt and backends::sodium. +exe pw : pw.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/pw/pw.cpp b/tools/test/fixtures/hash_jamfiles/pw/pw.cpp new file mode 100644 index 00000000..077ad6bf --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pw/pw.cpp @@ -0,0 +1,82 @@ +// 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 program over libsodium: Argon2id on the first case of libsodium's own table +// (test/default/pwhash_argon2id.c at 77e1ce5: its salt's first 16 bytes, its memory limit +// rounded down to a multiple of 1,024), scrypt on RFC 7914's second case, and HKDF (RFC 5869, +// A.1) on backends::sodium. + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace { + +// Prints label, a space and bytes in lowercase hex, then a newline. +void print_hex(char const* label, std::span bytes) { + std::printf("%s ", label); + for (std::uint8_t const b : bytes) { + std::printf("%02x", static_cast(b)); + } + std::printf("\n"); +} + +// RFC 5869, appendix A.1: SHA-256, a 22-byte IKM, a 13-byte salt, a 10-byte info, 42 bytes. +std::array rfc5869_a1_okm() { + std::array ikm{}; + ikm.fill(0x0b); + std::array salt{}; + std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); + std::array info{}; + std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); + std::array okm{}; + if (!webcpp::hash::hkdf( + okm, salt, ikm, info)) { + okm.fill(0); + } + return okm; +} + +std::span bytes(std::string_view text) { + return {reinterpret_cast(text.data()), text.size()}; +} + +} // namespace + +int main() { + namespace hash = webcpp::hash; + std::array const password{ + 0xa3, 0x47, 0xae, 0x92, 0xbc, 0xe9, 0xf8, 0x0f, 0x6f, 0x59, 0x5a, 0x44, 0x80, 0xfc, 0x9c, + 0x2f, 0xe7, 0xe7, 0xd7, 0x14, 0x8d, 0x37, 0x1e, 0x94, 0x87, 0xd7, 0x5f, 0x5c, 0x23, 0x00, + 0x8f, 0xfa, 0xe0, 0x65, 0x57, 0x7a, 0x92, 0x8f, 0xeb, 0xd9, 0xb1, 0x97, 0x3a, 0x5a, 0x95, + 0x07, 0x3a, 0xcd, 0xbe, 0xb6, 0xa0, 0x30, 0xcf, 0xc0, 0xd7, 0x9c, 0xaa, 0x2d, 0xc5, 0xcd, + 0x01, 0x1c, 0xef, 0x02, 0xc0, 0x8d, 0xa2, 0x32, 0xd7, 0x6d, 0x52, 0xdf, 0xbc, 0xa3, 0x8c, + 0xa8, 0xdc, 0xbd, 0x66, 0x5b, 0x17, 0xd1, 0x66, 0x5f, 0x7c, 0xf5, 0xfe, 0x59, 0x77, 0x2e, + 0xc9, 0x09, 0x73, 0x3b, 0x24, 0xde, 0x97, 0xd6, 0xf5, 0x8d, 0x22, 0x0b, 0x20, 0xc6, 0x0d, + 0x7c, 0x07, 0xec, 0x1f, 0xd9, 0x3c, 0x52, 0xc3, 0x10, 0x20, 0x30, 0x0c, 0x6c, 0x1f, 0xac, + 0xd7, 0x79, 0x37, 0xa5, 0x97, 0xc7, 0xa6}; + std::array const salt{0x55, 0x41, 0xfb, 0xc9, 0x95, 0xd5, 0xc1, 0x97, + 0xba, 0x29, 0x03, 0x46, 0xd2, 0xc5, 0x59, 0xde}; + std::array tag{}; + auto const argon2 = hash::argon2id(tag, password, salt, {5, 7256064}); + print_hex("argon2id", tag); + + std::array scrypted{}; + auto const scrypt = hash::scrypt(scrypted, bytes("password"), bytes("NaCl"), {1024, 8, 16}); + print_hex("scrypt", scrypted); + + print_hex("hkdf", rfc5869_a1_okm()); + return argon2 && scrypt ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/pw/pw.outcome b/tools/test/fixtures/hash_jamfiles/pw/pw.outcome new file mode 100644 index 00000000..16ae2f7a --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/pw/pw.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) + +[all] +targets: native wasip2 wasip3 emscripten +build: succeeds +run: pw +argon2id 18acec5d6507739f203d1f5d9f1d862f7c2cdac4f19d2bdff64487e60d969e3ced615337b9eec6ac4461c6ca07f0939741e57c24d0005c7ea171a0ee1e7348249d135b38f222e4dad7b9a033ed83f5ca27277393e316582033c74affe2566a2bea47f91f0fd9fe49ece7e1f79f3ad6e9b23e0277c8ecc4b313225748dd2a80f5679534a0700e246a79a49b3f74eb89ec6205fe1eeb941c73b1fcf1 +scrypt fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640 +hkdf 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 diff --git a/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/Jamfile b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/Jamfile new file mode 100644 index 00000000..ec2f7afc --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/scrypt_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/scrypt_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/scrypt_on_hash2/app.cpp b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/app.cpp new file mode 100644 index 00000000..6ddaa95b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/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) + +// scrypt on another backend than backends::sodium stops with spec section 3.3's text. + +#include +#include + +#include +#include + +int main() { + std::array output{}; + auto done = webcpp::hash::scrypt(output, {}, {}, {16, 1, 1}); + return done ? 0 : 1; +} 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 new file mode 100644 index 00000000..79e06c6e --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/scrypt_on_hash2/scrypt_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/scrypt_on_hash2, a compile-diagnostic. +[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. diff --git a/tools/test/fixtures/hash_jamfiles/sodium_hmac/Jamfile b/tools/test/fixtures/hash_jamfiles/sodium_hmac/Jamfile new file mode 100644 index 00000000..6516e7f1 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_hmac/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_hmac 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/sodium_hmac/app.cpp b/tools/test/fixtures/hash_jamfiles/sodium_hmac/app.cpp new file mode 100644 index 00000000..db10b589 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_hmac/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) + +// hkdf over an hmac libsodium has no HKDF for stops with spec section 3.3's text for +// backends::sodium. + +#include + +#include +#include + +int main() { + std::array output{}; + std::array input{}; + auto done = webcpp::hash::hkdf( + output, input, input, input); + return done ? 0 : 1; +} diff --git a/tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_hmac.outcome b/tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_hmac.outcome new file mode 100644 index 00000000..9747cbbc --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_hmac/sodium_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. Natively and on WASI the same text is +# test/messages/sodium_hmac, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::sodium has HKDF over hmac_sha2_256 and hmac_sha2_512 alone. Over this hmac, name backends::hash2 (every hmac), backends::openssl (every hmac but hmac_ripemd_128) or backends::bearssl (MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512; hkdf alone). diff --git a/tools/test/fixtures/hash_jamfiles/sodium_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/Jamfile new file mode 100644 index 00000000..e03b00bb --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_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_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_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/app.cpp new file mode 100644 index 00000000..0573b04a --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/app.cpp @@ -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) + +// A program that names backends::sodium and does not link libsodium stops with the instruction to +// add /third_party//sodium (spec section 5.7, the third row). + +#include + +int main() { + return 0; +} 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 new file mode 100644 index 00000000..c0cf3516 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/sodium_not_linked/sodium_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_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: backends::sodium, argon2id and scrypt need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ; diff --git a/tools/test/fixtures/hash_jamfiles/two_overrides/Jamfile b/tools/test/fixtures/hash_jamfiles/two_overrides/Jamfile new file mode 100644 index 00000000..9802d87f --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_overrides/Jamfile @@ -0,0 +1,11 @@ +# 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/two_overrides of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2 + WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM ; diff --git a/tools/test/fixtures/hash_jamfiles/two_overrides/app.cpp b/tools/test/fixtures/hash_jamfiles/two_overrides/app.cpp new file mode 100644 index 00000000..c3c0a5e3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_overrides/app.cpp @@ -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) + +// Two overrides of HKDF's default backend (spec 4.1) stop the build with an #error naming both +// defines. + +#include + +int main() { + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/two_overrides/two_overrides.outcome b/tools/test/fixtures/hash_jamfiles/two_overrides/two_overrides.outcome new file mode 100644 index 00000000..1949f007 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_overrides/two_overrides.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/two_overrides, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM are both defined. Keep one. diff --git a/tools/test/fixtures/hash_jamfiles/two_profiles/Jamfile b/tools/test/fixtures/hash_jamfiles/two_profiles/Jamfile new file mode 100644 index 00000000..8ddb1af4 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_profiles/Jamfile @@ -0,0 +1,11 @@ +# 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/two_profiles of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_HASH_PROFILE_FASTEST + WEBCPP_HASH_PROFILE_SMALLEST ; diff --git a/tools/test/fixtures/hash_jamfiles/two_profiles/app.cpp b/tools/test/fixtures/hash_jamfiles/two_profiles/app.cpp new file mode 100644 index 00000000..5bc57eb5 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_profiles/app.cpp @@ -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) + +// Two library profiles (spec 4.1) stop the build with an #error naming both defines. + +#include + +int main() { + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/two_profiles/two_profiles.outcome b/tools/test/fixtures/hash_jamfiles/two_profiles/two_profiles.outcome new file mode 100644 index 00000000..ee7e5835 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_profiles/two_profiles.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/two_profiles, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_SMALLEST are both defined. Keep one. diff --git a/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/Jamfile b/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/Jamfile new file mode 100644 index 00000000..f58c6537 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/Jamfile @@ -0,0 +1,11 @@ +# 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/two_umbrella_profiles of webcpp::hash, built for Emscripten +# by a user's Jamfile. +exe app : app.cpp /webcpp/hash//hash + : WEBCPP_PROFILE_FASTEST + WEBCPP_PROFILE_PORTABLE ; diff --git a/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/app.cpp b/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/app.cpp new file mode 100644 index 00000000..5d49b9ba --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/app.cpp @@ -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) + +// Two of webcpp's umbrella profiles (spec 4.1) stop the build with an #error naming both +// defines. + +#include + +int main() { + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/two_umbrella_profiles.outcome b/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/two_umbrella_profiles.outcome new file mode 100644 index 00000000..8acadddf --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/two_umbrella_profiles/two_umbrella_profiles.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/two_umbrella_profiles, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: WEBCPP_PROFILE_FASTEST and WEBCPP_PROFILE_PORTABLE are both defined. Keep one. diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_not_linked/Jamfile b/tools/test/fixtures/hash_jamfiles/xkcp_not_linked/Jamfile new file mode 100644 index 00000000..2b89acc3 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_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_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_not_linked/app.cpp b/tools/test/fixtures/hash_jamfiles/xkcp_not_linked/app.cpp new file mode 100644 index 00000000..b28b356b --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_not_linked/app.cpp @@ -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) + +// A program that names keccak_256 and does not link XKCP stops with the instruction to add +// /third_party//xkcp (spec section 5.7, the first row). + +#include + +int main() { + return 0; +} diff --git a/tools/test/fixtures/hash_jamfiles/xkcp_not_linked/xkcp_not_linked.outcome b/tools/test/fixtures/hash_jamfiles/xkcp_not_linked/xkcp_not_linked.outcome new file mode 100644 index 00000000..b7fa7b20 --- /dev/null +++ b/tools/test/fixtures/hash_jamfiles/xkcp_not_linked/xkcp_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_not_linked, a compile-diagnostic. +[all] +targets: emscripten +build: fails +contains: webcpp::hash: keccak_256 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_jamfiles_test.py b/tools/test/hash_jamfiles_test.py new file mode 100644 index 00000000..35abede0 --- /dev/null +++ b/tools/test/hash_jamfiles_test.py @@ -0,0 +1,116 @@ +#!/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) + +"""Builds every fixture of tools/test/fixtures/hash_jamfiles, a Jamfile as a user of webcpp::hash +writes it (b2's raw exe), with b2 as a user runs it, and checks its outcome file: the build's +status, the lines a failure prints, and a program's output (CODING-GUIDELINES.md chapter 8). The +cases are each line of the library's spec 5.1, one program with every C library, and each stop of +the build: the canaries at link time on every target, and the messages raised on Emscripten. + +The outcome files, their format and the build of a case are crypto_jamfiles_test.py's, read +through it: one scratch superproject per target, with libs/config, libs/hash, libs/crypto (whose +canary /third_party//bearssl compiles) and the fixtures in it; every case of a target shares one +build directory, so each C library is compiled once per target. Run with the names of some cases +to run only those, and with --target to run one target.""" + +from __future__ import annotations + +import shutil +import sys +import time +from pathlib import Path + +import crypto_jamfiles_test as jamfiles +import harness + +CASES = harness.FIXTURES / 'hash_jamfiles' + +# Cases whose outcome needs code that is not merged yet, as crypto_jamfiles_test.py's NOT_YET: +# a run without names leaves them out (and says so), a run that names one builds it. +NOT_YET: dict[str, str] = {} + + +def case_directories() -> list[Path]: + """Every directory of CASES, each with its one outcome file named after it and a Jamfile, + and every outcome file read for every target, else a jamfiles.OutcomeError.""" + cases = sorted(p for p in CASES.iterdir() if p.is_dir()) + for case in cases: + found = sorted(p.name for p in case.glob('*.outcome')) + if found != [case.name + '.outcome']: + raise jamfiles.OutcomeError(f'{case.name}: the outcome files are {found}; ' + f'the one is {case.name}.outcome') + if not (case / 'Jamfile').is_file(): + raise jamfiles.OutcomeError(f'{case.name}: no Jamfile') + for target in jamfiles.TOOLSETS: + jamfiles.outcome(case / f'{case.name}.outcome', target) + return cases + + +def selected(cases: list[Path], names: list[str], target: str) -> list[Path]: + """The cases to build for target: the named ones, else every one that is not in NOT_YET, + each that its outcome file's targets line names target for.""" + return [case for case in cases + if (case.name in names if names else case.name not in NOT_YET) + and target in jamfiles.outcome(case / f'{case.name}.outcome', target).targets] + + +def main(argv: list[str]) -> int: + targets = list(jamfiles.TOOLSETS) + if '--target' in argv: + position = argv.index('--target') + if position + 1 >= len(argv) or argv[position + 1] not in jamfiles.TOOLSETS: + print(f'hash_jamfiles: --target takes one of {targets}', file=sys.stderr) + return 2 + targets = [argv[position + 1]] + argv = argv[:position] + argv[position + 2:] + names = [a for a in argv if not a.startswith('--')] + if len(names) != len(argv): + print(f'hash_jamfiles: no option {[a for a in argv if a.startswith("--")]}; ' + 'the one is --target ', file=sys.stderr) + return 2 + try: + cases = case_directories() + except jamfiles.OutcomeError as error: + print(f'hash_jamfiles: {error}', file=sys.stderr) + return 2 + missing = [n for n in names if n not in {c.name for c in cases}] + if missing: + print(f'hash_jamfiles: no case named {missing}', file=sys.stderr) + return 2 + if not names: + for case, reason in NOT_YET.items(): + print(f'left out until {reason}: {case}') + faults: list[str] = [] + built = 0 + for target in targets: + chosen = selected(cases, names, target) + if not chosen: + continue + built += len(chosen) + started = time.monotonic() + root = harness.scratch_superproject() + try: + harness.copy_integration_libraries(root, 'config', 'hash', 'crypto') + shutil.copytree(CASES, root / 'user', ignore=harness.built) + if target == 'emscripten': + harness.link_emsdk(root) + elif target.startswith('wasi'): + harness.link_wasi_tools(root) + faults += jamfiles.run_target(root, target, chosen) + finally: + shutil.rmtree(root) + print(f'{target}: {len(chosen)} cases in {time.monotonic() - started:.0f} s') + if not built: + faults.append(f'no case was built for {targets}; nothing was tested') + for fault in faults: + print(f'hash_jamfiles: {fault}', file=sys.stderr) + print('hash_jamfiles_test: ' + ('failed' if faults else 'ok')) + return 1 if faults else 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) From de2da41e8857fe7dea1ad1a4cbe828aa14c99aba Mon Sep 17 00:00:00 2001 From: R Date: Sun, 15 Nov 2026 07:30:58 -0300 Subject: [PATCH 20/47] tools: one module for the user's Jamfiles tests, and every message of webcpp::hash checked against its Emscripten fixture --- CODING-GUIDELINES.md | 14 +- tools/test/crypto_jamfiles_format_test.py | 27 +- tools/test/crypto_jamfiles_test.py | 283 +--------------- .../canary_blake3_missing.outcome | 8 +- .../canary_blake3_other_commit.outcome | 8 +- .../every_library_emscripten/Jamfile | 6 +- .../every_library_emscripten/app.cpp | 61 ---- .../openssl_on_emscripten/Jamfile | 4 +- .../openssl_on_emscripten/kdf.cpp | 65 ---- tools/test/hash_jamfiles_format_test.py | 97 ++++++ tools/test/hash_jamfiles_test.py | 151 ++++----- tools/test/user_jamfiles.py | 316 ++++++++++++++++++ 12 files changed, 535 insertions(+), 505 deletions(-) delete mode 100644 tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp delete mode 100644 tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp create mode 100644 tools/test/hash_jamfiles_format_test.py create mode 100644 tools/test/user_jamfiles.py diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 8412b0bf..14193430 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -102,6 +102,7 @@ Not built yet: `tools/test/component_jam_test.py`, `tools/generated/generated_test.py`, `tools/test/emscripten_test.py`, `tools/test/crypto_jamfiles_test.py`, `tools/test/crypto_jamfiles_format_test.py`, + `tools/test/hash_jamfiles_test.py`, `tools/test/hash_jamfiles_format_test.py`, `tools/test/external_test.py`, `tools/test/doc_test.py`, `tools/test/harness_test.py`, `tools/test/third_party_test.py`, @@ -581,15 +582,16 @@ aliases, concepts, variables, data members and macros. silently. - A user's Jamfile of a library whose own tests cannot express it (b2's raw `exe`, a refusal on one target) is a fixture of the tools' test, not a - library's test: `tools/test/fixtures/crypto_jamfiles//` holds the + library's test: `tools/test/fixtures/_jamfiles//` holds the case's `Jamfile`, its sources and `.outcome`, and - `tools/test/crypto_jamfiles_test.py` builds each case on a scratch + `tools/test/_jamfiles_test.py` builds each case on a scratch superproject, with b2 as a user runs it, once per target, in a build - directory the cases of a target share. The outcome file's lines starting + directory the cases of a target share, through `tools/test/user_jamfiles.py`, + which every such test shares. The outcome file's lines starting with `#` are comments; a block `[all]`, `[native]`, `[native-linux]`, - `[native-darwin]`, `[native-windows]`, `[wasip2]`, `[wasip3]` or - `[emscripten]` applies by the target and the system (`[all]` and each block - that matches apply). `targets: ...` (native only without it) names + `[native-darwin]`, `[native-windows]`, `[native-arm64]`, `[native-x86_64]`, + `[wasip2]`, `[wasip3]` or `[emscripten]` applies by the target, the system + and the machine's architecture (`[all]` and each block that matches apply). `targets: ...` (native only without it) names the targets the case is built for; `build: succeeds` or `build: fails` is b2's exit status; after `build: fails` every other line must be a whole line of b2's output (trailing spaces aside), in any order; a line of one diff --git a/tools/test/crypto_jamfiles_format_test.py b/tools/test/crypto_jamfiles_format_test.py index 550eb2d3..489c6901 100644 --- a/tools/test/crypto_jamfiles_format_test.py +++ b/tools/test/crypto_jamfiles_format_test.py @@ -5,8 +5,9 @@ # accompanying file LICENSE_1_0.txt or copy at # https://www.boost.org/LICENSE_1_0.txt) -"""Checks crypto_jamfiles_test.py's own rules, without building anything: what an outcome file -may say, what a run that builds nothing is, and how a failure's lines are matched (whole lines). +"""Checks the rules of user_jamfiles.py, which crypto_jamfiles_test.py and hash_jamfiles_test.py +share, without building anything: what an outcome file may say, what a run that builds nothing +is, and how a failure's lines are matched (whole lines). """ from __future__ import annotations @@ -16,8 +17,9 @@ import tempfile from pathlib import Path -import crypto_jamfiles_test as jamfiles +import crypto_jamfiles_test import harness +import user_jamfiles as jamfiles TEST = Path(__file__).resolve().parent / 'crypto_jamfiles_test.py' @@ -138,10 +140,27 @@ def test_same_as_keeps_copies_identical(): outcome.write_text('[all]\nsame-as: a/app.cpp\nbuild: succeeds\n') assert jamfiles.same_as_faults(cases / 'b', cases), 'one name is a fault' assert parse('[all]\nsame-as: a/app.cpp app.cpp\nbuild: succeeds\n').succeeds +def test_a_native_block_applies_by_architecture(): + text = ('[all]\nbuild: fails\n[native-arm64]\ncontains: arm\n' + '[native-x86_64]\ncontains: x86\n') + expected = {'arm64': ['arm'], 'x86_64': ['x86']}.get(jamfiles.ARCHITECTURE, []) + assert parse(text).contains == expected, (jamfiles.ARCHITECTURE, parse(text)) + assert parse('[all]\ntargets: wasip2\nbuild: fails\nx\n[native-arm64]\ncontains: arm\n', + 'wasip2').contains == [] + + +def test_a_library_not_checked_out_is_named(): + result = subprocess.run( + [sys.executable, '-c', 'import sys, user_jamfiles; sys.exit(user_jamfiles.main(' + '"t", user_jamfiles.harness.FIXTURES, ("no_such_library",), {}, []))'], + capture_output=True, text=True, check=False, cwd=TEST.parent) + assert result.returncode == 2, result + assert ('libs/no_such_library is not checked out' in result.stderr + and 'git submodule update --init libs/no_such_library' in result.stderr), result def test_every_case_directory_is_read(): - cases = jamfiles.case_directories() + cases = jamfiles.case_directories(crypto_jamfiles_test.CASES) assert {c.name for c in cases} >= {'hello', 'broken'}, cases diff --git a/tools/test/crypto_jamfiles_test.py b/tools/test/crypto_jamfiles_test.py index 9b4cd1e5..cb478886 100644 --- a/tools/test/crypto_jamfiles_test.py +++ b/tools/test/crypto_jamfiles_test.py @@ -8,28 +8,19 @@ """Builds every fixture of tools/test/fixtures/crypto_jamfiles, a Jamfile as a user of webcpp::crypto writes it (b2's raw exe), with b2 as a user runs it, and checks its outcome file: the build's status, the lines a failure prints, and a program's output (CODING-GUIDELINES.md -chapter 8). One scratch superproject per target, with libs/crypto and the fixtures in it; every -case of a target shares one build directory, so BearSSL's 295 files are compiled once per -target. Run with the names of some cases to run only those, and with --target to run one -target.""" +chapter 8), through user_jamfiles.py. One scratch superproject per target, with libs/crypto and +the fixtures in it; every case of a target shares one build directory, so BearSSL's 295 files are +compiled once per target. Run with the names of some cases to run only those, and with +--target to run one target.""" from __future__ import annotations -import platform -import re -import shutil -import subprocess import sys -import time -from dataclasses import dataclass, field -from pathlib import Path import harness +import user_jamfiles CASES = harness.FIXTURES / 'crypto_jamfiles' -TOOLSETS = {'native': [], 'wasip2': ['toolset=clang-wasip2'], 'wasip3': ['toolset=clang-wasip3'], - 'emscripten': ['toolset=emscripten']} -SYSTEM = {'Linux': 'linux', 'Darwin': 'darwin', 'Windows': 'windows'}[platform.system()] # Cases whose outcome needs code that is not merged yet: a run without names leaves them out # (and says so), a run that names one builds it. Each entry names what it waits for. The @@ -37,271 +28,9 @@ # cases' outcome files as b2's whole output lines (a line: directive, if need be). NOT_YET: dict[str, str] = {} -BLOCKS = {'all', 'native', 'native-linux', 'native-darwin', 'native-windows', 'wasip2', 'wasip3', - 'emscripten'} - - -class OutcomeError(Exception): - """An outcome file or a case directory that does not follow the format.""" - - -def launcher(target: str) -> Path: - """The script the lanes run a WASI program with (tools/ci/matrix.py, wasm_lane).""" - return harness.ROOT / f'tools/boost/asio-{target}/run.sh' - - -@dataclass -class Outcome: - """What an outcome file says for one target.""" - targets: list[str] = field(default_factory=lambda: ['native']) - succeeds: bool | None = None - run: str | None = None - lines: list[str] = field(default_factory=list) - contains: list[str] = field(default_factory=list) - # (text, allowed): no line of b2's output contains text, unless it also contains allowed - # (none: not even then). - forbidden: list[tuple[str, str | None]] = field(default_factory=list) - arguments: list[str] = field(default_factory=list) - - -def outcome(path: Path, target: str) -> Outcome: - """The blocks of path that apply to target on this system, read into an Outcome. Every line - of the file is checked, whether its block applies or not, and so is the outcome that results - when target is one the case is built for (checked).""" - applying = {'all', target} | ({'native', 'native-' + SYSTEM} if target == 'native' else set()) - result = Outcome() - block = None - for number, raw in enumerate(path.read_text().splitlines(), 1): - where = f'{path.name}:{number}' - if not raw.strip() or raw.startswith('#'): - continue - if raw.startswith('[') and raw.endswith(']'): - block = raw[1:-1] - if block not in BLOCKS: - raise OutcomeError(f'{where}: no block [{block}]; the blocks are {sorted(BLOCKS)}') - continue - if block is None: - raise OutcomeError(f'{where}: a line before the first [block]: {raw!r}') - directive = re.match(r'([a-z]+(?:-[a-z]+)?):(?: |$)', raw) - key, value = (directive.group(1), raw[directive.end():]) if directive else ('', raw) - if key and key not in ('targets', 'build', 'run', 'arguments', 'line', 'contains', - 'not-contains', 'same-as'): - raise OutcomeError(f'{where}: no directive {key}: (a line of one lowercase word and ' - f'a colon is reserved for them): {raw!r}') - if key in ('targets', 'arguments', 'not-contains') and not value.split(): - raise OutcomeError(f'{where}: {key}: names nothing') - if key == 'targets': - unknown = [t for t in value.split() if t not in TOOLSETS] - if unknown: - raise OutcomeError( - f'{where}: no target {unknown}; the targets are {list(TOOLSETS)}') - elif key == 'build' and value not in ('succeeds', 'fails'): - raise OutcomeError(f'{where}: build: is succeeds or fails, not {value!r}') - elif key == 'run' and not value: - raise OutcomeError(f'{where}: run: names no program') - if block not in applying or key == 'same-as': - continue - if key == 'targets': - result.targets = value.split() - elif key == 'build': - result.succeeds = value == 'succeeds' - elif key == 'run': - result.run = value - elif key == 'arguments': - result.arguments += value.split() - elif key == 'contains': - result.contains.append(value) - elif key == 'not-contains': - text, separator, allowed = value.partition(' unless ') - if not text.strip() or (separator and not allowed.strip()): - raise OutcomeError(f'{where}: not-contains: needs a text, then ` unless ` ' - f'if any line may hold it: {raw!r}') - result.forbidden.append((text.strip(), allowed.strip() or None)) - else: - result.lines.append(value if key == 'line' else raw) - if target in result.targets: - checked(path, target, result) - return result - - -def checked(path: Path, target: str, result: Outcome) -> None: - """Raises an OutcomeError naming path and target unless result is coherent: a build is said - to succeed or fail; a failure has lines to find and no program to run; a success that - prints lines has a program.""" - if result.succeeds is None: - raise OutcomeError(f'{path.name} on {target}: no build: line') - if not result.succeeds and result.run is not None: - raise OutcomeError(f'{path.name} on {target}: run: after build: fails') - if result.succeeds and (result.contains or result.forbidden): - raise OutcomeError(f'{path.name} on {target}: contains: or not-contains: after build: ' - 'succeeds') - if not result.succeeds and not result.lines and not result.contains: - raise OutcomeError(f'{path.name} on {target}: build: fails with no line to find') - if result.succeeds and result.run is None and result.lines: - raise OutcomeError(f'{path.name} on {target}: lines after build: succeeds, with no run:') - - -def same_as_faults(case: Path, cases: Path = CASES) -> list[str]: - """Each `same-as: / ` of case's outcome file whose two files are not - byte-identical: the file of another case, and case's own copy of it. A fixture's program is - a copy, never a symbolic link (a checkout on Windows reads a link as a text file), and this - keeps the copies from drifting.""" - faults: list[str] = [] - for number, raw in enumerate((case / f'{case.name}.outcome').read_text().splitlines(), 1): - if not raw.startswith('same-as:'): - continue - names = raw[len('same-as:'):].split() - where = f'{case.name}.outcome:{number}' - if len(names) != 2: - faults.append(f'{where}: same-as: names / and , not {names}') - continue - original, copy = cases / names[0], case / names[1] - if not original.is_file() or not copy.is_file(): - faults.append(f'{where}: {names[0]} or {case.name}/{names[1]} does not exist') - elif original.read_bytes() != copy.read_bytes(): - faults.append(f'{where}: {case.name}/{names[1]} is not a copy of {names[0]}') - return faults - - -def case_directories() -> list[Path]: - """Every directory of CASES, each with its one outcome file named after it, and every - outcome file read for every target (so each line of each block is checked), else an - OutcomeError.""" - cases = sorted(p for p in CASES.iterdir() if p.is_dir()) - for case in cases: - found = sorted(p.name for p in case.glob('*.outcome')) - if found != [case.name + '.outcome']: - raise OutcomeError(f'{case.name}: the outcome files are {found}; ' - f'the one is {case.name}.outcome') - if not (case / 'Jamfile').is_file(): - raise OutcomeError(f'{case.name}: no Jamfile') - for target in TOOLSETS: - outcome(case / f'{case.name}.outcome', target) - faults = same_as_faults(case) - if faults: - raise OutcomeError('; '.join(faults)) - return cases - - -def program_command(build_dir: Path, case: str, name: str, target: str) -> list[str]: - """The command that runs the program name that the build of case made under build_dir, as its - lane runs one.""" - suffix = {'native': '.exe' if SYSTEM == 'windows' else '', 'wasip2': '.wasm', - 'wasip3': '.wasm', 'emscripten': '.js'}[target] - found = [p for p in build_dir.rglob(name + suffix) - if p.is_file() and f'user/{case}/' in p.relative_to(build_dir).as_posix()] - if len(found) != 1: - raise AssertionError(f'the build made {len(found)} files named {name}{suffix}') - if target == 'emscripten': - return ['node', str(found[0])] - if target.startswith('wasi'): - return [str(launcher(target)), str(found[0])] - return [str(found[0])] - - -def selected(cases: list[Path], names: list[str], target: str) -> list[Path]: - """The cases to build for target: the named ones, else every one that is not in NOT_YET, - each that its outcome file's targets line names target for.""" - return [case for case in cases - if (case.name in names if names else case.name not in NOT_YET) - and target in outcome(case / f'{case.name}.outcome', target).targets] - - -def run_target(root: Path, target: str, cases: list[Path]) -> list[str]: - """Builds each of cases for target in root and returns the faults, one line each.""" - faults: list[str] = [] - build_dir = root / 'bin' / f'user-{target}' - for case in cases: - expected = outcome(case / f'{case.name}.outcome', target) - scratch = root / 'scratch' / case.name - scratch.mkdir(parents=True, exist_ok=True) - arguments = [a.replace('@scratch', str(scratch)) for a in expected.arguments] - # No testing.launcher: a user's exe is run by this test, not by b2. - built = harness.run_b2(root, '-j3', f'--build-dir={build_dir}', *TOOLSETS[target], - *arguments, f'user/{case.name}') - output = built.stdout - if (built.returncode == 0) != expected.succeeds: - faults.append(f'{case.name} on {target}: the build ' - f'{"succeeded" if built.returncode == 0 else "failed"}\n{output[-3000:]}') - continue - if not expected.succeeds: - printed = {line.rstrip() for line in output.splitlines()} - faults += [f'{case.name} on {target}: b2 printed no line {line!r}' - for line in expected.lines if line.rstrip() not in printed] - faults += [f'{case.name} on {target}: no line of b2 contains {text!r}' - for text in expected.contains - if not any(text in line for line in printed)] - faults += [f'{case.name} on {target}: b2 printed {line!r}, which contains {text!r}' - f'{"" if allowed is None else f" and not {allowed!r}"}' - for text, allowed in expected.forbidden for line in sorted(printed) - if text in line and (allowed is None or allowed not in line)] - continue - if expected.run is not None: - try: - command = program_command(build_dir, case.name, expected.run, target) - except AssertionError as error: - faults.append(f'{case.name} on {target}: {error}') - continue - ran = subprocess.run(command, capture_output=True, text=True, check=False) - printed = ran.stdout.replace('\r\n', '\n').splitlines() - if ran.returncode != 0 or printed != expected.lines: - faults.append(f'{case.name} on {target}: {expected.run} exited {ran.returncode} ' - f'and printed {printed!r}; the outcome says {expected.lines!r}') - return faults - def main(argv: list[str]) -> int: - targets = list(TOOLSETS) - if '--target' in argv: - position = argv.index('--target') - if position + 1 >= len(argv) or argv[position + 1] not in TOOLSETS: - print(f'crypto_jamfiles: --target takes one of {list(TOOLSETS)}', file=sys.stderr) - return 2 - targets = [argv[position + 1]] - argv = argv[:position] + argv[position + 2:] - names = [a for a in argv if not a.startswith('--')] - if len(names) != len(argv): - print(f'crypto_jamfiles: no option {[a for a in argv if a.startswith("--")]}; ' - 'the one is --target ', file=sys.stderr) - return 2 - try: - cases = case_directories() - except OutcomeError as error: - print(f'crypto_jamfiles: {error}', file=sys.stderr) - return 2 - missing = [n for n in names if n not in {c.name for c in cases}] - if missing: - print(f'crypto_jamfiles: no case named {missing}', file=sys.stderr) - return 2 - if not names and NOT_YET: - for case, reason in NOT_YET.items(): - print(f'left out until {reason}: {case}') - faults: list[str] = [] - built = 0 - for target in targets: - chosen = selected(cases, names, target) - if not chosen: - continue - built += len(chosen) - started = time.monotonic() - root = harness.scratch_superproject() - try: - harness.copy_integration_libraries(root, 'config', 'crypto') - shutil.copytree(CASES, root / 'user', ignore=harness.built) - if target == 'emscripten': - harness.link_emsdk(root) - elif target.startswith('wasi'): - harness.link_wasi_tools(root) - faults += run_target(root, target, chosen) - finally: - shutil.rmtree(root) - print(f'{target}: done in {time.monotonic() - started:.0f} s') - if not built: - faults.append(f'no case was built for {targets}; nothing was tested') - for fault in faults: - print(f'crypto_jamfiles: {fault}', file=sys.stderr) - print('crypto_jamfiles_test: ' + ('failed' if faults else 'ok')) - return 1 if faults else 0 + return user_jamfiles.main('crypto_jamfiles', CASES, ('config', 'crypto'), NOT_YET, argv) if __name__ == '__main__': diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome index 569fcf14..63ebb00a 100644 --- a/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_missing/canary_blake3_missing.outcome @@ -4,15 +4,19 @@ # accompanying file LICENSE_1_0.txt or copy at # https://www.boost.org/LICENSE_1_0.txt) +# BLAKE3's configuration, and so the canary's name, follows the machine natively: +# neon on arm64, x86 on x86-64; the linker's own words follow the system. [all] targets: native wasip2 wasip3 emscripten build: fails [native-darwin] contains: Undefined symbols for architecture -contains: _webcpp_hash_blake3_f3149ec_neon__add_third_party_blake3_to_your_link [native-linux] +contains: undefined reference to ` +[native-arm64] +contains: webcpp_hash_blake3_f3149ec_neon__add_third_party_blake3_to_your_link +[native-x86_64] contains: webcpp_hash_blake3_f3149ec_x86__add_third_party_blake3_to_your_link -contains: undefined reference to `webcpp_hash_blake3_f3149ec_x86__add_third_party_blake3_to_your_link' [wasip2] contains: wasm-ld: error: contains: undefined symbol: webcpp_hash_blake3_f3149ec_portable__add_third_party_blake3_to_your_link diff --git a/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome index 05172ac3..337eec99 100644 --- a/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome +++ b/tools/test/fixtures/hash_jamfiles/canary_blake3_other_commit/canary_blake3_other_commit.outcome @@ -4,15 +4,19 @@ # accompanying file LICENSE_1_0.txt or copy at # https://www.boost.org/LICENSE_1_0.txt) +# BLAKE3's configuration, and so the canary's name, follows the machine natively: +# neon on arm64, x86 on x86-64; the linker's own words follow the system. [all] targets: native wasip2 wasip3 emscripten build: fails [native-darwin] contains: Undefined symbols for architecture -contains: _webcpp_hash_blake3_0000000_neon__add_third_party_blake3_to_your_link [native-linux] +contains: undefined reference to ` +[native-arm64] +contains: webcpp_hash_blake3_0000000_neon__add_third_party_blake3_to_your_link +[native-x86_64] contains: webcpp_hash_blake3_0000000_x86__add_third_party_blake3_to_your_link -contains: undefined reference to `webcpp_hash_blake3_0000000_x86__add_third_party_blake3_to_your_link' [wasip2] contains: wasm-ld: error: contains: undefined symbol: webcpp_hash_blake3_0000000_portable__add_third_party_blake3_to_your_link diff --git a/tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile index 129f56f9..1e76e175 100644 --- a/tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile +++ b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/Jamfile @@ -5,6 +5,6 @@ # https://www.boost.org/LICENSE_1_0.txt) # Every C library of webcpp::hash in one program, on Emscripten, where webcpp -# builds no OpenSSL. -exe app : app.cpp /webcpp/hash//hash /third_party//xkcp /third_party//blake3 - /third_party//sodium /third_party//bearssl ; +# builds no OpenSSL: every_library's program. +exe app : ../every_library/app.cpp /webcpp/hash//hash /third_party//xkcp + /third_party//blake3 /third_party//sodium /third_party//bearssl ; diff --git a/tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp b/tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp deleted file mode 100644 index b92cf047..00000000 --- a/tools/test/fixtures/hash_jamfiles/every_library_emscripten/app.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -// One program over every C library of webcpp::hash its target has: Keccak-256 and BLAKE3 of -// nothing, then HKDF (RFC 5869, A.1) on each linked backend and on the default backend. Each -// library is one archive, linked once; their symbols do not collide. - -#include - -#include -#include -#include -#include -#include - -namespace { - -// Prints label, a space and bytes in lowercase hex, then a newline. -void print_hex(char const* label, std::span bytes) { - std::printf("%s ", label); - for (std::uint8_t const b : bytes) { - std::printf("%02x", static_cast(b)); - } - std::printf("\n"); -} - -template -std::array rfc5869_a1_okm() { - std::array ikm{}; - ikm.fill(0x0b); - std::array salt{}; - std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); - std::array info{}; - std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); - std::array okm{}; - if (!webcpp::hash::hkdf(okm, salt, ikm, info)) { - okm.fill(0); - } - return okm; -} - -} // namespace - -int main() { - namespace hash = webcpp::hash; - hash::keccak_256 keccak; - print_hex("keccak_256", keccak.result()); - hash::blake3 blake; - print_hex("blake3", blake.result()); - print_hex("hkdf hash2", rfc5869_a1_okm()); - print_hex("hkdf sodium", rfc5869_a1_okm()); - print_hex("hkdf bearssl", rfc5869_a1_okm()); -#if defined(WEBCPP_HASH_HAS_OPENSSL) - print_hex("hkdf openssl", rfc5869_a1_okm()); -#endif - print_hex("hkdf default", rfc5869_a1_okm>()); - return 0; -} diff --git a/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/Jamfile b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/Jamfile index 2722c8ed..497af0f6 100644 --- a/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/Jamfile +++ b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/Jamfile @@ -4,5 +4,5 @@ # accompanying file LICENSE_1_0.txt or copy at # https://www.boost.org/LICENSE_1_0.txt) -# Spec 5.1's line for OpenSSL, built for Emscripten (spec 5.6). -exe kdf : kdf.cpp /webcpp/hash//hash /webcpp/hash//openssl ; +# Spec 5.1's line for OpenSSL, built for Emscripten (spec 5.6): kdf's program. +exe kdf : ../kdf/kdf.cpp /webcpp/hash//hash /webcpp/hash//openssl ; diff --git a/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp b/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp deleted file mode 100644 index 6bf70c08..00000000 --- a/tools/test/fixtures/hash_jamfiles/openssl_on_emscripten/kdf.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -// A program over OpenSSL: HKDF (RFC 5869, A.1) and, where the backend has it, -// PBKDF2-HMAC-SHA-256 (RFC 7914, section 11, its first case). - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace { - -// Prints label, a space and bytes in lowercase hex, then a newline. -void print_hex(char const* label, std::span bytes) { - std::printf("%s ", label); - for (std::uint8_t const b : bytes) { - std::printf("%02x", static_cast(b)); - } - std::printf("\n"); -} - -// RFC 5869, appendix A.1: SHA-256, a 22-byte IKM, a 13-byte salt, a 10-byte info, 42 bytes. -std::array rfc5869_a1_okm() { - std::array ikm{}; - ikm.fill(0x0b); - std::array salt{}; - std::iota(salt.begin(), salt.end(), std::uint8_t{0x00}); - std::array info{}; - std::iota(info.begin(), info.end(), std::uint8_t{0xf0}); - std::array okm{}; - if (!webcpp::hash::hkdf( - okm, salt, ikm, info)) { - okm.fill(0); - } - return okm; -} - -} // namespace - -int main() { - namespace hash = webcpp::hash; -#if defined(WEBCPP_HASH_HAS_OPENSSL) - std::printf("HAS_OPENSSL=%d\n", WEBCPP_HASH_HAS_OPENSSL); -#endif - print_hex("hkdf", rfc5869_a1_okm()); - std::string_view const password = "password"; - std::string_view const salt = "salt"; - std::array derived{}; - auto const done = hash::pbkdf2( - derived, std::span(reinterpret_cast(password.data()), password.size()), - std::span(reinterpret_cast(salt.data()), salt.size()), 1); - print_hex("pbkdf2", derived); - return done ? 0 : 1; -} diff --git a/tools/test/hash_jamfiles_format_test.py b/tools/test/hash_jamfiles_format_test.py new file mode 100644 index 00000000..ff0b1748 --- /dev/null +++ b/tools/test/hash_jamfiles_format_test.py @@ -0,0 +1,97 @@ +#!/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, without building anything, that every message of libs/hash/test/messages has its +Emscripten fixture in tools/test/fixtures/hash_jamfiles with the same source and text, and that +hash_jamfiles_test.py's check finds each kind of drift: a message without a fixture, a changed +source, a changed text, and a fixture that names a message with no directory.""" + +from __future__ import annotations + +import shutil +import sys +import tempfile +from collections.abc import Callable +from pathlib import Path + +import hash_jamfiles_test as jamfiles +import user_jamfiles + + +def faults_of_copies(change: Callable[[Path, Path], None]) -> list[str]: + """message_faults over copies of the messages and the fixtures, after change(messages, + fixtures) has altered the copies.""" + with tempfile.TemporaryDirectory() as directory: + messages = Path(directory) / 'messages' + fixtures = Path(directory) / 'fixtures' + shutil.copytree(jamfiles.MESSAGES, messages) + shutil.copytree(jamfiles.CASES, fixtures) + change(messages, fixtures) + original = jamfiles.MESSAGES + jamfiles.MESSAGES = messages + try: + return jamfiles.message_faults(user_jamfiles.case_directories(fixtures)) + finally: + jamfiles.MESSAGES = original + + +def test_the_tree_has_no_fault(): + faults = jamfiles.message_faults(user_jamfiles.case_directories(jamfiles.CASES)) + assert faults == [], faults + + +def test_a_message_without_fixture_is_a_fault(): + def change(messages: Path, _: Path) -> None: + shutil.copytree(messages / 'two_profiles', messages / 'three_profiles') + (messages / 'three_profiles' / 'two_profiles.cpp').rename( + messages / 'three_profiles' / 'three_profiles.cpp') + + faults = faults_of_copies(change) + assert any('three_profiles has no fixture' in f for f in faults), faults + + +def test_a_changed_source_is_a_fault(): + def change(messages: Path, _: Path) -> None: + source = messages / 'two_profiles' / 'two_profiles.cpp' + source.write_text(source.read_text().replace('return 0;', 'return 1;')) + + faults = faults_of_copies(change) + assert any(f.startswith('two_profiles: app.cpp') for f in faults), faults + + +def test_a_changed_text_is_a_fault(): + def change(messages: Path, _: Path) -> None: + source = messages / 'xkcp_not_linked' / 'xkcp_not_linked.cpp' + source.write_text(source.read_text().replace('needs XKCP', 'needs Keccak')) + + faults = faults_of_copies(change) + assert any(f.startswith('xkcp_not_linked: the outcome') for f in faults), faults + + +def test_a_fixture_of_no_message_is_a_fault(): + def change(messages: Path, _: Path) -> None: + shutil.rmtree(messages / 'two_overrides') + + faults = faults_of_copies(change) + assert any(f.startswith('two_overrides: its Jamfile names') for f in faults), faults + + +def main() -> int: + if not jamfiles.MESSAGES.is_dir(): + print('hash_jamfiles_format: libs/hash is not checked out. Check it out with ' + '`git submodule update --init libs/hash`.', file=sys.stderr) + return 2 + for name, case in sorted(globals().items()): + if name.startswith('test_'): + case() + print(f'{name}: ok') + print('hash_jamfiles_format_test: ok') + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/test/hash_jamfiles_test.py b/tools/test/hash_jamfiles_test.py index 35abede0..50b868f5 100644 --- a/tools/test/hash_jamfiles_test.py +++ b/tools/test/hash_jamfiles_test.py @@ -7,109 +7,94 @@ """Builds every fixture of tools/test/fixtures/hash_jamfiles, a Jamfile as a user of webcpp::hash writes it (b2's raw exe), with b2 as a user runs it, and checks its outcome file: the build's -status, the lines a failure prints, and a program's output (CODING-GUIDELINES.md chapter 8). The -cases are each line of the library's spec 5.1, one program with every C library, and each stop of -the build: the canaries at link time on every target, and the messages raised on Emscripten. +status, the lines a failure prints, and a program's output (CODING-GUIDELINES.md chapter 8), +through user_jamfiles.py. The cases are each line of the library's spec 5.1, one program with +every C library, and each stop of the build: the canaries at link time on every target, and the +messages raised on Emscripten. -The outcome files, their format and the build of a case are crypto_jamfiles_test.py's, read -through it: one scratch superproject per target, with libs/config, libs/hash, libs/crypto (whose -canary /third_party//bearssl compiles) and the fixtures in it; every case of a target shares one -build directory, so each C library is compiled once per target. Run with the names of some cases -to run only those, and with --target to run one target.""" +Each message of libs/hash/test/messages// (a compile-diagnostic, natively and on WASI) has +the fixture , its Emscripten case: before building anything, the test checks that the +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 +--target to run one target.""" from __future__ import annotations -import shutil +import re import sys -import time from pathlib import Path -import crypto_jamfiles_test as jamfiles import harness +import user_jamfiles CASES = harness.FIXTURES / 'hash_jamfiles' +MESSAGES = harness.ROOT / 'libs/hash/test/messages' -# Cases whose outcome needs code that is not merged yet, as crypto_jamfiles_test.py's NOT_YET: -# a run without names leaves them out (and says so), a run that names one builds it. +# Cases whose outcome needs code that is not merged yet, as crypto_jamfiles_test.py's NOT_YET. NOT_YET: dict[str, str] = {} +# The messages of libs/hash/test/messages without an Emscripten fixture, each with its reason. +NO_FIXTURE = { + 'ripemd128_on_openssl': 'it names /webcpp/hash//openssl, which Emscripten refuses before ' + 'the message (the fixture openssl_on_emscripten)', +} -def case_directories() -> list[Path]: - """Every directory of CASES, each with its one outcome file named after it and a Jamfile, - and every outcome file read for every target, else a jamfiles.OutcomeError.""" - cases = sorted(p for p in CASES.iterdir() if p.is_dir()) - for case in cases: - found = sorted(p.name for p in case.glob('*.outcome')) - if found != [case.name + '.outcome']: - raise jamfiles.OutcomeError(f'{case.name}: the outcome files are {found}; ' - f'the one is {case.name}.outcome') - if not (case / 'Jamfile').is_file(): - raise jamfiles.OutcomeError(f'{case.name}: no Jamfile') - for target in jamfiles.TOOLSETS: - jamfiles.outcome(case / f'{case.name}.outcome', target) - return cases +DIRECTIVE = re.compile(r'^// expected-error@\S+ \{\{(.*)\}\}$', re.MULTILINE) +# The Jamfile's first line after the licence names the message a fixture builds. +CLAIM = re.compile(r'^# test/messages/(\S+) of webcpp::hash', re.MULTILINE) -def selected(cases: list[Path], names: list[str], target: str) -> list[Path]: - """The cases to build for target: the named ones, else every one that is not in NOT_YET, - each that its outcome file's targets line names target for.""" - return [case for case in cases - if (case.name in names if names else case.name not in NOT_YET) - and target in jamfiles.outcome(case / f'{case.name}.outcome', target).targets] +def program_of(source: str) -> str: + """A message's source as a user's program: without its expected-error directive, the + clang-format guards around it and the note on clang's -verify, which only the + compile-diagnostic rule reads, and with no run of blank lines left behind.""" + text = re.sub(r'^// expected-error@.*\n', '', source, flags=re.MULTILINE) + text = text.replace('// clang-format off\n// clang-format on\n', '') + text = re.sub(r"^// clang's -verify reads.*\n(?://.*\n)*", '', text, flags=re.MULTILINE) + return re.sub(r'\n\n\n+', '\n\n', text) -def main(argv: list[str]) -> int: - targets = list(jamfiles.TOOLSETS) - if '--target' in argv: - position = argv.index('--target') - if position + 1 >= len(argv) or argv[position + 1] not in jamfiles.TOOLSETS: - print(f'hash_jamfiles: --target takes one of {targets}', file=sys.stderr) - return 2 - targets = [argv[position + 1]] - argv = argv[:position] + argv[position + 2:] - names = [a for a in argv if not a.startswith('--')] - if len(names) != len(argv): - print(f'hash_jamfiles: no option {[a for a in argv if a.startswith("--")]}; ' - 'the one is --target ', file=sys.stderr) - return 2 - try: - cases = case_directories() - except jamfiles.OutcomeError as error: - print(f'hash_jamfiles: {error}', file=sys.stderr) - return 2 - missing = [n for n in names if n not in {c.name for c in cases}] - if missing: - print(f'hash_jamfiles: no case named {missing}', file=sys.stderr) - return 2 - if not names: - for case, reason in NOT_YET.items(): - print(f'left out until {reason}: {case}') +def message_faults(cases: list[Path]) -> list[str]: + """The faults between libs/hash/test/messages and the fixtures, found without b2: a message + with no fixture and no entry in NO_FIXTURE, a fixture whose source or text is not its + message's, and a fixture that claims a message there is no directory of.""" faults: list[str] = [] - built = 0 - for target in targets: - chosen = selected(cases, names, target) - if not chosen: + by_name = {case.name: case for case in cases} + messages = sorted(p for p in MESSAGES.iterdir() if p.is_dir()) + for message in messages: + name = message.name + case = by_name.get(name) + if name in NO_FIXTURE: + if case is not None: + faults.append(f'{name}: a fixture of a message in NO_FIXTURE') + continue + if case is None: + faults.append(f'test/messages/{name} has no fixture {name} (an Emscripten case), ' + 'nor an entry in NO_FIXTURE') continue - built += len(chosen) - started = time.monotonic() - root = harness.scratch_superproject() - try: - harness.copy_integration_libraries(root, 'config', 'hash', 'crypto') - shutil.copytree(CASES, root / 'user', ignore=harness.built) - if target == 'emscripten': - harness.link_emsdk(root) - elif target.startswith('wasi'): - harness.link_wasi_tools(root) - faults += jamfiles.run_target(root, target, chosen) - finally: - shutil.rmtree(root) - print(f'{target}: {len(chosen)} cases in {time.monotonic() - started:.0f} s') - if not built: - faults.append(f'no case was built for {targets}; nothing was tested') - for fault in faults: - print(f'hash_jamfiles: {fault}', file=sys.stderr) - print('hash_jamfiles_test: ' + ('failed' if faults else 'ok')) - return 1 if faults else 0 + source = (message / f'{name}.cpp').read_text() + texts = DIRECTIVE.findall(source) + if (case / 'app.cpp').read_text() != program_of(source): + faults.append(f'{name}: app.cpp is not test/messages/{name}/{name}.cpp without its ' + 'directive') + expected = user_jamfiles.outcome(case / f'{name}.outcome', 'emscripten') + if expected.targets != ['emscripten'] or expected.contains != texts: + faults.append(f'{name}: the outcome is not the text {texts!r} on emscripten alone') + names = {m.name for m in messages} + for case in cases: + claimed = CLAIM.search((case / 'Jamfile').read_text()) + if claimed and (claimed.group(1) != case.name or case.name not in names): + faults.append(f'{case.name}: its Jamfile names test/messages/{claimed.group(1)}, ' + 'which is not its own message directory') + return faults + + +def main(argv: list[str]) -> int: + return user_jamfiles.main('hash_jamfiles', CASES, ('config', 'hash', 'crypto'), NOT_YET, argv, + message_faults) if __name__ == '__main__': diff --git a/tools/test/user_jamfiles.py b/tools/test/user_jamfiles.py new file mode 100644 index 00000000..3d48f1a1 --- /dev/null +++ b/tools/test/user_jamfiles.py @@ -0,0 +1,316 @@ +# 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 user's Jamfiles as fixtures (CODING-GUIDELINES.md chapter 8), shared by +crypto_jamfiles_test.py and hash_jamfiles_test.py: the outcome file's format, the build of a +case with b2 as a user runs it, the run of its program, and the command line of a test. + +A test names its directory of cases under tools/test/fixtures, the libraries of libs/ its +scratch superproject holds, and the cases it leaves out until code they need is merged. Each +target gets one scratch superproject, with those libraries and the cases in its user/; every case +of a target shares one build directory, so each C library is compiled once per target.""" + +from __future__ import annotations + +import platform +import re +import shutil +import subprocess +import sys +import time +from collections.abc import Callable +from dataclasses import dataclass, field +from pathlib import Path + +import harness + +TOOLSETS = {'native': [], 'wasip2': ['toolset=clang-wasip2'], 'wasip3': ['toolset=clang-wasip3'], + 'emscripten': ['toolset=emscripten']} +SYSTEM = {'Linux': 'linux', 'Darwin': 'darwin', 'Windows': 'windows'}[platform.system()] +# The machine's architecture, as a native block names it. +ARCHITECTURE = {'arm64': 'arm64', 'aarch64': 'arm64', 'x86_64': 'x86_64', + 'amd64': 'x86_64'}.get(platform.machine().lower(), platform.machine().lower()) + +BLOCKS = {'all', 'native', 'native-linux', 'native-darwin', 'native-windows', 'native-arm64', + 'native-x86_64', 'wasip2', 'wasip3', 'emscripten'} + + +class OutcomeError(Exception): + """An outcome file or a case directory that does not follow the format.""" + + +def launcher(target: str) -> Path: + """The script the lanes run a WASI program with (tools/ci/matrix.py, wasm_lane).""" + return harness.ROOT / f'tools/boost/asio-{target}/run.sh' + + +@dataclass +class Outcome: + """What an outcome file says for one target.""" + targets: list[str] = field(default_factory=lambda: ['native']) + succeeds: bool | None = None + run: str | None = None + lines: list[str] = field(default_factory=list) + contains: list[str] = field(default_factory=list) + # (text, allowed): no line of b2's output contains text, unless it also contains allowed + # (none: not even then). + forbidden: list[tuple[str, str | None]] = field(default_factory=list) + arguments: list[str] = field(default_factory=list) + + +def outcome(path: Path, target: str) -> Outcome: + """The blocks of path that apply to target on this system, read into an Outcome. Every line + of the file is checked, whether its block applies or not, and so is the outcome that results + when target is one the case is built for (checked).""" + applying = {'all', target} | ({'native', 'native-' + SYSTEM, 'native-' + ARCHITECTURE} + if target == 'native' else set()) + result = Outcome() + block = None + for number, raw in enumerate(path.read_text().splitlines(), 1): + where = f'{path.name}:{number}' + if not raw.strip() or raw.startswith('#'): + continue + if raw.startswith('[') and raw.endswith(']'): + block = raw[1:-1] + if block not in BLOCKS: + raise OutcomeError(f'{where}: no block [{block}]; the blocks are {sorted(BLOCKS)}') + continue + if block is None: + raise OutcomeError(f'{where}: a line before the first [block]: {raw!r}') + directive = re.match(r'([a-z]+(?:-[a-z]+)?):(?: |$)', raw) + key, value = (directive.group(1), raw[directive.end():]) if directive else ('', raw) + if key and key not in ('targets', 'build', 'run', 'arguments', 'line', 'contains', + 'not-contains', 'same-as'): + raise OutcomeError(f'{where}: no directive {key}: (a line of one lowercase word and ' + f'a colon is reserved for them): {raw!r}') + if key in ('targets', 'arguments', 'not-contains') and not value.split(): + raise OutcomeError(f'{where}: {key}: names nothing') + if key == 'targets': + unknown = [t for t in value.split() if t not in TOOLSETS] + if unknown: + raise OutcomeError( + f'{where}: no target {unknown}; the targets are {list(TOOLSETS)}') + elif key == 'build' and value not in ('succeeds', 'fails'): + raise OutcomeError(f'{where}: build: is succeeds or fails, not {value!r}') + elif key == 'run' and not value: + raise OutcomeError(f'{where}: run: names no program') + if block not in applying or key == 'same-as': + continue + if key == 'targets': + result.targets = value.split() + elif key == 'build': + result.succeeds = value == 'succeeds' + elif key == 'run': + result.run = value + elif key == 'arguments': + result.arguments += value.split() + elif key == 'contains': + result.contains.append(value) + elif key == 'not-contains': + text, separator, allowed = value.partition(' unless ') + if not text.strip() or (separator and not allowed.strip()): + raise OutcomeError(f'{where}: not-contains: needs a text, then ` unless ` ' + f'if any line may hold it: {raw!r}') + result.forbidden.append((text.strip(), allowed.strip() or None)) + else: + result.lines.append(value if key == 'line' else raw) + if target in result.targets: + checked(path, target, result) + return result + + +def checked(path: Path, target: str, result: Outcome) -> None: + """Raises an OutcomeError naming path and target unless result is coherent: a build is said + to succeed or fail; a failure has lines to find and no program to run; a success that + prints lines has a program.""" + if result.succeeds is None: + raise OutcomeError(f'{path.name} on {target}: no build: line') + if not result.succeeds and result.run is not None: + raise OutcomeError(f'{path.name} on {target}: run: after build: fails') + if result.succeeds and (result.contains or result.forbidden): + raise OutcomeError(f'{path.name} on {target}: contains: or not-contains: after build: ' + 'succeeds') + if not result.succeeds and not result.lines and not result.contains: + raise OutcomeError(f'{path.name} on {target}: build: fails with no line to find') + if result.succeeds and result.run is None and result.lines: + raise OutcomeError(f'{path.name} on {target}: lines after build: succeeds, with no run:') + + +def same_as_faults(case: Path, cases_directory: Path) -> list[str]: + """Each `same-as: / ` of case's outcome file whose two files are not + byte-identical: the file of another case of cases_directory, and case's own copy of it. A + fixture's program is a copy, never a symbolic link (a checkout on Windows reads a link as a + text file), and this keeps the copies from drifting.""" + faults: list[str] = [] + for number, raw in enumerate((case / f'{case.name}.outcome').read_text().splitlines(), 1): + if not raw.startswith('same-as:'): + continue + names = raw[len('same-as:'):].split() + where = f'{case.name}.outcome:{number}' + if len(names) != 2: + faults.append(f'{where}: same-as: names / and , not {names}') + continue + original, copy = cases_directory / names[0], case / names[1] + if not original.is_file() or not copy.is_file(): + faults.append(f'{where}: {names[0]} or {case.name}/{names[1]} does not exist') + elif original.read_bytes() != copy.read_bytes(): + faults.append(f'{where}: {case.name}/{names[1]} is not a copy of {names[0]}') + return faults + + +def case_directories(cases_directory: Path) -> list[Path]: + """Every directory of cases_directory, each with its one outcome file named after it, and + every outcome file read for every target (so each line of each block is checked), else an + OutcomeError.""" + cases = sorted(p for p in cases_directory.iterdir() if p.is_dir()) + for case in cases: + found = sorted(p.name for p in case.glob('*.outcome')) + if found != [case.name + '.outcome']: + raise OutcomeError(f'{case.name}: the outcome files are {found}; ' + f'the one is {case.name}.outcome') + if not (case / 'Jamfile').is_file(): + raise OutcomeError(f'{case.name}: no Jamfile') + for target in TOOLSETS: + outcome(case / f'{case.name}.outcome', target) + faults = same_as_faults(case, cases_directory) + if faults: + raise OutcomeError('; '.join(faults)) + return cases + + +def program_command(build_dir: Path, case: str, name: str, target: str) -> list[str]: + """The command that runs the program name that the build of case made under build_dir, as its + lane runs one.""" + suffix = {'native': '.exe' if SYSTEM == 'windows' else '', 'wasip2': '.wasm', + 'wasip3': '.wasm', 'emscripten': '.js'}[target] + found = [p for p in build_dir.rglob(name + suffix) + if p.is_file() and f'user/{case}/' in p.relative_to(build_dir).as_posix()] + if len(found) != 1: + raise AssertionError(f'the build made {len(found)} files named {name}{suffix}') + if target == 'emscripten': + return ['node', str(found[0])] + if target.startswith('wasi'): + return [str(launcher(target)), str(found[0])] + return [str(found[0])] + + +def selected(cases: list[Path], names: list[str], target: str, + not_yet: dict[str, str]) -> list[Path]: + """The cases to build for target: the named ones, else every one that is not in not_yet, + each that its outcome file's targets line names target for.""" + return [case for case in cases + if (case.name in names if names else case.name not in not_yet) + and target in outcome(case / f'{case.name}.outcome', target).targets] + + +def run_target(root: Path, target: str, cases: list[Path]) -> list[str]: + """Builds each of cases for target in root and returns the faults, one line each.""" + faults: list[str] = [] + build_dir = root / 'bin' / f'user-{target}' + for case in cases: + expected = outcome(case / f'{case.name}.outcome', target) + scratch = root / 'scratch' / case.name + scratch.mkdir(parents=True, exist_ok=True) + arguments = [a.replace('@scratch', str(scratch)) for a in expected.arguments] + # No testing.launcher: a user's exe is run by this test, not by b2. + built = harness.run_b2(root, '-j3', f'--build-dir={build_dir}', *TOOLSETS[target], + *arguments, f'user/{case.name}') + output = built.stdout + if (built.returncode == 0) != expected.succeeds: + faults.append(f'{case.name} on {target}: the build ' + f'{"succeeded" if built.returncode == 0 else "failed"}\n{output[-3000:]}') + continue + if not expected.succeeds: + printed = {line.rstrip() for line in output.splitlines()} + faults += [f'{case.name} on {target}: b2 printed no line {line!r}' + for line in expected.lines if line.rstrip() not in printed] + faults += [f'{case.name} on {target}: no line of b2 contains {text!r}' + for text in expected.contains + if not any(text in line for line in printed)] + faults += [f'{case.name} on {target}: b2 printed {line!r}, which contains {text!r}' + f'{"" if allowed is None else f" and not {allowed!r}"}' + for text, allowed in expected.forbidden for line in sorted(printed) + if text in line and (allowed is None or allowed not in line)] + continue + if expected.run is not None: + try: + command = program_command(build_dir, case.name, expected.run, target) + except AssertionError as error: + faults.append(f'{case.name} on {target}: {error}') + continue + ran = subprocess.run(command, capture_output=True, text=True, check=False) + printed = ran.stdout.replace('\r\n', '\n').splitlines() + if ran.returncode != 0 or printed != expected.lines: + faults.append(f'{case.name} on {target}: {expected.run} exited {ran.returncode} ' + f'and printed {printed!r}; the outcome says {expected.lines!r}') + return faults + + +def main(label: str, cases_directory: Path, libraries: tuple[str, ...], + not_yet: dict[str, str], argv: list[str], + check: Callable[[list[Path]], list[str]] | None = None) -> int: + """The command line of a test of label: [--target ] [case ...]. It builds the cases of + cases_directory in scratch superprojects that hold libs/ for each of libraries, and + prints `