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.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/pkg/crypto/rand/util.go b/src/pkg/crypto/rand/util.go
index 0cd5e0e02..5f7440785 100644
--- a/src/pkg/crypto/rand/util.go
+++ b/src/pkg/crypto/rand/util.go
@@ -27,9 +27,11 @@ var smallPrimesProduct = new(big.Int).SetUint64(16294579238595022365)
// Prime returns a number, p, of the given size, such that p is prime
// with high probability.
+// Prime will return error for any error returned by rand.Read or if bits < 2.
func Prime(rand io.Reader, bits int) (p *big.Int, err error) {
- if bits < 1 {
- err = errors.New("crypto/rand: prime size must be positive")
+ if bits < 2 {
+ err = errors.New("crypto/rand: prime size must be at least 2-bit")
+ return
}
b := uint(bits % 8)
@@ -79,7 +81,7 @@ func Prime(rand io.Reader, bits int) (p *big.Int, err error) {
for delta := uint64(0); delta < 1<<20; delta += 2 {
m := mod + delta
for _, prime := range smallPrimes {
- if m%uint64(prime) == 0 {
+ if m%uint64(prime) == 0 && (bits > 6 || m != uint64(prime)) {
continue NextDelta
}
}