The core of the key checker seems to be written in an oddly obtuse way for some reason, including some tests that are redundant. Specifically, the only primes that matter are 11,13,17,19,37,53,61,71,73,79,97,103,107,109,127,151,157. The others have check bitmasks that are all 1s (except for bit 0 = residue 0), which pass for all RSA keys (unless they have a small prime factor, but then you have bigger issues to worry about than the Infineon bug).
For some reason the bitmasks are expressed as decimal numbers (instead of hex or binary), which further obfuscates their meaning. These masks apparently have been generated from a simpler relation of the form n ^ r mod p = 1 for a prime p and a small exponent r, as documented here.
I've written a simpler implementation which omits the useless entries and directly computes the sets of indicator residues from the simpler relation, using more Pythonic constructs (sets instead of bitmasks). I think something along these lines would make more sense than the current code, and it is also ~3 times faster.
The core of the key checker seems to be written in an oddly obtuse way for some reason, including some tests that are redundant. Specifically, the only primes that matter are 11,13,17,19,37,53,61,71,73,79,97,103,107,109,127,151,157. The others have check bitmasks that are all 1s (except for bit 0 = residue 0), which pass for all RSA keys (unless they have a small prime factor, but then you have bigger issues to worry about than the Infineon bug).
For some reason the bitmasks are expressed as decimal numbers (instead of hex or binary), which further obfuscates their meaning. These masks apparently have been generated from a simpler relation of the form n ^ r mod p = 1 for a prime p and a small exponent r, as documented here.
I've written a simpler implementation which omits the useless entries and directly computes the sets of indicator residues from the simpler relation, using more Pythonic constructs (sets instead of bitmasks). I think something along these lines would make more sense than the current code, and it is also ~3 times faster.