1*86d7f5d3SJohn Marino /* $FreeBSD: src/sys/dev/rndtest/rndtest.h,v 1.1.4.1 2003/06/04 17:10:30 sam Exp $ */ 2*86d7f5d3SJohn Marino /* $DragonFly: src/sys/dev/crypto/rndtest/rndtest.h,v 1.2 2003/06/17 04:28:29 dillon Exp $ */ 3*86d7f5d3SJohn Marino /* $OpenBSD$ */ 4*86d7f5d3SJohn Marino 5*86d7f5d3SJohn Marino /* 6*86d7f5d3SJohn Marino * Copyright (c) 2002 Jason L. Wright (jason@thought.net) 7*86d7f5d3SJohn Marino * All rights reserved. 8*86d7f5d3SJohn Marino * 9*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 10*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 11*86d7f5d3SJohn Marino * are met: 12*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright 13*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 14*86d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 15*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the 16*86d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution. 17*86d7f5d3SJohn Marino * 3. All advertising materials mentioning features or use of this software 18*86d7f5d3SJohn Marino * must display the following acknowledgement: 19*86d7f5d3SJohn Marino * This product includes software developed by Jason L. Wright 20*86d7f5d3SJohn Marino * 4. The name of the author may not be used to endorse or promote products 21*86d7f5d3SJohn Marino * derived from this software without specific prior written permission. 22*86d7f5d3SJohn Marino * 23*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24*86d7f5d3SJohn Marino * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25*86d7f5d3SJohn Marino * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26*86d7f5d3SJohn Marino * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27*86d7f5d3SJohn Marino * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28*86d7f5d3SJohn Marino * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29*86d7f5d3SJohn Marino * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30*86d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31*86d7f5d3SJohn Marino * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32*86d7f5d3SJohn Marino * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33*86d7f5d3SJohn Marino * POSSIBILITY OF SUCH DAMAGE. 34*86d7f5d3SJohn Marino */ 35*86d7f5d3SJohn Marino 36*86d7f5d3SJohn Marino 37*86d7f5d3SJohn Marino /* Some of the tests depend on these values */ 38*86d7f5d3SJohn Marino #define RNDTEST_NBYTES 2500 39*86d7f5d3SJohn Marino #define RNDTEST_NBITS (8 * RNDTEST_NBYTES) 40*86d7f5d3SJohn Marino 41*86d7f5d3SJohn Marino struct rndtest_state { 42*86d7f5d3SJohn Marino device_t rs_parent; /* associated device */ 43*86d7f5d3SJohn Marino u_int8_t *rs_end, *rs_begin, *rs_current; 44*86d7f5d3SJohn Marino struct callout rs_to; 45*86d7f5d3SJohn Marino int rs_collect; /* collect and test data */ 46*86d7f5d3SJohn Marino int rs_discard; /* discard/accept random data */ 47*86d7f5d3SJohn Marino u_int8_t rs_buf[RNDTEST_NBYTES]; 48*86d7f5d3SJohn Marino }; 49*86d7f5d3SJohn Marino 50*86d7f5d3SJohn Marino struct rndtest_stats { 51*86d7f5d3SJohn Marino u_int32_t rst_discard; /* number of bytes discarded */ 52*86d7f5d3SJohn Marino u_int32_t rst_tests; /* number of test runs */ 53*86d7f5d3SJohn Marino u_int32_t rst_monobit; /* monobit test failures */ 54*86d7f5d3SJohn Marino u_int32_t rst_runs; /* 0/1 runs failures */ 55*86d7f5d3SJohn Marino u_int32_t rst_longruns; /* longruns failures */ 56*86d7f5d3SJohn Marino u_int32_t rst_chi; /* chi^2 failures */ 57*86d7f5d3SJohn Marino }; 58*86d7f5d3SJohn Marino 59*86d7f5d3SJohn Marino extern struct rndtest_state *rndtest_attach(device_t dev); 60*86d7f5d3SJohn Marino extern void rndtest_detach(struct rndtest_state *); 61*86d7f5d3SJohn Marino extern void rndtest_harvest(struct rndtest_state *arg, void * buf, u_int len); 62