gdsa: Include "dsa.h" for dsa_h2n.
[u/mdw/catacomb] / dsa.h
diff --git a/dsa.h b/dsa.h
index e8dee83..43ff845 100644 (file)
--- a/dsa.h
+++ b/dsa.h
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: dsa.h,v 1.4 1999/12/22 15:52:44 mdw Exp $
+ * $Id: dsa.h,v 1.9 2004/04/08 01:36:15 mdw Exp $
  *
  * Digital Signature Algorithm
  *
  * (c) 1999 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Catacomb.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * Catacomb is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with Catacomb; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: dsa.h,v $
- * Revision 1.4  1999/12/22 15:52:44  mdw
- * Reworking for new prime-search system.
- *
- * Revision 1.3  1999/12/10 23:29:48  mdw
- * Change header file guard names.
- *
- * Revision 1.2  1999/11/20 22:23:48  mdw
- * Allow event handler to abort the search process.
- *
- * Revision 1.1  1999/11/19 19:28:00  mdw
- * Implementation of the Digital Signature Algorithm.
- *
- */
-
 #ifndef CATACOMB_DSA_H
 #define CATACOMB_DSA_H
 
 
 /*----- 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
-    
+
 #ifndef CATACOMB_PGEN_H
 #  include "pgen.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;
+
+/* --- DSA key seed structure --- */
+
+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 --- *
  *
@@ -97,6 +95,20 @@ typedef struct dsa_sig {
   octet s[DSA_SIGLEN];                 /* 160-bit @s@ value */
 } dsa_sig;
 
+/*----- Key fetching ------------------------------------------------------*/
+
+#define dsa_paramfetch dh_paramfetch
+#define dsa_pubfetch dh_pubfetch
+#define dsa_privfetch dh_privfetch
+
+#define DSA_PARAMFETCHSZ DH_PARAMFETCHSZ
+#define DSA_PUBFETCHSZ DH_PUBFETCHSZ
+#define DSA_PRIVFETCHSZ DH_PRIVFETCHSZ
+
+#define dsa_paramfree dh_paramfree
+#define dsa_pubfree dh_pubfree
+#define dsa_privfree dh_privfree
+
 /*----- DSA stepper -------------------------------------------------------*/
 
 typedef struct dsa_stepctx {
@@ -107,6 +119,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@ --- *
@@ -116,11 +130,11 @@ typedef struct dsa_stepctx {
  * divisibility by small primes.
  */
 
-extern int dsa_step(int /*rq*/, pgen_event */*ev*/, void */*p*/);
+extern pgen_proc dsa_step;
 
 /*----- Functions provided ------------------------------------------------*/
 
-/* --- @dsa_seed@ --- *
+/* --- @dsa_gen@ --- *
  *
  * Arguments:  @dsa_param *dp@ = where to store parameters
  *             @unsigned ql@ = length of @q@ in bits
@@ -128,6 +142,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
  *
@@ -143,9 +158,39 @@ 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_h2n@ --- *
+ *
+ * Arguments:  @mp *d@ = destination integer
+ *             @mp *r@ = order of the DSA group
+ *             @const void *h@ = pointer to message hash
+ *             @size_t hsz@ = size (in bytes) of the hash output
+ *
+ * Returns:    Resulting integer.
+ *
+ * Use:                Converts a hash to an integer in the demented way necessary
+ *             for DSA/ECDSA.  This is, of course, completely insane, but
+ *             there you go.
+ */
+
+extern mp *dsa_h2n(mp */*d*/, mp */*r*/, const void */*h*/, size_t /*hsz*/);
 
 /* --- @dsa_mksig@ --- *
  *
@@ -221,9 +266,9 @@ extern int dsa_vrfy(const dsa_param */*dp*/, mp */*y*/,
  */
 
 extern int dsa_verify(const dsa_param */*dp*/, mp */*y*/,
-              const void */*m*/, size_t /*msz*/,
-              const void */*r*/, size_t /*rsz*/,
-              const void */*s*/, size_t /*ssz*/);
+                     const void */*m*/, size_t /*msz*/,
+                     const void */*r*/, size_t /*rsz*/,
+                     const void */*s*/, size_t /*ssz*/);
 
 /*----- That's all, folks -------------------------------------------------*/