Commit | Line | Data |
---|---|---|
3719602c PC |
1 | /* |
2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. | |
3 | * MD5 Message-Digest Algorithm (RFC 1321). | |
4 | * | |
5 | * Homepage: | |
6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 | |
7 | * | |
8 | * Author: | |
9 | * Alexander Peslyak, better known as Solar Designer <solar at openwall.com> | |
10 | * | |
11 | * This software was written by Alexander Peslyak in 2001. No copyright is | |
12 | * claimed, and the software is hereby placed in the public domain. | |
13 | * In case this attempt to disclaim copyright and place the software in the | |
14 | * public domain is deemed null and void, then the software is | |
15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the | |
16 | * general public under the following terms: | |
17 | * | |
18 | * Redistribution and use in source and binary forms, with or without | |
19 | * modification, are permitted. | |
20 | * | |
21 | * There's ABSOLUTELY NO WARRANTY, express or implied. | |
22 | * | |
23 | * (This is a heavily cut-down "BSD license".) | |
24 | * | |
25 | * This differs from Colin Plumb's older public domain implementation in that | |
26 | * no exactly 32-bit integer data type is required (any 32-bit or wider | |
27 | * unsigned integer data type will do), there's no compile-time endianness | |
28 | * configuration, and the function prototypes match OpenSSL's. No code from | |
29 | * Colin Plumb's implementation has been reused; this comment merely compares | |
30 | * the properties of the two independent implementations. | |
31 | * | |
32 | * The primary goals of this implementation are portability and ease of use. | |
33 | * It is meant to be fast, but not as fast as possible. Some known | |
34 | * optimizations are not included to reduce source code size and avoid | |
35 | * compile-time configuration. | |
36 | */ | |
37 | #include <stdio.h> | |
38 | #include <string.h> | |
39 | ||
40 | #include <lrc_hash.h> | |
41 | ||
42 | int main (int argc, char *argv[]) | |
43 | { | |
44 | /* For each command line argument in turn: | |
45 | ** filename -- prints message digest and name of file | |
46 | */ | |
47 | int i; | |
48 | MD5_CTX ctx; | |
49 | FILE* file; | |
50 | size_t numread; | |
51 | char buffer[16384]; | |
52 | unsigned char result[16]; | |
53 | ||
54 | for (i = 1; i < argc; i++) | |
55 | { | |
56 | MD5_Init(&ctx); | |
57 | file = fopen(argv[i], "rb"); | |
58 | ||
59 | if (file) | |
60 | { | |
61 | do | |
62 | { | |
63 | numread = fread((void*)buffer, 1, sizeof(buffer), file); | |
64 | ||
65 | if (numread) | |
66 | { | |
67 | MD5_Update(&ctx,(void*)buffer, numread); | |
68 | } | |
69 | } | |
70 | while (numread); | |
71 | ||
72 | fclose(file); | |
73 | MD5_Final(result, &ctx); | |
74 | printf("%02x%02x%02x%02x%02x%02x%02x%02x" | |
75 | "%02x%02x%02x%02x%02x%02x%02x%02x %s\n", | |
76 | result[ 0 ], result[ 1 ], result[ 2 ], result[ 3 ], | |
77 | result[ 4 ], result[ 5 ], result[ 6 ], result[ 7 ], | |
78 | result[ 8 ], result[ 9 ], result[ 10 ], result[ 11 ], | |
79 | result[ 12 ], result[ 13 ], result[ 14 ], result[ 15 ], | |
80 | argv[i]); | |
81 | } | |
82 | } | |
83 | ||
84 | return 0; | |
85 | } |