Skip to content

Add AES/GCM-SIV/NoPadding cipher support (RFC 8452) - #533

Open
jmcrawford45 wants to merge 9 commits into
corretto:mainfrom
jmcrawford45:jcrawford/issue-323-aes-gcm-siv
Open

Add AES/GCM-SIV/NoPadding cipher support (RFC 8452)#533
jmcrawford45 wants to merge 9 commits into
corretto:mainfrom
jmcrawford45:jcrawford/issue-323-aes-gcm-siv

Conversation

@jmcrawford45

Copy link
Copy Markdown

Issue #, if available: #323

Description of changes:

Implements AES-GCM-SIV (AES/GCM-SIV/NoPadding, AES_128/GCM-SIV/NoPadding, AES_256/GCM-SIV/NoPadding) backed by the AWS-LC EVP_AEAD API (EVP_aead_aes_128_gcm_siv / EVP_aead_aes_256_gcm_siv).

AES-GCM-SIV is a nonce-misuse-resistant AEAD cipher defined in
[RFC 8452](https://www.rfc-editor.org/rfc/rfc8452). Unlike AES-GCM, reusing a key+nonce pair does not compromise authenticity, only (some) confidentiality.


New files

  • csrc/aes_gcm_siv.cpp
    JNI implementation using EVP_AEAD_CTX_seal / EVP_AEAD_CTX_open. Context caching
    avoids redundant key schedule computation across calls with the same key.

  • src/.../AesGcmSivSpi.java
    CipherSpi implementation. Supports one-shot (doFinal) and streaming
    (update + doFinal) modes, heap and direct ByteBuffer, and AAD via updateAAD.

  • src/.../NativeEvpAeadCtx.java
    NativeResource wrapper for safe GC cleanup of native EVP_AEAD_CTX pointers.

  • benchmarks/.../AesGcmSivOneShot.java
    JMH benchmark for 1 MiB encrypt and decrypt with 128-bit and 256-bit keys.


Modified files

  • AmazonCorrettoCryptoProvider.java
    Registers the three algorithm aliases.

  • Utils.java / csrc/util.cpp
    Adds releaseEvpAeadCtx JNI teardown.

  • CMakeLists.txt
    Adds aes_gcm_siv.cpp to the native source list.

  • tst/.../AesGcmSivTest.java
    Full test suite:

    • All 28 RFC 8452 Appendix C KAT vectors (encrypt + decrypt)
    • Behavioral tests (ByteBuffer heap/direct, getOutputSize, 1 MiB round-trip, rekey,
      nonce-reuse tolerance, AAD ordering, tag authentication, algorithm name variants,
      16-thread concurrency)
  • README.md / DIFFERENCES.md
    Documents the new algorithm and its behavioral differences from AES/GCM/NoPadding
    (no IvParameterSpec, fixed 12-byte nonce, 128-bit tag only, 128/256-bit keys only,
    nonce reuse does not throw).


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute
this contribution, under the terms of your choice.

jmcrawford45 and others added 4 commits April 15, 2026 17:12
Implements GitHub issue corretto#323. Registers three algorithm names:
  - AES/GCM-SIV/NoPadding
  - AES_128/GCM-SIV/NoPadding
  - AES_256/GCM-SIV/NoPadding

New files:
  - csrc/aes_gcm_siv.cpp: JNI implementation using EVP_AEAD_CTX_seal/open
  - src/.../AesGcmSivSpi.java: CipherSpi — one-shot AEAD, 12-byte nonce,
    128-bit tag, 128/256-bit keys only; nonce reuse does not throw
  - src/.../NativeEvpAeadCtx.java: NativeResource wrapper for EVP_AEAD_CTX

Modified files:
  - csrc/util.cpp: add releaseEvpAeadCtx JNI function
  - src/.../Utils.java: declare releaseEvpAeadCtx native method
  - src/.../AmazonCorrettoCryptoProvider.java: register the three aliases
  - CMakeLists.txt: add csrc/aes_gcm_siv.cpp to the build

Tests: 40 cases covering RFC 8452 Appendix C KAT vectors, round-trips,
streaming buffering, auth failure (AEADBadTagException), parameter
validation, nonce-reuse tolerance, and algorithm name variants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add AES/GCM-SIV/NoPadding and AES_<n>/GCM-SIV/NoPadding to README
  supported algorithms list
- Document GCM-SIV behavioral differences in DIFFERENCES.md: rejects
  IvParameterSpec, enforces fixed nonce/tag length, tolerates nonce reuse
- Add AesGcmSivOneShot JMH benchmark (128/256-bit, 1 MiB, encrypt+decrypt)
- Expand AesGcmSivTest with 8 behavioral tests: ByteBuffer (heap+direct),
  getOutputSize (encrypt+decrypt), large 1 MiB round-trip, rekey changes
  output, AAD-after-update throws IllegalStateException, concurrent 16-thread
  encrypt/decrypt correctness

Closes corretto#323

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Mirrors AesGcmOneShot structure: extends AesBase, uses provider @PARAM
with ACCP and BouncyCastle (both support AES/GCM-SIV/NoPadding). SunJCE
is excluded because JDK-8256530 (add GCM-SIV to SunJCE) is still open.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jmcrawford45
jmcrawford45 requested a review from a team as a code owner April 15, 2026 22:12
@geedo0

geedo0 commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

/codebuild_run(e5d569f)

@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.29467% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.49%. Comparing base (a74cb49) to head (4351242).

Files with missing lines Patch % Lines
.../amazon/corretto/crypto/provider/AesGcmSivSpi.java 71.64% 38 Missing and 19 partials ⚠️
csrc/aes_gcm_siv.cpp 80.37% 16 Missing and 5 partials ⚠️
.../crypto/provider/AmazonCorrettoCryptoProvider.java 42.85% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #533      +/-   ##
============================================
- Coverage     78.60%   78.49%   -0.12%     
- Complexity     1186     1239      +53     
============================================
  Files           123      126       +3     
  Lines          7538     7857     +319     
  Branches        953      993      +40     
============================================
+ Hits           5925     6167     +242     
- Misses         1096     1150      +54     
- Partials        517      540      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@geedo0

geedo0 commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

The CI is failing on Linux platforms, the "AI em-dash" strikes again. We should adapt the build scripts to not barf on valid unicode, but for now let's just scrub this code for these problematic characters and use the plain ASCII '-' character.

/codebuild/output/src1217243364/src/github.com/corretto/amazon-corretto-crypto-provider/tst/com/amazon/corretto/crypto/provider/test/AesGcmSivTest.java:65: error: unmappable character (0xE2) for encoding US-ASCII
  // RFC 8452 Appendix C.1 ??? AEAD_AES_128_GCM_SIV

jmcrawford45 and others added 2 commits April 29, 2026 12:07
Replace em/en-dash Unicode characters in comments with ASCII hyphens to
fix CI compilation failure on Linux with US-ASCII encoding.

Add tests covering previously uncovered SPI paths: random-nonce init,
AlgorithmParameters init, engineGetIV/getParameters, ByteBuffer AAD
(array-backed and direct), wrap/unwrap, short-ciphertext decrypt, and
same-key native context caching (save and reuse paths).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
GCMParameterSpec is still preferred, but IvParameterSpec with exactly
12 bytes is accepted as a convenience fallback — consistent with
AesGcmSpi and with BouncyCastle's GCM-SIV implementation, which uses
IvParameterSpec in its own test suite.

Also add wrap/unwrap round-trip test to cover those code paths.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@jmcrawford45
jmcrawford45 force-pushed the jcrawford/issue-323-aes-gcm-siv branch from 5749e62 to e7011db Compare April 29, 2026 16:59
@jmcrawford45

Copy link
Copy Markdown
Author

The CI is failing on Linux platforms, the "AI em-dash" strikes again. We should adapt the build scripts to not barf on valid unicode, but for now let's just scrub this code for these problematic characters and use the plain ASCII '-' character.

/codebuild/output/src1217243364/src/github.com/corretto/amazon-corretto-crypto-provider/tst/com/amazon/corretto/crypto/provider/test/AesGcmSivTest.java:65: error: unmappable character (0xE2) for encoding US-ASCII
  // RFC 8452 Appendix C.1 ??? AEAD_AES_128_GCM_SIV

Thank you for considering my PR and taking a look. This should be fixed now. I've also added some more test coverage to make the build happy.

@geedo0

geedo0 commented May 4, 2026

Copy link
Copy Markdown
Contributor

/codebuild_run(4351242)

@jmcrawford45

Copy link
Copy Markdown
Author

@geedo0 @WillChilds-Klein thank you again for taking a look at the PR. I’ll be OOO for a couple of weeks starting next Monday, so if anything stands out before then, I’m happy to take a look. Otherwise, no rush at all and we can pick it up when I’m back.

@jmcrawford45

Copy link
Copy Markdown
Author

Hi @geedo0 @WillChilds-Klein I'm back from OOO and picking this up again. Whenever you get a chance for another look I'm happy to address feedback. Thanks!

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.

3 participants