1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-25 17:38:23 +00:00

Finishing inc_hash_blake2s and starting to write kernels

This commit is contained in:
Louka 2023-02-06 15:27:07 +01:00
parent 33762965f6
commit 12821a968b
5 changed files with 450 additions and 524 deletions

View File

@ -10,6 +10,59 @@
#include "inc_hash_blake2s.h" #include "inc_hash_blake2s.h"
DECLSPEC u32 blake2s_rot16_S (const u32 a) DECLSPEC u32 blake2s_rot16_S (const u32 a)
{
vconv32_t in;
in.v32 = a;
vconv32_t out;
out.v16.a = in.v16.b;
out.v16.b = in.v16.a;
return out.v32;
}
DECLSPEC u32x blake2s_rot16 (const u32x a)
{
u32x r;
#if VECT_SIZE == 1
r = blake2s_rot16_S (a);
#endif
#if VECT_SIZE >= 2
r.s0 = blake2s_rot16_S (a.s0);
r.s1 = blake2s_rot16_S (a.s1);
#endif
#if VECT_SIZE >= 4
r.s2 = blake2s_rot16_S (a.s2);
r.s3 = blake2s_rot16_S (a.s3);
#endif
#if VECT_SIZE >= 8
r.s4 = blake2s_rot16_S (a.s4);
r.s5 = blake2s_rot16_S (a.s5);
r.s6 = blake2s_rot16_S (a.s6);
r.s7 = blake2s_rot16_S (a.s7);
#endif
#if VECT_SIZE >= 16
r.s8 = blake2s_rot16_S (a.s8);
r.s9 = blake2s_rot16_S (a.s9);
r.sa = blake2s_rot16_S (a.sa);
r.sb = blake2s_rot16_S (a.sb);
r.sc = blake2s_rot16_S (a.sc);
r.sd = blake2s_rot16_S (a.sd);
r.se = blake2s_rot16_S (a.se);
r.sf = blake2s_rot16_S (a.sf);
#endif
return r;
}
DECLSPEC u32 blake2s_rot08_S (const u32 a)
{ {
#if defined IS_NV #if defined IS_NV
@ -19,8 +72,7 @@ DECLSPEC u32 blake2s_rot16_S (const u32 a)
vconv32_t out; vconv32_t out;
out.v16.a = hc_byte_perm_S (in.v16.b, in.v16.a, 0x1076); out.v32 = hc_byte_perm_S (in.v32.b, in.v32.a, 0x0321);
out.v16.b = hc_byte_perm_S (in.v16.b, in.v16.a, 0x5432);
return out.v32; return out.v32;
@ -32,189 +84,61 @@ DECLSPEC u32 blake2s_rot16_S (const u32 a)
vconv32_t out; vconv32_t out;
out.v16.a = hc_byte_perm_S (in.v16.b, in.v16.a, 0x01000706); out.v32 = hc_byte_perm_S (in.v32.b, in.v32.a, 0x00030201);
out.v16.b = hc_byte_perm_S (in.v16.b, in.v16.a, 0x05040302);
return out.v64; return out.v32;
#else #else
return hc_rotr64_S (a, 16); return hc_rotr32_S (a, 8);
#endif #endif
} }
DECLSPEC u64x blake2b_rot16 (const u64x a) DECLSPEC u32x blake2S_rot08 (const u32x a)
{ {
u64x r; u32x r;
#if VECT_SIZE == 1 #if VECT_SIZE == 1
r = blake2b_rot16_S (a); r = blake2s_rot08_S (a);
#endif #endif
#if VECT_SIZE >= 2 #if VECT_SIZE >= 2
r.s0 = blake2b_rot16_S (a.s0); r.s0 = blake2s_rot08_S (a.s0);
r.s1 = blake2b_rot16_S (a.s1); r.s1 = blake2s_rot08_S (a.s1);
#endif #endif
#if VECT_SIZE >= 4 #if VECT_SIZE >= 4
r.s2 = blake2b_rot16_S (a.s2); r.s2 = blake2s_rot08_S (a.s2);
r.s3 = blake2b_rot16_S (a.s3); r.s3 = blake2s_rot08_S (a.s3);
#endif #endif
#if VECT_SIZE >= 8 #if VECT_SIZE >= 8
r.s4 = blake2b_rot16_S (a.s4); r.s4 = blake2s_rot08_S (a.s4);
r.s5 = blake2b_rot16_S (a.s5); r.s5 = blake2s_rot08_S (a.s5);
r.s6 = blake2b_rot16_S (a.s6); r.s6 = blake2s_rot08_S (a.s6);
r.s7 = blake2b_rot16_S (a.s7); r.s7 = blake2s_rot08_S (a.s7);
#endif #endif
#if VECT_SIZE >= 16 #if VECT_SIZE >= 16
r.s8 = blake2b_rot16_S (a.s8); r.s8 = blake2s_rot08_S (a.s8);
r.s9 = blake2b_rot16_S (a.s9); r.s9 = blake2s_rot08_S (a.s9);
r.sa = blake2b_rot16_S (a.sa); r.sa = blake2s_rot08_S (a.sa);
r.sb = blake2b_rot16_S (a.sb); r.sb = blake2s_rot08_S (a.sb);
r.sc = blake2b_rot16_S (a.sc); r.sc = blake2s_rot08_S (a.sc);
r.sd = blake2b_rot16_S (a.sd); r.sd = blake2s_rot08_S (a.sd);
r.se = blake2b_rot16_S (a.se); r.se = blake2s_rot08_S (a.se);
r.sf = blake2b_rot16_S (a.sf); r.sf = blake2s_rot08_S (a.sf);
#endif #endif
return r; return r;
} }
DECLSPEC u64 blake2b_rot24_S (const u64 a) DECLSPEC void blake2s_transform (PRIVATE_AS u32 *h, PRIVATE_AS const u32 *m, const int len, const u32 f0)
{ {
#if defined IS_NV const u32 t0 = len;
vconv64_t in; u32 v[16];
in.v64 = a;
vconv64_t out;
out.v32.a = hc_byte_perm_S (in.v32.b, in.v32.a, 0x2107);
out.v32.b = hc_byte_perm_S (in.v32.b, in.v32.a, 0x6543);
return out.v64;
#elif (defined IS_AMD || defined IS_HIP) && HAS_VPERM == 1
vconv64_t in;
in.v64 = a;
vconv64_t out;
out.v32.a = hc_byte_perm_S (in.v32.b, in.v32.a, 0x02010007);
out.v32.b = hc_byte_perm_S (in.v32.b, in.v32.a, 0x06050403);
return out.v64;
#else
return hc_rotr64_S (a, 24);
#endif
}
DECLSPEC u64x blake2b_rot24 (const u64x a)
{
u64x r;
#if VECT_SIZE == 1
r = blake2b_rot24_S (a);
#endif
#if VECT_SIZE >= 2
r.s0 = blake2b_rot24_S (a.s0);
r.s1 = blake2b_rot24_S (a.s1);
#endif
#if VECT_SIZE >= 4
r.s2 = blake2b_rot24_S (a.s2);
r.s3 = blake2b_rot24_S (a.s3);
#endif
#if VECT_SIZE >= 8
r.s4 = blake2b_rot24_S (a.s4);
r.s5 = blake2b_rot24_S (a.s5);
r.s6 = blake2b_rot24_S (a.s6);
r.s7 = blake2b_rot24_S (a.s7);
#endif
#if VECT_SIZE >= 16
r.s8 = blake2b_rot24_S (a.s8);
r.s9 = blake2b_rot24_S (a.s9);
r.sa = blake2b_rot24_S (a.sa);
r.sb = blake2b_rot24_S (a.sb);
r.sc = blake2b_rot24_S (a.sc);
r.sd = blake2b_rot24_S (a.sd);
r.se = blake2b_rot24_S (a.se);
r.sf = blake2b_rot24_S (a.sf);
#endif
return r;
}
DECLSPEC u64 blake2b_rot32_S (const u64 a)
{
vconv64_t in;
in.v64 = a;
vconv64_t out;
out.v32.a = in.v32.b;
out.v32.b = in.v32.a;
return out.v64;
}
DECLSPEC u64x blake2b_rot32 (const u64x a)
{
u64x r;
#if VECT_SIZE == 1
r = blake2b_rot32_S (a);
#endif
#if VECT_SIZE >= 2
r.s0 = blake2b_rot32_S (a.s0);
r.s1 = blake2b_rot32_S (a.s1);
#endif
#if VECT_SIZE >= 4
r.s2 = blake2b_rot32_S (a.s2);
r.s3 = blake2b_rot32_S (a.s3);
#endif
#if VECT_SIZE >= 8
r.s4 = blake2b_rot32_S (a.s4);
r.s5 = blake2b_rot32_S (a.s5);
r.s6 = blake2b_rot32_S (a.s6);
r.s7 = blake2b_rot32_S (a.s7);
#endif
#if VECT_SIZE >= 16
r.s8 = blake2b_rot32_S (a.s8);
r.s9 = blake2b_rot32_S (a.s9);
r.sa = blake2b_rot32_S (a.sa);
r.sb = blake2b_rot32_S (a.sb);
r.sc = blake2b_rot32_S (a.sc);
r.sd = blake2b_rot32_S (a.sd);
r.se = blake2b_rot32_S (a.se);
r.sf = blake2b_rot32_S (a.sf);
#endif
return r;
}
DECLSPEC void blake2b_transform (PRIVATE_AS u64 *h, PRIVATE_AS const u64 *m, const int len, const u64 f0)
{
const u64 t0 = hl32_to_64_S (0, len);
u64 v[16];
v[ 0] = h[0]; v[ 0] = h[0];
v[ 1] = h[1]; v[ 1] = h[1];
@ -224,14 +148,14 @@ DECLSPEC void blake2b_transform (PRIVATE_AS u64 *h, PRIVATE_AS const u64 *m, con
v[ 5] = h[5]; v[ 5] = h[5];
v[ 6] = h[6]; v[ 6] = h[6];
v[ 7] = h[7]; v[ 7] = h[7];
v[ 8] = BLAKE2B_IV_00; v[ 8] = BLAKE2S_IV_00;
v[ 9] = BLAKE2B_IV_01; v[ 9] = BLAKE2S_IV_01;
v[10] = BLAKE2B_IV_02; v[10] = BLAKE2S_IV_02;
v[11] = BLAKE2B_IV_03; v[11] = BLAKE2S_IV_03;
v[12] = BLAKE2B_IV_04 ^ t0; v[12] = BLAKE2S_IV_04 ^ t0;
v[13] = BLAKE2B_IV_05; // ^ t1; v[13] = BLAKE2S_IV_05; // ^ t1;
v[14] = BLAKE2B_IV_06 ^ f0; v[14] = BLAKE2S_IV_06 ^ f0;
v[15] = BLAKE2B_IV_07; // ^ f1; v[15] = BLAKE2S_IV_07; // ^ f1;
BLAKE2S_ROUND ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); BLAKE2S_ROUND ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
BLAKE2S_ROUND (14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3); BLAKE2S_ROUND (14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3);
@ -254,16 +178,16 @@ DECLSPEC void blake2b_transform (PRIVATE_AS u64 *h, PRIVATE_AS const u64 *m, con
h[7] = h[7] ^ v[7] ^ v[15]; h[7] = h[7] ^ v[7] ^ v[15];
} }
DECLSPEC void blake2b_init (PRIVATE_AS blake2b_ctx_t *ctx) DECLSPEC void blake2s_init (PRIVATE_AS blake2s_ctx_t *ctx)
{ {
ctx->h[0] = BLAKE2B_IV_00 ^ 0x01010040; // default output length: 0x40 = 64 bytes ctx->h[0] = BLAKE2S_IV_00 ^ 0x01010020; // default output length: 0x20 = 32 bytes
ctx->h[1] = BLAKE2B_IV_01; ctx->h[1] = BLAKE2S_IV_01;
ctx->h[2] = BLAKE2B_IV_02; ctx->h[2] = BLAKE2S_IV_02;
ctx->h[3] = BLAKE2B_IV_03; ctx->h[3] = BLAKE2S_IV_03;
ctx->h[4] = BLAKE2B_IV_04; ctx->h[4] = BLAKE2S_IV_04;
ctx->h[5] = BLAKE2B_IV_05; ctx->h[5] = BLAKE2S_IV_05;
ctx->h[6] = BLAKE2B_IV_06; ctx->h[6] = BLAKE2S_IV_06;
ctx->h[7] = BLAKE2B_IV_07; ctx->h[7] = BLAKE2S_IV_07;
ctx->m[ 0] = 0; ctx->m[ 0] = 0;
ctx->m[ 1] = 0; ctx->m[ 1] = 0;
@ -285,58 +209,58 @@ DECLSPEC void blake2b_init (PRIVATE_AS blake2b_ctx_t *ctx)
ctx->len = 0; ctx->len = 0;
} }
DECLSPEC void blake2b_update_128 (PRIVATE_AS blake2b_ctx_t *ctx, PRIVATE_AS u32 *w0, PRIVATE_AS u32 *w1, PRIVATE_AS u32 *w2, PRIVATE_AS u32 *w3, PRIVATE_AS u32 *w4, PRIVATE_AS u32 *w5, PRIVATE_AS u32 *w6, PRIVATE_AS u32 *w7, const int len) DECLSPEC void blake2s_update_64 (PRIVATE_AS blake2s_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; if (len == 0) return;
const int pos = ctx->len & 127; const int pos = ctx->len & 63;
if (pos == 0) if (pos == 0)
{ {
if (ctx->len > 0) // if new block (pos == 0) AND the (old) len is not zero => transform if (ctx->len > 0) // if new block (pos == 0) AND the (old) len is not zero => transform
{ {
blake2b_transform (ctx->h, ctx->m, ctx->len, BLAKE2B_UPDATE); blake2s_transform (ctx->h, ctx->m, ctx->len, BLAKE2S_UPDATE);
} }
ctx->m[ 0] = hl32_to_64_S (w0[1], w0[0]); ctx->m[ 0] = w0[0];
ctx->m[ 1] = hl32_to_64_S (w0[3], w0[2]); ctx->m[ 1] = w0[1];
ctx->m[ 2] = hl32_to_64_S (w1[1], w1[0]); ctx->m[ 2] = w0[2];
ctx->m[ 3] = hl32_to_64_S (w1[3], w1[2]); ctx->m[ 3] = w0[3];
ctx->m[ 4] = hl32_to_64_S (w2[1], w2[0]); ctx->m[ 4] = w1[0];
ctx->m[ 5] = hl32_to_64_S (w2[3], w2[2]); ctx->m[ 5] = w1[1];
ctx->m[ 6] = hl32_to_64_S (w3[1], w3[0]); ctx->m[ 6] = w1[2];
ctx->m[ 7] = hl32_to_64_S (w3[3], w3[2]); ctx->m[ 7] = w1[3];
ctx->m[ 8] = hl32_to_64_S (w4[1], w4[0]); ctx->m[ 8] = w2[0];
ctx->m[ 9] = hl32_to_64_S (w4[3], w4[2]); ctx->m[ 9] = w2[1];
ctx->m[10] = hl32_to_64_S (w5[1], w5[0]); ctx->m[10] = w2[2];
ctx->m[11] = hl32_to_64_S (w5[3], w5[2]); ctx->m[11] = w2[3];
ctx->m[12] = hl32_to_64_S (w6[1], w6[0]); ctx->m[12] = w3[0];
ctx->m[13] = hl32_to_64_S (w6[3], w6[2]); ctx->m[13] = w3[1];
ctx->m[14] = hl32_to_64_S (w7[1], w7[0]); ctx->m[14] = w3[2];
ctx->m[15] = hl32_to_64_S (w7[3], w7[2]); ctx->m[15] = w3[3];
} }
else else
{ {
if ((pos + len) <= 128) if ((pos + len) <= 64)
{ {
switch_buffer_by_offset_8x4_le_S (w0, w1, w2, w3, w4, w5, w6, w7, pos); switch_buffer_by_offset_le_S (w0, w1, w2, w3, pos);
ctx->m[ 0] |= hl32_to_64_S (w0[1], w0[0]); ctx->m[ 0] |= w0[0];
ctx->m[ 1] |= hl32_to_64_S (w0[3], w0[2]); ctx->m[ 1] |= w0[1];
ctx->m[ 2] |= hl32_to_64_S (w1[1], w1[0]); ctx->m[ 2] |= w0[2];
ctx->m[ 3] |= hl32_to_64_S (w1[3], w1[2]); ctx->m[ 3] |= w0[3];
ctx->m[ 4] |= hl32_to_64_S (w2[1], w2[0]); ctx->m[ 4] |= w1[0];
ctx->m[ 5] |= hl32_to_64_S (w2[3], w2[2]); ctx->m[ 5] |= w1[1];
ctx->m[ 6] |= hl32_to_64_S (w3[1], w3[0]); ctx->m[ 6] |= w1[2];
ctx->m[ 7] |= hl32_to_64_S (w3[3], w3[2]); ctx->m[ 7] |= w1[3];
ctx->m[ 8] |= hl32_to_64_S (w4[1], w4[0]); ctx->m[ 8] |= w2[0];
ctx->m[ 9] |= hl32_to_64_S (w4[3], w4[2]); ctx->m[ 9] |= w2[1];
ctx->m[10] |= hl32_to_64_S (w5[1], w5[0]); ctx->m[10] |= w2[2];
ctx->m[11] |= hl32_to_64_S (w5[3], w5[2]); ctx->m[11] |= w2[3];
ctx->m[12] |= hl32_to_64_S (w6[1], w6[0]); ctx->m[12] |= w3[0];
ctx->m[13] |= hl32_to_64_S (w6[3], w6[2]); ctx->m[13] |= w3[1];
ctx->m[14] |= hl32_to_64_S (w7[1], w7[0]); ctx->m[14] |= w3[2];
ctx->m[15] |= hl32_to_64_S (w7[3], w7[2]); ctx->m[15] |= w3[3];
} }
else else
{ {
@ -344,75 +268,67 @@ DECLSPEC void blake2b_update_128 (PRIVATE_AS blake2b_ctx_t *ctx, PRIVATE_AS u32
u32 c1[4] = { 0 }; u32 c1[4] = { 0 };
u32 c2[4] = { 0 }; u32 c2[4] = { 0 };
u32 c3[4] = { 0 }; u32 c3[4] = { 0 };
u32 c4[4] = { 0 };
u32 c5[4] = { 0 };
u32 c6[4] = { 0 };
u32 c7[4] = { 0 };
switch_buffer_by_offset_8x4_carry_le_S (w0, w1, w2, w3, w4, w5, w6, w7, c0, c1, c2, c3, c4, c5, c6, c7, pos); switch_buffer_by_offset_carry_le_S (w0, w1, w2, w3, c0, c1, c2, c3, pos);
ctx->m[ 0] |= hl32_to_64_S (w0[1], w0[0]); ctx->m[ 0] |= w0[0];
ctx->m[ 1] |= hl32_to_64_S (w0[3], w0[2]); ctx->m[ 1] |= w0[1];
ctx->m[ 2] |= hl32_to_64_S (w1[1], w1[0]); ctx->m[ 2] |= w0[2];
ctx->m[ 3] |= hl32_to_64_S (w1[3], w1[2]); ctx->m[ 3] |= w0[3];
ctx->m[ 4] |= hl32_to_64_S (w2[1], w2[0]); ctx->m[ 4] |= w1[0];
ctx->m[ 5] |= hl32_to_64_S (w2[3], w2[2]); ctx->m[ 5] |= w1[1];
ctx->m[ 6] |= hl32_to_64_S (w3[1], w3[0]); ctx->m[ 6] |= w1[2];
ctx->m[ 7] |= hl32_to_64_S (w3[3], w3[2]); ctx->m[ 7] |= w1[3];
ctx->m[ 8] |= hl32_to_64_S (w4[1], w4[0]); ctx->m[ 8] |= w2[0];
ctx->m[ 9] |= hl32_to_64_S (w4[3], w4[2]); ctx->m[ 9] |= w2[1];
ctx->m[10] |= hl32_to_64_S (w5[1], w5[0]); ctx->m[10] |= w2[2];
ctx->m[11] |= hl32_to_64_S (w5[3], w5[2]); ctx->m[11] |= w2[3];
ctx->m[12] |= hl32_to_64_S (w6[1], w6[0]); ctx->m[12] |= w3[0];
ctx->m[13] |= hl32_to_64_S (w6[3], w6[2]); ctx->m[13] |= w3[1];
ctx->m[14] |= hl32_to_64_S (w7[1], w7[0]); ctx->m[14] |= w3[2];
ctx->m[15] |= hl32_to_64_S (w7[3], w7[2]); ctx->m[15] |= w3[3];
// len must be a multiple of 128 (not ctx->len) for BLAKE2B_UPDATE: // len must be a multiple of 64 (not ctx->len) for BLAKE2S_UPDATE:
const u32 cur_len = ((ctx->len + len) / 128) * 128; const u32 cur_len = ((ctx->len + len) / 64) * 64;
blake2b_transform (ctx->h, ctx->m, cur_len, BLAKE2B_UPDATE); blake2s_transform (ctx->h, ctx->m, cur_len, BLAKE2S_UPDATE);
ctx->m[ 0] = hl32_to_64_S (c0[1], c0[0]); ctx->m[ 0] = c0[0];
ctx->m[ 1] = hl32_to_64_S (c0[3], c0[2]); ctx->m[ 1] = c0[1];
ctx->m[ 2] = hl32_to_64_S (c1[1], c1[0]); ctx->m[ 2] = c0[2];
ctx->m[ 3] = hl32_to_64_S (c1[3], c1[2]); ctx->m[ 3] = c0[3];
ctx->m[ 4] = hl32_to_64_S (c2[1], c2[0]); ctx->m[ 4] = c1[0];
ctx->m[ 5] = hl32_to_64_S (c2[3], c2[2]); ctx->m[ 5] = c1[1];
ctx->m[ 6] = hl32_to_64_S (c3[1], c3[0]); ctx->m[ 6] = c1[2];
ctx->m[ 7] = hl32_to_64_S (c3[3], c3[2]); ctx->m[ 7] = c1[3];
ctx->m[ 8] = hl32_to_64_S (c4[1], c4[0]); ctx->m[ 8] = c2[0];
ctx->m[ 9] = hl32_to_64_S (c4[3], c4[2]); ctx->m[ 9] = c2[1];
ctx->m[10] = hl32_to_64_S (c5[1], c5[0]); ctx->m[10] = c2[2];
ctx->m[11] = hl32_to_64_S (c5[3], c5[2]); ctx->m[11] = c2[3];
ctx->m[12] = hl32_to_64_S (c6[1], c6[0]); ctx->m[12] = c3[0];
ctx->m[13] = hl32_to_64_S (c6[3], c6[2]); ctx->m[13] = c3[1];
ctx->m[14] = hl32_to_64_S (c7[1], c7[0]); ctx->m[14] = c3[2];
ctx->m[15] = hl32_to_64_S (c7[3], c7[2]); ctx->m[15] = c3[3];
} }
} }
ctx->len += len; ctx->len += len;
} }
DECLSPEC void blake2b_update (PRIVATE_AS blake2b_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len) DECLSPEC void blake2s_update (PRIVATE_AS blake2s_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len)
{ {
u32 w0[4]; u32 w0[4];
u32 w1[4]; u32 w1[4];
u32 w2[4]; u32 w2[4];
u32 w3[4]; u32 w3[4];
u32 w4[4];
u32 w5[4];
u32 w6[4];
u32 w7[4];
const int limit = (const int) len - 128; // int type needed, could be negative const int limit = (const int) len - 64; // int type needed, could be negative
int pos1; int pos1;
int pos4; int pos4;
for (pos1 = 0, pos4 = 0; pos1 < limit; pos1 += 128, pos4 += 32) for (pos1 = 0, pos4 = 0; pos1 < limit; pos1 += 64, pos4 += 16)
{ {
w0[0] = w[pos4 + 0]; w0[0] = w[pos4 + 0];
w0[1] = w[pos4 + 1]; w0[1] = w[pos4 + 1];
@ -430,24 +346,8 @@ DECLSPEC void blake2b_update (PRIVATE_AS blake2b_ctx_t *ctx, PRIVATE_AS const u3
w3[1] = w[pos4 + 13]; w3[1] = w[pos4 + 13];
w3[2] = w[pos4 + 14]; w3[2] = w[pos4 + 14];
w3[3] = w[pos4 + 15]; w3[3] = w[pos4 + 15];
w4[0] = w[pos4 + 16];
w4[1] = w[pos4 + 17]; blake2s_update_64 (ctx, w0, w1, w2, w3, 64);
w4[2] = w[pos4 + 18];
w4[3] = w[pos4 + 19];
w5[0] = w[pos4 + 20];
w5[1] = w[pos4 + 21];
w5[2] = w[pos4 + 22];
w5[3] = w[pos4 + 23];
w6[0] = w[pos4 + 24];
w6[1] = w[pos4 + 25];
w6[2] = w[pos4 + 26];
w6[3] = w[pos4 + 27];
w7[0] = w[pos4 + 28];
w7[1] = w[pos4 + 29];
w7[2] = w[pos4 + 30];
w7[3] = w[pos4 + 31];
blake2b_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128);
} }
w0[0] = w[pos4 + 0]; w0[0] = w[pos4 + 0];
@ -466,43 +366,23 @@ DECLSPEC void blake2b_update (PRIVATE_AS blake2b_ctx_t *ctx, PRIVATE_AS const u3
w3[1] = w[pos4 + 13]; w3[1] = w[pos4 + 13];
w3[2] = w[pos4 + 14]; w3[2] = w[pos4 + 14];
w3[3] = w[pos4 + 15]; w3[3] = w[pos4 + 15];
w4[0] = w[pos4 + 16];
w4[1] = w[pos4 + 17];
w4[2] = w[pos4 + 18];
w4[3] = w[pos4 + 19];
w5[0] = w[pos4 + 20];
w5[1] = w[pos4 + 21];
w5[2] = w[pos4 + 22];
w5[3] = w[pos4 + 23];
w6[0] = w[pos4 + 24];
w6[1] = w[pos4 + 25];
w6[2] = w[pos4 + 26];
w6[3] = w[pos4 + 27];
w7[0] = w[pos4 + 28];
w7[1] = w[pos4 + 29];
w7[2] = w[pos4 + 30];
w7[3] = w[pos4 + 31];
blake2b_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - (u32) pos1); blake2s_update_64 (ctx, w0, w1, w2, w3, len - (u32) pos1);
} }
DECLSPEC void blake2b_update_global (PRIVATE_AS blake2b_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len) DECLSPEC void blake2s_update_global (PRIVATE_AS blake2s_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{ {
u32 w0[4]; u32 w0[4];
u32 w1[4]; u32 w1[4];
u32 w2[4]; u32 w2[4];
u32 w3[4]; u32 w3[4];
u32 w4[4];
u32 w5[4];
u32 w6[4];
u32 w7[4];
const int limit = (const int) len - 128; // int type needed, could be negative const int limit = (const int) len - 64; // int type needed, could be negative
int pos1; int pos1;
int pos4; int pos4;
for (pos1 = 0, pos4 = 0; pos1 < limit; pos1 += 128, pos4 += 32) for (pos1 = 0, pos4 = 0; pos1 < limit; pos1 += 64, pos4 += 16)
{ {
w0[0] = w[pos4 + 0]; w0[0] = w[pos4 + 0];
w0[1] = w[pos4 + 1]; w0[1] = w[pos4 + 1];
@ -520,24 +400,8 @@ DECLSPEC void blake2b_update_global (PRIVATE_AS blake2b_ctx_t *ctx, GLOBAL_AS co
w3[1] = w[pos4 + 13]; w3[1] = w[pos4 + 13];
w3[2] = w[pos4 + 14]; w3[2] = w[pos4 + 14];
w3[3] = w[pos4 + 15]; w3[3] = w[pos4 + 15];
w4[0] = w[pos4 + 16];
w4[1] = w[pos4 + 17];
w4[2] = w[pos4 + 18];
w4[3] = w[pos4 + 19];
w5[0] = w[pos4 + 20];
w5[1] = w[pos4 + 21];
w5[2] = w[pos4 + 22];
w5[3] = w[pos4 + 23];
w6[0] = w[pos4 + 24];
w6[1] = w[pos4 + 25];
w6[2] = w[pos4 + 26];
w6[3] = w[pos4 + 27];
w7[0] = w[pos4 + 28];
w7[1] = w[pos4 + 29];
w7[2] = w[pos4 + 30];
w7[3] = w[pos4 + 31];
blake2b_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128); blake2s_update_64 (ctx, w0, w1, w2, w3, 64);
} }
w0[0] = w[pos4 + 0]; w0[0] = w[pos4 + 0];
@ -556,36 +420,20 @@ DECLSPEC void blake2b_update_global (PRIVATE_AS blake2b_ctx_t *ctx, GLOBAL_AS co
w3[1] = w[pos4 + 13]; w3[1] = w[pos4 + 13];
w3[2] = w[pos4 + 14]; w3[2] = w[pos4 + 14];
w3[3] = w[pos4 + 15]; w3[3] = w[pos4 + 15];
w4[0] = w[pos4 + 16];
w4[1] = w[pos4 + 17];
w4[2] = w[pos4 + 18];
w4[3] = w[pos4 + 19];
w5[0] = w[pos4 + 20];
w5[1] = w[pos4 + 21];
w5[2] = w[pos4 + 22];
w5[3] = w[pos4 + 23];
w6[0] = w[pos4 + 24];
w6[1] = w[pos4 + 25];
w6[2] = w[pos4 + 26];
w6[3] = w[pos4 + 27];
w7[0] = w[pos4 + 28];
w7[1] = w[pos4 + 29];
w7[2] = w[pos4 + 30];
w7[3] = w[pos4 + 31];
blake2b_update_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - (u32) pos1); blake2s_update_64 (ctx, w0, w1, w2, w3, len - (u32) pos1);
} }
DECLSPEC void blake2b_final (PRIVATE_AS blake2b_ctx_t *ctx) DECLSPEC void blake2s_final (PRIVATE_AS blake2s_ctx_t *ctx)
{ {
blake2b_transform (ctx->h, ctx->m, ctx->len, BLAKE2B_FINAL); blake2s_transform (ctx->h, ctx->m, ctx->len, BLAKE2S_FINAL);
} }
DECLSPEC void blake2b_transform_vector (PRIVATE_AS u64x *h, PRIVATE_AS const u64x *m, const u32x len, const u64 f0) DECLSPEC void blake2s_transform_vector (PRIVATE_AS u32x *h, PRIVATE_AS const u32x *m, const u32x len, const u32 f0)
{ {
const u64x t0 = hl32_to_64 (0, len); const u32x t0 = len;
u64x v[16]; u32x v[16];
v[ 0] = h[0]; v[ 0] = h[0];
v[ 1] = h[1]; v[ 1] = h[1];
@ -595,14 +443,14 @@ DECLSPEC void blake2b_transform_vector (PRIVATE_AS u64x *h, PRIVATE_AS const u64
v[ 5] = h[5]; v[ 5] = h[5];
v[ 6] = h[6]; v[ 6] = h[6];
v[ 7] = h[7]; v[ 7] = h[7];
v[ 8] = BLAKE2B_IV_00; v[ 8] = BLAKE2S_IV_00;
v[ 9] = BLAKE2B_IV_01; v[ 9] = BLAKE2S_IV_01;
v[10] = BLAKE2B_IV_02; v[10] = BLAKE2S_IV_02;
v[11] = BLAKE2B_IV_03; v[11] = BLAKE2S_IV_03;
v[12] = make_u64x (BLAKE2B_IV_04) ^ t0; v[12] = BLAKE2S_IV_04 ^ t0;
v[13] = BLAKE2B_IV_05; // ^ t1; v[13] = BLAKE2S_IV_05; // ^ t1;
v[14] = make_u64x (BLAKE2B_IV_06) ^ f0; v[14] = BLAKE2S_IV_06 ^ f0;
v[15] = BLAKE2B_IV_07; // ^ f1; v[15] = BLAKE2S_IV_07; // ^ f1;
BLAKE2S_ROUND_VECTOR ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); BLAKE2S_ROUND_VECTOR ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
BLAKE2S_ROUND_VECTOR (14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3); BLAKE2S_ROUND_VECTOR (14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3);
@ -625,16 +473,16 @@ DECLSPEC void blake2b_transform_vector (PRIVATE_AS u64x *h, PRIVATE_AS const u64
h[7] = h[7] ^ v[7] ^ v[15]; h[7] = h[7] ^ v[7] ^ v[15];
} }
DECLSPEC void blake2b_init_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx) DECLSPEC void blake2s_init_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx)
{ {
ctx->h[0] = BLAKE2B_IV_00 ^ 0x01010040; // default output length: 0x40 = 64 bytes ctx->h[0] = BLAKE2S_IV_00 ^ 0x01010020; // default output length: 0x20 = 32 bytes
ctx->h[1] = BLAKE2B_IV_01; ctx->h[1] = BLAKE2S_IV_01;
ctx->h[2] = BLAKE2B_IV_02; ctx->h[2] = BLAKE2S_IV_02;
ctx->h[3] = BLAKE2B_IV_03; ctx->h[3] = BLAKE2S_IV_03;
ctx->h[4] = BLAKE2B_IV_04; ctx->h[4] = BLAKE2S_IV_04;
ctx->h[5] = BLAKE2B_IV_05; ctx->h[5] = BLAKE2S_IV_05;
ctx->h[6] = BLAKE2B_IV_06; ctx->h[6] = BLAKE2S_IV_06;
ctx->h[7] = BLAKE2B_IV_07; ctx->h[7] = BLAKE2S_IV_07;
ctx->m[ 0] = 0; ctx->m[ 0] = 0;
ctx->m[ 1] = 0; ctx->m[ 1] = 0;
@ -656,7 +504,7 @@ DECLSPEC void blake2b_init_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx)
ctx->len = 0; ctx->len = 0;
} }
DECLSPEC void blake2b_init_vector_from_scalar (PRIVATE_AS blake2b_ctx_vector_t *ctx, PRIVATE_AS blake2b_ctx_t *ctx0) DECLSPEC void blake2s_init_vector_from_scalar (PRIVATE_AS blake2s_ctx_vector_t *ctx, PRIVATE_AS blake2s_ctx_t *ctx0)
{ {
ctx->h[0] = ctx0->h[0]; ctx->h[0] = ctx0->h[0];
ctx->h[1] = ctx0->h[1]; ctx->h[1] = ctx0->h[1];
@ -687,58 +535,58 @@ DECLSPEC void blake2b_init_vector_from_scalar (PRIVATE_AS blake2b_ctx_vector_t *
ctx->len = ctx0->len; ctx->len = ctx0->len;
} }
DECLSPEC void blake2b_update_vector_128 (PRIVATE_AS blake2b_ctx_vector_t *ctx, PRIVATE_AS u32x *w0, PRIVATE_AS u32x *w1, PRIVATE_AS u32x *w2, PRIVATE_AS u32x *w3, PRIVATE_AS u32x *w4, PRIVATE_AS u32x *w5, PRIVATE_AS u32x *w6, PRIVATE_AS u32x *w7, const int len) DECLSPEC void blake2s_update_vector_64 (PRIVATE_AS blake2s_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; if (len == 0) return;
const int pos = ctx->len & 127; const int pos = ctx->len & 63;
if (pos == 0) if (pos == 0)
{ {
if (ctx->len > 0) // if new block (pos == 0) AND the (old) len is not zero => transform if (ctx->len > 0) // if new block (pos == 0) AND the (old) len is not zero => transform
{ {
blake2b_transform_vector (ctx->h, ctx->m, (u32x) ctx->len, BLAKE2B_UPDATE); blake2s_transform_vector (ctx->h, ctx->m, (u32x) ctx->len, BLAKE2S_UPDATE);
} }
ctx->m[ 0] = hl32_to_64 (w0[1], w0[0]); ctx->m[ 0] = w0[0];
ctx->m[ 1] = hl32_to_64 (w0[3], w0[2]); ctx->m[ 1] = w0[1];
ctx->m[ 2] = hl32_to_64 (w1[1], w1[0]); ctx->m[ 2] = w0[2];
ctx->m[ 3] = hl32_to_64 (w1[3], w1[2]); ctx->m[ 3] = w0[3];
ctx->m[ 4] = hl32_to_64 (w2[1], w2[0]); ctx->m[ 4] = w1[0];
ctx->m[ 5] = hl32_to_64 (w2[3], w2[2]); ctx->m[ 5] = w1[1];
ctx->m[ 6] = hl32_to_64 (w3[1], w3[0]); ctx->m[ 6] = w1[2];
ctx->m[ 7] = hl32_to_64 (w3[3], w3[2]); ctx->m[ 7] = w1[3];
ctx->m[ 8] = hl32_to_64 (w4[1], w4[0]); ctx->m[ 8] = w2[0];
ctx->m[ 9] = hl32_to_64 (w4[3], w4[2]); ctx->m[ 9] = w2[1];
ctx->m[10] = hl32_to_64 (w5[1], w5[0]); ctx->m[10] = w2[2];
ctx->m[11] = hl32_to_64 (w5[3], w5[2]); ctx->m[11] = w2[3];
ctx->m[12] = hl32_to_64 (w6[1], w6[0]); ctx->m[12] = w3[0];
ctx->m[13] = hl32_to_64 (w6[3], w6[2]); ctx->m[13] = w3[1];
ctx->m[14] = hl32_to_64 (w7[1], w7[0]); ctx->m[14] = w3[2];
ctx->m[15] = hl32_to_64 (w7[3], w7[2]); ctx->m[15] = w3[3];
} }
else else
{ {
if ((pos + len) <= 128) if ((pos + len) <= 64)
{ {
switch_buffer_by_offset_8x4_le (w0, w1, w2, w3, w4, w5, w6, w7, pos); switch_buffer_by_offset_le (w0, w1, w2, w3, pos);
ctx->m[ 0] |= hl32_to_64 (w0[1], w0[0]); ctx->m[ 0] |= w0[0];
ctx->m[ 1] |= hl32_to_64 (w0[3], w0[2]); ctx->m[ 1] |= w0[1];
ctx->m[ 2] |= hl32_to_64 (w1[1], w1[0]); ctx->m[ 2] |= w0[2];
ctx->m[ 3] |= hl32_to_64 (w1[3], w1[2]); ctx->m[ 3] |= w0[3];
ctx->m[ 4] |= hl32_to_64 (w2[1], w2[0]); ctx->m[ 4] |= w1[0];
ctx->m[ 5] |= hl32_to_64 (w2[3], w2[2]); ctx->m[ 5] |= w1[1];
ctx->m[ 6] |= hl32_to_64 (w3[1], w3[0]); ctx->m[ 6] |= w1[2];
ctx->m[ 7] |= hl32_to_64 (w3[3], w3[2]); ctx->m[ 7] |= w1[3];
ctx->m[ 8] |= hl32_to_64 (w4[1], w4[0]); ctx->m[ 8] |= w2[0];
ctx->m[ 9] |= hl32_to_64 (w4[3], w4[2]); ctx->m[ 9] |= w2[1];
ctx->m[10] |= hl32_to_64 (w5[1], w5[0]); ctx->m[10] |= w2[2];
ctx->m[11] |= hl32_to_64 (w5[3], w5[2]); ctx->m[11] |= w2[3];
ctx->m[12] |= hl32_to_64 (w6[1], w6[0]); ctx->m[12] |= w3[0];
ctx->m[13] |= hl32_to_64 (w6[3], w6[2]); ctx->m[13] |= w3[1];
ctx->m[14] |= hl32_to_64 (w7[1], w7[0]); ctx->m[14] |= w3[2];
ctx->m[15] |= hl32_to_64 (w7[3], w7[2]); ctx->m[15] |= w3[3];
} }
else else
{ {
@ -746,75 +594,67 @@ DECLSPEC void blake2b_update_vector_128 (PRIVATE_AS blake2b_ctx_vector_t *ctx, P
u32x c1[4] = { 0 }; u32x c1[4] = { 0 };
u32x c2[4] = { 0 }; u32x c2[4] = { 0 };
u32x c3[4] = { 0 }; u32x c3[4] = { 0 };
u32x c4[4] = { 0 };
u32x c5[4] = { 0 };
u32x c6[4] = { 0 };
u32x c7[4] = { 0 };
switch_buffer_by_offset_8x4_carry_le (w0, w1, w2, w3, w4, w5, w6, w7, c0, c1, c2, c3, c4, c5, c6, c7, pos); switch_buffer_by_offset_carry_le (w0, w1, w2, w3, c0, c1, c2, c3, pos);
ctx->m[ 0] |= hl32_to_64 (w0[1], w0[0]); ctx->m[ 0] |= w0[0];
ctx->m[ 1] |= hl32_to_64 (w0[3], w0[2]); ctx->m[ 1] |= w0[1];
ctx->m[ 2] |= hl32_to_64 (w1[1], w1[0]); ctx->m[ 2] |= w0[2];
ctx->m[ 3] |= hl32_to_64 (w1[3], w1[2]); ctx->m[ 3] |= w0[3];
ctx->m[ 4] |= hl32_to_64 (w2[1], w2[0]); ctx->m[ 4] |= w1[0];
ctx->m[ 5] |= hl32_to_64 (w2[3], w2[2]); ctx->m[ 5] |= w1[1];
ctx->m[ 6] |= hl32_to_64 (w3[1], w3[0]); ctx->m[ 6] |= w1[2];
ctx->m[ 7] |= hl32_to_64 (w3[3], w3[2]); ctx->m[ 7] |= w1[3];
ctx->m[ 8] |= hl32_to_64 (w4[1], w4[0]); ctx->m[ 8] |= w2[0];
ctx->m[ 9] |= hl32_to_64 (w4[3], w4[2]); ctx->m[ 9] |= w2[1];
ctx->m[10] |= hl32_to_64 (w5[1], w5[0]); ctx->m[10] |= w2[2];
ctx->m[11] |= hl32_to_64 (w5[3], w5[2]); ctx->m[11] |= w2[3];
ctx->m[12] |= hl32_to_64 (w6[1], w6[0]); ctx->m[12] |= w3[0];
ctx->m[13] |= hl32_to_64 (w6[3], w6[2]); ctx->m[13] |= w3[1];
ctx->m[14] |= hl32_to_64 (w7[1], w7[0]); ctx->m[14] |= w3[2];
ctx->m[15] |= hl32_to_64 (w7[3], w7[2]); ctx->m[15] |= w3[3];
// len must be a multiple of 128 (not ctx->len) for BLAKE2B_UPDATE: // len must be a multiple of 64 (not ctx->len) for BLAKE2S_UPDATE:
const u32x cur_len = ((ctx->len + len) / 128) * 128; const u32x cur_len = ((ctx->len + len) / 64) * 64;
blake2b_transform_vector (ctx->h, ctx->m, cur_len, BLAKE2B_UPDATE); blake2s_transform_vector (ctx->h, ctx->m, cur_len, BLAKE2S_UPDATE);
ctx->m[ 0] = hl32_to_64 (c0[1], c0[0]); ctx->m[ 0] = c0[0];
ctx->m[ 1] = hl32_to_64 (c0[3], c0[2]); ctx->m[ 1] = c0[1];
ctx->m[ 2] = hl32_to_64 (c1[1], c1[0]); ctx->m[ 2] = c0[2];
ctx->m[ 3] = hl32_to_64 (c1[3], c1[2]); ctx->m[ 3] = c0[3];
ctx->m[ 4] = hl32_to_64 (c2[1], c2[0]); ctx->m[ 4] = c1[0];
ctx->m[ 5] = hl32_to_64 (c2[3], c2[2]); ctx->m[ 5] = c1[1];
ctx->m[ 6] = hl32_to_64 (c3[1], c3[0]); ctx->m[ 6] = c1[2];
ctx->m[ 7] = hl32_to_64 (c3[3], c3[2]); ctx->m[ 7] = c1[3];
ctx->m[ 8] = hl32_to_64 (c4[1], c4[0]); ctx->m[ 8] = c2[0];
ctx->m[ 9] = hl32_to_64 (c4[3], c4[2]); ctx->m[ 9] = c2[1];
ctx->m[10] = hl32_to_64 (c5[1], c5[0]); ctx->m[10] = c2[2];
ctx->m[11] = hl32_to_64 (c5[3], c5[2]); ctx->m[11] = c2[3];
ctx->m[12] = hl32_to_64 (c6[1], c6[0]); ctx->m[12] = c3[0];
ctx->m[13] = hl32_to_64 (c6[3], c6[2]); ctx->m[13] = c3[1];
ctx->m[14] = hl32_to_64 (c7[1], c7[0]); ctx->m[14] = c3[2];
ctx->m[15] = hl32_to_64 (c7[3], c7[2]); ctx->m[15] = c3[3];
} }
} }
ctx->len += len; ctx->len += len;
} }
DECLSPEC void blake2b_update_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len) DECLSPEC void blake2s_update_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len)
{ {
u32x w0[4]; u32x w0[4];
u32x w1[4]; u32x w1[4];
u32x w2[4]; u32x w2[4];
u32x w3[4]; u32x w3[4];
u32x w4[4];
u32x w5[4];
u32x w6[4];
u32x w7[4];
const int limit = (const int) len - 128; // int type needed, could be negative const int limit = (const int) len - 64; // int type needed, could be negative
int pos1; int pos1;
int pos4; int pos4;
for (pos1 = 0, pos4 = 0; pos1 < limit; pos1 += 128, pos4 += 32) for (pos1 = 0, pos4 = 0; pos1 < limit; pos1 += 64, pos4 += 16)
{ {
w0[0] = w[pos4 + 0]; w0[0] = w[pos4 + 0];
w0[1] = w[pos4 + 1]; w0[1] = w[pos4 + 1];
@ -832,24 +672,8 @@ DECLSPEC void blake2b_update_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx, PRIVA
w3[1] = w[pos4 + 13]; w3[1] = w[pos4 + 13];
w3[2] = w[pos4 + 14]; w3[2] = w[pos4 + 14];
w3[3] = w[pos4 + 15]; w3[3] = w[pos4 + 15];
w4[0] = w[pos4 + 16];
w4[1] = w[pos4 + 17];
w4[2] = w[pos4 + 18];
w4[3] = w[pos4 + 19];
w5[0] = w[pos4 + 20];
w5[1] = w[pos4 + 21];
w5[2] = w[pos4 + 22];
w5[3] = w[pos4 + 23];
w6[0] = w[pos4 + 24];
w6[1] = w[pos4 + 25];
w6[2] = w[pos4 + 26];
w6[3] = w[pos4 + 27];
w7[0] = w[pos4 + 28];
w7[1] = w[pos4 + 29];
w7[2] = w[pos4 + 30];
w7[3] = w[pos4 + 31];
blake2b_update_vector_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, 128); blake2s_update_vector_64 (ctx, w0, w1, w2, w3, 64);
} }
w0[0] = w[pos4 + 0]; w0[0] = w[pos4 + 0];
@ -868,27 +692,11 @@ DECLSPEC void blake2b_update_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx, PRIVA
w3[1] = w[pos4 + 13]; w3[1] = w[pos4 + 13];
w3[2] = w[pos4 + 14]; w3[2] = w[pos4 + 14];
w3[3] = w[pos4 + 15]; w3[3] = w[pos4 + 15];
w4[0] = w[pos4 + 16];
w4[1] = w[pos4 + 17];
w4[2] = w[pos4 + 18];
w4[3] = w[pos4 + 19];
w5[0] = w[pos4 + 20];
w5[1] = w[pos4 + 21];
w5[2] = w[pos4 + 22];
w5[3] = w[pos4 + 23];
w6[0] = w[pos4 + 24];
w6[1] = w[pos4 + 25];
w6[2] = w[pos4 + 26];
w6[3] = w[pos4 + 27];
w7[0] = w[pos4 + 28];
w7[1] = w[pos4 + 29];
w7[2] = w[pos4 + 30];
w7[3] = w[pos4 + 31];
blake2b_update_vector_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7, len - (u32) pos1); blake2s_update_vector_64 (ctx, w0, w1, w2, w3, len - (u32) pos1);
} }
DECLSPEC void blake2b_final_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx) DECLSPEC void blake2s_final_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx)
{ {
blake2b_transform_vector (ctx->h, ctx->m, (u32x) ctx->len, BLAKE2B_FINAL); blake2s_transform_vector (ctx->h, ctx->m, (u32x) ctx->len, BLAKE2S_FINAL);
} }

View File

@ -12,37 +12,31 @@
DECLSPEC u32 blake2s_rot16_S (const u32 a); DECLSPEC u32 blake2s_rot16_S (const u32 a);
DECLSPEC u32x blake2s_rot16 (const u32x a); DECLSPEC u32x blake2s_rot16 (const u32x a);
DECLSPEC u32 blake2s_rot24_S (const u32 a); DECLSPEC u32 blake2s_rot08_S (const u32 a);
DECLSPEC u32x blake2s_rot24 (const u32x a); DECLSPEC u32x blake2s_rot08 (const u32x a);
DECLSPEC u32 blake2s_rot32_S (const u32 a);
DECLSPEC u32x blake2s_rot32 (const u32x a);
DECLSPEC u32 blake2s_rot07_S (const u32 a);
DECLSPEC u32x blake2s_rot07 (const u32x a);
#define BLAKE2S_G(k0,k1,a,b,c,d) \ #define BLAKE2S_G(k0,k1,a,b,c,d) \
{ \ { \
a = a + b + m[k0]; \ a = a + b + m[k0]; \
d = blake2s_rot16_S (d ^ a); \ d = blake2s_rot16_S (d ^ a); \
c = c + d; \ c = c + d; \
b = blake2s_rot12_S (b ^ c); \ b = hc_rotr32_S (b ^ c, 12); \
a = a + b + m[k1]; \ a = a + b + m[k1]; \
d = blake2s_rot08_S (d ^ a); \ d = blake2s_rot08_S (d ^ a); \
c = c + d; \ c = c + d; \
b = blake2s_rot07_S (b ^ c); \ b = hc_rotr32_S (b ^ c, 7); \
} }
#define BLAKE2S_ROUND(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cc,cd,ce,cf) \ #define BLAKE2S_ROUND(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cc,cd,ce,cf) \
{ \ { \
BLAKE2B_G (c0, c1, v[0], v[4], v[ 8], v[12]); \ BLAKE2S_G (c0, c1, v[0], v[4], v[ 8], v[12]); \
BLAKE2B_G (c2, c3, v[1], v[5], v[ 9], v[13]); \ BLAKE2S_G (c2, c3, v[1], v[5], v[ 9], v[13]); \
BLAKE2B_G (c4, c5, v[2], v[6], v[10], v[14]); \ BLAKE2S_G (c4, c5, v[2], v[6], v[10], v[14]); \
BLAKE2B_G (c6, c7, v[3], v[7], v[11], v[15]); \ BLAKE2S_G (c6, c7, v[3], v[7], v[11], v[15]); \
BLAKE2B_G (c8, c9, v[0], v[5], v[10], v[15]); \ BLAKE2S_G (c8, c9, v[0], v[5], v[10], v[15]); \
BLAKE2B_G (ca, cb, v[1], v[6], v[11], v[12]); \ BLAKE2S_G (ca, cb, v[1], v[6], v[11], v[12]); \
BLAKE2B_G (cc, cd, v[2], v[7], v[ 8], v[13]); \ BLAKE2S_G (cc, cd, v[2], v[7], v[ 8], v[13]); \
BLAKE2B_G (ce, cf, v[3], v[4], v[ 9], v[14]); \ BLAKE2S_G (ce, cf, v[3], v[4], v[ 9], v[14]); \
} }
#define BLAKE2S_G_VECTOR(k0,k1,a,b,c,d) \ #define BLAKE2S_G_VECTOR(k0,k1,a,b,c,d) \
@ -50,53 +44,53 @@ DECLSPEC u32x blake2s_rot07 (const u32x a);
a = a + b + m[k0]; \ a = a + b + m[k0]; \
d = blake2s_rot16 (d ^ a); \ d = blake2s_rot16 (d ^ a); \
c = c + d; \ c = c + d; \
b = blake2s_rot12 (b ^ c); \ b = hc_rotr32 (b ^ c, 12); \
a = a + b + m[k1]; \ a = a + b + m[k1]; \
d = blake2s_rot08 (d ^ a); \ d = blake2s_rot08 (d ^ a); \
c = c + d; \ c = c + d; \
b = blake2s_rot07 (b ^ c); \ b = hc_rotr32 (b ^ c, 7); \
} }
#define BLAKE2B_ROUND_VECTOR(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cc,cd,ce,cf) \ #define BLAKE2S_ROUND_VECTOR(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cc,cd,ce,cf) \
{ \ { \
BLAKE2B_G_VECTOR (c0, c1, v[0], v[4], v[ 8], v[12]); \ BLAKE2S_G_VECTOR (c0, c1, v[0], v[4], v[ 8], v[12]); \
BLAKE2B_G_VECTOR (c2, c3, v[1], v[5], v[ 9], v[13]); \ BLAKE2S_G_VECTOR (c2, c3, v[1], v[5], v[ 9], v[13]); \
BLAKE2B_G_VECTOR (c4, c5, v[2], v[6], v[10], v[14]); \ BLAKE2S_G_VECTOR (c4, c5, v[2], v[6], v[10], v[14]); \
BLAKE2B_G_VECTOR (c6, c7, v[3], v[7], v[11], v[15]); \ BLAKE2S_G_VECTOR (c6, c7, v[3], v[7], v[11], v[15]); \
BLAKE2B_G_VECTOR (c8, c9, v[0], v[5], v[10], v[15]); \ BLAKE2S_G_VECTOR (c8, c9, v[0], v[5], v[10], v[15]); \
BLAKE2B_G_VECTOR (ca, cb, v[1], v[6], v[11], v[12]); \ BLAKE2S_G_VECTOR (ca, cb, v[1], v[6], v[11], v[12]); \
BLAKE2B_G_VECTOR (cc, cd, v[2], v[7], v[ 8], v[13]); \ BLAKE2S_G_VECTOR (cc, cd, v[2], v[7], v[ 8], v[13]); \
BLAKE2B_G_VECTOR (ce, cf, v[3], v[4], v[ 9], v[14]); \ BLAKE2S_G_VECTOR (ce, cf, v[3], v[4], v[ 9], v[14]); \
} }
typedef struct blake2b_ctx typedef struct blake2s_ctx
{ {
u64 m[16]; // buffer u32 m[16]; // buffer
u64 h[ 8]; // digest u32 h[ 8]; // digest
int len; int len;
} blake2b_ctx_t; } blake2s_ctx_t;
typedef struct blake2b_ctx_vector typedef struct blake2s_ctx_vector
{ {
u64x m[16]; // buffer u32x m[16]; // buffer
u64x h[ 8]; // digest u32x h[ 8]; // digest
int len; int len;
} blake2b_ctx_vector_t; } blake2s_ctx_vector_t;
DECLSPEC void blake2b_transform (PRIVATE_AS u64 *h, PRIVATE_AS const u64 *m, const int len, const u64 f0); DECLSPEC void blake2s_transform (PRIVATE_AS u32 *h, PRIVATE_AS const u32 *m, const int len, const u32 f0);
DECLSPEC void blake2b_init (PRIVATE_AS blake2b_ctx_t *ctx); DECLSPEC void blake2s_init (PRIVATE_AS blake2s_ctx_t *ctx);
DECLSPEC void blake2b_update (PRIVATE_AS blake2b_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len); DECLSPEC void blake2s_update (PRIVATE_AS blake2s_ctx_t *ctx, PRIVATE_AS const u32 *w, const int len);
DECLSPEC void blake2b_update_global (PRIVATE_AS blake2b_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len); DECLSPEC void blake2s_update_global (PRIVATE_AS blake2s_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
DECLSPEC void blake2b_final (PRIVATE_AS blake2b_ctx_t *ctx); DECLSPEC void blake2s_final (PRIVATE_AS blake2s_ctx_t *ctx);
DECLSPEC void blake2b_transform_vector (PRIVATE_AS u64x *h, PRIVATE_AS const u64x *m, const u32x len, const u64 f0); DECLSPEC void blake2s_transform_vector (PRIVATE_AS u32x *h, PRIVATE_AS const u32x *m, const u32x len, const u32 f0);
DECLSPEC void blake2b_init_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx); DECLSPEC void blake2s_init_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx);
DECLSPEC void blake2b_init_vector_from_scalar (PRIVATE_AS blake2b_ctx_vector_t *ctx, PRIVATE_AS blake2b_ctx_t *ctx0); DECLSPEC void blake2s_init_vector_from_scalar (PRIVATE_AS blake2s_ctx_vector_t *ctx, PRIVATE_AS blake2s_ctx_t *ctx0);
DECLSPEC void blake2b_update_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len); DECLSPEC void blake2s_update_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx, PRIVATE_AS const u32x *w, const int len);
DECLSPEC void blake2b_final_vector (PRIVATE_AS blake2b_ctx_vector_t *ctx); DECLSPEC void blake2s_final_vector (PRIVATE_AS blake2s_ctx_vector_t *ctx);
#endif // INC_HASH_BLAKE2B_H #endif // INC_HASH_BLAKE2S_H

View File

@ -1666,6 +1666,19 @@ typedef enum blake2b_constants
} blake2b_constants_t; } blake2b_constants_t;
typedef enum blake2s_constants
{
BLAKE2S_IV_00=0x6a09e667,
BLAKE2S_IV_01=0xbb67ae85,
BLAKE2S_IV_02=0x3c6ef372,
BLAKE2S_IV_03=0xa54ff53a,
BLAKE2S_IV_04=0x510e527f,
BLAKE2S_IV_05=0x9b05688c,
BLAKE2S_IV_06=0x1f83d9ab,
BLAKE2S_IV_07=0x5be0cd19
} blake2s_constants_t;
typedef enum combinator_mode typedef enum combinator_mode
{ {
COMBINATOR_MODE_BASE_LEFT = 10001, COMBINATOR_MODE_BASE_LEFT = 10001,

111
OpenCL/m35000_a0-pure.cl Normal file
View File

@ -0,0 +1,111 @@
/**
* 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_blake2s.cl)
#endif
KERNEL_FQ void m35000_mxx (KERN_ATTR_RULES ())
{
/**
* base
*/
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);
blake2s_ctx_t ctx;
blake2s_init (&ctx);
blake2s_update (&ctx, tmp.i, tmp.pw_len);
blake2s_final (&ctx);
const u32 r0 = h32_from_64_S (ctx.h[0]);
const u32 r1 = l32_from_64_S (ctx.h[0]);
const u32 r2 = h32_from_64_S (ctx.h[1]);
const u32 r3 = l32_from_64_S (ctx.h[1]);
COMPARE_M_SCALAR (r0, r1, r2, r3);
}
}
KERNEL_FQ void m35000_sxx (KERN_ATTR_RULES ())
{
/**
* base
*/
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);
blake2s_ctx_t ctx;
blake2s_init (&ctx);
blake2s_update (&ctx, tmp.i, tmp.pw_len);
blake2s_final (&ctx);
const u32 r0 = h32_from_64_S (ctx.h[0]);
const u32 r1 = l32_from_64_S (ctx.h[0]);
const u32 r2 = h32_from_64_S (ctx.h[1]);
const u32 r3 = l32_from_64_S (ctx.h[1]);
COMPARE_S_SCALAR (r0, r1, r2, r3);
}
}

View File

@ -4,7 +4,7 @@
## ##
SHARED ?= 0 SHARED ?= 0
DEBUG := 0 DEBUG := 1
PRODUCTION := 0 PRODUCTION := 0
PRODUCTION_VERSION := v6.2.6 PRODUCTION_VERSION := v6.2.6
ENABLE_CUBIN ?= 1 ENABLE_CUBIN ?= 1