3 * $Id: maurer.h,v 1.2 2000/08/11 21:34:59 mdw Exp $
5 * Maurer's universal statistical test
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 2000/08/11 21:34:59 mdw
34 * New restartable interface to Maurer testing.
36 * Revision 1.1 2000/06/17 11:29:49 mdw
37 * Maurer's universal statistical test.
41 #ifndef CATACOMB_MAURER_H
42 #define CATACOMB_MAURER_H
48 /*----- Header files ------------------------------------------------------*/
50 #include <mLib/bits.h>
52 /*----- Data structures ---------------------------------------------------*/
54 typedef struct maurer_ctx
{
55 unsigned l
; /* Chunk size, in bits */
56 uint32 a
; /* Bitscanner accumulator */
57 unsigned b
; /* Number of bits in accumulator */
58 unsigned long n
; /* Number of chunks read so far */
59 double x
; /* Statistic value */
60 unsigned long *t
; /* Offset table */
63 /*----- Functions provided ------------------------------------------------*/
65 /* --- @maurer_init@ --- *
67 * Arguments: @maurer_ctx *m@ = pointer to a context to initialize
68 * @unsigned l@ = number of bits to take at a time
70 * Returns: Minimum recommended amount of data to test.
72 * Use: Initializes a Maurer testing context. Note that @l@ values
73 * larger than 16 are not supported, and values less than 6 can
74 * give bizarre results.
77 extern unsigned long maurer_init(maurer_ctx */
*m*/
, unsigned /*l*/);
79 /* --- @maurer_test@ --- *
81 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
82 * @const void *buf@ = pointer to a buffer of data
83 * @size_t sz@ = size of the buffer
87 * Use: Scans a buffer of data and updates the testing context.
90 extern void maurer_test(maurer_ctx */
*m*/
,
91 const void */
*buf*/
, size_t /*sz*/);
93 /* --- @maurer_done@ --- *
95 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
97 * Returns: The statistic %$Z_u = (X_u - \mu)/\sigma$%, which should be
98 * normally distributed with a mean of 0 and variance of 1.
100 * Use: Returns the result of Maurer's universal statistical test.
101 * Also frees the memory allocated during initialization.
103 * If insufficient data was received, the value @HUGE_VAL@ is
107 extern double maurer_done(maurer_ctx */
*m*/
);
109 /* --- @maurer@ --- *
111 * Arguments: @const octet *p@ = pointer to a buffer of data
112 * @size_t sz@ = size of the buffer
113 * @unsigned l@ = number of bits to take at a time
115 * Returns: The statistic %$Z_u$%.
117 * Use: Simple interface to Maurer's universal statistical test. For
118 * large %$l$% you should use the more complicated restartable
122 extern double maurer(const octet */
*p*/
, size_t /*sz*/, unsigned /*l*/);
124 /*----- That's all, folks -------------------------------------------------*/