sources/md5.cpp

Tue, 26 May 2015 18:19:27 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 26 May 2015 18:19:27 +0300
changeset 82
895088452014
parent 11
cffa2777d917
child 88
08ccaf26cffd
permissions
-rw-r--r--

Clarify the controls footnote

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

mercurial