From ed867aa585bb18c2bb076837c5b8d458ca619748 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 18 Aug 2023 19:53:17 -0600 Subject: [PATCH] Using more secure random seeding --- crypto/crypto.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index 25994b2..c23cf10 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -5,10 +5,10 @@ import ( "crypto/cipher" "crypto/rand" "encoding/base64" - "encoding/binary" "errors" "io" mrand "math/rand" + "time" ) // ErrInvalidValue ... @@ -37,17 +37,11 @@ type KeyWallet struct { func GenerateKey(keylen int, alpha bool) []byte { key := make([]byte, keylen) if alpha { - var seed [8]byte - _, err := rand.Read(seed[:]) - if err != nil { - // XXX Panic? - panic("cannot seed cryptographically secure random number generator") - } - mrand.Seed(int64(binary.LittleEndian.Uint64(seed[:]))) + r := mrand.New(mrand.NewSource(time.Now().UnixNano())) chars := `abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}\\|'";:/?.>,<` for i := 0; i < keylen; i++ { - key[i] = chars[mrand.Intn(len(chars))] + key[i] = chars[r.Intn(len(chars))] } return key } -- 2.45.2