rsagen.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/rsagen [-b bits] [-t 'attr=value attr=value ...']\n");
  17. exits("usage");
  18. }
  19. void
  20. main(int argc, char **argv)
  21. {
  22. char *s;
  23. int bits;
  24. char *tag;
  25. RSApriv *key;
  26. bits = 1024;
  27. tag = nil;
  28. key = nil;
  29. fmtinstall('B', mpfmt);
  30. ARGBEGIN{
  31. case 'b':
  32. bits = atoi(EARGF(usage()));
  33. if(bits == 0)
  34. usage();
  35. break;
  36. case 't':
  37. tag = EARGF(usage());
  38. break;
  39. default:
  40. usage();
  41. }ARGEND
  42. if(argc != 0)
  43. usage();
  44. do{
  45. if(key)
  46. rsaprivfree(key);
  47. key = rsagen(bits, 6, 0);
  48. }while(mpsignif(key->pub.n) != bits);
  49. s = smprint("key proto=rsa %s%ssize=%d ek=%B !dk=%B n=%B !p=%B !q=%B !kp=%B !kq=%B !c2=%B\n",
  50. tag ? tag : "", tag ? " " : "",
  51. mpsignif(key->pub.n), key->pub.ek,
  52. key->dk, key->pub.n, key->p, key->q,
  53. key->kp, key->kq, key->c2);
  54. if(s == nil)
  55. sysfatal("smprint: %r");
  56. if(write(1, s, strlen(s)) != strlen(s))
  57. sysfatal("write: %r");
  58. exits(nil);
  59. }