]> git.codecow.com Git - Monocypher.git/commit
Avoid negating unsigned numbers (for MSVC)
authorLoup Vaillant <loup@loup-vaillant.fr>
Tue, 3 Apr 2018 19:54:49 +0000 (21:54 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Tue, 3 Apr 2018 19:54:49 +0000 (21:54 +0200)
commitc63252ada2e190110cb2353c3c1db72c264d7647
tree4c94c23108e07ce315bf0b4bb4e36a6960b45bf3
parent2e8d4ebb0f042878c9bea58677f42068fcfb583e
Avoid negating unsigned numbers (for MSVC)

MSVC doesn't like when people negate unsigned numbers, and the result is
still unsigned.  By default, it's an error.  Moreover, section 6.5.6 of
the C11 standard doesn't clearly specify what -x means when x is an
unsigned integer.  It does however specify ~x.

So I replaced -x by ~x+1.  This was getting ugly, though, so I made the
ALIGN macro.  ALIGN(x, block_size) returns how many bytes we need to
reach the next block size, assuming we've already consumed x bytes.  For
instance, ALIGN(11, 8) == 5.  It uses bit twiddling trickery, so the
block size must be a power of 2.
src/monocypher.c
src/optional/sha512.c