3 * $Id: dsarand.h,v 1.2 2000/06/17 10:54:14 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 2000/06/17 10:54:14 mdw
36 * Revision 1.1 1999/12/22 15:53:12 mdw
37 * Random number generator for finding DSA parameters.
41 #ifndef CATACOMB_DSARAND_H
42 #define CATACOMB_DSARAND_H
48 /*----- Header files ------------------------------------------------------*/
50 #include <mLib/bits.h>
52 #ifndef CATACOMB_GRAND_H
56 #ifndef CATACOMB_SHA_H
60 /*----- Data structures ---------------------------------------------------*/
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 */
68 /*----- Functions provided ------------------------------------------------*/
70 /* --- @dsarand_init@ --- *
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_init(dsarand */
*d*/
, const void */
*p*/
, size_t /*sz*/);
83 /* --- @dsarand_reseed@ --- *
85 * Arguments: @dsarand *d@ = pointer to context
86 * @const void *p@ = pointer to seed buffer
87 * @size_t sz@ = size of the buffer
91 * Use: Initializes a DSA random number generator.
94 extern void dsarand_reseed(dsarand */
*d*/
, const void */
*p*/
, size_t /*sz*/);
96 /* --- @dsarand_destroy@ --- *
98 * Arguments: @dsarand *d@ = pointer to context
102 * Use: Disposes of a DSA random number generation context.
105 extern void dsarand_destroy(dsarand */
*d*/
);
107 /* --- @dsarand_fill@ --- *
109 * Arguments: @dsarand *d@ = pointer to context
110 * @void *p@ = pointer to output buffer
111 * @size_t sz@ = size of output buffer
115 * Use: Fills an output buffer with pseudorandom data.
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
122 * %$P_n = \sum_{0 \le i < z} 2^{160i} SHA(p + nz + i)$%
123 * %${} \bmod 2^{8b}$%
125 * and the actual result in the output buffer is the XOR of all
126 * of the output passes.
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.
134 extern void dsarand_fill(dsarand */
*d*/
, void */
*p*/
, size_t /*sz*/);
136 /*----- Generic pseudorandom-number generator interface -------------------*/
138 /* --- Miscellaneous operations --- */
141 DSARAND_PASSES
= GRAND_SPECIFIC
144 /* --- @dsarand_create@ --- *
146 * Arguments: @const void *p@ = pointer to seed buffer
147 * @size_t sz@ = size of seed buffer
149 * Returns: Pointer to a generic generator.
151 * Use: Constructs a generic generator interface over a Catacomb
152 * entropy pool generator.
155 extern grand
*dsarand_create(const void */
*p*/
, size_t /*sz*/);
157 /*----- That's all, folks -------------------------------------------------*/