ObjFW  Diff

Differences From Artifact [5bb7027c8f]:

To Artifact [e568bcc89c]:


17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34




35
36
37
38
39
40
41
#import "OFHashes.h"

#ifdef BIG_ENDIAN
inline void
bswap(uint8_t *buf, size_t len)
{
	uint32_t t;
	do {
		t = (uint32_t)((uint32_t)buf[3] << 8 | buf[2]) << 16 |
		    ((uint32_t)buf[1] << 8 | buf[0]);
		*(uint32_t*)buf = t;
		buf += 4;
	} while(--len);

}
#else
#define bswap(buf, len)
#endif





/* The four MD5 core functions - F1 is optimized somewhat */
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#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. */







|




<
>





>
>
>
>







17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "OFHashes.h"

#ifdef BIG_ENDIAN
inline void
bswap(uint8_t *buf, size_t len)
{
	uint32_t t;
	while (len--) {
		t = (uint32_t)((uint32_t)buf[3] << 8 | buf[2]) << 16 |
		    ((uint32_t)buf[1] << 8 | buf[0]);
		*(uint32_t*)buf = t;
		buf += 4;

	}
}
#else
#define bswap(buf, len)
#endif

/*******
 * MD5 *
 *******/

/* The four MD5 core functions - F1 is optimized somewhat */
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#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. */
133
134
135
136
137
138
139


140
141
142
143
144
145
146
147
148





149
150
151
152
153
154
155
		buf[0] = 0x67452301;
		buf[1] = 0xEFCDAB89;
		buf[2] = 0x98BADCFE;
		buf[3] = 0x10325476;

		bits[0] = 0;
		bits[1] = 0;


	}

	return self;
}

- (void)updateWithBuffer: (const uint8_t*)buffer
		  ofSize: (size_t)size
{
	uint32_t t;






	/* Update bitcount */
	t = bits[0];
	if ((bits[0] = t + ((uint32_t)size << 3)) < t)
		bits[1]++;		/* Carry from low to high */
	bits[1] += size >> 29;








>
>









>
>
>
>
>







137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
		buf[0] = 0x67452301;
		buf[1] = 0xEFCDAB89;
		buf[2] = 0x98BADCFE;
		buf[3] = 0x10325476;

		bits[0] = 0;
		bits[1] = 0;

		calculated = NO;
	}

	return self;
}

- (void)updateWithBuffer: (const uint8_t*)buffer
		  ofSize: (size_t)size
{
	uint32_t t;

	if (calculated)
		return;
	if (size == 0)
		return;

	/* Update bitcount */
	t = bits[0];
	if ((bits[0] = t + ((uint32_t)size << 3)) < t)
		bits[1]++;		/* Carry from low to high */
	bits[1] += size >> 29;

185
186
187
188
189
190
191



192
193
194
195
196
197
198
}

- (uint8_t*)digest
{
	uint8_t	*p;
	size_t	count;




	/* Compute number of bytes mod 64 */
	count = (bits[0] >> 3) & 0x3F;

	/*
	 * Set the first char of padding to 0x80. This is safe since there is
	 * always at least one byte free
	 */







>
>
>







196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
}

- (uint8_t*)digest
{
	uint8_t	*p;
	size_t	count;

	if (calculated)
		return (uint8_t*)buf;

	/* Compute number of bytes mod 64 */
	count = (bits[0] >> 3) & 0x3F;

	/*
	 * Set the first char of padding to 0x80. This is safe since there is
	 * always at least one byte free
	 */
219
220
221
222
223
224
225


226
227
228
229

	/* Append length in bits and transform */
	((uint32_t*)in)[14] = bits[0];
	((uint32_t*)in)[15] = bits[1];

	md5_transform(buf, (uint32_t*)in);
	bswap((uint8_t*)buf, 4);



	return (uint8_t*)buf;
}
@end







>
>




233
234
235
236
237
238
239
240
241
242
243
244
245

	/* Append length in bits and transform */
	((uint32_t*)in)[14] = bits[0];
	((uint32_t*)in)[15] = bits[1];

	md5_transform(buf, (uint32_t*)in);
	bswap((uint8_t*)buf, 4);

	calculated = YES;

	return (uint8_t*)buf;
}
@end