From 4fea9297b9f96638892bb5e6c627e0da87e731c3 Mon Sep 17 00:00:00 2001 From: bazzilic Date: Tue, 7 Dec 2021 23:54:33 +0800 Subject: [PATCH] bump BigIntegerExt so it generates pseudo primes of exact given bit length --- src/Aprismatic.ElGamalExt/Aprismatic.ElGamalExt.csproj | 4 ++-- src/Aprismatic.ElGamalExt/ElGamal.cs | 5 +---- test/ElGamalTests/ElGamalTests.csproj | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Aprismatic.ElGamalExt/Aprismatic.ElGamalExt.csproj b/src/Aprismatic.ElGamalExt/Aprismatic.ElGamalExt.csproj index 26c4de2..a902843 100644 --- a/src/Aprismatic.ElGamalExt/Aprismatic.ElGamalExt.csproj +++ b/src/Aprismatic.ElGamalExt/Aprismatic.ElGamalExt.csproj @@ -5,8 +5,8 @@ - + - + \ No newline at end of file diff --git a/src/Aprismatic.ElGamalExt/ElGamal.cs b/src/Aprismatic.ElGamalExt/ElGamal.cs index 21e828f..a5edf4f 100644 --- a/src/Aprismatic.ElGamalExt/ElGamal.cs +++ b/src/Aprismatic.ElGamalExt/ElGamal.cs @@ -63,10 +63,7 @@ private ElGamalKeyStruct CreateKeyPair(int maxptbits) // TODO: This method shoul // Generate a large safe prime number P, and regenerate P when it is not same as KeySize in bytes do { - do - { - Q = BigInteger.Zero.GenPseudoPrime(KeySizeValue - 1, 16, rng); - } while (Q.BitCount() != KeySizeValue - 1); + Q = BigInteger.Zero.GenPseudoPrime(KeySizeValue - 1, 16, rng); PminusOne = bitwo * Q; P = PminusOne + BigInteger.One; } while (P.BitCount() != KeySizeValue && !P.IsProbablePrime(16)); diff --git a/test/ElGamalTests/ElGamalTests.csproj b/test/ElGamalTests/ElGamalTests.csproj index 7780d63..f8fc168 100644 --- a/test/ElGamalTests/ElGamalTests.csproj +++ b/test/ElGamalTests/ElGamalTests.csproj @@ -4,7 +4,7 @@ false - + all