Support Lim-Lee primes in Diffie-Hellman parameter generation.
authormdw <mdw>
Sat, 29 Jul 2000 09:59:13 +0000 (09:59 +0000)
committermdw <mdw>
Sat, 29 Jul 2000 09:59:13 +0000 (09:59 +0000)
keyutil.c

index be8d5f9..3a23a85 100644 (file)
--- a/keyutil.c
+++ b/keyutil.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: keyutil.c,v 1.7 2000/07/01 11:18:51 mdw Exp $
+ * $Id: keyutil.c,v 1.8 2000/07/29 09:59:13 mdw Exp $
  *
  * Simple key manager program
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: keyutil.c,v $
+ * Revision 1.8  2000/07/29 09:59:13  mdw
+ * Support Lim-Lee primes in Diffie-Hellman parameter generation.
+ *
  * Revision 1.7  2000/07/01 11:18:51  mdw
  * Use new interfaces for key manipulation.
  *
@@ -176,7 +179,9 @@ typedef struct keyopts {
 enum {
   f_bogus = 1,                         /* Error in parsing */
   f_lock = 2,                          /* Passphrase-lock private key */
-  f_quiet = 4                          /* Don't show a progress indicator */
+  f_quiet = 4,                         /* Don't show a progress indicator */
+  f_limlee = 8,                                /* Generate Lim-Lee primes */
+  f_subgroup = 16                      /* Generate a subgroup */
 };
 
 /* --- @dolock@ --- *
@@ -470,8 +475,8 @@ static void alg_dsaparam(keyopts *k)
 
     /* --- Allocate the parameters --- */
 
-    if (dsa_seed(&dp, k->qbits, k->bits, 0, p, sz,
-                (k->f & f_quiet) ? 0 : pgen_ev, 0))
+    if (dsa_gen(&dp, k->qbits, k->bits, 0, p, sz,
+               (k->f & f_quiet) ? 0 : pgen_ev, 0))
       die(EXIT_FAILURE, "DSA parameter generation failed");
 
     /* --- Store the parameters --- */
@@ -535,14 +540,39 @@ static void alg_dhparam(keyopts *k)
   if (!copyparam(k, pl)) {
     dh_param dp;
     key_data *kd = &k->k->k;
+    int rc;
 
     if (!k->bits)
       k->bits = 1024;
 
     /* --- Choose a large safe prime number --- */
 
-    if (dh_gen(&dp, k->qbits, k->bits, 0, &rand_global,
-              (k->f & f_quiet) ? 0 : pgen_ev, 0))
+    if (k->f & f_limlee) {
+      mp **f;
+      size_t nf;
+      if (!k->qbits)
+       k->qbits = 256;
+      rc = dh_limlee(&dp, k->qbits, k->bits,
+                    (k->f & f_subgroup) ? DH_SUBGROUP : 0,
+                    0, &rand_global, (k->f & f_quiet) ? 0 : pgen_ev, 0,
+                    (k->f & f_quiet) ? 0 : pgen_evspin, 0, &nf, &f);
+      if (!rc) {
+       dstr d = DSTR_INIT;
+       size_t i;
+       for (i = 0; i < nf; i++) {
+         if (i)
+           dstr_puts(&d, ", ");
+         mp_writedstr(f[i], &d, 10);
+         mp_drop(f[i]);
+       }
+       key_putattr(k->kf, k->k, "factors", d.buf);
+       dstr_destroy(&d);
+      }
+    } else
+      rc = dh_gen(&dp, k->qbits, k->bits, 0, &rand_global,
+                 (k->f & f_quiet) ? 0 : pgen_ev, 0);
+
+    if (rc)
       die(EXIT_FAILURE, "Diffie-Hellman parameter generation failed");
 
     key_structure(kd);
@@ -673,9 +703,11 @@ static int cmd_add(int argc, char *argv[])
       { "rand-id",     OPTF_ARGREQ,    0,      'r' },
       { "lock",                0,              0,      'l' },
       { "quiet",       0,              0,      'q' },
+      { "lim-lee",     0,              0,      'L' },
+      { "subgroup",    0,              0,      'S' },
       { 0,             0,              0,      0 }
     };
-    int i = mdwopt(argc, argv, "+a:b:B:p:e:c:t:r:lq", opt, 0, 0, 0);
+    int i = mdwopt(argc, argv, "+a:b:B:p:e:c:t:r:lqLS", opt, 0, 0, 0);
     if (i < 0)
       break;
 
@@ -772,6 +804,12 @@ static int cmd_add(int argc, char *argv[])
       case 'q':
        k.f |= f_quiet;
        break;
+      case 'L':
+       k.f |= f_limlee;
+       break;
+      case 'S':
+       k.f |= f_subgroup;
+       break;
 
       /* --- Other things are bogus --- */
 
@@ -1511,7 +1549,7 @@ static struct cmd {
 } cmds[] = {
   { "add", cmd_add,
     "add [options] type [attr...]\n\
-       Options: [-lq] [-a alg] [-b|-B bits] [-p param] [-r tag]\n\
+       Options: [-lqLS] [-a alg] [-b|-B bits] [-p param] [-r tag]\n\
                 [-e expire] [-t tag] [-c comment]"
   },
   { "expire", cmd_expire, "expire tag..." },