You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GH-53776: [C++][Gandiva] Add AES-CBC and AES-GCM support via binary encrypt/decrypt functions - #53815
Gandiva's aes_encrypt / aes_decrypt are ECB-only and VARCHAR-based. This adds binary encrypt / decrypt functions with CBC and authenticated GCM modes. See #53776.
What changes are included in this PR?
New encrypt(data, key, mode[, iv[, aad]]) and matching decrypt overloads. All arguments and results are binary except mode, which is utf8:
Modes (case-insensitive): AES-ECB, AES-CBC, AES-GCM, plus -PKCS7 / -NONE variants for ECB and CBC. Keys are 16, 24 or 32 bytes.
CBC needs a 16-byte IV. GCM takes any non-empty IV and optional AAD, appends a 16-byte tag, and verifies it on decryption.
IV and AAD are caller-managed and not embedded in the output. A GCM nonce must never repeat under the same key.
aes_encrypt / aes_decrypt and encrypt_utils.* are not modified.
The commits are layered: ECB, CBC, GCM, functions, projector tests. Start with encrypt_utils_gcm.cc (the IV length must be set before the IV, or OpenSSL uses only the first 12 bytes) and the output buffer sizing in the stubs in gdv_function_stubs.cc.
Are these changes tested?
Yes: unit tests per module, GCM known-answer tests from the GCM specification (test cases 4-6, which fail without the IV fix), stub tests including block-aligned inputs, and projector round-trip and error tests. The full Gandiva internals and projector suites pass locally with clang on macOS.
Are there any user-facing changes?
Yes, two new Gandiva functions, encrypt and decrypt, are available to expression builders. Nothing existing changes.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Human
AI
The original implementation was written by a human engineer in an internal codebase. AI tooling was used to port it onto current main, review it and fix what the review found (GCM IV-length ordering, a context leak on invalid key lengths, length validation and buffer sizing), write the tests, and write this description.
Oh, sorry. A Gandiva developer is already mentioned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Gandiva's
aes_encrypt/aes_decryptare ECB-only and VARCHAR-based. This adds binaryencrypt/decryptfunctions with CBC and authenticated GCM modes. See #53776.What changes are included in this PR?
New
encrypt(data, key, mode[, iv[, aad]])and matchingdecryptoverloads. All arguments and results arebinaryexceptmode, which isutf8:AES-ECB,AES-CBC,AES-GCM, plus-PKCS7/-NONEvariants for ECB and CBC. Keys are 16, 24 or 32 bytes.aes_encrypt/aes_decryptandencrypt_utils.*are not modified.The commits are layered: ECB, CBC, GCM, functions, projector tests. Start with
encrypt_utils_gcm.cc(the IV length must be set before the IV, or OpenSSL uses only the first 12 bytes) and the output buffer sizing in the stubs ingdv_function_stubs.cc.Are these changes tested?
Yes: unit tests per module, GCM known-answer tests from the GCM specification (test cases 4-6, which fail without the IV fix), stub tests including block-aligned inputs, and projector round-trip and error tests. The full Gandiva internals and projector suites pass locally with clang on macOS.
Are there any user-facing changes?
Yes, two new Gandiva functions,
encryptanddecrypt, are available to expression builders. Nothing existing changes.Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
The original implementation was written by a human engineer in an internal codebase. AI tooling was used to port it onto current main, review it and fix what the review found (GCM IV-length ordering, a context leak on invalid key lengths, length validation and buffer sizing), write the tests, and write this description.
Reviewed before submission by: