2017-06-18 21:31:40 +00:00
|
|
|
|
|
|
|
// important notes on this:
|
|
|
|
// input buf unused bytes needs to be set to zero
|
|
|
|
// input buf need to be in algorithm native byte order (md5 = LE, sha1 = BE, etc)
|
|
|
|
// input buf need to be 64 byte aligned when usin md5_update()
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
typedef struct md4_ctx
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
u32 h[4];
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
int len;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
} md4_ctx_t;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[4])
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
|
|
|
u32 a = digest[0];
|
|
|
|
u32 b = digest[1];
|
|
|
|
u32 c = digest[2];
|
|
|
|
u32 d = digest[3];
|
|
|
|
|
|
|
|
MD4_STEP_S (MD4_Fo, a, b, c, d, w0[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP_S (MD4_Fo, d, a, b, c, w0[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP_S (MD4_Fo, c, d, a, b, w0[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP_S (MD4_Fo, b, c, d, a, w0[3], MD4C00, MD4S03);
|
|
|
|
MD4_STEP_S (MD4_Fo, a, b, c, d, w1[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP_S (MD4_Fo, d, a, b, c, w1[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP_S (MD4_Fo, c, d, a, b, w1[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP_S (MD4_Fo, b, c, d, a, w1[3], MD4C00, MD4S03);
|
|
|
|
MD4_STEP_S (MD4_Fo, a, b, c, d, w2[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP_S (MD4_Fo, d, a, b, c, w2[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP_S (MD4_Fo, c, d, a, b, w2[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP_S (MD4_Fo, b, c, d, a, w2[3], MD4C00, MD4S03);
|
|
|
|
MD4_STEP_S (MD4_Fo, a, b, c, d, w3[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP_S (MD4_Fo, d, a, b, c, w3[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP_S (MD4_Fo, c, d, a, b, w3[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP_S (MD4_Fo, b, c, d, a, w3[3], MD4C00, MD4S03);
|
|
|
|
|
|
|
|
MD4_STEP_S (MD4_Go, a, b, c, d, w0[0], MD4C01, MD4S10);
|
|
|
|
MD4_STEP_S (MD4_Go, d, a, b, c, w1[0], MD4C01, MD4S11);
|
|
|
|
MD4_STEP_S (MD4_Go, c, d, a, b, w2[0], MD4C01, MD4S12);
|
|
|
|
MD4_STEP_S (MD4_Go, b, c, d, a, w3[0], MD4C01, MD4S13);
|
|
|
|
MD4_STEP_S (MD4_Go, a, b, c, d, w0[1], MD4C01, MD4S10);
|
|
|
|
MD4_STEP_S (MD4_Go, d, a, b, c, w1[1], MD4C01, MD4S11);
|
|
|
|
MD4_STEP_S (MD4_Go, c, d, a, b, w2[1], MD4C01, MD4S12);
|
|
|
|
MD4_STEP_S (MD4_Go, b, c, d, a, w3[1], MD4C01, MD4S13);
|
|
|
|
MD4_STEP_S (MD4_Go, a, b, c, d, w0[2], MD4C01, MD4S10);
|
|
|
|
MD4_STEP_S (MD4_Go, d, a, b, c, w1[2], MD4C01, MD4S11);
|
|
|
|
MD4_STEP_S (MD4_Go, c, d, a, b, w2[2], MD4C01, MD4S12);
|
|
|
|
MD4_STEP_S (MD4_Go, b, c, d, a, w3[2], MD4C01, MD4S13);
|
|
|
|
MD4_STEP_S (MD4_Go, a, b, c, d, w0[3], MD4C01, MD4S10);
|
|
|
|
MD4_STEP_S (MD4_Go, d, a, b, c, w1[3], MD4C01, MD4S11);
|
|
|
|
MD4_STEP_S (MD4_Go, c, d, a, b, w2[3], MD4C01, MD4S12);
|
|
|
|
MD4_STEP_S (MD4_Go, b, c, d, a, w3[3], MD4C01, MD4S13);
|
|
|
|
|
|
|
|
MD4_STEP_S (MD4_H , a, b, c, d, w0[0], MD4C02, MD4S20);
|
|
|
|
MD4_STEP_S (MD4_H , d, a, b, c, w2[0], MD4C02, MD4S21);
|
|
|
|
MD4_STEP_S (MD4_H , c, d, a, b, w1[0], MD4C02, MD4S22);
|
|
|
|
MD4_STEP_S (MD4_H , b, c, d, a, w3[0], MD4C02, MD4S23);
|
|
|
|
MD4_STEP_S (MD4_H , a, b, c, d, w0[2], MD4C02, MD4S20);
|
|
|
|
MD4_STEP_S (MD4_H , d, a, b, c, w2[2], MD4C02, MD4S21);
|
|
|
|
MD4_STEP_S (MD4_H , c, d, a, b, w1[2], MD4C02, MD4S22);
|
|
|
|
MD4_STEP_S (MD4_H , b, c, d, a, w3[2], MD4C02, MD4S23);
|
|
|
|
MD4_STEP_S (MD4_H , a, b, c, d, w0[1], MD4C02, MD4S20);
|
|
|
|
MD4_STEP_S (MD4_H , d, a, b, c, w2[1], MD4C02, MD4S21);
|
|
|
|
MD4_STEP_S (MD4_H , c, d, a, b, w1[1], MD4C02, MD4S22);
|
|
|
|
MD4_STEP_S (MD4_H , b, c, d, a, w3[1], MD4C02, MD4S23);
|
|
|
|
MD4_STEP_S (MD4_H , a, b, c, d, w0[3], MD4C02, MD4S20);
|
|
|
|
MD4_STEP_S (MD4_H , d, a, b, c, w2[3], MD4C02, MD4S21);
|
|
|
|
MD4_STEP_S (MD4_H , c, d, a, b, w1[3], MD4C02, MD4S22);
|
|
|
|
MD4_STEP_S (MD4_H , b, c, d, a, w3[3], MD4C02, MD4S23);
|
|
|
|
|
|
|
|
digest[0] += a;
|
|
|
|
digest[1] += b;
|
|
|
|
digest[2] += c;
|
|
|
|
digest[3] += d;
|
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_init (md4_ctx_t *ctx)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
ctx->h[0] = MD4M_A;
|
|
|
|
ctx->h[1] = MD4M_B;
|
|
|
|
ctx->h[2] = MD4M_C;
|
|
|
|
ctx->h[3] = MD4M_D;
|
|
|
|
|
|
|
|
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;
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_update_64 (md4_ctx_t *ctx, u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], const int len)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
const int pos = ctx->len & 63;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
ctx->len += len;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
|
|
|
if ((pos + len) < 64)
|
|
|
|
{
|
|
|
|
switch_buffer_by_offset_le_S (w0, w1, w2, w3, pos);
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
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];
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
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];
|
|
|
|
|
|
|
|
md4_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];
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_update (md4_ctx_t *ctx, const u32 *w, const int len)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
int pos1;
|
|
|
|
int pos4;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, 64);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
|
|
|
|
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, len - pos1);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_update_global (md4_ctx_t *ctx, const __global u32 *w, const int len)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
int pos1;
|
|
|
|
int pos4;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, 64);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
|
|
|
|
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, len - pos1);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-07-01 16:09:05 +00:00
|
|
|
void md4_update_global_swap (md4_ctx_t *ctx, const __global 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] = swap32_S (w0[0]);
|
|
|
|
w0[1] = swap32_S (w0[1]);
|
|
|
|
w0[2] = swap32_S (w0[2]);
|
|
|
|
w0[3] = swap32_S (w0[3]);
|
|
|
|
w1[0] = swap32_S (w1[0]);
|
|
|
|
w1[1] = swap32_S (w1[1]);
|
|
|
|
w1[2] = swap32_S (w1[2]);
|
|
|
|
w1[3] = swap32_S (w1[3]);
|
|
|
|
w2[0] = swap32_S (w2[0]);
|
|
|
|
w2[1] = swap32_S (w2[1]);
|
|
|
|
w2[2] = swap32_S (w2[2]);
|
|
|
|
w2[3] = swap32_S (w2[3]);
|
|
|
|
w3[0] = swap32_S (w3[0]);
|
|
|
|
w3[1] = swap32_S (w3[1]);
|
|
|
|
w3[2] = swap32_S (w3[2]);
|
|
|
|
w3[3] = swap32_S (w3[3]);
|
|
|
|
|
|
|
|
md4_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] = swap32_S (w0[0]);
|
|
|
|
w0[1] = swap32_S (w0[1]);
|
|
|
|
w0[2] = swap32_S (w0[2]);
|
|
|
|
w0[3] = swap32_S (w0[3]);
|
|
|
|
w1[0] = swap32_S (w1[0]);
|
|
|
|
w1[1] = swap32_S (w1[1]);
|
|
|
|
w1[2] = swap32_S (w1[2]);
|
|
|
|
w1[3] = swap32_S (w1[3]);
|
|
|
|
w2[0] = swap32_S (w2[0]);
|
|
|
|
w2[1] = swap32_S (w2[1]);
|
|
|
|
w2[2] = swap32_S (w2[2]);
|
|
|
|
w2[3] = swap32_S (w2[3]);
|
|
|
|
w3[0] = swap32_S (w3[0]);
|
|
|
|
w3[1] = swap32_S (w3[1]);
|
|
|
|
w3[2] = swap32_S (w3[2]);
|
|
|
|
w3[3] = swap32_S (w3[3]);
|
|
|
|
|
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, len - pos1);
|
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_update_global_utf16le (md4_ctx_t *ctx, const __global u32 *w, const int len)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
|
|
|
u32 w0[4];
|
|
|
|
u32 w1[4];
|
|
|
|
u32 w2[4];
|
|
|
|
u32 w3[4];
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
int pos1;
|
|
|
|
int pos4;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
2017-06-18 21:31:40 +00:00
|
|
|
|
|
|
|
make_utf16le_S (w1, w2, w3);
|
|
|
|
make_utf16le_S (w0, w0, w1);
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, 32 * 2);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
2017-06-18 21:31:40 +00:00
|
|
|
|
|
|
|
make_utf16le_S (w1, w2, w3);
|
|
|
|
make_utf16le_S (w0, w0, w1);
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-07-01 16:09:05 +00:00
|
|
|
void md4_update_global_utf16le_swap (md4_ctx_t *ctx, const __global 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 - 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] = swap32_S (w0[0]);
|
|
|
|
w0[1] = swap32_S (w0[1]);
|
|
|
|
w0[2] = swap32_S (w0[2]);
|
|
|
|
w0[3] = swap32_S (w0[3]);
|
|
|
|
w1[0] = swap32_S (w1[0]);
|
|
|
|
w1[1] = swap32_S (w1[1]);
|
|
|
|
w1[2] = swap32_S (w1[2]);
|
|
|
|
w1[3] = swap32_S (w1[3]);
|
|
|
|
w2[0] = swap32_S (w2[0]);
|
|
|
|
w2[1] = swap32_S (w2[1]);
|
|
|
|
w2[2] = swap32_S (w2[2]);
|
|
|
|
w2[3] = swap32_S (w2[3]);
|
|
|
|
w3[0] = swap32_S (w3[0]);
|
|
|
|
w3[1] = swap32_S (w3[1]);
|
|
|
|
w3[2] = swap32_S (w3[2]);
|
|
|
|
w3[3] = swap32_S (w3[3]);
|
|
|
|
|
|
|
|
md4_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] = swap32_S (w0[0]);
|
|
|
|
w0[1] = swap32_S (w0[1]);
|
|
|
|
w0[2] = swap32_S (w0[2]);
|
|
|
|
w0[3] = swap32_S (w0[3]);
|
|
|
|
w1[0] = swap32_S (w1[0]);
|
|
|
|
w1[1] = swap32_S (w1[1]);
|
|
|
|
w1[2] = swap32_S (w1[2]);
|
|
|
|
w1[3] = swap32_S (w1[3]);
|
|
|
|
w2[0] = swap32_S (w2[0]);
|
|
|
|
w2[1] = swap32_S (w2[1]);
|
|
|
|
w2[2] = swap32_S (w2[2]);
|
|
|
|
w2[3] = swap32_S (w2[3]);
|
|
|
|
w3[0] = swap32_S (w3[0]);
|
|
|
|
w3[1] = swap32_S (w3[1]);
|
|
|
|
w3[2] = swap32_S (w3[2]);
|
|
|
|
w3[3] = swap32_S (w3[3]);
|
|
|
|
|
|
|
|
md4_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2);
|
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_final (md4_ctx_t *ctx)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
const int pos = ctx->len & 63;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
append_0x80_4x4_S (ctx->w0, ctx->w1, ctx->w2, ctx->w3, pos);
|
2017-06-18 21:31:40 +00:00
|
|
|
|
|
|
|
if (pos >= 56)
|
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_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;
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
ctx->w3[2] = ctx->len * 8;
|
|
|
|
ctx->w3[3] = 0;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_transform (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-07-01 16:09:05 +00:00
|
|
|
// md4_hmac
|
|
|
|
|
|
|
|
typedef struct md4_hmac_ctx
|
|
|
|
{
|
|
|
|
md4_ctx_t ipad;
|
|
|
|
md4_ctx_t opad;
|
|
|
|
|
|
|
|
} md4_hmac_ctx_t;
|
|
|
|
|
|
|
|
void md4_hmac_init (md4_hmac_ctx_t *ctx, const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4])
|
|
|
|
{
|
|
|
|
u32 t0[4];
|
|
|
|
u32 t1[4];
|
|
|
|
u32 t2[4];
|
|
|
|
u32 t3[4];
|
|
|
|
|
|
|
|
// ipad
|
|
|
|
|
|
|
|
t0[0] = w0[0] ^ 0x36363636;
|
|
|
|
t0[1] = w0[1] ^ 0x36363636;
|
|
|
|
t0[2] = w0[2] ^ 0x36363636;
|
|
|
|
t0[3] = w0[3] ^ 0x36363636;
|
|
|
|
t1[0] = w1[0] ^ 0x36363636;
|
|
|
|
t1[1] = w1[1] ^ 0x36363636;
|
|
|
|
t1[2] = w1[2] ^ 0x36363636;
|
|
|
|
t1[3] = w1[3] ^ 0x36363636;
|
|
|
|
t2[0] = w2[0] ^ 0x36363636;
|
|
|
|
t2[1] = w2[1] ^ 0x36363636;
|
|
|
|
t2[2] = w2[2] ^ 0x36363636;
|
|
|
|
t2[3] = w2[3] ^ 0x36363636;
|
|
|
|
t3[0] = w3[0] ^ 0x36363636;
|
|
|
|
t3[1] = w3[1] ^ 0x36363636;
|
|
|
|
t3[2] = w3[2] ^ 0x36363636;
|
|
|
|
t3[3] = w3[3] ^ 0x36363636;
|
|
|
|
|
|
|
|
md4_init (&ctx->ipad);
|
|
|
|
|
|
|
|
md4_update_64 (&ctx->ipad, t0, t1, t2, t3, 64);
|
|
|
|
|
|
|
|
// opad
|
|
|
|
|
|
|
|
t0[0] = w0[0] ^ 0x5c5c5c5c;
|
|
|
|
t0[1] = w0[1] ^ 0x5c5c5c5c;
|
|
|
|
t0[2] = w0[2] ^ 0x5c5c5c5c;
|
|
|
|
t0[3] = w0[3] ^ 0x5c5c5c5c;
|
|
|
|
t1[0] = w1[0] ^ 0x5c5c5c5c;
|
|
|
|
t1[1] = w1[1] ^ 0x5c5c5c5c;
|
|
|
|
t1[2] = w1[2] ^ 0x5c5c5c5c;
|
|
|
|
t1[3] = w1[3] ^ 0x5c5c5c5c;
|
|
|
|
t2[0] = w2[0] ^ 0x5c5c5c5c;
|
|
|
|
t2[1] = w2[1] ^ 0x5c5c5c5c;
|
|
|
|
t2[2] = w2[2] ^ 0x5c5c5c5c;
|
|
|
|
t2[3] = w2[3] ^ 0x5c5c5c5c;
|
|
|
|
t3[0] = w3[0] ^ 0x5c5c5c5c;
|
|
|
|
t3[1] = w3[1] ^ 0x5c5c5c5c;
|
|
|
|
t3[2] = w3[2] ^ 0x5c5c5c5c;
|
|
|
|
t3[3] = w3[3] ^ 0x5c5c5c5c;
|
|
|
|
|
|
|
|
md4_init (&ctx->opad);
|
|
|
|
|
|
|
|
md4_update_64 (&ctx->opad, t0, t1, t2, t3, 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
void md4_hmac_update_64 (md4_hmac_ctx_t *ctx, u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], const int len)
|
|
|
|
{
|
|
|
|
md4_update_64 (&ctx->ipad, w0, w1, w2, w3, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void md4_hmac_update (md4_hmac_ctx_t *ctx, const u32 *w, const int len)
|
|
|
|
{
|
|
|
|
md4_update (&ctx->ipad, w, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void md4_hmac_update_global (md4_hmac_ctx_t *ctx, const __global u32 *w, const int len)
|
|
|
|
{
|
|
|
|
md4_update_global (&ctx->ipad, w, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void md4_hmac_update_global_swap (md4_hmac_ctx_t *ctx, const __global u32 *w, const int len)
|
|
|
|
{
|
|
|
|
md4_update_global_swap (&ctx->ipad, w, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void md4_hmac_update_global_utf16le (md4_hmac_ctx_t *ctx, const __global u32 *w, const int len)
|
|
|
|
{
|
|
|
|
md4_update_global_utf16le (&ctx->ipad, w, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void md4_hmac_update_global_utf16le_swap (md4_hmac_ctx_t *ctx, const __global u32 *w, const int len)
|
|
|
|
{
|
|
|
|
md4_update_global_utf16le_swap (&ctx->ipad, w, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void md4_hmac_final (md4_hmac_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
md4_final (&ctx->ipad);
|
|
|
|
|
|
|
|
u32 t0[4];
|
|
|
|
u32 t1[4];
|
|
|
|
u32 t2[4];
|
|
|
|
u32 t3[4];
|
|
|
|
|
|
|
|
t0[0] = ctx->ipad.h[0];
|
|
|
|
t0[1] = ctx->ipad.h[1];
|
|
|
|
t0[2] = ctx->ipad.h[2];
|
|
|
|
t0[3] = ctx->ipad.h[3];
|
|
|
|
t1[0] = 0;
|
|
|
|
t1[1] = 0;
|
|
|
|
t1[2] = 0;
|
|
|
|
t1[3] = 0;
|
|
|
|
t2[0] = 0;
|
|
|
|
t2[1] = 0;
|
|
|
|
t2[2] = 0;
|
|
|
|
t2[3] = 0;
|
|
|
|
t3[0] = 0;
|
|
|
|
t3[1] = 0;
|
|
|
|
t3[2] = 0;
|
|
|
|
t3[3] = 0;
|
|
|
|
|
|
|
|
md4_update_64 (&ctx->opad, t0, t1, t2, t3, 16);
|
|
|
|
|
|
|
|
md4_final (&ctx->opad);
|
|
|
|
}
|
|
|
|
|
2017-06-18 21:31:40 +00:00
|
|
|
// while input buf can be a vector datatype, the length of the different elements can not
|
|
|
|
|
|
|
|
typedef struct md4_ctx_vector
|
|
|
|
{
|
|
|
|
u32x h[4];
|
|
|
|
|
|
|
|
u32x w0[4];
|
|
|
|
u32x w1[4];
|
|
|
|
u32x w2[4];
|
|
|
|
u32x w3[4];
|
|
|
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
} md4_ctx_vector_t;
|
|
|
|
|
|
|
|
void md4_transform_vector (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
|
|
|
|
{
|
|
|
|
u32x a = digest[0];
|
|
|
|
u32x b = digest[1];
|
|
|
|
u32x c = digest[2];
|
|
|
|
u32x d = digest[3];
|
|
|
|
|
|
|
|
MD4_STEP (MD4_Fo, a, b, c, d, w0[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP (MD4_Fo, d, a, b, c, w0[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP (MD4_Fo, c, d, a, b, w0[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP (MD4_Fo, b, c, d, a, w0[3], MD4C00, MD4S03);
|
|
|
|
MD4_STEP (MD4_Fo, a, b, c, d, w1[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP (MD4_Fo, d, a, b, c, w1[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP (MD4_Fo, c, d, a, b, w1[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP (MD4_Fo, b, c, d, a, w1[3], MD4C00, MD4S03);
|
|
|
|
MD4_STEP (MD4_Fo, a, b, c, d, w2[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP (MD4_Fo, d, a, b, c, w2[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP (MD4_Fo, c, d, a, b, w2[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP (MD4_Fo, b, c, d, a, w2[3], MD4C00, MD4S03);
|
|
|
|
MD4_STEP (MD4_Fo, a, b, c, d, w3[0], MD4C00, MD4S00);
|
|
|
|
MD4_STEP (MD4_Fo, d, a, b, c, w3[1], MD4C00, MD4S01);
|
|
|
|
MD4_STEP (MD4_Fo, c, d, a, b, w3[2], MD4C00, MD4S02);
|
|
|
|
MD4_STEP (MD4_Fo, b, c, d, a, w3[3], MD4C00, MD4S03);
|
|
|
|
|
|
|
|
MD4_STEP (MD4_Go, a, b, c, d, w0[0], MD4C01, MD4S10);
|
|
|
|
MD4_STEP (MD4_Go, d, a, b, c, w1[0], MD4C01, MD4S11);
|
|
|
|
MD4_STEP (MD4_Go, c, d, a, b, w2[0], MD4C01, MD4S12);
|
|
|
|
MD4_STEP (MD4_Go, b, c, d, a, w3[0], MD4C01, MD4S13);
|
|
|
|
MD4_STEP (MD4_Go, a, b, c, d, w0[1], MD4C01, MD4S10);
|
|
|
|
MD4_STEP (MD4_Go, d, a, b, c, w1[1], MD4C01, MD4S11);
|
|
|
|
MD4_STEP (MD4_Go, c, d, a, b, w2[1], MD4C01, MD4S12);
|
|
|
|
MD4_STEP (MD4_Go, b, c, d, a, w3[1], MD4C01, MD4S13);
|
|
|
|
MD4_STEP (MD4_Go, a, b, c, d, w0[2], MD4C01, MD4S10);
|
|
|
|
MD4_STEP (MD4_Go, d, a, b, c, w1[2], MD4C01, MD4S11);
|
|
|
|
MD4_STEP (MD4_Go, c, d, a, b, w2[2], MD4C01, MD4S12);
|
|
|
|
MD4_STEP (MD4_Go, b, c, d, a, w3[2], MD4C01, MD4S13);
|
|
|
|
MD4_STEP (MD4_Go, a, b, c, d, w0[3], MD4C01, MD4S10);
|
|
|
|
MD4_STEP (MD4_Go, d, a, b, c, w1[3], MD4C01, MD4S11);
|
|
|
|
MD4_STEP (MD4_Go, c, d, a, b, w2[3], MD4C01, MD4S12);
|
|
|
|
MD4_STEP (MD4_Go, b, c, d, a, w3[3], MD4C01, MD4S13);
|
|
|
|
|
|
|
|
MD4_STEP (MD4_H , a, b, c, d, w0[0], MD4C02, MD4S20);
|
|
|
|
MD4_STEP (MD4_H , d, a, b, c, w2[0], MD4C02, MD4S21);
|
|
|
|
MD4_STEP (MD4_H , c, d, a, b, w1[0], MD4C02, MD4S22);
|
|
|
|
MD4_STEP (MD4_H , b, c, d, a, w3[0], MD4C02, MD4S23);
|
|
|
|
MD4_STEP (MD4_H , a, b, c, d, w0[2], MD4C02, MD4S20);
|
|
|
|
MD4_STEP (MD4_H , d, a, b, c, w2[2], MD4C02, MD4S21);
|
|
|
|
MD4_STEP (MD4_H , c, d, a, b, w1[2], MD4C02, MD4S22);
|
|
|
|
MD4_STEP (MD4_H , b, c, d, a, w3[2], MD4C02, MD4S23);
|
|
|
|
MD4_STEP (MD4_H , a, b, c, d, w0[1], MD4C02, MD4S20);
|
|
|
|
MD4_STEP (MD4_H , d, a, b, c, w2[1], MD4C02, MD4S21);
|
|
|
|
MD4_STEP (MD4_H , c, d, a, b, w1[1], MD4C02, MD4S22);
|
|
|
|
MD4_STEP (MD4_H , b, c, d, a, w3[1], MD4C02, MD4S23);
|
|
|
|
MD4_STEP (MD4_H , a, b, c, d, w0[3], MD4C02, MD4S20);
|
|
|
|
MD4_STEP (MD4_H , d, a, b, c, w2[3], MD4C02, MD4S21);
|
|
|
|
MD4_STEP (MD4_H , c, d, a, b, w1[3], MD4C02, MD4S22);
|
|
|
|
MD4_STEP (MD4_H , b, c, d, a, w3[3], MD4C02, MD4S23);
|
|
|
|
|
|
|
|
digest[0] += a;
|
|
|
|
digest[1] += b;
|
|
|
|
digest[2] += c;
|
|
|
|
digest[3] += d;
|
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_init_vector (md4_ctx_vector_t *ctx)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
ctx->h[0] = MD4M_A;
|
|
|
|
ctx->h[1] = MD4M_B;
|
|
|
|
ctx->h[2] = MD4M_C;
|
|
|
|
ctx->h[3] = MD4M_D;
|
|
|
|
|
|
|
|
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;
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_update_vector_64 (md4_ctx_vector_t *ctx, u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], const int len)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
const int pos = ctx->len & 63;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
ctx->len += len;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
|
|
|
if ((pos + len) < 64)
|
|
|
|
{
|
|
|
|
switch_buffer_by_offset_le (w0, w1, w2, w3, pos);
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
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];
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
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];
|
|
|
|
|
|
|
|
md4_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];
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_update_vector (md4_ctx_vector_t *ctx, const u32x *w, const int len)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
|
|
|
u32x w0[4];
|
|
|
|
u32x w1[4];
|
|
|
|
u32x w2[4];
|
|
|
|
u32x w3[4];
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
int pos1;
|
|
|
|
int pos4;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_update_vector_64 (ctx, w0, w1, w2, w3, 64);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 14:21:12 +00:00
|
|
|
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];
|
|
|
|
|
|
|
|
md4_update_vector_64 (ctx, w0, w1, w2, w3, len - pos1);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
void md4_final_vector (md4_ctx_vector_t *ctx)
|
2017-06-18 21:31:40 +00:00
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
const int pos = ctx->len & 63;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
append_0x80_4x4 (ctx->w0, ctx->w1, ctx->w2, ctx->w3, pos);
|
2017-06-18 21:31:40 +00:00
|
|
|
|
|
|
|
if (pos >= 56)
|
|
|
|
{
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_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;
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
ctx->w3[2] = ctx->len * 8;
|
|
|
|
ctx->w3[3] = 0;
|
2017-06-18 21:31:40 +00:00
|
|
|
|
2017-06-19 14:42:21 +00:00
|
|
|
md4_transform_vector (ctx->w0, ctx->w1, ctx->w2, ctx->w3, ctx->h);
|
2017-06-18 21:31:40 +00:00
|
|
|
}
|