Merge pull request #311 from cheeseandcereal/crypto_seed

use cryptographically secure rng seed
This commit is contained in:
Andrea Spacca 2020-05-17 19:10:56 +02:00 committed by GitHub
commit a26b32dd86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,6 +28,8 @@ import (
"errors"
gorillaHandlers "github.com/gorilla/handlers"
"log"
crypto_rand "crypto/rand"
"encoding/binary"
"math/rand"
"mime"
"net/http"
@ -306,7 +308,11 @@ func New(options ...OptionFn) (*Server, error) {
}
func init() {
rand.Seed(time.Now().UTC().UnixNano())
var seedBytes [8]byte
if _, err := crypto_rand.Read(seedBytes[:]); err != nil {
panic("cannot obtain cryptographically secure seed")
}
rand.Seed(int64(binary.LittleEndian.Uint64(seedBytes[:])))
}
func (s *Server) Run() {