diff --git a/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/DecryptionHandler.java b/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/DecryptionHandler.java index 2079b28402106..92b49680eba40 100644 --- a/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/DecryptionHandler.java +++ b/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/DecryptionHandler.java @@ -41,7 +41,6 @@ /** * This class implementation is referenced from AWS Encryption SDK - * https://tiny.amazon.com/lfkvesll/codeamazpackblobheadamaz4 * * This class implements the CryptoHandler interface by providing methods for the decryption of * ciphertext produced by the methods in {@link EncryptionHandler}. diff --git a/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/FrameDecryptionHandler.java b/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/FrameDecryptionHandler.java index 9645878c9f0dc..006dc0f814c35 100644 --- a/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/FrameDecryptionHandler.java +++ b/libs/encryption-sdk/src/main/java/org/opensearch/encryption/frame/core/FrameDecryptionHandler.java @@ -20,7 +20,6 @@ /** * This class implementation has been referenced from AWS encryption SDK. - * https://tiny.amazon.com/1j988pk3f/codeamazpackblobheadamaz4 * * The frame decryption handler is a subclass of the decryption handler and thereby provides an * implementation of the Cryptography handler. @@ -235,10 +234,7 @@ public static long estimateDecryptedSize(long encryptedSize, int frameSize, int long frames = (encryptedSize - lastFrameHeaderOverhead) / (frameSize + nonceLen + tagLenBytes + (Integer.SIZE / Byte.SIZE)) + 1; // Calculate the size of the actual content in frames - long contentSize = frames * frameSize; - - // Calculate the size of the last frame - long lastFrameSize = 0; + long contentSizeWithoutLastFrame = (frames - 1) * frameSize; // Calculate the sequence number size for all frames long seqNumberSize = frames * (Integer.SIZE / Byte.SIZE); @@ -247,9 +243,9 @@ public static long estimateDecryptedSize(long encryptedSize, int frameSize, int long headerOverhead = (nonceLen + tagLenBytes) * frames + seqNumberSize; // Calculate the size of the last frame content - lastFrameSize = encryptedSize - contentSize - headerOverhead - lastFrameHeaderOverhead; + long lastFrameSize = encryptedSize - contentSizeWithoutLastFrame - headerOverhead - lastFrameHeaderOverhead; - return contentSize + lastFrameSize; + return contentSizeWithoutLastFrame + lastFrameSize; } @Override