]> WPIA git - cassiopeia.git/blob - lib/collissiondetect/lib/libdetectcoll.h
add: Import libdetectcoll v0.2 source code by Marc Steven
[cassiopeia.git] / lib / collissiondetect / lib / libdetectcoll.h
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 <stdint.h>
33
34 // lib interface below
35
36 typedef struct {
37         uint64_t total;
38         uint32_t ihv[4];
39         unsigned char buffer[64];
40         int bigendian;
41         int found_collision;
42         int safe_hash;
43
44         uint32_t ihv1[4];
45         uint32_t ihv2[4];
46         uint32_t m2[16];
47         uint32_t states[260];
48         uint32_t statesmsb[260];
49         uint32_t tmpihv[4];
50         uint32_t tmpblock[16];
51         uint32_t previhv[4];
52         uint32_t prevblock[16];
53 } MD5_CTX;
54
55
56 void md5compress_states(uint32_t ihv[4], const uint32_t block[16], uint32_t states[260]);
57 int md5recompress_fast(unsigned t, uint32_t ihv[4], const uint32_t block[16], const uint32_t state[4], const uint32_t rihv[4]);
58 int detect_coll(const uint32_t block1[16], const uint32_t states[260], const uint32_t statesmsb[260], const uint32_t tihv[4], uint32_t ihv2[4], uint32_t block2[16]);
59
60 typedef struct {
61         uint32_t msgdiff[16];
62         unsigned t;
63         int negate;
64         int zero;
65         int msb;
66 } msgdiff_tuples_t;
67 extern msgdiff_tuples_t msgdiff_tuples[];
68
69 typedef struct {
70         uint64_t total;
71         uint32_t ihv[5];
72         unsigned char buffer[64];
73         int bigendian;
74         int found_collision;
75         int safe_hash;
76
77         uint32_t ihv1[5];
78         uint32_t ihv2[5];
79         uint32_t m1[80];
80         uint32_t m2[80];
81         uint32_t states[81*5];
82 } SHA1_CTX;     
83
84 void sha1compress_me(const uint32_t block[16], uint32_t me[80]);
85 void sha1compress_states(uint32_t ihv[5], const uint32_t me[80], uint32_t states[81*5]);
86 int sha1recompress_fast(unsigned t, uint32_t ihv[5], const uint32_t me[80], const uint32_t state[5], const uint32_t rihv[5]);
87
88
89
90 /* LIB INTERFACE */
91
92 void MD5Init(MD5_CTX*); // outputs MD5 hash if no collision was found and a modified-MD5 hash otherwise
93 void MD5Init_unsafe(MD5_CTX*); // always outputs MD5 hash
94 void MD5Update(MD5_CTX*, const char* buf, unsigned len);
95 int  MD5Final(unsigned char hash[16], MD5_CTX*); // returns: 0 = no collision, otherwise = collision found => warn user for active attack
96
97 void SHA1Init(SHA1_CTX*); // outputs SHA-1 hash if no collision was found and a modified-SHA-1 hash otherwise
98 void SHA1Init_unsafe(SHA1_CTX*); // always outputs SHA-1 hash
99 void SHA1Update(SHA1_CTX*, const char* buf, unsigned len);
100 int  SHA1Final(unsigned char hash[20], SHA1_CTX*); // returns: 0 = no collision, otherwise = collision found => warn user for active attack