8293779: redundant checking in AESCrypt.makeSessionKey() method

Reviewed-by: djelinski, hchao, mullan
This commit is contained in:
Xue-Lei Andrew Fan 2022-09-15 15:06:27 +00:00
parent 6fca9ae047
commit ecb456ae29

View File

@ -86,9 +86,9 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
throw new InvalidKeyException
("Wrong algorithm: AES or Rijndael required");
}
if (!isKeySizeValid(key.length)) {
throw new InvalidKeyException("Invalid AES key length: " +
key.length + " bytes");
if (key == null) { // Unlikely, but just double check it.
throw new InvalidKeyException("Empty key");
}
if (!MessageDigest.isEqual(key, lastKey)) {
@ -602,13 +602,11 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
* @exception InvalidKeyException If the key is invalid.
*/
private void makeSessionKey(byte[] k) throws InvalidKeyException {
if (k == null) {
throw new InvalidKeyException("Empty key");
}
if (!isKeySizeValid(k.length)) {
throw new InvalidKeyException("Invalid AES key length: " +
k.length + " bytes");
throw new InvalidKeyException("Invalid AES key length: " +
k.length + " bytes");
}
int ROUNDS = getRounds(k.length);
int ROUND_KEY_COUNT = (ROUNDS + 1) * 4;
@ -696,7 +694,6 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
sessionK = new int[][] { expandedKe, expandedKd };
}
/**
* Return The number of rounds for a given Rijndael keysize.
*