Enhancement/331 move to 256 bit entropy aes - #332
Merged
PropzSaladaz merged 5 commits intoSep 23, 2026
Merged
PropzSaladaz merged 5 commits into
PropzSaladaz merged 5 commits into
Conversation
…tionVersion struct
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved critical and moderate serialization and version-validation issues remain.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR introduces versioned V0/V1 threshold-encryption formats, enables full-entropy V1 masking by default, preserves V0 compatibility, and updates deterministic AES-GCM profiles.
Changes:
- Adds version-aware masking, headers, key handling, and encryption profiles.
- Retains legacy V0 decryption and explicit V0 production.
- Expands compatibility, round-trip, parsing, and CTest coverage.
| File | Reviewed change |
|---|---|
threshold_encryption/ThresholdEncryption.cpp |
Applies version-aware masking during decryption. |
threshold_encryption/threshold_encryption.h |
Exposes encryption profiles and versioned APIs. |
threshold_encryption/threshold_encryption.cpp |
Implements profile resolution and mask derivation. Moderate (1 vote): unsupported TEVersion values should be rejected instead of treated as V1. |
threshold_encryption/TEVersion.h |
Defines threshold-encryption format versions. |
threshold_encryption/EncryptionVersion.h |
Defines caller-facing encryption profiles. |
threshold_encryption/CMakeLists.txt |
Registers headers and test executables. |
threshold_encryption/Ciphertext.h |
Adds versioned ciphertext metadata. Nit (1 vote): clarify that V1 changes mask entropy, not AES-key entropy. |
threshold_encryption/Ciphertext.cpp |
Implements versioned header serialization and parsing. Critical (2 votes): reject key counts other than 1 or 2 before serialization. Moderate (1 vote): validate versions before comparing embedded keys. |
threshold_encryption/CipheredKey.h |
Adds key version tracking. Moderate (1 vote): toBytes() omits the version, causing standalone deserialization to default legacy keys to V1. |
threshold_encryption/CipheredKey.cpp |
Propagates versions during key parsing and creation. |
threshold_encryption/AesGcmCipher.h |
Updates AES-GCM version declarations and defaults. |
threshold_encryption/AesGcmCipher.cpp |
Updates deterministic IV derivation handling. |
test/unit_tests_te.cpp |
Adds masking, version, and header compatibility tests. |
test/test_TE_wrappers.cpp |
Adds V0/V1 integration and fixture round-trip tests. |
test/legacy_v0_fixtures.h |
Provides frozen legacy V0 ciphertext fixtures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
badrogger
approved these changes
Sep 23, 2026
PropzSaladaz
merged commit Sep 23, 2026
762cc08
into
enhancement/security-hardening
18 of 19 checks passed
PropzSaladaz
deleted the
enhancement/331-move-to-256-bit-entropy-aes
branch
September 23, 2026 16:36
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

Description
This PR hardens threshold encryption’s AES-key encapsulation.
The AES key has always been 256 bits long, but the legacy V0 masking logic used the first 32 ASCII characters of a SHA-256 hex digest. That provided only 128 bits of mask entropy. V1 instead uses the 32 raw SHA-256 bytes, providing the full 256 bits of entropy.
To preserve wire compatibility, ciphertexts now carry a version in their existing one-byte header:
This preserves historic V0 header values (
0x01and0x02) and introduces V1 headers (0x05and0x06). Ciphertext size is unchanged.The high-level encryption API now uses one caller-facing profile:
libBLS::EncryptMetaData metadata; metadata.encryptionVersion = libBLS::EncryptionVersion::V1;The profile maps internally to the appropriate TE and deterministic AES-GCM behavior (see #330 ):
EncryptionVersion::V0→TEVersion::V0andAesGcmVersion::V0EncryptionVersion::V1→TEVersion::V1andAesGcmVersion::V1EncryptionVersionaffects the TE wire format and masking for bothencrypt()andencryptDeterministic(). The AES-GCM version only affects deterministic IV derivation, so it only changesencryptDeterministic()output.New encryption defaults to V1. Callers can explicitly select V0 through metadata only when they deliberately need to produce legacy-compatible ciphertexts.
New libBLS versions can parse, validate, and decrypt both V0 and V1 ciphertexts. Parsed ciphertexts retain their version, so share combination and key validation automatically use the correct V0 or V1 mask derivation. Ciphertexts with an outer-header version that disagrees with an embedded key version are rejected.
Compatibility and breaking changes
Wire compatibility is one-way:
Existing high-level
encrypt()andencryptDeterministic()call signatures remain unchanged, but their default output is now V1.EncryptMetaData::aesGcmVersionhas been replaced byEncryptMetaData::encryptionVersion. This prevents callers from selecting incompatible TE and AES-GCM combinations.Direct
AesGcmCipherusers must update explicit enum values:AesGcmVersion::V1→ newAesGcmVersion::V0AesGcmVersion::V2→ newAesGcmVersion::V1Distributed systems using
encryptDeterministic()must pinmetadata.encryptionVersionin their protocol or epoch configuration. Nodes using different profiles will intentionally produce different ciphertext bytes for the same seed and plaintext.Test coverage
Fixes #331