mirror of
https://github.com/luxfi/corona.git
synced 2026-07-27 02:50:34 +00:00
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.
183 lines
4.8 KiB
Go
183 lines
4.8 KiB
Go
// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
//go:build corona_combine_ct
|
|
|
|
// combine_ct.go -- cgo bridge exposing corona threshold Signer.Finalize
|
|
// (Combine) to the C dudect harness in dudect_combine.c.
|
|
//
|
|
// CT-population framing for Combine:
|
|
//
|
|
// Combine has NO secret inputs in the Boschini construction:
|
|
// - z_i shares are broadcast Round-2 messages (public on the wire).
|
|
// - The group public key (A, bTilde) is public.
|
|
// - The challenge c is public.
|
|
// - The transcript_hash mu is public.
|
|
//
|
|
// The Combine routine is trivially CT under the BGL leakage model
|
|
// (no secret inputs => no secret-dependent leakage).
|
|
//
|
|
// Dudect on Combine is therefore a SANITY CHECK on the Combine
|
|
// pipeline's lack of timing artifacts as a function of which valid
|
|
// z-share TUPLE is supplied. Class A draws a fixed valid z-tuple
|
|
// (the dudect Welch's t-test class-A constancy requirement); class
|
|
// B draws a uniformly-sampled valid z-tuple from the pool.
|
|
|
|
package main
|
|
|
|
/*
|
|
#cgo arm64 CFLAGS: -include ${SRCDIR}/dudect_compat.h
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"encoding/gob"
|
|
"unsafe"
|
|
|
|
"github.com/luxfi/corona/threshold"
|
|
)
|
|
|
|
const kCombinePool = 64
|
|
|
|
type combineFixture struct {
|
|
groupKey *threshold.GroupKey
|
|
message string
|
|
signer0 *threshold.Signer
|
|
r2Data map[int]*threshold.Round2Data
|
|
}
|
|
|
|
var (
|
|
combineFixtures [kCombinePool]*combineFixture
|
|
combinePoolBytes [kCombinePool][]byte
|
|
combineChunkBytes int
|
|
)
|
|
|
|
// makeCombineFixture sets up a 2-of-3 ceremony and returns a fully
|
|
// populated R2 data map ready for Finalize.
|
|
func makeCombineFixture(msg string) (*combineFixture, error) {
|
|
const t, n = 2, 3
|
|
shares, gk, err := threshold.GenerateKeys(t, n, rand.Reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
signers := []int{0, 1, 2}
|
|
const sid = 1
|
|
prfKey := make([]byte, 32)
|
|
if _, err := rand.Read(prfKey); err != nil {
|
|
return nil, err
|
|
}
|
|
r1Data := make(map[int]*threshold.Round1Data)
|
|
for _, i := range signers {
|
|
s := threshold.NewSigner(shares[i])
|
|
d, err := s.Round1(sid, prfKey, signers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
r1Data[i] = d
|
|
}
|
|
r2Data := make(map[int]*threshold.Round2Data)
|
|
for _, i := range signers {
|
|
s := threshold.NewSigner(shares[i])
|
|
d, err := s.Round2(sid, msg, prfKey, signers, r1Data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
r2Data[i] = d
|
|
}
|
|
return &combineFixture{
|
|
groupKey: gk,
|
|
message: msg,
|
|
signer0: threshold.NewSigner(shares[0]),
|
|
r2Data: r2Data,
|
|
}, nil
|
|
}
|
|
|
|
// encodeCombineSample serializes the R2 data map (the variable input
|
|
// to Finalize). Sample width is the gob-encoded size.
|
|
func encodeCombineSample(f *combineFixture) ([]byte, error) {
|
|
var buf bytes.Buffer
|
|
enc := gob.NewEncoder(&buf)
|
|
if err := enc.Encode(f.r2Data); err != nil {
|
|
return nil, err
|
|
}
|
|
return buf.Bytes(), nil
|
|
}
|
|
|
|
func decodeCombineSample(data []byte) (map[int]*threshold.Round2Data, error) {
|
|
var r2Data map[int]*threshold.Round2Data
|
|
dec := gob.NewDecoder(bytes.NewReader(data))
|
|
if err := dec.Decode(&r2Data); err != nil {
|
|
return nil, err
|
|
}
|
|
return r2Data, nil
|
|
}
|
|
|
|
//export corona_combine_ct_setup
|
|
func corona_combine_ct_setup() C.int {
|
|
message := "dudect Combine sanity sample"
|
|
for i := 0; i < kCombinePool; i++ {
|
|
f, err := makeCombineFixture(message)
|
|
if err != nil {
|
|
return C.int(10 + i)
|
|
}
|
|
combineFixtures[i] = f
|
|
encoded, err := encodeCombineSample(f)
|
|
if err != nil {
|
|
return C.int(100 + i)
|
|
}
|
|
combinePoolBytes[i] = encoded
|
|
}
|
|
combineChunkBytes = len(combinePoolBytes[0])
|
|
for i := 1; i < kCombinePool; i++ {
|
|
if len(combinePoolBytes[i]) != combineChunkBytes {
|
|
return C.int(2)
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
//export corona_combine_ct_chunk_size
|
|
func corona_combine_ct_chunk_size() C.size_t {
|
|
return C.size_t(combineChunkBytes)
|
|
}
|
|
|
|
//export corona_combine_ct_pool_size
|
|
func corona_combine_ct_pool_size() C.size_t {
|
|
return C.size_t(kCombinePool)
|
|
}
|
|
|
|
//export corona_combine_ct_copy_pool
|
|
func corona_combine_ct_copy_pool(idx C.size_t, dst *C.uint8_t) C.int {
|
|
i := int(idx)
|
|
if i < 0 || i >= kCombinePool || combinePoolBytes[i] == nil {
|
|
return 1
|
|
}
|
|
dstSlice := unsafe.Slice((*byte)(unsafe.Pointer(dst)), combineChunkBytes)
|
|
copy(dstSlice, combinePoolBytes[i])
|
|
return 0
|
|
}
|
|
|
|
// One dudect measurement: decode the R2 data map and run Finalize.
|
|
// Combine has no secrets, so any timing artifact dudect detects is
|
|
// an unexpected content-dependent code path in the Finalize body.
|
|
//
|
|
//export corona_combine_ct
|
|
func corona_combine_ct(data *C.uint8_t) {
|
|
if combineFixtures[0] == nil {
|
|
return
|
|
}
|
|
dataSlice := unsafe.Slice((*byte)(unsafe.Pointer(data)), combineChunkBytes)
|
|
bytesCopy := append([]byte{}, dataSlice...)
|
|
r2Data, err := decodeCombineSample(bytesCopy)
|
|
if err != nil {
|
|
return
|
|
}
|
|
_, _ = combineFixtures[0].signer0.Finalize(r2Data)
|
|
}
|
|
|
|
func main() {}
|