11bb2d314SMark Murray /* 21bb2d314SMark Murray * random.h -- A strong random number generator 31bb2d314SMark Murray * 41bb2d314SMark Murray * $Id$ 51bb2d314SMark Murray * 61bb2d314SMark Murray * Version 0.92, last modified 21-Sep-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 501bb2d314SMark Murray #ifndef _MACHINE_RANDOM_H_ 511bb2d314SMark Murray #define _MACHINE_RANDOM_H_ 1 521bb2d314SMark Murray 531bb2d314SMark Murray #include <sys/ioctl.h> 541bb2d314SMark Murray 551bb2d314SMark Murray #define MEM_SETIRQ _IOW('r', 1, int) /* set interrupt */ 561bb2d314SMark Murray #define MEM_CLEARIRQ _IOW('r', 2, int) /* clear interrupt */ 571bb2d314SMark Murray #define MEM_RETURNIRQ _IOR('r', 3, int) /* return interrupt */ 581bb2d314SMark Murray 591bb2d314SMark Murray /* Interrupts to be used in the randomising process */ 601bb2d314SMark Murray 611bb2d314SMark Murray extern u_int16_t interrupt_allowed; 621bb2d314SMark Murray 631bb2d314SMark Murray /* Exported functions */ 641bb2d314SMark Murray 651bb2d314SMark Murray void rand_initialize(void); 661bb2d314SMark Murray void add_keyboard_randomness(u_char scancode); 671bb2d314SMark Murray 681bb2d314SMark Murray void get_random_bytes(void *buf, u_int nbytes); 691bb2d314SMark Murray u_int read_random(char *buf, u_int size); 701bb2d314SMark Murray u_int read_random_unlimited(char *buf, u_int size); 711bb2d314SMark Murray 721bb2d314SMark Murray #endif 73