Repository: incubator-pirk Updated Branches: refs/heads/master 0ed4452bf -> b59bd0192
PIRK-2 -- Updates to load Pallier's PRNG statically and from any provider - closes apache/incubator-pirk#2 Project: http://git-wip-us.apache.org/repos/asf/incubator-pirk/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-pirk/commit/b59bd019 Tree: http://git-wip-us.apache.org/repos/asf/incubator-pirk/tree/b59bd019 Diff: http://git-wip-us.apache.org/repos/asf/incubator-pirk/diff/b59bd019 Branch: refs/heads/master Commit: b59bd01923838870db0939103089864dfeb41618 Parents: 0ed4452 Author: eawilliams <[email protected]> Authored: Sun Jul 17 11:40:47 2016 -0400 Committer: eawilliams <[email protected]> Committed: Sun Jul 17 11:40:47 2016 -0400 ---------------------------------------------------------------------- .../org/apache/pirk/encryption/Paillier.java | 43 +++++++------------- 1 file changed, 15 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/b59bd019/src/main/java/org/apache/pirk/encryption/Paillier.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/encryption/Paillier.java b/src/main/java/org/apache/pirk/encryption/Paillier.java index 3eb72a9..5a5ac6d 100644 --- a/src/main/java/org/apache/pirk/encryption/Paillier.java +++ b/src/main/java/org/apache/pirk/encryption/Paillier.java @@ -69,6 +69,20 @@ public class Paillier implements Serializable private static final long serialVersionUID = 1L; private static Logger logger = LogUtils.getLoggerForThisClass(); + + private static final SecureRandom nativePRNGSecureRandom; + + static + { + try + { + nativePRNGSecureRandom = SecureRandom.getInstance("NativePRNG"); + } catch (Exception e) + { + logger.error("Unable to instantiate a SecureRandom object with the NativePRNG algorithm.", e); + throw new RuntimeException("Unable to instantiate a SecureRandom object with the NativePRNG algorithm.", e); + } + } BigInteger p = null; // large prime BigInteger q = null; // large prime @@ -222,18 +236,6 @@ public class Paillier implements Serializable private void getKeys(int certainty) { - SecureRandom nativePRNGSecureRandom = null; - try - { - nativePRNGSecureRandom = SecureRandom.getInstance("NativePRNG", "SUN"); - } catch (Exception e) - { - logger.error("Unable to instantiate a SecureRandom object from the SUN provider with the NativePRNG algorithm!"); - e.printStackTrace(); - // If we can't generate good random using a method we are confident in, we shouldn't continue - System.exit(1); - } - // Generate the primes BigInteger[] pq = PrimeGenerator.getPrimePair(bitLength, certainty, nativePRNGSecureRandom); p = pq[0]; @@ -258,19 +260,6 @@ public class Paillier implements Serializable */ public BigInteger encrypt(BigInteger m) throws PIRException { - BigInteger cipher = null; - SecureRandom nativePRNGSecureRandom = null; - try - { - nativePRNGSecureRandom = SecureRandom.getInstance("NativePRNG", "SUN"); - } catch (Exception e) - { - logger.error("Unable to instantiate a SecureRandom object from the SUN provider with the NativePRNG algorithm!"); - e.printStackTrace(); - // If we can't generate good random using a method we are confident in, we shouldn't continue - System.exit(1); - } - // Generate a random value r in (Z/NZ)* BigInteger r = (new BigInteger(bitLength, nativePRNGSecureRandom)).mod(N); while (r.mod(p).equals(BigInteger.ZERO) || r.mod(q).equals(BigInteger.ZERO) || r.equals(BigInteger.ONE) || r.equals(BigInteger.ZERO)) @@ -278,9 +267,7 @@ public class Paillier implements Serializable r = (new BigInteger(bitLength, nativePRNGSecureRandom)).mod(N); } - cipher = encrypt(m, r); - - return cipher; + return encrypt(m, r); } /**
