Skip to content

Improve performance of Diffie-Hellman key exchange #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/main/java/org/jruby/ext/openssl/PKeyDH.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ public static BigInteger generateX(BigInteger p, int limit) {
BigInteger x;
SecureRandom secureRandom = new SecureRandom();
// adapting algorithm from org.bouncycastle.crypto.generators.DHKeyGeneratorHelper,
// which seems a little stronger (?) than OpenSSL's (OSSL just generates a random,
// while BC generates a random potential prime [for limit > 0], though it's not
// subject to Miller-Rabin [certainty = 0], but is subject to other constraints)
// see also [ossl]/crypto/dh/dh_key.c #generate_key
if (limit == 0) {
final BigInteger pSub2 = p.subtract(TWO);
Expand All @@ -213,8 +210,7 @@ public static BigInteger generateX(BigInteger p, int limit) {
} while (x.equals(BigInteger.ZERO));
} else {
do {
// generate potential prime, though with 0 certainty (no Miller-Rabin tests)
x = new BigInteger(limit, 0, secureRandom);
x = new BigInteger(limit, secureRandom);
} while (x.equals(BigInteger.ZERO));
}
return x;
Expand Down