-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd4driver.c
89 lines (71 loc) · 1.39 KB
/
md4driver.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "MD4.h"
#include <unistd.h>
#define ANSWER 42
typedef unsigned char byte;
int read_cmd(byte *buf);
int write_cmd(byte *buf, int len);
int read_exact(byte *buf, int len);
int write_exact(byte *buf, int len);
int read_cmd(byte *buf)
{
int len;
if(read_exact(buf, 2) != 2)
return(-1);
len = (buf[0] << 8) | buf[1];
return read_exact(buf, len);
}
int write_cmd(byte *buf, int len)
{
byte li;
li = (len >> 8) & 0xff;
write_exact(&li, 1);
li = len & 0xff;
write_exact(&li, 1);
return write_exact(buf, len);
}
int read_exact(byte *buf, int len)
{
int i, got=0;
do
{
if ((i = read(0, buf+got, len-got)) <= 0)
return(i);
got += i;
}while(got<len);
return len;
}
int write_exact(byte *buf, int len)
{
int i, wrote=0;
do
{
if ((i = write(1, buf+wrote, len-wrote)) <= 0)
return i;
wrote += i;
}while(wrote<len);
return len;
}
//message is the rpc from the erlang port
//is of the form <<Size:2, Data:Size, _Rest/binary>>
//Size is little-endian
//returns -1 if message is an {'EXIT', Why} message
int main(void)
{
int i;
byte buf[1024];
byte out[16];
int buflen = 0;
for(i=0;i<1024;i++)
buf[i] = 0;
for(i=0;i<16;i++)
out[i] = 16;
while((buflen = read_cmd(buf)) > 0)
{
auth_md4Sum(out, buf, buflen);
write_cmd(out, 16);
for(i=0;i<1024;i++)
buf[i]=0;
for(i=0;i<16;i++)
out[i]=0;
}
}