瀏覽代碼

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 金鑰 ID: 4AEE18F83AFDEB23
共有 1 個檔案被更改,包括 7 行新增1 行删除
  1. +7
    -1
      server/server.go

+ 7
- 1
server/server.go 查看文件

@@ -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…
取消
儲存