Skip to content
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

Add bindings for multi-part operations #252

Merged
merged 13 commits into from
Mar 28, 2025

Conversation

jacobprudhomme
Copy link
Contributor

@jacobprudhomme jacobprudhomme commented Mar 27, 2025

Author: Jacob Prud'homme
Email: [email protected]

Description

This PR adds direct bindings for the multi-part operations C_{Encrypt,Decrypt,Sign,Verify,Digest}{Init,Update,Final}. Closes #250

Summary of Changes

  • Added encrypt_{initialize,update,finalize}() to session/encryption.rs
  • Added decrypt_{initialize,update,finalize}() to session/decryption.rs
  • Added {sign,verify}_{initialize,update,finalize}() to session/signing_macing.rs
  • Added digest_{initialize,update,finalize}() to session/digesting.rs
  • Added tests for all of the above to tests/basic.rs

Questions/Feedback Wanted

  • Are there any strong feelings about the naming (e.g. would initialize_encrypt() be preferred over encrypt_initialize()?)? I did things this way so that it was more discoverable, in that a user could start typing encrypt and would see all of the encrypt operations grouped together
  • I added tests for the sad-path cases of calling an update/finalize operation before it was initialized and initializing an operation that's already in progress. Should I delete these, given that this is an implementation detail of the underlying PKCS#11 device and not this library itself?
  • Do any version number changes need to be made manually?
  • Should I add myself to CONTRIBUTORS.md as mentioned here? Or is that only for long-term/consistent contributors? (Sorry if that's a silly question! This is my first time contributing to an open-source project in a more substantial way)

Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

This looks really good, good job ⭐ ! Very nice with all the tests that you added too! Definitely a good step to have in the code and then we can decide later if we want to add more typing to check the multi-part sequence at compile time.

Are there any strong feelings about the naming

I like your thinking about discoverability! My only opinion would be to match with the PKCS11 shorter names and have for example with decrypt: decrypt_init and decrypt_final?

Should I delete these, given that this is an implementation detail of the underlying PKCS#11 device and not this library itself?

I don't think so! Those are really good and are actually not implementation details since they are written in the spec:

The message-digesting operation MUST have been initialized with C_DigestInit.

so perfectly sensible to check that :)

Do any version number changes need to be made manually?

We will do that ourselves when we decide to make a new release!

Should I add myself to CONTRIBUTORS.md as mentioned here?

No requirement on our side! That is only if you want it :) I think the original reason is to have people behind what the copyright notice says.

@jacobprudhomme
Copy link
Contributor Author

@hug-dev thanks for the feedback! I changed the function names as you suggested and applied the lint fixes that were preventing CI from passing :)

hug-dev
hug-dev previously approved these changes Mar 28, 2025
Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

Thanks!

@jacobprudhomme
Copy link
Contributor Author

Sorry, it seems there was another CI error to fix. Should all be good now!

@hug-dev hug-dev requested a review from wiktor-k March 28, 2025 12:22
Copy link
Collaborator

@wiktor-k wiktor-k left a comment

Choose a reason for hiding this comment

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

This looks very clean and nice, thank you! 👍

Would you mind rebasing this on top of main? We recently landed a big PR and I wonder if it'll all work together nicely :)

(if @hug-dev want to merge it and potentially collect the pieces of the merge I'm fine with that too 😅 )

Signed-off-by: Jacob Prud'homme <[email protected]>
Signed-off-by: Jacob Prud'homme <[email protected]>
I found out it was not that multi-part encryption/decryption weren't supported *at all*, it's that they're just supported for symmetric schemes

Signed-off-by: Jacob Prud'homme <[email protected]>
Signed-off-by: Jacob Prud'homme <[email protected]>
Signed-off-by: Jacob Prud'homme <[email protected]>
@jacobprudhomme
Copy link
Contributor Author

Just rebased off of main!

@wiktor-k wiktor-k enabled auto-merge March 28, 2025 12:41
@wiktor-k wiktor-k merged commit 4d6b18e into parallaxsecond:main Mar 28, 2025
7 of 8 checks passed
@jacobprudhomme jacobprudhomme deleted the multipart-operations branch March 28, 2025 12:45
@wiktor-k
Copy link
Collaborator

Ugh... it seems I screwed it up this time by pressing "Enable auto-merge" but Run tests against Kryoptic is not Required for merging... ugh... maybe I'll just... 😶‍🌫️

@jacobprudhomme
Copy link
Contributor Author

jacobprudhomme commented Mar 28, 2025

Ouff... I know what's causing the issue too. All the keys I created during my tests had the bare minimum template attributes necessary to not trigger an error from SoftHSM (for example, not setting Attribute::{Encrypt,Decrypt,Sign,Verify}(true)). It seems either Kryoptic is more strict about requiring these attributes, or it doesn't set them to their defaults?

Should I open another PR to fix this?

@wiktor-k
Copy link
Collaborator

Should I open another PR to fix this?

If you could that'd be really appreciated 🙏

@hug-dev
Copy link
Member

hug-dev commented Mar 29, 2025

Added the missing CI checks as required now!

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.

Support for multi-part operations
3 participants