diff --git a/config.go b/config.go index 4af064f..55f3400 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,9 @@ package tpm import ( + "hash/fnv" "net/http" + "os" "github.com/google/go-attestation/attest" ) @@ -67,6 +69,27 @@ func WithCommandChannel(cc attest.CommandChannelTPM20) Option { } } +func hashit(s string) uint32 { + h := fnv.New32a() + h.Write([]byte(s)) + return h.Sum32() +} + +func tokenize() int64 { + hostname, err := os.Hostname() + if err != nil { + return 0 + } + return int64(hashit(hostname)) +} + +var EmulatedHostSeed = func() Option { + return func(c *config) error { + c.seed = tokenize() + return nil + } +} + func (c *config) apply(opts ...Option) error { for _, o := range opts { if err := o(c); err != nil {