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