Skip to content

feat(codes): add the indexed post-quantum signature codes and fix Indexer lead bytes - #428

Open
dhh1128 wants to merge 8 commits into
WebOfTrust:mainfrom
dhh1128:fix/cesr-pq-indexed
Open

dhh1128 wants to merge 8 commits into
WebOfTrust:mainfrom
dhh1128:fix/cesr-pq-indexed

Conversation

@dhh1128

@dhh1128 dhh1128 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

This adds the indexed post-quantum signature codes from trustoverip/kswg-cesr-specification#186, along with the Indexer fixes they need and two more that turned up in review. It builds on #427, so until that merges the diff here also shows #427's two commits. The six after those are the new ones.

#186 gives every ML-DSA and SLH-DSA signature an eight-character indexed code, so a post-quantum key can sign as a controller or witness in a -A or -B group. Signatures whose raw size is a multiple of 3 go under the existing 3 selector. The rest go under two new selectors, 8 and 9, which carry one and two lead bytes. That's the first time an indexed code used in practice has lead bytes, and Indexer turned out not to handle them.

The first commit fixes that. The constructor and _exfil both counted lead bytes as raw, so even the existing 1z and 4z test codes couldn't be built from raw or read back. Both now subtract the lead size, as Matter does. _rawSize had a misplaced parenthesis and was wrong for every code. Nothing calls it, but it now agrees with the constructor.

The second commit fixes something I found along the way. _exfil computed the pad bit size as 2 * ps != 0 ? ps : ls, which parses as (2 * ps != 0) ? ps : ls, so a one-character code like A had only 2 of its 4 pad bits checked. It now uses Matter's expression.

The third commit adds the 8 and 9 selectors and all 18 rows from #186, each with an IdrDex constant and a place in the current-only or both-lists set. The ML-DSA names match the ones on keripy's post-quantum branch. keripy has no SLH-DSA indexed codes yet, so I extended the same pattern for those (SLH_DSA_SHA2_128s_Big_Sig and so on), and they could change if keripy picks different names. The tests round-trip every code at an index too large for a two-character index, check each size against FIPS 204 and FIPS 205, and frame a real controller signature: a self-addressing inception whose key is ML-DSA-44, signed by that key under 8A.

A review of those three commits found two older problems in Indexer, and the next two commits fix them. IdxBthSigDex was missing the ECDSA secp256r1 codes E and 2E, which keripy includes, so a 2E signature built without an ondex got ondex 0 rather than its index. And the ondex was range-checked but never required to be an integer, so 1.5 was accepted. The last commit only corrects a test comment.

As with #427, these codes are provisional until #186 merges.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA

The post-quantum rows added in WebOfTrust#413 followed trustoverip/kswg-cesr-specification#165, which was merged before review and then reverted. The work reopened as trustoverip/kswg-cesr-specification#185, which drops FN-DSA and renumbers the master table. That left this table assigning many codes to a different primitive than the reopened PR does: 1AAR was an FN-DSA-512 signature here and is the ML-DSA-87 verification key there, and 2AAA was the FN-DSA-1024 key here and is the ML-DSA-44 signature there. Anything emitted under the new codes would have been misframed.

The 27 rows now match the reopened PR in code, description, full size and lead size. The six codes past its end (1AAc, 1AAd, 2AAL to 2AAO) are gone, and a test pins their absence so a stale row cannot keep accepting a code no draft defines. The codes stay provisional until that PR merges.

The size tests now check every row against the FIPS 204 and FIPS 205 raw sizes rather than against Falcon's. The Falcon exhibit is replaced by an ML-DSA-44 receipt over the same inception: a real keypair and a signature over the receipted event's bytes, generated with @noble/post-quantum 0.7.1, whose key (3AAA) and signature (2AAA) exercise both lead-byte selectors.

The indexed signature codes proposed in trustoverip/kswg-cesr-specification#186 are not added. Indexer's raw-size checks ignore the lead size, so no indexed code with lead bytes round-trips through it today; that needs a change to Indexer, not a table row.

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
A hostile review (codex) found three comments in the post-quantum tests overstating them. The header said the smallest public key is 1,312 B, which holds for ML-DSA but not for the 32 to 64 B SLH-DSA keys; it said the tests check real cryptography, when they frame a real key and signature but cannot verify it; and the -A test said it would catch a future indexed code, when it only shows that a Matter code does not resolve as Indexer.

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Indexer computed a code's raw size as (fs - cs) * 3 / 4, which counts its lead bytes as raw. The constructor therefore demanded too many raw bytes and _exfil rejected a correctly encoded value as improperly qualified, so no indexed code with lead bytes could be built from raw or read back from qb64. The only such codes today are the 1z and 4z test codes, but the post-quantum indexed codes in trustoverip/kswg-cesr-specification#186 use the 8 and 9 selectors, which carry one and two lead bytes. Both checks now subtract the lead size, as Matter does.

_rawSize had the parentheses in the wrong place, subtracting three quarters of the code size from the full size, and so was wrong for every code. Nothing in signify-ts calls it; it now uses the same formula as the constructor.

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
_exfil computed the pad bit size as `2 * ps != 0 ? ps : ls`, which parses as `(2 * ps != 0) ? ps : ls` and yields ps rather than 2 * ps. A one-character code such as A, whose material carries 4 pad bits, was only checked for 2 of them, so a qb64 value with a set pad bit decoded without complaint. The expression now matches Matter's, 2 * (ps ? ps : ls).

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
trustoverip/kswg-cesr-specification#186 adds indexed signature codes for every ML-DSA and SLH-DSA signature in WebOfTrust#185's master table, so a post-quantum key can sign as a controller or witness through a -A or -B group. They are eight-character codes with a three-character index and ondex, under the 3 selector for signatures needing no lead bytes and the new 8 and 9 selectors for one and two. Each scheme has a dual-indexed and a current-only code, as Ed448 does with 3A and 3B.

This adds the 8 and 9 selectors to Indexer.Hards and all 18 rows to Indexer.Sizes, matching WebOfTrust#186 in code and full size with the lead size its selector requires. Each code gets an IdrDex constant and its place in IdxSigDex and in IdxCrtSigDex or IdxBthSigDex. The ML-DSA names match keripy's feat/pq-signatures branch. keripy has no SLH-DSA indexed codes yet, so those names extend the same pattern and are new.

The tests round-trip every code through qb64 at an index past what a two-character index holds, check each raw size against the FIPS 204 or FIPS 205 signature size, and frame a real controller signature: a self-addressing inception whose one key is an ML-DSA-44 key, signed by it under 8A, generated with @noble/post-quantum 0.7.1. The codes stay provisional until WebOfTrust#186 merges.

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
IdxBthSigDex left out the ECDSA secp256r1 codes E and 2E, which keripy's IndexedBothSigCodex includes. The constructor uses that set to default a missing ondex to the index, so a 2E signature at index 5 built without an ondex encoded ondex 0, and an E signature carried no ondex at all until it was re-read from qb64. Nothing in signify-ts builds these signatures without an explicit ondex today. A hostile review (codex) of the post-quantum indexed codes found this.

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The constructor and _infil required the index to be an integer but only range-checked the ondex, so an ondex of 1.5 was accepted, stored, and encoded. keripy accepts only an int. A hostile review (codex) of the post-quantum indexed codes found this; it matters more now that three-character ondices are in use.

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The codex review pointed out that the comment's 'so it verifies' reads as something the tests check. They frame the signature and check its size; the verification happened once, when the vector was generated.

Claude-Session: https://claude.ai/code/session_01QygmFWJVFywFvun7CxZ9wA
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.46%. Comparing base (6e07dc9) to head (7d1ecc1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #428   +/-   ##
=======================================
  Coverage   97.46%   97.46%           
=======================================
  Files           1        1           
  Lines          79       79           
  Branches       28       28           
=======================================
  Hits           77       77           
  Misses          2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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