| 1 |
package tpm2 |
| 2 |
|
| 3 |
import ( |
| 4 |
"errors" |
| 5 |
"fmt" |
| 6 |
"io" |
| 7 |
) |
| 8 |
|
| 9 |
var ( |
| 10 |
ErrUnsupportedType = errors.New("unsupported key type") |
| 11 |
) |
| 12 |
|
| 13 |
// An LabeledEncapsulationKey represents a public key used in a TPM labeled-encapsulation scheme. |
| 14 |
type LabeledEncapsulationKey interface { |
| 15 |
// Encapsulate performs the labeled key encapsulation. |
| 16 |
Encapsulate(random io.Reader, label string) (secret []byte, ciphertext []byte, err error) |
| 17 |
// NameAlg fetches the Name hash algorithm of the encapsulation key. |
| 18 |
NameAlg() TPMAlgID |
| 19 |
// SymmetricParameters fetches the symmetric parameters for protection. |
| 20 |
SymmetricParameters() *TPMTSymDefObject |
| 21 |
} |
| 22 |
|
| 23 |
// ImportEncapsulationKey imports the TPM-form public key as a LabeledEncapsulationkey. |
| 24 |
func ImportEncapsulationKey(pub *TPMTPublic) (LabeledEncapsulationKey, error) { |
| 25 |
switch pub.Type { |
| 26 |
case TPMAlgRSA: |
| 27 |
return importRSAEncapsulationKey(pub) |
| 28 |
case TPMAlgECC: |
| 29 |
return importECCEncapsulationKey(pub) |
| 30 |
default: |
| 31 |
return nil, fmt.Errorf("%w %v", ErrUnsupportedType, pub.Type) |
| 32 |
} |
| 33 |
} |