/* -*-c-*-
*
- * $Id: dh.h,v 1.2 1999/12/10 23:29:48 mdw Exp $
+ * $Id: dh.h,v 1.4 2000/06/17 10:52:47 mdw Exp $
+ *
+ * Diffie-Hellman and related public-key systems
*
- * [Diffie-Hellman key negotiation *
* (c) 1999 Straylight/Edgeware
*/
/*----- Revision history --------------------------------------------------*
*
* $Log: dh.h,v $
- * Revision 1.2 1999/12/10 23:29:48 mdw
- * Change header file guard names.
+ * Revision 1.4 2000/06/17 10:52:47 mdw
+ * Minor changes for key fetching.
*
- * Revision 1.1 1999/11/20 22:24:44 mdw
- * Add Diffie-Hellman support.
+ * Revision 1.3 2000/02/12 18:21:02 mdw
+ * Overhaul of key management (again).
*
*/
/*----- Header files ------------------------------------------------------*/
-#ifndef CATACOMB_MP_H
-# include "mp.h"
+#ifndef CATACOMB_GRAND_H
+# include "grand.h"
+#endif
+
+#ifndef CATACOMB_KEY_H
+# include "key.h"
+#endif
+
+#ifndef CATACOMB_PGEN_H
+# include "pgen.h"
#endif
-/*----- Event codes -------------------------------------------------------*/
+/*----- Data structures ---------------------------------------------------*/
+
+typedef struct dh_param {
+ mp *p, *q;
+ mp *g;
+} dh_param;
+
+typedef struct dh_pub {
+ dh_param dp;
+ mp *y;
+} dh_pub;
+
+typedef struct dh_priv {
+ dh_param dp;
+ mp *x;
+ mp *y;
+} dh_priv;
+
+/*----- Key fetching ------------------------------------------------------*/
+
+extern const key_fetchdef dh_paramfetch[];
+#define DH_PARAMFETCHSZ 5
-enum {
- DHEV_OK,
+extern const key_fetchdef dh_pubfetch[];
+#define DH_PUBFETCHSZ 6
- DHEV_FAIL,
- DHEV_PASS
-};
+extern const key_fetchdef dh_privfetch[];
+#define DH_PRIVFETCHSZ 9
/*----- Functions provided ------------------------------------------------*/
-/* --- @dh_prime@ --- *
+/* --- @dh_gen@ --- *
*
- * Arguments: @mp *s@ = start point for search (must be odd)
- * @size_t n@ = number of concerted attempts to make, or zero
- * @void (*proc)(int ev, void *p)@ = event handler
- * @void *p@ = argument for event handler
+ * Arguments: @dh_param *dp@ = pointer to output parameter block
+ * @unsigned ql@ = length of %$q$% in bits, or zero
+ * @unsigned pl@ = length of %$p$% in bits
+ * @unsigned steps@ = number of steps to go
+ * @grand *r@ = random number source
+ * @pgen_proc *event@ = event handler function
+ * @void *ectx@ = argument for the event handler
*
- * Returns: A prime number %$p$% where %$p = 2q + 1$% for prime %$q$%.
+ * Returns: @PGEN_DONE@ if it worked, @PGEN_ABORT@ if it didn't.
*
- * Use: Finds a safe prime by sequential search from a given starting
- * point. If it fails, a null pointer is returned.
+ * Use: Generates Diffie-Hellman parameters.
*
- * The event handler is informed of the progress of the search.
- * It may abort the search at any time by returning a nonzero
- * value.
+ * The parameters are a prime %$q$%, relatively small, and a
+ * large prime %$p = kq + 1$% for some %$k$%, together with a
+ * generator %$g$% of the cyclic subgroup of order %$q$%. These
+ * are actually the same as the DSA parameter set, but the
+ * generation algorithm is different. Also, if @ql@ is zero,
+ * this algorithm forces %$k = 2$%, and chooses %$g = 4$%. Make
+ * sure you have something interesting to do if you choose this
+ * option.
*/
-extern mp *dh_prime(mp */*s*/, size_t /*n*/,
- int (*proc)(int /*ev*/, void */*p*/), void */*p*/);
+extern int dh_gen(dh_param */*dp*/, unsigned /*ql*/, unsigned /*pl*/,
+ unsigned /*steps*/, grand */*r*/, pgen_proc */*event*/,
+ void */*ectx*/);
/*----- That's all, folks -------------------------------------------------*/