3 * $Id: dsarand.h,v 1.3 2001/02/03 16:08:56 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.3 2001/02/03 16:08:56 mdw
34 * Give generic random objects separate namespaces for their supported misc
35 * ops. Add operations for reading the current seed value.
37 * Revision 1.2 2000/06/17 10:54:14 mdw
40 * Revision 1.1 1999/12/22 15:53:12 mdw
41 * Random number generator for finding DSA parameters.
45 #ifndef CATACOMB_DSARAND_H
46 #define CATACOMB_DSARAND_H
52 /*----- Header files ------------------------------------------------------*/
54 #include <mLib/bits.h>
56 #ifndef CATACOMB_GRAND_H
60 #ifndef CATACOMB_SHA_H
64 /*----- Data structures ---------------------------------------------------*/
66 typedef struct dsarand
{
67 octet
*p
; /* Pointer to seed (modified) */
68 size_t sz
; /* Size of the seed buffer */
69 unsigned passes
; /* Number of passes to make */
72 /*----- Functions provided ------------------------------------------------*/
74 /* --- @dsarand_init@ --- *
76 * Arguments: @dsarand *d@ = pointer to context
77 * @const void *p@ = pointer to seed buffer
78 * @size_t sz@ = size of the buffer
82 * Use: Initializes a DSA random number generator.
85 extern void dsarand_init(dsarand */
*d*/
, const void */
*p*/
, size_t /*sz*/);
87 /* --- @dsarand_reseed@ --- *
89 * Arguments: @dsarand *d@ = pointer to context
90 * @const void *p@ = pointer to seed buffer
91 * @size_t sz@ = size of the buffer
95 * Use: Initializes a DSA random number generator.
98 extern void dsarand_reseed(dsarand */
*d*/
, const void */
*p*/
, size_t /*sz*/);
100 /* --- @dsarand_destroy@ --- *
102 * Arguments: @dsarand *d@ = pointer to context
106 * Use: Disposes of a DSA random number generation context.
109 extern void dsarand_destroy(dsarand */
*d*/
);
111 /* --- @dsarand_fill@ --- *
113 * Arguments: @dsarand *d@ = pointer to context
114 * @void *p@ = pointer to output buffer
115 * @size_t sz@ = size of output buffer
119 * Use: Fills an output buffer with pseudorandom data.
121 * Let %$p$% be the numerical value of the input buffer, and let
122 * %$b$% be the number of bytes required. Let
123 * %$z = \lceil b / 20 \rceil$% be the number of SHA outputs
124 * required. Then the output of pass %$n$% is
126 * %$P_n = \sum_{0 \le i < z} 2^{160i} SHA(p + nz + i)$%
127 * %${} \bmod 2^{8b}$%
129 * and the actual result in the output buffer is the XOR of all
130 * of the output passes.
132 * The DSA procedure for choosing @q@ involves two passes with
133 * %$z = 1$%; the procedure for choosing @p@ involves one pass
134 * with larger %$z$%. This generalization of the DSA generation
135 * procedure is my own invention but it seems relatively sound.
138 extern void dsarand_fill(dsarand */
*d*/
, void */
*p*/
, size_t /*sz*/);
140 /*----- Generic pseudorandom-number generator interface -------------------*/
142 /* --- Miscellaneous operations --- */
145 DSARAND_PASSES
= GRAND_SPECIFIC('D'), /* @unsigned n@ */
146 DSARAND_SEEDSZ
, /* No args */
147 DSARAND_GETSEED
/* @void *buf@ */
150 /* --- @dsarand_create@ --- *
152 * Arguments: @const void *p@ = pointer to seed buffer
153 * @size_t sz@ = size of seed buffer
155 * Returns: Pointer to a generic generator.
157 * Use: Constructs a generic generator interface to a DSA generator.
160 extern grand
*dsarand_create(const void */
*p*/
, size_t /*sz*/);
162 /*----- That's all, folks -------------------------------------------------*/