src/java.base/share/classes/com/sun/crypto/provider/CipherFeedback.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  * This class represents ciphers in cipher-feedback (CFB) mode.
    33  * This class represents ciphers in cipher-feedback (CFB) mode.
    33  *
    34  *
    34  * <p>This mode is implemented independently of a particular cipher.
    35  * <p>This mode is implemented independently of a particular cipher.
   147      * a multiple of the <code>numBytes</code>
   148      * a multiple of the <code>numBytes</code>
   148      * @return the length of the encrypted data
   149      * @return the length of the encrypted data
   149      */
   150      */
   150     int encrypt(byte[] plain, int plainOffset, int plainLen,
   151     int encrypt(byte[] plain, int plainOffset, int plainLen,
   151                 byte[] cipher, int cipherOffset) {
   152                 byte[] cipher, int cipherOffset) {
   152         if ((plainLen % numBytes) != 0) {
   153         ArrayUtil.blockSizeCheck(plainLen, numBytes);
   153             throw new ProviderException("Internal error in input buffering");
   154         ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
   154         }
   155         ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
   155 
   156 
   156         int nShift = blockSize - numBytes;
   157         int nShift = blockSize - numBytes;
   157         int loopCount = plainLen / numBytes;
   158         int loopCount = plainLen / numBytes;
   158 
   159 
   159         for (; loopCount > 0 ;
   160         for (; loopCount > 0 ;
   223      * a multiple of the <code>numBytes</code>
   224      * a multiple of the <code>numBytes</code>
   224      * @return the length of the decrypted data
   225      * @return the length of the decrypted data
   225      */
   226      */
   226     int decrypt(byte[] cipher, int cipherOffset, int cipherLen,
   227     int decrypt(byte[] cipher, int cipherOffset, int cipherLen,
   227                 byte[] plain, int plainOffset) {
   228                 byte[] plain, int plainOffset) {
   228         if ((cipherLen % numBytes) != 0) {
   229 
   229             throw new ProviderException("Internal error in input buffering");
   230         ArrayUtil.blockSizeCheck(cipherLen, numBytes);
   230         }
   231         ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen);
       
   232         ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen);
   231 
   233 
   232         int nShift = blockSize - numBytes;
   234         int nShift = blockSize - numBytes;
   233         int loopCount = cipherLen / numBytes;
   235         int loopCount = cipherLen / numBytes;
   234 
   236 
   235         for (; loopCount > 0;
   237         for (; loopCount > 0;