From ab05357b512d536c5008555ad68b2047968f41c3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 22 May 2019 16:10:27 +0200 Subject: [PATCH] Fix crypto config --- crypto/random/entropy.go | 2 +- crypto/random/fullfeed.go | 56 +++++++++++++++++++-------------------- crypto/random/get.go | 6 ++--- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/crypto/random/entropy.go b/crypto/random/entropy.go index ad6b9d9..c9b7754 100644 --- a/crypto/random/entropy.go +++ b/crypto/random/entropy.go @@ -24,7 +24,7 @@ func init() { DefaultValue: 256, ValidationRegex: "^[0-9]{3,5}$", }) - minFeedEntropy = config.GetAsInt("random/min_feed_entropy", 256) + minFeedEntropy = config.Concurrent.GetAsInt("random/min_feed_entropy", 256) } // The Feeder is used to feed entropy to the RNG. diff --git a/crypto/random/fullfeed.go b/crypto/random/fullfeed.go index 4ff4dcf..8a99ed6 100644 --- a/crypto/random/fullfeed.go +++ b/crypto/random/fullfeed.go @@ -1,49 +1,49 @@ package random import ( - "time" + "time" ) var ( - fullFeedDuration = 1 * time.Millisecond + fullFeedDuration = 100 * time.Millisecond ) func getFullFeedDuration() time.Duration { - // full feed every 5x time of reseedAfterSeconds - secsUntilFullFeed := reseedAfterSeconds() * 5 + // full feed every 5x time of reseedAfterSeconds + secsUntilFullFeed := reseedAfterSeconds() * 5 - // full feed at most once per minute - if secsUntilFullFeed < 60 { - secsUntilFullFeed = 60 - } + // full feed at most once per minute + if secsUntilFullFeed < 60 { + secsUntilFullFeed = 60 + } - return time.Duration(secsUntilFullFeed * int64(time.Second)) + return time.Duration(secsUntilFullFeed * int64(time.Second)) } func fullFeeder() { - for { + for { - select { - case <-time.After(fullFeedDuration): + select { + case <-time.After(fullFeedDuration): - rngLock.Lock() - feedAll: - for { - select { - case data := <-rngFeeder: - rng.Reseed(data) - default: - break feedAll - } - } - rngLock.Unlock() + rngLock.Lock() + feedAll: + for { + select { + case data := <-rngFeeder: + rng.Reseed(data) + default: + break feedAll + } + } + rngLock.Unlock() - case <-shutdownSignal: - return - } + case <-shutdownSignal: + return + } - fullFeedDuration = getFullFeedDuration() + fullFeedDuration = getFullFeedDuration() - } + } } diff --git a/crypto/random/get.go b/crypto/random/get.go index 0b8463f..0403c61 100644 --- a/crypto/random/get.go +++ b/crypto/random/get.go @@ -32,9 +32,9 @@ func init() { ExpertiseLevel: config.ExpertiseLevelDeveloper, OptType: config.OptTypeInt, DefaultValue: 360, // ten minutes - ValidationRegex: "^[0-9]{2,5}$", + ValidationRegex: "^[1-9][0-9]{1,5}$", }) - reseedAfterSeconds = config.GetAsInt("random/reseed_after_seconds", 360) + reseedAfterSeconds = config.Concurrent.GetAsInt("random/reseed_after_seconds", 360) config.Register(&config.Option{ Name: "Reseed after x bytes", @@ -43,7 +43,7 @@ func init() { ExpertiseLevel: config.ExpertiseLevelDeveloper, OptType: config.OptTypeInt, DefaultValue: 1000000, // one megabyte - ValidationRegex: "^[0-9]{0,9}$", + ValidationRegex: "^[1-9][0-9]{2,9}$", }) reseedAfterBytes = config.GetAsInt("random/reseed_after_bytes", 1000000)