2 * Copyright (c) 2000-2013 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.
29 #ifndef SYS_DEV_RANDOM_RANDOMDEV_H_INCLUDED
30 #define SYS_DEV_RANDOM_RANDOMDEV_H_INCLUDED
32 /* This header contains only those definitions that are global
33 * and non algorithm-specific for the entropy processor
36 typedef void random_init_func_t(void);
37 typedef void random_deinit_func_t(void);
39 void randomdev_init_harvester(void (*)(const void *, u_int, u_int, enum random_entropy_source));
40 void randomdev_init_reader(void (*)(uint8_t *, u_int));
41 void randomdev_deinit_harvester(void);
42 void randomdev_deinit_reader(void);
44 /* Stub/fake routines for when no entropy processor is loaded */
45 extern void dummy_random_read_phony(uint8_t *, u_int);
47 /* kern.random sysctls */
48 #ifdef SYSCTL_DECL /* from sysctl.h */
49 SYSCTL_DECL(_kern_random);
51 /* If this was C++, the macro below would be a template */
52 #define RANDOM_CHECK_UINT(name, min, max) \
54 random_check_uint_##name(SYSCTL_HANDLER_ARGS) \
56 if (oidp->oid_arg1 != NULL) { \
57 if (*(u_int *)(oidp->oid_arg1) <= (min)) \
58 *(u_int *)(oidp->oid_arg1) = (min); \
59 else if (*(u_int *)(oidp->oid_arg1) > (max)) \
60 *(u_int *)(oidp->oid_arg1) = (max); \
62 return (sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, \
65 #endif /* SYSCTL_DECL */