/* -*-c-*-
*
- * $Id: keyutil.c,v 1.18 2004/04/01 12:50:09 mdw Exp $
+ * $Id: keyutil.c,v 1.22 2004/04/03 15:45:06 mdw Exp $
*
* Simple key manager program
*
/*----- Revision history --------------------------------------------------*
*
* $Log: keyutil.c,v $
+ * Revision 1.22 2004/04/03 15:45:06 mdw
+ * Oops. Fix formatting. :-S
+ *
+ * Revision 1.21 2004/04/03 15:15:19 mdw
+ * Fix stupid error in previous rashly-committed version.
+ *
+ * Revision 1.20 2004/04/03 15:14:28 mdw
+ * Handle points at infinity properly in listings.
+ *
+ * Revision 1.19 2004/04/03 03:31:01 mdw
+ * Allow explicit group parameters for DH groups.
+ *
* Revision 1.18 2004/04/01 12:50:09 mdw
* Add cyclic group abstraction, with test code. Separate off exponentation
* functions for better static linking. Fix a buttload of bugs on the way.
#include "mprand.h"
#include "mptext.h"
#include "pgen.h"
+#include "ptab.h"
#include "rsa.h"
#include "sha-mgf.h"
dh_param dp;
int rc;
+ if (k->curve) {
+ qd_parse qd;
+
+ if (strcmp(k->curve, "list") == 0) {
+ const pentry *pe;
+ printf("Built-in prime groups:\n");
+ for (pe = ptab; pe->name; pe++)
+ printf(" %s\n", pe->name);
+ exit(0);
+ }
+ qd.p = k->curve;
+ if (dh_parse(&qd, &dp))
+ die(EXIT_FAILURE, "error in group spec: %s", qd.e);
+ goto done;
+ }
+
if (!k->bits)
k->bits = 1024;
if (rc)
die(EXIT_FAILURE, "Diffie-Hellman parameter generation failed");
+ done:
key_structure(kd);
mpkey(kd, "p", dp.p, KCAT_SHARE);
mpkey(kd, "q", dp.q, KCAT_SHARE);
/* --- Decide on a curve --- */
if (!k->bits) k->bits = 256;
+ if (k->curve && strcmp(k->curve, "list") == 0) {
+ const ecentry *ee;
+ printf("Built-in elliptic curves:\n");
+ for (ee = ectab; ee->name; ee++)
+ printf(" %s\n", ee->name);
+ exit(0);
+ }
if (!k->curve) {
if (k->bits <= 56) k->curve = "secp112r1";
else if (k->bits <= 64) k->curve = "secp128r1";
{ "subgroup", 0, 0, 'S' },
{ 0, 0, 0, 0 }
};
- int i = mdwopt(argc, argv, "+a:b:B:p:e:c:t:R:C:A:s:n:lqrLS", opt, 0, 0, 0);
+ int i = mdwopt(argc, argv, "+a:b:B:p:e:c:t:R:C:A:s:n:lqrLS",
+ opt, 0, 0, 0);
if (i < 0)
break;
/* --- Elliptic curve parameters --- */
case 'C':
- if (strcmp(optarg, "list") == 0) {
- const ecentry *ee;
- printf("Built-in elliptic curves:\n");
- for (ee = ectab; ee->name; ee++)
- printf(" %s\n", ee->name);
- exit(0);
- }
k.curve = optarg;
break;
/* --- Elliptic curve points --- */
case KENC_EC:
- fputs(" 0x", stdout); mp_writefile(k->u.e.x, stdout, 16);
- fputs(", 0x", stdout); mp_writefile(k->u.e.y, stdout, 16);
- putchar('\n');
+ if (EC_ATINF(&k->u.e))
+ fputs(" inf\n", stdout);
+ else {
+ fputs(" 0x", stdout); mp_writefile(k->u.e.x, stdout, 16);
+ fputs(", 0x", stdout); mp_writefile(k->u.e.y, stdout, 16);
+ putchar('\n');
+ }
break;
/* --- Structured keys --- *