32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
39 #if (RIPEMD160_SUPPORT == ENABLED)
42 #define F(x, y, z) ((x) ^ (y) ^ (z))
43 #define G(x, y, z) (((x) & (y)) | (~(x) & (z)))
44 #define H(x, y, z) (((x) | ~(y)) ^ (z))
45 #define I(x, y, z) (((x) & (z)) | ((y) & ~(z)))
46 #define J(x, y, z) ((x) ^ ((y) | ~(z)))
48 #define FF(a, b, c, d, e, x, s) a += F(b, c, d) + (x), a = ROL32(a, s) + (e), c = ROL32(c, 10)
49 #define GG(a, b, c, d, e, x, s) a += G(b, c, d) + (x) + 0x5A827999, a = ROL32(a, s) + (e), c = ROL32(c, 10)
50 #define HH(a, b, c, d, e, x, s) a += H(b, c, d) + (x) + 0x6ED9EBA1, a = ROL32(a, s) + (e), c = ROL32(c, 10)
51 #define II(a, b, c, d, e, x, s) a += I(b, c, d) + (x) + 0x8F1BBCDC, a = ROL32(a, s) + (e), c = ROL32(c, 10)
52 #define JJ(a, b, c, d, e, x, s) a += J(b, c, d) + (x) + 0xA953FD4E, a = ROL32(a, s) + (e), c = ROL32(c, 10)
54 #define FFF(a, b, c, d, e, x, s) a += F(b, c, d) + (x), a = ROL32(a, s) + (e), c = ROL32(c, 10)
55 #define GGG(a, b, c, d, e, x, s) a += G(b, c, d) + (x) + 0x7A6D76E9, a = ROL32(a, s) + (e), c = ROL32(c, 10)
56 #define HHH(a, b, c, d, e, x, s) a += H(b, c, d) + (x) + 0x6D703EF3, a = ROL32(a, s) + (e), c = ROL32(c, 10)
57 #define III(a, b, c, d, e, x, s) a += I(b, c, d) + (x) + 0x5C4DD124, a = ROL32(a, s) + (e), c = ROL32(c, 10)
58 #define JJJ(a, b, c, d, e, x, s) a += J(b, c, d) + (x) + 0x50A28BE6, a = ROL32(a, s) + (e), c = ROL32(c, 10)
61 static const uint8_t padding[64] =
63 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
101 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
114 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
129 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
147 context->
h[0] = 0x67452301;
148 context->
h[1] = 0xEFCDAB89;
149 context->
h[2] = 0x98BADCFE;
150 context->
h[3] = 0x10325476;
151 context->
h[4] = 0xC3D2E1F0;
189 if(context->
size == 64)
216 if(context->
size < 56)
218 paddingSize = 56 - context->
size;
222 paddingSize = 64 + 56 - context->
size;
229 context->
x[14] =
htole32((uint32_t) totalSize);
230 context->
x[15] =
htole32((uint32_t) (totalSize >> 32));
236 for(i = 0; i < 5; i++)
259 uint32_t
aa= context->
h[0];
260 uint32_t bb = context->
h[1];
261 uint32_t cc = context->
h[2];
262 uint32_t dd = context->
h[3];
263 uint32_t ee = context->
h[4];
264 uint32_t aaa = context->
h[0];
265 uint32_t bbb = context->
h[1];
266 uint32_t ccc = context->
h[2];
267 uint32_t ddd = context->
h[3];
268 uint32_t eee = context->
h[4];
271 uint32_t *
x = context->
x;
274 for(i = 0; i < 16; i++)
280 FF(
aa, bb, cc, dd, ee,
x[0], 11);
281 FF(ee,
aa, bb, cc, dd,
x[1], 14);
282 FF(dd, ee,
aa, bb, cc,
x[2], 15);
283 FF(cc, dd, ee,
aa, bb,
x[3], 12);
284 FF(bb, cc, dd, ee,
aa,
x[4], 5);
285 FF(
aa, bb, cc, dd, ee,
x[5], 8);
286 FF(ee,
aa, bb, cc, dd,
x[6], 7);
287 FF(dd, ee,
aa, bb, cc,
x[7], 9);
288 FF(cc, dd, ee,
aa, bb,
x[8], 11);
289 FF(bb, cc, dd, ee,
aa,
x[9], 13);
290 FF(
aa, bb, cc, dd, ee,
x[10], 14);
291 FF(ee,
aa, bb, cc, dd,
x[11], 15);
292 FF(dd, ee,
aa, bb, cc,
x[12], 6);
293 FF(cc, dd, ee,
aa, bb,
x[13], 7);
294 FF(bb, cc, dd, ee,
aa,
x[14], 9);
295 FF(
aa, bb, cc, dd, ee,
x[15], 8);
298 GG(ee,
aa, bb, cc, dd,
x[7], 7);
299 GG(dd, ee,
aa, bb, cc,
x[4], 6);
300 GG(cc, dd, ee,
aa, bb,
x[13], 8);
301 GG(bb, cc, dd, ee,
aa,
x[1], 13);
302 GG(
aa, bb, cc, dd, ee,
x[10], 11);
303 GG(ee,
aa, bb, cc, dd,
x[6], 9);
304 GG(dd, ee,
aa, bb, cc,
x[15], 7);
305 GG(cc, dd, ee,
aa, bb,
x[3], 15);
306 GG(bb, cc, dd, ee,
aa,
x[12], 7);
307 GG(
aa, bb, cc, dd, ee,
x[0], 12);
308 GG(ee,
aa, bb, cc, dd,
x[9], 15);
309 GG(dd, ee,
aa, bb, cc,
x[5], 9);
310 GG(cc, dd, ee,
aa, bb,
x[2], 11);
311 GG(bb, cc, dd, ee,
aa,
x[14], 7);
312 GG(
aa, bb, cc, dd, ee,
x[11], 13);
313 GG(ee,
aa, bb, cc, dd,
x[8], 12);
316 HH(dd, ee,
aa, bb, cc,
x[3], 11);
317 HH(cc, dd, ee,
aa, bb,
x[10], 13);
318 HH(bb, cc, dd, ee,
aa,
x[14], 6);
319 HH(
aa, bb, cc, dd, ee,
x[4], 7);
320 HH(ee,
aa, bb, cc, dd,
x[9], 14);
321 HH(dd, ee,
aa, bb, cc,
x[15], 9);
322 HH(cc, dd, ee,
aa, bb,
x[8], 13);
323 HH(bb, cc, dd, ee,
aa,
x[1], 15);
324 HH(
aa, bb, cc, dd, ee,
x[2], 14);
325 HH(ee,
aa, bb, cc, dd,
x[7], 8);
326 HH(dd, ee,
aa, bb, cc,
x[0], 13);
327 HH(cc, dd, ee,
aa, bb,
x[6], 6);
328 HH(bb, cc, dd, ee,
aa,
x[13], 5);
329 HH(
aa, bb, cc, dd, ee,
x[11], 12);
330 HH(ee,
aa, bb, cc, dd,
x[5], 7);
331 HH(dd, ee,
aa, bb, cc,
x[12], 5);
334 II(cc, dd, ee,
aa, bb,
x[1], 11);
335 II(bb, cc, dd, ee,
aa,
x[9], 12);
336 II(
aa, bb, cc, dd, ee,
x[11], 14);
337 II(ee,
aa, bb, cc, dd,
x[10], 15);
338 II(dd, ee,
aa, bb, cc,
x[0], 14);
339 II(cc, dd, ee,
aa, bb,
x[8], 15);
340 II(bb, cc, dd, ee,
aa,
x[12], 9);
341 II(
aa, bb, cc, dd, ee,
x[4], 8);
342 II(ee,
aa, bb, cc, dd,
x[13], 9);
343 II(dd, ee,
aa, bb, cc,
x[3], 14);
344 II(cc, dd, ee,
aa, bb,
x[7], 5);
345 II(bb, cc, dd, ee,
aa,
x[15], 6);
346 II(
aa, bb, cc, dd, ee,
x[14], 8);
347 II(ee,
aa, bb, cc, dd,
x[5], 6);
348 II(dd, ee,
aa, bb, cc,
x[6], 5);
349 II(cc, dd, ee,
aa, bb,
x[2], 12);
352 JJ(bb, cc, dd, ee,
aa,
x[4], 9);
353 JJ(
aa, bb, cc, dd, ee,
x[0], 15);
354 JJ(ee,
aa, bb, cc, dd,
x[5], 5);
355 JJ(dd, ee,
aa, bb, cc,
x[9], 11);
356 JJ(cc, dd, ee,
aa, bb,
x[7], 6);
357 JJ(bb, cc, dd, ee,
aa,
x[12], 8);
358 JJ(
aa, bb, cc, dd, ee,
x[2], 13);
359 JJ(ee,
aa, bb, cc, dd,
x[10], 12);
360 JJ(dd, ee,
aa, bb, cc,
x[14], 5);
361 JJ(cc, dd, ee,
aa, bb,
x[1], 12);
362 JJ(bb, cc, dd, ee,
aa,
x[3], 13);
363 JJ(
aa, bb, cc, dd, ee,
x[8], 14);
364 JJ(ee,
aa, bb, cc, dd,
x[11], 11);
365 JJ(dd, ee,
aa, bb, cc,
x[6], 8);
366 JJ(cc, dd, ee,
aa, bb,
x[15], 5);
367 JJ(bb, cc, dd, ee,
aa,
x[13], 6);
370 JJJ(aaa, bbb, ccc, ddd, eee,
x[5], 8);
371 JJJ(eee, aaa, bbb, ccc, ddd,
x[14], 9);
372 JJJ(ddd, eee, aaa, bbb, ccc,
x[7], 9);
373 JJJ(ccc, ddd, eee, aaa, bbb,
x[0], 11);
374 JJJ(bbb, ccc, ddd, eee, aaa,
x[9], 13);
375 JJJ(aaa, bbb, ccc, ddd, eee,
x[2], 15);
376 JJJ(eee, aaa, bbb, ccc, ddd,
x[11], 15);
377 JJJ(ddd, eee, aaa, bbb, ccc,
x[4], 5);
378 JJJ(ccc, ddd, eee, aaa, bbb,
x[13], 7);
379 JJJ(bbb, ccc, ddd, eee, aaa,
x[6], 7);
380 JJJ(aaa, bbb, ccc, ddd, eee,
x[15], 8);
381 JJJ(eee, aaa, bbb, ccc, ddd,
x[8], 11);
382 JJJ(ddd, eee, aaa, bbb, ccc,
x[1], 14);
383 JJJ(ccc, ddd, eee, aaa, bbb,
x[10], 14);
384 JJJ(bbb, ccc, ddd, eee, aaa,
x[3], 12);
385 JJJ(aaa, bbb, ccc, ddd, eee,
x[12], 6);
388 III(eee, aaa, bbb, ccc, ddd,
x[6], 9);
389 III(ddd, eee, aaa, bbb, ccc,
x[11], 13);
390 III(ccc, ddd, eee, aaa, bbb,
x[3], 15);
391 III(bbb, ccc, ddd, eee, aaa,
x[7], 7);
392 III(aaa, bbb, ccc, ddd, eee,
x[0], 12);
393 III(eee, aaa, bbb, ccc, ddd,
x[13], 8);
394 III(ddd, eee, aaa, bbb, ccc,
x[5], 9);
395 III(ccc, ddd, eee, aaa, bbb,
x[10], 11);
396 III(bbb, ccc, ddd, eee, aaa,
x[14], 7);
397 III(aaa, bbb, ccc, ddd, eee,
x[15], 7);
398 III(eee, aaa, bbb, ccc, ddd,
x[8], 12);
399 III(ddd, eee, aaa, bbb, ccc,
x[12], 7);
400 III(ccc, ddd, eee, aaa, bbb,
x[4], 6);
401 III(bbb, ccc, ddd, eee, aaa,
x[9], 15);
402 III(aaa, bbb, ccc, ddd, eee,
x[1], 13);
403 III(eee, aaa, bbb, ccc, ddd,
x[2], 11);
406 HHH(ddd, eee, aaa, bbb, ccc,
x[15], 9);
407 HHH(ccc, ddd, eee, aaa, bbb,
x[5], 7);
408 HHH(bbb, ccc, ddd, eee, aaa,
x[1], 15);
409 HHH(aaa, bbb, ccc, ddd, eee,
x[3], 11);
410 HHH(eee, aaa, bbb, ccc, ddd,
x[7], 8);
411 HHH(ddd, eee, aaa, bbb, ccc,
x[14], 6);
412 HHH(ccc, ddd, eee, aaa, bbb,
x[6], 6);
413 HHH(bbb, ccc, ddd, eee, aaa,
x[9], 14);
414 HHH(aaa, bbb, ccc, ddd, eee,
x[11], 12);
415 HHH(eee, aaa, bbb, ccc, ddd,
x[8], 13);
416 HHH(ddd, eee, aaa, bbb, ccc,
x[12], 5);
417 HHH(ccc, ddd, eee, aaa, bbb,
x[2], 14);
418 HHH(bbb, ccc, ddd, eee, aaa,
x[10], 13);
419 HHH(aaa, bbb, ccc, ddd, eee,
x[0], 13);
420 HHH(eee, aaa, bbb, ccc, ddd,
x[4], 7);
421 HHH(ddd, eee, aaa, bbb, ccc,
x[13], 5);
424 GGG(ccc, ddd, eee, aaa, bbb,
x[8], 15);
425 GGG(bbb, ccc, ddd, eee, aaa,
x[6], 5);
426 GGG(aaa, bbb, ccc, ddd, eee,
x[4], 8);
427 GGG(eee, aaa, bbb, ccc, ddd,
x[1], 11);
428 GGG(ddd, eee, aaa, bbb, ccc,
x[3], 14);
429 GGG(ccc, ddd, eee, aaa, bbb,
x[11], 14);
430 GGG(bbb, ccc, ddd, eee, aaa,
x[15], 6);
431 GGG(aaa, bbb, ccc, ddd, eee,
x[0], 14);
432 GGG(eee, aaa, bbb, ccc, ddd,
x[5], 6);
433 GGG(ddd, eee, aaa, bbb, ccc,
x[12], 9);
434 GGG(ccc, ddd, eee, aaa, bbb,
x[2], 12);
435 GGG(bbb, ccc, ddd, eee, aaa,
x[13], 9);
436 GGG(aaa, bbb, ccc, ddd, eee,
x[9], 12);
437 GGG(eee, aaa, bbb, ccc, ddd,
x[7], 5);
438 GGG(ddd, eee, aaa, bbb, ccc,
x[10], 15);
439 GGG(ccc, ddd, eee, aaa, bbb,
x[14], 8);
442 FFF(bbb, ccc, ddd, eee, aaa,
x[12], 8);
443 FFF(aaa, bbb, ccc, ddd, eee,
x[15], 5);
444 FFF(eee, aaa, bbb, ccc, ddd,
x[10], 12);
445 FFF(ddd, eee, aaa, bbb, ccc,
x[4], 9);
446 FFF(ccc, ddd, eee, aaa, bbb,
x[1], 12);
447 FFF(bbb, ccc, ddd, eee, aaa,
x[5], 5);
448 FFF(aaa, bbb, ccc, ddd, eee,
x[8], 14);
449 FFF(eee, aaa, bbb, ccc, ddd,
x[7], 6);
450 FFF(ddd, eee, aaa, bbb, ccc,
x[6], 8);
451 FFF(ccc, ddd, eee, aaa, bbb,
x[2], 13);
452 FFF(bbb, ccc, ddd, eee, aaa,
x[13], 6);
453 FFF(aaa, bbb, ccc, ddd, eee,
x[14], 5);
454 FFF(eee, aaa, bbb, ccc, ddd,
x[0], 15);
455 FFF(ddd, eee, aaa, bbb, ccc,
x[3], 13);
456 FFF(ccc, ddd, eee, aaa, bbb,
x[9], 11);
457 FFF(bbb, ccc, ddd, eee, aaa,
x[11], 11);
460 ddd = context->
h[1] + cc + ddd;
461 context->
h[1] = context->
h[2] + dd + eee;
462 context->
h[2] = context->
h[3] + ee + aaa;
463 context->
h[3] = context->
h[4] +
aa + bbb;
464 context->
h[4] = context->
h[0] + bb + ccc;