dsagen.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <mp.h>
  12. #include <libsec.h>
  13. void
  14. usage(void)
  15. {
  16. fprint(2, "usage: auth/dsagen [-t 'attr=value attr=value ...']\n");
  17. exits("usage");
  18. }
  19. void
  20. main(int argc, char **argv)
  21. {
  22. char *s, *tag;
  23. DSApriv *key;
  24. tag = nil;
  25. fmtinstall('B', mpfmt);
  26. ARGBEGIN{
  27. case 't':
  28. tag = EARGF(usage());
  29. break;
  30. default:
  31. usage();
  32. }ARGEND
  33. if(argc != 0)
  34. usage();
  35. key = dsagen(nil);
  36. s = smprint("key proto=dsa %s%sp=%B q=%B alpha=%B key=%B !secret=%B\n",
  37. tag ? tag : "", tag ? " " : "",
  38. key->pub.p, key->pub.q, key->pub.alpha, key->pub.key,
  39. key->secret);
  40. if(s == nil)
  41. sysfatal("smprint: %r");
  42. if(write(1, s, strlen(s)) != strlen(s))
  43. sysfatal("write: %r");
  44. exits(nil);
  45. }