From 31a19b9acfea2c2e322752b3fb502256e1250c7a Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Mon, 26 May 2025 20:28:13 +0200 Subject: [PATCH] Added hash-modes: RIPEMD-320, HMAC-RIPEMD320 (key = $pass), HMAC-RIPEMD320 (key = $salt) --- OpenCL/inc_hash_ripemd320.cl | 2279 +++++++++++++++++++++++++++++++++ OpenCL/inc_hash_ripemd320.h | 147 +++ OpenCL/inc_types.h | 196 +++ OpenCL/m33600_a0-optimized.cl | 225 ++++ OpenCL/m33600_a0-pure.cl | 118 ++ OpenCL/m33600_a1-optimized.cl | 339 +++++ OpenCL/m33600_a1-pure.cl | 112 ++ OpenCL/m33600_a3-optimized.cl | 447 +++++++ OpenCL/m33600_a3-pure.cl | 138 ++ OpenCL/m33650_a0-pure.cl | 135 ++ OpenCL/m33650_a1-pure.cl | 183 +++ OpenCL/m33650_a3-pure.cl | 155 +++ OpenCL/m33660_a0-pure.cl | 139 ++ OpenCL/m33660_a1-pure.cl | 187 +++ OpenCL/m33660_a3-pure.cl | 159 +++ docs/changes.txt | 3 + docs/readme.txt | 3 + include/types.h | 1 + src/modules/module_33600.c | 196 +++ src/modules/module_33650.c | 223 ++++ src/modules/module_33660.c | 223 ++++ tools/test_modules/m33600.pm | 42 + tools/test_modules/m33650.pm | 45 + tools/test_modules/m33660.pm | 45 + 24 files changed, 5740 insertions(+) create mode 100644 OpenCL/inc_hash_ripemd320.cl create mode 100644 OpenCL/inc_hash_ripemd320.h create mode 100644 OpenCL/m33600_a0-optimized.cl create mode 100644 OpenCL/m33600_a0-pure.cl create mode 100644 OpenCL/m33600_a1-optimized.cl create mode 100644 OpenCL/m33600_a1-pure.cl create mode 100644 OpenCL/m33600_a3-optimized.cl create mode 100644 OpenCL/m33600_a3-pure.cl create mode 100644 OpenCL/m33650_a0-pure.cl create mode 100644 OpenCL/m33650_a1-pure.cl create mode 100644 OpenCL/m33650_a3-pure.cl create mode 100644 OpenCL/m33660_a0-pure.cl create mode 100644 OpenCL/m33660_a1-pure.cl create mode 100644 OpenCL/m33660_a3-pure.cl create mode 100644 src/modules/module_33600.c create mode 100644 src/modules/module_33650.c create mode 100644 src/modules/module_33660.c create mode 100644 tools/test_modules/m33600.pm create mode 100644 tools/test_modules/m33650.pm create mode 100644 tools/test_modules/m33660.pm diff --git a/OpenCL/inc_hash_ripemd320.cl b/OpenCL/inc_hash_ripemd320.cl new file mode 100644 index 000000000..96276042b --- /dev/null +++ b/OpenCL/inc_hash_ripemd320.cl @@ -0,0 +1,2279 @@ + +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_platform.h" +#include "inc_common.h" +#include "inc_hash_ripemd320.h" + +// important notes on this: +// input buf unused bytes needs to be set to zero +// input buf needs to be in algorithm native byte order (ripemd320 = LE, sha1 = BE, etc) +// input buf needs to be 64 byte aligned when using ripemd320_update() + +DECLSPEC void ripemd320_transform (PRIVATE_AS const u32 *w0, PRIVATE_AS const u32 *w1, PRIVATE_AS const u32 *w2, PRIVATE_AS const u32 *w3, PRIVATE_AS u32 *digest) +{ + u32 a1 = digest[0]; + u32 b1 = digest[1]; + u32 c1 = digest[2]; + u32 d1 = digest[3]; + u32 e1 = digest[4]; + + u32 a2 = digest[5]; + u32 b2 = digest[6]; + u32 c2 = digest[7]; + u32 d2 = digest[8]; + u32 e2 = digest[9]; + + u32 tmp = 0; + + RIPEMD320_STEP_S (RIPEMD320_F , a1, b1, c1, d1, e1, w0[0], RIPEMD320C00, RIPEMD320S00); + RIPEMD320_STEP_S (RIPEMD320_F , e1, a1, b1, c1, d1, w0[1], RIPEMD320C00, RIPEMD320S01); + RIPEMD320_STEP_S (RIPEMD320_F , d1, e1, a1, b1, c1, w0[2], RIPEMD320C00, RIPEMD320S02); + RIPEMD320_STEP_S (RIPEMD320_F , c1, d1, e1, a1, b1, w0[3], RIPEMD320C00, RIPEMD320S03); + RIPEMD320_STEP_S (RIPEMD320_F , b1, c1, d1, e1, a1, w1[0], RIPEMD320C00, RIPEMD320S04); + RIPEMD320_STEP_S (RIPEMD320_F , a1, b1, c1, d1, e1, w1[1], RIPEMD320C00, RIPEMD320S05); + RIPEMD320_STEP_S (RIPEMD320_F , e1, a1, b1, c1, d1, w1[2], RIPEMD320C00, RIPEMD320S06); + RIPEMD320_STEP_S (RIPEMD320_F , d1, e1, a1, b1, c1, w1[3], RIPEMD320C00, RIPEMD320S07); + RIPEMD320_STEP_S (RIPEMD320_F , c1, d1, e1, a1, b1, w2[0], RIPEMD320C00, RIPEMD320S08); + RIPEMD320_STEP_S (RIPEMD320_F , b1, c1, d1, e1, a1, w2[1], RIPEMD320C00, RIPEMD320S09); + RIPEMD320_STEP_S (RIPEMD320_F , a1, b1, c1, d1, e1, w2[2], RIPEMD320C00, RIPEMD320S0A); + RIPEMD320_STEP_S (RIPEMD320_F , e1, a1, b1, c1, d1, w2[3], RIPEMD320C00, RIPEMD320S0B); + RIPEMD320_STEP_S (RIPEMD320_F , d1, e1, a1, b1, c1, w3[0], RIPEMD320C00, RIPEMD320S0C); + RIPEMD320_STEP_S (RIPEMD320_F , c1, d1, e1, a1, b1, w3[1], RIPEMD320C00, RIPEMD320S0D); + RIPEMD320_STEP_S (RIPEMD320_F , b1, c1, d1, e1, a1, w3[2], RIPEMD320C00, RIPEMD320S0E); + RIPEMD320_STEP_S (RIPEMD320_F , a1, b1, c1, d1, e1, w3[3], RIPEMD320C00, RIPEMD320S0F); + + RIPEMD320_STEP_S (RIPEMD320_J , a2, b2, c2, d2, e2, w1[1], RIPEMD320C50, RIPEMD320S50); + RIPEMD320_STEP_S (RIPEMD320_J , e2, a2, b2, c2, d2, w3[2], RIPEMD320C50, RIPEMD320S51); + RIPEMD320_STEP_S (RIPEMD320_J , d2, e2, a2, b2, c2, w1[3], RIPEMD320C50, RIPEMD320S52); + RIPEMD320_STEP_S (RIPEMD320_J , c2, d2, e2, a2, b2, w0[0], RIPEMD320C50, RIPEMD320S53); + RIPEMD320_STEP_S (RIPEMD320_J , b2, c2, d2, e2, a2, w2[1], RIPEMD320C50, RIPEMD320S54); + RIPEMD320_STEP_S (RIPEMD320_J , a2, b2, c2, d2, e2, w0[2], RIPEMD320C50, RIPEMD320S55); + RIPEMD320_STEP_S (RIPEMD320_J , e2, a2, b2, c2, d2, w2[3], RIPEMD320C50, RIPEMD320S56); + RIPEMD320_STEP_S (RIPEMD320_J , d2, e2, a2, b2, c2, w1[0], RIPEMD320C50, RIPEMD320S57); + RIPEMD320_STEP_S (RIPEMD320_J , c2, d2, e2, a2, b2, w3[1], RIPEMD320C50, RIPEMD320S58); + RIPEMD320_STEP_S (RIPEMD320_J , b2, c2, d2, e2, a2, w1[2], RIPEMD320C50, RIPEMD320S59); + RIPEMD320_STEP_S (RIPEMD320_J , a2, b2, c2, d2, e2, w3[3], RIPEMD320C50, RIPEMD320S5A); + RIPEMD320_STEP_S (RIPEMD320_J , e2, a2, b2, c2, d2, w2[0], RIPEMD320C50, RIPEMD320S5B); + RIPEMD320_STEP_S (RIPEMD320_J , d2, e2, a2, b2, c2, w0[1], RIPEMD320C50, RIPEMD320S5C); + RIPEMD320_STEP_S (RIPEMD320_J , c2, d2, e2, a2, b2, w2[2], RIPEMD320C50, RIPEMD320S5D); + RIPEMD320_STEP_S (RIPEMD320_J , b2, c2, d2, e2, a2, w0[3], RIPEMD320C50, RIPEMD320S5E); + RIPEMD320_STEP_S (RIPEMD320_J , a2, b2, c2, d2, e2, w3[0], RIPEMD320C50, RIPEMD320S5F); + + tmp = a1; a1 = a2; a2 = tmp; + + RIPEMD320_STEP_S (RIPEMD320_Go, e1, a1, b1, c1, d1, w1[3], RIPEMD320C10, RIPEMD320S10); + RIPEMD320_STEP_S (RIPEMD320_Go, d1, e1, a1, b1, c1, w1[0], RIPEMD320C10, RIPEMD320S11); + RIPEMD320_STEP_S (RIPEMD320_Go, c1, d1, e1, a1, b1, w3[1], RIPEMD320C10, RIPEMD320S12); + RIPEMD320_STEP_S (RIPEMD320_Go, b1, c1, d1, e1, a1, w0[1], RIPEMD320C10, RIPEMD320S13); + RIPEMD320_STEP_S (RIPEMD320_Go, a1, b1, c1, d1, e1, w2[2], RIPEMD320C10, RIPEMD320S14); + RIPEMD320_STEP_S (RIPEMD320_Go, e1, a1, b1, c1, d1, w1[2], RIPEMD320C10, RIPEMD320S15); + RIPEMD320_STEP_S (RIPEMD320_Go, d1, e1, a1, b1, c1, w3[3], RIPEMD320C10, RIPEMD320S16); + RIPEMD320_STEP_S (RIPEMD320_Go, c1, d1, e1, a1, b1, w0[3], RIPEMD320C10, RIPEMD320S17); + RIPEMD320_STEP_S (RIPEMD320_Go, b1, c1, d1, e1, a1, w3[0], RIPEMD320C10, RIPEMD320S18); + RIPEMD320_STEP_S (RIPEMD320_Go, a1, b1, c1, d1, e1, w0[0], RIPEMD320C10, RIPEMD320S19); + RIPEMD320_STEP_S (RIPEMD320_Go, e1, a1, b1, c1, d1, w2[1], RIPEMD320C10, RIPEMD320S1A); + RIPEMD320_STEP_S (RIPEMD320_Go, d1, e1, a1, b1, c1, w1[1], RIPEMD320C10, RIPEMD320S1B); + RIPEMD320_STEP_S (RIPEMD320_Go, c1, d1, e1, a1, b1, w0[2], RIPEMD320C10, RIPEMD320S1C); + RIPEMD320_STEP_S (RIPEMD320_Go, b1, c1, d1, e1, a1, w3[2], RIPEMD320C10, RIPEMD320S1D); + RIPEMD320_STEP_S (RIPEMD320_Go, a1, b1, c1, d1, e1, w2[3], RIPEMD320C10, RIPEMD320S1E); + RIPEMD320_STEP_S (RIPEMD320_Go, e1, a1, b1, c1, d1, w2[0], RIPEMD320C10, RIPEMD320S1F); + + RIPEMD320_STEP_S (RIPEMD320_Io, e2, a2, b2, c2, d2, w1[2], RIPEMD320C60, RIPEMD320S60); + RIPEMD320_STEP_S (RIPEMD320_Io, d2, e2, a2, b2, c2, w2[3], RIPEMD320C60, RIPEMD320S61); + RIPEMD320_STEP_S (RIPEMD320_Io, c2, d2, e2, a2, b2, w0[3], RIPEMD320C60, RIPEMD320S62); + RIPEMD320_STEP_S (RIPEMD320_Io, b2, c2, d2, e2, a2, w1[3], RIPEMD320C60, RIPEMD320S63); + RIPEMD320_STEP_S (RIPEMD320_Io, a2, b2, c2, d2, e2, w0[0], RIPEMD320C60, RIPEMD320S64); + RIPEMD320_STEP_S (RIPEMD320_Io, e2, a2, b2, c2, d2, w3[1], RIPEMD320C60, RIPEMD320S65); + RIPEMD320_STEP_S (RIPEMD320_Io, d2, e2, a2, b2, c2, w1[1], RIPEMD320C60, RIPEMD320S66); + RIPEMD320_STEP_S (RIPEMD320_Io, c2, d2, e2, a2, b2, w2[2], RIPEMD320C60, RIPEMD320S67); + RIPEMD320_STEP_S (RIPEMD320_Io, b2, c2, d2, e2, a2, w3[2], RIPEMD320C60, RIPEMD320S68); + RIPEMD320_STEP_S (RIPEMD320_Io, a2, b2, c2, d2, e2, w3[3], RIPEMD320C60, RIPEMD320S69); + RIPEMD320_STEP_S (RIPEMD320_Io, e2, a2, b2, c2, d2, w2[0], RIPEMD320C60, RIPEMD320S6A); + RIPEMD320_STEP_S (RIPEMD320_Io, d2, e2, a2, b2, c2, w3[0], RIPEMD320C60, RIPEMD320S6B); + RIPEMD320_STEP_S (RIPEMD320_Io, c2, d2, e2, a2, b2, w1[0], RIPEMD320C60, RIPEMD320S6C); + RIPEMD320_STEP_S (RIPEMD320_Io, b2, c2, d2, e2, a2, w2[1], RIPEMD320C60, RIPEMD320S6D); + RIPEMD320_STEP_S (RIPEMD320_Io, a2, b2, c2, d2, e2, w0[1], RIPEMD320C60, RIPEMD320S6E); + RIPEMD320_STEP_S (RIPEMD320_Io, e2, a2, b2, c2, d2, w0[2], RIPEMD320C60, RIPEMD320S6F); + + tmp = b1; b1 = b2; b2 = tmp; + + RIPEMD320_STEP_S (RIPEMD320_H , d1, e1, a1, b1, c1, w0[3], RIPEMD320C20, RIPEMD320S20); + RIPEMD320_STEP_S (RIPEMD320_H , c1, d1, e1, a1, b1, w2[2], RIPEMD320C20, RIPEMD320S21); + RIPEMD320_STEP_S (RIPEMD320_H , b1, c1, d1, e1, a1, w3[2], RIPEMD320C20, RIPEMD320S22); + RIPEMD320_STEP_S (RIPEMD320_H , a1, b1, c1, d1, e1, w1[0], RIPEMD320C20, RIPEMD320S23); + RIPEMD320_STEP_S (RIPEMD320_H , e1, a1, b1, c1, d1, w2[1], RIPEMD320C20, RIPEMD320S24); + RIPEMD320_STEP_S (RIPEMD320_H , d1, e1, a1, b1, c1, w3[3], RIPEMD320C20, RIPEMD320S25); + RIPEMD320_STEP_S (RIPEMD320_H , c1, d1, e1, a1, b1, w2[0], RIPEMD320C20, RIPEMD320S26); + RIPEMD320_STEP_S (RIPEMD320_H , b1, c1, d1, e1, a1, w0[1], RIPEMD320C20, RIPEMD320S27); + RIPEMD320_STEP_S (RIPEMD320_H , a1, b1, c1, d1, e1, w0[2], RIPEMD320C20, RIPEMD320S28); + RIPEMD320_STEP_S (RIPEMD320_H , e1, a1, b1, c1, d1, w1[3], RIPEMD320C20, RIPEMD320S29); + RIPEMD320_STEP_S (RIPEMD320_H , d1, e1, a1, b1, c1, w0[0], RIPEMD320C20, RIPEMD320S2A); + RIPEMD320_STEP_S (RIPEMD320_H , c1, d1, e1, a1, b1, w1[2], RIPEMD320C20, RIPEMD320S2B); + RIPEMD320_STEP_S (RIPEMD320_H , b1, c1, d1, e1, a1, w3[1], RIPEMD320C20, RIPEMD320S2C); + RIPEMD320_STEP_S (RIPEMD320_H , a1, b1, c1, d1, e1, w2[3], RIPEMD320C20, RIPEMD320S2D); + RIPEMD320_STEP_S (RIPEMD320_H , e1, a1, b1, c1, d1, w1[1], RIPEMD320C20, RIPEMD320S2E); + RIPEMD320_STEP_S (RIPEMD320_H , d1, e1, a1, b1, c1, w3[0], RIPEMD320C20, RIPEMD320S2F); + + RIPEMD320_STEP_S (RIPEMD320_H , d2, e2, a2, b2, c2, w3[3], RIPEMD320C70, RIPEMD320S70); + RIPEMD320_STEP_S (RIPEMD320_H , c2, d2, e2, a2, b2, w1[1], RIPEMD320C70, RIPEMD320S71); + RIPEMD320_STEP_S (RIPEMD320_H , b2, c2, d2, e2, a2, w0[1], RIPEMD320C70, RIPEMD320S72); + RIPEMD320_STEP_S (RIPEMD320_H , a2, b2, c2, d2, e2, w0[3], RIPEMD320C70, RIPEMD320S73); + RIPEMD320_STEP_S (RIPEMD320_H , e2, a2, b2, c2, d2, w1[3], RIPEMD320C70, RIPEMD320S74); + RIPEMD320_STEP_S (RIPEMD320_H , d2, e2, a2, b2, c2, w3[2], RIPEMD320C70, RIPEMD320S75); + RIPEMD320_STEP_S (RIPEMD320_H , c2, d2, e2, a2, b2, w1[2], RIPEMD320C70, RIPEMD320S76); + RIPEMD320_STEP_S (RIPEMD320_H , b2, c2, d2, e2, a2, w2[1], RIPEMD320C70, RIPEMD320S77); + RIPEMD320_STEP_S (RIPEMD320_H , a2, b2, c2, d2, e2, w2[3], RIPEMD320C70, RIPEMD320S78); + RIPEMD320_STEP_S (RIPEMD320_H , e2, a2, b2, c2, d2, w2[0], RIPEMD320C70, RIPEMD320S79); + RIPEMD320_STEP_S (RIPEMD320_H , d2, e2, a2, b2, c2, w3[0], RIPEMD320C70, RIPEMD320S7A); + RIPEMD320_STEP_S (RIPEMD320_H , c2, d2, e2, a2, b2, w0[2], RIPEMD320C70, RIPEMD320S7B); + RIPEMD320_STEP_S (RIPEMD320_H , b2, c2, d2, e2, a2, w2[2], RIPEMD320C70, RIPEMD320S7C); + RIPEMD320_STEP_S (RIPEMD320_H , a2, b2, c2, d2, e2, w0[0], RIPEMD320C70, RIPEMD320S7D); + RIPEMD320_STEP_S (RIPEMD320_H , e2, a2, b2, c2, d2, w1[0], RIPEMD320C70, RIPEMD320S7E); + RIPEMD320_STEP_S (RIPEMD320_H , d2, e2, a2, b2, c2, w3[1], RIPEMD320C70, RIPEMD320S7F); + + tmp = c1; c1 = c2; c2 = tmp; + + RIPEMD320_STEP_S (RIPEMD320_Io, c1, d1, e1, a1, b1, w0[1], RIPEMD320C30, RIPEMD320S30); + RIPEMD320_STEP_S (RIPEMD320_Io, b1, c1, d1, e1, a1, w2[1], RIPEMD320C30, RIPEMD320S31); + RIPEMD320_STEP_S (RIPEMD320_Io, a1, b1, c1, d1, e1, w2[3], RIPEMD320C30, RIPEMD320S32); + RIPEMD320_STEP_S (RIPEMD320_Io, e1, a1, b1, c1, d1, w2[2], RIPEMD320C30, RIPEMD320S33); + RIPEMD320_STEP_S (RIPEMD320_Io, d1, e1, a1, b1, c1, w0[0], RIPEMD320C30, RIPEMD320S34); + RIPEMD320_STEP_S (RIPEMD320_Io, c1, d1, e1, a1, b1, w2[0], RIPEMD320C30, RIPEMD320S35); + RIPEMD320_STEP_S (RIPEMD320_Io, b1, c1, d1, e1, a1, w3[0], RIPEMD320C30, RIPEMD320S36); + RIPEMD320_STEP_S (RIPEMD320_Io, a1, b1, c1, d1, e1, w1[0], RIPEMD320C30, RIPEMD320S37); + RIPEMD320_STEP_S (RIPEMD320_Io, e1, a1, b1, c1, d1, w3[1], RIPEMD320C30, RIPEMD320S38); + RIPEMD320_STEP_S (RIPEMD320_Io, d1, e1, a1, b1, c1, w0[3], RIPEMD320C30, RIPEMD320S39); + RIPEMD320_STEP_S (RIPEMD320_Io, c1, d1, e1, a1, b1, w1[3], RIPEMD320C30, RIPEMD320S3A); + RIPEMD320_STEP_S (RIPEMD320_Io, b1, c1, d1, e1, a1, w3[3], RIPEMD320C30, RIPEMD320S3B); + RIPEMD320_STEP_S (RIPEMD320_Io, a1, b1, c1, d1, e1, w3[2], RIPEMD320C30, RIPEMD320S3C); + RIPEMD320_STEP_S (RIPEMD320_Io, e1, a1, b1, c1, d1, w1[1], RIPEMD320C30, RIPEMD320S3D); + RIPEMD320_STEP_S (RIPEMD320_Io, d1, e1, a1, b1, c1, w1[2], RIPEMD320C30, RIPEMD320S3E); + RIPEMD320_STEP_S (RIPEMD320_Io, c1, d1, e1, a1, b1, w0[2], RIPEMD320C30, RIPEMD320S3F); + + RIPEMD320_STEP_S (RIPEMD320_Go, c2, d2, e2, a2, b2, w2[0], RIPEMD320C80, RIPEMD320S80); + RIPEMD320_STEP_S (RIPEMD320_Go, b2, c2, d2, e2, a2, w1[2], RIPEMD320C80, RIPEMD320S81); + RIPEMD320_STEP_S (RIPEMD320_Go, a2, b2, c2, d2, e2, w1[0], RIPEMD320C80, RIPEMD320S82); + RIPEMD320_STEP_S (RIPEMD320_Go, e2, a2, b2, c2, d2, w0[1], RIPEMD320C80, RIPEMD320S83); + RIPEMD320_STEP_S (RIPEMD320_Go, d2, e2, a2, b2, c2, w0[3], RIPEMD320C80, RIPEMD320S84); + RIPEMD320_STEP_S (RIPEMD320_Go, c2, d2, e2, a2, b2, w2[3], RIPEMD320C80, RIPEMD320S85); + RIPEMD320_STEP_S (RIPEMD320_Go, b2, c2, d2, e2, a2, w3[3], RIPEMD320C80, RIPEMD320S86); + RIPEMD320_STEP_S (RIPEMD320_Go, a2, b2, c2, d2, e2, w0[0], RIPEMD320C80, RIPEMD320S87); + RIPEMD320_STEP_S (RIPEMD320_Go, e2, a2, b2, c2, d2, w1[1], RIPEMD320C80, RIPEMD320S88); + RIPEMD320_STEP_S (RIPEMD320_Go, d2, e2, a2, b2, c2, w3[0], RIPEMD320C80, RIPEMD320S89); + RIPEMD320_STEP_S (RIPEMD320_Go, c2, d2, e2, a2, b2, w0[2], RIPEMD320C80, RIPEMD320S8A); + RIPEMD320_STEP_S (RIPEMD320_Go, b2, c2, d2, e2, a2, w3[1], RIPEMD320C80, RIPEMD320S8B); + RIPEMD320_STEP_S (RIPEMD320_Go, a2, b2, c2, d2, e2, w2[1], RIPEMD320C80, RIPEMD320S8C); + RIPEMD320_STEP_S (RIPEMD320_Go, e2, a2, b2, c2, d2, w1[3], RIPEMD320C80, RIPEMD320S8D); + RIPEMD320_STEP_S (RIPEMD320_Go, d2, e2, a2, b2, c2, w2[2], RIPEMD320C80, RIPEMD320S8E); + RIPEMD320_STEP_S (RIPEMD320_Go, c2, d2, e2, a2, b2, w3[2], RIPEMD320C80, RIPEMD320S8F); + + tmp = d1; d1 = d2; d2 = tmp; + + RIPEMD320_STEP_S (RIPEMD320_J , b1, c1, d1, e1, a1, w1[0], RIPEMD320C40, RIPEMD320S40); + RIPEMD320_STEP_S (RIPEMD320_J , a1, b1, c1, d1, e1, w0[0], RIPEMD320C40, RIPEMD320S41); + RIPEMD320_STEP_S (RIPEMD320_J , e1, a1, b1, c1, d1, w1[1], RIPEMD320C40, RIPEMD320S42); + RIPEMD320_STEP_S (RIPEMD320_J , d1, e1, a1, b1, c1, w2[1], RIPEMD320C40, RIPEMD320S43); + RIPEMD320_STEP_S (RIPEMD320_J , c1, d1, e1, a1, b1, w1[3], RIPEMD320C40, RIPEMD320S44); + RIPEMD320_STEP_S (RIPEMD320_J , b1, c1, d1, e1, a1, w3[0], RIPEMD320C40, RIPEMD320S45); + RIPEMD320_STEP_S (RIPEMD320_J , a1, b1, c1, d1, e1, w0[2], RIPEMD320C40, RIPEMD320S46); + RIPEMD320_STEP_S (RIPEMD320_J , e1, a1, b1, c1, d1, w2[2], RIPEMD320C40, RIPEMD320S47); + RIPEMD320_STEP_S (RIPEMD320_J , d1, e1, a1, b1, c1, w3[2], RIPEMD320C40, RIPEMD320S48); + RIPEMD320_STEP_S (RIPEMD320_J , c1, d1, e1, a1, b1, w0[1], RIPEMD320C40, RIPEMD320S49); + RIPEMD320_STEP_S (RIPEMD320_J , b1, c1, d1, e1, a1, w0[3], RIPEMD320C40, RIPEMD320S4A); + RIPEMD320_STEP_S (RIPEMD320_J , a1, b1, c1, d1, e1, w2[0], RIPEMD320C40, RIPEMD320S4B); + RIPEMD320_STEP_S (RIPEMD320_J , e1, a1, b1, c1, d1, w2[3], RIPEMD320C40, RIPEMD320S4C); + RIPEMD320_STEP_S (RIPEMD320_J , d1, e1, a1, b1, c1, w1[2], RIPEMD320C40, RIPEMD320S4D); + RIPEMD320_STEP_S (RIPEMD320_J , c1, d1, e1, a1, b1, w3[3], RIPEMD320C40, RIPEMD320S4E); + RIPEMD320_STEP_S (RIPEMD320_J , b1, c1, d1, e1, a1, w3[1], RIPEMD320C40, RIPEMD320S4F); + + RIPEMD320_STEP_S (RIPEMD320_F , b2, c2, d2, e2, a2, w3[0], RIPEMD320C90, RIPEMD320S90); + RIPEMD320_STEP_S (RIPEMD320_F , a2, b2, c2, d2, e2, w3[3], RIPEMD320C90, RIPEMD320S91); + RIPEMD320_STEP_S (RIPEMD320_F , e2, a2, b2, c2, d2, w2[2], RIPEMD320C90, RIPEMD320S92); + RIPEMD320_STEP_S (RIPEMD320_F , d2, e2, a2, b2, c2, w1[0], RIPEMD320C90, RIPEMD320S93); + RIPEMD320_STEP_S (RIPEMD320_F , c2, d2, e2, a2, b2, w0[1], RIPEMD320C90, RIPEMD320S94); + RIPEMD320_STEP_S (RIPEMD320_F , b2, c2, d2, e2, a2, w1[1], RIPEMD320C90, RIPEMD320S95); + RIPEMD320_STEP_S (RIPEMD320_F , a2, b2, c2, d2, e2, w2[0], RIPEMD320C90, RIPEMD320S96); + RIPEMD320_STEP_S (RIPEMD320_F , e2, a2, b2, c2, d2, w1[3], RIPEMD320C90, RIPEMD320S97); + RIPEMD320_STEP_S (RIPEMD320_F , d2, e2, a2, b2, c2, w1[2], RIPEMD320C90, RIPEMD320S98); + RIPEMD320_STEP_S (RIPEMD320_F , c2, d2, e2, a2, b2, w0[2], RIPEMD320C90, RIPEMD320S99); + RIPEMD320_STEP_S (RIPEMD320_F , b2, c2, d2, e2, a2, w3[1], RIPEMD320C90, RIPEMD320S9A); + RIPEMD320_STEP_S (RIPEMD320_F , a2, b2, c2, d2, e2, w3[2], RIPEMD320C90, RIPEMD320S9B); + RIPEMD320_STEP_S (RIPEMD320_F , e2, a2, b2, c2, d2, w0[0], RIPEMD320C90, RIPEMD320S9C); + RIPEMD320_STEP_S (RIPEMD320_F , d2, e2, a2, b2, c2, w0[3], RIPEMD320C90, RIPEMD320S9D); + RIPEMD320_STEP_S (RIPEMD320_F , c2, d2, e2, a2, b2, w2[1], RIPEMD320C90, RIPEMD320S9E); + RIPEMD320_STEP_S (RIPEMD320_F , b2, c2, d2, e2, a2, w2[3], RIPEMD320C90, RIPEMD320S9F); + + tmp = e1; e1 = e2; e2 = tmp; + + const u32 a = digest[0] + a1; + const u32 b = digest[1] + b1; + const u32 c = digest[2] + c1; + const u32 d = digest[3] + d1; + const u32 e = digest[4] + e1; + const u32 f = digest[5] + a2; + const u32 g = digest[6] + b2; + const u32 h = digest[7] + c2; + const u32 i = digest[8] + d2; + const u32 l = digest[9] + e2; + + digest[0] = a; + digest[1] = b; + digest[2] = c; + digest[3] = d; + digest[4] = e; + digest[5] = f; + digest[6] = g; + digest[7] = h; + digest[8] = i; + digest[9] = l; +} + +DECLSPEC void ripemd320_init (PRIVATE_AS ripemd320_ctx_t *ctx) +{ + ctx->h[0] = RIPEMD320M_A; + ctx->h[1] = RIPEMD320M_B; + ctx->h[2] = RIPEMD320M_C; + ctx->h[3] = RIPEMD320M_D; + ctx->h[4] = RIPEMD320M_E; + ctx->h[5] = RIPEMD320M_F; + ctx->h[6] = RIPEMD320M_G; + ctx->h[7] = RIPEMD320M_H; + ctx->h[8] = RIPEMD320M_I; + ctx->h[9] = RIPEMD320M_L; + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + + ctx->len = 0; +} + +DECLSPEC void ripemd320_update_64 (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const int len) +{ + if (len == 0) return; + + const int pos = ctx->len & 63; + + ctx->len += len; + + if (pos == 0) + { + ctx->w0[0] = w0[0]; + ctx->w0[1] = w0[1]; + ctx->w0[2] = w0[2]; + ctx->w0[3] = w0[3]; + ctx->w1[0] = w1[0]; + ctx->w1[1] = w1[1]; + ctx->w1[2] = w1[2]; + ctx->w1[3] = w1[3]; + ctx->w2[0] = w2[0]; + ctx->w2[1] = w2[1]; + ctx->w2[2] = w2[2]; + ctx->w2[3] = w2[3]; + ctx->w3[0] = w3[0]; + ctx->w3[1] = w3[1]; + ctx->w3[2] = w3[2]; + ctx->w3[3] = w3[3]; + + if (len == 64) + { + ripemd320_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + } + } + else + { + if ((pos + len) < 64) + { + switch_buffer_by_offset_le_S (w0, w1, w2, w3, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + } + else + { + u32 c0[4] = { 0 }; + u32 c1[4] = { 0 }; + u32 c2[4] = { 0 }; + u32 c3[4] = { 0 }; + + switch_buffer_by_offset_carry_le_S (w0, w1, w2, w3, c0, c1, c2, c3, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + + ripemd320_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); + + ctx->w0[0] = c0[0]; + ctx->w0[1] = c0[1]; + ctx->w0[2] = c0[2]; + ctx->w0[3] = c0[3]; + ctx->w1[0] = c1[0]; + ctx->w1[1] = c1[1]; + ctx->w1[2] = c1[2]; + ctx->w1[3] = c1[3]; + ctx->w2[0] = c2[0]; + ctx->w2[1] = c2[1]; + ctx->w2[2] = c2[2]; + ctx->w2[3] = c2[3]; + ctx->w3[0] = c3[0]; + ctx->w3[1] = c3[1]; + ctx->w3[2] = c3[2]; + ctx->w3[3] = c3[3]; + } + } +} + +DECLSPEC void ripemd320_update (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + ripemd320_update_64 (ctx, w0, w1, w2, w3, len - pos1); +} + +DECLSPEC void ripemd320_update_swap (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, len - pos1); +} + +DECLSPEC void ripemd320_update_utf16le (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + if (hc_enc_scan (w, len)) + { + hc_enc_t hc_enc; + + hc_enc_init (&hc_enc); + + while (hc_enc_has_next (&hc_enc, len)) + { + u32 enc_buf[16] = { 0 }; + + const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf)); + + if (enc_len == -1) + { + ctx->len = -1; + + return; + } + + ripemd320_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len); + } + + return; + } + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 32 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2); +} + +DECLSPEC void ripemd320_update_utf16le_swap (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + if (hc_enc_scan (w, len)) + { + hc_enc_t hc_enc; + + hc_enc_init (&hc_enc); + + while (hc_enc_has_next (&hc_enc, len)) + { + u32 enc_buf[16] = { 0 }; + + const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf)); + + if (enc_len == -1) + { + ctx->len = -1; + + return; + } + + enc_buf[ 0] = hc_swap32_S (enc_buf[ 0]); + enc_buf[ 1] = hc_swap32_S (enc_buf[ 1]); + enc_buf[ 2] = hc_swap32_S (enc_buf[ 2]); + enc_buf[ 3] = hc_swap32_S (enc_buf[ 3]); + enc_buf[ 4] = hc_swap32_S (enc_buf[ 4]); + enc_buf[ 5] = hc_swap32_S (enc_buf[ 5]); + enc_buf[ 6] = hc_swap32_S (enc_buf[ 6]); + enc_buf[ 7] = hc_swap32_S (enc_buf[ 7]); + enc_buf[ 8] = hc_swap32_S (enc_buf[ 8]); + enc_buf[ 9] = hc_swap32_S (enc_buf[ 9]); + enc_buf[10] = hc_swap32_S (enc_buf[10]); + enc_buf[11] = hc_swap32_S (enc_buf[11]); + enc_buf[12] = hc_swap32_S (enc_buf[12]); + enc_buf[13] = hc_swap32_S (enc_buf[13]); + enc_buf[14] = hc_swap32_S (enc_buf[14]); + enc_buf[15] = hc_swap32_S (enc_buf[15]); + + ripemd320_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len); + } + + return; + } + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 32 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2); +} + +DECLSPEC void ripemd320_update_global (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + ripemd320_update_64 (ctx, w0, w1, w2, w3, len - pos1); +} + +DECLSPEC void ripemd320_update_global_swap (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, len - pos1); +} + +DECLSPEC void ripemd320_update_global_utf16le (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + if (hc_enc_scan_global (w, len)) + { + hc_enc_t hc_enc; + + hc_enc_init (&hc_enc); + + while (hc_enc_has_next (&hc_enc, len)) + { + u32 enc_buf[16] = { 0 }; + + const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf)); + + if (enc_len == -1) + { + ctx->len = -1; + + return; + } + + ripemd320_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len); + } + + return; + } + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 32 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2); +} + +DECLSPEC void ripemd320_update_global_utf16le_swap (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + if (hc_enc_scan_global (w, len)) + { + hc_enc_t hc_enc; + + hc_enc_init (&hc_enc); + + while (hc_enc_has_next (&hc_enc, len)) + { + u32 enc_buf[16] = { 0 }; + + const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf)); + + if (enc_len == -1) + { + ctx->len = -1; + + return; + } + + enc_buf[ 0] = hc_swap32_S (enc_buf[ 0]); + enc_buf[ 1] = hc_swap32_S (enc_buf[ 1]); + enc_buf[ 2] = hc_swap32_S (enc_buf[ 2]); + enc_buf[ 3] = hc_swap32_S (enc_buf[ 3]); + enc_buf[ 4] = hc_swap32_S (enc_buf[ 4]); + enc_buf[ 5] = hc_swap32_S (enc_buf[ 5]); + enc_buf[ 6] = hc_swap32_S (enc_buf[ 6]); + enc_buf[ 7] = hc_swap32_S (enc_buf[ 7]); + enc_buf[ 8] = hc_swap32_S (enc_buf[ 8]); + enc_buf[ 9] = hc_swap32_S (enc_buf[ 9]); + enc_buf[10] = hc_swap32_S (enc_buf[10]); + enc_buf[11] = hc_swap32_S (enc_buf[11]); + enc_buf[12] = hc_swap32_S (enc_buf[12]); + enc_buf[13] = hc_swap32_S (enc_buf[13]); + enc_buf[14] = hc_swap32_S (enc_buf[14]); + enc_buf[15] = hc_swap32_S (enc_buf[15]); + + ripemd320_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len); + } + + return; + } + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, 32 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le_S (w1, w2, w3); + make_utf16le_S (w0, w0, w1); + + w0[0] = hc_swap32_S (w0[0]); + w0[1] = hc_swap32_S (w0[1]); + w0[2] = hc_swap32_S (w0[2]); + w0[3] = hc_swap32_S (w0[3]); + w1[0] = hc_swap32_S (w1[0]); + w1[1] = hc_swap32_S (w1[1]); + w1[2] = hc_swap32_S (w1[2]); + w1[3] = hc_swap32_S (w1[3]); + w2[0] = hc_swap32_S (w2[0]); + w2[1] = hc_swap32_S (w2[1]); + w2[2] = hc_swap32_S (w2[2]); + w2[3] = hc_swap32_S (w2[3]); + w3[0] = hc_swap32_S (w3[0]); + w3[1] = hc_swap32_S (w3[1]); + w3[2] = hc_swap32_S (w3[2]); + w3[3] = hc_swap32_S (w3[3]); + + ripemd320_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2); +} + +DECLSPEC void ripemd320_final (PRIVATE_AS ripemd320_ctx_t *ctx) +{ + const int pos = ctx->len & 63; + + append_0x80_4x4_S (ctx->w0, ctx->w1, ctx->w2, ctx->w3, pos); + + if (pos >= 56) + { + ripemd320_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + } + + ctx->w3[2] = ctx->len * 8; + ctx->w3[3] = 0; + + ripemd320_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); +} + +// ripemd320_hmac + +DECLSPEC void ripemd320_hmac_init_64 (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w0, PRIVATE_AS const u32 *w1, PRIVATE_AS const u32 *w2, PRIVATE_AS const u32 *w3) +{ + u32 a0[4]; + u32 a1[4]; + u32 a2[4]; + u32 a3[4]; + + // ipad + + a0[0] = w0[0] ^ 0x36363636; + a0[1] = w0[1] ^ 0x36363636; + a0[2] = w0[2] ^ 0x36363636; + a0[3] = w0[3] ^ 0x36363636; + a1[0] = w1[0] ^ 0x36363636; + a1[1] = w1[1] ^ 0x36363636; + a1[2] = w1[2] ^ 0x36363636; + a1[3] = w1[3] ^ 0x36363636; + a2[0] = w2[0] ^ 0x36363636; + a2[1] = w2[1] ^ 0x36363636; + a2[2] = w2[2] ^ 0x36363636; + a2[3] = w2[3] ^ 0x36363636; + a3[0] = w3[0] ^ 0x36363636; + a3[1] = w3[1] ^ 0x36363636; + a3[2] = w3[2] ^ 0x36363636; + a3[3] = w3[3] ^ 0x36363636; + + ripemd320_init (&ctx->ipad); + + ripemd320_update_64 (&ctx->ipad, a0, a1, a2, a3, 64); + + // opad + + u32 b0[4]; + u32 b1[4]; + u32 b2[4]; + u32 b3[4]; + + b0[0] = w0[0] ^ 0x5c5c5c5c; + b0[1] = w0[1] ^ 0x5c5c5c5c; + b0[2] = w0[2] ^ 0x5c5c5c5c; + b0[3] = w0[3] ^ 0x5c5c5c5c; + b1[0] = w1[0] ^ 0x5c5c5c5c; + b1[1] = w1[1] ^ 0x5c5c5c5c; + b1[2] = w1[2] ^ 0x5c5c5c5c; + b1[3] = w1[3] ^ 0x5c5c5c5c; + b2[0] = w2[0] ^ 0x5c5c5c5c; + b2[1] = w2[1] ^ 0x5c5c5c5c; + b2[2] = w2[2] ^ 0x5c5c5c5c; + b2[3] = w2[3] ^ 0x5c5c5c5c; + b3[0] = w3[0] ^ 0x5c5c5c5c; + b3[1] = w3[1] ^ 0x5c5c5c5c; + b3[2] = w3[2] ^ 0x5c5c5c5c; + b3[3] = w3[3] ^ 0x5c5c5c5c; + + ripemd320_init (&ctx->opad); + + ripemd320_update_64 (&ctx->opad, b0, b1, b2, b3, 64); +} + +DECLSPEC void ripemd320_hmac_init (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + ripemd320_ctx_t tmp; + + ripemd320_init (&tmp); + + ripemd320_update (&tmp, w, len); + + ripemd320_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = tmp.h[8]; + w2[1] = tmp.h[9]; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = w[ 0]; + w0[1] = w[ 1]; + w0[2] = w[ 2]; + w0[3] = w[ 3]; + w1[0] = w[ 4]; + w1[1] = w[ 5]; + w1[2] = w[ 6]; + w1[3] = w[ 7]; + w2[0] = w[ 8]; + w2[1] = w[ 9]; + w2[2] = w[10]; + w2[3] = w[11]; + w3[0] = w[12]; + w3[1] = w[13]; + w3[2] = w[14]; + w3[3] = w[15]; + } + + ripemd320_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void ripemd320_hmac_init_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + ripemd320_ctx_t tmp; + + ripemd320_init (&tmp); + + ripemd320_update_swap (&tmp, w, len); + + ripemd320_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = tmp.h[8]; + w2[1] = tmp.h[9]; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = hc_swap32_S (w[ 0]); + w0[1] = hc_swap32_S (w[ 1]); + w0[2] = hc_swap32_S (w[ 2]); + w0[3] = hc_swap32_S (w[ 3]); + w1[0] = hc_swap32_S (w[ 4]); + w1[1] = hc_swap32_S (w[ 5]); + w1[2] = hc_swap32_S (w[ 6]); + w1[3] = hc_swap32_S (w[ 7]); + w2[0] = hc_swap32_S (w[ 8]); + w2[1] = hc_swap32_S (w[ 9]); + w2[2] = hc_swap32_S (w[10]); + w2[3] = hc_swap32_S (w[11]); + w3[0] = hc_swap32_S (w[12]); + w3[1] = hc_swap32_S (w[13]); + w3[2] = hc_swap32_S (w[14]); + w3[3] = hc_swap32_S (w[15]); + } + + ripemd320_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void ripemd320_hmac_init_global (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + ripemd320_ctx_t tmp; + + ripemd320_init (&tmp); + + ripemd320_update_global (&tmp, w, len); + + ripemd320_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = tmp.h[8]; + w2[1] = tmp.h[9]; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = w[ 0]; + w0[1] = w[ 1]; + w0[2] = w[ 2]; + w0[3] = w[ 3]; + w1[0] = w[ 4]; + w1[1] = w[ 5]; + w1[2] = w[ 6]; + w1[3] = w[ 7]; + w2[0] = w[ 8]; + w2[1] = w[ 9]; + w2[2] = w[10]; + w2[3] = w[11]; + w3[0] = w[12]; + w3[1] = w[13]; + w3[2] = w[14]; + w3[3] = w[15]; + } + + ripemd320_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void ripemd320_hmac_init_global_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + if (len > 64) + { + ripemd320_ctx_t tmp; + + ripemd320_init (&tmp); + + ripemd320_update_global_swap (&tmp, w, len); + + ripemd320_final (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = tmp.h[8]; + w2[1] = tmp.h[9]; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = hc_swap32_S (w[ 0]); + w0[1] = hc_swap32_S (w[ 1]); + w0[2] = hc_swap32_S (w[ 2]); + w0[3] = hc_swap32_S (w[ 3]); + w1[0] = hc_swap32_S (w[ 4]); + w1[1] = hc_swap32_S (w[ 5]); + w1[2] = hc_swap32_S (w[ 6]); + w1[3] = hc_swap32_S (w[ 7]); + w2[0] = hc_swap32_S (w[ 8]); + w2[1] = hc_swap32_S (w[ 9]); + w2[2] = hc_swap32_S (w[10]); + w2[3] = hc_swap32_S (w[11]); + w3[0] = hc_swap32_S (w[12]); + w3[1] = hc_swap32_S (w[13]); + w3[2] = hc_swap32_S (w[14]); + w3[3] = hc_swap32_S (w[15]); + } + + ripemd320_hmac_init_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void ripemd320_hmac_update_64 (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const int len) +{ + ripemd320_update_64 (&ctx->ipad, w0, w1, w2, w3, len); +} + +DECLSPEC void ripemd320_hmac_update (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + ripemd320_update (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_update_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + ripemd320_update_swap (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_update_utf16le (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + ripemd320_update_utf16le (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_update_utf16le_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) +{ + ripemd320_update_utf16le_swap (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_update_global (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + ripemd320_update_global (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_update_global_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + ripemd320_update_global_swap (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_update_global_utf16le (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + ripemd320_update_global_utf16le (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_update_global_utf16le_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) +{ + ripemd320_update_global_utf16le_swap (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_final (PRIVATE_AS ripemd320_hmac_ctx_t *ctx) +{ + ripemd320_final (&ctx->ipad); + + ctx->opad.w0[0] = ctx->ipad.h[0]; + ctx->opad.w0[1] = ctx->ipad.h[1]; + ctx->opad.w0[2] = ctx->ipad.h[2]; + ctx->opad.w0[3] = ctx->ipad.h[3]; + ctx->opad.w1[0] = ctx->ipad.h[4]; + ctx->opad.w1[1] = ctx->ipad.h[5]; + ctx->opad.w1[2] = ctx->ipad.h[6]; + ctx->opad.w1[3] = ctx->ipad.h[7]; + ctx->opad.w2[0] = ctx->ipad.h[8]; + ctx->opad.w2[1] = ctx->ipad.h[9]; + ctx->opad.w2[2] = 0; + ctx->opad.w2[3] = 0; + ctx->opad.w3[0] = 0; + ctx->opad.w3[1] = 0; + ctx->opad.w3[2] = 0; + ctx->opad.w3[3] = 0; + + ctx->opad.len += 40; + + ripemd320_final (&ctx->opad); +} + +// while input buf can be a vector datatype, the length of the different elements can not + +DECLSPEC void ripemd320_transform_vector (PRIVATE_AS const u32x *w0, PRIVATE_AS const u32x *w1, PRIVATE_AS const u32x *w2, PRIVATE_AS const u32x *w3, PRIVATE_AS u32x *digest) +{ + u32x a1 = digest[0]; + u32x b1 = digest[1]; + u32x c1 = digest[2]; + u32x d1 = digest[3]; + u32x e1 = digest[4]; + + u32x a2 = digest[5]; + u32x b2 = digest[6]; + u32x c2 = digest[7]; + u32x d2 = digest[8]; + u32x e2 = digest[9]; + + u32x tmp = 0; + + RIPEMD320_STEP (RIPEMD320_F , a1, b1, c1, d1, e1, w0[0], RIPEMD320C00, RIPEMD320S00); + RIPEMD320_STEP (RIPEMD320_F , e1, a1, b1, c1, d1, w0[1], RIPEMD320C00, RIPEMD320S01); + RIPEMD320_STEP (RIPEMD320_F , d1, e1, a1, b1, c1, w0[2], RIPEMD320C00, RIPEMD320S02); + RIPEMD320_STEP (RIPEMD320_F , c1, d1, e1, a1, b1, w0[3], RIPEMD320C00, RIPEMD320S03); + RIPEMD320_STEP (RIPEMD320_F , b1, c1, d1, e1, a1, w1[0], RIPEMD320C00, RIPEMD320S04); + RIPEMD320_STEP (RIPEMD320_F , a1, b1, c1, d1, e1, w1[1], RIPEMD320C00, RIPEMD320S05); + RIPEMD320_STEP (RIPEMD320_F , e1, a1, b1, c1, d1, w1[2], RIPEMD320C00, RIPEMD320S06); + RIPEMD320_STEP (RIPEMD320_F , d1, e1, a1, b1, c1, w1[3], RIPEMD320C00, RIPEMD320S07); + RIPEMD320_STEP (RIPEMD320_F , c1, d1, e1, a1, b1, w2[0], RIPEMD320C00, RIPEMD320S08); + RIPEMD320_STEP (RIPEMD320_F , b1, c1, d1, e1, a1, w2[1], RIPEMD320C00, RIPEMD320S09); + RIPEMD320_STEP (RIPEMD320_F , a1, b1, c1, d1, e1, w2[2], RIPEMD320C00, RIPEMD320S0A); + RIPEMD320_STEP (RIPEMD320_F , e1, a1, b1, c1, d1, w2[3], RIPEMD320C00, RIPEMD320S0B); + RIPEMD320_STEP (RIPEMD320_F , d1, e1, a1, b1, c1, w3[0], RIPEMD320C00, RIPEMD320S0C); + RIPEMD320_STEP (RIPEMD320_F , c1, d1, e1, a1, b1, w3[1], RIPEMD320C00, RIPEMD320S0D); + RIPEMD320_STEP (RIPEMD320_F , b1, c1, d1, e1, a1, w3[2], RIPEMD320C00, RIPEMD320S0E); + RIPEMD320_STEP (RIPEMD320_F , a1, b1, c1, d1, e1, w3[3], RIPEMD320C00, RIPEMD320S0F); + + RIPEMD320_STEP (RIPEMD320_J , a2, b2, c2, d2, e2, w1[1], RIPEMD320C50, RIPEMD320S50); + RIPEMD320_STEP (RIPEMD320_J , e2, a2, b2, c2, d2, w3[2], RIPEMD320C50, RIPEMD320S51); + RIPEMD320_STEP (RIPEMD320_J , d2, e2, a2, b2, c2, w1[3], RIPEMD320C50, RIPEMD320S52); + RIPEMD320_STEP (RIPEMD320_J , c2, d2, e2, a2, b2, w0[0], RIPEMD320C50, RIPEMD320S53); + RIPEMD320_STEP (RIPEMD320_J , b2, c2, d2, e2, a2, w2[1], RIPEMD320C50, RIPEMD320S54); + RIPEMD320_STEP (RIPEMD320_J , a2, b2, c2, d2, e2, w0[2], RIPEMD320C50, RIPEMD320S55); + RIPEMD320_STEP (RIPEMD320_J , e2, a2, b2, c2, d2, w2[3], RIPEMD320C50, RIPEMD320S56); + RIPEMD320_STEP (RIPEMD320_J , d2, e2, a2, b2, c2, w1[0], RIPEMD320C50, RIPEMD320S57); + RIPEMD320_STEP (RIPEMD320_J , c2, d2, e2, a2, b2, w3[1], RIPEMD320C50, RIPEMD320S58); + RIPEMD320_STEP (RIPEMD320_J , b2, c2, d2, e2, a2, w1[2], RIPEMD320C50, RIPEMD320S59); + RIPEMD320_STEP (RIPEMD320_J , a2, b2, c2, d2, e2, w3[3], RIPEMD320C50, RIPEMD320S5A); + RIPEMD320_STEP (RIPEMD320_J , e2, a2, b2, c2, d2, w2[0], RIPEMD320C50, RIPEMD320S5B); + RIPEMD320_STEP (RIPEMD320_J , d2, e2, a2, b2, c2, w0[1], RIPEMD320C50, RIPEMD320S5C); + RIPEMD320_STEP (RIPEMD320_J , c2, d2, e2, a2, b2, w2[2], RIPEMD320C50, RIPEMD320S5D); + RIPEMD320_STEP (RIPEMD320_J , b2, c2, d2, e2, a2, w0[3], RIPEMD320C50, RIPEMD320S5E); + RIPEMD320_STEP (RIPEMD320_J , a2, b2, c2, d2, e2, w3[0], RIPEMD320C50, RIPEMD320S5F); + + tmp = a1; a1 = a2; a2 = tmp; + + RIPEMD320_STEP (RIPEMD320_Go, e1, a1, b1, c1, d1, w1[3], RIPEMD320C10, RIPEMD320S10); + RIPEMD320_STEP (RIPEMD320_Go, d1, e1, a1, b1, c1, w1[0], RIPEMD320C10, RIPEMD320S11); + RIPEMD320_STEP (RIPEMD320_Go, c1, d1, e1, a1, b1, w3[1], RIPEMD320C10, RIPEMD320S12); + RIPEMD320_STEP (RIPEMD320_Go, b1, c1, d1, e1, a1, w0[1], RIPEMD320C10, RIPEMD320S13); + RIPEMD320_STEP (RIPEMD320_Go, a1, b1, c1, d1, e1, w2[2], RIPEMD320C10, RIPEMD320S14); + RIPEMD320_STEP (RIPEMD320_Go, e1, a1, b1, c1, d1, w1[2], RIPEMD320C10, RIPEMD320S15); + RIPEMD320_STEP (RIPEMD320_Go, d1, e1, a1, b1, c1, w3[3], RIPEMD320C10, RIPEMD320S16); + RIPEMD320_STEP (RIPEMD320_Go, c1, d1, e1, a1, b1, w0[3], RIPEMD320C10, RIPEMD320S17); + RIPEMD320_STEP (RIPEMD320_Go, b1, c1, d1, e1, a1, w3[0], RIPEMD320C10, RIPEMD320S18); + RIPEMD320_STEP (RIPEMD320_Go, a1, b1, c1, d1, e1, w0[0], RIPEMD320C10, RIPEMD320S19); + RIPEMD320_STEP (RIPEMD320_Go, e1, a1, b1, c1, d1, w2[1], RIPEMD320C10, RIPEMD320S1A); + RIPEMD320_STEP (RIPEMD320_Go, d1, e1, a1, b1, c1, w1[1], RIPEMD320C10, RIPEMD320S1B); + RIPEMD320_STEP (RIPEMD320_Go, c1, d1, e1, a1, b1, w0[2], RIPEMD320C10, RIPEMD320S1C); + RIPEMD320_STEP (RIPEMD320_Go, b1, c1, d1, e1, a1, w3[2], RIPEMD320C10, RIPEMD320S1D); + RIPEMD320_STEP (RIPEMD320_Go, a1, b1, c1, d1, e1, w2[3], RIPEMD320C10, RIPEMD320S1E); + RIPEMD320_STEP (RIPEMD320_Go, e1, a1, b1, c1, d1, w2[0], RIPEMD320C10, RIPEMD320S1F); + + RIPEMD320_STEP (RIPEMD320_Io, e2, a2, b2, c2, d2, w1[2], RIPEMD320C60, RIPEMD320S60); + RIPEMD320_STEP (RIPEMD320_Io, d2, e2, a2, b2, c2, w2[3], RIPEMD320C60, RIPEMD320S61); + RIPEMD320_STEP (RIPEMD320_Io, c2, d2, e2, a2, b2, w0[3], RIPEMD320C60, RIPEMD320S62); + RIPEMD320_STEP (RIPEMD320_Io, b2, c2, d2, e2, a2, w1[3], RIPEMD320C60, RIPEMD320S63); + RIPEMD320_STEP (RIPEMD320_Io, a2, b2, c2, d2, e2, w0[0], RIPEMD320C60, RIPEMD320S64); + RIPEMD320_STEP (RIPEMD320_Io, e2, a2, b2, c2, d2, w3[1], RIPEMD320C60, RIPEMD320S65); + RIPEMD320_STEP (RIPEMD320_Io, d2, e2, a2, b2, c2, w1[1], RIPEMD320C60, RIPEMD320S66); + RIPEMD320_STEP (RIPEMD320_Io, c2, d2, e2, a2, b2, w2[2], RIPEMD320C60, RIPEMD320S67); + RIPEMD320_STEP (RIPEMD320_Io, b2, c2, d2, e2, a2, w3[2], RIPEMD320C60, RIPEMD320S68); + RIPEMD320_STEP (RIPEMD320_Io, a2, b2, c2, d2, e2, w3[3], RIPEMD320C60, RIPEMD320S69); + RIPEMD320_STEP (RIPEMD320_Io, e2, a2, b2, c2, d2, w2[0], RIPEMD320C60, RIPEMD320S6A); + RIPEMD320_STEP (RIPEMD320_Io, d2, e2, a2, b2, c2, w3[0], RIPEMD320C60, RIPEMD320S6B); + RIPEMD320_STEP (RIPEMD320_Io, c2, d2, e2, a2, b2, w1[0], RIPEMD320C60, RIPEMD320S6C); + RIPEMD320_STEP (RIPEMD320_Io, b2, c2, d2, e2, a2, w2[1], RIPEMD320C60, RIPEMD320S6D); + RIPEMD320_STEP (RIPEMD320_Io, a2, b2, c2, d2, e2, w0[1], RIPEMD320C60, RIPEMD320S6E); + RIPEMD320_STEP (RIPEMD320_Io, e2, a2, b2, c2, d2, w0[2], RIPEMD320C60, RIPEMD320S6F); + + tmp = b1; b1 = b2; b2 = tmp; + + RIPEMD320_STEP (RIPEMD320_H , d1, e1, a1, b1, c1, w0[3], RIPEMD320C20, RIPEMD320S20); + RIPEMD320_STEP (RIPEMD320_H , c1, d1, e1, a1, b1, w2[2], RIPEMD320C20, RIPEMD320S21); + RIPEMD320_STEP (RIPEMD320_H , b1, c1, d1, e1, a1, w3[2], RIPEMD320C20, RIPEMD320S22); + RIPEMD320_STEP (RIPEMD320_H , a1, b1, c1, d1, e1, w1[0], RIPEMD320C20, RIPEMD320S23); + RIPEMD320_STEP (RIPEMD320_H , e1, a1, b1, c1, d1, w2[1], RIPEMD320C20, RIPEMD320S24); + RIPEMD320_STEP (RIPEMD320_H , d1, e1, a1, b1, c1, w3[3], RIPEMD320C20, RIPEMD320S25); + RIPEMD320_STEP (RIPEMD320_H , c1, d1, e1, a1, b1, w2[0], RIPEMD320C20, RIPEMD320S26); + RIPEMD320_STEP (RIPEMD320_H , b1, c1, d1, e1, a1, w0[1], RIPEMD320C20, RIPEMD320S27); + RIPEMD320_STEP (RIPEMD320_H , a1, b1, c1, d1, e1, w0[2], RIPEMD320C20, RIPEMD320S28); + RIPEMD320_STEP (RIPEMD320_H , e1, a1, b1, c1, d1, w1[3], RIPEMD320C20, RIPEMD320S29); + RIPEMD320_STEP (RIPEMD320_H , d1, e1, a1, b1, c1, w0[0], RIPEMD320C20, RIPEMD320S2A); + RIPEMD320_STEP (RIPEMD320_H , c1, d1, e1, a1, b1, w1[2], RIPEMD320C20, RIPEMD320S2B); + RIPEMD320_STEP (RIPEMD320_H , b1, c1, d1, e1, a1, w3[1], RIPEMD320C20, RIPEMD320S2C); + RIPEMD320_STEP (RIPEMD320_H , a1, b1, c1, d1, e1, w2[3], RIPEMD320C20, RIPEMD320S2D); + RIPEMD320_STEP (RIPEMD320_H , e1, a1, b1, c1, d1, w1[1], RIPEMD320C20, RIPEMD320S2E); + RIPEMD320_STEP (RIPEMD320_H , d1, e1, a1, b1, c1, w3[0], RIPEMD320C20, RIPEMD320S2F); + + RIPEMD320_STEP (RIPEMD320_H , d2, e2, a2, b2, c2, w3[3], RIPEMD320C70, RIPEMD320S70); + RIPEMD320_STEP (RIPEMD320_H , c2, d2, e2, a2, b2, w1[1], RIPEMD320C70, RIPEMD320S71); + RIPEMD320_STEP (RIPEMD320_H , b2, c2, d2, e2, a2, w0[1], RIPEMD320C70, RIPEMD320S72); + RIPEMD320_STEP (RIPEMD320_H , a2, b2, c2, d2, e2, w0[3], RIPEMD320C70, RIPEMD320S73); + RIPEMD320_STEP (RIPEMD320_H , e2, a2, b2, c2, d2, w1[3], RIPEMD320C70, RIPEMD320S74); + RIPEMD320_STEP (RIPEMD320_H , d2, e2, a2, b2, c2, w3[2], RIPEMD320C70, RIPEMD320S75); + RIPEMD320_STEP (RIPEMD320_H , c2, d2, e2, a2, b2, w1[2], RIPEMD320C70, RIPEMD320S76); + RIPEMD320_STEP (RIPEMD320_H , b2, c2, d2, e2, a2, w2[1], RIPEMD320C70, RIPEMD320S77); + RIPEMD320_STEP (RIPEMD320_H , a2, b2, c2, d2, e2, w2[3], RIPEMD320C70, RIPEMD320S78); + RIPEMD320_STEP (RIPEMD320_H , e2, a2, b2, c2, d2, w2[0], RIPEMD320C70, RIPEMD320S79); + RIPEMD320_STEP (RIPEMD320_H , d2, e2, a2, b2, c2, w3[0], RIPEMD320C70, RIPEMD320S7A); + RIPEMD320_STEP (RIPEMD320_H , c2, d2, e2, a2, b2, w0[2], RIPEMD320C70, RIPEMD320S7B); + RIPEMD320_STEP (RIPEMD320_H , b2, c2, d2, e2, a2, w2[2], RIPEMD320C70, RIPEMD320S7C); + RIPEMD320_STEP (RIPEMD320_H , a2, b2, c2, d2, e2, w0[0], RIPEMD320C70, RIPEMD320S7D); + RIPEMD320_STEP (RIPEMD320_H , e2, a2, b2, c2, d2, w1[0], RIPEMD320C70, RIPEMD320S7E); + RIPEMD320_STEP (RIPEMD320_H , d2, e2, a2, b2, c2, w3[1], RIPEMD320C70, RIPEMD320S7F); + + tmp = c1; c1 = c2; c2 = tmp; + + RIPEMD320_STEP (RIPEMD320_Io, c1, d1, e1, a1, b1, w0[1], RIPEMD320C30, RIPEMD320S30); + RIPEMD320_STEP (RIPEMD320_Io, b1, c1, d1, e1, a1, w2[1], RIPEMD320C30, RIPEMD320S31); + RIPEMD320_STEP (RIPEMD320_Io, a1, b1, c1, d1, e1, w2[3], RIPEMD320C30, RIPEMD320S32); + RIPEMD320_STEP (RIPEMD320_Io, e1, a1, b1, c1, d1, w2[2], RIPEMD320C30, RIPEMD320S33); + RIPEMD320_STEP (RIPEMD320_Io, d1, e1, a1, b1, c1, w0[0], RIPEMD320C30, RIPEMD320S34); + RIPEMD320_STEP (RIPEMD320_Io, c1, d1, e1, a1, b1, w2[0], RIPEMD320C30, RIPEMD320S35); + RIPEMD320_STEP (RIPEMD320_Io, b1, c1, d1, e1, a1, w3[0], RIPEMD320C30, RIPEMD320S36); + RIPEMD320_STEP (RIPEMD320_Io, a1, b1, c1, d1, e1, w1[0], RIPEMD320C30, RIPEMD320S37); + RIPEMD320_STEP (RIPEMD320_Io, e1, a1, b1, c1, d1, w3[1], RIPEMD320C30, RIPEMD320S38); + RIPEMD320_STEP (RIPEMD320_Io, d1, e1, a1, b1, c1, w0[3], RIPEMD320C30, RIPEMD320S39); + RIPEMD320_STEP (RIPEMD320_Io, c1, d1, e1, a1, b1, w1[3], RIPEMD320C30, RIPEMD320S3A); + RIPEMD320_STEP (RIPEMD320_Io, b1, c1, d1, e1, a1, w3[3], RIPEMD320C30, RIPEMD320S3B); + RIPEMD320_STEP (RIPEMD320_Io, a1, b1, c1, d1, e1, w3[2], RIPEMD320C30, RIPEMD320S3C); + RIPEMD320_STEP (RIPEMD320_Io, e1, a1, b1, c1, d1, w1[1], RIPEMD320C30, RIPEMD320S3D); + RIPEMD320_STEP (RIPEMD320_Io, d1, e1, a1, b1, c1, w1[2], RIPEMD320C30, RIPEMD320S3E); + RIPEMD320_STEP (RIPEMD320_Io, c1, d1, e1, a1, b1, w0[2], RIPEMD320C30, RIPEMD320S3F); + + RIPEMD320_STEP (RIPEMD320_Go, c2, d2, e2, a2, b2, w2[0], RIPEMD320C80, RIPEMD320S80); + RIPEMD320_STEP (RIPEMD320_Go, b2, c2, d2, e2, a2, w1[2], RIPEMD320C80, RIPEMD320S81); + RIPEMD320_STEP (RIPEMD320_Go, a2, b2, c2, d2, e2, w1[0], RIPEMD320C80, RIPEMD320S82); + RIPEMD320_STEP (RIPEMD320_Go, e2, a2, b2, c2, d2, w0[1], RIPEMD320C80, RIPEMD320S83); + RIPEMD320_STEP (RIPEMD320_Go, d2, e2, a2, b2, c2, w0[3], RIPEMD320C80, RIPEMD320S84); + RIPEMD320_STEP (RIPEMD320_Go, c2, d2, e2, a2, b2, w2[3], RIPEMD320C80, RIPEMD320S85); + RIPEMD320_STEP (RIPEMD320_Go, b2, c2, d2, e2, a2, w3[3], RIPEMD320C80, RIPEMD320S86); + RIPEMD320_STEP (RIPEMD320_Go, a2, b2, c2, d2, e2, w0[0], RIPEMD320C80, RIPEMD320S87); + RIPEMD320_STEP (RIPEMD320_Go, e2, a2, b2, c2, d2, w1[1], RIPEMD320C80, RIPEMD320S88); + RIPEMD320_STEP (RIPEMD320_Go, d2, e2, a2, b2, c2, w3[0], RIPEMD320C80, RIPEMD320S89); + RIPEMD320_STEP (RIPEMD320_Go, c2, d2, e2, a2, b2, w0[2], RIPEMD320C80, RIPEMD320S8A); + RIPEMD320_STEP (RIPEMD320_Go, b2, c2, d2, e2, a2, w3[1], RIPEMD320C80, RIPEMD320S8B); + RIPEMD320_STEP (RIPEMD320_Go, a2, b2, c2, d2, e2, w2[1], RIPEMD320C80, RIPEMD320S8C); + RIPEMD320_STEP (RIPEMD320_Go, e2, a2, b2, c2, d2, w1[3], RIPEMD320C80, RIPEMD320S8D); + RIPEMD320_STEP (RIPEMD320_Go, d2, e2, a2, b2, c2, w2[2], RIPEMD320C80, RIPEMD320S8E); + RIPEMD320_STEP (RIPEMD320_Go, c2, d2, e2, a2, b2, w3[2], RIPEMD320C80, RIPEMD320S8F); + + tmp = d1; d1 = d2; d2 = tmp; + + RIPEMD320_STEP (RIPEMD320_J , b1, c1, d1, e1, a1, w1[0], RIPEMD320C40, RIPEMD320S40); + RIPEMD320_STEP (RIPEMD320_J , a1, b1, c1, d1, e1, w0[0], RIPEMD320C40, RIPEMD320S41); + RIPEMD320_STEP (RIPEMD320_J , e1, a1, b1, c1, d1, w1[1], RIPEMD320C40, RIPEMD320S42); + RIPEMD320_STEP (RIPEMD320_J , d1, e1, a1, b1, c1, w2[1], RIPEMD320C40, RIPEMD320S43); + RIPEMD320_STEP (RIPEMD320_J , c1, d1, e1, a1, b1, w1[3], RIPEMD320C40, RIPEMD320S44); + RIPEMD320_STEP (RIPEMD320_J , b1, c1, d1, e1, a1, w3[0], RIPEMD320C40, RIPEMD320S45); + RIPEMD320_STEP (RIPEMD320_J , a1, b1, c1, d1, e1, w0[2], RIPEMD320C40, RIPEMD320S46); + RIPEMD320_STEP (RIPEMD320_J , e1, a1, b1, c1, d1, w2[2], RIPEMD320C40, RIPEMD320S47); + RIPEMD320_STEP (RIPEMD320_J , d1, e1, a1, b1, c1, w3[2], RIPEMD320C40, RIPEMD320S48); + RIPEMD320_STEP (RIPEMD320_J , c1, d1, e1, a1, b1, w0[1], RIPEMD320C40, RIPEMD320S49); + RIPEMD320_STEP (RIPEMD320_J , b1, c1, d1, e1, a1, w0[3], RIPEMD320C40, RIPEMD320S4A); + RIPEMD320_STEP (RIPEMD320_J , a1, b1, c1, d1, e1, w2[0], RIPEMD320C40, RIPEMD320S4B); + RIPEMD320_STEP (RIPEMD320_J , e1, a1, b1, c1, d1, w2[3], RIPEMD320C40, RIPEMD320S4C); + RIPEMD320_STEP (RIPEMD320_J , d1, e1, a1, b1, c1, w1[2], RIPEMD320C40, RIPEMD320S4D); + RIPEMD320_STEP (RIPEMD320_J , c1, d1, e1, a1, b1, w3[3], RIPEMD320C40, RIPEMD320S4E); + RIPEMD320_STEP (RIPEMD320_J , b1, c1, d1, e1, a1, w3[1], RIPEMD320C40, RIPEMD320S4F); + + RIPEMD320_STEP (RIPEMD320_F , b2, c2, d2, e2, a2, w3[0], RIPEMD320C90, RIPEMD320S90); + RIPEMD320_STEP (RIPEMD320_F , a2, b2, c2, d2, e2, w3[3], RIPEMD320C90, RIPEMD320S91); + RIPEMD320_STEP (RIPEMD320_F , e2, a2, b2, c2, d2, w2[2], RIPEMD320C90, RIPEMD320S92); + RIPEMD320_STEP (RIPEMD320_F , d2, e2, a2, b2, c2, w1[0], RIPEMD320C90, RIPEMD320S93); + RIPEMD320_STEP (RIPEMD320_F , c2, d2, e2, a2, b2, w0[1], RIPEMD320C90, RIPEMD320S94); + RIPEMD320_STEP (RIPEMD320_F , b2, c2, d2, e2, a2, w1[1], RIPEMD320C90, RIPEMD320S95); + RIPEMD320_STEP (RIPEMD320_F , a2, b2, c2, d2, e2, w2[0], RIPEMD320C90, RIPEMD320S96); + RIPEMD320_STEP (RIPEMD320_F , e2, a2, b2, c2, d2, w1[3], RIPEMD320C90, RIPEMD320S97); + RIPEMD320_STEP (RIPEMD320_F , d2, e2, a2, b2, c2, w1[2], RIPEMD320C90, RIPEMD320S98); + RIPEMD320_STEP (RIPEMD320_F , c2, d2, e2, a2, b2, w0[2], RIPEMD320C90, RIPEMD320S99); + RIPEMD320_STEP (RIPEMD320_F , b2, c2, d2, e2, a2, w3[1], RIPEMD320C90, RIPEMD320S9A); + RIPEMD320_STEP (RIPEMD320_F , a2, b2, c2, d2, e2, w3[2], RIPEMD320C90, RIPEMD320S9B); + RIPEMD320_STEP (RIPEMD320_F , e2, a2, b2, c2, d2, w0[0], RIPEMD320C90, RIPEMD320S9C); + RIPEMD320_STEP (RIPEMD320_F , d2, e2, a2, b2, c2, w0[3], RIPEMD320C90, RIPEMD320S9D); + RIPEMD320_STEP (RIPEMD320_F , c2, d2, e2, a2, b2, w2[1], RIPEMD320C90, RIPEMD320S9E); + RIPEMD320_STEP (RIPEMD320_F , b2, c2, d2, e2, a2, w2[3], RIPEMD320C90, RIPEMD320S9F); + + tmp = e1; e1 = e2; e2 = tmp; + + const u32x a = digest[0] + a1; + const u32x b = digest[1] + b1; + const u32x c = digest[2] + c1; + const u32x d = digest[3] + d1; + const u32x e = digest[4] + e1; + const u32x f = digest[5] + a2; + const u32x g = digest[6] + b2; + const u32x h = digest[7] + c2; + const u32x i = digest[8] + d2; + const u32x l = digest[9] + e2; + + digest[0] = a; + digest[1] = b; + digest[2] = c; + digest[3] = d; + digest[4] = e; + digest[5] = f; + digest[6] = g; + digest[7] = h; + digest[8] = i; + digest[9] = l; +} + +DECLSPEC void ripemd320_init_vector (PRIVATE_AS ripemd320_ctx_vector_t *ctx) +{ + ctx->h[0] = RIPEMD320M_A; + ctx->h[1] = RIPEMD320M_B; + ctx->h[2] = RIPEMD320M_C; + ctx->h[3] = RIPEMD320M_D; + ctx->h[4] = RIPEMD320M_E; + ctx->h[5] = RIPEMD320M_F; + ctx->h[6] = RIPEMD320M_G; + ctx->h[7] = RIPEMD320M_H; + ctx->h[8] = RIPEMD320M_I; + ctx->h[9] = RIPEMD320M_L; + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + + ctx->len = 0; +} + +DECLSPEC void ripemd320_init_vector_from_scalar (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS ripemd320_ctx_t *ctx0) +{ + ctx->h[0] = ctx0->h[0]; + ctx->h[1] = ctx0->h[1]; + ctx->h[2] = ctx0->h[2]; + ctx->h[3] = ctx0->h[3]; + ctx->h[4] = ctx0->h[4]; + ctx->h[5] = ctx0->h[5]; + ctx->h[6] = ctx0->h[6]; + ctx->h[7] = ctx0->h[7]; + ctx->h[8] = ctx0->h[8]; + ctx->h[9] = ctx0->h[9]; + + ctx->w0[0] = ctx0->w0[0]; + ctx->w0[1] = ctx0->w0[1]; + ctx->w0[2] = ctx0->w0[2]; + ctx->w0[3] = ctx0->w0[3]; + ctx->w1[0] = ctx0->w1[0]; + ctx->w1[1] = ctx0->w1[1]; + ctx->w1[2] = ctx0->w1[2]; + ctx->w1[3] = ctx0->w1[3]; + ctx->w2[0] = ctx0->w2[0]; + ctx->w2[1] = ctx0->w2[1]; + ctx->w2[2] = ctx0->w2[2]; + ctx->w2[3] = ctx0->w2[3]; + ctx->w3[0] = ctx0->w3[0]; + ctx->w3[1] = ctx0->w3[1]; + ctx->w3[2] = ctx0->w3[2]; + ctx->w3[3] = ctx0->w3[3]; + + ctx->len = ctx0->len; +} + +DECLSPEC void ripemd320_update_vector_64 (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, const int len) +{ + if (len == 0) return; + + const int pos = ctx->len & 63; + + ctx->len += len; + + if (pos == 0) + { + ctx->w0[0] = w0[0]; + ctx->w0[1] = w0[1]; + ctx->w0[2] = w0[2]; + ctx->w0[3] = w0[3]; + ctx->w1[0] = w1[0]; + ctx->w1[1] = w1[1]; + ctx->w1[2] = w1[2]; + ctx->w1[3] = w1[3]; + ctx->w2[0] = w2[0]; + ctx->w2[1] = w2[1]; + ctx->w2[2] = w2[2]; + ctx->w2[3] = w2[3]; + ctx->w3[0] = w3[0]; + ctx->w3[1] = w3[1]; + ctx->w3[2] = w3[2]; + ctx->w3[3] = w3[3]; + + if (len == 64) + { + ripemd320_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + } + } + else + { + if ((pos + len) < 64) + { + switch_buffer_by_offset_le (w0, w1, w2, w3, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + } + else + { + u32x c0[4] = { 0 }; + u32x c1[4] = { 0 }; + u32x c2[4] = { 0 }; + u32x c3[4] = { 0 }; + + switch_buffer_by_offset_carry_le (w0, w1, w2, w3, c0, c1, c2, c3, pos); + + ctx->w0[0] |= w0[0]; + ctx->w0[1] |= w0[1]; + ctx->w0[2] |= w0[2]; + ctx->w0[3] |= w0[3]; + ctx->w1[0] |= w1[0]; + ctx->w1[1] |= w1[1]; + ctx->w1[2] |= w1[2]; + ctx->w1[3] |= w1[3]; + ctx->w2[0] |= w2[0]; + ctx->w2[1] |= w2[1]; + ctx->w2[2] |= w2[2]; + ctx->w2[3] |= w2[3]; + ctx->w3[0] |= w3[0]; + ctx->w3[1] |= w3[1]; + ctx->w3[2] |= w3[2]; + ctx->w3[3] |= w3[3]; + + ripemd320_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); + + ctx->w0[0] = c0[0]; + ctx->w0[1] = c0[1]; + ctx->w0[2] = c0[2]; + ctx->w0[3] = c0[3]; + ctx->w1[0] = c1[0]; + ctx->w1[1] = c1[1]; + ctx->w1[2] = c1[2]; + ctx->w1[3] = c1[3]; + ctx->w2[0] = c2[0]; + ctx->w2[1] = c2[1]; + ctx->w2[2] = c2[2]; + ctx->w2[3] = c2[3]; + ctx->w3[0] = c3[0]; + ctx->w3[1] = c3[1]; + ctx->w3[2] = c3[2]; + ctx->w3[3] = c3[3]; + } + } +} + +DECLSPEC void ripemd320_update_vector (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, len - pos1); +} + +DECLSPEC void ripemd320_update_vector_swap (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32 (w0[0]); + w0[1] = hc_swap32 (w0[1]); + w0[2] = hc_swap32 (w0[2]); + w0[3] = hc_swap32 (w0[3]); + w1[0] = hc_swap32 (w1[0]); + w1[1] = hc_swap32 (w1[1]); + w1[2] = hc_swap32 (w1[2]); + w1[3] = hc_swap32 (w1[3]); + w2[0] = hc_swap32 (w2[0]); + w2[1] = hc_swap32 (w2[1]); + w2[2] = hc_swap32 (w2[2]); + w2[3] = hc_swap32 (w2[3]); + w3[0] = hc_swap32 (w3[0]); + w3[1] = hc_swap32 (w3[1]); + w3[2] = hc_swap32 (w3[2]); + w3[3] = hc_swap32 (w3[3]); + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, 64); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + w2[0] = w[pos4 + 8]; + w2[1] = w[pos4 + 9]; + w2[2] = w[pos4 + 10]; + w2[3] = w[pos4 + 11]; + w3[0] = w[pos4 + 12]; + w3[1] = w[pos4 + 13]; + w3[2] = w[pos4 + 14]; + w3[3] = w[pos4 + 15]; + + w0[0] = hc_swap32 (w0[0]); + w0[1] = hc_swap32 (w0[1]); + w0[2] = hc_swap32 (w0[2]); + w0[3] = hc_swap32 (w0[3]); + w1[0] = hc_swap32 (w1[0]); + w1[1] = hc_swap32 (w1[1]); + w1[2] = hc_swap32 (w1[2]); + w1[3] = hc_swap32 (w1[3]); + w2[0] = hc_swap32 (w2[0]); + w2[1] = hc_swap32 (w2[1]); + w2[2] = hc_swap32 (w2[2]); + w2[3] = hc_swap32 (w2[3]); + w3[0] = hc_swap32 (w3[0]); + w3[1] = hc_swap32 (w3[1]); + w3[2] = hc_swap32 (w3[2]); + w3[3] = hc_swap32 (w3[3]); + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, len - pos1); +} + +DECLSPEC void ripemd320_update_vector_utf16le (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le (w1, w2, w3); + make_utf16le (w0, w0, w1); + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, 32 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le (w1, w2, w3); + make_utf16le (w0, w0, w1); + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2); +} + +DECLSPEC void ripemd320_update_vector_utf16le_swap (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + int pos1; + int pos4; + + for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8) + { + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le (w1, w2, w3); + make_utf16le (w0, w0, w1); + + w0[0] = hc_swap32 (w0[0]); + w0[1] = hc_swap32 (w0[1]); + w0[2] = hc_swap32 (w0[2]); + w0[3] = hc_swap32 (w0[3]); + w1[0] = hc_swap32 (w1[0]); + w1[1] = hc_swap32 (w1[1]); + w1[2] = hc_swap32 (w1[2]); + w1[3] = hc_swap32 (w1[3]); + w2[0] = hc_swap32 (w2[0]); + w2[1] = hc_swap32 (w2[1]); + w2[2] = hc_swap32 (w2[2]); + w2[3] = hc_swap32 (w2[3]); + w3[0] = hc_swap32 (w3[0]); + w3[1] = hc_swap32 (w3[1]); + w3[2] = hc_swap32 (w3[2]); + w3[3] = hc_swap32 (w3[3]); + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, 32 * 2); + } + + w0[0] = w[pos4 + 0]; + w0[1] = w[pos4 + 1]; + w0[2] = w[pos4 + 2]; + w0[3] = w[pos4 + 3]; + w1[0] = w[pos4 + 4]; + w1[1] = w[pos4 + 5]; + w1[2] = w[pos4 + 6]; + w1[3] = w[pos4 + 7]; + + make_utf16le (w1, w2, w3); + make_utf16le (w0, w0, w1); + + w0[0] = hc_swap32 (w0[0]); + w0[1] = hc_swap32 (w0[1]); + w0[2] = hc_swap32 (w0[2]); + w0[3] = hc_swap32 (w0[3]); + w1[0] = hc_swap32 (w1[0]); + w1[1] = hc_swap32 (w1[1]); + w1[2] = hc_swap32 (w1[2]); + w1[3] = hc_swap32 (w1[3]); + w2[0] = hc_swap32 (w2[0]); + w2[1] = hc_swap32 (w2[1]); + w2[2] = hc_swap32 (w2[2]); + w2[3] = hc_swap32 (w2[3]); + w3[0] = hc_swap32 (w3[0]); + w3[1] = hc_swap32 (w3[1]); + w3[2] = hc_swap32 (w3[2]); + w3[3] = hc_swap32 (w3[3]); + + ripemd320_update_vector_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2); +} + +DECLSPEC void ripemd320_final_vector (PRIVATE_AS ripemd320_ctx_vector_t *ctx) +{ + const int pos = ctx->len & 63; + + append_0x80_4x4 (ctx->w0, ctx->w1, ctx->w2, ctx->w3, pos); + + if (pos >= 56) + { + ripemd320_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); + + ctx->w0[0] = 0; + ctx->w0[1] = 0; + ctx->w0[2] = 0; + ctx->w0[3] = 0; + ctx->w1[0] = 0; + ctx->w1[1] = 0; + ctx->w1[2] = 0; + ctx->w1[3] = 0; + ctx->w2[0] = 0; + ctx->w2[1] = 0; + ctx->w2[2] = 0; + ctx->w2[3] = 0; + ctx->w3[0] = 0; + ctx->w3[1] = 0; + ctx->w3[2] = 0; + ctx->w3[3] = 0; + } + + ctx->w3[2] = ctx->len * 8; + ctx->w3[3] = 0; + + ripemd320_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h); +} + +// HMAC + Vector + +DECLSPEC void ripemd320_hmac_init_vector_64 (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w0, PRIVATE_AS const u32x *w1, PRIVATE_AS const u32x *w2, PRIVATE_AS const u32x *w3) +{ + u32x a0[4]; + u32x a1[4]; + u32x a2[4]; + u32x a3[4]; + + // ipad + + a0[0] = w0[0] ^ 0x36363636; + a0[1] = w0[1] ^ 0x36363636; + a0[2] = w0[2] ^ 0x36363636; + a0[3] = w0[3] ^ 0x36363636; + a1[0] = w1[0] ^ 0x36363636; + a1[1] = w1[1] ^ 0x36363636; + a1[2] = w1[2] ^ 0x36363636; + a1[3] = w1[3] ^ 0x36363636; + a2[0] = w2[0] ^ 0x36363636; + a2[1] = w2[1] ^ 0x36363636; + a2[2] = w2[2] ^ 0x36363636; + a2[3] = w2[3] ^ 0x36363636; + a3[0] = w3[0] ^ 0x36363636; + a3[1] = w3[1] ^ 0x36363636; + a3[2] = w3[2] ^ 0x36363636; + a3[3] = w3[3] ^ 0x36363636; + + ripemd320_init_vector (&ctx->ipad); + + ripemd320_update_vector_64 (&ctx->ipad, a0, a1, a2, a3, 64); + + // opad + + u32x b0[4]; + u32x b1[4]; + u32x b2[4]; + u32x b3[4]; + + b0[0] = w0[0] ^ 0x5c5c5c5c; + b0[1] = w0[1] ^ 0x5c5c5c5c; + b0[2] = w0[2] ^ 0x5c5c5c5c; + b0[3] = w0[3] ^ 0x5c5c5c5c; + b1[0] = w1[0] ^ 0x5c5c5c5c; + b1[1] = w1[1] ^ 0x5c5c5c5c; + b1[2] = w1[2] ^ 0x5c5c5c5c; + b1[3] = w1[3] ^ 0x5c5c5c5c; + b2[0] = w2[0] ^ 0x5c5c5c5c; + b2[1] = w2[1] ^ 0x5c5c5c5c; + b2[2] = w2[2] ^ 0x5c5c5c5c; + b2[3] = w2[3] ^ 0x5c5c5c5c; + b3[0] = w3[0] ^ 0x5c5c5c5c; + b3[1] = w3[1] ^ 0x5c5c5c5c; + b3[2] = w3[2] ^ 0x5c5c5c5c; + b3[3] = w3[3] ^ 0x5c5c5c5c; + + ripemd320_init_vector (&ctx->opad); + + ripemd320_update_vector_64 (&ctx->opad, b0, b1, b2, b3, 64); +} + +DECLSPEC void ripemd320_hmac_init_vector (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + if (len > 64) + { + ripemd320_ctx_vector_t tmp; + + ripemd320_init_vector (&tmp); + + ripemd320_update_vector (&tmp, w, len); + + ripemd320_final_vector (&tmp); + + w0[0] = tmp.h[0]; + w0[1] = tmp.h[1]; + w0[2] = tmp.h[2]; + w0[3] = tmp.h[3]; + w1[0] = tmp.h[4]; + w1[1] = tmp.h[5]; + w1[2] = tmp.h[6]; + w1[3] = tmp.h[7]; + w2[0] = tmp.h[8]; + w2[1] = tmp.h[9]; + w2[2] = 0; + w2[3] = 0; + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + } + else + { + w0[0] = w[ 0]; + w0[1] = w[ 1]; + w0[2] = w[ 2]; + w0[3] = w[ 3]; + w1[0] = w[ 4]; + w1[1] = w[ 5]; + w1[2] = w[ 6]; + w1[3] = w[ 7]; + w2[0] = w[ 8]; + w2[1] = w[ 9]; + w2[2] = w[10]; + w2[3] = w[11]; + w3[0] = w[12]; + w3[1] = w[13]; + w3[2] = w[14]; + w3[3] = w[15]; + } + + ripemd320_hmac_init_vector_64 (ctx, w0, w1, w2, w3); +} + +DECLSPEC void ripemd320_hmac_update_vector_64 (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, const int len) +{ + ripemd320_update_vector_64 (&ctx->ipad, w0, w1, w2, w3, len); +} + +DECLSPEC void ripemd320_hmac_update_vector (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) +{ + ripemd320_update_vector (&ctx->ipad, w, len); +} + +DECLSPEC void ripemd320_hmac_final_vector (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx) +{ + ripemd320_final_vector (&ctx->ipad); + + ctx->opad.w0[0] = ctx->ipad.h[0]; + ctx->opad.w0[1] = ctx->ipad.h[1]; + ctx->opad.w0[2] = ctx->ipad.h[2]; + ctx->opad.w0[3] = ctx->ipad.h[3]; + ctx->opad.w1[0] = ctx->ipad.h[4]; + ctx->opad.w1[1] = ctx->ipad.h[5]; + ctx->opad.w1[2] = ctx->ipad.h[6]; + ctx->opad.w1[3] = ctx->ipad.h[7]; + ctx->opad.w2[0] = ctx->ipad.h[8]; + ctx->opad.w2[1] = ctx->ipad.h[9]; + ctx->opad.w2[2] = 0; + ctx->opad.w2[3] = 0; + ctx->opad.w3[0] = 0; + ctx->opad.w3[1] = 0; + ctx->opad.w3[2] = 0; + ctx->opad.w3[3] = 0; + + ctx->opad.len += 40; + + ripemd320_final_vector (&ctx->opad); +} diff --git a/OpenCL/inc_hash_ripemd320.h b/OpenCL/inc_hash_ripemd320.h new file mode 100644 index 000000000..e9737bb94 --- /dev/null +++ b/OpenCL/inc_hash_ripemd320.h @@ -0,0 +1,147 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#ifndef INC_HASH_RIPEMD320_H +#define INC_HASH_RIPEMD320_H + +#define RIPEMD320_F(x,y,z) ((x) ^ (y) ^ (z)) +#define RIPEMD320_G(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) /* x ? y : z */ +#define RIPEMD320_H(x,y,z) (((x) | ~(y)) ^ (z)) +#define RIPEMD320_I(x,y,z) ((y) ^ ((z) & ((x) ^ (y)))) /* z ? x : y */ +#define RIPEMD320_J(x,y,z) ((x) ^ ((y) | ~(z))) + +#ifdef USE_BITSELECT +#define RIPEMD320_Go(x,y,z) (bitselect ((z), (y), (x))) +#define RIPEMD320_Io(x,y,z) (bitselect ((y), (x), (z))) +#else +#define RIPEMD320_Go(x,y,z) (RIPEMD320_G ((x), (y), (z))) +#define RIPEMD320_Io(x,y,z) (RIPEMD320_I ((x), (y), (z))) +#endif + +#define RIPEMD320_STEP_S(f,a,b,c,d,e,x,K,s) \ +{ \ + a += K; \ + a += x; \ + a += f (b, c, d); \ + a = hc_rotl32_S (a, s); \ + a += e; \ + c = hc_rotl32_S (c, 10u); \ +} + +#define RIPEMD320_STEP(f,a,b,c,d,e,x,K,s) \ +{ \ + a += make_u32x (K); \ + a += x; \ + a += f (b, c, d); \ + a = hc_rotl32 (a, s); \ + a += e; \ + c = hc_rotl32 (c, 10u); \ +} + +#define ROTATE_LEFT_WORKAROUND_BUG(a,n) ((a << n) | (a >> (32 - n))) + +#define RIPEMD320_STEP_S_WORKAROUND_BUG(f,a,b,c,d,e,x,K,s) \ +{ \ + a += K; \ + a += x; \ + a += f (b, c, d); \ + a = ROTATE_LEFT_WORKAROUND_BUG (a, s); \ + a += e; \ + c = hc_rotl32_S (c, 10u); \ +} + +#define RIPEMD320_STEP_WORKAROUND_BUG(f,a,b,c,d,e,x,K,s) \ +{ \ + a += make_u32x (K); \ + a += x; \ + a += f (b, c, d); \ + a = ROTATE_LEFT_WORKAROUND_BUG (a, s); \ + a += e; \ + c = hc_rotl32 (c, 10u); \ +} + +typedef struct ripemd320_ctx +{ + u32 h[10]; + + u32 w0[4]; + u32 w1[4]; + u32 w2[4]; + u32 w3[4]; + + int len; + +} ripemd320_ctx_t; + +typedef struct ripemd320_hmac_ctx +{ + ripemd320_ctx_t ipad; + ripemd320_ctx_t opad; + +} ripemd320_hmac_ctx_t; + +typedef struct ripemd320_ctx_vector +{ + u32x h[10]; + + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + int len; + +} ripemd320_ctx_vector_t; + +typedef struct ripemd320_hmac_ctx_vector +{ + ripemd320_ctx_vector_t ipad; + ripemd320_ctx_vector_t opad; + +} ripemd320_hmac_ctx_vector_t; + +DECLSPEC void ripemd320_transform (PRIVATE_AS const u32 *w0, PRIVATE_AS const u32 *w1, PRIVATE_AS const u32 *w2, PRIVATE_AS const u32 *w3, PRIVATE_AS u32 *digest); +DECLSPEC void ripemd320_init (PRIVATE_AS ripemd320_ctx_t *ctx); +DECLSPEC void ripemd320_update_64 (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const int len); +DECLSPEC void ripemd320_update (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_update_swap (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_update_utf16le (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_update_utf16le_swap (PRIVATE_AS ripemd320_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_update_global (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_update_global_swap (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_update_global_utf16le (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_update_global_utf16le_swap (PRIVATE_AS ripemd320_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_final (PRIVATE_AS ripemd320_ctx_t *ctx); +DECLSPEC void ripemd320_hmac_init_64 (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w0, PRIVATE_AS const u32 *w1, PRIVATE_AS const u32 *w2, PRIVATE_AS const u32 *w3); +DECLSPEC void ripemd320_hmac_init (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_init_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_init_global (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_init_global_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_64 (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const int len); +DECLSPEC void ripemd320_hmac_update (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_utf16le (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_utf16le_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_global (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_global_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_global_utf16le (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_update_global_utf16le_swap (PRIVATE_AS ripemd320_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); +DECLSPEC void ripemd320_hmac_final (PRIVATE_AS ripemd320_hmac_ctx_t *ctx); +DECLSPEC void ripemd320_transform_vector (PRIVATE_AS const u32x *w0, PRIVATE_AS const u32x *w1, PRIVATE_AS const u32x *w2, PRIVATE_AS const u32x *w3, PRIVATE_AS u32x *digest); +DECLSPEC void ripemd320_init_vector (PRIVATE_AS ripemd320_ctx_vector_t *ctx); +DECLSPEC void ripemd320_init_vector_from_scalar (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS ripemd320_ctx_t *ctx0); +DECLSPEC void ripemd320_update_vector_64 (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, const int len); +DECLSPEC void ripemd320_update_vector (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void ripemd320_update_vector_swap (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void ripemd320_update_vector_utf16le (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void ripemd320_update_vector_utf16le_swap (PRIVATE_AS ripemd320_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void ripemd320_final_vector (PRIVATE_AS ripemd320_ctx_vector_t *ctx); +DECLSPEC void ripemd320_hmac_init_vector_64 (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w0, PRIVATE_AS const u32x *w1, PRIVATE_AS const u32x *w2, PRIVATE_AS const u32x *w3); +DECLSPEC void ripemd320_hmac_init_vector (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void ripemd320_hmac_update_vector_64 (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, const int len); +DECLSPEC void ripemd320_hmac_update_vector (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); +DECLSPEC void ripemd320_hmac_final_vector (PRIVATE_AS ripemd320_hmac_ctx_vector_t *ctx); + +#endif // INC_HASH_RIPEMD320_H diff --git a/OpenCL/inc_types.h b/OpenCL/inc_types.h index 4d7b937d5..233e28958 100644 --- a/OpenCL/inc_types.h +++ b/OpenCL/inc_types.h @@ -1565,6 +1565,202 @@ typedef enum ripemd160_constants } ripemd160_constants_t; +typedef enum ripemd320_constants +{ + RIPEMD320M_A=0x67452301U, + RIPEMD320M_B=0xefcdab89U, + RIPEMD320M_C=0x98badcfeU, + RIPEMD320M_D=0x10325476U, + RIPEMD320M_E=0xc3d2e1f0U, + RIPEMD320M_F=0x76543210U, + RIPEMD320M_G=0xfedcba98U, + RIPEMD320M_H=0x89abcdefU, + RIPEMD320M_I=0x01234567U, + RIPEMD320M_L=0x3c2d1e0fU, + + RIPEMD320C00=0x00000000U, + RIPEMD320C10=0x5a827999U, + RIPEMD320C20=0x6ed9eba1U, + RIPEMD320C30=0x8f1bbcdcU, + RIPEMD320C40=0xa953fd4eU, + RIPEMD320C50=0x50a28be6U, + RIPEMD320C60=0x5c4dd124U, + RIPEMD320C70=0x6d703ef3U, + RIPEMD320C80=0x7a6d76e9U, + RIPEMD320C90=0x00000000U, + + RIPEMD320S00=11, + RIPEMD320S01=14, + RIPEMD320S02=15, + RIPEMD320S03=12, + RIPEMD320S04=5, + RIPEMD320S05=8, + RIPEMD320S06=7, + RIPEMD320S07=9, + RIPEMD320S08=11, + RIPEMD320S09=13, + RIPEMD320S0A=14, + RIPEMD320S0B=15, + RIPEMD320S0C=6, + RIPEMD320S0D=7, + RIPEMD320S0E=9, + RIPEMD320S0F=8, + + RIPEMD320S10=7, + RIPEMD320S11=6, + RIPEMD320S12=8, + RIPEMD320S13=13, + RIPEMD320S14=11, + RIPEMD320S15=9, + RIPEMD320S16=7, + RIPEMD320S17=15, + RIPEMD320S18=7, + RIPEMD320S19=12, + RIPEMD320S1A=15, + RIPEMD320S1B=9, + RIPEMD320S1C=11, + RIPEMD320S1D=7, + RIPEMD320S1E=13, + RIPEMD320S1F=12, + + RIPEMD320S20=11, + RIPEMD320S21=13, + RIPEMD320S22=6, + RIPEMD320S23=7, + RIPEMD320S24=14, + RIPEMD320S25=9, + RIPEMD320S26=13, + RIPEMD320S27=15, + RIPEMD320S28=14, + RIPEMD320S29=8, + RIPEMD320S2A=13, + RIPEMD320S2B=6, + RIPEMD320S2C=5, + RIPEMD320S2D=12, + RIPEMD320S2E=7, + RIPEMD320S2F=5, + + RIPEMD320S30=11, + RIPEMD320S31=12, + RIPEMD320S32=14, + RIPEMD320S33=15, + RIPEMD320S34=14, + RIPEMD320S35=15, + RIPEMD320S36=9, + RIPEMD320S37=8, + RIPEMD320S38=9, + RIPEMD320S39=14, + RIPEMD320S3A=5, + RIPEMD320S3B=6, + RIPEMD320S3C=8, + RIPEMD320S3D=6, + RIPEMD320S3E=5, + RIPEMD320S3F=12, + + RIPEMD320S40=9, + RIPEMD320S41=15, + RIPEMD320S42=5, + RIPEMD320S43=11, + RIPEMD320S44=6, + RIPEMD320S45=8, + RIPEMD320S46=13, + RIPEMD320S47=12, + RIPEMD320S48=5, + RIPEMD320S49=12, + RIPEMD320S4A=13, + RIPEMD320S4B=14, + RIPEMD320S4C=11, + RIPEMD320S4D=8, + RIPEMD320S4E=5, + RIPEMD320S4F=6, + + RIPEMD320S50=8, + RIPEMD320S51=9, + RIPEMD320S52=9, + RIPEMD320S53=11, + RIPEMD320S54=13, + RIPEMD320S55=15, + RIPEMD320S56=15, + RIPEMD320S57=5, + RIPEMD320S58=7, + RIPEMD320S59=7, + RIPEMD320S5A=8, + RIPEMD320S5B=11, + RIPEMD320S5C=14, + RIPEMD320S5D=14, + RIPEMD320S5E=12, + RIPEMD320S5F=6, + + RIPEMD320S60=9, + RIPEMD320S61=13, + RIPEMD320S62=15, + RIPEMD320S63=7, + RIPEMD320S64=12, + RIPEMD320S65=8, + RIPEMD320S66=9, + RIPEMD320S67=11, + RIPEMD320S68=7, + RIPEMD320S69=7, + RIPEMD320S6A=12, + RIPEMD320S6B=7, + RIPEMD320S6C=6, + RIPEMD320S6D=15, + RIPEMD320S6E=13, + RIPEMD320S6F=11, + + RIPEMD320S70=9, + RIPEMD320S71=7, + RIPEMD320S72=15, + RIPEMD320S73=11, + RIPEMD320S74=8, + RIPEMD320S75=6, + RIPEMD320S76=6, + RIPEMD320S77=14, + RIPEMD320S78=12, + RIPEMD320S79=13, + RIPEMD320S7A=5, + RIPEMD320S7B=14, + RIPEMD320S7C=13, + RIPEMD320S7D=13, + RIPEMD320S7E=7, + RIPEMD320S7F=5, + + RIPEMD320S80=15, + RIPEMD320S81=5, + RIPEMD320S82=8, + RIPEMD320S83=11, + RIPEMD320S84=14, + RIPEMD320S85=14, + RIPEMD320S86=6, + RIPEMD320S87=14, + RIPEMD320S88=6, + RIPEMD320S89=9, + RIPEMD320S8A=12, + RIPEMD320S8B=9, + RIPEMD320S8C=12, + RIPEMD320S8D=5, + RIPEMD320S8E=15, + RIPEMD320S8F=8, + + RIPEMD320S90=8, + RIPEMD320S91=5, + RIPEMD320S92=12, + RIPEMD320S93=9, + RIPEMD320S94=12, + RIPEMD320S95=5, + RIPEMD320S96=14, + RIPEMD320S97=6, + RIPEMD320S98=8, + RIPEMD320S99=13, + RIPEMD320S9A=6, + RIPEMD320S9B=5, + RIPEMD320S9C=15, + RIPEMD320S9D=13, + RIPEMD320S9E=11, + RIPEMD320S9F=11 + +} ripemd320_constants_t; + typedef enum keccak_constants { KECCAK_RNDC_00=0x0000000000000001UL, diff --git a/OpenCL/m33600_a0-optimized.cl b/OpenCL/m33600_a0-optimized.cl new file mode 100644 index 000000000..8e120caac --- /dev/null +++ b/OpenCL/m33600_a0-optimized.cl @@ -0,0 +1,225 @@ + +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp_optimized.h) +#include M2S(INCLUDE_PATH/inc_rp_optimized.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +DECLSPEC void ripemd320_transform_transport_vector (PRIVATE_AS const u32x *w, PRIVATE_AS u32x *dgst) +{ + ripemd320_transform_vector (w + 0, w + 4, w + 8, w + 12, dgst); +} + +KERNEL_FQ void m33600_m04 (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0[4] = { 0 }; + u32x w1[4] = { 0 }; + u32x w2[4] = { 0 }; + u32x w3[4] = { 0 }; + + const u32x out_len = apply_rules_vect_optimized (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1); + + append_0x80_2x4_VV (w0, w1, out_len); + + u32x w[16]; + + w[ 0] = w0[0]; + w[ 1] = w0[1]; + w[ 2] = w0[2]; + w[ 3] = w0[3]; + w[ 4] = w1[0]; + w[ 5] = w1[1]; + w[ 6] = w1[2]; + w[ 7] = w1[3]; + w[ 8] = 0; + w[ 9] = 0; + w[10] = 0; + w[11] = 0; + w[12] = 0; + w[13] = 0; + w[14] = out_len * 8; + w[15] = 0; + + /** + * RipeMD320 + */ + + u32x dgst[10]; + + dgst[0] = RIPEMD320M_A; + dgst[1] = RIPEMD320M_B; + dgst[2] = RIPEMD320M_C; + dgst[3] = RIPEMD320M_D; + dgst[4] = RIPEMD320M_E; + dgst[5] = RIPEMD320M_F; + dgst[6] = RIPEMD320M_G; + dgst[7] = RIPEMD320M_H; + dgst[8] = RIPEMD320M_I; + dgst[9] = RIPEMD320M_L; + + ripemd320_transform_transport_vector (w, dgst); + + COMPARE_M_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]); + } +} + +KERNEL_FQ void m33600_m08 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m33600_m16 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m33600_s04 (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + u32x w0[4] = { 0 }; + u32x w1[4] = { 0 }; + u32x w2[4] = { 0 }; + u32x w3[4] = { 0 }; + + const u32x out_len = apply_rules_vect_optimized (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1); + + append_0x80_2x4_VV (w0, w1, out_len); + + u32x w[16]; + + w[ 0] = w0[0]; + w[ 1] = w0[1]; + w[ 2] = w0[2]; + w[ 3] = w0[3]; + w[ 4] = w1[0]; + w[ 5] = w1[1]; + w[ 6] = w1[2]; + w[ 7] = w1[3]; + w[ 8] = 0; + w[ 9] = 0; + w[10] = 0; + w[11] = 0; + w[12] = 0; + w[13] = 0; + w[14] = out_len * 8; + w[15] = 0; + + /** + * RipeMD320 + */ + + u32x dgst[10]; + + dgst[0] = RIPEMD320M_A; + dgst[1] = RIPEMD320M_B; + dgst[2] = RIPEMD320M_C; + dgst[3] = RIPEMD320M_D; + dgst[4] = RIPEMD320M_E; + dgst[5] = RIPEMD320M_F; + dgst[6] = RIPEMD320M_G; + dgst[7] = RIPEMD320M_H; + dgst[8] = RIPEMD320M_I; + dgst[9] = RIPEMD320M_L; + + ripemd320_transform_transport_vector (w, dgst); + + COMPARE_S_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]); + } +} + +KERNEL_FQ void m33600_s08 (KERN_ATTR_RULES ()) +{ +} + +KERNEL_FQ void m33600_s16 (KERN_ATTR_RULES ()) +{ +} diff --git a/OpenCL/m33600_a0-pure.cl b/OpenCL/m33600_a0-pure.cl new file mode 100644 index 000000000..9839edc58 --- /dev/null +++ b/OpenCL/m33600_a0-pure.cl @@ -0,0 +1,118 @@ + +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp.h) +#include M2S(INCLUDE_PATH/inc_rp.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33600_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + ripemd320_ctx_t ctx; + + ripemd320_init (&ctx); + + ripemd320_update (&ctx, tmp.i, tmp.pw_len); + + ripemd320_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33600_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + ripemd320_ctx_t ctx; + + ripemd320_init (&ctx); + + ripemd320_update (&ctx, tmp.i, tmp.pw_len); + + ripemd320_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33600_a1-optimized.cl b/OpenCL/m33600_a1-optimized.cl new file mode 100644 index 000000000..efa719980 --- /dev/null +++ b/OpenCL/m33600_a1-optimized.cl @@ -0,0 +1,339 @@ + +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +DECLSPEC void ripemd320_transform_transport_vector (PRIVATE_AS const u32x *w, PRIVATE_AS u32x *dgst) +{ + ripemd320_transform_vector (w + 0, w + 4, w + 8, w + 12, dgst); +} + +KERNEL_FQ void m33600_m04 (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_l_len = pws[gid].pw_len & 63; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos) & 63; + + const u32x pw_len = (pw_l_len + pw_r_len) & 63; + + /** + * concat password candidate + */ + + u32x wordl0[4] = { 0 }; + u32x wordl1[4] = { 0 }; + u32x wordl2[4] = { 0 }; + u32x wordl3[4] = { 0 }; + + wordl0[0] = pw_buf0[0]; + wordl0[1] = pw_buf0[1]; + wordl0[2] = pw_buf0[2]; + wordl0[3] = pw_buf0[3]; + wordl1[0] = pw_buf1[0]; + wordl1[1] = pw_buf1[1]; + wordl1[2] = pw_buf1[2]; + wordl1[3] = pw_buf1[3]; + + u32x wordr0[4] = { 0 }; + u32x wordr1[4] = { 0 }; + u32x wordr2[4] = { 0 }; + u32x wordr3[4] = { 0 }; + + wordr0[0] = ix_create_combt (combs_buf, il_pos, 0); + wordr0[1] = ix_create_combt (combs_buf, il_pos, 1); + wordr0[2] = ix_create_combt (combs_buf, il_pos, 2); + wordr0[3] = ix_create_combt (combs_buf, il_pos, 3); + wordr1[0] = ix_create_combt (combs_buf, il_pos, 4); + wordr1[1] = ix_create_combt (combs_buf, il_pos, 5); + wordr1[2] = ix_create_combt (combs_buf, il_pos, 6); + wordr1[3] = ix_create_combt (combs_buf, il_pos, 7); + + if (COMBS_MODE == COMBINATOR_MODE_BASE_LEFT) + { + switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len); + } + else + { + switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len); + } + + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + w0[0] = wordl0[0] | wordr0[0]; + w0[1] = wordl0[1] | wordr0[1]; + w0[2] = wordl0[2] | wordr0[2]; + w0[3] = wordl0[3] | wordr0[3]; + w1[0] = wordl1[0] | wordr1[0]; + w1[1] = wordl1[1] | wordr1[1]; + w1[2] = wordl1[2] | wordr1[2]; + w1[3] = wordl1[3] | wordr1[3]; + w2[0] = wordl2[0] | wordr2[0]; + w2[1] = wordl2[1] | wordr2[1]; + w2[2] = wordl2[2] | wordr2[2]; + w2[3] = wordl2[3] | wordr2[3]; + w3[0] = wordl3[0] | wordr3[0]; + w3[1] = wordl3[1] | wordr3[1]; + w3[2] = wordl3[2] | wordr3[2]; + w3[3] = wordl3[3] | wordr3[3]; + + /** + * RipeMD320 + */ + + u32x w[16]; + + w[ 0] = w0[0]; + w[ 1] = w0[1]; + w[ 2] = w0[2]; + w[ 3] = w0[3]; + w[ 4] = w1[0]; + w[ 5] = w1[1]; + w[ 6] = w1[2]; + w[ 7] = w1[3]; + w[ 8] = w2[0]; + w[ 9] = w2[1]; + w[10] = w2[2]; + w[11] = w2[3]; + w[12] = w3[0]; + w[13] = w3[1]; + w[14] = pw_len * 8; + w[15] = 0; + + u32x dgst[10]; + + dgst[0] = RIPEMD320M_A; + dgst[1] = RIPEMD320M_B; + dgst[2] = RIPEMD320M_C; + dgst[3] = RIPEMD320M_D; + dgst[4] = RIPEMD320M_E; + dgst[5] = RIPEMD320M_F; + dgst[6] = RIPEMD320M_G; + dgst[7] = RIPEMD320M_H; + dgst[8] = RIPEMD320M_I; + dgst[9] = RIPEMD320M_L; + + ripemd320_transform_transport_vector (w, dgst); + + COMPARE_M_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]); + } +} + +KERNEL_FQ void m33600_m08 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m33600_m16 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m33600_s04 (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + + /** + * base + */ + + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + u32 pw_buf0[4]; + u32 pw_buf1[4]; + + pw_buf0[0] = pws[gid].i[0]; + pw_buf0[1] = pws[gid].i[1]; + pw_buf0[2] = pws[gid].i[2]; + pw_buf0[3] = pws[gid].i[3]; + pw_buf1[0] = pws[gid].i[4]; + pw_buf1[1] = pws[gid].i[5]; + pw_buf1[2] = pws[gid].i[6]; + pw_buf1[3] = pws[gid].i[7]; + + const u32 pw_l_len = pws[gid].pw_len & 63; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos) & 63; + + const u32x pw_len = (pw_l_len + pw_r_len) & 63; + + /** + * concat password candidate + */ + + u32x wordl0[4] = { 0 }; + u32x wordl1[4] = { 0 }; + u32x wordl2[4] = { 0 }; + u32x wordl3[4] = { 0 }; + + wordl0[0] = pw_buf0[0]; + wordl0[1] = pw_buf0[1]; + wordl0[2] = pw_buf0[2]; + wordl0[3] = pw_buf0[3]; + wordl1[0] = pw_buf1[0]; + wordl1[1] = pw_buf1[1]; + wordl1[2] = pw_buf1[2]; + wordl1[3] = pw_buf1[3]; + + u32x wordr0[4] = { 0 }; + u32x wordr1[4] = { 0 }; + u32x wordr2[4] = { 0 }; + u32x wordr3[4] = { 0 }; + + wordr0[0] = ix_create_combt (combs_buf, il_pos, 0); + wordr0[1] = ix_create_combt (combs_buf, il_pos, 1); + wordr0[2] = ix_create_combt (combs_buf, il_pos, 2); + wordr0[3] = ix_create_combt (combs_buf, il_pos, 3); + wordr1[0] = ix_create_combt (combs_buf, il_pos, 4); + wordr1[1] = ix_create_combt (combs_buf, il_pos, 5); + wordr1[2] = ix_create_combt (combs_buf, il_pos, 6); + wordr1[3] = ix_create_combt (combs_buf, il_pos, 7); + + if (COMBS_MODE == COMBINATOR_MODE_BASE_LEFT) + { + switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len); + } + else + { + switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len); + } + + u32x w0[4]; + u32x w1[4]; + u32x w2[4]; + u32x w3[4]; + + w0[0] = wordl0[0] | wordr0[0]; + w0[1] = wordl0[1] | wordr0[1]; + w0[2] = wordl0[2] | wordr0[2]; + w0[3] = wordl0[3] | wordr0[3]; + w1[0] = wordl1[0] | wordr1[0]; + w1[1] = wordl1[1] | wordr1[1]; + w1[2] = wordl1[2] | wordr1[2]; + w1[3] = wordl1[3] | wordr1[3]; + w2[0] = wordl2[0] | wordr2[0]; + w2[1] = wordl2[1] | wordr2[1]; + w2[2] = wordl2[2] | wordr2[2]; + w2[3] = wordl2[3] | wordr2[3]; + w3[0] = wordl3[0] | wordr3[0]; + w3[1] = wordl3[1] | wordr3[1]; + w3[2] = wordl3[2] | wordr3[2]; + w3[3] = wordl3[3] | wordr3[3]; + + /** + * RipeMD320 + */ + + u32x w[16]; + + w[ 0] = w0[0]; + w[ 1] = w0[1]; + w[ 2] = w0[2]; + w[ 3] = w0[3]; + w[ 4] = w1[0]; + w[ 5] = w1[1]; + w[ 6] = w1[2]; + w[ 7] = w1[3]; + w[ 8] = w2[0]; + w[ 9] = w2[1]; + w[10] = w2[2]; + w[11] = w2[3]; + w[12] = w3[0]; + w[13] = w3[1]; + w[14] = pw_len * 8; + w[15] = 0; + + u32x dgst[10]; + + dgst[0] = RIPEMD320M_A; + dgst[1] = RIPEMD320M_B; + dgst[2] = RIPEMD320M_C; + dgst[3] = RIPEMD320M_D; + dgst[4] = RIPEMD320M_E; + dgst[5] = RIPEMD320M_F; + dgst[6] = RIPEMD320M_G; + dgst[7] = RIPEMD320M_H; + dgst[8] = RIPEMD320M_I; + dgst[9] = RIPEMD320M_L; + + ripemd320_transform_transport_vector (w, dgst); + + COMPARE_S_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]); + } +} + +KERNEL_FQ void m33600_s08 (KERN_ATTR_BASIC ()) +{ +} + +KERNEL_FQ void m33600_s16 (KERN_ATTR_BASIC ()) +{ +} diff --git a/OpenCL/m33600_a1-pure.cl b/OpenCL/m33600_a1-pure.cl new file mode 100644 index 000000000..a97881806 --- /dev/null +++ b/OpenCL/m33600_a1-pure.cl @@ -0,0 +1,112 @@ + +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33600_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + ripemd320_ctx_t ctx0; + + ripemd320_init (&ctx0); + + ripemd320_update_global (&ctx0, pws[gid].i, pws[gid].pw_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + ripemd320_ctx_t ctx = ctx0; + + ripemd320_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len); + + ripemd320_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33600_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + ripemd320_ctx_t ctx0; + + ripemd320_init (&ctx0); + + ripemd320_update_global (&ctx0, pws[gid].i, pws[gid].pw_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + ripemd320_ctx_t ctx = ctx0; + + ripemd320_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len); + + ripemd320_final (&ctx); + + const u32 r0 = ctx.h[DGST_R0]; + const u32 r1 = ctx.h[DGST_R1]; + const u32 r2 = ctx.h[DGST_R2]; + const u32 r3 = ctx.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33600_a3-optimized.cl b/OpenCL/m33600_a3-optimized.cl new file mode 100644 index 000000000..f55c1a36f --- /dev/null +++ b/OpenCL/m33600_a3-optimized.cl @@ -0,0 +1,447 @@ + +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +DECLSPEC void ripemd320_transform_transport_vector (PRIVATE_AS const u32x *w, PRIVATE_AS u32x *dgst) +{ + ripemd320_transform_vector (w + 0, w + 4, w + 8, w + 12, dgst); +} + +DECLSPEC void m33600m (PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const u32 pw_len, KERN_ATTR_FUNC_BASIC ()) +{ + /** + * modifiers are taken from args + */ + + /** + * loop + */ + + u32 w0l = w0[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = ix_create_bft (bfs_buf, il_pos); + + const u32x w0lr = w0l | w0r; + + u32x w[16]; + + w[ 0] = w0lr; + w[ 1] = w0[1]; + w[ 2] = w0[2]; + w[ 3] = w0[3]; + w[ 4] = w1[0]; + w[ 5] = w1[1]; + w[ 6] = w1[2]; + w[ 7] = w1[3]; + w[ 8] = w2[0]; + w[ 9] = w2[1]; + w[10] = w2[2]; + w[11] = w2[3]; + w[12] = w3[0]; + w[13] = w3[1]; + w[14] = pw_len * 8; + w[15] = 0; + + /** + * RipeMD320 + */ + + u32x dgst[10]; + + dgst[0] = RIPEMD320M_A; + dgst[1] = RIPEMD320M_B; + dgst[2] = RIPEMD320M_C; + dgst[3] = RIPEMD320M_D; + dgst[4] = RIPEMD320M_E; + dgst[5] = RIPEMD320M_F; + dgst[6] = RIPEMD320M_G; + dgst[7] = RIPEMD320M_H; + dgst[8] = RIPEMD320M_I; + dgst[9] = RIPEMD320M_L; + + ripemd320_transform_transport_vector (w, dgst); + + COMPARE_M_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]); + } +} + +DECLSPEC void m33600s (PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, const u32 pw_len, KERN_ATTR_FUNC_BASIC ()) +{ + /** + * modifiers are taken from args + */ + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * loop + */ + + u32 w0l = w0[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = ix_create_bft (bfs_buf, il_pos); + + const u32x w0lr = w0l | w0r; + + u32x w[16]; + + w[ 0] = w0lr; + w[ 1] = w0[1]; + w[ 2] = w0[2]; + w[ 3] = w0[3]; + w[ 4] = w1[0]; + w[ 5] = w1[1]; + w[ 6] = w1[2]; + w[ 7] = w1[3]; + w[ 8] = w2[0]; + w[ 9] = w2[1]; + w[10] = w2[2]; + w[11] = w2[3]; + w[12] = w3[0]; + w[13] = w3[1]; + w[14] = pw_len * 8; + w[15] = 0; + + /** + * RipeMD320 + */ + + u32x dgst[10]; + + dgst[0] = RIPEMD320M_A; + dgst[1] = RIPEMD320M_B; + dgst[2] = RIPEMD320M_C; + dgst[3] = RIPEMD320M_D; + dgst[4] = RIPEMD320M_E; + dgst[5] = RIPEMD320M_F; + dgst[6] = RIPEMD320M_G; + dgst[7] = RIPEMD320M_H; + dgst[8] = RIPEMD320M_I; + dgst[9] = RIPEMD320M_L; + + ripemd320_transform_transport_vector (w, dgst); + + COMPARE_S_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]); + } +} + +KERNEL_FQ void m33600_m04 (KERN_ATTR_BASIC ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) return; + + u32 w0[4]; + + w0[0] = pws[gid].i[ 0]; + w0[1] = pws[gid].i[ 1]; + w0[2] = pws[gid].i[ 2]; + w0[3] = pws[gid].i[ 3]; + + u32 w1[4]; + + w1[0] = 0; + w1[1] = 0; + w1[2] = 0; + w1[3] = 0; + + u32 w2[4]; + + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + + u32 w3[4]; + + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m33600m (w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m33600_m08 (KERN_ATTR_BASIC ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) return; + + u32 w0[4]; + + w0[0] = pws[gid].i[ 0]; + w0[1] = pws[gid].i[ 1]; + w0[2] = pws[gid].i[ 2]; + w0[3] = pws[gid].i[ 3]; + + u32 w1[4]; + + w1[0] = pws[gid].i[ 4]; + w1[1] = pws[gid].i[ 5]; + w1[2] = pws[gid].i[ 6]; + w1[3] = pws[gid].i[ 7]; + + u32 w2[4]; + + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + + u32 w3[4]; + + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m33600m (w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m33600_m16 (KERN_ATTR_BASIC ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) return; + + u32 w0[4]; + + w0[0] = pws[gid].i[ 0]; + w0[1] = pws[gid].i[ 1]; + w0[2] = pws[gid].i[ 2]; + w0[3] = pws[gid].i[ 3]; + + u32 w1[4]; + + w1[0] = pws[gid].i[ 4]; + w1[1] = pws[gid].i[ 5]; + w1[2] = pws[gid].i[ 6]; + w1[3] = pws[gid].i[ 7]; + + u32 w2[4]; + + w2[0] = pws[gid].i[ 8]; + w2[1] = pws[gid].i[ 9]; + w2[2] = pws[gid].i[10]; + w2[3] = pws[gid].i[11]; + + u32 w3[4]; + + w3[0] = pws[gid].i[12]; + w3[1] = pws[gid].i[13]; + w3[2] = 0; + w3[3] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m33600m (w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m33600_s04 (KERN_ATTR_BASIC ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) return; + + u32 w0[4]; + + w0[0] = pws[gid].i[ 0]; + w0[1] = pws[gid].i[ 1]; + w0[2] = pws[gid].i[ 2]; + w0[3] = pws[gid].i[ 3]; + + u32 w1[4]; + + w1[0] = 0; + w1[1] = 0; + w1[2] = 0; + w1[3] = 0; + + u32 w2[4]; + + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + + u32 w3[4]; + + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m33600s (w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m33600_s08 (KERN_ATTR_BASIC ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) return; + + u32 w0[4]; + + w0[0] = pws[gid].i[ 0]; + w0[1] = pws[gid].i[ 1]; + w0[2] = pws[gid].i[ 2]; + w0[3] = pws[gid].i[ 3]; + + u32 w1[4]; + + w1[0] = pws[gid].i[ 4]; + w1[1] = pws[gid].i[ 5]; + w1[2] = pws[gid].i[ 6]; + w1[3] = pws[gid].i[ 7]; + + u32 w2[4]; + + w2[0] = 0; + w2[1] = 0; + w2[2] = 0; + w2[3] = 0; + + u32 w3[4]; + + w3[0] = 0; + w3[1] = 0; + w3[2] = 0; + w3[3] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m33600s (w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, kernel_param, gid, lid, lsz); +} + +KERNEL_FQ void m33600_s16 (KERN_ATTR_BASIC ()) +{ + /** + * base + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + const u64 lsz = get_local_size (0); + + if (gid >= GID_CNT) return; + + u32 w0[4]; + + w0[0] = pws[gid].i[ 0]; + w0[1] = pws[gid].i[ 1]; + w0[2] = pws[gid].i[ 2]; + w0[3] = pws[gid].i[ 3]; + + u32 w1[4]; + + w1[0] = pws[gid].i[ 4]; + w1[1] = pws[gid].i[ 5]; + w1[2] = pws[gid].i[ 6]; + w1[3] = pws[gid].i[ 7]; + + u32 w2[4]; + + w2[0] = pws[gid].i[ 8]; + w2[1] = pws[gid].i[ 9]; + w2[2] = pws[gid].i[10]; + w2[3] = pws[gid].i[11]; + + u32 w3[4]; + + w3[0] = pws[gid].i[12]; + w3[1] = pws[gid].i[13]; + w3[2] = 0; + w3[3] = 0; + + const u32 pw_len = pws[gid].pw_len & 63; + + /** + * main + */ + + m33600s (w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_extra0_buf, d_extra1_buf, d_extra2_buf, d_extra3_buf, kernel_param, gid, lid, lsz); +} diff --git a/OpenCL/m33600_a3-pure.cl b/OpenCL/m33600_a3-pure.cl new file mode 100644 index 000000000..ae113ddcd --- /dev/null +++ b/OpenCL/m33600_a3-pure.cl @@ -0,0 +1,138 @@ + +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33600_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + ripemd320_ctx_vector_t ctx; + + ripemd320_init_vector (&ctx); + + ripemd320_update_vector (&ctx, w, pw_len); + + ripemd320_final_vector (&ctx); + + const u32x r0 = ctx.h[DGST_R0]; + const u32x r1 = ctx.h[DGST_R1]; + const u32x r2 = ctx.h[DGST_R2]; + const u32x r3 = ctx.h[DGST_R3]; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33600_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + ripemd320_ctx_vector_t ctx; + + ripemd320_init_vector (&ctx); + + ripemd320_update_vector (&ctx, w, pw_len); + + ripemd320_final_vector (&ctx); + + const u32x r0 = ctx.h[DGST_R0]; + const u32x r1 = ctx.h[DGST_R1]; + const u32x r2 = ctx.h[DGST_R2]; + const u32x r3 = ctx.h[DGST_R3]; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33650_a0-pure.cl b/OpenCL/m33650_a0-pure.cl new file mode 100644 index 000000000..071cffbc0 --- /dev/null +++ b/OpenCL/m33650_a0-pure.cl @@ -0,0 +1,135 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp.h) +#include M2S(INCLUDE_PATH/inc_rp.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33650_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + ripemd320_hmac_ctx_t ctx; + + ripemd320_hmac_init (&ctx, tmp.i, tmp.pw_len); + + ripemd320_hmac_update (&ctx, s, salt_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33650_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + ripemd320_hmac_ctx_t ctx; + + ripemd320_hmac_init (&ctx, tmp.i, tmp.pw_len); + + ripemd320_hmac_update (&ctx, s, salt_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33650_a1-pure.cl b/OpenCL/m33650_a1-pure.cl new file mode 100644 index 000000000..3c248fc8d --- /dev/null +++ b/OpenCL/m33650_a1-pure.cl @@ -0,0 +1,183 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33650_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32 w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = combs_buf[il_pos].i[idx]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + ripemd320_hmac_ctx_t ctx; + + ripemd320_hmac_init (&ctx, c, pw_len + comb_len); + + ripemd320_hmac_update (&ctx, s, salt_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33650_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32 w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = combs_buf[il_pos].i[idx]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + ripemd320_hmac_ctx_t ctx; + + ripemd320_hmac_init (&ctx, c, pw_len + comb_len); + + ripemd320_hmac_update (&ctx, s, salt_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33650_a3-pure.cl b/OpenCL/m33650_a3-pure.cl new file mode 100644 index 000000000..4511a6438 --- /dev/null +++ b/OpenCL/m33650_a3-pure.cl @@ -0,0 +1,155 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33650_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + ripemd320_hmac_ctx_vector_t ctx; + + ripemd320_hmac_init_vector (&ctx, w, pw_len); + + ripemd320_hmac_update_vector (&ctx, s, salt_len); + + ripemd320_hmac_final_vector (&ctx); + + const u32x r0 = ctx.opad.h[DGST_R0]; + const u32x r1 = ctx.opad.h[DGST_R1]; + const u32x r2 = ctx.opad.h[DGST_R2]; + const u32x r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33650_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + ripemd320_hmac_ctx_vector_t ctx; + + ripemd320_hmac_init_vector (&ctx, w, pw_len); + + ripemd320_hmac_update_vector (&ctx, s, salt_len); + + ripemd320_hmac_final_vector (&ctx); + + const u32x r0 = ctx.opad.h[DGST_R0]; + const u32x r1 = ctx.opad.h[DGST_R1]; + const u32x r2 = ctx.opad.h[DGST_R2]; + const u32x r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33660_a0-pure.cl b/OpenCL/m33660_a0-pure.cl new file mode 100644 index 000000000..fd7b04dea --- /dev/null +++ b/OpenCL/m33660_a0-pure.cl @@ -0,0 +1,139 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_rp.h) +#include M2S(INCLUDE_PATH/inc_rp.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33660_mxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + ripemd320_hmac_ctx_t ctx0; + + ripemd320_hmac_init (&ctx0, s, salt_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + ripemd320_hmac_ctx_t ctx = ctx0; + + ripemd320_hmac_update (&ctx, tmp.i, tmp.pw_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33660_sxx (KERN_ATTR_RULES ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + COPY_PW (pws[gid]); + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + ripemd320_hmac_ctx_t ctx0; + + ripemd320_hmac_init (&ctx0, s, salt_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + ripemd320_hmac_ctx_t ctx = ctx0; + + ripemd320_hmac_update (&ctx, tmp.i, tmp.pw_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33660_a1-pure.cl b/OpenCL/m33660_a1-pure.cl new file mode 100644 index 000000000..9d070fa83 --- /dev/null +++ b/OpenCL/m33660_a1-pure.cl @@ -0,0 +1,187 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +//#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_scalar.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33660_mxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32 w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + ripemd320_hmac_ctx_t ctx0; + + ripemd320_hmac_init (&ctx0, s, salt_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = combs_buf[il_pos].i[idx]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + ripemd320_hmac_ctx_t ctx = ctx0; + + ripemd320_hmac_update (&ctx, c, pw_len + comb_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SCALAR (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33660_sxx (KERN_ATTR_BASIC ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32 w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32 s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + ripemd320_hmac_ctx_t ctx0; + + ripemd320_hmac_init (&ctx0, s, salt_len); + + /** + * loop + */ + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos++) + { + const u32 comb_len = combs_buf[il_pos].pw_len; + + u32 c[64]; + + #ifdef _unroll + #pragma unroll + #endif + for (int idx = 0; idx < 64; idx++) + { + c[idx] = combs_buf[il_pos].i[idx]; + } + + switch_buffer_by_offset_1x64_le_S (c, pw_len); + + #ifdef _unroll + #pragma unroll + #endif + for (int i = 0; i < 64; i++) + { + c[i] |= w[i]; + } + + ripemd320_hmac_ctx_t ctx = ctx0; + + ripemd320_hmac_update (&ctx, c, pw_len + comb_len); + + ripemd320_hmac_final (&ctx); + + const u32 r0 = ctx.opad.h[DGST_R0]; + const u32 r1 = ctx.opad.h[DGST_R1]; + const u32 r2 = ctx.opad.h[DGST_R2]; + const u32 r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SCALAR (r0, r1, r2, r3); + } +} diff --git a/OpenCL/m33660_a3-pure.cl b/OpenCL/m33660_a3-pure.cl new file mode 100644 index 000000000..10e42f73d --- /dev/null +++ b/OpenCL/m33660_a3-pure.cl @@ -0,0 +1,159 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#define NEW_SIMD_CODE + +#ifdef KERNEL_STATIC +#include M2S(INCLUDE_PATH/inc_vendor.h) +#include M2S(INCLUDE_PATH/inc_types.h) +#include M2S(INCLUDE_PATH/inc_platform.cl) +#include M2S(INCLUDE_PATH/inc_common.cl) +#include M2S(INCLUDE_PATH/inc_simd.cl) +#include M2S(INCLUDE_PATH/inc_hash_ripemd320.cl) +#endif + +KERNEL_FQ void m33660_mxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + ripemd320_hmac_ctx_vector_t ctx0; + + ripemd320_hmac_init_vector (&ctx0, s, salt_len); + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + ripemd320_hmac_ctx_vector_t ctx = ctx0; + + ripemd320_hmac_update_vector (&ctx, w, pw_len); + + ripemd320_hmac_final_vector (&ctx); + + const u32x r0 = ctx.opad.h[DGST_R0]; + const u32x r1 = ctx.opad.h[DGST_R1]; + const u32x r2 = ctx.opad.h[DGST_R2]; + const u32x r3 = ctx.opad.h[DGST_R3]; + + COMPARE_M_SIMD (r0, r1, r2, r3); + } +} + +KERNEL_FQ void m33660_sxx (KERN_ATTR_VECTOR ()) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + if (gid >= GID_CNT) return; + + /** + * digest + */ + + const u32 search[4] = + { + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R0], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R1], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R2], + digests_buf[DIGESTS_OFFSET_HOST].digest_buf[DGST_R3] + }; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + const u32 salt_len = salt_bufs[SALT_POS_HOST].salt_len; + + u32x s[64] = { 0 }; + + for (u32 i = 0, idx = 0; i < salt_len; i += 4, idx += 1) + { + s[idx] = salt_bufs[SALT_POS_HOST].salt_buf[idx]; + } + + ripemd320_hmac_ctx_vector_t ctx0; + + ripemd320_hmac_init_vector (&ctx0, s, salt_len); + + /** + * loop + */ + + u32x w0l = w[0]; + + for (u32 il_pos = 0; il_pos < IL_CNT; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + + const u32x w0 = w0l | w0r; + + w[0] = w0; + + ripemd320_hmac_ctx_vector_t ctx = ctx0; + + ripemd320_hmac_update_vector (&ctx, w, pw_len); + + ripemd320_hmac_final_vector (&ctx); + + const u32x r0 = ctx.opad.h[DGST_R0]; + const u32x r1 = ctx.opad.h[DGST_R1]; + const u32x r2 = ctx.opad.h[DGST_R2]; + const u32x r3 = ctx.opad.h[DGST_R3]; + + COMPARE_S_SIMD (r0, r1, r2, r3); + } +} diff --git a/docs/changes.txt b/docs/changes.txt index 103019d6d..991d43615 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -27,6 +27,8 @@ - Added hash-mode: GPG (AES-128/AES-256 (SHA-256($pass))) - Added hash-mode: GPG (AES-128/AES-256 (SHA-512($pass))) - Added hash-mode: GPG (CAST5 (SHA-1($pass))) +- Added hash-mode: HMAC-RIPEMD320 (key = $pass) +- Added hash-mode: HMAC-RIPEMD320 (key = $salt) - Added hash-mode: Kerberos 5, etype 17, AS-REP - Added hash-mode: Kerberos 5, etype 18, AS-REP - Added hash-mode: MetaMask Mobile Wallet @@ -39,6 +41,7 @@ - Added hash-mode: NetIQ SSPR (SHA-1 with Salt) - Added hash-mode: NetIQ SSPR (SHA-256 with Salt) - Added hash-mode: NetIQ SSPR (SHA-512 with Salt) +- Added hash-mode: RIPEMD-320 - Added hash-mode: RC4 104-bit DropN - Added hash-mode: RC4 40-bit DropN - Added hash-mode: RC4 72-bit DropN diff --git a/docs/readme.txt b/docs/readme.txt index 38d1bb594..2f0efe391 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -57,6 +57,7 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or - SHA3-384 - SHA3-512 - RIPEMD-160 +- RIPEMD-320 - BLAKE2b-512 - BLAKE2s-256 - SM3 @@ -143,6 +144,8 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or - HMAC-MD5 (key = $salt) - HMAC-RIPEMD160 (key = $pass) - HMAC-RIPEMD160 (key = $salt) +- HMAC-RIPEMD320 (key = $pass) +- HMAC-RIPEMD320 (key = $salt) - HMAC-SHA1 (key = $pass) - HMAC-SHA1 (key = $salt) - HMAC-SHA256 (key = $pass) diff --git a/include/types.h b/include/types.h index 880af23ee..919e7758a 100644 --- a/include/types.h +++ b/include/types.h @@ -481,6 +481,7 @@ typedef enum dgst_size DGST_SIZE_4_6 = (6 * sizeof (u32)), // 24 DGST_SIZE_4_7 = (7 * sizeof (u32)), // 28 DGST_SIZE_4_8 = (8 * sizeof (u32)), // 32 + DGST_SIZE_4_10 = (10 * sizeof (u32)), // 40 DGST_SIZE_4_16 = (16 * sizeof (u32)), // 64 !!! DGST_SIZE_4_32 = (32 * sizeof (u32)), // 128 !!! DGST_SIZE_4_64 = (64 * sizeof (u32)), // 256 diff --git a/src/modules/module_33600.c b/src/modules/module_33600.c new file mode 100644 index 000000000..745b95b8f --- /dev/null +++ b/src/modules/module_33600.c @@ -0,0 +1,196 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_10; +static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH; +static const char *HASH_NAME = "RIPEMD-320"; +static const u64 KERN_TYPE = 33600; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_PT_ADD80; +static const u32 SALT_TYPE = SALT_TYPE_NONE; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "8339009b816d4e4c2a6be3c6e1daac6aca69a7670ecdc583adfca0db17cc8f08ce35d6c759b038ab"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + u32 *digest = (u32 *) digest_buf; + + hc_token_t token; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 1; + + token.len[0] = 80; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + const u8 *hash_pos = token.buf[0]; + + digest[0] = hex_to_u32 (hash_pos + 0); + digest[1] = hex_to_u32 (hash_pos + 8); + digest[2] = hex_to_u32 (hash_pos + 16); + digest[3] = hex_to_u32 (hash_pos + 24); + digest[4] = hex_to_u32 (hash_pos + 32); + digest[5] = hex_to_u32 (hash_pos + 40); + digest[6] = hex_to_u32 (hash_pos + 48); + digest[7] = hex_to_u32 (hash_pos + 56); + digest[8] = hex_to_u32 (hash_pos + 64); + digest[9] = hex_to_u32 (hash_pos + 72); + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + // we can not change anything in the original buffer, otherwise destroying sorting + // therefore create some local buffer + + u32 tmp[10]; + + tmp[0] = digest[0]; + tmp[1] = digest[1]; + tmp[2] = digest[2]; + tmp[3] = digest[3]; + tmp[4] = digest[4]; + tmp[5] = digest[5]; + tmp[6] = digest[6]; + tmp[7] = digest[7]; + tmp[8] = digest[8]; + tmp[9] = digest[9]; + + + u8 *out_buf = (u8 *) line_buf; + + u32_to_hex (tmp[0], out_buf + 0); + u32_to_hex (tmp[1], out_buf + 8); + u32_to_hex (tmp[2], out_buf + 16); + u32_to_hex (tmp[3], out_buf + 24); + u32_to_hex (tmp[4], out_buf + 32); + u32_to_hex (tmp[5], out_buf + 40); + u32_to_hex (tmp[6], out_buf + 48); + u32_to_hex (tmp[7], out_buf + 56); + u32_to_hex (tmp[8], out_buf + 64); + u32_to_hex (tmp[9], out_buf + 72); + + const int out_len = 80; + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_charset = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_deprecated_notice = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = MODULE_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_postprocess = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hashes_count_min = MODULE_DEFAULT; + module_ctx->module_hashes_count_max = MODULE_DEFAULT; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_size = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_init = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_term = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/src/modules/module_33650.c b/src/modules/module_33650.c new file mode 100644 index 000000000..a3b2d2d07 --- /dev/null +++ b/src/modules/module_33650.c @@ -0,0 +1,223 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_10; +static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH_AUTHENTICATED; +static const char *HASH_NAME = "HMAC-RIPEMD320 (key = $pass)"; +static const u64 KERN_TYPE = 33650; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE + | OPTI_TYPE_NOT_ITERATED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_ST_ADD80 + | OPTS_TYPE_ST_ADDBITS14; +static const u32 SALT_TYPE = SALT_TYPE_GENERIC; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "e740440e7bd65056a90f1aa4eb00e00308a9f1788866b4eacbd46cfc8032301d4e5b3a9d179be044:95454599772294521162217"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + u32 *digest = (u32 *) digest_buf; + + hc_token_t token; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 2; + + token.sep[0] = hashconfig->separator; + token.len[0] = 80; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + token.len_min[1] = SALT_MIN; + token.len_max[1] = SALT_MAX; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH; + + if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) + { + token.len_min[1] *= 2; + token.len_max[1] *= 2; + + token.attr[1] |= TOKEN_ATTR_VERIFY_HEX; + } + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + const u8 *hash_pos = token.buf[0]; + + digest[0] = hex_to_u32 (hash_pos + 0); + digest[1] = hex_to_u32 (hash_pos + 8); + digest[2] = hex_to_u32 (hash_pos + 16); + digest[3] = hex_to_u32 (hash_pos + 24); + digest[4] = hex_to_u32 (hash_pos + 32); + digest[5] = hex_to_u32 (hash_pos + 40); + digest[6] = hex_to_u32 (hash_pos + 48); + digest[7] = hex_to_u32 (hash_pos + 56); + digest[8] = hex_to_u32 (hash_pos + 64); + digest[9] = hex_to_u32 (hash_pos + 72); + + const u8 *salt_pos = token.buf[1]; + const int salt_len = token.len[1]; + + const bool parse_rc = generic_salt_decode (hashconfig, salt_pos, salt_len, (u8 *) salt->salt_buf, (int *) &salt->salt_len); + + if (parse_rc == false) return (PARSER_SALT_LENGTH); + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + // we can not change anything in the original buffer, otherwise destroying sorting + // therefore create some local buffer + + u32 tmp[10]; + + tmp[0] = digest[0]; + tmp[1] = digest[1]; + tmp[2] = digest[2]; + tmp[3] = digest[3]; + tmp[4] = digest[4]; + tmp[5] = digest[5]; + tmp[6] = digest[6]; + tmp[7] = digest[7]; + tmp[8] = digest[8]; + tmp[9] = digest[9]; + + u8 *out_buf = (u8 *) line_buf; + + int out_len = 0; + + u32_to_hex (tmp[0], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[1], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[2], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[3], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[4], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[5], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[6], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[7], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[8], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[9], out_buf + out_len); out_len += 8; + + out_buf[out_len] = hashconfig->separator; + + out_len += 1; + + out_len += generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, out_buf + out_len); + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_charset = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_deprecated_notice = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = MODULE_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_postprocess = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hashes_count_min = MODULE_DEFAULT; + module_ctx->module_hashes_count_max = MODULE_DEFAULT; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_size = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_init = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_term = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/src/modules/module_33660.c b/src/modules/module_33660.c new file mode 100644 index 000000000..1c0dfbc1a --- /dev/null +++ b/src/modules/module_33660.c @@ -0,0 +1,223 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_10; +static const u32 HASH_CATEGORY = HASH_CATEGORY_RAW_HASH_AUTHENTICATED; +static const char *HASH_NAME = "HMAC-RIPEMD320 (key = $salt)"; +static const u64 KERN_TYPE = 33660; +static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE + | OPTI_TYPE_NOT_ITERATED; +static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE + | OPTS_TYPE_PT_GENERATE_LE + | OPTS_TYPE_PT_ADD80 + | OPTS_TYPE_PT_ADDBITS14; +static const u32 SALT_TYPE = SALT_TYPE_GENERIC; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "345136b13b3a6e52901e2a414efa0cf5fca2fecf8b03279656d3b0f42c30df3006c5ad186494996b:2436077107013929602"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + u32 *digest = (u32 *) digest_buf; + + hc_token_t token; + + memset (&token, 0, sizeof (hc_token_t)); + + token.token_cnt = 2; + + token.sep[0] = hashconfig->separator; + token.len[0] = 80; + token.attr[0] = TOKEN_ATTR_FIXED_LENGTH + | TOKEN_ATTR_VERIFY_HEX; + + token.len_min[1] = SALT_MIN; + token.len_max[1] = SALT_MAX; + token.attr[1] = TOKEN_ATTR_VERIFY_LENGTH; + + if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) + { + token.len_min[1] *= 2; + token.len_max[1] *= 2; + + token.attr[1] |= TOKEN_ATTR_VERIFY_HEX; + } + + const int rc_tokenizer = input_tokenizer ((const u8 *) line_buf, line_len, &token); + + if (rc_tokenizer != PARSER_OK) return (rc_tokenizer); + + const u8 *hash_pos = token.buf[0]; + + digest[0] = hex_to_u32 (hash_pos + 0); + digest[1] = hex_to_u32 (hash_pos + 8); + digest[2] = hex_to_u32 (hash_pos + 16); + digest[3] = hex_to_u32 (hash_pos + 24); + digest[4] = hex_to_u32 (hash_pos + 32); + digest[5] = hex_to_u32 (hash_pos + 40); + digest[6] = hex_to_u32 (hash_pos + 48); + digest[7] = hex_to_u32 (hash_pos + 56); + digest[8] = hex_to_u32 (hash_pos + 64); + digest[9] = hex_to_u32 (hash_pos + 72); + + const u8 *salt_pos = token.buf[1]; + const int salt_len = token.len[1]; + + const bool parse_rc = generic_salt_decode (hashconfig, salt_pos, salt_len, (u8 *) salt->salt_buf, (int *) &salt->salt_len); + + if (parse_rc == false) return (PARSER_SALT_LENGTH); + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + // we can not change anything in the original buffer, otherwise destroying sorting + // therefore create some local buffer + + u32 tmp[10]; + + tmp[0] = digest[0]; + tmp[1] = digest[1]; + tmp[2] = digest[2]; + tmp[3] = digest[3]; + tmp[4] = digest[4]; + tmp[5] = digest[5]; + tmp[6] = digest[6]; + tmp[7] = digest[7]; + tmp[8] = digest[8]; + tmp[9] = digest[9]; + + u8 *out_buf = (u8 *) line_buf; + + int out_len = 0; + + u32_to_hex (tmp[0], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[1], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[2], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[3], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[4], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[5], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[6], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[7], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[8], out_buf + out_len); out_len += 8; + u32_to_hex (tmp[9], out_buf + out_len); out_len += 8; + + out_buf[out_len] = hashconfig->separator; + + out_len += 1; + + out_len += generic_salt_encode (hashconfig, (const u8 *) salt->salt_buf, (const int) salt->salt_len, out_buf + out_len); + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_charset = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_deprecated_notice = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = MODULE_DEFAULT; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_extra_tuningdb_block = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_postprocess = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hashes_count_min = MODULE_DEFAULT; + module_ctx->module_hashes_count_max = MODULE_DEFAULT; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_size = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_init = MODULE_DEFAULT; + module_ctx->module_hook_extra_param_term = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/tools/test_modules/m33600.pm b/tools/test_modules/m33600.pm new file mode 100644 index 000000000..2f857f8ee --- /dev/null +++ b/tools/test_modules/m33600.pm @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Crypt::Digest::RIPEMD320 qw (ripemd320_hex); + +sub module_constraints { [[0, 256], [-1, -1], [0, 55], [-1, -1], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + + my $digest = ripemd320_hex ($word); + + my $hash = sprintf ("%s", $digest); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $word; + + my $word_packed = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word_packed); + + return ($new_hash, $word); +} + +1; diff --git a/tools/test_modules/m33650.pm b/tools/test_modules/m33650.pm new file mode 100644 index 000000000..c4340b22f --- /dev/null +++ b/tools/test_modules/m33650.pm @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Crypt::Digest::RIPEMD320 qw (ripemd320); +use Digest::HMAC qw (hmac_hex); + +sub module_constraints { [[0, 256], [0, 256], [0, 55], [0, 55], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $digest = hmac_hex ($salt, $word, \&ripemd320, 64); + + my $hash = sprintf ("%s:%s", $digest, $salt); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $salt, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $salt; + return unless defined $word; + + my $word_packed = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word_packed, $salt); + + return ($new_hash, $word); +} + +1; diff --git a/tools/test_modules/m33660.pm b/tools/test_modules/m33660.pm new file mode 100644 index 000000000..3a6f1a978 --- /dev/null +++ b/tools/test_modules/m33660.pm @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Crypt::Digest::RIPEMD320 qw (ripemd320); +use Digest::HMAC qw (hmac_hex); + +sub module_constraints { [[0, 256], [0, 256], [0, 55], [0, 55], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $digest = hmac_hex ($word, $salt, \&ripemd320, 64); + + my $hash = sprintf ("%s:%s", $digest, $salt); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $salt, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $salt; + return unless defined $word; + + my $word_packed = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word_packed, $salt); + + return ($new_hash, $word); +} + +1;