by herr_gurke on 10/14/22, 6:33 AM with 48 comments
by Someone on 10/14/22, 7:02 AM
π π β 8530092
β· I.e. 0b100000100010100010101100: for all primes π β€ 23,
TestBit(π π, π) = true
if π β€ 23 then
β· Quick check for small values, simpler and faster
than testing equality on each option
return TestBit(π π, π)
end if
if Β¬TestBit(π, 0) then return β₯
β· I.e. π is even and, as per line 2, π > 2 thus composite
end if
And it indeed is a bug. The function guarantees to return false βif the number can be determined to be compositeβ and true for all primes, so it should err in only one way.I would further improve the code by having it shortcut for all primes smaller than 31 (adding 29 and 31) or 63.
by nairboon on 10/14/22, 8:04 AM
by tromp on 10/14/22, 7:55 AM
That is one modest reviewer!
by raverbashing on 10/14/22, 8:19 AM
19 should have been tested by a lookup table, there's no need to apply such heavy test to it
However, by changing that constant (if not properly verified) I'd worry it might change the primality test for some classes of numbers. Where this might be later manipulated to produce a weak key
by omega3 on 10/14/22, 10:27 AM
by gsk22 on 10/14/22, 7:44 AM
I don't know much about Swiss e-voting, but seems even the most brain-dead unit test of the IsProbablePrime function should have caught this.
by amelius on 10/14/22, 8:16 AM