scp-app

git clone git://git.codymlewis.com/scp-app.git
Log | Files | Refs | LICENSE

commit d1bc10cf190d474a21a71d9bba7233229087a71c
parent 3c34f4ad5d3fe5c4f154fa7e22f243182b57d172
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Sun, 23 Sep 2018 21:58:10 +1000

Fixed safe prime generation

Diffstat:
MDH.java | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/DH.java b/DH.java @@ -13,11 +13,13 @@ public class DH { * @return a random prime with length: bitLength */ public static BigInteger genPrime(int bitLength) { - BigInteger prime = BigInteger.probablePrime(bitLength, new SecureRandom()); + BigInteger prime; byte b[] = new byte[1]; b[0] = 2; - prime = prime.multiply(new BigInteger(b)); - prime = prime.add(BigInteger.ONE); + BigInteger two = new BigInteger(b); + do { + prime = BigInteger.probablePrime(bitLength, new SecureRandom()); + } while(!prime.multiply(two).add(BigInteger.ONE).isProbablePrime(5)); return prime; } /**