< prev index next >

src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java

Print this page

        

@@ -349,12 +349,12 @@
     /**
      * Encrypt exactly one block of plaintext.
      */
     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);
     }
 
     // Encryption operation. Possibly replaced with a compiler intrinsic.
     @HotSpotIntrinsicCandidate

@@ -428,12 +428,12 @@
     /**
      * Decrypt exactly one block of plaintext.
      */
     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);
     }
 
     // Decrypt operation. Possibly replaced with a compiler intrinsic.
     @HotSpotIntrinsicCandidate

@@ -591,30 +591,10 @@
         out[outOffset++] = (byte)(Si[(a2 >>> 16) & 0xFF] ^ (t1 >>> 16));
         out[outOffset++] = (byte)(Si[(a1 >>>  8) & 0xFF] ^ (t1 >>>  8));
         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.
      *
      * @param k The 128/192/256-bit cipher key to use.
      * @exception InvalidKeyException  If the key is invalid.
< prev index next >