ObjFW  Diff

Differences From Artifact [2ed1eeca9f]:

To Artifact [233d143bc4]:


29
30
31
32
33
34
35













36
37
38
39
40
41
42
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55







+
+
+
+
+
+
+
+
+
+
+
+
+







#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))

/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \
	(w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)

#ifdef OF_BIG_ENDIAN
static OF_INLINE void
BSWAP32_VEC_IF_BE(uint32_t *buffer, size_t length)
{
	while (length--) {
		*buffer = OF_BSWAP32(*buffer);
		buffer++;
	}
}
#else
# define BSWAP32_VEC_IF_BE(buffer, length)
#endif

static void
md5_transform(uint32_t buffer[4], const uint32_t in[16])
{
	register uint32_t a, b, c, d;

	a = buffer[0];
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210







-
+









-
+








		if (length < t) {
			memcpy(p, buffer_, length);
			return;
		}

		memcpy(p, buffer_, t);
		of_bswap32_vec_if_be(in.u32, 16);
		BSWAP32_VEC_IF_BE(in.u32, 16);
		md5_transform(buffer, in.u32);

		buffer_ += t;
		length -= t;
	}

	/* Process data in 64-byte chunks */
	while (length >= 64) {
		memcpy(in.u8, buffer_, 64);
		of_bswap32_vec_if_be(in.u32, 16);
		BSWAP32_VEC_IF_BE(in.u32, 16);
		md5_transform(buffer, in.u32);

		buffer_ += 64;
		length -= 64;
	}

	/* Handle any remaining bytes of data. */
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242

243
244
245
246
247
248
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254

255
256
257
258
259
260
261







-
+








-
+






-
+






	/* Bytes of padding needed to make 64 bytes */
	count = 64 - 1 - count;

	/* Pad out to 56 mod 64 */
	if (count < 8) {
		/* Two lots of padding: Pad the first block to 64 bytes */
		memset(p, 0, count);
		of_bswap32_vec_if_be(in.u32, 16);
		BSWAP32_VEC_IF_BE(in.u32, 16);
		md5_transform(buffer, in.u32);

		/* Now fill the next block with 56 bytes */
		memset(in.u8, 0, 56);
	} else {
		/* Pad block to 56 bytes */
		memset(p, 0, count - 8);
	}
	of_bswap32_vec_if_be(in.u32, 14);
	BSWAP32_VEC_IF_BE(in.u32, 14);

	/* Append length in bits and transform */
	in.u32[14] = bits[0];
	in.u32[15] = bits[1];

	md5_transform(buffer, in.u32);
	of_bswap32_vec_if_be(buffer, 4);
	BSWAP32_VEC_IF_BE(buffer, 4);

	calculated = YES;

	return (uint8_t*)buffer;
}
@end