コード例 #1
0
ファイル: server.go プロジェクト: postfix/fortunad
// Initialise the PRNG, TPM, and add initial entropy from host and TPM.
func setup() {
	log.Println("initialising PRNG and TPM")
	if _, err := os.Stat(seedFile); err == nil {
		log.Printf("seed file found; loading PRNG state from %s",
			seedFile)
		prng, err = fortuna.FromSeed(seedFile)
		if err != nil {
			log.Fatalf("%v", err)
		}
	} else {
		log.Println("no seed file found, initialising new PRNG")
		prng = fortuna.New()
	}
	tpmSource = fortuna.NewSourceWriter(prng, SourceTPM)
	devRandSource = fortuna.NewSourceWriter(prng, SourceDevRand)
	connTimeSource = fortuna.NewSourceWriter(prng, SourceConnTime)

	var err error
	tpmCtx, err = tpm.NewTPMContext()
	if err != nil {
		log.Fatalf("%v", err)
	}
	err = refillPRNG()
	if err != nil {
		log.Fatalf("%v", err)
	}
}
コード例 #2
0
ファイル: fortuna.go プロジェクト: postfix/entropyshare
// Initialise the PRNG, TPM, and add initial entropy from host and TPM.
func Start(seedFile string) {
	if seedFile == "" {
		log.Fatal("no seed file specified")
	}
	config.seedFile = seedFile
	config.shutdownChan = make(chan interface{}, 0)
	config.entropyChan = make(chan int64, 4)
	log.Println("initialising PRNG and TPM")
	if _, err := os.Stat(config.seedFile); err == nil {
		log.Printf("seed file found; loading PRNG state from %s",
			config.seedFile)
		config.prng, err = fortuna.FromSeed(config.seedFile)
		if err != nil {
			log.Fatalf("%v", err)
		}
	} else {
		log.Println("no seed file found, initialising new PRNG")
		config.prng = fortuna.New()
	}
	config.tpmSource = fortuna.NewSourceWriter(config.prng, SourceTPM)
	config.devRandSource = fortuna.NewSourceWriter(config.prng, SourceDevRand)
	config.connTimeSource = fortuna.NewSourceWriter(config.prng, SourceConnTime)
	var err error

	config.tpmCtx, err = tpm.NewTPMContext()
	if err != nil {
		log.Fatalf("%v", err)
	}
	err = refillPRNG()
	if err != nil {
		log.Fatalf("%v", err)
	}

	err = config.prng.WriteSeed(config.seedFile)
	if err != nil {
		log.Fatalf("%v", err)
	}

	go logAutoUpdate()
	go entropyCheck()
}