feat(std/signature): verify P-256 ECDSA signatures (ES256) #229
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/16-p256-verify"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #225 (slice 3 of #16).
What
std/signatureverifies ECDSA over P-256 with SHA-256, the ES256 of JWS, COSE and WebAuthn passkeys:P256PublicKey:fromBytes(65-byte uncompressed SEC 1 point),fromCoordinates(x, y),tryFromhexadecimal;bytes,hex,Show,Equals,Hash;verifies(message, signature).P256Signature:fromBytes(64 bytes r || s, the JWS/P1363 form),fromDer(strict DER, the WebAuthn/X.509 form),tryFromhexadecimal.SignatureError.NotDer(reason)is new;NotAPointandScalarOutOfRangenow also serve P-256.src/montgomery.trb(private): Montgomery arithmetic over nine 30-bit limbs (R = 2^270) for p and n; every intermediate stays below 2^61, so an overflow would panic, never answer wrong.Checks (security-relevant)
Tests
std/signature/tests/p256.test.trb(15 tests) withtests/wycheproof.trb(generated data, Apache 2.0 notice kept):crypto; changed message, r, s or key refused.ecdsa_secp256r1_sha256_p1363_test.json(262) andecdsa_secp256r1_sha256_test.json(484, DER) verifies or is refused exactly as the file says. The refused direction is covered by the files' own invalid variants (bit flips, r/s of 0, n, p and neighbours, infinity, bad DER).The arithmetic was first written as a Python model with the same limbs and steps (checking every intermediate against 2^63) and ran both Wycheproof files with zero mismatches before the TorbScript port.
Locally:
torb checkclean,torb format --checkclean on all touched files,torb testof std/signature in the VM: 25 passed in about 64 s (P-256 runs about 8 verifications per second in the VM; native not measured locally).docs skill --checkup to date.Seed impact
None: no native, no compiler, no seed change. Pure TorbScript in std/signature plus its docs page and the regenerated skill reference.
eefcc3bc18c7c2fa7207CI red on
8c7913e: ci / tier B (linux-x64) failed after 7m35s (run 411, job 6); ci / gates fails as a consequence. All other jobs green (tier A, bootstrap, pdisc, same-C, playground). Cause not seen: the job log is not readable with the reviewer token. Review is pending and runs again once CI is green.8c7913eae0ff8a73b9beTier B on
8c7913efailed in the C runtime tests, not in this change:tests/io_test.c:301 torb_network_operations_alive(): 2, expected 1intest_io_a_cancelled_wait_releases_its_registration(234 tests, 1 failed; everything std/signature related passed). This PR touches no runtime or native code, and the same lane was green on main (a488fa3e) and other heads minutes later, so it reads as a flaky runtime test. I rebased onto main (a488fa3e, 4 commits; clean,pdisc checkok) to get a fresh headff8a73band a fresh CI run. If the test fails again on this head I will open an issue for it. Re-requesting review once the new head is pushed.CI red on
ff8a73b: ci / tier A (linux-x64) failed after 4m11s (run 434, job 5445); ci / gates fails as a consequence. All other jobs that ran are green (bootstrap, same-C, release-sync/registry, playground, pdisc). Cause:test compiler/tests (native), 1 of 2737 failed (shard 4 of 4): language server test "A keystroke in a body checks that body > a body whose inferred result changes checks the bodies that call it",Assertion failed: messagesOf(published(answers).get(mainUri) ?? []) == ["ExpectedInt64, foundString"]. All std/signature tests passed in the VM and native lanes. The PR touches no compiler or language-server code, so this looks like a flake or a main-side regression; please re-run or open an issue for it. Also note: the PR is currently reported as not mergeable (main moved to3bd7c22after the rebase ontoa488fa3), so it needs another rebase before it can merge. Review is pending and runs again once CI is green.ff8a73b9beb266855c15Tier A on
ff8a73bfailed in one language-server test ("A keystroke in a body checks that body > a body whose inferred result changes checks the bodies that call it"), 1 of 2737; the PR touches no compiler or language-server code. That is the known timing-dependent flake tracked in #244 (language-server tests fail tier A at random). I rebased onto current main (99a8c96, mergeable again): conflicts only in docs/standard-library/signature.md and its skill copy, since main now generates the declaration blocks; the P256PublicKey and P256Signature blocks carrytorb:declarationmarkers in the formtorb docs declarationswrites (Self, show, equals, hash listed),pdisc checkok. New headb266855. Re-requesting review once CI on it is done.Checklist for
b266855:p256.test.trb, including all 262 (P1363) and 484 (DER) Wycheproof secp256r1/SHA-256 cases and RFC 6979 A.2.5 vectors; CI green for exactly this head (tier A, bootstrap, same-C, playground, pdisc, gates). The earlier red runs were the language-server flake (#244), not this change.Non-blocking: none.