math/mpreduce.h: Missing include files.
[u/mdw/catacomb] / rand / maurer.h
CommitLineData
39be2708 1/* -*-c-*-
2 *
39be2708 3 * Maurer's universal statistical test
4 *
5 * (c) 2000 Straylight/Edgeware
6 */
7
45c0fd36 8/*----- Licensing notice --------------------------------------------------*
39be2708 9 *
10 * This file is part of Catacomb.
11 *
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
45c0fd36 16 *
39be2708 17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
45c0fd36 21 *
39be2708 22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
39be2708 28#ifndef CATACOMB_MAURER_H
29#define CATACOMB_MAURER_H
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35/*----- Header files ------------------------------------------------------*/
36
37#include <mLib/bits.h>
38
e3dc2d22 39/*----- Data structures ---------------------------------------------------*/
40
41typedef struct maurer_ctx {
42 unsigned l; /* Chunk size, in bits */
43 uint32 a; /* Bitscanner accumulator */
44 unsigned b; /* Number of bits in accumulator */
45 unsigned long n; /* Number of chunks read so far */
46 double x; /* Statistic value */
47 unsigned long *t; /* Offset table */
48} maurer_ctx;
49
39be2708 50/*----- Functions provided ------------------------------------------------*/
51
e3dc2d22 52/* --- @maurer_init@ --- *
53 *
54 * Arguments: @maurer_ctx *m@ = pointer to a context to initialize
55 * @unsigned l@ = number of bits to take at a time
56 *
57 * Returns: Minimum recommended amount of data to test.
58 *
59 * Use: Initializes a Maurer testing context. Note that @l@ values
60 * larger than 16 are not supported, and values less than 6 can
61 * give bizarre results.
62 */
63
64extern unsigned long maurer_init(maurer_ctx */*m*/, unsigned /*l*/);
65
66/* --- @maurer_test@ --- *
67 *
68 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
69 * @const void *buf@ = pointer to a buffer of data
70 * @size_t sz@ = size of the buffer
71 *
72 * Returns: ---
73 *
74 * Use: Scans a buffer of data and updates the testing context.
75 */
76
77extern void maurer_test(maurer_ctx */*m*/,
78 const void */*buf*/, size_t /*sz*/);
79
80/* --- @maurer_done@ --- *
81 *
82 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
83 *
84 * Returns: The statistic %$Z_u = (X_u - \mu)/\sigma$%, which should be
85 * normally distributed with a mean of 0 and variance of 1.
86 *
87 * Use: Returns the result of Maurer's universal statistical test.
88 * Also frees the memory allocated during initialization.
89 *
90 * If insufficient data was received, the value @HUGE_VAL@ is
91 * returned.
92 */
93
94extern double maurer_done(maurer_ctx */*m*/);
95
39be2708 96/* --- @maurer@ --- *
97 *
98 * Arguments: @const octet *p@ = pointer to a buffer of data
99 * @size_t sz@ = size of the buffer
100 * @unsigned l@ = number of bits to take at a time
101 *
e3dc2d22 102 * Returns: The statistic %$Z_u$%.
39be2708 103 *
e3dc2d22 104 * Use: Simple interface to Maurer's universal statistical test. For
105 * large %$l$% you should use the more complicated restartable
106 * interface.
39be2708 107 */
108
109extern double maurer(const octet */*p*/, size_t /*sz*/, unsigned /*l*/);
110
111/*----- That's all, folks -------------------------------------------------*/
112
113#ifdef __cplusplus
114 }
115#endif
116
117#endif