# HG changeset patch # User Peter Sanchez # Date 1692409997 21600 # Fri Aug 18 19:53:17 2023 -0600 # Node ID d0bc97ccbcbe3116d0c7e47a228e913447aaf1a0 # Parent 5f221cb61f1274b04481ba6b4fedb2bc4a18aa39 Using more secure random seeding diff --git a/crypto/crypto.go b/crypto/crypto.go --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -5,10 +5,10 @@ "crypto/cipher" "crypto/rand" "encoding/base64" - "encoding/binary" "errors" "io" mrand "math/rand" + "time" ) // ErrInvalidValue ... @@ -37,17 +37,11 @@ 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 }