Pollard's rho algorithm for computing discrete logs.
[u/mdw/catacomb] / dsarand.h
1 /* -*-c-*-
2 *
3 * $Id: dsarand.h,v 1.2 2000/06/17 10:54:14 mdw Exp $
4 *
5 * Random number generator for DSA
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
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.
18 *
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.
23 *
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
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: dsarand.h,v $
33 * Revision 1.2 2000/06/17 10:54:14 mdw
34 * Typesetting fixes.
35 *
36 * Revision 1.1 1999/12/22 15:53:12 mdw
37 * Random number generator for finding DSA parameters.
38 *
39 */
40
41 #ifndef CATACOMB_DSARAND_H
42 #define CATACOMB_DSARAND_H
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /*----- Header files ------------------------------------------------------*/
49
50 #include <mLib/bits.h>
51
52 #ifndef CATACOMB_GRAND_H
53 # include "grand.h"
54 #endif
55
56 #ifndef CATACOMB_SHA_H
57 # include "sha.h"
58 #endif
59
60 /*----- Data structures ---------------------------------------------------*/
61
62 typedef struct dsarand {
63 octet *p; /* Pointer to seed (modified) */
64 size_t sz; /* Size of the seed buffer */
65 unsigned passes; /* Number of passes to make */
66 } dsarand;
67
68 /*----- Functions provided ------------------------------------------------*/
69
70 /* --- @dsarand_init@ --- *
71 *
72 * Arguments: @dsarand *d@ = pointer to context
73 * @const void *p@ = pointer to seed buffer
74 * @size_t sz@ = size of the buffer
75 *
76 * Returns: ---
77 *
78 * Use: Initializes a DSA random number generator.
79 */
80
81 extern void dsarand_init(dsarand */*d*/, const void */*p*/, size_t /*sz*/);
82
83 /* --- @dsarand_reseed@ --- *
84 *
85 * Arguments: @dsarand *d@ = pointer to context
86 * @const void *p@ = pointer to seed buffer
87 * @size_t sz@ = size of the buffer
88 *
89 * Returns: ---
90 *
91 * Use: Initializes a DSA random number generator.
92 */
93
94 extern void dsarand_reseed(dsarand */*d*/, const void */*p*/, size_t /*sz*/);
95
96 /* --- @dsarand_destroy@ --- *
97 *
98 * Arguments: @dsarand *d@ = pointer to context
99 *
100 * Returns: ---
101 *
102 * Use: Disposes of a DSA random number generation context.
103 */
104
105 extern void dsarand_destroy(dsarand */*d*/);
106
107 /* --- @dsarand_fill@ --- *
108 *
109 * Arguments: @dsarand *d@ = pointer to context
110 * @void *p@ = pointer to output buffer
111 * @size_t sz@ = size of output buffer
112 *
113 * Returns: ---
114 *
115 * Use: Fills an output buffer with pseudorandom data.
116 *
117 * Let %$p$% be the numerical value of the input buffer, and let
118 * %$b$% be the number of bytes required. Let
119 * %$z = \lceil b / 20 \rceil$% be the number of SHA outputs
120 * required. Then the output of pass %$n$% is
121 *
122 * %$P_n = \sum_{0 \le i < z} 2^{160i} SHA(p + nz + i)$%
123 * %${} \bmod 2^{8b}$%
124 *
125 * and the actual result in the output buffer is the XOR of all
126 * of the output passes.
127 *
128 * The DSA procedure for choosing @q@ involves two passes with
129 * %$z = 1$%; the procedure for choosing @p@ involves one pass
130 * with larger %$z$%. This generalization of the DSA generation
131 * procedure is my own invention but it seems relatively sound.
132 */
133
134 extern void dsarand_fill(dsarand */*d*/, void */*p*/, size_t /*sz*/);
135
136 /*----- Generic pseudorandom-number generator interface -------------------*/
137
138 /* --- Miscellaneous operations --- */
139
140 enum {
141 DSARAND_PASSES = GRAND_SPECIFIC
142 };
143
144 /* --- @dsarand_create@ --- *
145 *
146 * Arguments: @const void *p@ = pointer to seed buffer
147 * @size_t sz@ = size of seed buffer
148 *
149 * Returns: Pointer to a generic generator.
150 *
151 * Use: Constructs a generic generator interface over a Catacomb
152 * entropy pool generator.
153 */
154
155 extern grand *dsarand_create(const void */*p*/, size_t /*sz*/);
156
157 /*----- That's all, folks -------------------------------------------------*/
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif