1 /* 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7 #include <errno.h> 8 9 #include "native_client/src/untrusted/irt/irt.h" 10 #include "native_client/src/untrusted/nacl/nacl_irt.h" 11 12 static struct nacl_irt_random random_interface = { NULL }; 13 nacl_secure_random_init(void)14int nacl_secure_random_init(void) { 15 return 0; /* Success */ 16 } 17 random_init(void)18static void random_init(void) { 19 nacl_interface_query(NACL_IRT_RANDOM_v0_1, &random_interface, 20 sizeof(random_interface)); 21 } 22 nacl_secure_random(void * dest,size_t bytes,size_t * bytes_written)23int nacl_secure_random(void *dest, size_t bytes, size_t *bytes_written) { 24 if (!__libnacl_irt_init_fn(&random_interface.get_random_bytes, 25 random_init)) { 26 return ENOSYS; 27 } 28 return random_interface.get_random_bytes(dest, bytes, bytes_written); 29 } 30