src/java.base/share/classes/com/sun/crypto/provider/CipherBlockChaining.java
changeset 51052 080776992b29
parent 47216 71c04702a3d5
--- a/src/java.base/share/classes/com/sun/crypto/provider/CipherBlockChaining.java	Thu Jul 12 08:44:39 2018 +0800
+++ b/src/java.base/share/classes/com/sun/crypto/provider/CipherBlockChaining.java	Fri Jul 13 02:36:42 2018 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
 import java.util.Objects;
 
 import jdk.internal.HotSpotIntrinsicCandidate;
+import sun.security.util.ArrayUtil;
 
 
 /**
@@ -145,9 +146,9 @@
         if (plainLen <= 0) {
             return plainLen;
         }
-        cryptBlockSizeCheck(plainLen);
-        cryptNullAndBoundsCheck(plain, plainOffset, plainLen);
-        cryptNullAndBoundsCheck(cipher, cipherOffset, plainLen);
+        ArrayUtil.blockSizeCheck(plainLen, blockSize);
+        ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
+        ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
         return implEncrypt(plain, plainOffset, plainLen,
                            cipher, cipherOffset);
     }
@@ -196,9 +197,9 @@
         if (cipherLen <= 0) {
             return cipherLen;
         }
-        cryptBlockSizeCheck(cipherLen);
-        cryptNullAndBoundsCheck(cipher, cipherOffset, cipherLen);
-        cryptNullAndBoundsCheck(plain, plainOffset, cipherLen);
+        ArrayUtil.blockSizeCheck(cipherLen, blockSize);
+        ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen);
+        ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen);
         return implDecrypt(cipher, cipherOffset, cipherLen, plain, plainOffset);
     }
 
@@ -218,23 +219,4 @@
         }
         return cipherLen;
     }
-
-    private void cryptBlockSizeCheck(int len) {
-        if ((len % blockSize) != 0) {
-            throw new ProviderException("Internal error in input buffering");
-        }
-    }
-
-    private static void cryptNullAndBoundsCheck(byte[] array, int offset, int len) {
-        Objects.requireNonNull(array);
-
-        if (offset < 0 || offset >= array.length) {
-            throw new ArrayIndexOutOfBoundsException(offset);
-        }
-
-        int endIndex = offset + len - 1;
-        if (endIndex < 0 || endIndex >= array.length) {
-            throw new ArrayIndexOutOfBoundsException(endIndex);
-        }
-    }
 }