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