11bb2d314SMark Murray /* 21bb2d314SMark Murray * random.h -- A strong random number generator 31bb2d314SMark Murray * 4c3aac50fSPeter Wemm * $FreeBSD$ 51bb2d314SMark Murray * 66a9bf141SMark Murray * Version 0.95, last modified 18-Oct-95 71bb2d314SMark Murray * 81bb2d314SMark Murray * Copyright Theodore Ts'o, 1994, 1995. All rights reserved. 91bb2d314SMark Murray * 101bb2d314SMark Murray * Redistribution and use in source and binary forms, with or without 111bb2d314SMark Murray * modification, are permitted provided that the following conditions 121bb2d314SMark Murray * are met: 131bb2d314SMark Murray * 1. Redistributions of source code must retain the above copyright 141bb2d314SMark Murray * notice, and the entire permission notice in its entirety, 151bb2d314SMark Murray * including the disclaimer of warranties. 161bb2d314SMark Murray * 2. Redistributions in binary form must reproduce the above copyright 171bb2d314SMark Murray * notice, this list of conditions and the following disclaimer in the 181bb2d314SMark Murray * documentation and/or other materials provided with the distribution. 191bb2d314SMark Murray * 3. The name of the author may not be used to endorse or promote 201bb2d314SMark Murray * products derived from this software without specific prior 211bb2d314SMark Murray * written permission. 221bb2d314SMark Murray * 231bb2d314SMark Murray * ALTERNATIVELY, this product may be distributed under the terms of 241bb2d314SMark Murray * the GNU Public License, in which case the provisions of the GPL are 251bb2d314SMark Murray * required INSTEAD OF the above restrictions. (This clause is 261bb2d314SMark Murray * necessary due to a potential bad interaction between the GPL and 271bb2d314SMark Murray * the restrictions contained in a BSD-style copyright.) 281bb2d314SMark Murray * 291bb2d314SMark Murray * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 301bb2d314SMark Murray * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 311bb2d314SMark Murray * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 321bb2d314SMark Murray * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 331bb2d314SMark Murray * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 341bb2d314SMark Murray * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 351bb2d314SMark Murray * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 361bb2d314SMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 371bb2d314SMark Murray * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 381bb2d314SMark Murray * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 391bb2d314SMark Murray * OF THE POSSIBILITY OF SUCH DAMAGE. 401bb2d314SMark Murray * 411bb2d314SMark Murray */ 421bb2d314SMark Murray 431bb2d314SMark Murray /* 441bb2d314SMark Murray * Many kernel routines will have a use for good random numbers, 451bb2d314SMark Murray * for example, for truely random TCP sequence numbers, which prevent 461bb2d314SMark Murray * certain forms of TCP spoofing attacks. 471bb2d314SMark Murray * 481bb2d314SMark Murray */ 491bb2d314SMark Murray 50a3b693c9SBruce Evans #ifndef _SYS_RANDOM_H_ 51a3b693c9SBruce Evans #define _SYS_RANDOM_H_ 521bb2d314SMark Murray 53f0ea07bfSBruce Evans #include <sys/ioccom.h> 541bb2d314SMark Murray 556a9bf141SMark Murray #define MEM_SETIRQ _IOW('r', 1, u_int16_t) /* set interrupt */ 566a9bf141SMark Murray #define MEM_CLEARIRQ _IOW('r', 2, u_int16_t) /* clear interrupt */ 576a9bf141SMark Murray #define MEM_RETURNIRQ _IOR('r', 3, u_int16_t) /* return interrupt */ 586a9bf141SMark Murray 59664a31e4SPeter Wemm #ifdef _KERNEL 60f0ea07bfSBruce Evans 61316bbd5cSBruce Evans /* Type of the cookie passed to add_interrupt_randomness. */ 621bb2d314SMark Murray 63316bbd5cSBruce Evans struct random_softc { 64316bbd5cSBruce Evans inthand2_t *sc_handler; 65316bbd5cSBruce Evans void *sc_arg; 66316bbd5cSBruce Evans int sc_intr; 67316bbd5cSBruce Evans }; 681bb2d314SMark Murray 691bb2d314SMark Murray /* Exported functions */ 701bb2d314SMark Murray 711bb2d314SMark Murray void rand_initialize(void); 721bb2d314SMark Murray void add_keyboard_randomness(u_char scancode); 73316bbd5cSBruce Evans inthand2_t add_interrupt_randomness; 74aba89c50SMark Murray #ifdef notused 756a9bf141SMark Murray void add_blkdev_randomness(int major); 76aba89c50SMark Murray #endif 771bb2d314SMark Murray 78aba89c50SMark Murray #ifdef notused 791bb2d314SMark Murray void get_random_bytes(void *buf, u_int nbytes); 80aba89c50SMark Murray #endif 812eeb0e2eSPoul-Henning Kamp u_int read_random(void *buf, u_int size); 822eeb0e2eSPoul-Henning Kamp u_int read_random_unlimited(void *buf, u_int size); 83aba89c50SMark Murray #ifdef notused 846a9bf141SMark Murray u_int write_random(const char *buf, u_int nbytes); 85aba89c50SMark Murray #endif 86a3b693c9SBruce Evans struct proc; 8735b8b2ddSPeter Wemm int random_poll(dev_t dev, int events, struct proc *p); 886a9bf141SMark Murray 89664a31e4SPeter Wemm #endif /* _KERNEL */ 901bb2d314SMark Murray 91a3b693c9SBruce Evans #endif /* !_SYS_RANDOM_H_ */ 92