Files
rns/did_test.go
zeekay 366c1d87a4 feat(rns): canonical DID computation + cross-language KAT fixture
Adds the minimum-viable PQ-RNS conformance test:

- did.go: ComputeDID(kemPubKey, sigPubKey) — base32 lowercase no-padding
  of SHA3-256(kemPubKey || sigPubKey), prefixed "did⚡"
- did_test.go: Go test that reads testdata/pqrns_kat.json and verifies
  the implementation reproduces the canonical DID
- testdata/pqrns_kat.json: language-neutral fixture — fixed input keys
  (1216 bytes of 0x01 for KEM, 1984 bytes of 0x02 for sig) → fixed
  SHA3-256 (72bea585...) and DID (did:zap:ok7klbkh...)

Every language SDK that implements PQ-RNS MUST reproduce the same DID
for the same inputs. The KAT catches any divergence on the hash, byte
order, base32 alphabet, or casing.

go test ./... passes locally.
2026-05-27 04:47:35 -07:00

57 lines
1.5 KiB
Go

package rns
import (
"encoding/hex"
"encoding/json"
"os"
"testing"
)
// TestDIDKAT verifies ComputeDID against the canonical KAT in
// testdata/pqrns_kat.json. Every language SDK that ships a PQ-RNS
// implementation MUST pass this same fixture; a divergence on the
// hash, byte order, base32 alphabet, or casing fails the test.
func TestDIDKAT(t *testing.T) {
raw, err := os.ReadFile("testdata/pqrns_kat.json")
if err != nil {
t.Fatalf("read KAT fixture: %v", err)
}
var kat struct {
DIDCanonical struct {
Inputs struct {
KEMHex string `json:"kem_pubkey_hex"`
SigHex string `json:"sig_pubkey_hex"`
} `json:"inputs"`
Outputs struct {
Sha3Hex string `json:"sha3_256_hex"`
DID string `json:"did"`
} `json:"outputs"`
} `json:"did_canonical"`
}
if err := json.Unmarshal(raw, &kat); err != nil {
t.Fatalf("parse KAT: %v", err)
}
kemPK, err := hex.DecodeString(kat.DIDCanonical.Inputs.KEMHex)
if err != nil {
t.Fatalf("decode kem hex: %v", err)
}
sigPK, err := hex.DecodeString(kat.DIDCanonical.Inputs.SigHex)
if err != nil {
t.Fatalf("decode sig hex: %v", err)
}
if want, got := 1216, len(kemPK); got != want {
t.Fatalf("kem pk size: got %d, want %d", got, want)
}
if want, got := 1984, len(sigPK); got != want {
t.Fatalf("sig pk size: got %d, want %d", got, want)
}
got := ComputeDID(kemPK, sigPK)
if got != kat.DIDCanonical.Outputs.DID {
t.Fatalf("DID diverged:\n got %s\n want %s", got, kat.DIDCanonical.Outputs.DID)
}
}