@@ -134,6 +134,11 @@ else if (key instanceof RSAPublicKey)
134
134
protected int engineGetOutputSize (
135
135
int inputLen )
136
136
{
137
+ if (tlsRsaSpec != null )
138
+ {
139
+ return TlsRsaKeyExchange .PRE_MASTER_SECRET_LENGTH ;
140
+ }
141
+
137
142
try
138
143
{
139
144
return cipher .getOutputBlockSize ();
@@ -334,6 +339,7 @@ else if (key instanceof RSAPrivateKey)
334
339
}
335
340
else if (params instanceof TLSRSAPremasterSecretParameterSpec )
336
341
{
342
+ // TODO Restrict mode to DECRYPT_MODE (and/or UNWRAP_MODE)
337
343
if (!(param instanceof RSAKeyParameters ) || !((RSAKeyParameters )param ).isPrivate ())
338
344
{
339
345
throw new InvalidKeyException ("RSA private key required for TLS decryption" );
@@ -353,6 +359,7 @@ else if (params instanceof TLSRSAPremasterSecretParameterSpec)
353
359
}
354
360
else
355
361
{
362
+ // TODO Remove after checking all AsymmetricBlockCipher init methods?
356
363
param = new ParametersWithRandom (param , CryptoServicesRegistrar .getSecureRandom ());
357
364
}
358
365
@@ -446,6 +453,7 @@ protected byte[] engineDoFinal(
446
453
int inputLen )
447
454
throws IllegalBlockSizeException , BadPaddingException
448
455
{
456
+ // TODO Can input actually be null?
449
457
if (input != null )
450
458
{
451
459
engineUpdate (input , inputOffset , inputLen );
@@ -462,16 +470,8 @@ protected int engineDoFinal(
462
470
int outputOffset )
463
471
throws IllegalBlockSizeException , BadPaddingException , ShortBufferException
464
472
{
465
- int outputSize ;
466
- if (tlsRsaSpec != null )
467
- {
468
- outputSize = TlsRsaKeyExchange .PRE_MASTER_SECRET_LENGTH ;
469
- }
470
- else
471
- {
472
- outputSize = engineGetOutputSize (input == null ? 0 : inputLen );
473
- }
474
-
473
+ // TODO Can input actually be null?
474
+ int outputSize = engineGetOutputSize (input == null ? 0 : inputLen );
475
475
if (outputOffset > output .length - outputSize )
476
476
{
477
477
throw new ShortBufferException ("output buffer too short for input." );
0 commit comments