Browse Source

use cryptographically secure rng seed

Signed-off-by: Adam Crowder <adam@adamcrowder.net>
tags/v1.2.0
Adam Crowder 4 years ago
parent
commit
0a6b5817a9
No known key found for this signature in database GPG Key ID: CA63AD7FC16C6CC0
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      server/server.go

+ 7
- 1
server/server.go 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() {


Loading…
Cancel
Save