New functions for freeing public and private keys.
[u/mdw/catacomb] / dh.h
1 /* -*-c-*-
2 *
3 * $Id: dh.h,v 1.5 2000/07/01 11:20:51 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.5 2000/07/01 11:20:51 mdw
34 * New functions for freeing public and private keys.
35 *
36 * Revision 1.4 2000/06/17 10:52:47 mdw
37 * Minor changes for key fetching.
38 *
39 * Revision 1.3 2000/02/12 18:21:02 mdw
40 * Overhaul of key management (again).
41 *
42 */
43
44 #ifndef CATACOMB_DH_H
45 #define CATACOMB_DH_H
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 /*----- Header files ------------------------------------------------------*/
52
53 #ifndef CATACOMB_GRAND_H
54 # include "grand.h"
55 #endif
56
57 #ifndef CATACOMB_KEY_H
58 # include "key.h"
59 #endif
60
61 #ifndef CATACOMB_PGEN_H
62 # include "pgen.h"
63 #endif
64
65 /*----- Data structures ---------------------------------------------------*/
66
67 typedef struct dh_param {
68 mp *p, *q;
69 mp *g;
70 } dh_param;
71
72 typedef struct dh_pub {
73 dh_param dp;
74 mp *y;
75 } dh_pub;
76
77 typedef struct dh_priv {
78 dh_param dp;
79 mp *x;
80 mp *y;
81 } dh_priv;
82
83 /*----- Key fetching ------------------------------------------------------*/
84
85 extern const key_fetchdef dh_paramfetch[];
86 #define DH_PARAMFETCHSZ 5
87
88 extern const key_fetchdef dh_pubfetch[];
89 #define DH_PUBFETCHSZ 6
90
91 extern const key_fetchdef dh_privfetch[];
92 #define DH_PRIVFETCHSZ 9
93
94 /* --- @dh_paramfree@, @dh_pubfree@, @dh_privfree@ --- *
95 *
96 * Arguments: @dh_param *dp@, @dh_pub *dp@, @dh_priv *dp@ = pointer to
97 * key block to free
98 *
99 * Returns: ---
100 *
101 * Use: Frees a Diffie-Hellman key block.
102 */
103
104 extern void dh_paramfree(dh_param */*dp*/);
105 extern void dh_pubfree(dh_pub */*dp*/);
106 extern void dh_privfree(dh_priv */*dp*/);
107
108 /*----- Functions provided ------------------------------------------------*/
109
110 /* --- @dh_gen@ --- *
111 *
112 * Arguments: @dh_param *dp@ = pointer to output parameter block
113 * @unsigned ql@ = length of %$q$% in bits, or zero
114 * @unsigned pl@ = length of %$p$% in bits
115 * @unsigned steps@ = number of steps to go
116 * @grand *r@ = random number source
117 * @pgen_proc *event@ = event handler function
118 * @void *ectx@ = argument for the event handler
119 *
120 * Returns: @PGEN_DONE@ if it worked, @PGEN_ABORT@ if it didn't.
121 *
122 * Use: Generates Diffie-Hellman parameters.
123 *
124 * The parameters are a prime %$q$%, relatively small, and a
125 * large prime %$p = kq + 1$% for some %$k$%, together with a
126 * generator %$g$% of the cyclic subgroup of order %$q$%. These
127 * are actually the same as the DSA parameter set, but the
128 * generation algorithm is different. Also, if @ql@ is zero,
129 * this algorithm forces %$k = 2$%, and chooses %$g = 4$%. Make
130 * sure you have something interesting to do if you choose this
131 * option.
132 */
133
134 extern int dh_gen(dh_param */*dp*/, unsigned /*ql*/, unsigned /*pl*/,
135 unsigned /*steps*/, grand */*r*/, pgen_proc */*event*/,
136 void */*ectx*/);
137
138 /*----- That's all, folks -------------------------------------------------*/
139
140 #ifdef __cplusplus
141 }
142 #endif
143
144 #endif