key-flags.c, key-pack.c, key-pass.c: Don't use the `key.h' machinery.
[u/mdw/catacomb] / maurer.h
CommitLineData
39be2708 1/* -*-c-*-
2 *
b817bfc6 3 * $Id: maurer.h,v 1.3 2004/04/08 01:36:15 mdw Exp $
39be2708 4 *
5 * Maurer's universal statistical test
6 *
7 * (c) 2000 Straylight/Edgeware
8 */
9
45c0fd36 10/*----- Licensing notice --------------------------------------------------*
39be2708 11 *
12 * This file is part of Catacomb.
13 *
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.
45c0fd36 18 *
39be2708 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.
45c0fd36 23 *
39be2708 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,
27 * MA 02111-1307, USA.
28 */
29
39be2708 30#ifndef CATACOMB_MAURER_H
31#define CATACOMB_MAURER_H
32
33#ifdef __cplusplus
34 extern "C" {
35#endif
36
37/*----- Header files ------------------------------------------------------*/
38
39#include <mLib/bits.h>
40
e3dc2d22 41/*----- Data structures ---------------------------------------------------*/
42
43typedef 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 */
50} maurer_ctx;
51
39be2708 52/*----- Functions provided ------------------------------------------------*/
53
e3dc2d22 54/* --- @maurer_init@ --- *
55 *
56 * Arguments: @maurer_ctx *m@ = pointer to a context to initialize
57 * @unsigned l@ = number of bits to take at a time
58 *
59 * Returns: Minimum recommended amount of data to test.
60 *
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.
64 */
65
66extern unsigned long maurer_init(maurer_ctx */*m*/, unsigned /*l*/);
67
68/* --- @maurer_test@ --- *
69 *
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
73 *
74 * Returns: ---
75 *
76 * Use: Scans a buffer of data and updates the testing context.
77 */
78
79extern void maurer_test(maurer_ctx */*m*/,
80 const void */*buf*/, size_t /*sz*/);
81
82/* --- @maurer_done@ --- *
83 *
84 * Arguments: @maurer_ctx *m@ = pointer to a Maurer testing context
85 *
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.
88 *
89 * Use: Returns the result of Maurer's universal statistical test.
90 * Also frees the memory allocated during initialization.
91 *
92 * If insufficient data was received, the value @HUGE_VAL@ is
93 * returned.
94 */
95
96extern double maurer_done(maurer_ctx */*m*/);
97
39be2708 98/* --- @maurer@ --- *
99 *
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
103 *
e3dc2d22 104 * Returns: The statistic %$Z_u$%.
39be2708 105 *
e3dc2d22 106 * Use: Simple interface to Maurer's universal statistical test. For
107 * large %$l$% you should use the more complicated restartable
108 * interface.
39be2708 109 */
110
111extern double maurer(const octet */*p*/, size_t /*sz*/, unsigned /*l*/);
112
113/*----- That's all, folks -------------------------------------------------*/
114
115#ifdef __cplusplus
116 }
117#endif
118
119#endif