Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <libsec.h>
3
 
4
// Because of the way that non multiple of 8
5
// buffers are handled, the decryptor must
6
// be fed buffers of the same size as the
7
// encryptor
8
 
9
 
10
// If the length is not a multiple of 8, I encrypt
11
// the overflow to be compatible with lacy's cryptlib
12
void
13
des3CBCencrypt(uchar *p, int len, DES3state *s)
14
{
15
	uchar *p2, *ip, *eip;
16
 
17
	for(; len >= 8; len -= 8){
18
		p2 = p;
19
		ip = s->ivec;
20
		for(eip = ip+8; ip < eip; )
21
			*p2++ ^= *ip++;
22
		triple_block_cipher(s->expanded, p, DES3EDE);
23
		memmove(s->ivec, p, 8);
24
		p += 8;
25
	}
26
 
27
	if(len > 0){
28
		ip = s->ivec;
29
		triple_block_cipher(s->expanded, ip, DES3EDE);
30
		for(eip = ip+len; ip < eip; )
31
			*p++ ^= *ip++;
32
	}
33
}
34
 
35
void
36
des3CBCdecrypt(uchar *p, int len, DES3state *s)
37
{
38
	uchar *ip, *eip, *tp;
39
	uchar tmp[8];
40
 
41
	for(; len >= 8; len -= 8){
42
		memmove(tmp, p, 8);
43
		triple_block_cipher(s->expanded, p, DES3DED);
44
		tp = tmp;
45
		ip = s->ivec;
46
		for(eip = ip+8; ip < eip; ){
47
			*p++ ^= *ip;
48
			*ip++ = *tp++;
49
		}
50
	}
51
 
52
	if(len > 0){
53
		ip = s->ivec;
54
		triple_block_cipher(s->expanded, ip, DES3EDE);
55
		for(eip = ip+len; ip < eip; )
56
			*p++ ^= *ip++;
57
	}
58
}