Files
zeekay b50de9cebd luxfi/tee: optional TEE-backed threshold custody extension
Extracted verbatim from luxfi/threshold/protocols/{mldsa,rlwe,slhdsa}-tee
to decomplect optional TEE custody from the threshold core. The cores
(pulsar/corona/magnetar/mpc) never depend on this module; the dependency
points tee -> core only. The permissionless dealerless signing path in
luxfi/threshold has zero dependency on TEE.

Packages:
  mldsa-tee   ML-DSA-65 (FIPS 204) TEE custody signer
  rlwe-tee    Corona Ring-LWE TEE custody signer
  slhdsa-tee  SLH-DSA (FIPS 205) TEE custody signer + t-of-n CombinerPool

Full end-to-end attestation suites (committed AMD Milan SEV-SNP vectors,
HSM release-gate, byte-identity with FIPS reference) moved with the
packages and pass: go build/vet/test ./... all green.
2026-06-27 11:19:11 -07:00

83 lines
2.3 KiB
Go

// SPDX-License-Identifier: BSD-3-Clause
package rlwetee
import (
"context"
"crypto/sha256"
"crypto/subtle"
"errors"
"fmt"
"github.com/luxfi/mpc/cc/attest"
"github.com/luxfi/mpc/pkg/kms"
)
// Envelope is the minimal kms.CompositeAttestation implementation
// consumed by this package. Mirrors slhdsa-tee.Envelope so embedders
// that compose multiple primitives share the same plumbing.
type Envelope struct {
Kind attest.Kind
EvidenceBytes []byte
ExpectedNonce [32]byte
RIM [32]byte
Hardware [32]byte
TEEPub [32]byte
VerifyOpts []attest.Option
}
var _ kms.CompositeAttestation = (*Envelope)(nil)
// Verify implements kms.CompositeAttestation.Verify.
func (e *Envelope) Verify(expectedNonce [32]byte) (bool, error) {
if subtle.ConstantTimeCompare(e.ExpectedNonce[:], expectedNonce[:]) != 1 {
return false, nil
}
return true, nil
}
// VerifyEvidence implements kms.CompositeAttestation.VerifyEvidence.
func (e *Envelope) VerifyEvidence(ctx context.Context, opts ...attest.Option) ([]*attest.VerifiedReport, error) {
if len(e.EvidenceBytes) == 0 {
return nil, fmt.Errorf("%w: empty evidence", attest.ErrInvalidEvidence)
}
allOpts := append([]attest.Option{}, e.VerifyOpts...)
allOpts = append(allOpts, opts...)
rep, err := attest.Dispatch(ctx, e.Kind, e.EvidenceBytes, allOpts...)
if err != nil {
return nil, err
}
if err := defaultRIMCheck(rep, e.RIM); err != nil {
return nil, err
}
return []*attest.VerifiedReport{rep}, nil
}
func (e *Envelope) RIMDigest() [32]byte { return e.RIM }
func (e *Envelope) HardwareFingerprint() [32]byte { return e.Hardware }
func (e *Envelope) TEEPublicKey() [32]byte { return e.TEEPub }
func (e *Envelope) EvidenceIssuers() []string {
switch e.Kind {
case attest.KindSEVSNP:
return []string{kms.IssuerSEVSNP}
case attest.KindTDX:
return []string{kms.IssuerTDX}
case attest.KindNRAS:
return []string{kms.IssuerNVNRAS}
default:
return nil
}
}
func defaultRIMCheck(rep *attest.VerifiedReport, expected [32]byte) error {
if rep == nil {
return errors.New("rlwe-tee: defaultRIMCheck: nil verified report")
}
got := sha256.Sum256(rep.Measurement)
if subtle.ConstantTimeCompare(got[:], expected[:]) != 1 {
return fmt.Errorf("%w: report measurement does not fold to operator-asserted RIM", attest.ErrPolicy)
}
return nil
}