Merge pull request #52 from safing/fix/make-second-os-rng-feed-async

Make second OS rng feed async
This commit is contained in:
Patrick Pacher 2020-05-29 14:46:01 +02:00 committed by GitHub
commit 03eaf58e69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package rng
import (
"context"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
@ -49,14 +50,22 @@ func start() error {
return errors.New("failed to initialize rng")
}
// explicitly add randomness
// add another (async) OS rng seed
module.StartWorker("initial rng feed", func(_ context.Context) error {
// get entropy from OS
osEntropy := make([]byte, minFeedEntropy/8)
_, err := rand.Read(osEntropy)
if err != nil {
return fmt.Errorf("could not read entropy from os: %s", err)
}
// feed
rngLock.Lock()
rng.Reseed(osEntropy)
rngLock.Unlock()
return nil
})
// mark as ready
rngReady = true
// random source: OS