Add Nix flake for mciasctl and mciasgrpcctl

Vendor dependencies and expose control program binaries via
nix build. Uses nixpkgs-unstable for Go 1.26 support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 21:01:21 -07:00
parent 35e96444aa
commit 115f23a3ea
2485 changed files with 6802335 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package tpm2
import (
"io"
)
var (
labelIdentity = "IDENTITY"
)
// CreateCredential creates an encrypted secret that can be recovered using ActivateCredential as part of a key-attestation flow.
func CreateCredential(rand io.Reader, pub LabeledEncapsulationKey, name []byte, credentialValue []byte) (idObject []byte, encSecret []byte, err error) {
secret, ciphertext, err := pub.Encapsulate(rand, labelIdentity)
if err != nil {
return nil, nil, err
}
// Marshal the credentialValue as a TPM2B_DIGEST before encrypting it.
// See Part 1, "Credential Protection", and Part 2, "TPMS_ID_OBJECT".
credential2B := Marshal(TPM2BDigest{Buffer: credentialValue})
// Encrypt the credentialValue as encIdentity.
encIdentity, err := deriveAndEncrypt(pub, secret, name, credential2B)
if err != nil {
return nil, nil, err
}
// Compute the HMAC of (encIdentity || name)
identityHMAC, err := deriveAndHMAC(pub, secret, nil, encIdentity, name)
if err != nil {
return nil, nil, err
}
// Marshal the virtual TPMS_ID_OBJECT ourselves. We have to do this since encIdentity's size is encrypted.
idObject = make([]byte, 0, 2+len(identityHMAC)+len(encIdentity))
idObject = append(idObject, Marshal(TPM2BDigest{Buffer: identityHMAC})...)
idObject = append(idObject, encIdentity...)
return idObject, ciphertext, nil
}