162053Smarkm/*- 2128059Smarkm * Copyright (c) 2000-2004 Mark R V Murray 362053Smarkm * All rights reserved. 462053Smarkm * 562053Smarkm * Redistribution and use in source and binary forms, with or without 662053Smarkm * modification, are permitted provided that the following conditions 762053Smarkm * are met: 862053Smarkm * 1. Redistributions of source code must retain the above copyright 962053Smarkm * notice, this list of conditions and the following disclaimer 1062053Smarkm * in this position and unchanged. 1162053Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1262053Smarkm * notice, this list of conditions and the following disclaimer in the 1362053Smarkm * documentation and/or other materials provided with the distribution. 1462053Smarkm * 1562053Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1662053Smarkm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1762053Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1862053Smarkm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1962053Smarkm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2062053Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2162053Smarkm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2262053Smarkm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2362053Smarkm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2462053Smarkm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2562053Smarkm * 2662053Smarkm * $FreeBSD$ 2762053Smarkm */ 2862053Smarkm 2974072Smarkm/* This contains Yarrow-specific declarations. 3074072Smarkm * See http://www.counterpane.com/yarrow.html 3163771Smarkm */ 3262053Smarkm 3362765Smarkm#define TIMEBIN 16 /* max value for Pt/t */ 3462765Smarkm 3562765Smarkm#define FAST 0 3662765Smarkm#define SLOW 1 3762765Smarkm 3863771Smarkm/* This is the beastie that needs protecting. It contains all of the 3962053Smarkm * state that we are excited about. 4074072Smarkm * Exactly one will be instantiated. 4162053Smarkm */ 4262765Smarkmstruct random_state { 4374072Smarkm u_int64_t counter[4]; /* C - 256 bits */ 4465686Smarkm struct yarrowkey key; /* K */ 4574072Smarkm u_int gengateinterval; /* Pg */ 4674072Smarkm u_int bins; /* Pt/t */ 4774072Smarkm u_int outputblocks; /* count output blocks for gates */ 4862765Smarkm u_int slowoverthresh; /* slow pool overthreshhold reseed count */ 4962765Smarkm struct pool { 5062765Smarkm struct source { 5162765Smarkm u_int bits; /* estimated bits of entropy */ 5262765Smarkm u_int frac; /* fractional bits of entropy 5362765Smarkm (given as 1024/n) */ 5462765Smarkm } source[ENTROPYSOURCE]; 5562765Smarkm u_int thresh; /* pool reseed threshhold */ 5665686Smarkm struct yarrowhash hash; /* accumulated entropy */ 5762765Smarkm } pool[2]; /* pool[0] is fast, pool[1] is slow */ 5874072Smarkm u_int which; /* toggle - sets the current insertion pool */ 5962053Smarkm}; 60