Переглянути джерело

Merge pull request #311 from cheeseandcereal/crypto_seed

use cryptographically secure rng seed
tags/v1.2.0
Andrea Spacca 4 роки тому
committed by GitHub
джерело
коміт
a26b32dd86
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 4AEE18F83AFDEB23
1 змінених файлів з 7 додано та 1 видалено
  1. +7
    -1
      server/server.go

+ 7
- 1
server/server.go Переглянути файл

@@ -28,6 +28,8 @@ import (
"errors" "errors"
gorillaHandlers "github.com/gorilla/handlers" gorillaHandlers "github.com/gorilla/handlers"
"log" "log"
crypto_rand "crypto/rand"
"encoding/binary"
"math/rand" "math/rand"
"mime" "mime"
"net/http" "net/http"
@@ -306,7 +308,11 @@ func New(options ...OptionFn) (*Server, error) {
} }


func init() { 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() { func (s *Server) Run() {


Завантаження…
Відмінити
Зберегти