root/dev/rndvar.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


    1 /*      $OpenBSD: rndvar.h,v 1.19 2003/11/03 18:24:28 tedu Exp $        */
    2 
    3 /*
    4  * Copyright (c) 1996,2000 Michael Shalayeff.
    5  *
    6  * This software derived from one contributed by Theodore Ts'o.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  */
   30 
   31 #ifndef __RNDVAR_H__
   32 #define __RNDVAR_H__
   33 
   34 #define POOLWORDS 1024  /* Power of 2 - note that this is 32-bit words */
   35 
   36 #define RND_RND         0       /* real randomness like nuclear chips */
   37 #define RND_SRND        1       /* strong random source */
   38 #define RND_URND        2       /* less strong random source */
   39 #define RND_PRND        3       /* pseudo random source */
   40 #define RND_ARND        4       /* aRC4 based random number generator */
   41 #define RND_NODEV       5       /* First invalid minor device number */
   42 
   43 #define RND_SRC_TRUE    0
   44 #define RND_SRC_TIMER   1
   45 #define RND_SRC_MOUSE   2
   46 #define RND_SRC_TTY     3
   47 #define RND_SRC_DISK    4
   48 #define RND_SRC_NET     5
   49 #define RND_SRC_AUDIO   6
   50 #define RND_SRC_VIDEO   7
   51 #define RND_SRC_NUM     8
   52 
   53 struct rndstats {
   54         quad_t rnd_total;       /* total bits of entropy generated */
   55         quad_t rnd_used;        /* strong data bits read so far */
   56         quad_t rnd_reads;       /* strong read calls */
   57         quad_t arc4_reads;      /* aRC4 data bytes read so far */
   58         quad_t arc4_nstirs;     /* arc4 pool stirs */
   59         quad_t arc4_stirs;      /* arc4 pool stirs (bits used) */
   60 
   61         quad_t rnd_pad[5];
   62 
   63         quad_t rnd_waits;       /* sleeps for data */
   64         quad_t rnd_enqs;        /* enqueue calls */
   65         quad_t rnd_deqs;        /* dequeue calls */
   66         quad_t rnd_drops;       /* queue-full drops */
   67         quad_t rnd_drople;      /* queue low watermark low entropy drops */
   68 
   69         quad_t rnd_ed[32];      /* entropy feed distribution */
   70         quad_t rnd_sc[RND_SRC_NUM]; /* add* calls */
   71         quad_t rnd_sb[RND_SRC_NUM]; /* add* bits */
   72 };
   73 
   74 #ifdef _KERNEL
   75 extern struct rndstats rndstats;
   76 
   77 #define add_true_randomness(d)  enqueue_randomness(RND_SRC_TRUE,  (int)(d))
   78 #define add_timer_randomness(d) enqueue_randomness(RND_SRC_TIMER, (int)(d))
   79 #define add_mouse_randomness(d) enqueue_randomness(RND_SRC_MOUSE, (int)(d))
   80 #define add_tty_randomness(d)   enqueue_randomness(RND_SRC_TTY,   (int)(d))
   81 #define add_disk_randomness(d)  enqueue_randomness(RND_SRC_DISK,  (int)(d))
   82 #define add_net_randomness(d)   enqueue_randomness(RND_SRC_NET,   (int)(d))
   83 #define add_audio_randomness(d) enqueue_randomness(RND_SRC_AUDIO, (int)(d))
   84 #define add_video_randomness(d) enqueue_randomness(RND_SRC_VIDEO, (int)(d))
   85 
   86 void enqueue_randomness(int, int);
   87 void get_random_bytes(void *, size_t);
   88 void arc4random_bytes(void *, size_t);
   89 u_int32_t arc4random(void);
   90 
   91 #endif /* _KERNEL */
   92 
   93 #endif /* __RNDVAR_H__ */

/* [<][>][^][v][top][bottom][index][help] */