@@ -113,7 +113,8 @@ protected JcaTlsCrypto(JcaJceHelper helper, SecureRandom entropySource, SecureRa
113113 * @param entropySource primary entropy source, used for key generation.
114114 * @param nonceEntropySource secondary entropy source, used for nonce and IV generation.
115115 */
116- protected JcaTlsCrypto (JcaJceHelper helper , JcaJceHelper altHelper , SecureRandom entropySource , SecureRandom nonceEntropySource )
116+ protected JcaTlsCrypto (JcaJceHelper helper , JcaJceHelper altHelper , SecureRandom entropySource ,
117+ SecureRandom nonceEntropySource )
117118 {
118119 this .helper = helper ;
119120 this .altHelper = altHelper ;
@@ -573,7 +574,7 @@ public boolean hasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm)
573574 case CryptoSignatureAlgorithm .gostr34102012_256 :
574575 case CryptoSignatureAlgorithm .gostr34102012_512 :
575576
576- // TODO[RFC 8998]
577+ // TODO[RFC 8998]
577578 case CryptoSignatureAlgorithm .sm2 :
578579
579580 default :
@@ -755,7 +756,7 @@ public boolean hasSignatureAlgorithm(short signatureAlgorithm)
755756 case SignatureAlgorithm .gostr34102012_256 :
756757 case SignatureAlgorithm .gostr34102012_512 :
757758
758- // TODO[RFC 8998]
759+ // TODO[RFC 8998]
759760// case SignatureAlgorithm.sm2:
760761
761762 default :
@@ -784,7 +785,7 @@ public boolean hasSignatureScheme(int signatureScheme)
784785 switch (signatureScheme )
785786 {
786787 case SignatureScheme .sm2sig_sm3 :
787- // TODO[tls] Implement before adding
788+ // TODO[tls] Implement before adding
788789 case SignatureScheme .DRAFT_mldsa44 :
789790 case SignatureScheme .DRAFT_mldsa65 :
790791 case SignatureScheme .DRAFT_mldsa87 :
@@ -903,8 +904,7 @@ protected TlsAEADCipherImpl createAEADCipher(String cipherName, String algorithm
903904 * @throws GeneralSecurityException in case of failure.
904905 */
905906 protected TlsBlockCipherImpl createBlockCipher (String cipherName , String algorithm , int keySize ,
906- boolean isEncrypting )
907- throws GeneralSecurityException
907+ boolean isEncrypting ) throws GeneralSecurityException
908908 {
909909 return new JceBlockCipherImpl (this , helper .createCipher (cipherName ), algorithm , keySize , isEncrypting );
910910 }
@@ -920,8 +920,7 @@ protected TlsBlockCipherImpl createBlockCipher(String cipherName, String algorit
920920 * @throws GeneralSecurityException in case of failure.
921921 */
922922 protected TlsBlockCipherImpl createBlockCipherWithCBCImplicitIV (String cipherName , String algorithm , int keySize ,
923- boolean isEncrypting )
924- throws GeneralSecurityException
923+ boolean isEncrypting ) throws GeneralSecurityException
925924 {
926925 return new JceBlockCipherWithCBCImplicitIVImpl (this , helper .createCipher (cipherName ), algorithm , isEncrypting );
927926 }
@@ -955,17 +954,15 @@ protected TlsNullCipher createNullCipher(TlsCryptoParameters cryptoParams, int m
955954 }
956955
957956 protected TlsStreamSigner createStreamSigner (SignatureAndHashAlgorithm algorithm , PrivateKey privateKey ,
958- boolean needsRandom )
959- throws IOException
957+ boolean needsRandom ) throws IOException
960958 {
961959 String algorithmName = JcaUtils .getJcaAlgorithmName (algorithm );
962960
963961 return createStreamSigner (algorithmName , null , privateKey , needsRandom );
964962 }
965963
966964 protected TlsStreamSigner createStreamSigner (String algorithmName , AlgorithmParameterSpec parameter ,
967- PrivateKey privateKey , boolean needsRandom )
968- throws IOException
965+ PrivateKey privateKey , boolean needsRandom ) throws IOException
969966 {
970967 SecureRandom random = needsRandom ? getSecureRandom () : null ;
971968
@@ -977,14 +974,13 @@ protected TlsStreamSigner createStreamSigner(String algorithmName, AlgorithmPara
977974 }
978975 catch (InvalidKeyException e )
979976 {
980- if (altHelper != null )
981- {
982- return createStreamSigner (altHelper , algorithmName , parameter , privateKey , random );
983- }
984- else
977+ JcaJceHelper altHelper = getAltHelper ();
978+ if (altHelper == null )
985979 {
986980 throw e ;
987981 }
982+
983+ return createStreamSigner (altHelper , algorithmName , parameter , privateKey , random );
988984 }
989985 }
990986 catch (GeneralSecurityException e )
@@ -993,38 +989,36 @@ protected TlsStreamSigner createStreamSigner(String algorithmName, AlgorithmPara
993989 }
994990 }
995991
996- private TlsStreamSigner createStreamSigner (JcaJceHelper helper , String algorithmName , AlgorithmParameterSpec parameter ,
997- PrivateKey privateKey , SecureRandom random )
998- throws GeneralSecurityException
992+ protected TlsStreamSigner createStreamSigner (JcaJceHelper helper , String algorithmName ,
993+ AlgorithmParameterSpec parameter , PrivateKey privateKey , SecureRandom random ) throws GeneralSecurityException
999994 {
1000995 try
1001996 {
1002997 if (null != parameter )
1003998 {
999+ Signature dummySigner ;
10041000 try
10051001 {
1006- Signature dummySigner = helper .createSignature (algorithmName );
1007- dummySigner .initSign (privateKey , random );
1008- helper = new ProviderJcaJceHelper (dummySigner .getProvider ());
1002+ dummySigner = helper .createSignature (algorithmName );
10091003 }
10101004 catch (NoSuchAlgorithmException e )
10111005 {
10121006 // more PKCS#11 mischief
10131007 String upperAlg = Strings .toUpperCase (algorithmName );
1014- if (upperAlg .endsWith ("MGF1 " ))
1008+ if (upperAlg .endsWith ("ANDMGF1 " ))
10151009 {
10161010 // ANDMGF1 has vanished from the Sun PKCS11 provider.
10171011 algorithmName = upperAlg .replace ("ANDMGF1" , "SSA-PSS" );
1018- Signature dummySigner = helper .createSignature (algorithmName );
1019-
1020- dummySigner .initSign (privateKey , random );
1021- helper = new ProviderJcaJceHelper (dummySigner .getProvider ());
1012+ dummySigner = helper .createSignature (algorithmName );
10221013 }
10231014 else
10241015 {
10251016 throw e ;
10261017 }
10271018 }
1019+
1020+ dummySigner .initSign (privateKey , random );
1021+ helper = new ProviderJcaJceHelper (dummySigner .getProvider ());
10281022 }
10291023
10301024 Signature signer = helper .createSignature (algorithmName );
@@ -1038,7 +1032,7 @@ private TlsStreamSigner createStreamSigner(JcaJceHelper helper, String algorithm
10381032 catch (InvalidKeyException e )
10391033 {
10401034 String upperAlg = Strings .toUpperCase (algorithmName );
1041- if (upperAlg .endsWith ("MGF1 " ))
1035+ if (upperAlg .endsWith ("ANDMGF1 " ))
10421036 {
10431037 // ANDMGF1 has vanished from the Sun PKCS11 provider.
10441038 algorithmName = upperAlg .replace ("ANDMGF1" , "SSA-PSS" );
@@ -1060,8 +1054,7 @@ protected TlsStreamVerifier createStreamVerifier(DigitallySigned digitallySigned
10601054 }
10611055
10621056 protected TlsStreamVerifier createStreamVerifier (String algorithmName , AlgorithmParameterSpec parameter ,
1063- byte [] signature , PublicKey publicKey )
1064- throws IOException
1057+ byte [] signature , PublicKey publicKey ) throws IOException
10651058 {
10661059 try
10671060 {
@@ -1088,8 +1081,7 @@ protected TlsStreamVerifier createStreamVerifier(String algorithmName, Algorithm
10881081 }
10891082
10901083 protected Tls13Verifier createTls13Verifier (String algorithmName , AlgorithmParameterSpec parameter ,
1091- PublicKey publicKey )
1092- throws IOException
1084+ PublicKey publicKey ) throws IOException
10931085 {
10941086 try
10951087 {
@@ -1269,8 +1261,7 @@ public JcaJceHelper getAltHelper()
12691261 }
12701262
12711263 protected TlsBlockCipherImpl createCBCBlockCipherImpl (TlsCryptoParameters cryptoParams , String algorithm ,
1272- int cipherKeySize , boolean forEncryption )
1273- throws GeneralSecurityException
1264+ int cipherKeySize , boolean forEncryption ) throws GeneralSecurityException
12741265 {
12751266 String cipherName = algorithm + "/CBC/NoPadding" ;
12761267
@@ -1325,8 +1316,7 @@ private TlsAEADCipher createCipher_Camellia_GCM(TlsCryptoParameters cryptoParams
13251316 }
13261317
13271318 protected TlsCipher createCipher_CBC (TlsCryptoParameters cryptoParams , String algorithm , int cipherKeySize ,
1328- int macAlgorithm )
1329- throws GeneralSecurityException , IOException
1319+ int macAlgorithm ) throws GeneralSecurityException , IOException
13301320 {
13311321 TlsBlockCipherImpl encrypt = createCBCBlockCipherImpl (cryptoParams , algorithm , cipherKeySize , true );
13321322 TlsBlockCipherImpl decrypt = createCBCBlockCipherImpl (cryptoParams , algorithm , cipherKeySize , false );
0 commit comments