Skip to content

feat: validate raw SLH private-key imports asynchronously - #1093

Merged
boorad merged 6 commits into
margelo:mainfrom
sidhujag:feat/slh-dsa-raw-key-validation
Nov 15, 2026
Merged

boorad merged 6 commits into
margelo:mainfrom
sidhujag:feat/slh-dsa-raw-key-validation

Conversation

@sidhujag

@sidhujag sidhujag commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Complete raw SLH-DSA keys now use createPrivateKeyAsync(), which returns a validated PrivateKeyObject. The native worker validates its own copy and transfers that same key into the returned handle. The separate public SlhDsa validator is removed; other synchronous key imports keep their existing API.

Busy admission has a separate error from invalid key material. Tests cover all twelve variants, wrong inputs, seed/root corruption, caller-buffer erasure, worker cleanup and admission reuse. There is also a positive SK.prf mutation test: root validation does not authenticate those original bytes, and a changed SK.prf can still produce a valid signature. Stored-key integrity remains the application's responsibility.

The branch retains the latest upstream fixes. The example also normalizes its generated ReactCodegen path so the CocoaPods checksum does not depend on Bun's peer-directory name, and resolves one Nitro runtime to prevent duplicate Android dispatcher installation.

Validation: TypeScript, lint, formatting, Node Jest, the ncrypto/OpenSSL compatibility check and the standalone C++ admission regression pass. Both full example runs pass at 273ae4f76166b0954737fa1f0cf4e486f7956d83: 2,209 tests on iOS 27.2 Simulator and 2,209 on the Android emulator.

Both local native runs are complete. Keeping this draft for the required maintainer-signed attestation; the local test results are not that attestation.

@vercel

vercel Bot commented Nov 8, 2026

Copy link
Copy Markdown

@sidhujag is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

@boorad

boorad commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the careful write-up, and for keeping this a draft until it has a device run. The OpenSSL call is the right one, and the twelve fixtures match the NIST ACVP keyGen file at 975de31 (SHA-256 d7c53a1b…d920). EVP_PKEY_new_raw_private_key_ex does not check consistency, and EVP_PKEY_pairwise_check is what recomputes PK.root from SK.seed and PK.seed. Copying the secret onto the worker and wiping it afterwards is also right. The root walk is slow on the s sets, so it should not run on the JavaScript thread.

I do not want to merge it in this shape.

SlhDsa is an internal helper. Public SLH-DSA already goes through generateKeyPair, sign / verify, and createPrivateKey({ format: 'raw-private' }). Exporting the class puts crypto.SlhDsa on the object that install() assigns to global.crypto, and getPublicKey() / getPrivateKey() on that class return DER while this method speaks raw FIPS 205 bytes. The hole is initRawPrivate: it imports a raw SLH-DSA private key and never runs the pairwise check. Please hang the check on that import, asynchronously, and return a KeyObject. A second import of the same bytes should not skip the check.

Two limits should be explicit. OpenSSL's pairwise test never reads SK.prf, so a key with a damaged SK.prf passes and later signatures do not verify. The example only flips the last byte, which is PK.root on the 128-bit vector. Please add corrupted SK.seed, PK.seed, PK.root, and SK.prf cases, and say in the docs that SK.prf is not checked unless you also do a deterministic sign/verify. The process-wide admission flag fails with the same string as a bad key, and the overlap test accepts either outcome. A caller that treats that error as "corrupt key" can discard a good one. Use a different error when another validation is in progress.

The user-facing docs should describe the import, the byte lengths, and those two errors. The Nitro release-mode paragraph can stay in a code comment. Please run the example on device before taking this out of draft. The happy path depends on the hand-rolled Promise executor, and nothing has executed it yet.

@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

Deployment failed for project react-native-quick-crypto with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

@sidhujag sidhujag changed the title feat: validate complete raw SLH-DSA private keys off thread feat: validate raw SLH private-key imports asynchronously Nov 12, 2026

sidhujag commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated this to return a validated PrivateKeyObject from createPrivateKeyAsync(), removed the public SlhDsa helper, and separated busy from invalid-key errors.

One correction on SK.prf: changing just that component can still produce valid signatures. The new test checks this directly. The root check validates the seed/root relationship, but signing and verifying cannot establish that SK.prf matches the original saved bytes. FIPS 205, algorithms 18–20 describes that distinction.

@sidhujag

Copy link
Copy Markdown
Contributor Author

@boorad ^

@boorad

boorad commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

AgentSCM icon AgentSCM · Local validation

Reported outcome: pass · 2/2 checks reported · 5 omissions

Source: github.com/margelo/react-native-quick-crypto at 0389db8edc49

Worker-reported; the verifier checks the signature and source bindings, not whether commands ran.

Command results
  • ios-e2e: Exited, exit 0, 129184 ms
  • android-e2e: Exited, exit 0, 87418 ms
Coverage and environment

Coverage: 2/2 checks reported; 5 omissions.

  • ignored tests

  • windows

  • container smoke

  • hub end-to-end

  • live execution

  • Services available: PostgreSQL=false, S3=false

  • Platform: macos-aarch64

  • Toolchain: 1.4.2, v24.21.0, git version 2.54.0 (Apple Git-157)

Source details
  • Repository: github.com/margelo/react-native-quick-crypto
  • Commit: 0389db8edc49dad785f57ea6bb5f0526005dd028
  • Tree: 51e8b28a84cb52061eb4c22f33f9d4c696af4869
  • Base ref: main
  • Base tip: 57b83c60520ea0e673e64955cfc98852061d5115
  • Merge base: 57b83c60520ea0e673e64955cfc98852061d5115
Signed machine-readable evidence

The exact signed bytes are preserved below for verification and audit tooling.

eyJ2ZXJzaW9uIjoxLCJhbGdvcml0aG0iOiJlZDI1NTE5IiwicGF5bG9hZCI6eyJ2ZXJzaW9uIjox
LCJyZXF1aXJlbWVudF9pZCI6ImxvY2FsLXZhbGlkYXRpb24iLCJjaGVja19raW5kIjoiY29tbWFu
ZC92MSIsInN1YmplY3QiOnsicmVwb3NpdG9yeSI6ImdpdGh1Yi5jb20vbWFyZ2Vsby9yZWFjdC1u
YXRpdmUtcXVpY2stY3J5cHRvIiwiY2hhbmdlIjp7InJlcG9zaXRvcnkiOiJnaXRodWIuY29tL21h
cmdlbG8vcmVhY3QtbmF0aXZlLXF1aWNrLWNyeXB0byIsImlkIjoiZ2l0LWNvbW1pdDowMzg5ZGI4
ZWRjNDlkYWQ3ODVmNTdlYTZiYjVmMDUyNjAwNWRkMDI4In0sImNoYW5nZV92ZXJzaW9uIjoxLCJj
b250ZXh0X2RpZ2VzdCI6ImVhYTBhOTA1NjEwNjFmMTdmZmM4YmQ1Yzg1ZTc3ZjkxZGNmNWViMWRm
M2JjYzhjMDhjOGJlMmNjMDVi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yNTRmNTdiZGMxZWUz
ZWY2YzZiNzFlMTNkMjlkNWQ0Y2JlNmMiLCJzdGRlcnJfc2hhMjU2IjoiYmU2MDMxYjA2NTNlNTYw
MjU0NWY2OTk5NjNhMzI5OGQ5MzYxNjllZDY4Y2YzOThlMWYxZTFhZDYyOTRmNTg2NSIsInRydW5j
YXRlZCI6ZmFsc2V9XSwic2VydmljZXMiOnsicG9zdGdyZXMiOmZhbHNlLCJzMyI6ZmFsc2V9LCJw
bGF0Zm9ybSI6Im1hY29zLWFhcmNoNjQiLCJ0b29sY2hhaW4iOlsiMS40LjIiLCJ2MjQuMjEuMCIs
ImdpdCB2ZXJzaW9uIDIuNTQuMCAoQXBwbGUgR2l0LTE1NykiXSwidHJlZV91bmNoYW5nZWRfYWZ0
ZXIiOnRydWV9

@boorad

boorad commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Local device E2E evidence

  • Head: 0389db8edc49dad785f57ea6bb5f0526005dd028
  • AgentSCM attestation: 55a1c6952c1ac1658a3c2f6ca08736e51924ec6f492a1551bc2dff36a70ccdf0
  • iOS result SHA-256: aee68f9049766fa2bbb9b7dfc19a041b098e5ac31735c55043b13a33a198c6ae
  • iOS screenshot SHA-256: 11d0d8e385d1800ec286d5c39514b44213e4c35fd66183ff7e198af3d29e7c1d
  • Android result SHA-256: 48af9c54fb5835b0544d29e998f42208fb74f4b8db49b665e98911797c473a6d
  • Android screenshot SHA-256: 12d477a35c7e737231f1e0f005c41485d91b6f5cdc01341c36f3d2c49963fdc9
Platform Final screenshot
iOS iOS local E2E result
Android Android local E2E result

The hashes above are present in command stdout committed by the signed attestation. Images expire after 30 days; the hashes remain the durable binding.

@boorad
boorad marked this pull request as ready for review November 15, 2026 13:09
@boorad
boorad merged commit 0c3d92d into margelo:main Nov 15, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — 0389db8e Deployed Nov 15, 2026 by vercel[bot]
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.

2 participants