From 33ceefb2099fbca56097a709144d1df55cd900c0 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Thu, 26 Mar 2020 15:04:46 +0900 Subject: [PATCH] Remove nim random usage from noise --- libp2p/protocols/secure/noise.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index 357abe03c..83017bb41 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -9,7 +9,6 @@ import chronos import chronicles -import random import stew/[endians2, byteutils] import nimcrypto/[utils, sysrand, sha2, hmac] import ../../connection @@ -283,8 +282,13 @@ proc sendHSMessage(sconn: Connection; buf: seq[byte]) {.async.} = await sconn.write(outbuf) proc packNoisePayload(payload: openarray[byte]): seq[byte] = + var + ns: uint32 + if randomBytes(addr ns, 4) != 4: + raise newException(NoiseHandshakeError, "Failed to generate randomBytes") + let - noiselen = rand(2..