1 #include "os.h"
2 #include <mp.h>
3 #include <libsec.h>
4
5 // I wasn't sure what to do when the buffer was not
6 // a multiple of 8. I did what lacy's cryptolib did
7 // to be compatible, but it looks dangerous to me
8 // since its encrypting plain text with the key. -- presotto
9
10 void
desECBencrypt(uchar * p,int len,DESstate * s)11 desECBencrypt(uchar *p, int len, DESstate *s)
12 {
13 int i;
14 uchar tmp[8];
15
16 for(; len >= 8; len -= 8){
17 block_cipher(s->expanded, p, 0);
18 p += 8;
19 }
20
21 if(len > 0){
22 for (i=0; i<8; i++)
23 tmp[i] = i;
24 block_cipher(s->expanded, tmp, 0);
25 for (i = 0; i < len; i++)
26 p[i] ^= tmp[i];
27 }
28 }
29
30 void
desECBdecrypt(uchar * p,int len,DESstate * s)31 desECBdecrypt(uchar *p, int len, DESstate *s)
32 {
33 int i;
34 uchar tmp[8];
35
36 for(; len >= 8; len -= 8){
37 block_cipher(s->expanded, p, 1);
38 p += 8;
39 }
40
41 if(len > 0){
42 for (i=0; i<8; i++)
43 tmp[i] = i;
44 block_cipher(s->expanded, tmp, 0);
45 for (i = 0; i < len; i++)
46 p[i] ^= tmp[i];
47 }
48 }
49