forked from tzikis/ArduinoMD5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
54 lines (40 loc) · 765 Bytes
/
main.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
/*
* test_md5.c
*
* Created on: 26 апр. 2023 г.
* Author: user
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#if __WIN32__
#include <fcntl.h>
#include <io.h>
#endif
#include "md5.h"
#define BUFLEN 1024
int main(int argc, char * argv[]) {
int rtn = 0;
uint8_t buf[BUFLEN];
size_t sizeread;
MD5_CTX ctx;
uint8_t hash[MD5_HASH_LEN];
char * digest = NULL;
#if __WIN32__
_setmode(_fileno(stdin), _O_BINARY);
#else
freopen(NULL, "rb", stdin);
#endif
MD5Init(&ctx);
while (!feof(stdin)) {
sizeread = fread(buf, 1, BUFLEN, stdin);
if (sizeread != 0) {
MD5Update(&ctx, buf, sizeread);
}
}
MD5Final(hash, &ctx);
digest = make_digest(hash, MD5_HASH_LEN);
fputs(digest, stdout);
free(digest);
return rtn;
}