feat: add go tpm rand
This commit is contained in:
24
go-tpm-rand/main.go
Normal file
24
go-tpm-rand/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/google/go-tpm/legacy/tpm2"
|
||||
)
|
||||
|
||||
// reference: https://ericchiang.github.io/post/tpm-keys/
|
||||
func main() {
|
||||
f, err := os.OpenFile("/dev/tpmrm0", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
log.Fatalf("opening tpm: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
out, err := tpm2.GetRandom(f, 16)
|
||||
if err != nil {
|
||||
log.Fatalf("getting random bytes: %v", err)
|
||||
}
|
||||
fmt.Printf("%x\n", out)
|
||||
}
|
||||
Reference in New Issue
Block a user