8251117: Cannot check P11Key size in P11Cipher and P11AEADCipher

Reviewed-by: valeriep
This commit is contained in:
Zdenek Zambersky 2020-08-04 17:19:21 -03:00 committed by Martin Balao
parent ed5696dd2c
commit 1cc09ccaef
2 changed files with 6 additions and 2 deletions

View File

@ -280,7 +280,9 @@ final class P11AEADCipher extends CipherSpi {
SecureRandom sr)
throws InvalidKeyException, InvalidAlgorithmParameterException {
reset(true);
if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) {
if (fixedKeySize != -1 &&
((key instanceof P11Key) ? ((P11Key) key).length() >> 3 :
key.getEncoded().length) != fixedKeySize) {
throw new InvalidKeyException("Key size is invalid");
}
P11Key newKey = P11SecretKeyFactory.convertKey(token, key, ALGO);

View File

@ -345,7 +345,9 @@ final class P11Cipher extends CipherSpi {
SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException {
reset(true);
if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) {
if (fixedKeySize != -1 &&
((key instanceof P11Key) ? ((P11Key) key).length() >> 3 :
key.getEncoded().length) != fixedKeySize) {
throw new InvalidKeyException("Key size is invalid");
}
switch (opmode) {