yarrow.h revision 65686
167754Smsmith/*- 267754Smsmith * Copyright (c) 2000 Mark R V Murray 367754Smsmith * All rights reserved. 467754Smsmith * 567754Smsmith * Redistribution and use in source and binary forms, with or without 667754Smsmith * modification, are permitted provided that the following conditions 7217365Sjkim * are met: 8281075Sdim * 1. Redistributions of source code must retain the above copyright 970243Smsmith * notice, this list of conditions and the following disclaimer 1067754Smsmith * in this position and unchanged. 11217365Sjkim * 2. Redistributions in binary form must reproduce the above copyright 12217365Sjkim * notice, this list of conditions and the following disclaimer in the 13217365Sjkim * documentation and/or other materials provided with the distribution. 14217365Sjkim * 15217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16217365Sjkim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17217365Sjkim * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18217365Sjkim * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19217365Sjkim * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20217365Sjkim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21217365Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22217365Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23217365Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24217365Sjkim * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2567754Smsmith * 26217365Sjkim * $FreeBSD: head/sys/dev/random/yarrow.h 65686 2000-09-10 13:52:19Z markm $ 27217365Sjkim */ 28217365Sjkim 2967754Smsmith/* #define ENTROPYSOURCE nn entropy sources (actually classes) 30217365Sjkim * The entropy classes will as follows: 31217365Sjkim * 0 - Direct write 32217365Sjkim * 1 - Keyboard 33217365Sjkim * 2 - Mouse 34217365Sjkim */ 35217365Sjkim 36217365Sjkim#define ENTROPYBIN 256 /* buckets to harvest entropy events */ 37217365Sjkim#define TIMEBIN 16 /* max value for Pt/t */ 38217365Sjkim 39217365Sjkim#define FAST 0 40217365Sjkim#define SLOW 1 41217365Sjkim 42217365Sjkimint random_init(void); 4367754Smsmithvoid random_deinit(void); 44193341Sjkimvoid random_init_harvester(void (*)(struct timespec *, void *, u_int, u_int, u_int, enum esource)); 45193341Sjkimvoid random_deinit_harvester(void); 46193341Sjkim 4767754Smsmithvoid write_random(void *, u_int); 48102550Siwasaki 4967754Smsmith/* This is the beastie that needs protecting. It contains all of the 50102550Siwasaki * state that we are excited about. 5191116Smsmith * This is a biiig structure. It may move over to a malloc(9)ed 5267754Smsmith * replacement. 5367754Smsmith */ 5467754Smsmithstruct random_state { 5567754Smsmith u_int64_t counter; /* C */ 56250838Sjkim struct yarrowkey key; /* K */ 5767754Smsmith int gengateinterval; /* Pg */ 5867754Smsmith int bins; /* Pt/t */ 5967754Smsmith int outputblocks; /* count output blocks for gates */ 6067754Smsmith u_int slowoverthresh; /* slow pool overthreshhold reseed count */ 61250838Sjkim struct pool { 6267754Smsmith struct source { 6367754Smsmith u_int bits; /* estimated bits of entropy */ 6467754Smsmith u_int frac; /* fractional bits of entropy 6567754Smsmith (given as 1024/n) */ 6667754Smsmith } source[ENTROPYSOURCE]; 6799679Siwasaki u_int thresh; /* pool reseed threshhold */ 6899679Siwasaki struct yarrowhash hash; /* accumulated entropy */ 6999679Siwasaki } pool[2]; /* pool[0] is fast, pool[1] is slow */ 7099679Siwasaki int which; /* toggle - shows the current insertion pool */ 71281075Sdim}; 7267754Smsmith 7367754Smsmithextern struct random_state random_state; 7467754Smsmith