From 1101533dea7d94291753ee9b0030693f27d2e86a Mon Sep 17 00:00:00 2001 From: Larpon Date: Fri, 5 Feb 2021 19:26:34 +0100 Subject: [PATCH] crypto: document rest of rand submodule (#8580) --- vlib/crypto/rand/utils.v | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/vlib/crypto/rand/utils.v b/vlib/crypto/rand/utils.v index 537bf28911..31eaf2da18 100644 --- a/vlib/crypto/rand/utils.v +++ b/vlib/crypto/rand/utils.v @@ -7,6 +7,7 @@ module rand import math.bits import encoding.binary +// int_u64 returns a random unsigned 64-bit integer `u64` read from a real OS source of entropy. pub fn int_u64(max u64) ?u64 { bitlen := bits.len_64(max) if bitlen == 0 { @@ -19,8 +20,8 @@ pub fn int_u64(max u64) ?u64 { } mut n := u64(0) for { - mut bytes := read(k)? - bytes[0] &= byte(int(u64(1)<= ws; k++ { - z[k] = binary.big_endian_u64(b[i-ws..i]) + z[k] = binary.big_endian_u64(b[i - ws..i]) i -= ws } if i > 0 { mut d := u64(0) for s := u64(0); i > 0; s += u64(8) { - d |= u64(b[i-1]) << s + d |= u64(b[i - 1]) << s i-- } - z[z.len-1] = d + z[z.len - 1] = d } return z }