src/java.base/share/classes/com/sun/crypto/provider/PCBC.java
changeset 51052 080776992b29
parent 47216 71c04702a3d5
equal deleted inserted replaced
51051:4e98b465d706 51052:080776992b29
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    25 
    25 
    26 package com.sun.crypto.provider;
    26 package com.sun.crypto.provider;
    27 
    27 
    28 import java.security.InvalidKeyException;
    28 import java.security.InvalidKeyException;
    29 import java.security.ProviderException;
    29 import java.security.ProviderException;
       
    30 import sun.security.util.ArrayUtil;
    30 
    31 
    31 
    32 
    32 /**
    33 /**
    33  * This class represents ciphers in Plaintext Cipher Block Chaining (PCBC)
    34  * This class represents ciphers in Plaintext Cipher Block Chaining (PCBC)
    34  * mode.
    35  * mode.
   134      * @return the length of the encrypted data
   135      * @return the length of the encrypted data
   135      */
   136      */
   136     int encrypt(byte[] plain, int plainOffset, int plainLen,
   137     int encrypt(byte[] plain, int plainOffset, int plainLen,
   137                 byte[] cipher, int cipherOffset)
   138                 byte[] cipher, int cipherOffset)
   138     {
   139     {
   139         if ((plainLen % blockSize) != 0) {
   140         ArrayUtil.blockSizeCheck(plainLen, blockSize);
   140             throw new ProviderException("Internal error in input buffering");
   141         ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
   141         }
   142         ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
       
   143 
   142         int i;
   144         int i;
   143         int endIndex = plainOffset + plainLen;
   145         int endIndex = plainOffset + plainLen;
   144 
   146 
   145         for (; plainOffset < endIndex;
   147         for (; plainOffset < endIndex;
   146              plainOffset += blockSize, cipherOffset += blockSize) {
   148              plainOffset += blockSize, cipherOffset += blockSize) {
   174      * @return the length of the decrypted data
   176      * @return the length of the decrypted data
   175      */
   177      */
   176     int decrypt(byte[] cipher, int cipherOffset, int cipherLen,
   178     int decrypt(byte[] cipher, int cipherOffset, int cipherLen,
   177                 byte[] plain, int plainOffset)
   179                 byte[] plain, int plainOffset)
   178     {
   180     {
   179         if ((cipherLen % blockSize) != 0) {
   181         ArrayUtil.blockSizeCheck(cipherLen, blockSize);
   180              throw new ProviderException("Internal error in input buffering");
   182         ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen);
   181         }
   183         ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen);
       
   184 
   182         int i;
   185         int i;
   183         int endIndex = cipherOffset + cipherLen;
   186         int endIndex = cipherOffset + cipherLen;
   184 
   187 
   185         for (; cipherOffset < endIndex;
   188         for (; cipherOffset < endIndex;
   186              plainOffset += blockSize, cipherOffset += blockSize) {
   189              plainOffset += blockSize, cipherOffset += blockSize) {