summaryrefslogtreecommitdiff
path: root/appl/cmd/ssh/cipherrc4.b
blob: f43f9c8d3cfb3aaaa98e3ee6a89947ecacb487d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
implement Cipher;

include "sys.m";

include "ipints.m";
	ipints: IPints;
	IPint: import ipints;

include "crypt.m";
	crypt: Crypt;
	RC4state: import crypt;

include "sshio.m";

Cipherstate: adt
{
	enc: ref RC4state;
	dec: ref RC4state;
};

cs: ref Cipherstate;

id(): int
{
	return SSH_CIPHER_RC4;
}

init(key: array of byte, isserver: int)
{
	ipints = load IPints IPints->PATH;
	crypt = load Crypt Crypt->PATH;
	if(isserver)
		cs = ref Cipherstate(crypt->rc4setup(key[0:16]), crypt->rc4setup(key[16:32]));
	else
		cs = ref Cipherstate(crypt->rc4setup(key[16:32]), crypt->rc4setup(key[0:16]));
}

encrypt(buf: array of byte, nbuf: int)
{
	crypt->rc4(cs.enc, buf, nbuf);
}

decrypt(buf: array of byte, nbuf: int)
{
	crypt->rc4(cs.dec, buf, nbuf);
}