src/share/classes/com/sun/crypto/provider/CipherBlockChaining.java

Print this page
8012900: CICO ignores AAD in GCM mode

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -133,12 +133,13 @@
      * @param plain the buffer with the input data to be encrypted
      * @param plainOffset the offset in <code>plain</code>
      * @param plainLen the length of the input data
      * @param cipher the buffer for the result
      * @param cipherOffset the offset in <code>cipher</code>
+     * @return the length of the encrypted data
      */
-    void encrypt(byte[] plain, int plainOffset, int plainLen,
+    int encrypt(byte[] plain, int plainOffset, int plainLen,
                  byte[] cipher, int cipherOffset)
     {
         int i;
         int endIndex = plainOffset + plainLen;
 

@@ -148,10 +149,11 @@
                 k[i] = (byte)(plain[i+plainOffset] ^ r[i]);
             }
             embeddedCipher.encryptBlock(k, 0, cipher, cipherOffset);
             System.arraycopy(cipher, cipherOffset, r, 0, blockSize);
         }
+        return plainLen;
     }
 
     /**
      * Performs decryption operation.
      *

@@ -172,16 +174,17 @@
      * @param cipher the buffer with the input data to be decrypted
      * @param cipherOffset the offset in <code>cipherOffset</code>
      * @param cipherLen the length of the input data
      * @param plain the buffer for the result
      * @param plainOffset the offset in <code>plain</code>
+     * @return the length of the decrypted data
      *
      * @exception IllegalBlockSizeException if input data whose length does
      * not correspond to the embedded cipher's block size is passed to the
      * embedded cipher
      */
-    void decrypt(byte[] cipher, int cipherOffset, int cipherLen,
+    int decrypt(byte[] cipher, int cipherOffset, int cipherLen,
                  byte[] plain, int plainOffset)
     {
         int i;
         byte[] cipherOrig=null;
         int endIndex = cipherOffset + cipherLen;

@@ -193,11 +196,10 @@
             // This is necessary because in this constellation, a
             // ciphertext block (or parts of it) will be overridden by
             // the plaintext result.
             cipherOrig = cipher.clone();
         }
-
         for (; cipherOffset < endIndex;
              cipherOffset += blockSize, plainOffset += blockSize) {
             embeddedCipher.decryptBlock(cipher, cipherOffset, k, 0);
             for (i = 0; i < blockSize; i++) {
                 plain[i+plainOffset] = (byte)(k[i] ^ r[i]);

@@ -206,7 +208,8 @@
                 System.arraycopy(cipher, cipherOffset, r, 0, blockSize);
             } else {
                 System.arraycopy(cipherOrig, cipherOffset, r, 0, blockSize);
             }
         }
+        return cipherLen;
     }
 }