feat: add go tpm rand
This commit is contained in:
7
go-tpm-rand/go.mod
Normal file
7
go-tpm-rand/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module git.hatter.ink/go-tpm-rand
|
||||
|
||||
go 1.24.3
|
||||
|
||||
require github.com/google/go-tpm v0.9.5
|
||||
|
||||
require golang.org/x/sys v0.8.0 // indirect
|
||||
4
go-tpm-rand/go.sum
Normal file
4
go-tpm-rand/go.sum
Normal file
@@ -0,0 +1,4 @@
|
||||
github.com/google/go-tpm v0.9.5 h1:ocUmnDebX54dnW+MQWGQRbdaAcJELsa6PqZhJ48KwVU=
|
||||
github.com/google/go-tpm v0.9.5/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
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