3 * $Id: dsarand.h,v 1.1 1999/12/22 15:53:12 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.1 1999/12/22 15:53:12 mdw
34 * Random number generator for finding DSA parameters.
38 #ifndef CATACOMB_DSARAND_H
39 #define CATACOMB_DSARAND_H
45 /*----- Header files ------------------------------------------------------*/
47 #include <mLib/bits.h>
49 #ifndef CATACOMB_GRAND_H
53 #ifndef CATACOMB_SHA_H
57 /*----- Data structures ---------------------------------------------------*/
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 */
65 /*----- Functions provided ------------------------------------------------*/
67 /* --- @dsarand_init@ --- *
69 * Arguments: @dsarand *d@ = pointer to context
70 * @const void *p@ = pointer to seed buffer
71 * @size_t sz@ = size of the buffer
75 * Use: Initializes a DSA random number generator.
78 extern void dsarand_init(dsarand */
*d*/
, const void */
*p*/
, size_t /*sz*/);
80 /* --- @dsarand_reseed@ --- *
82 * Arguments: @dsarand *d@ = pointer to context
83 * @const void *p@ = pointer to seed buffer
84 * @size_t sz@ = size of the buffer
88 * Use: Initializes a DSA random number generator.
91 extern void dsarand_reseed(dsarand */
*d*/
, const void */
*p*/
, size_t /*sz*/);
93 /* --- @dsarand_destroy@ --- *
95 * Arguments: @dsarand *d@ = pointer to context
99 * Use: Disposes of a DSA random number generation context.
102 extern void dsarand_destroy(dsarand */
*d*/
);
104 /* --- @dsarand_fill@ --- *
106 * Arguments: @dsarand *d@ = pointer to context
107 * @void *p@ = pointer to output buffer
108 * @size_t sz@ = size of output buffer
112 * Use: Fills an output buffer with pseudorandom data.
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
119 * %$P_n = \sum_{0 \le i < z} 2^{160i} SHA(p + nz + i)$%
120 * %${} \bmod 2^{8b}$%
122 * and the actual result in the output buffer is the XOR of all
123 * of the output passes.
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.
131 extern void dsarand_fill(dsarand */
*d*/
, void */
*p*/
, size_t /*sz*/);
133 /*----- Generic pseudorandom-number generator interface -------------------*/
135 /* --- Miscellaneous operations --- */
138 DSARAND_PASSES
= GRAND_SPECIFIC
141 /* --- @dsarand_create@ --- *
143 * Arguments: @const void *p@ = pointer to seed buffer
144 * @size_t sz@ = size of seed buffer
146 * Returns: Pointer to a generic generator.
148 * Use: Constructs a generic generator interface over a Catacomb
149 * entropy pool generator.
152 extern grand
*dsarand_create(const void */
*p*/
, size_t /*sz*/);
154 /*----- That's all, folks -------------------------------------------------*/