diff --git a/src/libsodium/sodium/utils.c b/src/libsodium/sodium/utils.c index fd629e13..334b0c00 100644 --- a/src/libsodium/sodium/utils.c +++ b/src/libsodium/sodium/utils.c @@ -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