-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
keccak: guard against misaligned memory accesses on ARM #5724
Conversation
src/crypto/keccak.c
Outdated
for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { | ||
for (i = 0; i < rsizw; i++) { | ||
uint64_t ina; | ||
memcpy(&ina, &((uint64_t*)in)[i], 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the source pointer be (void *)? otherwise the compiler will still assume uint64_t alignment, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I also added a better unit test for this. I can't seem to be able to connect to ssh for now, I'll push later when I can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and implemented. This will be successful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I've disassembled similar code in the past, GCC / Clang will generate identical code whether its an uint64_t
cast/alias or a memcpy
when the target platform supports unaligned accesses. When the platform doesn't, they will fall back into the slower copy code (but typically don't call the library memcpy
function either).
Instead of carrying two versions - is it worth always doing the memcpy
? The penalty will be slightly slower when armv7 (or similar) has an aligned memory access case since it won't branch into the cast/alias version. But it will be less code duplication in our codebase and ASM.
The code generated is exactly the same as the direct access one on x86_64
It was 100% identical code indeed. I changed it to only use the memcpy version now. |
c223832 keccak: guard against misaligned memory accesses on ARM (moneromooo-monero)
No description provided.