-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcrypto_hashes.c
67 lines (55 loc) · 1.16 KB
/
crypto_hashes.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
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/if_alg.h>
int main(int argc, char **argv)
{
int cli_fd;
int ser_fd;
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "hash",
.salg_name = "sha1",
};
int i;
char buf[1000];
if (argc != 3) {
fprintf(stderr, "%s [hash_function] [input]\n"
"Where hash_function is one of the below\n"
"\t 1. crct10dif\n"
"\t 2. sha224\n"
"\t 3. sha256\n"
"\t 4. sha1\n"
"\t 5. md5\n"
"\t 6. md4\n",
argv[0]);
return -1;
}
strcpy(sa.salg_name, argv[1]);
ser_fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
if (ser_fd < 0)
return -1;
int ret;
ret = bind(ser_fd, (struct sockaddr *)&sa, sizeof(sa));
if (ret < 0)
return -1;
cli_fd = accept(ser_fd, NULL, NULL);
if (cli_fd < 0)
return -1;
write(cli_fd, argv[2], strlen(argv[2]));
ret = read(cli_fd, buf, sizeof(buf));
if (ret < 0)
return -1;
for (i = 0; i < ret; i ++) {
printf("%02x", buf[i] & 0xff);
}
printf("\n");
close(cli_fd);
close(ser_fd);
return 0;
}