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