Skip to content

Commit

Permalink
math: Added parity check to ProbablyPrime
Browse files Browse the repository at this point in the history
Fixes golang#9269

Change-Id: I25751632e95978537b656aedfa5c35ab2273089b
Reviewed-on: https://go-review.googlesource.com/1380
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
ALTree authored and griesemer committed Dec 12, 2014
1 parent da43976 commit 5de497b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/math/big/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,10 @@ func (n nat) probablyPrime(reps int) bool {
}
}

if n[0]&1 == 0 {
return false // n is even
}

const primesProduct32 = 0xC0CFD797 // Π {p ∈ primes, 2 < p <= 29}
const primesProduct64 = 0xE221F97C30E94E1D // Π {p ∈ primes, 2 < p <= 53}

Expand Down

0 comments on commit 5de497b

Please sign in to comment.