Skip to content

codecs: dudect's bech32 cases prepare their texts by the constant-time conversion - #4

Merged
pinhopro merged 1 commit into
mainfrom
main-green
Dec 3, 2026
Merged

pinhopro merged 1 commit into
mainfrom
main-green

Conversation

@pinhopro

@pinhopro pinhopro commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

bech32_stream_decode read |t| 132 and 104 in two of three runs on an AMD EPYC 9V74 (codecs#2's run). It passed on every other runner model.

Cause: the harness, not the library. A probe on seven 9V74 hosted runners (eight fresh processes each, Clang 18 -O3 as the lane builds it) measured five variants of the program:

variant processes over 10
as it is 23 / 56 (up to 122)
stream decoder writes its data apart from its hold 54 / 56
stream decoder does not wipe its hold 32 / 56
no address randomisation (setarch -R) 50 / 56
class text encoded through a secure::secret<32> (constant-time conversion) 0 / 56 (1 to 4)

Changing the decode does not help. The decode's x86-64 code has no branch or table read on the text (disassembled), and the A/A control was clean. Changing only the unmeasured preparation removes the signal. The public conversion of the public bytes runs the same instructions for both classes, but it leaves their values unwiped in memory that the measured operation reuses. The secret conversion wipes them. This is the remedy base58's cases already use (codecs#2).

Fix: every bech32 case's shared preparation now encodes through a secure::secret<32>. The library is unchanged.

Verified: the program builds and runs (Clang 18, x86-64), and the lint (macOS half and the Linux amd64 lint) is clean. The probe branch has been deleted.

🤖 Generated with Claude Code

…e conversion

bech32_stream_decode read |t| 104 and 132 in two of three runs on an AMD EPYC 9V74 (codecs#2's
run) and passed elsewhere. A probe on seven 9V74 runners, eight fresh processes each, measured
the program as the lane builds it in five variants. As it is, 23 of 56 processes read over 10
(up to 122). With the stream decoder changed to write its data apart from its hold, 54 of 56.
Without its wipe, 32 of 56. Without address randomisation, 50 of 56. With the class's text
encoded by the constant-time conversion of a secure::secret<32>, as base58's cases already are,
0 of 56 (1 to 4).

So the decode is not where the classes differ: its x86-64 code (Clang 18, -O3) has no branch or
table read on the text, and the A/A control was clean. What differs is what the preparation leaves
behind. The public conversion of the public bytes runs the same instructions for both classes
but leaves their values, unwiped, in memory the measured operation reuses. The secret conversion
wipes them. Every bech32 case shares the one preparation, which now goes through the secret
conversion. The library is unchanged.
@pinhopro
pinhopro merged commit d2942b2 into main Dec 3, 2026
29 checks passed
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