14eeb4f04SMark Murray /*- 2e866d8f0SMark Murray * Copyright (c) 2000-2015 Mark R. V. Murray 34eeb4f04SMark Murray * All rights reserved. 41bb2d314SMark Murray * 51bb2d314SMark Murray * Redistribution and use in source and binary forms, with or without 61bb2d314SMark Murray * modification, are permitted provided that the following conditions 71bb2d314SMark Murray * are met: 81bb2d314SMark Murray * 1. Redistributions of source code must retain the above copyright 94eeb4f04SMark Murray * notice, this list of conditions and the following disclaimer 104eeb4f04SMark Murray * in this position and unchanged. 111bb2d314SMark Murray * 2. Redistributions in binary form must reproduce the above copyright 121bb2d314SMark Murray * notice, this list of conditions and the following disclaimer in the 131bb2d314SMark Murray * documentation and/or other materials provided with the distribution. 141bb2d314SMark Murray * 154eeb4f04SMark Murray * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 164eeb4f04SMark Murray * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 174eeb4f04SMark Murray * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 184eeb4f04SMark Murray * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 194eeb4f04SMark Murray * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 204eeb4f04SMark Murray * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 214eeb4f04SMark Murray * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 224eeb4f04SMark Murray * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 234eeb4f04SMark Murray * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 244eeb4f04SMark Murray * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 251bb2d314SMark Murray * 264eeb4f04SMark Murray * $FreeBSD$ 271bb2d314SMark Murray */ 281bb2d314SMark Murray 29a3b693c9SBruce Evans #ifndef _SYS_RANDOM_H_ 30a3b693c9SBruce Evans #define _SYS_RANDOM_H_ 311bb2d314SMark Murray 32da3fb6b4SMark Murray #ifdef _KERNEL 33da3fb6b4SMark Murray 34707d98feSEd Schouten #include <sys/types.h> 35707d98feSEd Schouten 36e866d8f0SMark Murray #if !defined(KLD_MODULE) 37646041a8SMark Murray #if defined(RANDOM_LOADABLE) && defined(RANDOM_YARROW) 38646041a8SMark Murray #error "Cannot define both RANDOM_LOADABLE and RANDOM_YARROW" 39646041a8SMark Murray #endif 40e866d8f0SMark Murray #endif 41646041a8SMark Murray 42707d98feSEd Schouten struct uio; 43707d98feSEd Schouten 44646041a8SMark Murray #if defined(DEV_RANDOM) 45d1b06863SMark Murray u_int read_random(void *, u_int); 46707d98feSEd Schouten int read_random_uio(struct uio *, bool); 47646041a8SMark Murray #else 48646041a8SMark Murray static __inline int 49646041a8SMark Murray read_random_uio(void *a __unused, u_int b __unused) 50646041a8SMark Murray { 51646041a8SMark Murray return (0); 52646041a8SMark Murray } 53646041a8SMark Murray static __inline u_int 54646041a8SMark Murray read_random(void *a __unused, u_int b __unused) 55646041a8SMark Murray { 56646041a8SMark Murray return (0); 57646041a8SMark Murray } 58646041a8SMark Murray #endif 591bb2d314SMark Murray 60a9befd40SRobert Watson /* 6110cb2424SMark Murray * Note: if you add or remove members of random_entropy_source, remember to also update the 6210cb2424SMark Murray * KASSERT regarding what valid members are in random_harvest_internal(), and remember the 6310cb2424SMark Murray * strings in the static array random_source_descr[] in random_harvestq.c. 6410cb2424SMark Murray * 6510cb2424SMark Murray * NOTE: complain loudly to markm@ or on the lists if this enum gets more than 32 6610cb2424SMark Murray * distinct values (0-31)! ENTROPYSOURCE may be == 32, but not > 32. 67a9befd40SRobert Watson */ 6810cb2424SMark Murray enum random_entropy_source { 69e1199601SMark Murray RANDOM_START = 0, 701a3c1f06SMark Murray RANDOM_CACHED = 0, 7110cb2424SMark Murray /* Environmental sources */ 728cc20a46SMark Murray RANDOM_ATTACH, 73e1199601SMark Murray RANDOM_KEYBOARD, 74e1199601SMark Murray RANDOM_MOUSE, 75c495c935SMark Murray RANDOM_NET_TUN, 76c495c935SMark Murray RANDOM_NET_ETHER, 77c495c935SMark Murray RANDOM_NET_NG, 78e1199601SMark Murray RANDOM_INTERRUPT, 79c495c935SMark Murray RANDOM_SWI, 80d1b06863SMark Murray RANDOM_FS_ATIME, 81e866d8f0SMark Murray RANDOM_UMA, /* Special!! UMA/SLAB Allocator */ 82e866d8f0SMark Murray RANDOM_ENVIRONMENTAL_END = RANDOM_UMA, 83d1b06863SMark Murray /* Fast hardware random-number sources from here on. */ 84f02e47dcSMark Murray RANDOM_PURE_OCTEON, 85f02e47dcSMark Murray RANDOM_PURE_SAFE, 86f02e47dcSMark Murray RANDOM_PURE_GLXSB, 87f02e47dcSMark Murray RANDOM_PURE_UBSEC, 88f02e47dcSMark Murray RANDOM_PURE_HIFN, 89f02e47dcSMark Murray RANDOM_PURE_RDRAND, 90f02e47dcSMark Murray RANDOM_PURE_NEHEMIAH, 9169160622SDag-Erling Smørgrav RANDOM_PURE_RNDTEST, 9210c40180SBryan Venteicher RANDOM_PURE_VIRTIO, 93*a1acc06fSMark Murray RANDOM_PURE_BROADCOM, 94e1199601SMark Murray ENTROPYSOURCE 95e1199601SMark Murray }; 96d1b06863SMark Murray 97d1b06863SMark Murray #define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1) 98d1b06863SMark Murray 99646041a8SMark Murray #if defined(DEV_RANDOM) 100d1b06863SMark Murray void random_harvest_queue(const void *, u_int, u_int, enum random_entropy_source); 101d1b06863SMark Murray void random_harvest_fast(const void *, u_int, u_int, enum random_entropy_source); 102d1b06863SMark Murray void random_harvest_direct(const void *, u_int, u_int, enum random_entropy_source); 103646041a8SMark Murray #else 104646041a8SMark Murray #define random_harvest_queue(a, b, c, d) do {} while (0) 105646041a8SMark Murray #define random_harvest_fast(a, b, c, d) do {} while (0) 106646041a8SMark Murray #define random_harvest_direct(a, b, c, d) do {} while (0) 107646041a8SMark Murray #endif 10814636c3bSMark Murray 109e866d8f0SMark Murray #if defined(RANDOM_ENABLE_UMA) 110e866d8f0SMark Murray #define random_harvest_fast_uma(a, b, c, d) random_harvest_fast(a, b, c, d) 111e866d8f0SMark Murray #else /* !defined(RANDOM_ENABLE_UMA) */ 112e866d8f0SMark Murray #define random_harvest_fast_uma(a, b, c, d) do {} while (0) 113e866d8f0SMark Murray #endif /* defined(RANDOM_ENABLE_UMA) */ 114e866d8f0SMark Murray 1154a7cdfd7SMark Murray #endif /* _KERNEL */ 116da3fb6b4SMark Murray 1174eeb4f04SMark Murray #endif /* _SYS_RANDOM_H_ */ 118