annotate src/lib/md5.c @ 9490:fd84592e817b HEAD

dovecot-example.conf: Updated dict comments.
author Timo Sirainen <tss@iki.fi>
date Mon, 23 Nov 2009 13:08:47 -0500
parents 0448f2fa8349
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /*
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
2 * This is an OpenSSL-compatible implementation of the RSA Data Security,
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
3 * Inc. MD5 Message-Digest Algorithm.
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
4 *
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
5 * Written by Solar Designer <solar@openwall.com> in 2001, and placed in
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
6 * the public domain. There's absolutely no warranty.
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 *
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
8 * This differs from Colin Plumb's older public domain implementation in
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
9 * that no 32-bit integer data type is required, there's no compile-time
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
10 * endianness configuration, and the function prototypes match OpenSSL's.
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
11 * The primary goals are portability and ease of use.
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 *
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
13 * This implementation is meant to be fast, but not as fast as possible.
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
14 * Some known optimizations are not included to reduce source code size
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
15 * and avoid compile-time configuration.
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
18 #include "lib.h"
2337
beefcc4249ef md5_final() didn't properly clear the whole MD5 context. Also changed to use
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
19 #include "safe-memset.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #include "md5.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 /*
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
23 * The basic MD5 functions.
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 *
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
25 * F is optimized compared to its RFC 1321 definition just like in Colin
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
26 * Plumb's implementation.
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
27 */
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
28 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
29 #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
30 #define H(x, y, z) ((x) ^ (y) ^ (z))
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
31 #define I(x, y, z) ((y) ^ ((x) | ~(z)))
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
33 /*
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
34 * The MD5 transformation for all four rounds.
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
35 */
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
36 #define STEP(f, a, b, c, d, x, t, s) \
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
37 (a) += f((b), (c), (d)) + (x) + (t); \
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
38 (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
39 (a) += (b);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
41 /*
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
42 * SET reads 4 input bytes in little-endian byte order and stores them
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
43 * in a properly aligned word in host byte order.
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
44 *
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
45 * The check for little-endian architectures which tolerate unaligned
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
46 * memory accesses is just an optimization. Nothing will break if it
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
47 * doesn't work.
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
48 */
4380
7eef9a1c51c4 MD4 was broken with 64bit systems. Added a few x86-64 optimizations. Patch
Timo Sirainen <tss@iki.fi>
parents: 2337
diff changeset
49 #if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
50 #define SET(n) \
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
51 (*(const uint_fast32_t *)&ptr[(n) * 4])
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
52 #define GET(n) \
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
53 SET(n)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
54 #else
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
55 #define SET(n) \
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
56 (ctx->block[(n)] = \
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
57 (uint_fast32_t)ptr[(n) * 4] | \
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
58 ((uint_fast32_t)ptr[(n) * 4 + 1] << 8) | \
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
59 ((uint_fast32_t)ptr[(n) * 4 + 2] << 16) | \
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
60 ((uint_fast32_t)ptr[(n) * 4 + 3] << 24))
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
61 #define GET(n) \
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
62 (ctx->block[(n)])
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
63 #endif
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 /*
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
66 * This processes one or more 64-byte data blocks, but does NOT update
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
67 * the bit counters. There're no alignment requirements.
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
69 static const void *body(struct md5_context *ctx, const void *data, size_t size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 {
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
71 const unsigned char *ptr;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
72 uint_fast32_t a, b, c, d;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
73 uint_fast32_t saved_a, saved_b, saved_c, saved_d;
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
74
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
75 ptr = data;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
76
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
77 a = ctx->a;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
78 b = ctx->b;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
79 c = ctx->c;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
80 d = ctx->d;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
81
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
82 do {
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
83 saved_a = a;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
84 saved_b = b;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
85 saved_c = c;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
86 saved_d = d;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
87
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
88 /* Round 1 */
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
89 STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
90 STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
91 STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
92 STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
93 STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
94 STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
95 STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
96 STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
97 STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
98 STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
99 STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
100 STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
101 STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
102 STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
103 STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
104 STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
105
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
106 /* Round 2 */
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
107 STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
108 STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
109 STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
110 STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
111 STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
112 STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
113 STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
114 STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
115 STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
116 STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
117 STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
118 STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
119 STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
120 STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
121 STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
122 STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
123
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
124 /* Round 3 */
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
125 STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
126 STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
127 STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
128 STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
129 STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
130 STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
131 STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
132 STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
133 STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
134 STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
135 STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
136 STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
137 STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
138 STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
139 STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
140 STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
141
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
142 /* Round 4 */
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
143 STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
144 STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
145 STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
146 STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
147 STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
148 STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
149 STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
150 STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
151 STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
152 STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
153 STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
154 STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
155 STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
156 STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
157 STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
158 STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
159
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
160 a += saved_a;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
161 b += saved_b;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
162 c += saved_c;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
163 d += saved_d;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
164
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
165 ptr += 64;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
166 } while (size -= 64);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
167
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
168 ctx->a = a;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
169 ctx->b = b;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
170 ctx->c = c;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
171 ctx->d = d;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
172
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
173 return ptr;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
176 void md5_init(struct md5_context *ctx)
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
177 {
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
178 ctx->a = 0x67452301;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
179 ctx->b = 0xefcdab89;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
180 ctx->c = 0x98badcfe;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
181 ctx->d = 0x10325476;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
183 ctx->lo = 0;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
184 ctx->hi = 0;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
185 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
187 void md5_update(struct md5_context *ctx, const void *data, size_t size)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 {
805
5ac361acb316 Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents: 579
diff changeset
189 /* @UNSAFE */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
190 uint_fast32_t saved_lo;
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
191 unsigned long used, free;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
192
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
193 saved_lo = ctx->lo;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
194 if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
195 ctx->hi++;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
196 ctx->hi += size >> 29;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
197
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
198 used = saved_lo & 0x3f;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
199
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
200 if (used) {
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
201 free = 64 - used;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
202
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
203 if (size < free) {
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
204 memcpy(&ctx->buffer[used], data, size);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
205 return;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
206 }
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
207
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
208 memcpy(&ctx->buffer[used], data, free);
579
e524da896d92 Several minor fixes: signess, casting away const, missing static, etc.
Timo Sirainen <tss@iki.fi>
parents: 346
diff changeset
209 data = (const unsigned char *) data + free;
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
210 size -= free;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
211 body(ctx, ctx->buffer, 64);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
212 }
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
213
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
214 if (size >= 64) {
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
215 data = body(ctx, data, size & ~(unsigned long)0x3f);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
216 size &= 0x3f;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
217 }
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
218
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
219 memcpy(ctx->buffer, data, size);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221
4642
0448f2fa8349 Added MD5_RESULTLEN macro.
Timo Sirainen <tss@iki.fi>
parents: 4380
diff changeset
222 void md5_final(struct md5_context *ctx, unsigned char result[MD5_RESULTLEN])
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
223 {
805
5ac361acb316 Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents: 579
diff changeset
224 /* @UNSAFE */
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
225 unsigned long used, free;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
227 used = ctx->lo & 0x3f;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
228
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
229 ctx->buffer[used++] = 0x80;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
230
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
231 free = 64 - used;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
232
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
233 if (free < 8) {
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
234 memset(&ctx->buffer[used], 0, free);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
235 body(ctx, ctx->buffer, 64);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
236 used = 0;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
237 free = 64;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
238 }
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
239
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
240 memset(&ctx->buffer[used], 0, free - 8);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
241
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
242 ctx->lo <<= 3;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
243 ctx->buffer[56] = ctx->lo;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
244 ctx->buffer[57] = ctx->lo >> 8;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
245 ctx->buffer[58] = ctx->lo >> 16;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
246 ctx->buffer[59] = ctx->lo >> 24;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
247 ctx->buffer[60] = ctx->hi;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
248 ctx->buffer[61] = ctx->hi >> 8;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
249 ctx->buffer[62] = ctx->hi >> 16;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
250 ctx->buffer[63] = ctx->hi >> 24;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
251
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
252 body(ctx, ctx->buffer, 64);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
253
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
254 result[0] = ctx->a;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
255 result[1] = ctx->a >> 8;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
256 result[2] = ctx->a >> 16;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
257 result[3] = ctx->a >> 24;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
258 result[4] = ctx->b;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
259 result[5] = ctx->b >> 8;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
260 result[6] = ctx->b >> 16;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
261 result[7] = ctx->b >> 24;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
262 result[8] = ctx->c;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
263 result[9] = ctx->c >> 8;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
264 result[10] = ctx->c >> 16;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
265 result[11] = ctx->c >> 24;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
266 result[12] = ctx->d;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
267 result[13] = ctx->d >> 8;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
268 result[14] = ctx->d >> 16;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
269 result[15] = ctx->d >> 24;
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
270
2337
beefcc4249ef md5_final() didn't properly clear the whole MD5 context. Also changed to use
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
271 safe_memset(ctx, 0, sizeof(*ctx));
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
272 }
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
273
4642
0448f2fa8349 Added MD5_RESULTLEN macro.
Timo Sirainen <tss@iki.fi>
parents: 4380
diff changeset
274 void md5_get_digest(const void *data, size_t size,
0448f2fa8349 Added MD5_RESULTLEN macro.
Timo Sirainen <tss@iki.fi>
parents: 4380
diff changeset
275 unsigned char result[MD5_RESULTLEN])
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
276 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
277 struct md5_context ctx;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278
21
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
279 md5_init(&ctx);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
280 md5_update(&ctx, data, size);
163675942b83 Replaced the MD5 implementation with Solar Designer's.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
281 md5_final(&ctx, result);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 }