Skip to content

Commit ecb456a

Browse files
committed
8293779: redundant checking in AESCrypt.makeSessionKey() method
Reviewed-by: djelinski, hchao, mullan
1 parent 6fca9ae commit ecb456a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ void init(boolean decrypting, String algorithm, byte[] key)
8686
throw new InvalidKeyException
8787
("Wrong algorithm: AES or Rijndael required");
8888
}
89-
if (!isKeySizeValid(key.length)) {
90-
throw new InvalidKeyException("Invalid AES key length: " +
91-
key.length + " bytes");
89+
90+
if (key == null) { // Unlikely, but just double check it.
91+
throw new InvalidKeyException("Empty key");
9292
}
9393

9494
if (!MessageDigest.isEqual(key, lastKey)) {
@@ -602,13 +602,11 @@ private void implDecryptBlock(byte[] in, int inOffset,
602602
* @exception InvalidKeyException If the key is invalid.
603603
*/
604604
private void makeSessionKey(byte[] k) throws InvalidKeyException {
605-
if (k == null) {
606-
throw new InvalidKeyException("Empty key");
607-
}
608605
if (!isKeySizeValid(k.length)) {
609-
throw new InvalidKeyException("Invalid AES key length: " +
610-
k.length + " bytes");
606+
throw new InvalidKeyException("Invalid AES key length: " +
607+
k.length + " bytes");
611608
}
609+
612610
int ROUNDS = getRounds(k.length);
613611
int ROUND_KEY_COUNT = (ROUNDS + 1) * 4;
614612

@@ -696,7 +694,6 @@ private void makeSessionKey(byte[] k) throws InvalidKeyException {
696694
sessionK = new int[][] { expandedKe, expandedKd };
697695
}
698696

699-
700697
/**
701698
* Return The number of rounds for a given Rijndael keysize.
702699
*

0 commit comments

Comments
 (0)