tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit f2e497aad3f96a3275a2873e6a55d964b63cbcf3
parent 39b928efaa30cc577a7ed8f0fe8605c77023d857
Author: parazyd <parazyd@dyne.org>
Date:   Mon, 12 Mar 2018 11:17:19 +0100

Use crypto/rand in dam-client to select random directories.

Diffstat:
Mcmd/dam-client/main.go | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/cmd/dam-client/main.go b/cmd/dam-client/main.go @@ -24,12 +24,13 @@ import ( "bufio" "bytes" "compress/gzip" + "crypto/rand" "crypto/rsa" "encoding/base64" "encoding/json" "io/ioutil" "log" - "math/rand" + "math/big" "os" "os/exec" "strconv" @@ -193,10 +194,9 @@ func fetchDirlist(locations []string) ([]string, error) { log.Println("Found enough directories. Picking out 6 random ones.") // Pick out 6 random directories from the retrieved list. for k := 0; k <= 5; k++ { - rand.Seed(time.Now().Unix()) - n := rand.Int() % len(dirSlice) - dirlist = append(dirlist, dirSlice[n]) - dirSlice[n] = dirSlice[len(dirSlice)-1] + n, _ := rand.Int(rand.Reader, big.NewInt(int64(len(dirSlice)))) + dirlist = append(dirlist, dirSlice[n.Int64()]) + dirSlice[n.Int64()] = dirSlice[len(dirSlice)-1] dirSlice = dirSlice[:len(dirSlice)-1] } }