3 * Maurer's universal statistical test
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
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.
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.
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,
28 #ifndef CATACOMB_MAURER_H
29 #define CATACOMB_MAURER_H
35 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/bits.h>
39 /*----- Data structures ---------------------------------------------------*/
41 typedef 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 */
50 /*----- Functions provided ------------------------------------------------*/
52 /* --- @maurer_init@ --- *
54 * Arguments: @maurer_ctx *m@ = pointer to a context to initialize
55 * @unsigned l@ = number of bits to take at a time
57 * Returns: Minimum recommended amount of data to test.
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.
64 extern unsigned long maurer_init(maurer_ctx */*m*/, unsigned /*l*/);
66 /* --- @maurer_test@ --- *
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
74 * Use: Scans a buffer of data and updates the testing context.
77 extern void maurer_test(maurer_ctx */*m*/,
78 const void */*buf*/, size_t /*sz*/);
80 /* --- @maurer_done@ --- *
82 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
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.
87 * Use: Returns the result of Maurer's universal statistical test.
88 * Also frees the memory allocated during initialization.
90 * If insufficient data was received, the value @HUGE_VAL@ is
94 extern double maurer_done(maurer_ctx */*m*/);
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
102 * Returns: The statistic %$Z_u$%.
104 * Use: Simple interface to Maurer's universal statistical test. For
105 * large %$l$% you should use the more complicated restartable
109 extern double maurer(const octet */*p*/, size_t /*sz*/, unsigned /*l*/);
111 /*----- That's all, folks -------------------------------------------------*/