From 73e6bca7a3a08d5b854a837542fe7a584db9ff02 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 2 Feb 2023 00:26:21 +0200 Subject: [PATCH] extend CSPRNG to support math/rand.Source64 interface --- csrand.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/csrand.go b/csrand.go index 4a5cea8..2b8d07e 100644 --- a/csrand.go +++ b/csrand.go @@ -10,6 +10,7 @@ type secureRandomSource struct{} var RandomSource secureRandomSource var int63Limit = big.NewInt(0).Lsh(big.NewInt(1), 63) +var int64Limit = big.NewInt(0).Lsh(big.NewInt(1), 64) func (_ secureRandomSource) Seed(_ int64) { } @@ -21,3 +22,11 @@ func (_ secureRandomSource) Int63() int64 { } return randNum.Int64() } + +func (_ secureRandomSource) Uint64() uint64 { + randNum, err := crand.Int(crand.Reader, int64Limit) + if err != nil { + panic(err) + } + return randNum.Uint64() +}