3 * $Id: dsarand.h,v 1.4 2004/04/08 01:36:15 mdw Exp $
5 * Random number generator for DSA
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 #ifndef CATACOMB_DSARAND_H
31 #define CATACOMB_DSARAND_H
37 /*----- Header files ------------------------------------------------------*/
39 #include <mLib/bits.h>
41 #ifndef CATACOMB_GRAND_H
45 #ifndef CATACOMB_SHA_H
49 /*----- Data structures ---------------------------------------------------*/
51 typedef struct dsarand {
52 octet *p; /* Pointer to seed (modified) */
53 size_t sz; /* Size of the seed buffer */
54 unsigned passes; /* Number of passes to make */
57 /*----- Functions provided ------------------------------------------------*/
59 /* --- @dsarand_init@ --- *
61 * Arguments: @dsarand *d@ = pointer to context
62 * @const void *p@ = pointer to seed buffer
63 * @size_t sz@ = size of the buffer
67 * Use: Initializes a DSA random number generator.
70 extern void dsarand_init(dsarand */*d*/, const void */*p*/, size_t /*sz*/);
72 /* --- @dsarand_reseed@ --- *
74 * Arguments: @dsarand *d@ = pointer to context
75 * @const void *p@ = pointer to seed buffer
76 * @size_t sz@ = size of the buffer
80 * Use: Initializes a DSA random number generator.
83 extern void dsarand_reseed(dsarand */*d*/, const void */*p*/, size_t /*sz*/);
85 /* --- @dsarand_destroy@ --- *
87 * Arguments: @dsarand *d@ = pointer to context
91 * Use: Disposes of a DSA random number generation context.
94 extern void dsarand_destroy(dsarand */*d*/);
96 /* --- @dsarand_fill@ --- *
98 * Arguments: @dsarand *d@ = pointer to context
99 * @void *p@ = pointer to output buffer
100 * @size_t sz@ = size of output buffer
104 * Use: Fills an output buffer with pseudorandom data.
106 * Let %$p$% be the numerical value of the input buffer, and let
107 * %$b$% be the number of bytes required. Let
108 * %$z = \lceil b / 20 \rceil$% be the number of SHA outputs
109 * required. Then the output of pass %$n$% is
111 * %$P_n = \sum_{0 \le i < z} 2^{160i} SHA(p + nz + i)$%
112 * %${} \bmod 2^{8b}$%
114 * and the actual result in the output buffer is the XOR of all
115 * of the output passes.
117 * The DSA procedure for choosing @q@ involves two passes with
118 * %$z = 1$%; the procedure for choosing @p@ involves one pass
119 * with larger %$z$%. This generalization of the DSA generation
120 * procedure is my own invention but it seems relatively sound.
123 extern void dsarand_fill(dsarand */*d*/, void */*p*/, size_t /*sz*/);
125 /*----- Generic pseudorandom-number generator interface -------------------*/
127 /* --- Miscellaneous operations --- */
130 DSARAND_PASSES = GRAND_SPECIFIC('D'), /* @unsigned n@ */
131 DSARAND_SEEDSZ, /* No args */
132 DSARAND_GETSEED /* @void *buf@ */
135 /* --- @dsarand_create@ --- *
137 * Arguments: @const void *p@ = pointer to seed buffer
138 * @size_t sz@ = size of seed buffer
140 * Returns: Pointer to a generic generator.
142 * Use: Constructs a generic generator interface to a DSA generator.
145 extern grand *dsarand_create(const void */*p*/, size_t /*sz*/);
147 /*----- That's all, folks -------------------------------------------------*/