From: Benny Baumann Date: Sat, 11 Nov 2017 12:38:57 +0000 (+0100) Subject: Merge changes Icf0b8af5,I2f8a5077 X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=cd36db3ec2a1437f1d943f1a356ce1814f5d1b0e;hp=c7ba0d7ba91c9d3d12c651ecba0ddf8f27835d4c Merge changes Icf0b8af5,I2f8a5077 * changes: add: table to store certificate logs chg: manage more resources explicitly --- diff --git a/src/club/wpia/gigi/crypto/key/KeyCheckSmallFactors.java b/src/club/wpia/gigi/crypto/key/KeyCheckSmallFactors.java index a0965344..8f78c6a5 100644 --- a/src/club/wpia/gigi/crypto/key/KeyCheckSmallFactors.java +++ b/src/club/wpia/gigi/crypto/key/KeyCheckSmallFactors.java @@ -3,7 +3,6 @@ package club.wpia.gigi.crypto.key; import java.math.BigInteger; import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; -import java.util.ArrayList; import club.wpia.gigi.GigiApiException; import club.wpia.gigi.output.template.SprintfCommand; @@ -12,23 +11,21 @@ public class KeyCheckSmallFactors extends KeyCheck { private static final long MAX_CHECKED_SMALL_PRIME_BOUNDARY = 10000; - private static final BigInteger[] primes; + private static final BigInteger primeProduct; static { - ArrayList prims = new ArrayList<>(1024); + BigInteger prod = BigInteger.ONE; NextPrime: for (long i = 2; i < MAX_CHECKED_SMALL_PRIME_BOUNDARY; i++) { - for (BigInteger p : prims) { - if (BigInteger.ZERO.equals(BigInteger.valueOf(i).mod(p))) { - continue NextPrime; - } + if ( !BigInteger.ONE.equals(BigInteger.valueOf(i).gcd(prod))) { + continue NextPrime; } - prims.add(BigInteger.valueOf(i)); + prod = prod.multiply(BigInteger.valueOf(i)); } - primes = prims.toArray(new BigInteger[0]); + primeProduct = prod; register(new KeyCheckSmallFactors()); } @@ -42,10 +39,9 @@ public class KeyCheckSmallFactors extends KeyCheck { BigInteger modulus = ((RSAPublicKey) key).getModulus(); // Check for small prime factors below 10000 - for (BigInteger n : primes) { - if (BigInteger.ZERO.equals(modulus.mod(n))) { - throw new GigiApiException(SprintfCommand.createSimple("Small factors check of public key: Key is divisible by {0}.", n.toString())); - } + BigInteger n = modulus.gcd(primeProduct); + if ( !BigInteger.ONE.equals(n)) { + throw new GigiApiException(SprintfCommand.createSimple("Small factors check of public key: Key has known factor of {0}.", n.toString())); } }