Files
corona/threshold/fuzz_verify_test.go
T
Antje Worring dc15c54a47 harden: hedged 256-bit nonce key, DRY CT comparator, honest CT/proof docs
Closes the CRIT-1 residual (D1-2) sid-entropy gap and the CT/doc hygiene
gaps to bring Corona to the no-leak/no-gap bar. EasyCrypt proofs untouched.

PRIORITY 1 — anti-nonce-reuse / no-leak durability:
- The Round-1 nonce-PRF key no longer keys on a bare 64-bit sid. It now
  derives from a 256-bit domain-separated SessionID (primitives.DeriveSessionID:
  TranscriptHash("corona.sign.session-id.v1" || be64(sid) || T)) AND a fresh
  per-signature 256-bit hedge salt drawn inside the kernel from party.Rand
  (default crypto/rand). PRNGKeyForRound = PRF(skShare, "CoronaNonceV3" ||
  sessionID || salt). Hedging restores threshold-Raccoon's fresh-per-signature
  nonce posture: reuse durability no longer rests on the external consensus
  layer never reissuing an sid — even an sid collision yields distinct R with
  prob 2^-256. A deterministic 256-bit SessionID alone is necessary but NOT
  sufficient (it repeats when sid repeats); the salt is what closes the leak.
- SignRound1 is fail-closed: rejects an all-zero derived SessionID or all-zero
  salt with ErrDegenerateSession, and surfaces a short-read error. The
  consensus slot-uniqueness invariant is documented as a HARD precondition at
  SignRound1 and Signer.Round1 (no longer a buried comment).
- KAT/oracle determinism preserved via one seam: sign.DeterministicNonceSource
  (KeyedPRNG over seed || "corona.sign.nonce-salt.v1" || partyIndex), set on
  Party.Rand / Signer.SetNonceRand only by reproducibility harnesses.
- SignRound1 / Signer.Round1 now return an error; all call sites updated.
- KAT REGEN: only sign_verify_e2e.json changes (nonce-key bytes moved);
  transcript_hash.json / MAC / legacy PRNGKey vectors are byte-stable, proving
  the consensus-agreed transcript path was left untouched. Regenerated via
  `bash scripts/regen-kats.sh`; `--verify` confirms byte-determinism (10 files).
- Regression: sign/nonce_reuse_test.go proves same-(skShare,sid) yields distinct
  D (fresh R), pinned-nonce reproduces byte-identically, and the degenerate-
  session guard fires. TestE2EKATReplayDeterminism rewritten to assert both the
  hedged-differs and pinned-reproduces properties (was a defanged no-op).

PRIORITY 2 — constant-time hygiene:
- reshare/commit.go already used a constant-time comparator; the real gap was
  the verbatim duplication of constTimePolyEqual+uint64SliceToBytes across dkg2
  and reshare. Consolidated to one canonical utils.ConstantTimePolyEqual; both
  delegate (no dkg2<->reshare dependency). Orphaned imports removed.
- FullRankCheck and the reshare commit path are now covered in the CT review
  with their public-operand justification.

PRIORITY 3 — doc accuracy:
- CONSTANT-TIME-REVIEW.md rewritten Corona-specific and file:line-accurate:
  drops the stale Pulsar/lens/warp/secp256k1 content; audits the real call
  sites (hedged nonce key, masking PRF, lattigo samplers as the residual TCB
  axiom, utils.ConstantTimePolyEqual, CheckL2Norm/Verify/FullRankCheck big.Int
  variable-time on PUBLIC operands, activation/commit-digest array equality,
  keyera/reshare zeroization).
- PROOF-CLAIMS.md §1: threshold.Combine / sign.LocalSign (nonexistent) -> the
  real sign.Party.SignFinalize exposed as threshold.Signer.Finalize.
- threshold/threshold.go package doc: Ring-LWE -> Module-LWE.
2026-06-21 08:21:58 -07:00

116 lines
3.2 KiB
Go

// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package threshold
import (
"bytes"
"crypto/rand"
"encoding/gob"
"testing"
)
// FuzzVerifyParseSignature exercises Corona threshold.Verify on
// attacker-supplied (gob-encoded) signature bytes. Verify holds no
// long-term secret state, so this is the input-handling fuzz target:
// any panic / data-race / out-of-bounds in the parser is a finding.
//
// The corpus seeds are derived from a fresh honest signature. Mutated
// bytes are very unlikely to verify; the test only asserts NO PANIC,
// not Verify(...) = true.
func FuzzVerifyParseSignature(f *testing.F) {
// Seed corpus: one fresh valid signature.
shares, gk, err := GenerateKeys(2, 3, rand.Reader)
if err != nil {
f.Fatalf("GenerateKeys: %v", err)
}
signers := make([]*Signer, 3)
for i, share := range shares {
signers[i] = NewSigner(share)
}
signerIDs := []int{0, 1, 2}
const sid = 1
prfKey := make([]byte, 32)
if _, err := rand.Read(prfKey); err != nil {
f.Fatal(err)
}
message := "fuzz verify seed message"
r1 := make(map[int]*Round1Data)
for _, s := range signers {
d, err := s.Round1(sid, prfKey, signerIDs)
if err != nil {
f.Fatal(err)
}
r1[d.PartyID] = d
}
r2 := make(map[int]*Round2Data)
for _, s := range signers {
d, err := s.Round2(sid, message, prfKey, signerIDs, r1)
if err != nil {
f.Fatal(err)
}
r2[d.PartyID] = d
}
sig, err := signers[0].Finalize(r2)
if err != nil {
f.Fatal(err)
}
var buf bytes.Buffer
if err := gob.NewEncoder(&buf).Encode(sig); err != nil {
f.Fatal(err)
}
f.Add(buf.Bytes())
// Also seed a known-invalid empty input.
f.Add([]byte{})
f.Fuzz(func(t *testing.T, data []byte) {
// Decode; any panic in the parser is a finding.
defer func() {
if r := recover(); r != nil {
t.Fatalf("Verify parse panic on %d bytes: %v", len(data), r)
}
}()
var sig Signature
if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&sig); err != nil {
// Decode failure is fine -- the parser rejected malformed
// input.
return
}
// Verify on the decoded signature must not panic regardless of
// whether it accepts or rejects.
_ = Verify(gk, message, &sig)
})
}
// FuzzVerifyRandomBytes is the simpler raw-bytes input fuzz: random
// bytes treated directly as a Corona signature wire encoding.
//
// Together with FuzzVerifyParseSignature, this exercises BOTH the
// structural (gob) and the byte-level interpretation paths.
func FuzzVerifyRandomBytes(f *testing.F) {
_, gk, err := GenerateKeys(2, 3, rand.Reader)
if err != nil {
f.Fatalf("GenerateKeys: %v", err)
}
f.Add([]byte{0, 0, 0, 0})
f.Add([]byte{0xff, 0xff, 0xff, 0xff})
f.Add(make([]byte, 32))
f.Add(make([]byte, 256))
f.Fuzz(func(t *testing.T, data []byte) {
defer func() {
if r := recover(); r != nil {
t.Fatalf("decode panic on %d bytes: %v", len(data), r)
}
}()
var sig Signature
_ = gob.NewDecoder(bytes.NewReader(data)).Decode(&sig)
// We do NOT verify here -- random bytes may decode partially
// and the verify pipeline expects more structure than the gob
// parser enforces. The property under test is that the parser
// does not panic.
_ = gk
})
}