jdk/src/jdk.crypto.ucrypto/solaris/classes/com/oracle/security/ucrypto/NativeCipherWithJavaPadding.java
changeset 32646 db7c5592a47f
parent 28059 e576535359cc
child 35302 e4d2275861c3
equal deleted inserted replaced
32645:32e2fd6206d1 32646:db7c5592a47f
   182             }
   182             }
   183             byte padValue = lastData[lastData.length - 1];
   183             byte padValue = lastData[lastData.length - 1];
   184             if (padValue < 1 || padValue > blockSize) {
   184             if (padValue < 1 || padValue > blockSize) {
   185                 UcryptoProvider.debug("PKCS5Padding: unpad, lastData: " + Arrays.toString(lastData));
   185                 UcryptoProvider.debug("PKCS5Padding: unpad, lastData: " + Arrays.toString(lastData));
   186                 UcryptoProvider.debug("PKCS5Padding: unpad, padValue=" + padValue);
   186                 UcryptoProvider.debug("PKCS5Padding: unpad, padValue=" + padValue);
   187                 throw new BadPaddingException("Invalid pad value!");
   187                 throw new BadPaddingException("Invalid pad value: " + padValue);
   188             }
   188             }
   189 
   189 
   190             // sanity check padding bytes
   190             // sanity check padding bytes
   191             int padStartIndex = lastData.length - padValue;
   191             int padStartIndex = lastData.length - padValue;
   192             for (int i = padStartIndex; i < lastData.length; i++) {
   192             for (int i = padStartIndex; i < lastData.length; i++) {
   386             // truncate off extra bytes
   386             // truncate off extra bytes
   387             if (actualOut != out.length) {
   387             if (actualOut != out.length) {
   388                 out = Arrays.copyOf(out, actualOut);
   388                 out = Arrays.copyOf(out, actualOut);
   389             }
   389             }
   390         } catch (ShortBufferException sbe) {
   390         } catch (ShortBufferException sbe) {
   391             throw new UcryptoException("Internal Error");
   391             throw new UcryptoException("Internal Error", sbe);
   392         } finally {
   392         } finally {
   393             reset();
   393             reset();
   394         }
   394         }
   395         return out;
   395         return out;
   396     }
   396     }
   402         throws ShortBufferException, IllegalBlockSizeException,
   402         throws ShortBufferException, IllegalBlockSizeException,
   403                BadPaddingException {
   403                BadPaddingException {
   404         int estimatedOutLen = engineGetOutputSize(inLen);
   404         int estimatedOutLen = engineGetOutputSize(inLen);
   405 
   405 
   406         if (out.length - outOfs < estimatedOutLen) {
   406         if (out.length - outOfs < estimatedOutLen) {
   407             throw new ShortBufferException();
   407             throw new ShortBufferException("Actual: " + (out.length - outOfs) +
       
   408                 ". Estimated Out Length: " + estimatedOutLen);
   408         }
   409         }
   409         try {
   410         try {
   410             if (nc.encrypt) {
   411             if (nc.encrypt) {
   411                 int k = nc.engineUpdate(in, inOfs, inLen, out, outOfs);
   412                 int k = nc.engineUpdate(in, inOfs, inLen, out, outOfs);
   412                 lastBlockLen += inLen;
   413                 lastBlockLen += inLen;