]> WPIA git - cassiopeia.git/blob - lib/collissiondetect/src/main.c
fix: Fix compiler errors due to the modified build system
[cassiopeia.git] / lib / collissiondetect / src / main.c
1 /**************************************************************************\
2 |
3 |    Copyright (C) 2012 CWI
4 |    
5 |    Contact:
6 |    Marc Stevens
7 |    Cryptology Group
8 |    Centrum Wiskunde & Informatica
9 |    P.O. Box 94079, 1090 GB Amsterdam, Netherlands
10 |    marc@marc-stevens.nl
11 |
12 |  Permission is hereby granted, free of charge, to any person obtaining a copy
13 |  of this software and associated documentation files (the "Software"), to deal
14 |  in the Software without restriction, including without limitation the rights
15 |  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 |  copies of the Software, and to permit persons to whom the Software is
17 |  furnished to do so, subject to the following conditions:
18
19 |  The above copyright notice and this permission notice shall be included in
20 |  all copies or substantial portions of the Software.
21
22 |  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 |  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 |  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 |  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 |  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 |  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 |  THE SOFTWARE.
29 |
30 \**************************************************************************/
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "libdetectcoll.h"
37
38 void gen_sha1_dv_xm_tables();
39
40 int main(int argc, char** argv) {
41         FILE* fd;
42         unsigned char hash[16];
43         unsigned char hash2[20];
44         char buffer[65536];
45         unsigned size;
46         MD5_CTX ctx;
47         SHA1_CTX ctx2;
48         int i,j;
49
50         gen_sha1_dv_xm_tables();
51         if (argc < 2) {
52                 printf("Usage: md5sum <file>\n");
53                 return 1;
54         }
55         for (i=1; i < argc; ++i) {
56                 fd = fopen(argv[i], "rb");
57                 if (fd == NULL) {
58                         printf("cannot open file: %s\n", argv[i]);
59                         return 1;
60                 }
61
62                 MD5Init_unsafe(&ctx);
63                 SHA1Init_unsafe(&ctx2);
64
65                 while (1) {
66                         size=fread(buffer,1,65536,fd);
67                         MD5Update(&ctx, buffer, size);
68                         SHA1Update(&ctx2, buffer, size);
69                         if (size != 65536)
70                                 break;
71                 }
72                 if (ferror(fd)) {
73                         printf("error while reading file: %s\n", argv[i]);
74                         return 1;
75                 }
76                 if (!feof(fd)) {
77                         printf("not end of file?: %s\n",argv[i]);
78                         return 1;
79                 }
80
81                 MD5Final(hash,&ctx);
82                 for (j = 0; j < 16; ++j) 
83                         sprintf(buffer+(j*2), "%02x", hash[j]);
84                 buffer[32] = 0;
85                 if (ctx.found_collision) {
86                         printf("md5 *coll* %s %s\n", buffer, argv[i]);
87                 } else {
88                         printf("md5 %s %s\n", buffer, argv[i]);
89                 }
90
91                 SHA1Final(hash2,&ctx2);
92                 for (j = 0; j < 20; ++j) 
93                         sprintf(buffer+(j*2), "%02x", hash2[j]);
94                 buffer[20*2] = 0;
95                 if (ctx2.found_collision) {
96                         printf("sha1 *coll* %s %s\n", buffer, argv[i]);
97                 } else {
98                         printf("sha1 %s %s\n", buffer, argv[i]);
99                 }
100                 printf("\n");
101
102                 fclose(fd);
103         }
104 }