1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 02:25:14 -07:00

_sodium_alignedcalloc(): use arc4random_buf() if available

This commit is contained in:
Frank Denis 2013-10-21 21:07:39 -07:00
parent 323f24ef60
commit 696934b123

View File

@ -54,9 +54,14 @@ _sodium_alignedcalloc(unsigned char ** const unaligned_p, const size_t len)
return NULL;
}
*unaligned_p = unaligned;
#ifdef HAVE_ARC4RANDOM
(void) i;
arc4random_buf(unaligned, len + (size_t) 256U);
#else
for (i = (size_t) 0U; i < len + (size_t) 256U; ++i) {
unaligned[i] = (unsigned char) rand();
}
#endif
aligned = unaligned + 64;
aligned += (ptrdiff_t) 63 & (-(ptrdiff_t) aligned);
memset(aligned, 0, len);