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

Fix pointer alignment #22

Closed
hdevalence opened this issue Aug 28, 2018 · 2 comments
Closed

Fix pointer alignment #22

hdevalence opened this issue Aug 28, 2018 · 2 comments
Milestone

Comments

@hdevalence
Copy link
Contributor

The keccakf crate doesn't operate on a state composed of bytes, it operates on a state composed of words. (cf #11, #20). This is currently handled by doing

fn transmute_state(st: &mut [u8; 200]) -> &mut [u64; 25] {
    unsafe { &mut *(st as *mut [u8; 200] as *mut [u64; 25]) }
}

Unfortunately this isn't quite right because the second pointer has tighter alignment requirements than the first pointer, which isn't guaranteed to have u64 alignment.

@hdevalence
Copy link
Contributor Author

Storing the state as words is unappealing because it's a) wrong -- the state is a byte array and b) it means that we have to do a conversion on every byte access. This might be fine on LE systems where the conversion is a no-op but it seems bad on a BE system, where it would be preferable to do a byteswap before calling keccakf and then swap back.

@hdevalence
Copy link
Contributor Author

@myrrlyn suggests getting the correct alignment by wrapping the bytes in a newtype with #[repr(align(64))]

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

1 participant