Handle null random values in PSSSignatureSpi
Uses the same pattern as SignatureSpi to handle null random parameters
passed into engineInitSign().
introduced additional calls to engineInitSign() with null
random values which is causing test failures for us.
private byte trailer;
private boolean isRaw;
private RSAKeyParameters key;
+ private SecureRandom random;
private org.bouncycastle.crypto.signers.PSSSigner pss;
private boolean isInitState = true;
@@ -123,15 +124,8 @@ protected void engineInitSign(
SecureRandom random)
throws InvalidKeyException
{
- if (!(privateKey instanceof RSAPrivateKey))
- {
- throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
- }
-
- key = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey);
- pss = new org.bouncycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength, trailer);
- pss.init(true, new ParametersWithRandom(key, random));
- isInitState = true;
+ this.random = random;
+ engineInitSign(privateKey);
}
protected void engineInitSign(
@@ -145,7 +139,16 @@ protected void engineInitSign(
key = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey);
pss = new org.bouncycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength, trailer);
+
+ if (random != null)
+ {
+ pss.init(true, new ParametersWithRandom(key, random));
+ }
+ else
+ {
pss.init(true, key);
+ }
+
isInitState = true;
}
