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

Should keccak::f1600 take a &mut [u8; 200] rather than a &mut [u64; 25]? #3

Open
hdevalence opened this issue Aug 20, 2018 · 2 comments

Comments

@hdevalence
Copy link

I think it would be better if the keccak::f1600 function explicitly took a byte array, rather than taking an array of 64-bit words.

The reason is that this allows the keccak crate to provide endianness handling internally, rather than forcing every client crate to handle it themselves (or just leaves them to not handle it at all).

@newpavlov
Copy link
Member

I think it will have a worse performance, especially on big-endian machines, as you'll have to do byte swapping twice per function call (on read and write). For little-endian machines compiler may optimize redundant temporary array and read/writes into it, but I wouldn't bet on it.

@hdevalence
Copy link
Author

On little-endian machines, you can use a pointer cast to convert a &mut [u8; 200] into a &mut [u64; 25] for free. You may have to byte-swap on big-endian machines, but clients will have to do that anyways if they want to access the bytes of the sponge data.

I guess the point is not really about the performance, but about whose responsibility it is to handle endianness. Maybe the crate could provide an f1600_bytes function that took a &mut [u8; 200] and did a byte-swap on big-endian machines?

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

No branches or pull requests

2 participants