Skip to content

Fix RSA OKCS OAEP mechanism #165

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

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

wiktor-k
Copy link
Collaborator

Handling of empty data specified was broken.

As specified in "2.1.7 PKCS #1 RSA OAEP mechanism parameters" the CKZ_DATA_SPECIFIED source:

Array of CK_BYTE containing the value of the encoding parameter.
If the parameter is empty, pSourceData must be NULL and ulSourceDataLen
must be zero.

Adjusts by returning std::ptr::null() when the source data has not been specified (PkcsOaepSource::empty() was used) and adds a tests case for this.

One more test case that is ignored is added to handle the case when the data specified is non-empty. Unfortunately this test fails for unknown reasons (I haven't been able to find if SoftHSM supports it or not).

Fixes: #163
Fixes: #164

wiktor-k and others added 3 commits September 12, 2023 10:51
Handling of empty data specified was broken.

As specified in "2.1.7 PKCS parallaxsecond#1 RSA OAEP mechanism parameters" the
`CKZ_DATA_SPECIFIED` source:

> Array of CK_BYTE containing the value of the encoding parameter.
> If the parameter is empty, pSourceData must be NULL and ulSourceDataLen
> must be zero.

Adjusts by returning `std::ptr::null()` when the source data has not
been specified (`PkcsOaepSource::empty()` was used) and adds a tests
case for this.

One more test case that is ignored is added to handle the case when the
data specified is non-empty. Unfortunately this test fails for unknown
reasons (I haven't been able to find if SoftHSM supports it or not).

Fixes: parallaxsecond#163
Fixes: parallaxsecond#164

Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
Co-authored-by: Nachiketh S Ujjainimath <[email protected]>
Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
@probablynachi
Copy link
Contributor

Thank you so much for your quick response and fix!

@wiktor-k
Copy link
Collaborator Author

Thank you so much for your quick response and fix!

No problem. I surveyed existing alternative implementations and started changing stuff here and there and finally your test case succeeded. Thanks for submitting it as this was the critical factor that allowed me to quickly check various things.

(Note that it may take some time until it's reviewed and a new version of the crate is released to crates.io)

See you later! 👋

Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix!

@ionut-arm ionut-arm merged commit 5739579 into parallaxsecond:main Sep 25, 2023
@wiktor-k wiktor-k deleted the add-oaep-test-case branch September 26, 2023 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PKCS OAEP padding always returns: Pkcs11(ArgumentsBad)
4 participants