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

[crypto] Pass buffers by value. #20891

Merged
merged 4 commits into from
Jan 25, 2024

Conversation

jadephilipoom
Copy link
Contributor

Since word/byte buffers are structs containing only a pointer and a length, there is no need to make them pointers when they are return values, and this makes the API more ergonomic and easier to call from Rust (since you can just pass a slice directly). I also fixed the order of data and len in the buffer types for Rust compatibility in the second commit. The third commit applies the same change to hash digest structs (which look a lot like word buffers except they remember the hash mode used to construct them).

@jadephilipoom jadephilipoom requested a review from a team as a code owner January 19, 2024 09:59
@jadephilipoom jadephilipoom force-pushed the pass-buffers-by-value branch 3 times, most recently from 0c0f251 to e102b33 Compare January 19, 2024 16:47
@moidx moidx removed the request for review from a team January 20, 2024 01:11
*
* The order of `data` and `len` is important here for Rust compatibility; if
* `data` comes first, the representation exactly matches slices and is easier
* to call from Rust.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible that the current compiler implementation always puts data first, but the layout of slices is not guaranteed, so that's not something we can rely on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, that's a shame. I'll remove the comment.

Since word/byte buffers are structs containing only a pointer and a
length, there is no need to make them pointers when they are return
values, and this makes the API a little more ergonomic.

Signed-off-by: Jade Philipoom <[email protected]>
This is helpful for compatibility when the cryptolib is called from Rust
code.

Signed-off-by: Jade Philipoom <[email protected]>
Now that the output buffer is passed by value, the length must be
returned separately.

Signed-off-by: Jade Philipoom <[email protected]>
@jadephilipoom jadephilipoom merged commit dc7402f into lowRISC:master Jan 25, 2024
32 checks passed
@jadephilipoom jadephilipoom deleted the pass-buffers-by-value branch January 25, 2024 08:37
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