Fix KeyMaterial::concatenate logic and improve Condition<T> correctness for i64/u64#7
Open
Quant-TheodoreFelix wants to merge 3 commits intobcgit:mainfrom
Open
Fix KeyMaterial::concatenate logic and improve Condition<T> correctness for i64/u64#7Quant-TheodoreFelix wants to merge 3 commits intobcgit:mainfrom
KeyMaterial::concatenate logic and improve Condition<T> correctness for i64/u64#7Quant-TheodoreFelix wants to merge 3 commits intobcgit:mainfrom
Conversation
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Title
Fix
KeyMaterial::concatenatelogic and improveCondition<T>correctness fori64/u64Description
This PR addresses three main issues: a logical bug in
KeyMaterial::concatenateregarding security strength, the missing implementation ofCondition<u64>, and a correctness fix for theCondition<i64>::TRUEconstant.1. Fix func concatenate in KeyMaterial Security Logic
KeyMaterial::concatenatestates that combining a full entropy key with a low entropy key should result in a low entropy key (conserving the weaker security parameters). However, the implementation was usingmax(), which effectively "upgraded" the security strength of the resulting key to the higher of the two inputs.min()for bothkey_typeandsecurity_strengthto strictly adhere to the documentation and safe security modeling principles.2. Implement u64 Condition
Condition<u64>was defined but lacked a concrete implementation, preventing constant-time operations onu64primitives.impl Condition<u64>including:from_boolusing0u64.wrapping_sub(value).TRUEconstant definition asu64::MAX(all-ones) to ensure bitwise operations likeselectwork correctly across all bits.select,is_true, and other helper methods.3. Fix TRUE Constant in i64 Condition
Condition<i64>::TRUEwas previously defined as1. This causedselectandnegatefunctions (which rely on bitwise maskingval & mask) to fail for all bits except the LSB.Condition<i64>::TRUEto-1(all ones in two's complement) to ensure the mask covers the entire integer width.4. Tests
u64_testsinct_tests.rsto verifyCondition<u64>behavior.or_halvesto verify bit-folding logic.selectandnegatelogic behaves correctly with the updatedTRUEconstants.Motivation
To ensure the library adheres to its stated security contract regarding key material degradation and to provide correct, functional constant-time primitives for 64-bit integers.
Checklist
Condition<u64>andor_halves.cargo testpasses.