rsagen.c (999B)
1 #include <u.h> 2 #include <libc.h> 3 #include <mp.h> 4 #include <libsec.h> 5 6 void 7 usage(void) 8 { 9 fprint(2, "usage: auth/rsagen [-b bits] [-t 'attr=value attr=value ...']\n"); 10 exits("usage"); 11 } 12 13 void 14 main(int argc, char **argv) 15 { 16 char *s; 17 int bits; 18 char *tag; 19 RSApriv *key; 20 21 bits = 1024; 22 tag = nil; 23 key = nil; 24 fmtinstall('B', mpfmt); 25 26 ARGBEGIN{ 27 case 'b': 28 bits = atoi(EARGF(usage())); 29 if(bits == 0) 30 usage(); 31 break; 32 case 't': 33 tag = EARGF(usage()); 34 break; 35 default: 36 usage(); 37 }ARGEND 38 39 if(argc != 0) 40 usage(); 41 42 do{ 43 if(key) 44 rsaprivfree(key); 45 key = rsagen(bits, 6, 0); 46 }while(mpsignif(key->pub.n) != bits); 47 48 s = smprint("key proto=rsa %s%ssize=%d ek=%lB !dk=%lB n=%lB !p=%lB !q=%lB !kp=%lB !kq=%lB !c2=%lB\n", 49 tag ? tag : "", tag ? " " : "", 50 mpsignif(key->pub.n), key->pub.ek, 51 key->dk, key->pub.n, key->p, key->q, 52 key->kp, key->kq, key->c2); 53 if(s == nil) 54 sysfatal("smprint: %r"); 55 56 if(write(1, s, strlen(s)) != strlen(s)) 57 sysfatal("write: %r"); 58 59 exits(nil); 60 }