Added patch to obtain random bytes for Chrome NaCl via IRT -- allows build with NaCl SDK toolchain

This commit is contained in:
James Robson 2015-05-22 09:56:51 -06:00
parent a678c09ea3
commit ea2c1e86e2

View File

@ -9,6 +9,12 @@
# include <emscripten.h> # include <emscripten.h>
#endif #endif
#ifdef __native_client__
#include <stdlib.h>
#include <irt.h>
#endif
#include "randombytes.h" #include "randombytes.h"
#include "randombytes_sysrandom.h" #include "randombytes_sysrandom.h"
@ -114,9 +120,24 @@ void
randombytes_buf(void * const buf, const size_t size) randombytes_buf(void * const buf, const size_t size)
{ {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
#ifdef __native_client__
size_t n = 0;
struct nacl_irt_random rand_intf;
if (nacl_interface_query(NACL_IRT_RANDOM_v0_1,
&rand_intf, sizeof(rand_intf)) != sizeof(rand_intf)) abort();
while (n < size) {
size_t nread;
if (rand_intf.get_random_bytes(
(unsigned char *)buf+n, size-n, &nread) != 0) abort();
n += nread;
}
#else
if (size > (size_t) 0U) { if (size > (size_t) 0U) {
implementation->buf(buf, size); implementation->buf(buf, size);
} }
#endif
#else #else
unsigned char *p = buf; unsigned char *p = buf;
size_t i; size_t i;