Repair sodium_is_zero()

This commit is contained in:
Frank Denis 2015-11-16 23:17:42 +01:00
parent 397d50664a
commit 07c42492e5

View File

@ -158,18 +158,23 @@ int
sodium_is_zero(const unsigned char *n, const size_t nlen)
{
size_t i = 0U;
#if !defined(CPU_UNALIGNED_ACCESS) || !defined(NATIVE_LITTLE_ENDIAN)
uint_fast8_t c = 0U;
#else
uint_fast64_t c = 0U;
for (; i < (nlen & ~0x7); i += 8U) {
c |= *((const uint64_t *) (const void *) &n[i]);
}
#endif
uint_fast8_t c = 0U;
for (; i < nlen; i++) {
c |= n[i];
}
return (int) (((c - 1U) >> 8) & 1U);
return (int) ((((uint_fast16_t) c - 1U) >> 8) & 1U);
#else
uint_fast32_t c = 0U;
for (; i < (nlen & ~0x3); i += 4U) {
c |= *((const uint32_t *) (const void *) &n[i]);
}
for (; i < nlen; i++) {
c |= n[i];
}
return (int) ((((uint_fast64_t) c - 1U) >> 32) & 1U);
#endif
}
void