3 * $Id: maurer.h,v 1.3 2004/04/08 01:36:15 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 #ifndef CATACOMB_MAURER_H
31 #define CATACOMB_MAURER_H
37 /*----- Header files ------------------------------------------------------*/
39 #include <mLib/bits.h>
41 /*----- Data structures ---------------------------------------------------*/
43 typedef struct maurer_ctx {
44 unsigned l; /* Chunk size, in bits */
45 uint32 a; /* Bitscanner accumulator */
46 unsigned b; /* Number of bits in accumulator */
47 unsigned long n; /* Number of chunks read so far */
48 double x; /* Statistic value */
49 unsigned long *t; /* Offset table */
52 /*----- Functions provided ------------------------------------------------*/
54 /* --- @maurer_init@ --- *
56 * Arguments: @maurer_ctx *m@ = pointer to a context to initialize
57 * @unsigned l@ = number of bits to take at a time
59 * Returns: Minimum recommended amount of data to test.
61 * Use: Initializes a Maurer testing context. Note that @l@ values
62 * larger than 16 are not supported, and values less than 6 can
63 * give bizarre results.
66 extern unsigned long maurer_init(maurer_ctx */*m*/, unsigned /*l*/);
68 /* --- @maurer_test@ --- *
70 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
71 * @const void *buf@ = pointer to a buffer of data
72 * @size_t sz@ = size of the buffer
76 * Use: Scans a buffer of data and updates the testing context.
79 extern void maurer_test(maurer_ctx */*m*/,
80 const void */*buf*/, size_t /*sz*/);
82 /* --- @maurer_done@ --- *
84 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
86 * Returns: The statistic %$Z_u = (X_u - \mu)/\sigma$%, which should be
87 * normally distributed with a mean of 0 and variance of 1.
89 * Use: Returns the result of Maurer's universal statistical test.
90 * Also frees the memory allocated during initialization.
92 * If insufficient data was received, the value @HUGE_VAL@ is
96 extern double maurer_done(maurer_ctx */*m*/);
100 * Arguments: @const octet *p@ = pointer to a buffer of data
101 * @size_t sz@ = size of the buffer
102 * @unsigned l@ = number of bits to take at a time
104 * Returns: The statistic %$Z_u$%.
106 * Use: Simple interface to Maurer's universal statistical test. For
107 * large %$l$% you should use the more complicated restartable
111 extern double maurer(const octet */*p*/, size_t /*sz*/, unsigned /*l*/);
113 /*----- That's all, folks -------------------------------------------------*/