-
Notifications
You must be signed in to change notification settings - Fork 90
Uncap HKDF salt length restriction #951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
cbc7128 to
47329ec
Compare
47329ec to
79377fb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #951 +/- ##
==========================================
- Coverage 95.80% 92.53% -3.27%
==========================================
Files 61 74 +13
Lines 8143 9855 +1712
Branches 0 9855 +9855
==========================================
+ Hits 7801 9119 +1318
- Misses 342 449 +107
- Partials 0 287 +287 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
79377fb to
e9f3653
Compare
| pub fn new(algorithm: Algorithm, value: &[u8]) -> Self { | ||
| Salt::try_new(algorithm, value).expect("Salt length limit exceeded.") | ||
| Salt::try_new(algorithm, value).expect("Failed to create Salt") | ||
| } | ||
|
|
||
| #[allow(clippy::unnecessary_wraps)] | ||
| fn try_new(algorithm: Algorithm, value: &[u8]) -> Result<Salt, Unspecified> { | ||
| let salt_len = value.len(); | ||
| if salt_len > MAX_HKDF_SALT_LEN { | ||
| return Err(Unspecified); | ||
| } | ||
| let mut salt_bytes = [0u8; MAX_HKDF_SALT_LEN]; | ||
| salt_bytes[0..salt_len].copy_from_slice(value); | ||
| Ok(Self { | ||
| algorithm, | ||
| bytes: salt_bytes, | ||
| len: salt_len, | ||
| }) | ||
| let bytes = value.to_vec().into_boxed_slice(); | ||
| Ok(Self { algorithm, bytes }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think try_new is needed now that we have no effective limit, we can just move this implementation into new.
| // Box<[u8]> implements Zeroize, so we can call it directly | ||
| self.bytes.zeroize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: I think the Salt is a public value, so I'm not sure this is necessary.
Description of changes:
Remove the salt length restriction for HKDF operations by moving the salt bytes field to be a Box'd value.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.