summaryrefslogtreecommitdiff
path: root/src/pkg/crypto/rand/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/crypto/rand/util.go')
-rw-r--r--src/pkg/crypto/rand/util.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/pkg/crypto/rand/util.go b/src/pkg/crypto/rand/util.go
index 21608dbac..0cd5e0e02 100644
--- a/src/pkg/crypto/rand/util.go
+++ b/src/pkg/crypto/rand/util.go
@@ -100,8 +100,11 @@ func Prime(rand io.Reader, bits int) (p *big.Int, err error) {
}
}
-// Int returns a uniform random value in [0, max).
+// Int returns a uniform random value in [0, max). It panics if max <= 0.
func Int(rand io.Reader, max *big.Int) (n *big.Int, err error) {
+ if max.Sign() <= 0 {
+ panic("crypto/rand: argument to Int is <= 0")
+ }
k := (max.BitLen() + 7) / 8
// b is the number of bits in the most significant byte of max.