-
Notifications
You must be signed in to change notification settings - Fork 15
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
memcpy() warnings and constant time #53
Comments
Hi! |
And, nope, my pull request doesn't fix it. gcc is too smart for us.
becomes:
Since
|
How about this one below? Looks like We need to use own copying routines, otherwise the volatility is stripped away. Executed in Compiler Explorer:
Something like this:
|
This gets closer to constant time than before (the memory copy always happens), although there are two extra instructions on one path: 64d6957 |
Could this be treated like POD? I missed that, interesting.
Edit: https://godbolt.org/z/ozxY9b - looks like temp variable cannot be on function-local stack, otherwise its handled differently. |
It looks like the modp256k1.c and modp256r1.c use
memcpy(tmp, tmp, ...)
to try to maintain a constant time implementation. This causes a warning with newerarm-none-eabi-gcc
(I'm testing with 9.2.1 from the Ubuntu 20.04 repo):The standard does not guarantee what will happen in this case:
Many libraries will check for overlap and fall back to
memove()
, which can short-circuit in the case of the src == dst. This would prevent the functions from actually being constant time.The text was updated successfully, but these errors were encountered: