Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make second OS rng feed async #52

Merged
merged 1 commit into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions rng/rng.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rng

import (
"context"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
Expand Down Expand Up @@ -49,14 +50,22 @@ func start() error {
return errors.New("failed to initialize rng")
}

// explicitly add randomness
osEntropy := make([]byte, minFeedEntropy/8)
_, err := rand.Read(osEntropy)
if err != nil {
return fmt.Errorf("could not read entropy from os: %s", err)
}
rng.Reseed(osEntropy)

// 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
Comment on lines +65 to 69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should that be moved into the worker and maybe replaced by an abool?


// random source: OS
Expand Down