Skip to content

Add more setters for EcKdf. #292

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nwalfield
Copy link

Adds setters for the ANSI X9.63 KDFs (EcKdf::sha1, etc) and the NIST SP800-56A KDFs (EcKdf::sha1_sp800) to EcKdf.

Fixes EcKdf::sha256.

Fixes #281.

The SP800 variants were recently added to Kryoptic.

I've tested this using Sequoia, but I haven't included any unit tests. First, the unit tests will fail, because the current released version of Kryoptic doesn't include support for the SP800 yet. Second, creating test vectors will be a huge amount of work. Given how simple the implementation is, do you want unit tests for these functions?

Thanks for taking a look.

@Jakuje
Copy link
Collaborator

Jakuje commented Jun 25, 2025

Code wise looks good. I would prefer to have some test prepared so we can enable it once the kryoptic version will get updated in Fedora, if nothing to prevent the case of having mechanisms like the sha256 added without any testing.

I do not think it needs to be full coverage of all combinations, but at least one test with NIST SP800 and one with ANSI with known answer test to make sure it works.

@hug-dev
Copy link
Member

hug-dev commented Jun 26, 2025

Thanks for this, looks good! Agree with @Jakuje about adding two simple tests where this is available in Fedora!

@nwalfield
Copy link
Author

I've updated the MR to include a test that uses known good values. I created the test vector by instrumenting Sequoia OpenPGP and dumping the relevant values. The test vector is for SHA256-SP800. It would be straightforward (although still some work) to create test vectors for SHA384-SP800 and SHA512-SP800.

As Sequoia does not use the ANSI functions, I cannot create test vectors for them without a lot of work. That said, I'm not sure of the value of additional test vectors: I think the test suite is about testing the library, not the underlying token implementation. The test demonstrates that the shape of the API is correct, and that the shared value is passed correctly.

Thoughts?

@Jakuje
Copy link
Collaborator

Jakuje commented Jun 27, 2025

Regarding the ANSI variant, I think its ok to skip it as it is mostly the same (for the rust-cryptoki).

&[
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::GENERIC_SECRET),
Attribute::ValueLen((derivation.len() as u64).into()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still does not work on 32b arch. We had more of them fixed recently in 80b22b2, but I think all of them are constants.

Not sure what would be the cleanest way to do this, but probably some From for u32 to keep it safe? Or just Ulong::new(derivation.len()), but it makes the API ugly, i think...

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the hint. I switched to Ulong::new(derivation.len()).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still it probably needs

Attribute::ValueLen(Ulong::new(derivation.len() as u64)),

or the try_into().unwrap() as suggested by the rust ...

Adds setters for the ANSI X9.63 KDFs (`EcKdf::sha1`, etc) and the NIST
SP800-56A KDFs (`EcKdf::sha1_sp800`) to `EcKdf`.

Fixes `EcKdf::sha256`.

Fixes parallaxsecond#281.

Signed-off-by: Neal H. Walfield <[email protected]>
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.

EcKdf documentation unclear
3 participants