Skip to content

GH-53776: [C++][Gandiva] Add AES-CBC and AES-GCM support via binary encrypt/decrypt functions - #53815

Open
dmitry-chirkov-dremio wants to merge 7 commits into
apache:mainfrom
dmitry-chirkov-dremio:gandiva-encrypt-decrypt-cbc-gcm
Open

dmitry-chirkov-dremio wants to merge 7 commits into
apache:mainfrom
dmitry-chirkov-dremio:gandiva-encrypt-decrypt-cbc-gcm

Conversation

@dmitry-chirkov-dremio

@dmitry-chirkov-dremio dmitry-chirkov-dremio commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

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.

Reviewed before submission by:

  • Human
  • AI

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53776 has been automatically assigned in GitHub to PR creator.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53776 has no components, please add labels for components.

@dmitry-chirkov-dremio
dmitry-chirkov-dremio force-pushed the gandiva-encrypt-decrypt-cbc-gcm branch from 2c58f9e to a4c81f1 Compare October 15, 2026 02:50
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53776 has no components, please add labels for components.

3 similar comments
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53776 has no components, please add labels for components.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53776 has no components, please add labels for components.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53776 has no components, please add labels for components.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53776 has no components, please add labels for components.

namespace {

// ERR_raise() only exists since OpenSSL 3.0
void RaiseOpenSSLError(int reason) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd love a feedback if this fallback to an earlier OpenSSL version is needed. The oldest OpenSSL in CI is 3.0.2 (Ubuntu 22.04 ARM64).

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant