Skip to content

Commit b0c629c

Browse files
committed
added system/security property to disable Lenstra check where appropriate.
1 parent 0226bd9 commit b0c629c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

core/src/main/java/org/bouncycastle/crypto/engines/RSACoreEngine.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
import org.bouncycastle.crypto.params.RSAKeyParameters;
1313
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
1414
import org.bouncycastle.util.Arrays;
15+
import org.bouncycastle.util.Properties;
1516

1617
/**
1718
* this does your basic RSA algorithm.
1819
*/
1920
class RSACoreEngine
2021
{
22+
static final String NO_LENSTRA_CHECK = "org.bouncycastle.rsa.no_lenstra_check";
23+
2124
private RSAKeyParameters key;
2225
private boolean forEncryption;
2326

@@ -182,7 +185,7 @@ public BigInteger processBlock(BigInteger input)
182185
RSAPrivateCrtKeyParameters crtKey = (RSAPrivateCrtKeyParameters)key;
183186

184187
BigInteger e = crtKey.getPublicExponent();
185-
if (e != null) // can't apply fault-attack countermeasure without public exponent
188+
if (e != null || Properties.isOverrideSet(NO_LENSTRA_CHECK)) // can't apply fault-attack countermeasure without public exponent
186189
{
187190
BigInteger p = crtKey.getP();
188191
BigInteger q = crtKey.getQ();
@@ -206,11 +209,14 @@ public BigInteger processBlock(BigInteger input)
206209
// m = h * q + mQ
207210
m = h.multiply(q).add(mQ);
208211

209-
// defence against Arjen Lenstra’s CRT attack
210-
BigInteger check = m.modPow(e, crtKey.getModulus());
211-
if (!check.equals(input))
212+
if (e != null)
212213
{
213-
throw new IllegalStateException("RSA engine faulty decryption/signing detected");
214+
// defence against Arjen Lenstra’s CRT attack
215+
BigInteger check = m.modPow(e, crtKey.getModulus());
216+
if (!check.equals(input))
217+
{
218+
throw new IllegalStateException("RSA engine faulty decryption/signing detected");
219+
}
214220
}
215221

216222
return m;

0 commit comments

Comments
 (0)