Skip to content

secure: genesis (the DIT guard, erase_secret, secret, constant_time_equal, declassify and the constant-time blocks) - #1

Merged
pinhopro merged 42 commits into
mainfrom
secure/genesis
Nov 26, 2026
Merged

pinhopro merged 42 commits into
mainfrom
secure/genesis

Conversation

@pinhopro

Copy link
Copy Markdown
Contributor

webcpp::secure's genesis: the side-channel and secret-in-memory primitives that crypto, hash and codecs share, every name under webcpp::secure, depending on config alone, no algorithm.

  • <webcpp/secure/timing_guard.hpp>: timing_guard, cpu_has_dit(), dit_is_set(), the seam WEBCPP_SECURE_TIMING_ENTERED; DIT on arm64 under Apple's systems, Linux and Windows (_ReadStatusReg/_WriteStatusReg, FEAT_DIT probed once under SEH). The guard leaves DIT as it found it, also when Windows on ARM64 clears DIT on resuming after a catch.
  • erase_secret, secret<N>, constant_time_equal (any two byte sequences), declassify, moved from crypto with no alias; detail/wipe.hpp with its test seam.
  • <webcpp/secure/constant_time.hpp>: value_barrier, masks, select, lookup, select_bytes, byte comparisons, tested exhaustively on 8 bits and at random above.
  • The own lane constant-time: memcheck, MemorySanitizer, dudect with A/A controls and planted leaks that must fail.
  • The page, five examples, the guard's bench (37.0 ns to set DIT, 1.2 ns when set, 0 disengaged; release, idle machine).

Verified locally before merge: clang 908, gcc-15 713, wasip2 808, wasip3 791, Emscripten 598, clang and Emscripten release, the constant-time lanes on Linux and macOS, macOS and Linux lint, MSVC 14.3 and 14.5 x64 debug, MSVC 14.5 arm64 debug for the DIT tests (over secure, hash and crypto together). Change: webcpporg/proposals, libraries/secure genesis.

🤖 Generated with Claude Code

R added 30 commits November 24, 2026 14:27
…tions section, so the reference and doc-check pass
… from config's withdrawn change, with its seam, its test support and its tests
…fy with its checkers' marks as test support
…byte comparisons, checked against a plain reference
…y, so a 64-bit entry keeps its top half on WebAssembly
…the compiler cannot merge, hoist or drop it
… which reports an asm statement's uninitialised register input
…over every block, each with a planted leak that must fail
…o 100 columns, and the changelog lines keep to 30 words
…test::exit_status, as every test does, so that a failure fails on Emscripten
…real buffers whose read or write would change the result, with no null span
R added 12 commits November 25, 2026 17:46
…t a vector's, for which MSVC's debug library also allocates a proxy
…459): each takes two words, and user_globals checks it
…ndows on ARM64 clears DIT after a catch

Windows on ARM64 keeps PSTATE.DIT through the search for a handler and the
unwinding, then resumes the thread after a catch block (or in an __except
block) with DIT clear: RtlRestoreContext clears it whatever the context's
Cpsr says (probes on the Windows 11 ARM64 VM, MSVC 14.3 and 14.5, debug and
release). An exception caught inside a guard's scope thus left the scope with
DIT clear, and a guard that had found DIT set did nothing at its end, so the
call left a program's DIT clear (hash timing_botan_failure on MSVC arm64).

The guard now remembers what it found: clear, it clears DIT at its end as
before; set, it reads DIT again at its end and sets it if something inside
cleared it. timing_guard_exceptions checks it on every target, with
exceptions on and off: DIT cleared inside nested guards in every order, an
exception caught inside a guard, and one thrown through nested guards (DIT
during the unwinding as each guard found it; after the catch, what a
guard-free catch leaves, clear on Windows on ARM64). The page says what
Windows does, the performance page is measured again (the second read costs
about a nanosecond), and `__try` and `__except` render as code.
… dudect_harness checks its lines without freopen and fopen, which MSVC deprecates (C4996), and on every target
…ide a guard, since on 64-bit ARM only DIT makes their time independent of their data

MSVC 14.5's arm64 lookup failed dudect_blocks (|t| 12 to 17, five runs of five)
on the Windows 11 ARM64 machine, while 14.3's passed. Its machine code is
branch-free and index-free: per entry eor, sub, bic, neg (the mask), the
volatile barrier's str and ldr at a fixed slot, ldr of every entry in order,
and, orr, with the loop's public bound the only branch. The same program with
an msr of DIT and an isb around the lookup gave |t| 14.6 to 17.5 writing 0 and
0.8 to 2.6 writing DIT's bit: the time depended on the data with DIT clear.
Arm promises a data-independent time only with DIT set, and every function of
webcpp that computes on a secret holds a guard, so the program now measures
the blocks as those functions run them, and the blocks page says so.
…tion, and the constant-time Jamfile's comment keeps to 80 columns (lint fix)
…s with a bounds-checked loop in place of string_view::substr, which may throw from a noexcept function (clang-tidy's bugprone-exception-escape)
…that DIT after a catch is as the unwinding left it, names the guard around a catch that returns to a C library, the blocks need DIT on 64-bit ARM (constant_time.hpp, hex_digit holds a guard), and the dudect |t| is 11 to 17.5 as logged
…t the backslash, which Asciidoctor printed (no attribute reference to escape there)
…load 1.9): clear 37.0 ns, set 1.2 ns, disengaged 0.0 ns; the page drops its load NOTE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant