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