diff --git a/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java b/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java index 28d52d68ead..44ab4eda410 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java @@ -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. *