1 /* 2 * Copyright 2009, Colin Günther, coling@gmx.de. All rights reserved. 3 * Copyright 2018, Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 extern "C" { 8 #include <compat/sys/libkern.h> 9 } 10 11 #include <util/Random.h> 12 13 14 u_int 15 read_random(void* buf, u_int len) 16 { 17 uint8* bufs = (uint8*)buf; 18 for (int i = 0; i < len; i++) 19 bufs[i] = secure_get_random<uint8>(); 20 return len; 21 } 22 23 24 void 25 arc4rand(void *ptr, u_int len, int reseed) 26 { 27 read_random(ptr, len); 28 } 29 30 31 uint32_t 32 arc4random(void) 33 { 34 uint32_t ret; 35 36 arc4rand(&ret, sizeof ret, 0); 37 return ret; 38 } 39