ffacs opened a new pull request, #12539:
URL: https://github.com/apache/arrow-rs/pull/12539

   # Which issue does this PR close?
   
   - Closes #7258
   
   # Rationale for this change
   
   Parquet modular encryption specifies both `AES_GCM_V1` and `AES_GCM_CTR_V1` 
as well as 128-, 192-, and 256-bit AES keys. Previously `parquet` only 
supported `AES_GCM_V1` with 128- and 256-bit keys (via `ring`), returning 
`ParquetError::NYI` for `AES_GCM_CTR_V1` files and rejecting 24-byte AES-192 
keys.
   
   To add `AES_GCM_CTR_V1` and AES-192 support while preserving 
`wasm32-unknown-unknown` compatibility and avoiding a C/CMake build dependency 
(such as `aws-lc-rs`), this PR keeps `ring` for 128/256-bit AES-GCM and adds 
pure-Rust `aes-gcm` (`0.10.3`, `default-features = false, features = ["aes"]`) 
and `ctr` (`0.9.2`, `default-features = false`) under the `encryption` feature 
for AES-192-GCM and AES-128/192/256-CTR.
   
   # What changes are included in this PR?
   
   - **Dependencies & docs**:
     - Add optional `aes-gcm` and `ctr` crates to the `encryption` feature in 
`parquet/Cargo.toml` and update `parquet/README.md`.
   - **Ciphers (`parquet/src/encryption/ciphers.rs`)**:
     - Replace `RingGcmBlockDecryptor` / `RingGcmBlockEncryptor` with `GcmKey` 
/ `GcmBlockEncryptor`, dispatching 16- and 32-byte keys to `ring` and 24-byte 
keys to `aes-gcm` (`AesGcm<Aes192, U12>`).
     - Add `CtrKey` and `CtrBlockEncryptor` (reusing `CounterNonce`) 
implementing Parquet's AES-CTR framing (`[4-byte LE length][12-byte 
nonce][ciphertext]` with 16-byte IV `nonce || 0x00000001` and big-endian 32-bit 
counter `Ctr32BE`).
   - **Read & write paths**:
     - Add `EncryptionPropertiesBuilder::with_aes_gcm_ctr_v1(mut self) -> Self` 
to configure `AES_GCM_CTR_V1` when writing encrypted Parquet files.
     - Encrypt page bodies (`DataPage`, `DataPageV2`, `DictionaryPage`) with 
`CtrBlockEncryptor` in `PageEncryptor` while keeping page headers and all 
metadata modules encrypted with AES-GCM.
     - Support `EncryptionAlgorithm::AES_GCM_CTR_V1` in `FileDecryptor`, 
`CryptoContext`, `MetadataObjectWriter`, and `parquet_metadata_with_encryption` 
(including `supply_aad_prefix`).
     - Fix `SerializedPageReaderContext::read_page_header` to decrypt page 
headers with `metadata_decryptor()` (GCM) instead of `data_decryptor()` (which 
is CTR under `AES_GCM_CTR_V1`).
     - Unify internal Thrift structs `AesGcmV1` and `AesGcmCtrV1` into 
`AesParameters`.
   
   # Are these changes tested?
   
   Yes:
   - Enabled existing sync and async `parquet-testing` `AES_GCM_CTR_V1` 
integration tests (`test_aes_ctr_encryption` in 
`parquet/tests/encryption/encryption.rs` and `encryption_async.rs`), replacing 
the previous `NYI` assertions with full read verification.
   - Added cipher unit tests in `parquet/src/encryption/ciphers.rs`:
     - NIST SP 800-38D Test Case 9 known-answer test for AES-192-GCM.
     - OpenSSL-verified known-answer tests for AES-128/192/256-CTR with 
Parquet's `nonce || 1` IV over multi-block + partial-tail input.
     - Multi-length CTR round-trip and GCM negative tests across 16/24/32-byte 
keys.
   - Added integration tests in `parquet/tests/encryption/encryption.rs`:
     - `test_aes192_and_ctr_roundtrip`: matrix over 16/24/32-byte keys, 
`AES_GCM_V1` vs `AES_GCM_CTR_V1`, encrypted vs plaintext footer, uniform vs 
column keys, multiple pages, dictionary encoding, page index, and `DataPageV2`.
     - `test_aes_gcm_ctr_v1_uses_ctr_for_pages_and_gcm_for_headers`: verifies 
written CTR pages omit the 16-byte GCM tag, tampering with page headers fails 
GCM authentication, and tampering with page bodies behaves as unauthenticated 
CTR vs authenticated GCM.
     - `test_aes192_invalid_keys_and_signatures`: verifies AES-192 wrong footer 
key, wrong AAD prefix, and wrong column key error handling.
   
   # Are there any significant user-facing changes?
   
   - New public method: 
`parquet::encryption::encrypt::EncryptionPropertiesBuilder::with_aes_gcm_ctr_v1(self)
 -> Self`.
   - The `encryption` Cargo feature of `parquet` now also pulls in `aes-gcm` 
and `ctr` (with `default-features = false`).
   - Invalid AES key length error message changed from `Error creating 
RingGcmBlockDecryptor with unsupported key length: <len>` to `Unsupported AES 
key length: <len>` (updated in `parquet/tests/encryption/encryption_async.rs`).
   
   # AI usage disclosure
   
   AI assistance was used for code review, refactoring CTR encryption to reuse 
`CounterNonce`, and generating unit/integration tests (including KAT vectors 
verified independently against OpenSSL). All changes were reviewed and tested 
locally.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to