Skip to content

Unverified KMAC-128 and KMAC-256 implementation#1292

Open
kraemv wants to merge 10 commits intocryspen:mainfrom
kraemv:feature/kmac
Open

Unverified KMAC-128 and KMAC-256 implementation#1292
kraemv wants to merge 10 commits intocryspen:mainfrom
kraemv:feature/kmac

Conversation

@kraemv
Copy link

@kraemv kraemv commented Jan 21, 2026

Hello everyone,
I implemented KMAC-128 and KMAC-256 in Rust and would like to contribute my code to libcrux. I am not familiar with hax and F*, hence my commit does not contain a correctness proof.
I have tested my code with the wycheproof project, the test vectors and the changes to the /tests repository are included in this PR.
I made changes to sha3/src/portable.rs to implement an iterative CShake API with the correct Keccak padding. An iterative API is required to make the code no_std compatible.
Could you please share your thoughts about the length values (e.g. key_length) in hacl/kmac.rs, as they will panic for inputs larger than 2^61 bytes.

@kraemv kraemv requested review from a team as code owners January 21, 2026 08:59
Copy link
Collaborator

@jschneider-bensch jschneider-bensch 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!
I haven't had time for a detailed look yet, just a few comments.

@franziskuskiefer
Copy link
Member

@kraemv do you think you could add runtime safety, i.e. that the code never panics, if you help you with the set up?

@jschneider-bensch
Copy link
Collaborator

In this PR to your branch, I've added a basic setup for doing runtime safety proofs. Let me know what you think!

@kraemv kraemv force-pushed the feature/kmac branch 3 times, most recently from a45d10b to c93fb3e Compare January 26, 2026 09:31
@kraemv
Copy link
Author

kraemv commented Jan 26, 2026

The fstar runtime safety proof now goes through.

@jschneider-bensch jschneider-bensch added the waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 28, 2026
kraemv and others added 4 commits January 29, 2026 14:13
* [kmac] Add basic hax extraction setup

* [kmac] Add hax-lib dependency

* [kmac] Comment out const blocks (unsupported by hax)
@jschneider-bensch
Copy link
Collaborator

It's very nice that you can extract and typecheck this code for runtime safety without any annotations!
I came up with some ideas for refactoring the code and tried them out on this branch: https://github.com/cryspen/libcrux/tree/jonas/refactor-kmac-cshake (comparison)

  • I reduced code duplication a bit using a const generic for the RATE and passing in the CSHAKE implementation as a generic as well.
  • I moved the CSHAKE-specific parts out of KMAC and into a general purpose CSHAKE implementation in sha3.
  • To do this I needed to add some annotations for runtime safety, but the extraction should typecheck on that branch as well.

Would you be okay with incorporating these changes here?

@kraemv
Copy link
Author

kraemv commented Jan 30, 2026

Hi Jonas,
I like your changes to the code, they benefit readability and structure! Also, the structure is now closer to the definitions of KMAC and CSHAKE in the standard.
Do you think it is easier to proof functional correctness at some future point for a more generic code?
With the new structure, you should be able to remove CShake128It in [crates/algorithms/sha3/src/portable/cshake.rs] as it is superseded by CShake128 in [crates/algorithms/sha3/src/portable/incremental.rs].

@jschneider-bensch
Copy link
Collaborator

I think we have found in ML-KEM and ML-DSA as well that doing a functional correctness proof on a generic implementation can be advantageous since you only do the proof once and it should hold for all different (valid!) parameters the generic implementation can be instantiated with.

I made a few more small changes on the refactoring branch, updating changelogs and removing the obsolete code you found. I think with these also merged into your PR this looks very good to me already!
One thing we should do before merging the PR is add some more documentation around the new CSHAKE and KMAC APIs. Just let me know if you'd like to give that a shot or if not, I can do it.

@kraemv
Copy link
Author

kraemv commented Feb 4, 2026

Well, then I am very happy to have the generic code now :)
I merged the most recent changes into this PR already. I am also very happy with the state of the code!
I would be grateful if you could do the documentation, as I am currently quite busy with another project.

@jschneider-bensch
Copy link
Collaborator

Okay, then I'll take care of the rest. 👍 Thanks a lot for your efforts!

@kraemv
Copy link
Author

kraemv commented Feb 5, 2026

Thank you for your feedback on the code and the support to prove runtime safety!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments