Supply commentry for the Diffie-Hellman parameters. Add Lim-Lee
[u/mdw/catacomb] / dh.h
1 /* -*-c-*-
2 *
3 * $Id: dh.h,v 1.6 2000/07/29 10:01:16 mdw Exp $
4 *
5 * Diffie-Hellman and related public-key systems
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: dh.h,v $
33 * Revision 1.6 2000/07/29 10:01:16 mdw
34 * Supply commentry for the Diffie-Hellman parameters. Add Lim-Lee
35 * parameter generation.
36 *
37 * Revision 1.5 2000/07/01 11:20:51 mdw
38 * New functions for freeing public and private keys.
39 *
40 * Revision 1.4 2000/06/17 10:52:47 mdw
41 * Minor changes for key fetching.
42 *
43 * Revision 1.3 2000/02/12 18:21:02 mdw
44 * Overhaul of key management (again).
45 *
46 */
47
48 #ifndef CATACOMB_DH_H
49 #define CATACOMB_DH_H
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 /*----- Header files ------------------------------------------------------*/
56
57 #ifndef CATACOMB_GRAND_H
58 # include "grand.h"
59 #endif
60
61 #ifndef CATACOMB_KEY_H
62 # include "key.h"
63 #endif
64
65 #ifndef CATACOMB_PGEN_H
66 # include "pgen.h"
67 #endif
68
69 /*----- Data structures ---------------------------------------------------*/
70
71 typedef struct dh_param { /* Prime numbers %$p$% and %$q$% */
72 mp *p, *q; /* Generates order-%$q$% subgroup */
73 mp *g;
74 } dh_param;
75
76 typedef struct dh_pub { /* Shared parameters */
77 dh_param dp; /* Public key */
78 mp *y;
79 } dh_pub;
80
81 typedef struct dh_priv { /* Shared parameters */
82 dh_param dp; /* Private key */
83 mp *x; /* %$y \equiv g^x \pmod{p}$% */
84 mp *y;
85 } dh_priv;
86
87 /*----- Key fetching ------------------------------------------------------*/
88
89 extern const key_fetchdef dh_paramfetch[];
90 #define DH_PARAMFETCHSZ 5
91
92 extern const key_fetchdef dh_pubfetch[];
93 #define DH_PUBFETCHSZ 6
94
95 extern const key_fetchdef dh_privfetch[];
96 #define DH_PRIVFETCHSZ 9
97
98 /* --- @dh_paramfree@, @dh_pubfree@, @dh_privfree@ --- *
99 *
100 * Arguments: @dh_param *dp@, @dh_pub *dp@, @dh_priv *dp@ = pointer to
101 * key block to free
102 *
103 * Returns: ---
104 *
105 * Use: Frees a Diffie-Hellman key block.
106 */
107
108 extern void dh_paramfree(dh_param */*dp*/);
109 extern void dh_pubfree(dh_pub */*dp*/);
110 extern void dh_privfree(dh_priv */*dp*/);
111
112 /*----- Functions provided ------------------------------------------------*/
113
114 /* --- @dh_gen@ --- *
115 *
116 * Arguments: @dh_param *dp@ = pointer to output parameter block
117 * @unsigned ql@ = length of %$q$% in bits, or zero
118 * @unsigned pl@ = length of %$p$% in bits
119 * @unsigned steps@ = number of steps to go
120 * @grand *r@ = random number source
121 * @pgen_proc *event@ = event handler function
122 * @void *ectx@ = argument for the event handler
123 *
124 * Returns: @PGEN_DONE@ if it worked, @PGEN_ABORT@ if it didn't.
125 *
126 * Use: Generates Diffie-Hellman parameters.
127 *
128 * The parameters are a prime %$q$%, relatively small, and a
129 * large prime %$p = kq + 1$% for some %$k$%, together with a
130 * generator %$g$% of the cyclic subgroup of order %$q$%. These
131 * are actually the same as the DSA parameter set, but the
132 * generation algorithm is different. Also, if @ql@ is zero,
133 * this algorithm forces %$k = 2$%, and chooses %$g = 4$%. Make
134 * sure you have something interesting to do if you choose this
135 * option.
136 */
137
138 extern int dh_gen(dh_param */*dp*/, unsigned /*ql*/, unsigned /*pl*/,
139 unsigned /*steps*/, grand */*r*/, pgen_proc */*event*/,
140 void */*ectx*/);
141
142 /* --- @dh_limlee@ --- *
143 *
144 * Arguments: @dh_param *dp@ = pointer to output parameter block
145 * @unsigned ql@ = length of smallest factor of %$(p - 1)/2$%
146 * @unsigned pl@ = length of %$p$% in bits
147 * @unsigned flags@ = other generation flags
148 * @unsigned steps@ = number of steps to go
149 * @grand *r@ = random number source
150 * @pgen_proc *oev@ = outer event handler function
151 * @void *oec@ = argument for the outer event handler
152 * @pgen_proc *iev@ = inner event handler function
153 * @void *iec@ = argument for the inner event handler
154 * @size_t *nf@, @mp ***f@ = output array for factors
155 *
156 * Returns: @PGEN_DONE@ if it worked, @PGEN_ABORT@ if it didn't.
157 *
158 * Use: Generates Diffie-Hellman parameters based on a Lim-Lee prime.
159 *
160 * The modulus is a large prime %$p = 2 \prod q_i + 1$%, @pl@
161 * bits long, where the %$q_i$% are smaller primes each at least
162 * @ql@ bits long. It is safe to set @nf@ and @f@ to zero if
163 * you're not interested in the factor values.
164 *
165 * The returned %$g$% generates a subgroup of order %$q_0$% (the
166 * first factor, returned as @f[0]@), if the flag @DH_SUBGROUP@
167 * is set on entry; otherwise %$g$% will have order
168 * %$(p - 1)/2$%.
169 */
170
171 #define DH_SUBGROUP 1u
172
173 extern int dh_limlee(dh_param */*dp*/, unsigned /*ql*/, unsigned /*pl*/,
174 unsigned /*flags*/, unsigned /*steps*/, grand */*r*/,
175 pgen_proc */*oev*/, void */*oec*/, pgen_proc */*iev*/,
176 void */*iec*/, size_t */*nf*/, mp ***/*f*/);
177
178 /*----- That's all, folks -------------------------------------------------*/
179
180 #ifdef __cplusplus
181 }
182 #endif
183
184 #endif