Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
20a4e07
crypto: P-256 key pairs from a raw scalar and validated public keys o…
Nov 21, 2026
5fdce87
crypto: P-256's tests pin the non-canonical coordinates and the backe…
Nov 21, 2026
3364579
crypto: P-256 ECDSA on BearSSL with RFC 6979's nonce, raw and DER, an…
Nov 21, 2026
ae82bbd
crypto: P-256 ECDSA's page shows the signing lines from its example, …
Nov 21, 2026
806ad57
crypto: P-256 ECDSA's tests refuse tampering on every signature, cove…
Nov 21, 2026
663a5d6
crypto: P-256 ECDH on BearSSL returns the shared point's raw x coordi…
Nov 21, 2026
e660ca3
crypto: P-256 ECDH's use case claims nothing of webcpp::trystero, its…
Nov 21, 2026
0a8fb41
crypto: SPKI and PKCS#8 for P-256 by RFC 5480's and RFC 5915's fixed …
Nov 21, 2026
16a5341
crypto: P-256's formats read results unchecked where they are checked…
Nov 21, 2026
d9e9319
crypto: the namespace tables name P-256's SPKI and PKCS#8 with their …
Nov 21, 2026
ffbd690
crypto: P-256 ECDH's use case and page cite Trystero 0.27.0's pairwis…
Nov 21, 2026
2e9a79c
crypto: OpenSSL natively and WebCrypto in node as oracles of P-256's …
Nov 21, 2026
9353697
crypto: P-256's oracle paragraph names code without a possessive that…
Nov 21, 2026
b21b096
crypto: P-256's WebCrypto oracle splits a case into asking and judgin…
Nov 21, 2026
ca341d9
crypto: P-256's OpenSSL oracle compares the scalar OpenSSL loads from…
Nov 21, 2026
9121118
crypto: merge main, with the data-independent-timing change, into P-256
Nov 21, 2026
d6889c0
crypto: the memory guide names the standard libraries of LLVM and GNU…
Nov 21, 2026
bebd561
crypto: P-256's examples bind the error's message to a named string b…
Nov 21, 2026
98fbcec
crypto: P-256's constant-time paths, sizes and throughput, and the te…
Nov 21, 2026
a7fe945
crypto: the throughput page measures P-256's signing, verification an…
Nov 21, 2026
1dde538
crypto: the size matrix measures P-256's signing, verification and EC…
Nov 21, 2026
cea6e28
crypto: the constant-time section gives P-256's dudect readings of th…
Nov 21, 2026
9cc0060
crypto: review fixes: a speed cell says provisional where its figures…
Nov 21, 2026
699ee2f
crypto: the BearSSL canary names the pin 32381d6, webcpporg/bearssl's…
Nov 21, 2026
59877a0
crypto: the constant-time claims for P-256 state what ran, memcheck a…
Nov 21, 2026
362d7ed
crypto: the BearSSL verdicts suppression and three stack sources name…
Nov 21, 2026
85536f0
crypto: the final review's fixes, AGENTS.md names the BearSSL fix, th…
Nov 21, 2026
66cad54
crypto: the timing coverage test's long lines are wrapped
Nov 21, 2026
1bacf5c
crypto: the timing coverage test checks the P-256 key pair's moves in…
Nov 22, 2026
ebb5c22
crypto: merge main, with GCM's two-pass open, the AES block cipher's …
Nov 22, 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
12 changes: 9 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ specific to crypto.

- An algorithm type does every guard; a backend's header supplies only the six traits of
`detail/engines.hpp` (`block_state`, `block_engine`, `gcm_state`, `gcm_engine`, `aead_state`,
`aead_engine`) and, for the curves and `hybrid`, the functions of its own header.
`aead_engine`), the two of `detail/p_curves.hpp` per P-curve (`p_curve_state`,
`p_curve_engine`) and, for the other curves and `hybrid`, the functions of its own header.
- A new public function that calls a backend holds `detail::timing_guard` as its
first statement (it sets arm64's DIT for the call, `detail/timing.hpp`) and joins the coverage
test of its backend, `test/timing_coverage_<backend>_test.cpp`, which checks through the seam
that each call entered its own guard. A function that only copies or encodes bytes, with no
backend call, holds none.
- The constant-time lane's P-256 paths (`test/constant_time/paths.hpp`): BearSSL's ECDSA signing
branches on its own verdicts, listed for memcheck in `bearssl_verdicts.supp`, which a later
P-curve's signing joins; MemorySanitizer counts BearSSL's window selections public (masks of the
form `(q | -q) >> 31`), so the public point and `ecdh_x` are checked traced by memcheck alone.
- A test of a backend is a `.cpp` of its own per backend, never a define that changes the backend
of one source (spec section 4.3's pitfall).
- Every C library is unchanged upstream code. A moved pin is a change of its own
(CODING-GUIDELINES.md chapter 5, rule 12).
- Every C library is upstream code, unchanged except where CODING-GUIDELINES.md chapter 5 rule 1
allows a security fix on the mirror's `webcpp` branch (BearSSL: 32381d6, ECDSA's nonce
decoding); a moved pin carries that commit. A moved pin is a change of its own (rule 12).
- X25519's constant time on wasip2 is an open finding (the page's constant-time table): do not
describe it as a pass.
69 changes: 51 additions & 18 deletions bench/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
times five runs of the family's fixed operation and reports their median, in microseconds per
operation. The data holds, per cell, every invocation's median, their median, and the fastest and
slowest single run. The operation each cell's program reports must be the one
doc/tables/crypto.json states for its family (the size matrix's), or the cell is refused. A time
doc/tables/crypto.json states for its family (the size matrix's), or the cell is refused. A cell
the program lists with a third word, `<family> <backend> <operation>`, is a further operation of
the family, measured as `throughput <family> <backend> <operation>`, whose text is the entry of
that name in the family's "sized_operations". A time
never fails this script: only a program that does not run, or a cell it does not know, does.
`--render-only` rewrites the page from the data.

Expand Down Expand Up @@ -260,37 +263,57 @@ def run(target, command):


def cells_of(target, exe, families):
"""The cells the program was built with, which it lists without measuring; each must be a
family of crypto.json."""
cells = [tuple(line.split()) for line in run(target, [exe, "--list"]).splitlines() if line]
for family, backend in cells:
"""The cells the program was built with, which it lists without measuring, each as (family,
backend, operation), the operation "" for the family's fixed one; each must be a family of
crypto.json, and a further operation one of its "sized_operations"."""
cells = []
for line in run(target, [exe, "--list"]).splitlines():
words = line.split()
if not words:
continue
if len(words) not in (2, 3):
sys.exit(f"collect.py: {target} lists {line!r}, which is not "
"\"<family> <backend> [<operation>]\"")
family, backend = words[0], words[1]
further = words[2] if len(words) == 3 else ""
if family not in families:
sys.exit(f"collect.py: {target} lists {family} {backend}, and crypto.json has no "
f"family {family}")
if further and further not in families[family].get("sized_operations", {}):
sys.exit(f"collect.py: {target} lists {family} {backend} {further}, and crypto.json's "
f"family {family} has no sized operation {further}")
cells.append((family, backend, further))
return cells


def stated_operation(family, further):
"""The operation crypto.json states for a cell: the family's fixed one, or the further one of
that name."""
return family["sized_operations"][further] if further else family["measured"]


def measure(exes, invocations):
data = crypto_json()
families = {family["name"]: family for family in data["families"]}
cases = {}
for target, exe in exes.items():
for family, backend in cells_of(target, exe, families):
cases[(target, family, backend)] = {"exe": exe, "results": []}
for family, backend, further in cells_of(target, exe, families):
cases[(target, family, backend, further)] = {"exe": exe, "results": []}
loads = [os.getloadavg()]
for _ in range(invocations):
for (target, family, backend), case in cases.items():
command = [case["exe"], family, backend, "--runs", "5"]
for (target, family, backend, further), case in cases.items():
command = [case["exe"], family, backend] + ([further] if further else []) + [
"--runs", "5"]
case["results"].append(program_line(target, command, run(target, command),
THROUGHPUT_LINE_SHAPE))
loads.append(os.getloadavg())
out = []
for (target, family, backend), case in cases.items():
for (target, family, backend, further), case in cases.items():
results = case["results"]
stated = families[family]["measured"]
stated = stated_operation(families[family], further)
if results[0]["operation"] != stated:
sys.exit(f"collect.py: {target} {family} {backend} measures "
f"{results[0]['operation']!r}, and crypto.json states {stated!r}")
sys.exit(f"collect.py: {target} {family} {backend}{' ' + further if further else ''} "
f"measures {results[0]['operation']!r}, and crypto.json states {stated!r}")
medians = [r["median_us"] for r in results]
runs = [t for r in results for t in r["runs_us"]]
out.append({
Expand All @@ -308,8 +331,8 @@ def measure(exes, invocations):
"max_us": max(runs),
})
return {
"measurement": "each family's fixed operation per backend and target, "
"bench/operations.hpp",
"measurement": "each family's fixed operation, and its further sized operations, per "
"backend and target, bench/operations.hpp",
"date": utc_today(),
"machine": machine(),
"load_average_before_after": [list(loads[0]), list(loads[1])],
Expand Down Expand Up @@ -479,8 +502,9 @@ def render(data, page):
"[#crypto-performance]",
"=== Throughput",
"",
"How long each family's fixed operation takes on each backend and target, the operation",
"the size matrix's programs call (bench/operations.hpp). A dated reference, measured by",
"How long each family's fixed operation, and each further operation the size matrix",
"measures, takes on each backend and target, the operations the size matrix's programs",
"call (bench/operations.hpp). A dated reference, measured by",
"hand, that decides nothing: every default is chosen by the reason",
"<<crypto-backends-defaults>> states, whatever these figures say.",
"",
Expand Down Expand Up @@ -515,8 +539,17 @@ def render(data, page):
"| Operation | Backend | Target | Median (µs) | Fastest (µs) | Slowest (µs) "
"| Per second",
]
operations = {family["name"]: [family["measured"]] +
list(family.get("sized_operations", {}).values())
for family in table["families"]}

def operation_rank(case):
# A further operation crypto.json no longer states sorts after the stated ones.
stated = operations[case["family"]]
return stated.index(case["operation"]) if case["operation"] in stated else len(stated)

cases = sorted(data["cases"], key=lambda c: (order.index(c["family"]), c["backend"],
TARGETS.index(c["target"])))
operation_rank(c), TARGETS.index(c["target"])))
for c in cases:
lines += [
"",
Expand Down
94 changes: 94 additions & 0 deletions bench/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <webcpp/crypto/ciphers/chacha20_poly1305.hpp>
#include <webcpp/crypto/ciphers/gcm.hpp>
#include <webcpp/crypto/curves/ed25519.hpp>
#include <webcpp/crypto/curves/p256.hpp>
#include <webcpp/crypto/curves/x25519.hpp>
#include <webcpp/crypto/error.hpp>
#ifdef WEBCPP_CRYPTO_HAS_SECP256K1
Expand Down Expand Up @@ -452,6 +453,99 @@ class secp256k1_silent_payments {
};
#endif

// An ECDSA signature of a 32-byte SHA-256 digest on P-256, RFC 6979's nonce, S as computed.
template <class Backend>
class p256 {
public:
static constexpr std::string_view operation = "ECDSA signature of a 32-byte SHA-256 digest";

explicit p256(std::uint8_t seed)
: digest_(filled<32>(static_cast<std::uint8_t>(seed + 3U))),
key_(take(curves::p256::basic_keypair<Backend>::make(
filled<32>(static_cast<std::uint8_t>(seed | 1U))),
"make")) {}

std::uint8_t run() { return take(key_.sign_ecdsa(digest_), "sign_ecdsa")[0]; }

bool check() {
auto const signature = take(key_.sign_ecdsa(digest_), "sign_ecdsa");
auto const public_key = take(key_.public_key(), "public_key");
return curves::p256::verify_ecdsa(signature, digest_, public_key).has_value();
}

private:
std::array<std::uint8_t, 32> digest_{};
curves::p256::basic_keypair<Backend> key_;
};

// The verification of an ECDSA signature of a 32-byte SHA-256 digest on P-256; the signature and
// the public key are made once, outside what is measured.
template <class Backend>
class p256_verify_ecdsa {
public:
static constexpr std::string_view operation = "ECDSA verification of a 32-byte SHA-256 digest";

explicit p256_verify_ecdsa(std::uint8_t seed)
: digest_(filled<32>(static_cast<std::uint8_t>(seed + 3U))),
key_(take(curves::p256::basic_keypair<Backend>::make(
filled<32>(static_cast<std::uint8_t>(seed | 1U))),
"make")),
public_key_(take(key_.public_key(), "public_key")),
signature_(take(key_.sign_ecdsa(digest_), "sign_ecdsa")) {}

std::uint8_t run() {
take(curves::p256::verify_ecdsa(signature_, digest_, public_key_), "verify_ecdsa");
return signature_[0];
}

bool check() {
auto other = signature_;
other[63] ^= 1U;
return curves::p256::verify_ecdsa(signature_, digest_, public_key_).has_value() &&
!curves::p256::verify_ecdsa(other, digest_, public_key_).has_value();
}

private:
std::array<std::uint8_t, 32> digest_{};
curves::p256::basic_keypair<Backend> key_;
curves::p256::basic_public_key<Backend> public_key_;
std::array<std::uint8_t, curves::p256::signature_size> signature_{};
};

// The x coordinate of the ECDH shared point of a P-256 key pair and a peer's public key.
template <class Backend>
class p256_ecdh_x {
public:
static constexpr std::string_view operation =
"x coordinate of the ECDH shared point with a peer's public key";

explicit p256_ecdh_x(std::uint8_t seed)
: key_(take(curves::p256::basic_keypair<Backend>::make(
filled<32>(static_cast<std::uint8_t>(seed | 1U))),
"make")),
peer_(take(curves::p256::basic_keypair<Backend>::make(
filled<32>(static_cast<std::uint8_t>(seed + 6U))),
"make")),
peer_public_(take(peer_.public_key(), "public_key")) {}

std::uint8_t run() {
auto const shared = take(key_.ecdh_x(peer_public_), "ecdh_x");
return shared.bytes()[0];
}

bool check() {
auto const own_public = take(key_.public_key(), "public_key");
auto const shared = take(key_.ecdh_x(peer_public_), "ecdh_x");
auto const peer_shared = take(peer_.ecdh_x(own_public), "ecdh_x");
return std::ranges::equal(shared.bytes(), peer_shared.bytes());
}

private:
curves::p256::basic_keypair<Backend> key_;
curves::p256::basic_keypair<Backend> peer_;
curves::p256::basic_public_key<Backend> peer_public_;
};

// An Ed25519 signature of a 32-byte message.
template <class Backend>
class ed25519 {
Expand Down
Loading
Loading