github.com/insomniacslk/u-root@v0.0.0-20200717035308-96b791510d76/pkg/tss/constants.go (about) 1 // Copyright 2020 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package tss 6 7 import ( 8 "crypto" 9 "fmt" 10 11 "github.com/google/go-tpm/tpm2" 12 ) 13 14 // TPMVersion is used to configure a preference in 15 // which TPM to use, if multiple are available. 16 type TPMVersion uint8 17 18 // TPM versions 19 const ( 20 TPMVersionAgnostic TPMVersion = iota 21 TPMVersion12 22 TPMVersion20 23 ) 24 25 const ( 26 nvPerOwnerRead = 0x00100000 27 nvPerAuthRead = 0x00200000 28 ) 29 30 // TPMInterface indicates how the client communicates 31 // with the TPM. 32 type TPMInterface uint8 33 34 // TPM interfaces 35 const ( 36 TPMInterfaceDirect TPMInterface = iota 37 TPMInterfaceKernelManaged 38 TPMInterfaceDaemonManaged 39 ) 40 41 // HashAlg is the TPM hash algorithm id 42 type HashAlg uint8 43 44 var ( 45 // HashSHA1 is the TPM 1.2 identifier for SHA1 46 HashSHA1 = HashAlg(tpm2.AlgSHA1) 47 // HashSHA256 is the TPM 2.0 identifier for SHA256 48 HashSHA256 = HashAlg(tpm2.AlgSHA256) 49 ) 50 51 func (a HashAlg) cryptoHash() crypto.Hash { 52 switch a { 53 case HashSHA1: 54 return crypto.SHA1 55 case HashSHA256: 56 return crypto.SHA256 57 } 58 return 0 59 } 60 61 func (a HashAlg) GoTPMAlg() tpm2.Algorithm { 62 switch a { 63 case HashSHA1: 64 return tpm2.AlgSHA1 65 case HashSHA256: 66 return tpm2.AlgSHA256 67 } 68 return 0 69 } 70 71 // String returns a human-friendly representation of the hash algorithm. 72 func (a HashAlg) String() string { 73 switch a { 74 case HashSHA1: 75 return "SHA1" 76 case HashSHA256: 77 return "SHA256" 78 } 79 return fmt.Sprintf("HashAlg<%d>", int(a)) 80 }