3 * Random number generator for DSA
5 * (c) 1999 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_DSARAND_H
29 #define CATACOMB_DSARAND_H
35 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/bits.h>
39 #ifndef CATACOMB_GRAND_H
43 #ifndef CATACOMB_SHA_H
47 /*----- Data structures ---------------------------------------------------*/
49 typedef struct dsarand {
50 octet *p; /* Pointer to seed (modified) */
51 size_t sz; /* Size of the seed buffer */
52 unsigned passes; /* Number of passes to make */
55 /*----- Functions provided ------------------------------------------------*/
57 /* --- @dsarand_init@ --- *
59 * Arguments: @dsarand *d@ = pointer to context
60 * @const void *p@ = pointer to seed buffer
61 * @size_t sz@ = size of the buffer
65 * Use: Initializes a DSA random number generator.
68 extern void dsarand_init(dsarand */*d*/, const void */*p*/, size_t /*sz*/);
70 /* --- @dsarand_reseed@ --- *
72 * Arguments: @dsarand *d@ = pointer to context
73 * @const void *p@ = pointer to seed buffer
74 * @size_t sz@ = size of the buffer
78 * Use: Initializes a DSA random number generator.
81 extern void dsarand_reseed(dsarand */*d*/, const void */*p*/, size_t /*sz*/);
83 /* --- @dsarand_destroy@ --- *
85 * Arguments: @dsarand *d@ = pointer to context
89 * Use: Disposes of a DSA random number generation context.
92 extern void dsarand_destroy(dsarand */*d*/);
94 /* --- @dsarand_fill@ --- *
96 * Arguments: @dsarand *d@ = pointer to context
97 * @void *p@ = pointer to output buffer
98 * @size_t sz@ = size of output buffer
102 * Use: Fills an output buffer with pseudorandom data.
104 * Let %$p$% be the numerical value of the input buffer, and let
105 * %$b$% be the number of bytes required. Let
106 * %$z = \lceil b / 20 \rceil$% be the number of SHA outputs
107 * required. Then the output of pass %$n$% is
109 * %$P_n = \sum_{0 \le i < z} 2^{160i} SHA(p + nz + i)$%
110 * %${} \bmod 2^{8b}$%
112 * and the actual result in the output buffer is the XOR of all
113 * of the output passes.
115 * The DSA procedure for choosing @q@ involves two passes with
116 * %$z = 1$%; the procedure for choosing @p@ involves one pass
117 * with larger %$z$%. This generalization of the DSA generation
118 * procedure is my own invention but it seems relatively sound.
121 extern void dsarand_fill(dsarand */*d*/, void */*p*/, size_t /*sz*/);
123 /*----- Generic pseudorandom-number generator interface -------------------*/
125 /* --- Miscellaneous operations --- */
128 DSARAND_PASSES = GRAND_SPECIFIC('D'), /* @unsigned n@ */
129 DSARAND_SEEDSZ, /* No args */
130 DSARAND_GETSEED /* @void *buf@ */
133 /* --- @dsarand_create@ --- *
135 * Arguments: @const void *p@ = pointer to seed buffer
136 * @size_t sz@ = size of seed buffer
138 * Returns: Pointer to a generic generator.
140 * Use: Constructs a generic generator interface to a DSA generator.
143 extern grand *dsarand_create(const void */*p*/, size_t /*sz*/);
145 /*----- That's all, folks -------------------------------------------------*/