-
Notifications
You must be signed in to change notification settings - Fork 3
/
simck.c
72 lines (55 loc) · 1.45 KB
/
simck.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
/*
* Copyright (c) Regents of The University of Michigan
* See COPYING.
*/
#include <config.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "md.h"
#include "simta.h"
const char *simta_progname = "simck";
int
main(int argc, char *argv[]) {
int fd;
SNET *snet;
char *line;
u_int line_len;
const EVP_MD *testdigest;
struct message_digest md;
if (argc != 3) {
fprintf(stderr, "Usage: %s <checksum_algorithm> <file>\n", argv[ 0 ]);
return 1;
}
testdigest = EVP_get_digestbyname((const char *)(argv[ 1 ]));
if (testdigest == NULL) {
fprintf(stderr, "%s: unknown checksum algorithm\n", argv[ 1 ]);
return 1;
}
md_init(&md);
md_reset(&md, argv[ 1 ]);
if ((fd = open(argv[ 2 ], O_RDONLY, 0)) < 0) {
perror("open");
exit(1);
}
if ((snet = snet_attach(fd)) == NULL) {
perror("snet_attach");
exit(1);
}
while ((line = snet_getline(snet, NULL)) != NULL) {
line_len = strlen(line);
md_update(&md, line, line_len);
}
md_finalize(&md);
md_cleanup(&md);
if (snet_close(snet) != 0) {
perror("snet_close");
return 1;
}
printf("\nChecksum: %s\n", md.md_b16);
return 0;
}
/* vim: set softtabstop=4 shiftwidth=4 expandtab :*/