Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
93f225c
crypto: the memory option's errors 13 and 14, and config.hpp's refusa…
Nov 17, 2026
757eab9
crypto: the Doc Comments of the memory option's errors use the enum's…
Nov 17, 2026
df83326
crypto: OpenSSL's memory functions as an option of the config: the ad…
Nov 17, 2026
ab1d78f
crypto: the memory guard is always declared and called, and the adapt…
Nov 17, 2026
f47ca15
crypto: the memory option's branch of the OpenSSL header and its adap…
Nov 17, 2026
3716e19
crypto: the memory option's counting resource and its proof that ever…
Nov 17, 2026
15a7aaf
crypto: the memory option's test support documented, sized from 3.5.9…
Nov 17, 2026
6b016e3
crypto: the memory option's test support says what a full buffer does…
Nov 17, 2026
74ae2da
crypto: the memory option's late, foreign, forgotten, replaced and fa…
Nov 17, 2026
d20ce8d
crypto: the memory option's install tests check their messages uncond…
Nov 17, 2026
de60f0d
crypto: fail_init's test says why its makes live in an inner scope
Nov 17, 2026
a0ecbe3
crypto: the changelog's Unreleased keeps the lint's ten lines: the me…
Nov 17, 2026
f38baba
crypto: the memory option's link cases on MSVC, and <windows.h> besid…
Nov 17, 2026
7ec7fde
crypto: memory_functions_refused's Doc Comment keeps its brief to one…
Nov 17, 2026
136f12b
crypto: the memory option beside Asio's TLS, libdatachannel and a TLS…
Nov 17, 2026
de1f991
crypto: the memory option's neighbours test records which of libdatac…
Nov 17, 2026
a3f3531
crypto: the memory option's page, example and tables
Nov 17, 2026
d4f404a
crypto: the memory option's changelog line, guide condition, example …
Nov 17, 2026
6540ae2
crypto: the memory option's changelog line names openssl_memory_resou…
Nov 17, 2026
8583816
crypto: install_memory_functions and the memory option's guard are [[…
Nov 18, 2026
f7dc87b
crypto: the memory option's example binds the error's message before …
Nov 18, 2026
6e10da6
crypto: the WebAssembly refusal's message test keeps its Jam comment …
Nov 18, 2026
9849772
crypto: the memory option's second thread calls OPENSSL_thread_stop, …
Nov 18, 2026
ba577e3
crypto: fail_init makes the resource fail only on an OpenSSL built wi…
Nov 18, 2026
23721bc
crypto: the memory option's page and Doc Comments say that a resource…
Nov 18, 2026
b8d57ff
crypto: the memory option's example works on a thread that calls OPEN…
Nov 18, 2026
24ba3a5
crypto: the backend OpenSSL's Doc Comment says that its make allocate…
Nov 18, 2026
f50b19c
crypto: openssl_memory_resource's brief names its header, so that llm…
Nov 18, 2026
218ae7d
crypto: the memory option's page says what a later CRYPTO_set_mem_fun…
Nov 18, 2026
f883124
crypto: the memory option's page says that a shared library which hid…
Nov 18, 2026
07b8b71
crypto: the memory option's use case says "of OpenSSL's", as every ot…
Nov 18, 2026
08e5715
crypto: the memory option's page and Doc Comments say that a failure …
Nov 18, 2026
cc2b801
crypto: the memory option's example worker calls OPENSSL_thread_stop …
Nov 18, 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
4 changes: 2 additions & 2 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ of every version are on webcpp's index page.
* Added ciphers::gcm, AES-GCM in place with an incremental seal, whose failed open zeroes the data.
* Added the default backend, ciphers::aes128_gcm and aes256_gcm, and the refusals of backends that conflict.
* Added backends::bearssl: AES-GCM on every target allocating nothing, the block cipher refused, and the Jamfile line a program lacks without it.
* Added backends::openssl and /webcpp/crypto//openssl on native and WASI; a message on it allocates nothing after make.
* Added backends::openssl, /webcpp/crypto//openssl on native and WASI, allocating nothing after make; WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE: OpenSSL's allocations in the program's resource, refused on WebAssembly (WASI included) and without OpenSSL: openssl_memory_resource, install_memory_functions, memory_functions_refused, memory_functions_not_installed.
* Added backends::ctaes, the AES block cipher alone on every target; ciphers::gcm refuses it.
* Added curves::secp256k1: key pairs, BIP340 and ECDSA signatures, ECDH, strict DER, low-S and the x-only tweak.
* Added the link-time canaries of BearSSL, ctaes and libsecp256k1, and their own suites on webcpp's build.
* Added the page: a chapter per namespace and use case, tables generated from the tests, every Jamfile and message, and llms.txt.
* Added the page: a chapter per namespace and use case, the memory option's guide and example, tables generated from the tests, every Jamfile and message, and llms.txt.
// end::unreleased[]
11 changes: 9 additions & 2 deletions doc/errors.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ bytes) or 04 (65 bytes), or not a point of the curve.
|11 |`invalid_signature` |A signature that does not verify, or is not a valid encoding: not strict
DER, or an r or an s that is zero or not below the group order.
|12 |`backend_failure` |A backend failed where its contract says it does not.
|13 |`memory_functions_refused` |OpenSSL's memory functions could not be installed: OpenSSL has
already allocated, or another party installed its own. From `backends::openssl::install_memory_functions`,
with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`.
|14 |`memory_functions_not_installed` |OpenSSL's memory functions are not webcpp::crypto's. From
every `make` of the OpenSSL backend, with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`.
|===

The values 13 and 14 are reserved for OpenSSL's memory option, which is not part
of this version, and are not declared. A value that `error` does not define
A value that `error` does not define
has the message "unknown webcpp.crypto error". `random_device` also returns
`errc::not_supported` where there is no generator at all, and OpenSSL's `make`
`errc::not_enough_memory` when OpenSSL cannot allocate its context.
`memory_functions_refused` and `memory_functions_not_installed` come only with
OpenSSL's memory option, natively: <<crypto-memory-openssl>> says what each
means and what to do.

include::generated/backends-error.adoc[]

Expand Down
2 changes: 1 addition & 1 deletion doc/generated/backend-facts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The library behind each, and what it costs a program:
|OpenSSL 3.5.9's libcrypto, built from source and static
|Apache-2.0
|`+<openssl/*.h>+`
|`+make+` allocates the cipher's context through OpenSSL's own allocator, outside the program's resource; a message allocates nothing after `+make+`
|`+make+` allocates the cipher's context through OpenSSL's own allocator, outside the program's resource, unless a native program sets `+WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE+`, which sends every allocation of OpenSSL's in the process to `+openssl_memory_resource()+`; a message allocates nothing after `+make+`

|ctaes
|ctaes as Bitcoin Core v31.1 ships it (`+src/crypto/ctaes+`), built from source
Expand Down
20 changes: 20 additions & 0 deletions doc/generated/backends-memory_option.adoc
Original file line number Diff line number Diff line change
@@ -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)

// Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles,
// the message tests and the Jamfile fixtures: run it again, never edit this file.

The backends of `+openssl_memory_resource+`, `+backends::openssl::install_memory_functions+`, from the test programs that run it:

[cols="1,2,2,4",options="header"]
|===
|Backend |Jamfile |Header |Targets

|OpenSSL
|`+/webcpp/crypto//openssl+`
|`+<webcpp/crypto/backends/openssl.hpp>+`
|native (tested by `+adapter+`, `+everything+`, `+late+`, `+foreign+`, `+fresh_install+`, `+forgotten+`, `+replaced+`, `+second_install+`, `+fail_second+`, `+fail_init+`, `+fail_init_threads+`, `+neighbours+`, `+handshake+`); not on wasip2, wasip3, emscripten: `+config.hpp+` refuses the option on every WebAssembly target
|===
16 changes: 16 additions & 0 deletions doc/generated/jamfiles.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ It prints:
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/encrypt_and_sign.outcome[tag=output]
----

`+memory_option+`:: OpenSSL's allocations in the program's own resource: the define and OpenSSL in the requirements of the program's project, the resource defined once, the install first in `+main+`.
+
Its Jamfile, built and run on native:
+
[listing]
----
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/memory_option/Jamfile[tag=jamfile]
----
+
It prints:
+
[listing]
----
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/memory_option/memory_option.outcome[tag=output]
----

`+openssl_linked+`:: OpenSSL, built from source, named in the type: natively and on WASI.
+
Its Jamfile, built and run on native, wasip2, wasip3:
Expand Down
11 changes: 11 additions & 0 deletions doc/generated/matrix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
|libsecp256k1
|native, wasip2, wasip3, emscripten
|`+secp256k1_xonly_tweak+`

|`+openssl_memory_resource+`, `+backends::openssl::install_memory_functions+`
|OpenSSL
|native; not on wasip2, wasip3, emscripten: `+config.hpp+` refuses the option on every WebAssembly target
|`+adapter+`, `+everything+`, `+late+`, `+foreign+`, `+fresh_install+`, `+forgotten+`, `+replaced+`, `+second_install+`, `+fail_second+`, `+fail_init+`, `+fail_init_threads+`, `+neighbours+`, `+handshake+`
|===

The same, by target: the backends each operation runs on.
Expand Down Expand Up @@ -136,4 +141,10 @@ The same, by target: the backends each operation runs on.
|libsecp256k1
|libsecp256k1
|libsecp256k1

|`+openssl_memory_resource+`, `+backends::openssl::install_memory_functions+`
|OpenSSL
|none
|none
|none
|===
87 changes: 87 additions & 0 deletions doc/generated/messages.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ The fix: Add `+/webcpp/crypto//openssl+` or `+/third_party//bearssl+` to the pro

The fix: Add `+/third_party//bearssl+` to the program's sources.

|`+openssl_memory_not_linked+`
|native
|`+webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE routes OpenSSL's allocations, and OpenSSL is not linked. In the program's Jamfile, add /webcpp/crypto//openssl beside /webcpp/crypto//crypto, or remove that define. (without b2: define WEBCPP_CRYPTO_HAS_OPENSSL=1 and link libcrypto)+`

The fix: A target has the define and not OpenSSL: put `+<library>/webcpp/crypto//openssl+` in the same project requirements as the define, or remove the define.

|`+openssl_memory_on_webassembly+`
|wasip2, wasip3
|`+webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE is an option of native programs, and this program is built for WebAssembly. Remove that define from the program's Jamfile.+`

The fix: Remove `+<define>WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE+` from the WebAssembly build: give that build a project of its own, without the define and OpenSSL, naming `+/third_party//bearssl+`. On WebAssembly the backend is BearSSL, which allocates nothing.

|`+openssl_not_linked+`
|native, wasip2
|`+webcpp::crypto: the backend OpenSSL is used and not linked. In the program's Jamfile, add /webcpp/crypto//openssl beside /webcpp/crypto//crypto. (without b2: define WEBCPP_CRYPTO_HAS_OPENSSL=1 and link libcrypto)+`
Expand Down Expand Up @@ -312,6 +324,40 @@ On each target, the build's output contains:
* emscripten:
** `+webcpp::crypto: OpenSSL is not built for Emscripten. In the program's Jamfile, replace /webcpp/crypto//openssl with /third_party//bearssl.+`

`+memory_missing_definition_install+`:: The memory option set in the program's project, the install called, and `+openssl_memory_resource()+` not defined. The fix: Define `+std::pmr::memory_resource& webcpp::crypto::openssl_memory_resource() noexcept+` once in the program, returning a resource that is never destroyed.
+
Its Jamfile:
+
[listing]
----
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/memory_missing_definition_install/Jamfile[tag=jamfile]
----
+
On each target, the build's output contains:
+
* native, macOS:
** `+Undefined symbols for architecture+`
** `+"webcpp::crypto::openssl_memory_resource()", referenced from:+`
* native, Linux:
** `pass:[undefined reference to &#96;webcpp::crypto::openssl_memory_resource()']`

`+memory_missing_definition_make+`:: The memory option set in the program's project, a `+make+` on OpenSSL, and `+openssl_memory_resource()+` not defined. The fix: Define `+std::pmr::memory_resource& webcpp::crypto::openssl_memory_resource() noexcept+` once in the program, returning a resource that is never destroyed.
+
Its Jamfile:
+
[listing]
----
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/memory_missing_definition_make/Jamfile[tag=jamfile]
----
+
On each target, the build's output contains:
+
* native, macOS:
** `+Undefined symbols for architecture+`
** `+"webcpp::crypto::openssl_memory_resource()", referenced from:+`
* native, Linux:
** `pass:[undefined reference to &#96;webcpp::crypto::openssl_memory_resource()']`

`+no_backend_on_emscripten+`:: A program for Emscripten that uses the default backend and links none. The fix: Add `+/third_party//bearssl+` to the program's sources.
+
Its Jamfile:
Expand All @@ -326,6 +372,20 @@ On each target, the build's output contains:
* emscripten:
** `+webcpp::crypto: no backend is linked. On WebAssembly the backend is BearSSL: in the program's Jamfile, add /third_party//bearssl beside /webcpp/crypto//crypto, as in: exe app : app.cpp /webcpp/crypto//crypto /third_party//bearssl ; (without b2: define WEBCPP_CRYPTO_HAS_BEARSSL=1 and link BearSSL built with webcpp's src/canary_bearssl.c)+`

`+openssl_memory_on_emscripten+`:: The memory option of the OpenSSL backend set in a build for Emscripten. The fix: Remove `+<define>WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE+` from the WebAssembly build: give that build a project of its own, without the define and OpenSSL, naming `+/third_party//bearssl+`. On WebAssembly the backend is BearSSL, which allocates nothing.
+
Its Jamfile:
+
[listing]
----
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/openssl_memory_on_emscripten/Jamfile[tag=jamfile]
----
+
On each target, the build's output contains:
+
* emscripten:
** `+webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE is an option of native programs, and this program is built for WebAssembly. Remove that define from the program's Jamfile.+`

`+openssl_on_emscripten+`:: `+/webcpp/crypto//openssl+` named in a build for Emscripten. The fix: Name `+/third_party//bearssl+` in its place for the Emscripten build.
+
Its Jamfile:
Expand Down Expand Up @@ -398,10 +458,26 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at
|the compile
|Use `+aes256_gcm+` with BearSSL or OpenSSL linked.

|`+memory_missing_definition_install+`
|the link
|Define `+std::pmr::memory_resource& webcpp::crypto::openssl_memory_resource() noexcept+` once in the program, returning a resource that is never destroyed.

|`+memory_missing_definition_make+`
|the link
|Define `+std::pmr::memory_resource& webcpp::crypto::openssl_memory_resource() noexcept+` once in the program, returning a resource that is never destroyed.

|`+memory_two_files+`
|the link
|Give the define in the requirements of the program's project, with OpenSSL beside it, `+project app : requirements <define>WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE <library>/webcpp/crypto//openssl ;+`, so that every target of the program gets both.

|`+no_backend+`
|the compile
|As `+no_backend_native+`.

|`+openssl_memory_not_linked+`
|the compile
|A target has the define and not OpenSSL: put `+<library>/webcpp/crypto//openssl+` in the same project requirements as the define, or remove the define.

|`+openssl_not_linked+`
|the compile
|Add `+/webcpp/crypto//openssl+`.
Expand All @@ -422,3 +498,14 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at
|the compile
|Keep one of the two defines.
|===

Elsewhere than MSVC these mistakes build, and nothing stops them; the fixtures record it:

`+memory_two_files+`:: Two files of one program, one compiled with the memory option and one without.
+
Its Jamfile, which builds on native:
+
[listing]
----
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/memory_two_files/Jamfile[tag=jamfile]
----
9 changes: 7 additions & 2 deletions doc/generated/namespace-root.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,37 @@
// Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles,
// the message tests and the Jamfile fixtures: run it again, never edit this file.

[cols="2h,5,5,5",options="header"]
[cols="2h,5,5,5,5",options="header"]
|===
|Name |`random_device` |`equal` |`error`
|Name |`random_device` |`equal` |`error` |`openssl_memory_resource`

|What it is for
|Keys, IVs, tokens, nonces: every secret a program draws
|Checking a tag, a MAC or a token
|Telling failures apart
|Keeping every allocation of OpenSSL's in the program's own resource, natively

|Header
|`<webcpp/crypto/random_device.hpp>`
|`<webcpp/crypto/equal.hpp>`
|`<webcpp/crypto/error.hpp>`
|`<webcpp/crypto/backends/openssl.hpp>`

|Errors
|`entropy_unavailable`, `errc::not_supported`
|none: it returns `bool`
|its values are the errors
|`memory_functions_refused`, `memory_functions_not_installed`

|Standards and sources
|link:https://pubs.opengroup.org/onlinepubs/9799919799/functions/getentropy.html[POSIX.1-2024, getentropy], link:https://learn.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom[Microsoft, BCryptGenRandom], link:https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues[W3C Web Cryptography API, getRandomValues], link:https://github.com/WebAssembly/wasi-random[WASI, wasi:random]
|link:https://cwe.mitre.org/data/definitions/208.html[CWE-208, observable timing discrepancy]
|none
|link:https://docs.openssl.org/3.5/man3/OPENSSL_malloc/[OpenSSL 3.5's OPENSSL_malloc(3), CRYPTO_set_mem_functions]

|Choose it when
|you need a random number an attacker must not predict; never `std::mt19937` or `rand` (link:https://cwe.mitre.org/data/definitions/338.html[CWE-338, a weak generator used for security])
|you compare anything secret; never `==` or `memcmp` on a MAC
|you branch on a failure: forged data, a wrong size, no entropy
|a native program on OpenSSL must allocate only from its own arena; on WebAssembly, BearSSL allocates nothing
|===
6 changes: 6 additions & 0 deletions doc/generated/use-cases.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
`+/third_party//secp256k1+`
|<<crypto-memory,[.keep]`+arena_signer.cpp+`>>

|Keep every allocation of OpenSSL's in the program's arena
|`+openssl_memory_resource+`, `+backends::openssl::install_memory_functions+`
|OpenSSL, natively
|`+/webcpp/crypto//crypto+` in the program; in the project requirements, `+<define>WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE+` and `+<library>/webcpp/crypto//openssl+`
|<<crypto-memory-openssl,[.keep]`+openssl_memory.cpp+`>>

|Seed BearSSL's own generator for code that calls BearSSL directly
|`+random_device::fill+`
|BearSSL's C API
Expand Down
26 changes: 26 additions & 0 deletions doc/jamfile.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ time, and there is no AES-NI. A program for which timing attacks matter there
defines `WEBCPP_CRYPTO_DEFAULT_BACKEND_BEARSSL`, or names
`ciphers::gcm<ciphers::aes256<backends::bearssl>>`.

[#crypto-jamfile-memory]
=== OpenSSL's memory option

A native program that sends OpenSSL's allocations to its own resource
(<<crypto-memory-openssl>>) gives the define
`WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` and `/webcpp/crypto//openssl`
together, in the requirements of its project, not of one target. Every target
of the program then gets both: its own libraries, and a tool that only calls
`random_device` or `equal`, which would otherwise have the define without
OpenSSL. The fixture `memory_option` builds and runs this Jamfile natively:

[listing]
----
include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/memory_option/Jamfile[tag=jamfile]
----

Each mistake stops the build, with the messages of
<<crypto-jamfile-messages>>: the define on a target without OpenSSL, or in a
build for WebAssembly, is refused by `config.hpp`; `openssl_memory_resource()`
not defined is a link error; and on MSVC, files of one program compiled some
with the define and some without are refused by the linker (`LNK2038`). These
requirements cannot be built for WebAssembly, since the option is refused
there and `/webcpp/crypto//openssl` stops an Emscripten build: a WebAssembly
build of the same program is a project of its own, in a directory of its own,
with neither the define nor OpenSSL, and names `/third_party//bearssl`.

[#crypto-jamfile-cases]
=== Every Jamfile a user writes

Expand Down
Loading
Loading