2 * Copyright (c) 2015 Mark R V Murray
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/random.h>
36 #include <sys/sysctl.h>
38 #include <dev/random/randomdev.h>
40 /* Set up the sysctl root node for the entropy device */
41 SYSCTL_NODE(_kern, OID_AUTO, random, CTLFLAG_RW, 0,
42 "Cryptographically Secure Random Number Generator");
43 SYSCTL_NODE(_kern_random, OID_AUTO, initial_seeding, CTLFLAG_RW, 0,
44 "Initial seeding control and information");
47 * N.B., this is a dangerous default, but it matches the behavior prior to
48 * r346250 (and, say, OpenBSD -- although they get some guaranteed saved
49 * entropy from the prior boot because of their KARL system, on RW media).
51 bool random_bypass_before_seeding = true;
52 SYSCTL_BOOL(_kern_random_initial_seeding, OID_AUTO,
53 bypass_before_seeding, CTLFLAG_RDTUN, &random_bypass_before_seeding,
54 0, "If set non-zero, bypass the random device in requests for random "
55 "data when the random device is not yet seeded. This is considered "
56 "dangerous. Ordinarily, the random device will block requests until "
57 "it is seeded by sufficient entropy.");
60 * This is a read-only diagnostic that reports the combination of the former
61 * tunable and actual bypass. It is intended for programmatic inspection by
62 * userspace administrative utilities after boot.
64 bool read_random_bypassed_before_seeding = false;
65 SYSCTL_BOOL(_kern_random_initial_seeding, OID_AUTO,
66 read_random_bypassed_before_seeding, CTLFLAG_RD,
67 &read_random_bypassed_before_seeding, 0, "If non-zero, the random device "
68 "was bypassed because the 'bypass_before_seeding' knob was enabled and a "
69 "request was submitted prior to initial seeding.");
72 * This is a read-only diagnostic that reports the combination of the former
73 * tunable and actual bypass for arc4random initial seeding. It is intended
74 * for programmatic inspection by userspace administrative utilities after
77 bool arc4random_bypassed_before_seeding = false;
78 SYSCTL_BOOL(_kern_random_initial_seeding, OID_AUTO,
79 arc4random_bypassed_before_seeding, CTLFLAG_RD,
80 &arc4random_bypassed_before_seeding, 0, "If non-zero, the random device "
81 "was bypassed when initially seeding the kernel arc4random(9), because "
82 "the 'bypass_before_seeding' knob was enabled and a request was submitted "
83 "prior to initial seeding.");
86 * This knob is for users who do not want additional warnings in their logs
87 * because they intend to handle bypass by inspecting the status of the
90 bool random_bypass_disable_warnings = false;
91 SYSCTL_BOOL(_kern_random_initial_seeding, OID_AUTO,
92 disable_bypass_warnings, CTLFLAG_RDTUN,
93 &random_bypass_disable_warnings, 0, "If non-zero, do not log a warning "
94 "if the 'bypass_before_seeding' knob is enabled and a request is "
95 "submitted prior to initial seeding.");
97 MALLOC_DEFINE(M_ENTROPY, "entropy", "Entropy harvesting buffers and data structures");
99 #if defined(RANDOM_LOADABLE)
100 const struct random_algorithm *p_random_alg_context;
101 void (*_read_random)(void *, u_int);
102 int (*_read_random_uio)(struct uio *, bool);
103 bool (*_is_random_seeded)(void);
104 #endif /* defined(RANDOM_LOADABLE) */