dsagen.c 721 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <mp.h>
  4. #include <libsec.h>
  5. void
  6. usage(void)
  7. {
  8. fprint(2, "usage: auth/dsagen [-t 'attr=value attr=value ...']\n");
  9. exits("usage");
  10. }
  11. void
  12. main(int argc, char **argv)
  13. {
  14. char *s, *tag;
  15. DSApriv *key;
  16. tag = nil;
  17. fmtinstall('B', mpfmt);
  18. ARGBEGIN{
  19. case 't':
  20. tag = EARGF(usage());
  21. break;
  22. default:
  23. usage();
  24. }ARGEND
  25. if(argc != 0)
  26. usage();
  27. key = dsagen(nil);
  28. s = smprint("key proto=dsa %s%sp=%B q=%B alpha=%B key=%B !secret=%B\n",
  29. tag ? tag : "", tag ? " " : "",
  30. key->pub.p, key->pub.q, key->pub.alpha, key->pub.key,
  31. key->secret);
  32. if(s == nil)
  33. sysfatal("smprint: %r");
  34. if(write(1, s, strlen(s)) != strlen(s))
  35. sysfatal("write: %r");
  36. exits(nil);
  37. }