Skip to content

codecs: z-base-32, the format of pkarr's keys - #6

Merged
pinhopro merged 5 commits into
mainfrom
codecs/zbase32
Dec 4, 2026
Merged

pinhopro merged 5 commits into
mainfrom
codecs/zbase32

Conversation

@pinhopro

@pinhopro pinhopro commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Adds formats::zbase32 (<webcpp/codecs/zbase32.hpp>): z-base-32, the format pkarr writes its Ed25519 keys in (32 bytes as 52 characters), which iroh reaches through pkarr. Design: webcpporg/proposals, libraries/codecs/openspec/changes/zbase32/ (D1 to D3, rulings R1 to R10).

What

  • One implementation. base32's detail templates take an alphabet type in place of bool Hex (base32_alphabet<Hex>, zbase32_alphabet); the codec and stream codec move to detail/formats/base32_codec.hpp. base32's behaviour and tests are unchanged.
  • z-base-32's alphabet by masks: a value's symbol by secure::constant_time::lookup, a symbol's value by is_equal_mask against the 32 symbols, as bech32's; constant time on every call, streaming natively.
  • Canonical decode: lower case alone (upper case, = and other characters are invalid_character), a remainder of 1, 3 or 6 is invalid_length, non-zero trailing bits are invalid_padding. pkarr's decoder (crate base32 0.5.1) ignores trailing bits and truncates bad lengths; codecs refuses them.
  • Exact sizes: 32 bytes encode into text<52>, text<52> decodes into bytes<32>.
  • Vectors: pkarr at 3dca339 (its key with bytes, its other keys, its refused keys) and the z-base-32 document's byte examples, with provenance in test/zbase32_vectors.hpp; a plain reference against every byte at every place and 5000 near-valid texts; the stream test; noexcept, allocation and <windows.h> tests.
  • Own lanes: the constant-time paths (memcheck, MemorySanitizer) and dudect zbase32_decode / zbase32_encode with A/A controls; the fuzz target zbase32 with 35 corpus inputs.
  • The page: a z-base-32 section with example/zbase32_pkarr.cpp, the tables, the changelog line (merged into base32's to keep ten lines).

Local verification (head e55940b)

  • clang, gcc-15, wasip2, wasip3, Emscripten over libs/codecs/test, example, test/fuzz: 0 failed.
  • b2 libs/codecs/doc: built.
  • Native dudect (release, Apple M-series): every case below 10 (zbase32_decode 2.15, zbase32_encode 1.70).
  • Linux constant-time lane: status 0, judge 0, planted leaks found. Linux fuzz lane: status 0.
  • MSVC 14.3 and 14.5 x64 debug: 220 passed each, new failures 0.
  • macOS lint clean; Linux lint (linux-lint, files mode): CLEAN.

🤖 Generated with Claude Code

R added 5 commits December 4, 2026 00:21
… codec and stream codec in detail/formats/base32_codec.hpp
…tion over its own alphabet, constant time and streaming, tested against pkarr's vectors
… zbase32_decode and zbase32_encode with their A/A controls, the fuzz target with its corpus
…karr.cpp, the tables, the changelog's line
@pinhopro
pinhopro merged commit 85061b2 into main Dec 4, 2026
29 checks passed
@pinhopro
pinhopro deleted the codecs/zbase32 branch December 4, 2026 05:29
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