1*0d283a3aSriastradh /* $NetBSD: arc4random.h,v 1.1 2024/08/27 13:43:02 riastradh Exp $ */ 2*0d283a3aSriastradh 3*0d283a3aSriastradh /*- 4*0d283a3aSriastradh * Copyright (c) 2014 The NetBSD Foundation, Inc. 5*0d283a3aSriastradh * All rights reserved. 6*0d283a3aSriastradh * 7*0d283a3aSriastradh * This code is derived from software contributed to The NetBSD Foundation 8*0d283a3aSriastradh * by Taylor R. Campbell. 9*0d283a3aSriastradh * 10*0d283a3aSriastradh * Redistribution and use in source and binary forms, with or without 11*0d283a3aSriastradh * modification, are permitted provided that the following conditions 12*0d283a3aSriastradh * are met: 13*0d283a3aSriastradh * 1. Redistributions of source code must retain the above copyright 14*0d283a3aSriastradh * notice, this list of conditions and the following disclaimer. 15*0d283a3aSriastradh * 2. Redistributions in binary form must reproduce the above copyright 16*0d283a3aSriastradh * notice, this list of conditions and the following disclaimer in the 17*0d283a3aSriastradh * documentation and/or other materials provided with the distribution. 18*0d283a3aSriastradh * 19*0d283a3aSriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*0d283a3aSriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*0d283a3aSriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*0d283a3aSriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*0d283a3aSriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*0d283a3aSriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*0d283a3aSriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*0d283a3aSriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*0d283a3aSriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*0d283a3aSriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*0d283a3aSriastradh * POSSIBILITY OF SUCH DAMAGE. 30*0d283a3aSriastradh */ 31*0d283a3aSriastradh 32*0d283a3aSriastradh #ifndef _LIBC_GEN_ARC4RANDOM_H_ 33*0d283a3aSriastradh #define _LIBC_GEN_ARC4RANDOM_H_ 34*0d283a3aSriastradh 35*0d283a3aSriastradh #include <stdbool.h> 36*0d283a3aSriastradh #include <stdint.h> 37*0d283a3aSriastradh 38*0d283a3aSriastradh #include "reentrant.h" 39*0d283a3aSriastradh 40*0d283a3aSriastradh struct crypto_prng { 41*0d283a3aSriastradh uint8_t state[32]; 42*0d283a3aSriastradh }; 43*0d283a3aSriastradh 44*0d283a3aSriastradh struct arc4random_prng { 45*0d283a3aSriastradh struct crypto_prng arc4_prng; 46*0d283a3aSriastradh unsigned arc4_epoch; 47*0d283a3aSriastradh }; 48*0d283a3aSriastradh 49*0d283a3aSriastradh struct arc4random_global_state { 50*0d283a3aSriastradh mutex_t lock; 51*0d283a3aSriastradh thread_key_t thread_key; 52*0d283a3aSriastradh struct arc4random_prng prng; 53*0d283a3aSriastradh bool initialized; 54*0d283a3aSriastradh }; 55*0d283a3aSriastradh 56*0d283a3aSriastradh #define arc4random_global __arc4random_global /* libc private symbol */ 57*0d283a3aSriastradh 58*0d283a3aSriastradh extern struct arc4random_global_state arc4random_global; 59*0d283a3aSriastradh 60*0d283a3aSriastradh #endif /* _LIBC_GEN_ARC4RANDOM_H_ */ 61