]> git.codecow.com Git - Monocypher.git/commit
Remove unnecessary dependency on 2's complement
authorMichael Forney <mforney@mforney.org>
Tue, 19 Nov 2019 20:15:16 +0000 (12:15 -0800)
committerMichael Forney <mforney@mforney.org>
Tue, 19 Nov 2019 20:15:16 +0000 (12:15 -0800)
commit0073a9c8941a0e04a10035e7cc00ffddc8c0f083
tree2cfd21a4cf554e710bc3e3a484fd811f5d752955
parent4b4259be8df26637e8ad78d0676526d0b44a5a80
Remove unnecessary dependency on 2's complement

Although the bit-representation of signed integer types in C99 is
implementation-defined and can be sign-magnitude, one's complement, or
two's complement[0], the conversion of negative values to an unsigned
integer type is defined to be adding 1 plus the maximum value of the
unsigned type[1].

Since -1 + 0xffffffff + 1 == 0xffffffff, just using u32 here has the
right behavior without relying on the representation of signed integers.

[0] http://port70.net/~nsz/c/c99/n1256.html#6.2.6.2p2
[1] http://port70.net/~nsz/c/c99/n1256.html#6.3.1.3p2
src/monocypher.c