Skip to content

Comments

Fix AES-GCM edge cases to allow for null input or output arrays#145

Merged
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:gcmNullPlaintext
Aug 27, 2025
Merged

Fix AES-GCM edge cases to allow for null input or output arrays#145
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:gcmNullPlaintext

Conversation

@cconlon
Copy link
Member

@cconlon cconlon commented Aug 26, 2025

This PR fixes both JNI and JCE levels for AES-GCM usage to allow for the cases where a user may pass in a null input/plaintext, or provide a null output buffer. These are scenarios where a user may provide Additional Authenticated Data during encrypt() to generate an auth tag.

JUnit test cases have been added for regression prevention.

This fixes the OpenJDK SunJCE test: crypto/provider/Cipher/AES/TestKATForGCM.java

@cconlon cconlon self-assigned this Aug 26, 2025
@cconlon cconlon requested a review from Copilot August 26, 2025 19:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes AES-GCM edge cases to handle null input/output arrays for scenarios where users only provide Additional Authenticated Data (AAD) to generate authentication tags. The changes ensure compatibility with OpenJDK SunJCE test requirements.

Key changes:

  • Modified JNI validation logic to allow null plaintext/ciphertext when only generating authentication tags
  • Updated JCE cipher implementation to handle null input arrays correctly during encryption/decryption
  • Added comprehensive test cases for null plaintext scenarios with and without AAD

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
jni/jni_aesgcm.c Updated input validation to allow null input arrays for GMAC operations
src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Added null-safety check before array copy operations
src/test/java/com/wolfssl/wolfcrypt/test/AesGcmTest.java Updated existing tests and added new test cases for null plaintext scenarios
src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java Added JCE-level test cases for null plaintext with OpenJDK test vectors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@cconlon cconlon assigned rlm2002 and unassigned cconlon Aug 26, 2025
Copy link
Contributor

@rlm2002 rlm2002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The branch conflicts just need to be resolved.

@rlm2002 rlm2002 assigned cconlon and unassigned rlm2002 Aug 26, 2025
@cconlon cconlon assigned rlm2002 and unassigned cconlon Aug 27, 2025
@rlm2002 rlm2002 merged commit 32498c6 into wolfSSL:master Aug 27, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants