mirror of
https://github.com/luxfi/tee.git
synced 2026-10-30 15:15:53 +00:00
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.
96 lines
3.0 KiB
Go
96 lines
3.0 KiB
Go
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package mldsatee
|
|
|
|
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 in shape so
|
|
// embedders that compose both primitives can 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.
|
|
//
|
|
// Dispatches the single evidence blob to cc/attest, returns the
|
|
// verified report on success, surfaces any chain / signature /
|
|
// policy failure verbatim. Additionally pins the operator-asserted
|
|
// RIM to sha256(measurement) of the verified report.
|
|
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
|
|
}
|
|
|
|
// RIMDigest implements kms.CompositeAttestation.RIMDigest.
|
|
func (e *Envelope) RIMDigest() [32]byte { return e.RIM }
|
|
|
|
// HardwareFingerprint implements kms.CompositeAttestation.HardwareFingerprint.
|
|
func (e *Envelope) HardwareFingerprint() [32]byte { return e.Hardware }
|
|
|
|
// TEEPublicKey implements kms.CompositeAttestation.TEEPublicKey.
|
|
func (e *Envelope) TEEPublicKey() [32]byte { return e.TEEPub }
|
|
|
|
// EvidenceIssuers implements kms.CompositeAttestation.EvidenceIssuers.
|
|
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
|
|
}
|
|
}
|
|
|
|
// defaultRIMCheck verifies the cc/attest verified-report Measurement
|
|
// matches the operator-asserted RIM digest under sha256-folding.
|
|
func defaultRIMCheck(rep *attest.VerifiedReport, expected [32]byte) error {
|
|
if rep == nil {
|
|
return errors.New("mldsa-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
|
|
}
|