Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1ca14cc
tools: the hash fixtures use hash's spelled-out names
Nov 23, 2026
1ebf852
tools: wrap the doc tables test's long line
Nov 23, 2026
3862638
tools: hash's doc tables read a function row's form
Nov 24, 2026
d5231fe
tools: the lint's findings on hash's doc tables (Optional for the run…
Nov 24, 2026
c9c26db
tools: hash's llms.txt names the parameters a form takes as byte_pieces
Nov 24, 2026
e445acd
libs/hash: HKDF over byte pieces on backends::hash2 and its review an…
Nov 24, 2026
626e67c
tools: hash's llms.txt defaults case reads the pieces forms with the …
Nov 24, 2026
2badd97
libs/hash: HKDF over byte pieces on backends::sodium and backends::be…
Nov 24, 2026
ecb75c5
tools: hash's doc tables cases read hkdf and the pieces forms under o…
Nov 24, 2026
c20b67b
libs/hash: HKDF over byte pieces on backends::openssl and backends::b…
Nov 24, 2026
1bba1b7
libs/hash: async_hkdf_extract, async_hkdf_expand and async_hkdf over …
Nov 24, 2026
dd7ab8a
tools: hash_jamfiles fixtures for extract_on_bearssl, and the webcryp…
Nov 24, 2026
f425dbd
libs/hash: WebCrypto's HKDF over byte pieces and the webcrypto messag…
Nov 24, 2026
74d3cd0
tools: hash_allocation_collect_test checks that HKDF over pieces' row…
Nov 24, 2026
51724bc
libs/hash: HKDF over byte pieces' guide, changelog and timing coverag…
Nov 24, 2026
c08b9ef
hash: merge origin/main (crypto's uniform types) into hkdf-pieces, li…
Nov 24, 2026
102eb10
libs/hash: the end lint's findings (gitlink dccd138)
Nov 24, 2026
2b1f97c
tools: a test under node ends as node ends on its own, around node #6…
Nov 24, 2026
36d536f
libs/hash: the MSVC lanes' findings (gitlink 8ca88de)
Nov 25, 2026
ed36683
tools: node-test's table under the grace, and the process.exit paths …
Nov 25, 2026
9bac938
libs/hash: the final review's fixes (gitlink 22fba54)
Nov 25, 2026
864fb93
libs/hash: the gitlink at the merge of hash's HKDF over byte pieces (…
Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,8 @@ variants; and `std::exit` sets the status without ending node, so that a
later write replaces it, and anything pending keeps node running. Under the
pre-js, a program ends with these statuses (measured with Emscripten 6.0.11
and node 26.7.0, the same source built without a variant, with `-sJSPI` and
with `-sASYNCIFY`):
with `-sASYNCIFY`; the two rows of work still pending after the status with
node 26.13.0, since node ends on its own):

| `main` | without suspension | JSPI | Asyncify |
| --- | --- | --- | --- |
Expand All @@ -1026,8 +1027,8 @@ with `-sASYNCIFY`):
| suspends, `std::exit(7)` unmarked | (aborts) | 7 | 7 |
| suspends, `std::exit(0)` unmarked | (aborts) | 0 | **1**, with the line below |
| awaits a promise that nothing settles | (aborts) | **1** at once, with the line below | **1** at once, with the line below |
| suspends, `exit_status(3)`; later a callback gives `exit_status(0)` and a timer sets `process.exitCode = 0` | (aborts) | 3 at once | 3 at once |
| suspends, `exit_status(0)` while a timer of 300 s is pending | (aborts) | 0 at once | 0 at once |
| suspends, `exit_status(3)`; later a callback gives `exit_status(0)` and a timer sets `process.exitCode = 0` (both after 50 ms) | (aborts) | 3, once the pending 50 ms timers have run | 3, once the pending 50 ms timers have run |
| suspends, `exit_status(0)` while a timer of 300 s is pending | (aborts) | 0 after 10 s | 0 after 10 s |
| sleeps 600 s after `bound(3s)` | (aborts) | 1 after 3 s | 1 after 3 s |
| never called (`-sINVOKE_RUN=0`), returns 0 | **1**, with the line below | **1**, with the line below | **1**, with the line below |
| `bound(0s)`, or a bound past 2147483 s | (aborts) | **1** at once, naming it | **1** at once, naming it |
Expand All @@ -1041,10 +1042,23 @@ is a failure already. It reads `main` as finished only when the glue called
it (it wraps the glue's `callMain`), so that a program linked with
`-sINVOKE_RUN=0`, whose `main` nothing calls, fails too.
`webcpp::test::exit_status` gives its status to the pre-js, which ends node
with the first status it is given on node's next turn, whatever is still
pending or runs later, and restores it over any later write of
`process.exitCode`. It never calls `std::exit`, which in a debug build prints
Emscripten's notice that the runtime is kept alive. A test is also bounded: past 120 s, the
with the first status it is given, whatever runs later, and restores it over
any later write of `process.exitCode`. Node ends on its own as soon as
nothing holds it, and through `process.exit` only if something still holds it
(a pending timer, a live worker) 10 s after the status. That is a workaround
for node issue #64274: in node 26.13.0 `process.exit` can deadlock, when a
background compile waits for a GC that the exiting main thread never runs
(hash's `async_heavy` hung 5 times in 300 runs, 10 at a time), and a natural
exit cannot. Under 10 to 36 runs at once on 18 cores, `async_heavy` ended on
its own 0.2 ms to 5.4 s after its status, hence the 10 s. Two paths still
end through `process.exit` and can meet the same deadlock: the 10 s fallback
itself, for a test that holds node past its grace, and the bound below, for a
test that runs past it; such a test can then hang until the CI job's timeout
instead of failing at its bound. Both are rare and outside a test's normal
end. Once the pinned node is a release with node PR #66171, which fixes it,
the pre-js calls `process.exit` on node's next turn again, and both paths are
safe again. It never calls `std::exit`, which
in a debug build prints Emscripten's notice that the runtime is kept alive. A test is also bounded: past 120 s, the
pre-js stops it with 1 and the line `webcpp: the test ran past its bound of
<n> s`. 120 s is longer than any emscripten test of webcpp, and short enough
that a test that waits forever fails inside the CI job instead of running to
Expand Down
2 changes: 1 addition & 1 deletion libs/hash
Submodule hash updated 115 files
173 changes: 130 additions & 43 deletions tools/hash/doc_tables.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tools/node-test/include/webcpp/test/exit_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace webcpp::test {
/**
Gives status to webcpp's test support and returns it, so that main ends with it: natively
the status is main's; on emscripten the support ends node with the first status it is given,
on its next turn, whatever is still pending or runs later.
whatever runs later: as soon as nothing holds node, or 10 s later if something still does (a
pending timer, a live worker).

Tip: it never calls std::exit, which under Emscripten's default EXIT_RUNTIME=0 neither ends
node nor keeps the status from a later write, and in a debug build prints Emscripten's notice
Expand Down
24 changes: 21 additions & 3 deletions tools/node-test/node-pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (typeof process === 'object' && typeof process.on === 'function') {
if (watchdog) {
clearTimeout(watchdog)
}
// process.exit here can meet node #64274's deadlock: see the grace below.
watchdog = setTimeout(() => {
process.stderr.write(`webcpp: the test ran past its bound of ${seconds} s\n`)
process.exit(1)
Expand All @@ -31,13 +32,30 @@ if (typeof process === 'object' && typeof process.on === 'function') {
}
bound(120)
Module['webcppTestBound'] = bound
// Node ends with the first status on its next turn, whatever is still pending or runs
// later: a timer, a callback that gives another status, a write of process.exitCode.
// Node ends with the first status, whatever runs later: a callback that gives another
// status, a write of process.exitCode. It ends on its own as soon as nothing holds it, as
// Emscripten's own glue ends under node, and through process.exit only if something
// still holds it (a pending timer, a live worker) after the grace below.
// Workaround for node issue #64274: in node 26.13.0, process.exit can deadlock when a
// background compile of the main isolate waits for a GC that the exiting main thread never
// runs (seen in hash's async_heavy, 5 hangs in 300 runs); a natural exit disposes the
// isolate first and cannot. Remove the grace and call process.exit(status) on the next
// turn again once the pinned node is a release with node PR #66171 (commit 77fdeb6fa0).
// The grace is 10 s: async_heavy, under 10 to 36 runs at once on 18 cores, ended on its
// own 0.2 ms to 5.4 s after its status (median 0.3 to 1.6 s), and a fallback that fires
// before the workers wind down meets the deadlock.
// Two paths still call process.exit and can meet the same deadlock: this fallback, for a
// test that holds node past the grace, and the bound above, for a test that runs past it.
// Such a test can then hang until the CI job's timeout instead of failing at its bound;
// both are rare and outside a test's normal end, and safe again under the same condition
// (a pinned node with PR #66171).
const grace = 10000
Module['webcppTestFinished'] = given => {
finished = true
if (status === null) {
status = given
setImmediate(() => process.exit(status))
process.exitCode = status
setTimeout(() => process.exit(status), grace).unref()
}
}
// Whether main was called: postRun runs all the same in a program whose glue never calls
Expand Down
31 changes: 19 additions & 12 deletions tools/test/emscripten_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
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
status: a main that did not finish fails, the first status given through webcpp::test::exit_status
ends the test at once and is kept, and a test past its bound is stopped; a program node runs that
links -sMODULARIZE or -sEXPORT_ES6, which node would load without running, is refused. A program a
page loads (webcpp.variants) is named Boost's way in each variant, debug and release, with its
manifest beside its jspi artifact and its size table (webcpp.size-table), and none of them is built
natively; a build of them that asks for JavaScript exceptions, which their jspi variant would keep,
is refused. Each case builds a scratch superproject with browser_demo and node_test_demo, whose
path holds a space, and the emsdk linked into its .local; Emscripten's cache is the one the harness
gives every b2. Run with the names of some cases to run only those."""
ends the test and is kept, as node ends on its own or, with a timer still pending, 10 s later, and
a test past its bound is stopped; a program node runs that links -sMODULARIZE or -sEXPORT_ES6,
which node would load without running, is refused. A program a page loads (webcpp.variants) is
named Boost's way in each variant, debug and release, with its manifest beside its jspi artifact
and its size table (webcpp.size-table), and none of them is built natively; a build of them that
asks for JavaScript exceptions, which their jspi variant would keep, is refused. Each case builds a
scratch superproject with browser_demo and node_test_demo, whose path holds a space, and the emsdk
linked into its .local; Emscripten's cache is the one the harness gives every b2. Run with the
names of some cases to run only those."""

from __future__ import annotations

Expand Down Expand Up @@ -334,7 +335,8 @@ def test_a_test_ends_as_its_main_ends(root):
'returns_zero_after_suspension_jspi', 'never_resumes_jspi', 'never_resumes_asyncify',
'keeps_the_first_status_jspi', 'keeps_the_first_status_asyncify',
'ends_with_a_timer_pending_jspi', 'ends_with_a_timer_pending_asyncify',
'exits_unmarked_jspi', 'exits_unmarked_asyncify', 'main_never_called', 'bound_zero',
'ends_on_its_own_jspi', 'ends_on_its_own_asyncify', 'exits_unmarked_jspi',
'exits_unmarked_asyncify', 'main_never_called', 'bound_zero',
'bound_too_long'}, result.stdout[-4000:]
assert exit_status(root, 'returns_one_after_suspension_jspi')[0] == 1
# Under JSPI a main that returns 0 after a suspension finished: the pre-js reads its end
Expand All @@ -352,14 +354,19 @@ def test_a_test_ends_as_its_main_ends(root):
assert 'past its bound' not in text, (name, text)
assert exit_status(root, 'exit_in_coroutine_asyncify')[0] == 3
assert exit_status(root, 'exit_in_handler_jspi')[0] == 3
# The first status exit_status gives ends the test at once: neither a later exit_status(0)
# nor a later write of process.exitCode = 0 replaces it, and a pending timer does not hold
# it to its bound.
# The first status exit_status gives ends the test: neither a later exit_status(0) nor a
# later write of process.exitCode = 0 replaces it, and a pending timer does not hold it to
# its bound, only to the pre-js's grace of 10 s.
for name in ('keeps_the_first_status_jspi', 'keeps_the_first_status_asyncify'):
assert exit_status(root, name)[0] == 3, name
for name in ('ends_with_a_timer_pending_jspi', 'ends_with_a_timer_pending_asyncify'):
status, text = exit_status(root, name)
assert status == 0 and 'past its bound' not in text, (name, text)
# A test that gives its status with nothing pending ends as node ends on its own, never
# through process.exit, which can hang in node 26.13.0 (node issue #64274).
for name in ('ends_on_its_own_jspi', 'ends_on_its_own_asyncify'):
status, text = exit_status(root, name)
assert status == 0 and 'node ended on its own' in text, (name, text)
# An unmarked std::exit after a suspension: JSPI keeps its status, Asyncify fails it.
assert exit_status(root, 'exits_unmarked_jspi')[0] == 0
status, text = exit_status(root, 'exits_unmarked_asyncify')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ int main() {
std::array<std::uint8_t, 32> output{};
std::array<std::uint8_t, 16> salt{};
auto done = webcpp::hash::argon2<webcpp::hash::kdfs::argon2d>(
output, {}, salt, {.passes = 3, .memory_kib = 65536});
output, {}, salt, {.passes = 3, .memory_kibibytes = 65536});
return done ? 0 : 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
int main() {
std::array<std::uint8_t, 32> output{};
std::array<std::uint8_t, 16> salt{};
auto done = webcpp::hash::argon2<int>(output, {}, salt, {.passes = 3, .memory_kib = 65536});
auto done =
webcpp::hash::argon2<int>(output, {}, salt, {.passes = 3, .memory_kibibytes = 65536});
return done ? 0 : 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ int main() {
std::array<std::uint8_t, 32> output{};
std::array<std::uint8_t, 16> salt{};
auto done = webcpp::hash::argon2<webcpp::hash::kdfs::argon2d, webcpp::hash::backends::sodium>(
output, {}, salt, {.passes = 3, .memory_kib = 65536});
output, {}, salt, {.passes = 3, .memory_kibibytes = 65536});
return done ? 0 : 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main() {
std::array<std::uint8_t, 16> const salt{};
webcpp::hash::async_argon2<webcpp::hash::kdfs::argon2id>(
context.get_executor(), output, {}, salt,
webcpp::hash::argon2_parameters{.passes = 3, .memory_kib = 65536},
webcpp::hash::argon2_parameters{.passes = 3, .memory_kibibytes = 65536},
[](boost::system::error_code /*code*/) {});
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
int main() {
webcpp::asio::io_context context;
std::array<std::uint8_t, 32> output{};
std::array<std::uint8_t, 4> input{};
webcpp::hash::async_hkdf<webcpp::hash::hmac_sha3_256>(
context.get_executor(), output, {}, {}, {}, [](boost::system::error_code /*code*/) {});
context.get_executor(), output, input, input, input,
[](boost::system::error_code /*code*/) {});
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
int main() {
webcpp::asio::io_context context;
std::array<std::uint8_t, 64> output{};
webcpp::hash::async_scrypt(context.get_executor(), output, {}, {},
webcpp::hash::scrypt_parameters{.n = 16, .r = 1, .p = 1},
[](boost::system::error_code /*code*/) {});
webcpp::hash::async_scrypt(
context.get_executor(), output, {}, {},
webcpp::hash::scrypt_parameters{.cost = 16, .block_size = 1, .parallelism = 1},
[](boost::system::error_code /*code*/) {});
return 0;
}
9 changes: 9 additions & 0 deletions tools/test/fixtures/hash_jamfiles/extract_on_bearssl/Jamfile
Original file line number Diff line number Diff line change
@@ -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/extract_on_bearssl of webcpp::hash, built for Emscripten
# by a user's Jamfile.
exe app : app.cpp /webcpp/hash//hash /third_party//bearssl ;
28 changes: 28 additions & 0 deletions tools/test/fixtures/hash_jamfiles/extract_on_bearssl/app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

// The single-buffer hkdf_extract 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, while hkdf_extract over
// pieces on BearSSL compiles (the change hkdf-pieces, scenario "BearSSL's Extract over pieces").

#include <webcpp/hash/backends/bearssl.hpp>
#include <webcpp/hash/hkdf.hpp>
#include <webcpp/hash/hmac.hpp>

#include <array>
#include <cstdint>

int main() {
std::array<std::uint8_t, 13> salt{};
std::array<std::uint8_t, 22> ikm{};
auto pieces =
webcpp::hash::hkdf_extract<webcpp::hash::hmac_sha2_256, webcpp::hash::backends::bearssl>(
salt, {ikm, ikm});
auto single =
webcpp::hash::hkdf_extract<webcpp::hash::hmac_sha2_256, webcpp::hash::backends::bearssl>(
salt, ikm);
return pieces && single ? 0 : 1;
}
Original file line number Diff line number Diff line change
@@ -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/extract_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, backends::openssl or backends::botan.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main() {
std::array<std::uint8_t, 16> salt{};
auto const argon2id = hash::argon2id<hash::backends::openssl>(
output, {}, salt, hash::argon2id_parameters{.passes = 2, .memory = 19456 * 1024});
auto const scrypt = hash::scrypt<hash::backends::openssl>(output, {}, salt,
hash::scrypt_parameters{1024, 8, 1});
auto const scrypt = hash::scrypt<hash::backends::openssl>(
output, {}, salt, hash::scrypt_parameters{.cost = 1024, .block_size = 8, .parallelism = 1});
return argon2id && scrypt ? 0 : 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
int main() {
std::array<std::uint8_t, 32> output{};
std::array<std::uint8_t, 16> salt{};
auto done = webcpp::hash::scrypt(output, {}, salt, webcpp::hash::scrypt_parameters{1024, 8, 1});
auto done = webcpp::hash::scrypt(
output, {}, salt,
webcpp::hash::scrypt_parameters{.cost = 1024, .block_size = 8, .parallelism = 1});
return done ? 0 : 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

int main() {
std::array<std::uint8_t, 32> output{};
std::array<std::uint8_t, 4> input{};
auto done = webcpp::hash::hkdf<webcpp::hash::hmac_sha2_256, webcpp::hash::backends::webcrypto>(
output, {}, {}, {});
output, input, input, input);
return done ? 0 : 1;
}
2 changes: 2 additions & 0 deletions tools/test/fixtures/node_test_demo/test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ webcpp.run-fail keeps_the_first_status_jspi : keeps_the_first_status.cpp : $(jsp
webcpp.run-fail keeps_the_first_status_asyncify : keeps_the_first_status.cpp : $(asyncify) ;
webcpp.run ends_with_a_timer_pending_jspi : ends_with_a_timer_pending.cpp : $(jspi) ;
webcpp.run ends_with_a_timer_pending_asyncify : ends_with_a_timer_pending.cpp : $(asyncify) ;
webcpp.run ends_on_its_own_jspi : ends_on_its_own.cpp : $(jspi) ;
webcpp.run ends_on_its_own_asyncify : ends_on_its_own.cpp : $(asyncify) ;
webcpp.run exits_unmarked_jspi : exits_unmarked.cpp : $(jspi) ;
webcpp.run-fail exits_unmarked_asyncify : exits_unmarked.cpp : $(asyncify) ;
# The glue never calls a main linked with -sINVOKE_RUN=0.
Expand Down
27 changes: 27 additions & 0 deletions tools/test/fixtures/node_test_demo/test/ends_on_its_own.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

// Ends with 0 through exit_status with nothing pending, and says so when node, its loop empty,
// emits beforeExit, which it never emits on a call of process.exit.

#include <webcpp/test/exit_status.hpp>

#include <emscripten.h>
#include <emscripten/em_js.h>

// clang-format off
EM_JS(void, say_when_node_ends_on_its_own, (), {
process.once('beforeExit', () => {
process.stdout.write('node ended on its own\n');
});
});
// clang-format on

int main() {
say_when_node_ends_on_its_own();
emscripten_sleep(10);
return webcpp::test::exit_status(0);
}
Loading
Loading