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

feat: add HKDF mechanisms #227

Merged
merged 4 commits into from
Oct 23, 2024
Merged

feat: add HKDF mechanisms #227

merged 4 commits into from
Oct 23, 2024

Conversation

Direktor799
Copy link
Contributor

Add HKDF mechanisms to cryptoki and cryptoki-sys. The mechanisms were defined in PKCS#11 v3.0.

I found that SoftHSM doesn't support such mechanisms so I couldn't write any unit test. But I did run some CKM_HKDF_DERIVE tests against our own HSM and it works.

@hug-dev
Copy link
Member

hug-dev commented Oct 14, 2024

Thank you!! As a prerequisite to this PR maybe we should agree and go on with #156 so that we use v3.0 and then merge your changes based on that?

@wiktor-k
Copy link
Collaborator

Thank you!! As a prerequisite to this PR maybe we should agree and go on with #156 so that we use v3.0 and then merge your changes based on that?

That's a good idea. This PR unnecessarily couples the HKDF and the 3.0 change that maybe should be there in the first place. Does #156 also solve the "unofficial OASIS header" issue reported at #66? If so maybe we need some acks from other maintainers that the licensing looks good in #156 and then rebase this on top of master (when #156 is done).

@hug-dev would you ask in #parsec if everyone is OK with this approach? 🙏

@Direktor799
Copy link
Contributor Author

Thank you!! As a prerequisite to this PR maybe we should agree and go on with #156 so that we use v3.0 and then merge your changes based on that?

That will be nice, thank you!

@hug-dev
Copy link
Member

hug-dev commented Oct 14, 2024

@hug-dev would you ask in #parsec if everyone is OK with this approach? 🙏

Yes! Also pinged on the related PR to use another free source of headers.

wiktor-k
wiktor-k previously approved these changes Oct 23, 2024
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.

In general this looks good, just a couple of nits.

Btw it seems softhsm does not implement HKDF which is sad :(

use super::MechanismType;

#[derive(Debug, Clone, Copy)]
/// The salt for the extract stage.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you move the doc comment above the #[derive] for consistency?

expand: bool,
prf_hash_mechanism: MechanismType,
salt: HkdfSalt,
info: &'a [u8],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... info is required even when expand is set to false? Is info always set when expand is true and empty otherwise?

If so the two could be collapsed into an expand_info: Option<&[u8]> param 🤔

(in general bool parameters are annoying since it's not visible from the call-site which is which)

.expect("salt length does not fit in CK_ULONG"),
_ => 0,
},
hSaltKey: match salt {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd convert all these two-arm matches to if lets... but this is purely a stylistic choice 😅

@@ -0,0 +1,116 @@
//! Mechanisms of hash-based key derive function (HKDF)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be good to insert a copyright header here, just like so: https://github.com/parallaxsecond/rust-cryptoki/blob/main/cryptoki/src/types.rs#L1-L2

Copy link
Member

Choose a reason for hiding this comment

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

@wiktor-k do we use to put 2021 everywhere or the year the file is added instead?

Copy link
Member

@hug-dev hug-dev Oct 23, 2024

Choose a reason for hiding this comment

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

Let's use 2024 here instead then, until we find a better solution :)

wiktor-k
wiktor-k previously approved these changes Oct 23, 2024
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.

LGTM 👍 thanks!

@wiktor-k wiktor-k requested a review from hug-dev October 23, 2024 10:47
hug-dev
hug-dev previously approved these changes Oct 23, 2024
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! ONe question about copyright year that can be solved later

@@ -0,0 +1,116 @@
//! Mechanisms of hash-based key derive function (HKDF)
Copy link
Member

Choose a reason for hiding this comment

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

@wiktor-k do we use to put 2021 everywhere or the year the file is added instead?

@hug-dev
Copy link
Member

hug-dev commented Oct 23, 2024

@Direktor799 You might need to rebase!

@wiktor-k
Copy link
Collaborator

do we use to put 2021 everywhere or the year the file is added instead?

I think the date of the file addition was used in previous instances. The entire copyright years issues is a minefield: https://daniel.haxx.se/blog/2023/01/08/copyright-without-years/

In my other project we've migrated to reuse which automatically checks licensing info. Previously we used headers, just like here, but then we aggregated everything in one file and it's good. (I guess this is a question if we want to improve copyright headers in the long run and if so how).

@@ -0,0 +1,121 @@
// Copyright 2021 Contributors to the Parsec project.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2021 Contributors to the Parsec project.
// Copyright 2024 Contributors to the Parsec project.

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.

LGTM 👍 thanks!

@hug-dev hug-dev merged commit 9e3f1b6 into parallaxsecond:main Oct 23, 2024
7 checks passed
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.

3 participants