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