agl / curve25519-donna Public
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
-ftrapv reports signed integer overflows on left shift #31
Comments
|
From looking at teor2345/tor@ced74e0, it seems very ugly -- I don't want to merge that I'm afraid. |
|
Okay. Would you be amenable in principle to some other approach to avoid left-shifting negative numbers? It is technically undefined, if I'm researching this properly. |
|
Yes, it's technically undefined behaviour:
However, it's the result of trying to support non-two's complement machines. That may have made sense in the 1970's but I'm very dubious that we should be paying the cost to support them now. (I'm not sure if they still even exist.) Rather I'm seeing whether there's support in the standards group for defining this behaviour. |
|
Any updates here? |
|
Even if the C committee makes this defined -- and I strongly suspect they won't -- it will be decades before C compilers are all updated to acknowledge the change. The patch should be merged. |
|
@agl: You should at least add |
|
The right way to "left shift a possibly negative number" is to simply write x*(1<<n). It has the exact semantics you want but without the undefined behavior (assuming no overflow). If you also want well-defined behavior on overflow without depending on non-portable compiler extensions you need to convert to an unsigned type and back. |
Needed for curve25519-donna agl/curve25519-donna#31
Apparently, C thinks that a left shift of a negative number is undefined behavior. But the donna code does this.
A volunteer contributor to Tor, named "teor", has sent us a patch to fix this issue. We'd like it to go upstream before we merge it, though. You can see the ticket at https://trac.torproject.org/projects/tor/ticket/13538 . This code will need a bit of hacking to go into donna. I'm making this issue as a placeholder.
The text was updated successfully, but these errors were encountered: