File: labeled_kem_convert.go

package info (click to toggle)
golang-github-google-go-tpm 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: makefile: 13
file content (33 lines) | stat: -rw-r--r-- 988 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package tpm2

import (
	"errors"
	"fmt"
	"io"
)

var (
	ErrUnsupportedType = errors.New("unsupported key type")
)

// An LabeledEncapsulationKey represents a public key used in a TPM labeled-encapsulation scheme.
type LabeledEncapsulationKey interface {
	// Encapsulate performs the labeled key encapsulation.
	Encapsulate(random io.Reader, label string) (secret []byte, ciphertext []byte, err error)
	// NameAlg fetches the Name hash algorithm of the encapsulation key.
	NameAlg() TPMAlgID
	// SymmetricParameters fetches the symmetric parameters for protection.
	SymmetricParameters() *TPMTSymDefObject
}

// ImportEncapsulationKey imports the TPM-form public key as a LabeledEncapsulationkey.
func ImportEncapsulationKey(pub *TPMTPublic) (LabeledEncapsulationKey, error) {
	switch pub.Type {
	case TPMAlgRSA:
		return importRSAEncapsulationKey(pub)
	case TPMAlgECC:
		return importECCEncapsulationKey(pub)
	default:
		return nil, fmt.Errorf("%w %v", ErrUnsupportedType, pub.Type)
	}
}