# HG changeset patch # User kvn # Date 1452211405 28800 # Node ID 70b4ba174883bd601f402b93c0a7d13add4f0534 # Parent bfdb1fc66989388c5f6f2513f4525bb96e441447 8135250: Replace custom check/range functionality with check index/range methods in java.util.Objects Reviewed-by: jrose, kvn Contributed-by: kishor.kharbas@intel.com diff -r bfdb1fc66989 -r 70b4ba174883 jdk/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java --- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java Wed Jan 06 08:02:24 2016 +0100 +++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java Thu Jan 07 16:03:25 2016 -0800 @@ -351,8 +351,8 @@ */ void encryptBlock(byte[] in, int inOffset, byte[] out, int outOffset) { - cryptBlockCheck(in, inOffset); - cryptBlockCheck(out, outOffset); + Objects.checkFromIndexSize(inOffset, AES_BLOCK_SIZE, in.length); + Objects.checkFromIndexSize(outOffset, AES_BLOCK_SIZE, out.length); implEncryptBlock(in, inOffset, out, outOffset); } @@ -430,8 +430,8 @@ */ void decryptBlock(byte[] in, int inOffset, byte[] out, int outOffset) { - cryptBlockCheck(in, inOffset); - cryptBlockCheck(out, outOffset); + Objects.checkFromIndexSize(inOffset, AES_BLOCK_SIZE, in.length); + Objects.checkFromIndexSize(outOffset, AES_BLOCK_SIZE, out.length); implDecryptBlock(in, inOffset, out, outOffset); } @@ -593,26 +593,6 @@ out[outOffset ] = (byte)(Si[(a0 ) & 0xFF] ^ (t1 )); } - // Used to perform all checks required by the Java semantics - // (i.e., null checks and bounds checks) on the input parameters - // to encryptBlock and to decryptBlock. - // Normally, the Java Runtime performs these checks, however, as - // encryptBlock and decryptBlock are possibly replaced with - // compiler intrinsics, the JDK performs the required checks instead. - // Does not check accesses to class-internal (private) arrays. - private static void cryptBlockCheck(byte[] array, int offset) { - Objects.requireNonNull(array); - - if (offset < 0 || offset >= array.length) { - throw new ArrayIndexOutOfBoundsException(offset); - } - - int largestIndex = offset + AES_BLOCK_SIZE - 1; - if (largestIndex < 0 || largestIndex >= array.length) { - throw new ArrayIndexOutOfBoundsException(largestIndex); - } - } - /** * Expand a user-supplied key material into a session key. * diff -r bfdb1fc66989 -r 70b4ba174883 jdk/src/java.base/share/classes/com/sun/crypto/provider/CounterMode.java --- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/CounterMode.java Wed Jan 06 08:02:24 2016 +0100 +++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/CounterMode.java Thu Jan 07 16:03:25 2016 -0800 @@ -173,9 +173,9 @@ */ private int crypt(byte[] in, int inOff, int len, byte[] out, int outOff) { - cryptBlockCheck(in, inOff, len); - cryptBlockCheck(out, outOff, len); - return implCrypt(in, inOff, len, out, outOff); + Objects.checkFromIndexSize(inOff, len, in.length); + Objects.checkFromIndexSize(outOff, len, out.length); + return implCrypt(in, inOff, len, out, outOff); } // Implementation of crpyt() method. Possibly replaced with a compiler intrinsic. @@ -193,22 +193,4 @@ return result; } - // Used to perform all checks required by the Java semantics - // (i.e., null checks and bounds checks) on the input parameters to crypt(). - // Normally, the Java Runtime performs these checks, however, as crypt() is - // possibly replaced with compiler intrinsic, the JDK performs the - // required checks instead. - // Does not check accesses to class-internal (private) arrays. - private static void cryptBlockCheck(byte[] array, int offset, int len) { - Objects.requireNonNull(array); - - if (offset < 0 || len < 0 || offset >= array.length) { - throw new ArrayIndexOutOfBoundsException(offset); - } - - int largestIndex = offset + len - 1; - if (largestIndex < 0 || largestIndex >= array.length) { - throw new ArrayIndexOutOfBoundsException(largestIndex); - } - } }