source: rtems-libbsd/freebsd/sys/sys/random.h @ 9ea8664

5-freebsd-12
Last change on this file since 9ea8664 was 9ea8664, checked in by Christian Mauderer <christian.mauderer@…>, on Jun 26, 2018 at 11:54:08 AM

random: Implement read_random via getentropy.

  • Property mode set to 100644
File size: 3.9 KB
Line 
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#if !defined(KLD_MODULE)
37#if defined(RANDOM_LOADABLE) && defined(RANDOM_YARROW)
38#error "Cannot define both RANDOM_LOADABLE and RANDOM_YARROW"
39#endif
40#endif
41
42struct uio;
43
44#if defined(DEV_RANDOM)
45u_int read_random(void *, u_int);
46int read_random_uio(struct uio *, bool);
47#else
48static __inline int
49read_random_uio(void *a __unused, u_int b __unused)
50{
51        return (0);
52}
53#ifndef __rtems__
54static __inline u_int
55read_random(void *a __unused, u_int b __unused)
56{
57        return (0);
58}
59#else /* __rtems__ */
60#include <unistd.h>
61static __inline u_int
62read_random(void *ptr, u_int n)
63{
64        getentropy(ptr, n);
65        return (n);
66}
67#endif /* __rtems__ */
68#endif
69
70/*
71 * Note: if you add or remove members of random_entropy_source, remember to also update the
72 * KASSERT regarding what valid members are in random_harvest_internal(), and remember the
73 * strings in the static array random_source_descr[] in random_harvestq.c.
74 *
75 * NOTE: complain loudly to markm@ or on the lists if this enum gets more than 32
76 * distinct values (0-31)! ENTROPYSOURCE may be == 32, but not > 32.
77 */
78enum random_entropy_source {
79        RANDOM_START = 0,
80        RANDOM_CACHED = 0,
81        /* Environmental sources */
82        RANDOM_ATTACH,
83        RANDOM_KEYBOARD,
84        RANDOM_MOUSE,
85        RANDOM_NET_TUN,
86        RANDOM_NET_ETHER,
87        RANDOM_NET_NG,
88        RANDOM_INTERRUPT,
89        RANDOM_SWI,
90        RANDOM_FS_ATIME,
91        RANDOM_UMA,     /* Special!! UMA/SLAB Allocator */
92        RANDOM_ENVIRONMENTAL_END = RANDOM_UMA,
93        /* Fast hardware random-number sources from here on. */
94        RANDOM_PURE_OCTEON,
95        RANDOM_PURE_SAFE,
96        RANDOM_PURE_GLXSB,
97        RANDOM_PURE_UBSEC,
98        RANDOM_PURE_HIFN,
99        RANDOM_PURE_RDRAND,
100        RANDOM_PURE_NEHEMIAH,
101        RANDOM_PURE_RNDTEST,
102        RANDOM_PURE_VIRTIO,
103        RANDOM_PURE_BROADCOM,
104        ENTROPYSOURCE
105};
106
107#define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1)
108
109#if defined(DEV_RANDOM)
110void random_harvest_queue(const void *, u_int, u_int, enum random_entropy_source);
111void random_harvest_fast(const void *, u_int, u_int, enum random_entropy_source);
112void random_harvest_direct(const void *, u_int, u_int, enum random_entropy_source);
113#else
114#define random_harvest_queue(a, b, c, d) do {} while (0)
115#define random_harvest_fast(a, b, c, d) do {} while (0)
116#define random_harvest_direct(a, b, c, d) do {} while (0)
117#endif
118
119#if defined(RANDOM_ENABLE_UMA)
120#define random_harvest_fast_uma(a, b, c, d)     random_harvest_fast(a, b, c, d)
121#else /* !defined(RANDOM_ENABLE_UMA) */
122#define random_harvest_fast_uma(a, b, c, d)     do {} while (0)
123#endif /* defined(RANDOM_ENABLE_UMA) */
124
125#endif /* _KERNEL */
126
127#endif /* _SYS_RANDOM_H_ */
Note: See TracBrowser for help on using the repository browser.