src/java.base/share/classes/com/sun/crypto/provider/ElectronicCodeBook.java
changeset 51052 080776992b29
parent 47216 71c04702a3d5
child 57786 948ac3112da8
--- a/src/java.base/share/classes/com/sun/crypto/provider/ElectronicCodeBook.java	Thu Jul 12 08:44:39 2018 +0800
+++ b/src/java.base/share/classes/com/sun/crypto/provider/ElectronicCodeBook.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
@@ -27,6 +27,7 @@
 
 import java.security.InvalidKeyException;
 import java.security.ProviderException;
+import sun.security.util.ArrayUtil;
 
 /**
  * This class represents ciphers in electronic codebook (ECB) mode.
@@ -112,9 +113,10 @@
      * @return the length of the encrypted data
      */
     int encrypt(byte[] in, int inOff, int len, byte[] out, int outOff) {
-        if ((len % blockSize) != 0) {
-             throw new ProviderException("Internal error in input buffering");
-        }
+        ArrayUtil.blockSizeCheck(len, blockSize);
+        ArrayUtil.nullAndBoundsCheck(in, inOff, len);
+        ArrayUtil.nullAndBoundsCheck(out, outOff, len);
+
         for (int i = len; i >= blockSize; i -= blockSize) {
             embeddedCipher.encryptBlock(in, inOff, out, outOff);
             inOff += blockSize;
@@ -141,9 +143,10 @@
      * @return the length of the decrypted data
      */
     int decrypt(byte[] in, int inOff, int len, byte[] out, int outOff) {
-        if ((len % blockSize) != 0) {
-             throw new ProviderException("Internal error in input buffering");
-        }
+        ArrayUtil.blockSizeCheck(len, blockSize);
+        ArrayUtil.nullAndBoundsCheck(in, inOff, len);
+        ArrayUtil.nullAndBoundsCheck(out, outOff, len);
+
         for (int i = len; i >= blockSize; i -= blockSize) {
             embeddedCipher.decryptBlock(in, inOff, out, outOff);
             inOff += blockSize;