summaryrefslogtreecommitdiff
path: root/libsec/port/rsatest.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /libsec/port/rsatest.c
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'libsec/port/rsatest.c')
-rw-r--r--libsec/port/rsatest.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/libsec/port/rsatest.c b/libsec/port/rsatest.c
new file mode 100644
index 00000000..ee10dcd3
--- /dev/null
+++ b/libsec/port/rsatest.c
@@ -0,0 +1,57 @@
+#include "os.h"
+#include <mp.h>
+#include <libsec.h>
+#include <bio.h>
+
+void
+main(void)
+{
+ RSApriv *rsa;
+ Biobuf b;
+ char *p;
+ int n;
+ mpint *clr, *enc, *clr2;
+ uchar buf[4096];
+ uchar *e;
+ vlong start;
+
+ fmtinstall('B', mpfmt);
+
+ rsa = rsagen(1024, 16, 0);
+ if(rsa == nil)
+ sysfatal("rsagen");
+ Binit(&b, 0, OREAD);
+ clr = mpnew(0);
+ clr2 = mpnew(0);
+ enc = mpnew(0);
+
+ strtomp("123456789abcdef123456789abcdef123456789abcdef123456789abcdef", nil, 16, clr);
+ rsaencrypt(&rsa->pub, clr, enc);
+
+ start = nsec();
+ for(n = 0; n < 10; n++)
+ rsadecrypt(rsa, enc, clr);
+ print("%lld\n", nsec()-start);
+
+ start = nsec();
+ for(n = 0; n < 10; n++)
+ mpexp(enc, rsa->dk, rsa->pub.n, clr2);
+ print("%lld\n", nsec()-start);
+
+ if(mpcmp(clr, clr2) != 0)
+ print("%B != %B\n", clr, clr2);
+
+ print("> ");
+ while(p = Brdline(&b, '\n')){
+ n = Blinelen(&b);
+ letomp((uchar*)p, n, clr);
+ print("clr %B\n", clr);
+ rsaencrypt(&rsa->pub, clr, enc);
+ print("enc %B\n", enc);
+ rsadecrypt(rsa, enc, clr);
+ print("clr %B\n", clr);
+ n = mptole(clr, buf, sizeof(buf), nil);
+ write(1, buf, n);
+ print("> ");
+ }
+}