keymgmt: fix HKDF salt parameter validation per PKCS#11 spec#481
Merged
Conversation
Jakuje
approved these changes
Jul 15, 2026
Jakuje
left a comment
Contributor
There was a problem hiding this comment.
i am not much fan of this syntax, but if cargo fmt does not complain, I will not complain either.
Contributor
Author
@Jakuje This was the original I disliked redundancy of the result, but It is more readable. Should i replace it back? |
Contributor
|
the first match is clearly redundant, the second needs the pSaltLen check, but otherwise I would find this more readable: match params.ulSaltType {
CKF_HKDF_SALT_DATA => {
if params.pSalt.is_null() || params.ulSaltLen == 0 {
return Err(CKR_MECHANISM_PARAM_INVALID)?;
}
}
CKF_HKDF_SALT_KEY => {
if params.hSaltKey == CK_INVALID_HANDLE {
return Err(CKR_MECHANISM_PARAM_INVALID)?;
}
}
_ => {
return Err(CKR_MECHANISM_PARAM_INVALID)?;
}
} |
Contributor
Author
|
yeah the NULL check is pretty redundant... I will use your proposal Thanks! |
The previous version blocked the usage of CKF_HKDF_KEY which is not blocked by pkcs#11 standard and was causing issues. Replace the null-salt check in CKM_HKDF_DERIVE with proper per-type validation of CK_HKDF_PARAMS.ulSaltType as defined in PKCS#11 v3.0 §2.30.2: - CKF_HKDF_SALT_DATA: require non-null pSalt with ulSaltLen > 0 - CKF_HKDF_SALT_KEY: require a valid hSaltKey handle - All other salt types (including CKF_HKDF_SALT_NULL): reject with CKR_MECHANISM_PARAM_INVALID
FrantisekKrenzelok
force-pushed
the
cko_data
branch
from
July 16, 2026 09:49
2ff4258 to
d304897
Compare
Jakuje
approved these changes
Jul 16, 2026
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.
The previous version blocked the usage of CKF_HKDF_KEY which is not blocked by pkcs#11 standard and was causing issues.
Replace the null-salt check in CKM_HKDF_DERIVE with proper per-type validation of CK_HKDF_PARAMS.ulSaltType as defined in PKCS#11 v3.0 §2.30.2:
Description
Checklist
Reviewer's checklist: