The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/rnd.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: rnd.h,v 1.20 2006/09/20 05:21:38 cube Exp $    */
    2 
    3 /*-
    4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Michael Graff <explorer@flame.org>.  This code uses ideas and
    9  * algorithms from the Linux driver written by Ted Ts'o.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. All advertising materials mentioning features or use of this software
   20  *    must display the following acknowledgement:
   21  *      This product includes software developed by the NetBSD
   22  *      Foundation, Inc. and its contributors.
   23  * 4. Neither the name of The NetBSD Foundation nor the names of its
   24  *    contributors may be used to endorse or promote products derived
   25  *    from this software without specific prior written permission.
   26  *
   27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   37  * POSSIBILITY OF SUCH DAMAGE.
   38  */
   39 
   40 #ifndef _SYS_RND_H_
   41 #define _SYS_RND_H_
   42 
   43 #ifndef _KERNEL
   44 #include <sys/cdefs.h>
   45 #endif /* !_KERNEL */
   46 
   47 #include <sys/types.h>
   48 
   49 #ifdef _KERNEL
   50 #include <sys/queue.h>
   51 #endif
   52 
   53 #define RND_DEV_RANDOM  0       /* minor devices for random and kinda random */
   54 #define RND_DEV_URANDOM 1
   55 
   56 /*
   57  * Size of entropy pool in 32-bit words.  This _MUST_ be a power of 2.  Don't
   58  * change this unless you really know what you are doing...
   59  */
   60 #ifndef RND_POOLWORDS
   61 #define RND_POOLWORDS   128
   62 #endif
   63 #define RND_POOLBITS    (RND_POOLWORDS * 32)
   64 
   65 /*
   66  * Number of bytes returned per hash.  This value is used in both
   67  * rnd.c and rndpool.c to decide when enough entropy exists to do a
   68  * hash to extract it.
   69  */
   70 #define RND_ENTROPY_THRESHOLD   10
   71 
   72 /*
   73  * Size of the event queue.  This _MUST_ be a power of 2.
   74  */
   75 #ifndef RND_EVENTQSIZE
   76 #define RND_EVENTQSIZE  128
   77 #endif
   78 
   79 typedef struct
   80 {
   81         uint32_t        poolsize;
   82         uint32_t        threshold;
   83         uint32_t        maxentropy;
   84 
   85         uint32_t        added;
   86         uint32_t        curentropy;
   87         uint32_t        removed;
   88         uint32_t        discarded;
   89         uint32_t        generated;
   90 } rndpoolstat_t;
   91 
   92 
   93 typedef struct {
   94         uint32_t        cursor;         /* current add point in the pool */
   95         uint32_t        rotate;         /* how many bits to rotate by */
   96         rndpoolstat_t   stats;          /* current statistics */
   97         uint32_t        pool[RND_POOLWORDS]; /* random pool data */
   98 } rndpool_t;
   99 
  100 typedef struct {
  101         char            name[16];       /* device name */
  102         uint32_t        last_time;      /* last time recorded */
  103         uint32_t        last_delta;     /* last delta value */
  104         uint32_t        last_delta2;    /* last delta2 value */
  105         uint32_t        total;          /* entropy from this source */
  106         uint32_t        type;           /* type */
  107         uint32_t        flags;          /* flags */
  108         void            *state;         /* state informaiton */
  109 } rndsource_t;
  110 
  111 
  112 /*
  113  * Flags to control the source.  Low byte is type, upper bits are flags.
  114  */
  115 #define RND_FLAG_NO_ESTIMATE    0x00000100      /* don't estimate entropy */
  116 #define RND_FLAG_NO_COLLECT     0x00000200      /* don't collect entropy */
  117 
  118 #define RND_TYPE_UNKNOWN        0       /* unknown source */
  119 #define RND_TYPE_DISK           1       /* source is physical disk */
  120 #define RND_TYPE_NET            2       /* source is a network device */
  121 #define RND_TYPE_TAPE           3       /* source is a tape drive */
  122 #define RND_TYPE_TTY            4       /* source is a tty device */
  123 #define RND_TYPE_RNG            5       /* source is a random number
  124                                            generator */
  125 #define RND_TYPE_MAX            5       /* last type id used */
  126 
  127 #ifdef _KERNEL
  128 typedef struct __rndsource_element rndsource_element_t;
  129 
  130 struct __rndsource_element {
  131         LIST_ENTRY(__rndsource_element) list; /* the linked list */
  132         rndsource_t     data;           /* the actual data */
  133 };
  134 
  135 /*
  136  * Used by rnd_extract_data() and rndpool_extract_data() to describe how
  137  * "good" the data has to be.
  138  */
  139 #define RND_EXTRACT_ANY         0  /* extract anything, even if no entropy */
  140 #define RND_EXTRACT_GOOD        1  /* return as many good bytes
  141                                       (short read ok) */
  142 
  143 #define RND_ENABLED(rp) \
  144         (((rp)->data.flags & RND_FLAG_NO_COLLECT) == 0)
  145 
  146 void            rndpool_init(rndpool_t *);
  147 void            rndpool_init_global(void);
  148 uint32_t        rndpool_get_entropy_count(rndpool_t *);
  149 void            rndpool_get_stats(rndpool_t *, void *, int);
  150 void            rndpool_increment_entropy_count(rndpool_t *, uint32_t);
  151 uint32_t        *rndpool_get_pool(rndpool_t *);
  152 uint32_t        rndpool_get_poolsize(void);
  153 void            rndpool_add_data(rndpool_t *, void *, uint32_t, uint32_t);
  154 uint32_t        rndpool_extract_data(rndpool_t *, void *, uint32_t,
  155                     uint32_t);
  156 
  157 void            rnd_init(void);
  158 void            rnd_add_uint32(rndsource_element_t *, uint32_t);
  159 void            rnd_add_data(rndsource_element_t *, void *, uint32_t,
  160                     uint32_t);
  161 uint32_t        rnd_extract_data(void *, uint32_t, uint32_t);
  162 void            rnd_attach_source(rndsource_element_t *, const char *,
  163                     uint32_t, uint32_t);
  164 void            rnd_detach_source(rndsource_element_t *);
  165 
  166 #endif /* _KERNEL */
  167 
  168 #define RND_MAXSTATCOUNT        10      /* 10 sources at once max */
  169 
  170 /*
  171  * return "count" random entries, starting at "start"
  172  */
  173 typedef struct {
  174         uint32_t        start;
  175         uint32_t        count;
  176         rndsource_t     source[RND_MAXSTATCOUNT];
  177 } rndstat_t;
  178 
  179 /*
  180  * return information on a specific source by name
  181  */
  182 typedef struct {
  183         char            name[16];
  184         rndsource_t     source;
  185 } rndstat_name_t;
  186 
  187 /*
  188  * set/clear device flags.  If type is set to 0xff, the name is used
  189  * instead.  Otherwise, the flags set/cleared apply to all devices of
  190  * the specified type, and the name is ignored.
  191  */
  192 typedef struct {
  193         char            name[16];       /* the name we are adjusting */
  194         uint32_t        type;           /* the type of device we want */
  195         uint32_t        flags;          /* flags to set or clear */
  196         uint32_t        mask;           /* mask for the flags we are setting */
  197 } rndctl_t;
  198 
  199 typedef struct {
  200         uint32_t        len;
  201         uint32_t        entropy;
  202         u_char          data[RND_POOLWORDS * 4];
  203 } rnddata_t;
  204 
  205 #define RNDGETENTCNT    _IOR('R',  101, uint32_t) /* get entropy count */
  206 #define RNDGETSRCNUM    _IOWR('R', 102, rndstat_t) /* get rnd source info */
  207 #define RNDGETSRCNAME   _IOWR('R', 103, rndstat_name_t) /* get src by name */
  208 #define RNDCTL          _IOW('R',  104, rndctl_t)  /* set/clear source flags */
  209 #define RNDADDDATA      _IOW('R',  105, rnddata_t) /* add data to the pool */
  210 #define RNDGETPOOLSTAT  _IOR('R',  106, rndpoolstat_t)
  211 
  212 #endif /* !_SYS_RND_H_ */

Cache object: b8fd374c60843be1f4d58a139014cbb2


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.