From 6a5c6c55096ea8ac99587accc3120b72d9dcfe23 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 15 Dec 2022 16:28:10 +0100 Subject: [PATCH] Improve ElGamal validation by refraining from biginteger for loop variable --- .../key/util/PublicKeyParameterValidationUtil.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/util/PublicKeyParameterValidationUtil.java b/pgpainless-core/src/main/java/org/pgpainless/key/util/PublicKeyParameterValidationUtil.java index 88e9897a..344f063b 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/util/PublicKeyParameterValidationUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/util/PublicKeyParameterValidationUtil.java @@ -265,14 +265,15 @@ public class PublicKeyParameterValidationUtil { // check g^i mod p != 1 for i < threshold BigInteger res = g; - BigInteger i = BigInteger.valueOf(1); - BigInteger threshold = BigInteger.valueOf(2).shiftLeft(17); - while (i.compareTo(threshold) < 0) { + // 262144 + int threshold = 2 << 17; + int i = 1; + while (i < threshold) { res = res.multiply(g).mod(p); if (res.equals(one)) { return false; } - i = i.add(one); + i++; } // blinded exponentiation to check y = g^(r*(p-1)+x) mod p