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

Clean up Hacl-rs integration and add Poly1305 and ChaCha20Poly1305 #703

Merged
merged 14 commits into from
Dec 20, 2024

Conversation

keks
Copy link
Member

@keks keks commented Dec 2, 2024

This PR addresses the following cleanup issues:

It also adds Poly1305 (MAC) and ChaChaPoly1305 (AEAD), which means we also make progress on this issue:

I am currently stuck on implementing the existing AEAD API with the new code, because that uses a single ctxt_ptxt function argument to encrypt and does in-place encryption. The API exposed by hacl-rs uses separate arguments, and we can't put the argument in both because that would result in a shared mutable reference. I suggest we leave the old API be for now and address this once we have a better idea of what the final API should be.

Opinions @franziskuskiefer @jschneider-bensch?

TODOs left:

  • Agree on how to deal with in-place encryption API
  • Act on whatever was agreed
  • Add RSA signatures

Fixes #696
Fixes #673
Fixes #675

keks added 4 commits December 2, 2024 11:32
- drop portable_hacl feature
- don't export hacl modules when hacl feature is set
- (on some) add an expose-hacl feature to export hacl module
This commit adds inlines:

- plain inline inside hacl-rs code (sometimes)
- inline(always) for functions that call hacl-rs code

This way our wrapper functions get inlined away and the caller just
calls the hacl-rs function, and inside the hacl-rs function there are
few calls to internal functions (where it makes sense).
@franziskuskiefer
Copy link
Member

I suggest we leave the old API be for now and address this once we have a better idea of what the final API should be.

Sounds good to me.
In C I think the API allows both. But in Rust we of course can't do that. We could ask them if they can generate the other version as well.

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

Generally lgtm with a couple nits.

The main question I have is around when hacl internals are exposed. The basic design should be that only a libcrux API is exposed (backed by some implementation), and we only expose something backend (hacl) specific if that's required by another backend (hacl) implementation, guarded by some fatures. You started doing that. But there still seem to be a bunch of exports of hacl specific modules. Or maybe it's just the naming that needs to change.

curve25519/src/lib.rs Outdated Show resolved Hide resolved
curve25519/src/lib.rs Outdated Show resolved Hide resolved
ed25519/src/lib.rs Outdated Show resolved Hide resolved
hacl-rs/src/lowstar/endianness.rs Show resolved Hide resolved
libcrux-hkdf/src/hkdf.rs Outdated Show resolved Hide resolved
chacha20poly1305/src/hacl/chacha20_vec32.rs Outdated Show resolved Hide resolved
chacha20poly1305/src/lib.rs Outdated Show resolved Hide resolved
chacha20poly1305/src/impl_hacl.rs Outdated Show resolved Hide resolved
chacha20poly1305/src/impl_hacl.rs Outdated Show resolved Hide resolved
rsa/src/lib.rs Outdated Show resolved Hide resolved
@keks keks marked this pull request as ready for review December 19, 2024 15:19
@keks keks requested a review from a team as a code owner December 19, 2024 15:19
@keks
Copy link
Member Author

keks commented Dec 19, 2024

Regarding the features: I removed all the hacl features and only have the expose-hacl on a few select crates. We can add them again should we want to add a second implementation.

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

Generally lgtm with the couple nits.

chacha20poly1305/src/impl_hacl.rs Outdated Show resolved Hide resolved
chacha20poly1305/src/impl_hacl.rs Show resolved Hide resolved
chacha20poly1305/src/impl_hacl.rs Show resolved Hide resolved
rsa/src/impl_hacl.rs Outdated Show resolved Hide resolved
rsa/src/impl_hacl.rs Show resolved Hide resolved
rsa/src/impl_hacl.rs Show resolved Hide resolved
rsa/src/lib.rs Show resolved Hide resolved
@keks
Copy link
Member Author

keks commented Dec 19, 2024

I hope this was it :)

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

The APIs aren't great. But we can improve them later.

@franziskuskiefer franziskuskiefer added this pull request to the merge queue Dec 20, 2024
Merged via the queue into main with commit 315cf8a Dec 20, 2024
52 checks passed
@franziskuskiefer franziskuskiefer deleted the keks/more-hacl-rs branch December 20, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants