1112125Ssam/* $FreeBSD$ */ 2112125Ssam/* $OpenBSD$ */ 3112125Ssam 4139749Simp/*- 5112125Ssam * Copyright (c) 2002 Jason L. Wright (jason@thought.net) 6112125Ssam * All rights reserved. 7112125Ssam * 8112125Ssam * Redistribution and use in source and binary forms, with or without 9112125Ssam * modification, are permitted provided that the following conditions 10112125Ssam * are met: 11112125Ssam * 1. Redistributions of source code must retain the above copyright 12112125Ssam * notice, this list of conditions and the following disclaimer. 13112125Ssam * 2. Redistributions in binary form must reproduce the above copyright 14112125Ssam * notice, this list of conditions and the following disclaimer in the 15112125Ssam * documentation and/or other materials provided with the distribution. 16112125Ssam * 3. All advertising materials mentioning features or use of this software 17112125Ssam * must display the following acknowledgement: 18112125Ssam * This product includes software developed by Jason L. Wright 19112125Ssam * 4. The name of the author may not be used to endorse or promote products 20112125Ssam * derived from this software without specific prior written permission. 21112125Ssam * 22112125Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23112125Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24112125Ssam * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25112125Ssam * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26112125Ssam * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27112125Ssam * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28112125Ssam * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29112125Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30112125Ssam * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31112125Ssam * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32112125Ssam * POSSIBILITY OF SUCH DAMAGE. 33112125Ssam */ 34112125Ssam 35112125Ssam 36112125Ssam/* Some of the tests depend on these values */ 37112125Ssam#define RNDTEST_NBYTES 2500 38112125Ssam#define RNDTEST_NBITS (8 * RNDTEST_NBYTES) 39112125Ssam 40112125Ssamstruct rndtest_state { 41112125Ssam device_t rs_parent; /* associated device */ 42112125Ssam u_int8_t *rs_end, *rs_begin, *rs_current; 43112125Ssam struct callout rs_to; 44112125Ssam int rs_collect; /* collect and test data */ 45112125Ssam int rs_discard; /* discard/accept random data */ 46112125Ssam u_int8_t rs_buf[RNDTEST_NBYTES]; 47112125Ssam}; 48112125Ssam 49112125Ssamstruct rndtest_stats { 50112125Ssam u_int32_t rst_discard; /* number of bytes discarded */ 51112125Ssam u_int32_t rst_tests; /* number of test runs */ 52112125Ssam u_int32_t rst_monobit; /* monobit test failures */ 53112125Ssam u_int32_t rst_runs; /* 0/1 runs failures */ 54112125Ssam u_int32_t rst_longruns; /* longruns failures */ 55112125Ssam u_int32_t rst_chi; /* chi^2 failures */ 56112125Ssam}; 57112125Ssam 58112125Ssamextern struct rndtest_state *rndtest_attach(device_t dev); 59112125Ssamextern void rndtest_detach(struct rndtest_state *); 60112125Ssamextern void rndtest_harvest(struct rndtest_state *arg, void * buf, u_int len); 61