Add an internal-representation no-op function.
[u/mdw/catacomb] / dsa.h
diff --git a/dsa.h b/dsa.h
index 2b4949d..ce7e762 100644 (file)
--- a/dsa.h
+++ b/dsa.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: dsa.h,v 1.6 2000/07/01 11:20:51 mdw Exp $
+ * $Id: dsa.h,v 1.8 2001/02/03 16:08:24 mdw Exp $
  *
  * Digital Signature Algorithm
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: dsa.h,v $
+ * Revision 1.8  2001/02/03 16:08:24  mdw
+ * Add consistency checking for public keys.
+ *
+ * Revision 1.7  2000/07/29 09:59:44  mdw
+ * Share data structures with Diffie-Hellman stuff.
+ *
  * Revision 1.6  2000/07/01 11:20:51  mdw
  * New functions for freeing public and private keys.
  *
 
 /*----- Header files ------------------------------------------------------*/
 
+#ifndef CATACOMB_DH_H
+#  include "dh.h"
+#endif
+
 #ifndef CATACOMB_KEY_H
 #  include "key.h"
 #endif
 
+#ifndef CATACOMB_KEYCHECK_H
+#  include "keycheck.h"
+#endif
+
 #ifndef CATACOMB_MP_H
 #  include "mp.h"
 #endif
 
 /*----- Data structures ---------------------------------------------------*/
 
-/* --- DSA parameter structure --- *
- *
- * These parameters can, and probably should, be shared among a group of
- * users.
- */
+/* --- The parameters and keys are the same as for Diffie-Hellman --- */
 
-typedef struct dsa_param {
-  mp *p, *q;                           /* Prime numbers %$p$% and %$q$% */
-  mp *g;                               /* Generates order-%$q$% subgroup */
-} dsa_param;
+typedef dh_param dsa_param;
+typedef dh_pub dsa_pub;
+typedef dh_priv dsa_priv;
 
-typedef struct dsa_pub {
-  dsa_param dp;                                /* Shared parameters */
-  mp *y;                               /* Public key */
-} dsa_pub;
+/* --- DSA key seed structure --- */
 
-typedef struct dsa_priv {
-  dsa_param dp;                                /* Shared parameters */
-  mp *x;                               /* Private key */
-  mp *y;                               /* %$y \equiv g^x \pmod{p}$% */
-} dsa_priv;
+typedef struct dsa_seed {
+  void *p;                             /* Pointer to seed material */
+  size_t sz;                           /* Size of seed material */
+  unsigned count;                      /* Iterations to find @p@ */
+} dsa_seed;
 
 /* --- DSA signature structure --- *
  *
@@ -120,28 +126,17 @@ typedef struct dsa_sig {
 
 /*----- Key fetching ------------------------------------------------------*/
 
-extern const key_fetchdef dsa_paramfetch[];
-#define DSA_PARAMFETCHSZ 5
+#define dsa_paramfetch dh_paramfetch
+#define dsa_pubfetch dh_pubfetch
+#define dsa_privfetch dh_privfetch
 
-extern const key_fetchdef dsa_pubfetch[];
-#define DSA_PUBFETCHSZ 6
+#define DSA_PARAMFETCHSZ DH_PARAMFETCHSZ
+#define DSA_PUBFETCHSZ DH_PUBFETCHSZ
+#define DSA_PRIVFETCHSZ DH_PRIVFETCHSZ
 
-extern const key_fetchdef dsa_privfetch[];
-#define DSA_PRIVFETCHSZ 9
-
-/* --- @dsa_paramfree@, @dsa_pubfree@, @dsa_privfree@ --- *
- *
- * Arguments:  @dsa_param *dp@, @dsa_pub *dp@, @dsa_priv *dp@ = pointer
- *                     to key block to free
- *
- * Returns:    ---
- *
- * Use:                Frees a DSA key block.
- */
-
-extern void dsa_paramfree(dsa_param */*dp*/);
-extern void dsa_pubfree(dsa_pub */*dp*/);
-extern void dsa_privfree(dsa_priv */*dp*/);
+#define dsa_paramfree dh_paramfree
+#define dsa_pubfree dh_pubfree
+#define dsa_privfree dh_privfree
 
 /*----- DSA stepper -------------------------------------------------------*/
 
@@ -153,6 +148,8 @@ typedef struct dsa_stepctx {
   mp *q;                               /* Force @p@ to be a multiple */
   size_t bits;                         /* Number of bits in the result */
   unsigned or;                         /* OR mask for low order bits */
+  unsigned count;                      /* Counts the number of steps made */
+  void *seedbuf;                       /* Pointer to seed buffer */
 } dsa_stepctx;
 
 /* --- @dsa_step@ --- *
@@ -166,7 +163,7 @@ extern int dsa_step(int /*rq*/, pgen_event */*ev*/, void */*p*/);
 
 /*----- Functions provided ------------------------------------------------*/
 
-/* --- @dsa_seed@ --- *
+/* --- @dsa_gen@ --- *
  *
  * Arguments:  @dsa_param *dp@ = where to store parameters
  *             @unsigned ql@ = length of @q@ in bits
@@ -174,6 +171,7 @@ extern int dsa_step(int /*rq*/, pgen_event */*ev*/, void */*p*/);
  *             @unsigned steps@ = number of steps to find @q@
  *             @const void *k@ = pointer to key material
  *             @size_t sz@ = size of key material
+ *             @dsa_seed *sd@ = optional pointer for output seed information
  *             @pgen_proc *event@ = event handler function
  *             @void *ectx@ = argument for event handler
  *
@@ -189,9 +187,23 @@ extern int dsa_step(int /*rq*/, pgen_event */*ev*/, void */*p*/);
  *             %$l$%.  Neither limitation applies to this implementation.
  */
 
-extern int dsa_seed(dsa_param */*dp*/, unsigned /*ql*/, unsigned /*pl*/,
-                   unsigned /*steps*/, const void */*k*/, size_t /*sz*/,
-                   pgen_proc */*event*/, void */*ectx*/);
+extern int dsa_gen(dsa_param */*dp*/, unsigned /*ql*/, unsigned /*pl*/,
+                  unsigned /*steps*/, const void */*k*/, size_t /*sz*/,
+                  dsa_seed */*sd*/, pgen_proc */*event*/, void */*ectx*/);
+
+/* --- @dsa_checkparam@ --- *
+ *
+ * Arguments:  @keycheck *kc@ = keycheck state
+ *             @const dsa_param *dp@ = pointer to the parameter set
+ *             @const dsa_seed *ds@ = pointer to seed information
+ *
+ * Returns:    Zero if all OK, or return status from function.
+ *
+ * Use:                Checks a set of DSA parameters for consistency and security.
+ */
+
+extern int dsa_checkparam(keycheck */*kc*/, const dsa_param */*dp*/,
+                         const dsa_seed */*ds*/);
 
 /* --- @dsa_mksig@ --- *
  *