Files
Hanzo AI a2c1d1da31 corona: symmetric domain separation — PULSAR-* tags -> CORONA-*
Leftover from Corona's "Pulsar-R" lineage. Pulsar (M-LWE) and Corona
(R-LWE) are independent constructions with separate hardness assumptions,
so their cSHAKE personalisation strings must be distinct.

Changes (Go, non-luxcpp):
  - hash tags: PULSAR-HC-v1 -> CORONA-HC-v1, etc. (HU, TRANSCRIPT, PRF, MAC, PAIRWISE)
  - profile IDs: "Pulsar-SHA3" -> "Corona-SHA3", "Pulsar-BLAKE3" -> "Corona-BLAKE3"
  - context strings: pulsar.dkg2.A.v1 -> corona.dkg2.A.v1, etc.
  - env vars: PULSAR_RESHARE_KAT_PATH -> CORONA_RESHARE_KAT_PATH, etc.
  - struct names: pulsarSHA3 -> coronaSHA3
  - KAT derive roots: sign_e2e_pulsar -> sign_e2e_corona

What's preserved (different scope):
  - luxcpp/crypto/pulsar/* path references in comments (separate repo,
    out of scope; the C++ side will rename in its own commit)
  - Cross-runtime KAT files on disk (will regenerate next CI run)

All 11 packages test green: dkg, dkg2, hash, keyera, networking,
primitives, reshare, sign, threshold, utils, wire.
2026-05-13 14:19:13 -07:00

128 lines
3.2 KiB
Go

// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package hash
// CoronaBLAKE3 is a NON-NORMATIVE legacy suite kept for byte-equality
// checks against transcripts produced before the Corona-SHA3 profile
// was pinned as canonical. NEW deployments MUST use Corona-SHA3.
import (
"encoding/binary"
"github.com/zeebo/blake3"
)
// coronaBLAKE3 implements HashSuite using BLAKE3 primitives.
type coronaBLAKE3 struct{}
// NewCoronaBLAKE3 returns the legacy BLAKE3 suite. NOT for production.
func NewCoronaBLAKE3() HashSuite { return coronaBLAKE3{} }
func (coronaBLAKE3) ID() string { return "Corona-BLAKE3" }
func (coronaBLAKE3) Hc(transcript []byte) []byte {
h := blake3.New()
_, _ = h.Write([]byte(tagHC))
_, _ = h.Write(transcript)
return h.Sum(nil)[:32]
}
func (coronaBLAKE3) Hu(transcript []byte, outLen int) []byte {
h := blake3.New()
_, _ = h.Write([]byte(tagHU))
_, _ = h.Write(transcript)
out := make([]byte, outLen)
_, _ = h.Digest().Read(out)
return out
}
func (coronaBLAKE3) TranscriptHash(parts ...[]byte) [32]byte {
h := blake3.New()
_, _ = h.Write([]byte(tagTranscript))
for _, p := range parts {
var lenBuf [4]byte
binary.BigEndian.PutUint32(lenBuf[:], uint32(len(p)))
_, _ = h.Write(lenBuf[:])
_, _ = h.Write(p)
}
var out [32]byte
copy(out[:], h.Sum(nil)[:32])
return out
}
func (coronaBLAKE3) PRF(key, msg []byte, outLen int) []byte {
keyArr := blake3SizedKey(key)
h, _ := blake3.NewKeyed(keyArr[:])
_, _ = h.Write([]byte(tagPRF))
_, _ = h.Write(msg)
out := make([]byte, outLen)
_, _ = h.Digest().Read(out)
return out
}
func (coronaBLAKE3) MAC(key, msg []byte, outLen int) []byte {
keyArr := blake3SizedKey(key)
h, _ := blake3.NewKeyed(keyArr[:])
_, _ = h.Write([]byte(tagMAC))
_, _ = h.Write(msg)
out := make([]byte, outLen)
_, _ = h.Digest().Read(out)
return out
}
func (coronaBLAKE3) DerivePairwise(
kex []byte,
chainID, groupID []byte,
eraID, generation uint64,
i, j int,
outLen int,
) []byte {
a, b := i, j
if a > b {
a, b = b, a
}
keyArr := blake3SizedKey(kex)
h, _ := blake3.NewKeyed(keyArr[:])
_, _ = h.Write([]byte(tagPairwise))
writeLen(h, chainID)
writeLen(h, groupID)
var u8 [8]byte
binary.BigEndian.PutUint64(u8[:], eraID)
_, _ = h.Write(u8[:])
binary.BigEndian.PutUint64(u8[:], generation)
_, _ = h.Write(u8[:])
var u4 [4]byte
binary.BigEndian.PutUint32(u4[:], uint32(a))
_, _ = h.Write(u4[:])
binary.BigEndian.PutUint32(u4[:], uint32(b))
_, _ = h.Write(u4[:])
out := make([]byte, outLen)
_, _ = h.Digest().Read(out)
return out
}
// blake3SizedKey compresses an arbitrary keying material into the
// 32-byte key BLAKE3.NewKeyed requires.
func blake3SizedKey(kex []byte) [32]byte {
if len(kex) == 32 {
var out [32]byte
copy(out[:], kex)
return out
}
h := blake3.New()
_, _ = h.Write([]byte("CORONA-KDF-KEY-v1"))
_, _ = h.Write(kex)
var out [32]byte
copy(out[:], h.Sum(nil)[:32])
return out
}
// writeLen writes a length-prefixed byte slice to the hash writer.
func writeLen(h interface{ Write(p []byte) (int, error) }, data []byte) {
var lenBuf [4]byte
binary.BigEndian.PutUint32(lenBuf[:], uint32(len(data)))
_, _ = h.Write(lenBuf[:])
_, _ = h.Write(data)
}