Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/libsec/port/rsatest.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <mp.h>
3
#include <libsec.h>
4
#include <bio.h>
5
 
6
void
7
main(void)
8
{
9
	int n;
10
	vlong start;
11
	char *p;
12
	uchar buf[4096];
13
	Biobuf b;
14
	RSApriv *rsa;
15
	mpint *clr, *enc, *clr2;
16
 
17
	fmtinstall('B', mpfmt);
18
 
19
	rsa = rsagen(1024, 16, 0);
20
	if(rsa == nil)
21
		sysfatal("rsagen");
22
	Binit(&b, 0, OREAD);
23
	clr = mpnew(0);
24
	clr2 = mpnew(0);
25
	enc = mpnew(0);
26
 
27
	strtomp("123456789abcdef123456789abcdef123456789abcdef123456789abcdef", nil, 16, clr);
28
	rsaencrypt(&rsa->pub, clr, enc);
29
 
30
	start = nsec();
31
	for(n = 0; n < 10; n++)
32
		rsadecrypt(rsa, enc, clr);
33
	print("%lld\n", nsec()-start);
34
 
35
	start = nsec();
36
	for(n = 0; n < 10; n++)
37
		mpexp(enc, rsa->dk, rsa->pub.n, clr2);
38
	print("%lld\n", nsec()-start);
39
 
40
	if(mpcmp(clr, clr2) != 0)
41
		print("%B != %B\n", clr, clr2);
42
 
43
	print("> ");
44
	while(p = Brdline(&b, '\n')){
45
		n = Blinelen(&b);
46
		letomp((uchar*)p, n, clr);
47
		print("clr %B\n", clr);
48
		rsaencrypt(&rsa->pub, clr, enc);
49
		print("enc %B\n", enc);
50
		rsadecrypt(rsa, enc, clr);
51
		print("clr %B\n", clr);
52
		n = mptole(clr, buf, sizeof(buf), nil);
53
		write(1, buf, n);
54
		print("> ");
55
	}
56
}