ggershinsky commented on code in PR #3231:
URL: https://github.com/apache/iceberg/pull/3231#discussion_r1054066094


##########
core/src/main/java/org/apache/iceberg/encryption/Ciphers.java:
##########
@@ -96,33 +110,45 @@ public AesGcmDecryptor(byte[] keyBytes) {
     }
 
     public byte[] decrypt(byte[] ciphertext, byte[] aad)  {
-      int plainTextLength = ciphertext.length - GCM_TAG_LENGTH - NONCE_LENGTH;
-      Preconditions.checkState(plainTextLength >= 1,
+      return decrypt(ciphertext, 0, ciphertext.length, aad);
+    }
+
+    public byte[] decrypt(byte[] ciphertext, int ciphertextOffset, int 
ciphertextLength, byte[] aad)  {
+      Preconditions.checkState(ciphertextLength - GCM_TAG_LENGTH - 
NONCE_LENGTH >= 1,
           "Cannot decrypt cipher text of length " + ciphertext.length +
           " because text must longer than GCM_TAG_LENGTH + NONCE_LENGTH bytes. 
Text may not be encrypted" +
           " with AES GCM cipher");
 
       // Get the nonce from ciphertext
       byte[] nonce = new byte[NONCE_LENGTH];
-      System.arraycopy(ciphertext, 0, nonce, 0, NONCE_LENGTH);
+      System.arraycopy(ciphertext, ciphertextOffset, nonce, 0, NONCE_LENGTH);
 
-      byte[] plainText = new byte[plainTextLength];
-      int inputLength = ciphertext.length - NONCE_LENGTH;
+      int inputLength = ciphertextLength - NONCE_LENGTH;
       try {
         GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH_BITS, 
nonce);
         cipher.init(Cipher.DECRYPT_MODE, aesKey, spec);
         if (null != aad) {
           cipher.updateAAD(aad);
         }
-        cipher.doFinal(ciphertext, NONCE_LENGTH, inputLength, plainText, 0);
+        return cipher.doFinal(ciphertext, ciphertextOffset + NONCE_LENGTH, 
inputLength);
       }  catch (AEADBadTagException e) {
         throw new RuntimeException("GCM tag check failed. Possible reasons: 
wrong decryption key; or corrupt/tampered" +
-            "data. AES GCM doesn't differentiate between these two.. ", e);
+            "data. AES GCM doesn't differentiate between these two.", e);
       } catch (GeneralSecurityException e) {
         throw new RuntimeException("Failed to decrypt", e);
       }
+    }
+  }
 
-      return plainText;
+  static byte[] streamBlockAAD(byte[] fileAadPrefix, int currentBlockIndex) {
+    byte[] blockAAD = Ints.toByteArray(currentBlockIndex);

Review Comment:
   Agreed, we'll use the same endianness.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to