Is/1481 improve randomness and ecdsa signatures - #532
Open
PropzSaladaz wants to merge 6 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens SGX enclave ECDSA signing by fixing the enclave RNG concurrency design, correcting ECDSA nonce generation to the proper scalar domain, and tightening signing/verification edge-case handling to reduce the risk of nonce reuse and invalid-signature acceptance.
Changes:
- Replace the previous global seed+counter SHA256 PRG with direct
sgx_read_randusage (plus init-time RNG self-test) to avoid concurrency-driven repetition. - Update ECDSA signing to generate nonce
kuniformly in[1, n-1]via rejection sampling, and add retries for non-invertiblekands == 0. - Fix ECDSA verification range checking (
r/s) and add an integration test that stresses concurrent key generation distinctness.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/integration/keys/ECDSAIntegrationTests.cpp | Adds a parallel keygen “distinctness under contention” integration test. |
| secure_enclave/Signature.c | Hardens ECDSA nonce selection and signing retry logic; fixes verifier range check logic. |
| secure_enclave/secure_enclave.c | Switches RNG to direct sgx_read_rand, adds RNG self-test at init, removes old global PRG state. |
| secure_enclave/EnclaveCommon.h | Removes the exported globalRandom declaration consistent with RNG refactor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PropzSaladaz
force-pushed
the
IS/1481-improve-randomness-and-ecdsa-signatures
branch
from
July 24, 2026 15:27
869ac0d to
562ede5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve enclave randomness and harden ECDSA signing
Summary
Fixes a concurrency flaw in the enclave RNG that could cause ECDSA nonce reuse, corrects the nonce scalar domain, and hardens signing/verification edge cases. All changes are on the nonce-generation and internal-validation paths; signature output remains standard secp256k1 ECDSA.
Changes
RNG — fix concurrency race
get_global_randomnow reads directly from the hardware DRNG (sgx_read_rand) on every call, and fails closed (aborts) on any RNG error.SHA256(seed ‖ counter)PRG whose counter used a non-atomic read-modify-write. Under the enclave's multi-TCS threading, two concurrent callers could observe the same counter and derive identical randomness → reused ECDSA nonces.ECDSA nonce — correct scalar domain
kis now reduced against the group ordern(was the field primep) using rejection sampling to a uniform value in[1, n-1], eliminating modulo bias and the zero-nonce case.ECDSA signing — robustness
k(mpz_invertreturn now checked) and ons == 0, alongside the existingr == 0retry.ECDSA verification — stricter input validation
r/srange check insignature_verify(&&→||), which was previously a no-op, so out-of-range values are now correctly rejected.Tests
Backward compatibility