Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
39 #if (RIPEMD128_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)))
47 #define FF(a, b, c, d, x, s) a += F(b, c, d) + (x), a = ROL32(a, s)
48 #define GG(a, b, c, d, x, s) a += G(b, c, d) + (x) + 0x5A827999, a = ROL32(a, s)
49 #define HH(a, b, c, d, x, s) a += H(b, c, d) + (x) + 0x6ED9EBA1, a = ROL32(a, s)
50 #define II(a, b, c, d, x, s) a += I(b, c, d) + (x) + 0x8F1BBCDC, a = ROL32(a, s)
52 #define FFF(a, b, c, d, x, s) a += F(b, c, d) + (x), a = ROL32(a, s)
53 #define GGG(a, b, c, d, x, s) a += G(b, c, d) + (x) + 0x6D703EF3, a = ROL32(a, s)
54 #define HHH(a, b, c, d, x, s) a += H(b, c, d) + (x) + 0x5C4DD124, a = ROL32(a, s)
55 #define III(a, b, c, d, x, s) a += I(b, c, d) + (x) + 0x50A28BE6, a = ROL32(a, s)
58 static const uint8_t padding[64] =
60 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
98 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
111 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
126 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
144 context->
h[0] = 0x67452301;
145 context->
h[1] = 0xEFCDAB89;
146 context->
h[2] = 0x98BADCFE;
147 context->
h[3] = 0x10325476;
185 if(context->
size == 64)
212 if(context->
size < 56)
214 paddingSize = 56 - context->
size;
218 paddingSize = 64 + 56 - context->
size;
225 context->
x[14] =
htole32((uint32_t) totalSize);
226 context->
x[15] =
htole32((uint32_t) (totalSize >> 32));
232 for(i = 0; i < 4; i++)
255 uint32_t
aa= context->
h[0];
256 uint32_t bb = context->
h[1];
257 uint32_t cc = context->
h[2];
258 uint32_t dd = context->
h[3];
259 uint32_t aaa = context->
h[0];
260 uint32_t bbb = context->
h[1];
261 uint32_t ccc = context->
h[2];
262 uint32_t ddd = context->
h[3];
265 uint32_t *
x = context->
x;
268 for(i = 0; i < 16; i++)
274 FF(
aa, bb, cc, dd,
x[0], 11);
275 FF(dd,
aa, bb, cc,
x[1], 14);
276 FF(cc, dd,
aa, bb,
x[2], 15);
277 FF(bb, cc, dd,
aa,
x[3], 12);
278 FF(
aa, bb, cc, dd,
x[4], 5);
279 FF(dd,
aa, bb, cc,
x[5], 8);
280 FF(cc, dd,
aa, bb,
x[6], 7);
281 FF(bb, cc, dd,
aa,
x[7], 9);
282 FF(
aa, bb, cc, dd,
x[8], 11);
283 FF(dd,
aa, bb, cc,
x[9], 13);
284 FF(cc, dd,
aa, bb,
x[10], 14);
285 FF(bb, cc, dd,
aa,
x[11], 15);
286 FF(
aa, bb, cc, dd,
x[12], 6);
287 FF(dd,
aa, bb, cc,
x[13], 7);
288 FF(cc, dd,
aa, bb,
x[14], 9);
289 FF(bb, cc, dd,
aa,
x[15], 8);
292 GG(
aa, bb, cc, dd,
x[7], 7);
293 GG(dd,
aa, bb, cc,
x[4], 6);
294 GG(cc, dd,
aa, bb,
x[13], 8);
295 GG(bb, cc, dd,
aa,
x[1], 13);
296 GG(
aa, bb, cc, dd,
x[10], 11);
297 GG(dd,
aa, bb, cc,
x[6], 9);
298 GG(cc, dd,
aa, bb,
x[15], 7);
299 GG(bb, cc, dd,
aa,
x[3], 15);
300 GG(
aa, bb, cc, dd,
x[12], 7);
301 GG(dd,
aa, bb, cc,
x[0], 12);
302 GG(cc, dd,
aa, bb,
x[9], 15);
303 GG(bb, cc, dd,
aa,
x[5], 9);
304 GG(
aa, bb, cc, dd,
x[2], 11);
305 GG(dd,
aa, bb, cc,
x[14], 7);
306 GG(cc, dd,
aa, bb,
x[11], 13);
307 GG(bb, cc, dd,
aa,
x[8], 12);
310 HH(
aa, bb, cc, dd,
x[3], 11);
311 HH(dd,
aa, bb, cc,
x[10], 13);
312 HH(cc, dd,
aa, bb,
x[14], 6);
313 HH(bb, cc, dd,
aa,
x[4], 7);
314 HH(
aa, bb, cc, dd,
x[9], 14);
315 HH(dd,
aa, bb, cc,
x[15], 9);
316 HH(cc, dd,
aa, bb,
x[8], 13);
317 HH(bb, cc, dd,
aa,
x[1], 15);
318 HH(
aa, bb, cc, dd,
x[2], 14);
319 HH(dd,
aa, bb, cc,
x[7], 8);
320 HH(cc, dd,
aa, bb,
x[0], 13);
321 HH(bb, cc, dd,
aa,
x[6], 6);
322 HH(
aa, bb, cc, dd,
x[13], 5);
323 HH(dd,
aa, bb, cc,
x[11], 12);
324 HH(cc, dd,
aa, bb,
x[5], 7);
325 HH(bb, cc, dd,
aa,
x[12], 5);
328 II(
aa, bb, cc, dd,
x[1], 11);
329 II(dd,
aa, bb, cc,
x[9], 12);
330 II(cc, dd,
aa, bb,
x[11], 14);
331 II(bb, cc, dd,
aa,
x[10], 15);
332 II(
aa, bb, cc, dd,
x[0], 14);
333 II(dd,
aa, bb, cc,
x[8], 15);
334 II(cc, dd,
aa, bb,
x[12], 9);
335 II(bb, cc, dd,
aa,
x[4], 8);
336 II(
aa, bb, cc, dd,
x[13], 9);
337 II(dd,
aa, bb, cc,
x[3], 14);
338 II(cc, dd,
aa, bb,
x[7], 5);
339 II(bb, cc, dd,
aa,
x[15], 6);
340 II(
aa, bb, cc, dd,
x[14], 8);
341 II(dd,
aa, bb, cc,
x[5], 6);
342 II(cc, dd,
aa, bb,
x[6], 5);
343 II(bb, cc, dd,
aa,
x[2], 12);
346 III(aaa, bbb, ccc, ddd,
x[5], 8);
347 III(ddd, aaa, bbb, ccc,
x[14], 9);
348 III(ccc, ddd, aaa, bbb,
x[7], 9);
349 III(bbb, ccc, ddd, aaa,
x[0], 11);
350 III(aaa, bbb, ccc, ddd,
x[9], 13);
351 III(ddd, aaa, bbb, ccc,
x[2], 15);
352 III(ccc, ddd, aaa, bbb,
x[11], 15);
353 III(bbb, ccc, ddd, aaa,
x[4], 5);
354 III(aaa, bbb, ccc, ddd,
x[13], 7);
355 III(ddd, aaa, bbb, ccc,
x[6], 7);
356 III(ccc, ddd, aaa, bbb,
x[15], 8);
357 III(bbb, ccc, ddd, aaa,
x[8], 11);
358 III(aaa, bbb, ccc, ddd,
x[1], 14);
359 III(ddd, aaa, bbb, ccc,
x[10], 14);
360 III(ccc, ddd, aaa, bbb,
x[3], 12);
361 III(bbb, ccc, ddd, aaa,
x[12], 6);
364 HHH(aaa, bbb, ccc, ddd,
x[6], 9);
365 HHH(ddd, aaa, bbb, ccc,
x[11], 13);
366 HHH(ccc, ddd, aaa, bbb,
x[3], 15);
367 HHH(bbb, ccc, ddd, aaa,
x[7], 7);
368 HHH(aaa, bbb, ccc, ddd,
x[0], 12);
369 HHH(ddd, aaa, bbb, ccc,
x[13], 8);
370 HHH(ccc, ddd, aaa, bbb,
x[5], 9);
371 HHH(bbb, ccc, ddd, aaa,
x[10], 11);
372 HHH(aaa, bbb, ccc, ddd,
x[14], 7);
373 HHH(ddd, aaa, bbb, ccc,
x[15], 7);
374 HHH(ccc, ddd, aaa, bbb,
x[8], 12);
375 HHH(bbb, ccc, ddd, aaa,
x[12], 7);
376 HHH(aaa, bbb, ccc, ddd,
x[4], 6);
377 HHH(ddd, aaa, bbb, ccc,
x[9], 15);
378 HHH(ccc, ddd, aaa, bbb,
x[1], 13);
379 HHH(bbb, ccc, ddd, aaa,
x[2], 11);
382 GGG(aaa, bbb, ccc, ddd,
x[15], 9);
383 GGG(ddd, aaa, bbb, ccc,
x[5], 7);
384 GGG(ccc, ddd, aaa, bbb,
x[1], 15);
385 GGG(bbb, ccc, ddd, aaa,
x[3], 11);
386 GGG(aaa, bbb, ccc, ddd,
x[7], 8);
387 GGG(ddd, aaa, bbb, ccc,
x[14], 6);
388 GGG(ccc, ddd, aaa, bbb,
x[6], 6);
389 GGG(bbb, ccc, ddd, aaa,
x[9], 14);
390 GGG(aaa, bbb, ccc, ddd,
x[11], 12);
391 GGG(ddd, aaa, bbb, ccc,
x[8], 13);
392 GGG(ccc, ddd, aaa, bbb,
x[12], 5);
393 GGG(bbb, ccc, ddd, aaa,
x[2], 14);
394 GGG(aaa, bbb, ccc, ddd,
x[10], 13);
395 GGG(ddd, aaa, bbb, ccc,
x[0], 13);
396 GGG(ccc, ddd, aaa, bbb,
x[4], 7);
397 GGG(bbb, ccc, ddd, aaa,
x[13], 5);
400 FFF(aaa, bbb, ccc, ddd,
x[8], 15);
401 FFF(ddd, aaa, bbb, ccc,
x[6], 5);
402 FFF(ccc, ddd, aaa, bbb,
x[4], 8);
403 FFF(bbb, ccc, ddd, aaa,
x[1], 11);
404 FFF(aaa, bbb, ccc, ddd,
x[3], 14);
405 FFF(ddd, aaa, bbb, ccc,
x[11], 14);
406 FFF(ccc, ddd, aaa, bbb,
x[15], 6);
407 FFF(bbb, ccc, ddd, aaa,
x[0], 14);
408 FFF(aaa, bbb, ccc, ddd,
x[5], 6);
409 FFF(ddd, aaa, bbb, ccc,
x[12], 9);
410 FFF(ccc, ddd, aaa, bbb,
x[2], 12);
411 FFF(bbb, ccc, ddd, aaa,
x[13], 9);
412 FFF(aaa, bbb, ccc, ddd,
x[9], 12);
413 FFF(ddd, aaa, bbb, ccc,
x[7], 5);
414 FFF(ccc, ddd, aaa, bbb,
x[10], 15);
415 FFF(bbb, ccc, ddd, aaa,
x[14], 8);
418 ddd = context->
h[1] + cc + ddd;
419 context->
h[1] = context->
h[2] + dd + aaa;
420 context->
h[2] = context->
h[3] +
aa + bbb;
421 context->
h[3] = context->
h[0] + bb + ccc;
const uint8_t RIPEMD128_OID[5]
void(* HashAlgoInit)(void *context)
RIPEMD-128 hash function.
#define III(a, b, c, d, x, s)
void ripemd128ProcessBlock(Ripemd128Context *context)
Process message in 16-word blocks.
#define II(a, b, c, d, x, s)
#define RIPEMD128_DIGEST_SIZE
#define HH(a, b, c, d, x, s)
void ripemd128Final(Ripemd128Context *context, uint8_t *digest)
Finish the RIPEMD-128 message digest.
#define HHH(a, b, c, d, x, s)
#define FFF(a, b, c, d, x, s)
void(* HashAlgoUpdate)(void *context, const void *data, size_t length)
const HashAlgo ripemd128HashAlgo
#define GGG(a, b, c, d, x, s)
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
#define FF(a, b, c, d, x, s)
void ripemd128Init(Ripemd128Context *context)
Initialize RIPEMD-128 message digest context.
General definitions for cryptographic algorithms.
#define RIPEMD128_BLOCK_SIZE
void(* HashAlgoFinal)(void *context, uint8_t *digest)
#define GG(a, b, c, d, x, s)
error_t ripemd128Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using RIPEMD-128.
#define cryptoAllocMem(size)
RIPEMD-128 algorithm context.
Common interface for hash algorithms.
#define RIPEMD128_MIN_PAD_SIZE
error_t(* HashAlgoCompute)(const void *data, size_t length, uint8_t *digest)
void ripemd128Update(Ripemd128Context *context, const void *data, size_t length)
Update the RIPEMD-128 context with a portion of the message being hashed.