Blob Blame History Raw
# HG changeset patch
# User mbalao
# Date 1596572361 10800
#      Tue Aug 04 17:19:21 2020 -0300
# Node ID d8a0513b92ee262d4e64c1e13d43e1b3f3e5c5d5
# Parent  a259b5b1bc7cc4dd0d8fa19e8bdbf96a4e76224f
8251117: Cannot check P11Key size in P11Cipher and P11AEADCipher
Reviewed-by: andrew
Contributed-by: zzambers@redhat.com

diff --git openjdk.orig/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java openjdk/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java
--- openjdk.orig/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java
@@ -345,7 +345,9 @@
             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) {