diff --git a/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c b/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c index f2d7b512..468cd653 100644 --- a/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +++ b/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c @@ -4,7 +4,7 @@ #include #ifdef __native_client__ -# include +# include # include "utils.h" # include "randombytes.h" @@ -13,11 +13,23 @@ static void randombytes_nativeclient_buf(void * const buf, const size_t size) { - size_t readnb; + unsigned char *buf_ = (unsigned char *) buf; + struct nacl_irt_random rand_intf; + size_t readnb = (size_t) 0U; + size_t toread = size; - if (nacl_secure_random(buf, size, &readnb) != 0 || readnb != size) { + if (nacl_interface_query(NACL_IRT_RANDOM_v0_1, &rand_intf, + sizeof rand_intf) != sizeof rand_intf) { abort(); } + while (toread > (size_t) 0U) { + if (rand_intf.get_random_bytes(buf_, size, &readnb) != 0 || + readnb > size) { + abort(); + } + toread -= readnb; + buf_ += readnb; + } } static uint32_t