The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/random.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (c) 2000-2015, 2017 Mark R. V. Murray
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer
   12  *    in this position and unchanged.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27  *
   28  * $FreeBSD: head/sys/sys/random.h 346282 2019-04-16 17:12:17Z cem $
   29  */
   30 
   31 #ifndef _SYS_RANDOM_H_
   32 #define _SYS_RANDOM_H_
   33 
   34 #include <sys/types.h>
   35 
   36 #ifdef _KERNEL
   37 
   38 struct uio;
   39 
   40 #if defined(DEV_RANDOM)
   41 void read_random(void *, u_int);
   42 int read_random_uio(struct uio *, bool);
   43 bool is_random_seeded(void);
   44 #else
   45 static __inline int
   46 read_random_uio(void *a __unused, u_int b __unused)
   47 {
   48         return (0);
   49 }
   50 static __inline void
   51 read_random(void *a __unused, u_int b __unused)
   52 {
   53 }
   54 static __inline bool
   55 is_random_seeded(void)
   56 {
   57         return (false);
   58 }
   59 #endif
   60 
   61 /*
   62  * Note: if you add or remove members of random_entropy_source, remember to
   63  * also update the strings in the static array random_source_descr[] in
   64  * random_harvestq.c.
   65  */
   66 enum random_entropy_source {
   67         RANDOM_START = 0,
   68         RANDOM_CACHED = 0,
   69         /* Environmental sources */
   70         RANDOM_ATTACH,
   71         RANDOM_KEYBOARD,
   72         RANDOM_MOUSE,
   73         RANDOM_NET_TUN,
   74         RANDOM_NET_ETHER,
   75         RANDOM_NET_NG,
   76         RANDOM_INTERRUPT,
   77         RANDOM_SWI,
   78         RANDOM_FS_ATIME,
   79         RANDOM_UMA,     /* Special!! UMA/SLAB Allocator */
   80         RANDOM_ENVIRONMENTAL_END = RANDOM_UMA,
   81         /* Fast hardware random-number sources from here on. */
   82         RANDOM_PURE_START,
   83         RANDOM_PURE_OCTEON = RANDOM_PURE_START,
   84         RANDOM_PURE_SAFE,
   85         RANDOM_PURE_GLXSB,
   86         RANDOM_PURE_UBSEC,
   87         RANDOM_PURE_HIFN,
   88         RANDOM_PURE_RDRAND,
   89         RANDOM_PURE_NEHEMIAH,
   90         RANDOM_PURE_RNDTEST,
   91         RANDOM_PURE_VIRTIO,
   92         RANDOM_PURE_BROADCOM,
   93         RANDOM_PURE_CCP,
   94         RANDOM_PURE_DARN,
   95         RANDOM_PURE_TPM,
   96         ENTROPYSOURCE
   97 };
   98 _Static_assert(ENTROPYSOURCE <= 32,
   99     "hardcoded assumption that values fit in a typical word-sized bitset");
  100 
  101 #define RANDOM_LEGACY_BOOT_ENTROPY_MODULE       "/boot/entropy"
  102 #define RANDOM_CACHED_BOOT_ENTROPY_MODULE       "boot_entropy_cache"
  103 
  104 #if defined(DEV_RANDOM)
  105 extern u_int hc_source_mask;
  106 void random_harvest_queue_(const void *, u_int, enum random_entropy_source);
  107 void random_harvest_fast_(const void *, u_int);
  108 void random_harvest_direct_(const void *, u_int, enum random_entropy_source);
  109 
  110 static __inline void
  111 random_harvest_queue(const void *entropy, u_int size, enum random_entropy_source origin)
  112 {
  113 
  114         if (hc_source_mask & (1 << origin))
  115                 random_harvest_queue_(entropy, size, origin);
  116 }
  117 
  118 static __inline void
  119 random_harvest_fast(const void *entropy, u_int size, enum random_entropy_source origin)
  120 {
  121 
  122         if (hc_source_mask & (1 << origin))
  123                 random_harvest_fast_(entropy, size);
  124 }
  125 
  126 static __inline void
  127 random_harvest_direct(const void *entropy, u_int size, enum random_entropy_source origin)
  128 {
  129 
  130         if (hc_source_mask & (1 << origin))
  131                 random_harvest_direct_(entropy, size, origin);
  132 }
  133 
  134 void random_harvest_register_source(enum random_entropy_source);
  135 void random_harvest_deregister_source(enum random_entropy_source);
  136 #else
  137 #define random_harvest_queue(a, b, c) do {} while (0)
  138 #define random_harvest_fast(a, b, c) do {} while (0)
  139 #define random_harvest_direct(a, b, c) do {} while (0)
  140 #define random_harvest_register_source(a) do {} while (0)
  141 #define random_harvest_deregister_source(a) do {} while (0)
  142 #endif
  143 
  144 #if defined(RANDOM_ENABLE_UMA)
  145 #define random_harvest_fast_uma(a, b, c)        random_harvest_fast(a, b, c)
  146 #else /* !defined(RANDOM_ENABLE_UMA) */
  147 #define random_harvest_fast_uma(a, b, c)        do {} while (0)
  148 #endif /* defined(RANDOM_ENABLE_UMA) */
  149 
  150 #if defined(RANDOM_ENABLE_ETHER)
  151 #define random_harvest_queue_ether(a, b)        random_harvest_queue(a, b, RANDOM_NET_ETHER)
  152 #else /* !defined(RANDOM_ENABLE_ETHER) */
  153 #define random_harvest_queue_ether(a, b)        do {} while (0)
  154 #endif /* defined(RANDOM_ENABLE_ETHER) */
  155 
  156 
  157 #endif /* _KERNEL */
  158 
  159 #define GRND_NONBLOCK   0x1
  160 #define GRND_RANDOM     0x2
  161 
  162 __BEGIN_DECLS
  163 ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
  164 __END_DECLS
  165 
  166 #endif /* _SYS_RANDOM_H_ */

Cache object: b1f23630f00eede41ca33b0e58d2947c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.