Wed, 27 Jan 2021 23:11:41 +0200
updated the documentation of the string functions
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #include "md5.h" |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | #include <stdio.h> |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | #include <string.h> |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
11
diff
changeset
|
4 | BEGIN_ZFC_NAMESPACE |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * This code implements the MD5 message-digest algorithm. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * The algorithm is due to Ron Rivest. This code was |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * written by Colin Plumb in 1993, no copyright is claimed. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This code is in the public domain; do with it what you wish. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * Equivalent code is available from RSA Data Security, Inc. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * This code has been tested against that, and is equivalent, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * except that you don't need to include two pages of legalese |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * with every copy. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | * To compute the message digest of a chunk of bytes, declare an |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | * MD5Context structure, pass it to MD5Init, call MD5Update as |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | * needed on buffers full of bytes, and then call MD5Final, which |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | * will fill a supplied 16-byte array with the digest. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | * |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | /* md5.h */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | typedef unsigned int uint32; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | struct MD5Context |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | uint32 buf[4]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | uint32 bits[2]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | unsigned char in[64]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | }; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | void MD5Init (struct MD5Context*); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | void MD5Update (struct MD5Context*, unsigned const char*, unsigned); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | void MD5Final (unsigned char digest[16], struct MD5Context*); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | void MD5Transform (uint32 buf[4], uint32 const in[16]); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | * This is needed to make RSAREF happy on some MS-DOS compilers. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | typedef struct MD5Context MD5_CTX; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | /* md5.c */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | * Note: this code is harmless on little-endian machines. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | static void byteReverse (unsigned char* buf, unsigned longs) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | uint32 t; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | do |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | t = (uint32) ( (unsigned) buf[3] << 8 | buf[2]) << 16 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | ( (unsigned) buf[1] << 8 | buf[0]); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | * (uint32*) buf = t; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | buf += 4; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | while (--longs); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | static void putu32 (uint32 data, unsigned char* addr) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | addr[0] = (unsigned char) data; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | addr[1] = (unsigned char) (data >> 8); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | addr[2] = (unsigned char) (data >> 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | addr[3] = (unsigned char) (data >> 24); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | * initialization constants. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | void MD5Init (struct MD5Context* ctx) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | ctx->buf[0] = 0x67452301U; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | ctx->buf[1] = 0xefcdab89U; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | ctx->buf[2] = 0x98badcfeU; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | ctx->buf[3] = 0x10325476U; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | ctx->bits[0] = 0; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | ctx->bits[1] = 0; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | * Update context to reflect the concatenation of another buffer full |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | * of bytes. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | void MD5Update (struct MD5Context* ctx, unsigned const char* buf, unsigned len) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | uint32 t; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | /* Update bitcount */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | t = ctx->bits[0]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | if ( (ctx->bits[0] = t + ( (uint32) len << 3)) < t) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | ctx->bits[1]++; /* Carry from low to high */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | ctx->bits[1] += len >> 29; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | /* Handle any leading odd-sized chunks */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | if (t) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | unsigned char* p = (unsigned char*) ctx->in + t; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | t = 64 - t; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | if (len < t) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | memcpy (p, buf, len); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | return; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | memcpy (p, buf, t); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | byteReverse (ctx->in, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | MD5Transform (ctx->buf, (uint32*) ctx->in); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | buf += t; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | len -= t; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | /* Process data in 64-byte chunks */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | while (len >= 64) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | memcpy (ctx->in, buf, 64); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | byteReverse (ctx->in, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | MD5Transform (ctx->buf, (uint32*) ctx->in); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | buf += 64; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | len -= 64; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | /* Handle any remaining bytes of data. */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | memcpy (ctx->in, buf, len); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | * Final wrapup - pad to 64-byte boundary with the bit pattern |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | * 1 0* (64-bit count of bits processed, MSB-first) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | void MD5Final (unsigned char digest[16], struct MD5Context* ctx) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | unsigned count; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | unsigned char* p; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | /* Compute number of bytes mod 64 */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | count = (ctx->bits[0] >> 3) & 0x3F; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | /* Set the first char of padding to 0x80. This is safe since there is |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | always at least one byte free */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | p = ctx->in + count; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | *p++ = 0x80; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | /* Bytes of padding needed to make 64 bytes */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | count = 64 - 1 - count; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | /* Pad out to 56 mod 64 */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | if (count < 8) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | /* Two lots of padding: Pad the first block to 64 bytes */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | memset (p, 0, count); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | byteReverse (ctx->in, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | MD5Transform (ctx->buf, (uint32*) ctx->in); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | /* Now fill the next block with 56 bytes */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | memset (ctx->in, 0, 56); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | else |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | /* Pad block to 56 bytes */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | memset (p, 0, count - 8); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | byteReverse (ctx->in, 14); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | /* Append length in bits and transform */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | putu32 (ctx->bits[0], ctx->in + (14 * 4)); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | putu32 (ctx->bits[1], ctx->in + (15 * 4)); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | MD5Transform (ctx->buf, (uint32*) ctx->in); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | byteReverse ( (unsigned char*) ctx->buf, 4); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | memcpy (digest, ctx->buf, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | // memset (ctx, 0, sizeof (ctx)); /* In case it's sensitive */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | ctx = NULL; // GCC doesn't like the line above. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | /* The four core functions - F1 is optimized somewhat */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | /* #define F1(x, y, z) (x & y | ~x & z) */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | #define F1(x, y, z) (z ^ (x & (y ^ z))) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | #define F2(x, y, z) F1(z, x, y) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | #define F3(x, y, z) (x ^ y ^ z) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | #define F4(x, y, z) (y ^ (x | ~z)) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | /* This is the central step in the MD5 algorithm. */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | #define MD5STEP(f, w, x, y, z, data, s) \ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | * The core of the MD5 algorithm, this alters an existing MD5 hash to |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | * reflect the addition of 16 longwords of new data. MD5Update blocks |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | * the data and converts bytes into longwords for this routine. |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | */ |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | void MD5Transform (uint32 buf[4], uint32 const in[16]) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | uint32 a, b, c, d; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | a = buf[0]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | b = buf[1]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | c = buf[2]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | d = buf[3]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | MD5STEP (F1, a, b, c, d, in[0] + 0xd76aa478U, 7); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | MD5STEP (F1, d, a, b, c, in[1] + 0xe8c7b756U, 12); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | MD5STEP (F1, c, d, a, b, in[2] + 0x242070dbU, 17); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | MD5STEP (F1, b, c, d, a, in[3] + 0xc1bdceeeU, 22); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | MD5STEP (F1, a, b, c, d, in[4] + 0xf57c0fafU, 7); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | MD5STEP (F1, d, a, b, c, in[5] + 0x4787c62aU, 12); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | MD5STEP (F1, c, d, a, b, in[6] + 0xa8304613U, 17); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | MD5STEP (F1, b, c, d, a, in[7] + 0xfd469501U, 22); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | MD5STEP (F1, a, b, c, d, in[8] + 0x698098d8U, 7); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | MD5STEP (F1, d, a, b, c, in[9] + 0x8b44f7afU, 12); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | MD5STEP (F1, c, d, a, b, in[10] + 0xffff5bb1U, 17); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | MD5STEP (F1, b, c, d, a, in[11] + 0x895cd7beU, 22); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | MD5STEP (F1, a, b, c, d, in[12] + 0x6b901122U, 7); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | MD5STEP (F1, d, a, b, c, in[13] + 0xfd987193U, 12); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | MD5STEP (F1, c, d, a, b, in[14] + 0xa679438eU, 17); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | MD5STEP (F1, b, c, d, a, in[15] + 0x49b40821U, 22); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | MD5STEP (F2, a, b, c, d, in[1] + 0xf61e2562U, 5); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | MD5STEP (F2, d, a, b, c, in[6] + 0xc040b340U, 9); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | MD5STEP (F2, c, d, a, b, in[11] + 0x265e5a51U, 14); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | MD5STEP (F2, b, c, d, a, in[0] + 0xe9b6c7aaU, 20); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | MD5STEP (F2, a, b, c, d, in[5] + 0xd62f105dU, 5); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | MD5STEP (F2, d, a, b, c, in[10] + 0x02441453U, 9); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | MD5STEP (F2, c, d, a, b, in[15] + 0xd8a1e681U, 14); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | MD5STEP (F2, b, c, d, a, in[4] + 0xe7d3fbc8U, 20); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | MD5STEP (F2, a, b, c, d, in[9] + 0x21e1cde6U, 5); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | MD5STEP (F2, d, a, b, c, in[14] + 0xc33707d6U, 9); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | MD5STEP (F2, c, d, a, b, in[3] + 0xf4d50d87U, 14); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | MD5STEP (F2, b, c, d, a, in[8] + 0x455a14edU, 20); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | MD5STEP (F2, a, b, c, d, in[13] + 0xa9e3e905U, 5); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | MD5STEP (F2, d, a, b, c, in[2] + 0xfcefa3f8U, 9); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | MD5STEP (F2, c, d, a, b, in[7] + 0x676f02d9U, 14); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | MD5STEP (F2, b, c, d, a, in[12] + 0x8d2a4c8aU, 20); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | MD5STEP (F3, a, b, c, d, in[5] + 0xfffa3942U, 4); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | MD5STEP (F3, d, a, b, c, in[8] + 0x8771f681U, 11); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | MD5STEP (F3, c, d, a, b, in[11] + 0x6d9d6122U, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | MD5STEP (F3, b, c, d, a, in[14] + 0xfde5380cU, 23); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | MD5STEP (F3, a, b, c, d, in[1] + 0xa4beea44U, 4); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | MD5STEP (F3, d, a, b, c, in[4] + 0x4bdecfa9U, 11); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | MD5STEP (F3, c, d, a, b, in[7] + 0xf6bb4b60U, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | MD5STEP (F3, b, c, d, a, in[10] + 0xbebfbc70U, 23); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | MD5STEP (F3, a, b, c, d, in[13] + 0x289b7ec6U, 4); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | MD5STEP (F3, d, a, b, c, in[0] + 0xeaa127faU, 11); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | MD5STEP (F3, c, d, a, b, in[3] + 0xd4ef3085U, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | MD5STEP (F3, b, c, d, a, in[6] + 0x04881d05U, 23); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | MD5STEP (F3, a, b, c, d, in[9] + 0xd9d4d039U, 4); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | MD5STEP (F3, d, a, b, c, in[12] + 0xe6db99e5U, 11); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | MD5STEP (F3, c, d, a, b, in[15] + 0x1fa27cf8U, 16); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | MD5STEP (F3, b, c, d, a, in[2] + 0xc4ac5665U, 23); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | MD5STEP (F4, a, b, c, d, in[0] + 0xf4292244U, 6); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | MD5STEP (F4, d, a, b, c, in[7] + 0x432aff97U, 10); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | MD5STEP (F4, c, d, a, b, in[14] + 0xab9423a7U, 15); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | MD5STEP (F4, b, c, d, a, in[5] + 0xfc93a039U, 21); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | MD5STEP (F4, a, b, c, d, in[12] + 0x655b59c3U, 6); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | MD5STEP (F4, d, a, b, c, in[3] + 0x8f0ccc92U, 10); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | MD5STEP (F4, c, d, a, b, in[10] + 0xffeff47dU, 15); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | MD5STEP (F4, b, c, d, a, in[1] + 0x85845dd1U, 21); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | MD5STEP (F4, a, b, c, d, in[8] + 0x6fa87e4fU, 6); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | MD5STEP (F4, d, a, b, c, in[15] + 0xfe2ce6e0U, 10); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | MD5STEP (F4, c, d, a, b, in[6] + 0xa3014314U, 15); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | MD5STEP (F4, b, c, d, a, in[13] + 0x4e0811a1U, 21); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | MD5STEP (F4, a, b, c, d, in[4] + 0xf7537e82U, 6); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | MD5STEP (F4, d, a, b, c, in[11] + 0xbd3af235U, 10); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | MD5STEP (F4, c, d, a, b, in[2] + 0x2ad7d2bbU, 15); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
285 | MD5STEP (F4, b, c, d, a, in[9] + 0xeb86d391U, 21); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | buf[0] += a; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | buf[1] += b; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | buf[2] += c; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | buf[3] += d; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | void CalculateMD5 (const unsigned char* buffer, int length, char* checksum) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | int i; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | struct MD5Context m_md5; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | unsigned char signature[16]; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | MD5Init (&m_md5); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | MD5Update (&m_md5, buffer, length); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | MD5Final (signature, &m_md5); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | for (i = 0; i < 16; i++) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | { |
11 | 305 | sprintf (checksum + i * 2, "%02x", signature[i]); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
309 | std::string md5(const char *buffer) |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
310 | { |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
311 | char checksum[33]; |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
312 | CalculateMD5(reinterpret_cast<const unsigned char*>(buffer), strlen(buffer), checksum); |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
313 | checksum[sizeof checksum - 1] = '\0'; |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
314 | return {checksum}; |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
315 | } |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
88
diff
changeset
|
316 | |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
11
diff
changeset
|
317 | END_ZFC_NAMESPACE |