1 /*- 2 * Copyright (c) 2000-2015 Mark R. V. Murray 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _SYS_RANDOM_H_ 30 #define _SYS_RANDOM_H_ 31 32 #ifdef _KERNEL 33 34 #include <sys/types.h> 35 36 #include "opt_random.h" 37 38 #if !defined(KLD_MODULE) 39 #if defined(RANDOM_LOADABLE) && defined(RANDOM_YARROW) 40 #error "Cannot define both RANDOM_LOADABLE and RANDOM_YARROW" 41 #endif 42 #endif 43 44 struct uio; 45 46 #if defined(DEV_RANDOM) 47 u_int read_random(void *, u_int); 48 int read_random_uio(struct uio *, bool); 49 #else 50 static __inline int 51 read_random_uio(void *a __unused, u_int b __unused) 52 { 53 return (0); 54 } 55 static __inline u_int 56 read_random(void *a __unused, u_int b __unused) 57 { 58 return (0); 59 } 60 #endif 61 62 /* 63 * Note: if you add or remove members of random_entropy_source, remember to also update the 64 * KASSERT regarding what valid members are in random_harvest_internal(), and remember the 65 * strings in the static array random_source_descr[] in random_harvestq.c. 66 * 67 * NOTE: complain loudly to markm@ or on the lists if this enum gets more than 32 68 * distinct values (0-31)! ENTROPYSOURCE may be == 32, but not > 32. 69 */ 70 enum random_entropy_source { 71 RANDOM_START = 0, 72 RANDOM_CACHED = 0, 73 /* Environmental sources */ 74 RANDOM_ATTACH, 75 RANDOM_KEYBOARD, 76 RANDOM_MOUSE, 77 RANDOM_NET_TUN, 78 RANDOM_NET_ETHER, 79 RANDOM_NET_NG, 80 RANDOM_INTERRUPT, 81 RANDOM_SWI, 82 RANDOM_FS_ATIME, 83 RANDOM_UMA, /* Special!! UMA/SLAB Allocator */ 84 RANDOM_ENVIRONMENTAL_END = RANDOM_UMA, 85 /* Fast hardware random-number sources from here on. */ 86 RANDOM_PURE_OCTEON, 87 RANDOM_PURE_SAFE, 88 RANDOM_PURE_GLXSB, 89 RANDOM_PURE_UBSEC, 90 RANDOM_PURE_HIFN, 91 RANDOM_PURE_RDRAND, 92 RANDOM_PURE_NEHEMIAH, 93 RANDOM_PURE_RNDTEST, 94 RANDOM_PURE_VIRTIO, 95 ENTROPYSOURCE 96 }; 97 98 #define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1) 99 100 #if defined(DEV_RANDOM) 101 void random_harvest_queue(const void *, u_int, u_int, enum random_entropy_source); 102 void random_harvest_fast(const void *, u_int, u_int, enum random_entropy_source); 103 void random_harvest_direct(const void *, u_int, u_int, enum random_entropy_source); 104 #else 105 #define random_harvest_queue(a, b, c, d) do {} while (0) 106 #define random_harvest_fast(a, b, c, d) do {} while (0) 107 #define random_harvest_direct(a, b, c, d) do {} while (0) 108 #endif 109 110 #if defined(RANDOM_ENABLE_UMA) 111 #define random_harvest_fast_uma(a, b, c, d) random_harvest_fast(a, b, c, d) 112 #else /* !defined(RANDOM_ENABLE_UMA) */ 113 #define random_harvest_fast_uma(a, b, c, d) do {} while (0) 114 #endif /* defined(RANDOM_ENABLE_UMA) */ 115 116 #endif /* _KERNEL */ 117 118 #endif /* _SYS_RANDOM_H_ */ 119