102c986abSMark Murray /*- 2d1b06863SMark Murray * Copyright (c) 2000-2015 Mark R V Murray 302c986abSMark Murray * All rights reserved. 402c986abSMark Murray * 502c986abSMark Murray * Redistribution and use in source and binary forms, with or without 602c986abSMark Murray * modification, are permitted provided that the following conditions 702c986abSMark Murray * are met: 802c986abSMark Murray * 1. Redistributions of source code must retain the above copyright 902c986abSMark Murray * notice, this list of conditions and the following disclaimer 1002c986abSMark Murray * in this position and unchanged. 1102c986abSMark Murray * 2. Redistributions in binary form must reproduce the above copyright 1202c986abSMark Murray * notice, this list of conditions and the following disclaimer in the 1302c986abSMark Murray * documentation and/or other materials provided with the distribution. 1402c986abSMark Murray * 1502c986abSMark Murray * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1602c986abSMark Murray * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1702c986abSMark Murray * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1802c986abSMark Murray * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1902c986abSMark Murray * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2002c986abSMark Murray * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2102c986abSMark Murray * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2202c986abSMark Murray * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2302c986abSMark Murray * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2402c986abSMark Murray * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2502c986abSMark Murray * 2602c986abSMark Murray * $FreeBSD$ 2702c986abSMark Murray */ 2802c986abSMark Murray 293e8957eaSDag-Erling Smørgrav #ifndef SYS_DEV_RANDOM_RANDOMDEV_H_INCLUDED 303e8957eaSDag-Erling Smørgrav #define SYS_DEV_RANDOM_RANDOMDEV_H_INCLUDED 313e8957eaSDag-Erling Smørgrav 323aa77530SMark Murray #ifdef _KERNEL 333aa77530SMark Murray 3402c986abSMark Murray /* This header contains only those definitions that are global 3502c986abSMark Murray * and non algorithm-specific for the entropy processor 3602c986abSMark Murray */ 3702c986abSMark Murray 3810cb2424SMark Murray #ifdef SYSCTL_DECL /* from sysctl.h */ 3910cb2424SMark Murray SYSCTL_DECL(_kern_random); 403782136fSConrad Meyer SYSCTL_DECL(_kern_random_initial_seeding); 4110cb2424SMark Murray 4210cb2424SMark Murray #define RANDOM_CHECK_UINT(name, min, max) \ 4310cb2424SMark Murray static int \ 4410cb2424SMark Murray random_check_uint_##name(SYSCTL_HANDLER_ARGS) \ 4510cb2424SMark Murray { \ 4610cb2424SMark Murray if (oidp->oid_arg1 != NULL) { \ 4710cb2424SMark Murray if (*(u_int *)(oidp->oid_arg1) <= (min)) \ 4810cb2424SMark Murray *(u_int *)(oidp->oid_arg1) = (min); \ 4910cb2424SMark Murray else if (*(u_int *)(oidp->oid_arg1) > (max)) \ 5010cb2424SMark Murray *(u_int *)(oidp->oid_arg1) = (max); \ 5110cb2424SMark Murray } \ 5210cb2424SMark Murray return (sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, \ 5310cb2424SMark Murray req)); \ 5410cb2424SMark Murray } 5510cb2424SMark Murray #endif /* SYSCTL_DECL */ 563e8957eaSDag-Erling Smørgrav 57d1b06863SMark Murray MALLOC_DECLARE(M_ENTROPY); 58d1b06863SMark Murray 593782136fSConrad Meyer extern bool random_bypass_before_seeding; 603782136fSConrad Meyer extern bool read_random_bypassed_before_seeding; 613782136fSConrad Meyer extern bool arc4random_bypassed_before_seeding; 623782136fSConrad Meyer extern bool random_bypass_disable_warnings; 633782136fSConrad Meyer 643aa77530SMark Murray #endif /* _KERNEL */ 653aa77530SMark Murray 66d1b06863SMark Murray struct harvest_event; 67d1b06863SMark Murray 68d1b06863SMark Murray typedef void random_alg_pre_read_t(void); 69d0d71d81SConrad Meyer typedef void random_alg_read_t(uint8_t *, size_t); 70646041a8SMark Murray typedef bool random_alg_seeded_t(void); 71d1b06863SMark Murray typedef void random_alg_eventprocessor_t(struct harvest_event *); 72d1b06863SMark Murray 73d1b06863SMark Murray typedef u_int random_source_read_t(void *, u_int); 74d1b06863SMark Murray 75d1b06863SMark Murray /* 76d1b06863SMark Murray * Random Algorithm is a processor of randomness for the kernel 77d1b06863SMark Murray * and for userland. 78d1b06863SMark Murray */ 79d1b06863SMark Murray struct random_algorithm { 80d1b06863SMark Murray const char *ra_ident; 81d1b06863SMark Murray u_int ra_poolcount; 82d1b06863SMark Murray random_alg_pre_read_t *ra_pre_read; 83d1b06863SMark Murray random_alg_read_t *ra_read; 84d1b06863SMark Murray random_alg_seeded_t *ra_seeded; 85d1b06863SMark Murray random_alg_eventprocessor_t *ra_event_processor; 86d1b06863SMark Murray }; 87d1b06863SMark Murray 88*3ee1d5bbSConrad Meyer #if defined(RANDOM_LOADABLE) 89*3ee1d5bbSConrad Meyer extern const struct random_algorithm *p_random_alg_context; 90*3ee1d5bbSConrad Meyer #else 91*3ee1d5bbSConrad Meyer extern const struct random_algorithm random_alg_context; 92*3ee1d5bbSConrad Meyer #define p_random_alg_context (&random_alg_context) 93*3ee1d5bbSConrad Meyer #endif 94d1b06863SMark Murray 953aa77530SMark Murray #ifdef _KERNEL 963aa77530SMark Murray 97d1b06863SMark Murray /* 98d1b06863SMark Murray * Random Source is a source of entropy that can provide 99d1b06863SMark Murray * specified or approximate amount of entropy immediately 100d1b06863SMark Murray * upon request. 101d1b06863SMark Murray */ 102d1b06863SMark Murray struct random_source { 103d1b06863SMark Murray const char *rs_ident; 104d1b06863SMark Murray enum random_entropy_source rs_source; 105d1b06863SMark Murray random_source_read_t *rs_read; 106d1b06863SMark Murray }; 107d1b06863SMark Murray 108d1b06863SMark Murray void random_source_register(struct random_source *); 109d1b06863SMark Murray void random_source_deregister(struct random_source *); 110d1b06863SMark Murray 1113aa77530SMark Murray #endif /* _KERNEL */ 1123aa77530SMark Murray 113d1b06863SMark Murray void randomdev_unblock(void); 114d1b06863SMark Murray 115d1b06863SMark Murray #endif /* SYS_DEV_RANDOM_RANDOMDEV_H_INCLUDED */ 116