Add *_hmac_init_swap for later use

pull/1301/head
jsteube 7 years ago
parent f03156b05e
commit 9c6c21490f

@ -848,6 +848,63 @@ void md4_hmac_init (md4_hmac_ctx_t *ctx, const u32 *w, const int len)
md4_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void md4_hmac_init_swap (md4_hmac_ctx_t *ctx, const u32 *w, const int len)
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
if (len > 64)
{
md4_ctx_t tmp;
md4_init (&tmp);
md4_update_swap (&tmp, w, len);
md4_final (&tmp);
w0[0] = tmp.h[0];
w0[1] = tmp.h[1];
w0[2] = tmp.h[2];
w0[3] = tmp.h[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
}
md4_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void md4_hmac_init_global (md4_hmac_ctx_t *ctx, __global const u32 *w, const int len)
{
u32 w0[4];

@ -882,6 +882,63 @@ void md5_hmac_init (md5_hmac_ctx_t *ctx, const u32 *w, const int len)
md5_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void md5_hmac_init_swap (md5_hmac_ctx_t *ctx, const u32 *w, const int len)
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
if (len > 64)
{
md5_ctx_t tmp;
md5_init (&tmp);
md5_update_swap (&tmp, w, len);
md5_final (&tmp);
w0[0] = tmp.h[0];
w0[1] = tmp.h[1];
w0[2] = tmp.h[2];
w0[3] = tmp.h[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
}
md5_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void md5_hmac_init_global (md5_hmac_ctx_t *ctx, __global const u32 *w, const int len)
{
u32 w0[4];

@ -982,6 +982,63 @@ void ripemd160_hmac_init (ripemd160_hmac_ctx_t *ctx, const u32 *w, const int len
ripemd160_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void ripemd160_hmac_init_swap (ripemd160_hmac_ctx_t *ctx, const u32 *w, const int len)
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
if (len > 64)
{
ripemd160_ctx_t tmp;
ripemd160_init (&tmp);
ripemd160_update_swap (&tmp, w, len);
ripemd160_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] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
}
ripemd160_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void ripemd160_hmac_init_global (ripemd160_hmac_ctx_t *ctx, __global const u32 *w, const int len)
{
u32 w0[4];

@ -914,6 +914,63 @@ void sha1_hmac_init (sha1_hmac_ctx_t *ctx, const u32 *w, const int len)
sha1_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void sha1_hmac_init_swap (sha1_hmac_ctx_t *ctx, const u32 *w, const int len)
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
if (len > 64)
{
sha1_ctx_t tmp;
sha1_init (&tmp);
sha1_update_swap (&tmp, w, len);
sha1_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] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
}
sha1_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void sha1_hmac_init_global (sha1_hmac_ctx_t *ctx, __global const u32 *w, const int len)
{
u32 w0[4];

@ -899,6 +899,63 @@ void sha256_hmac_init (sha256_hmac_ctx_t *ctx, const u32 *w, const int len)
sha256_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void sha256_hmac_init_swap (sha256_hmac_ctx_t *ctx, const u32 *w, const int len)
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
if (len > 64)
{
sha256_ctx_t tmp;
sha256_init (&tmp);
sha256_update_swap (&tmp, w, len);
sha256_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] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
}
sha256_hmac_init_64 (ctx, w0, w1, w2, w3);
}
void sha256_hmac_init_global (sha256_hmac_ctx_t *ctx, __global const u32 *w, const int len)
{
u32 w0[4];

@ -1431,6 +1431,99 @@ void sha384_hmac_init (sha384_hmac_ctx_t *ctx, const u32 *w, const int len)
sha384_hmac_init_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7);
}
void sha384_hmac_init_swap (sha384_hmac_ctx_t *ctx, const u32 *w, const int len)
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
u32 w4[4];
u32 w5[4];
u32 w6[4];
u32 w7[4];
if (len > 128)
{
sha384_ctx_t tmp;
sha384_init (&tmp);
sha384_update_swap (&tmp, w, len);
sha384_final (&tmp);
w0[0] = h32_from_64_S (tmp.h[0]);
w0[1] = l32_from_64_S (tmp.h[0]);
w0[2] = h32_from_64_S (tmp.h[1]);
w0[3] = l32_from_64_S (tmp.h[1]);
w1[0] = h32_from_64_S (tmp.h[2]);
w1[1] = l32_from_64_S (tmp.h[2]);
w1[2] = h32_from_64_S (tmp.h[3]);
w1[3] = l32_from_64_S (tmp.h[3]);
w2[0] = h32_from_64_S (tmp.h[4]);
w2[1] = l32_from_64_S (tmp.h[4]);
w2[2] = h32_from_64_S (tmp.h[5]);
w2[3] = l32_from_64_S (tmp.h[5]);
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
w4[0] = 0;
w4[1] = 0;
w4[2] = 0;
w4[3] = 0;
w5[0] = 0;
w5[1] = 0;
w5[2] = 0;
w5[3] = 0;
w6[0] = 0;
w6[1] = 0;
w6[2] = 0;
w6[3] = 0;
w7[0] = 0;
w7[1] = 0;
w7[2] = 0;
w7[3] = 0;
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
w4[0] = swap32_S (w[16]);
w4[1] = swap32_S (w[17]);
w4[2] = swap32_S (w[18]);
w4[3] = swap32_S (w[19]);
w5[0] = swap32_S (w[20]);
w5[1] = swap32_S (w[21]);
w5[2] = swap32_S (w[22]);
w5[3] = swap32_S (w[23]);
w6[0] = swap32_S (w[24]);
w6[1] = swap32_S (w[25]);
w6[2] = swap32_S (w[26]);
w6[3] = swap32_S (w[27]);
w7[0] = swap32_S (w[28]);
w7[1] = swap32_S (w[29]);
w7[2] = swap32_S (w[30]);
w7[3] = swap32_S (w[31]);
}
sha384_hmac_init_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7);
}
void sha384_hmac_init_global (sha384_hmac_ctx_t *ctx, __global const u32 *w, const int len)
{
u32 w0[4];

@ -1431,6 +1431,99 @@ void sha512_hmac_init (sha512_hmac_ctx_t *ctx, const u32 *w, const int len)
sha512_hmac_init_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7);
}
void sha512_hmac_init_swap (sha512_hmac_ctx_t *ctx, const u32 *w, const int len)
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
u32 w4[4];
u32 w5[4];
u32 w6[4];
u32 w7[4];
if (len > 128)
{
sha512_ctx_t tmp;
sha512_init (&tmp);
sha512_update_swap (&tmp, w, len);
sha512_final (&tmp);
w0[0] = h32_from_64_S (tmp.h[0]);
w0[1] = l32_from_64_S (tmp.h[0]);
w0[2] = h32_from_64_S (tmp.h[1]);
w0[3] = l32_from_64_S (tmp.h[1]);
w1[0] = h32_from_64_S (tmp.h[2]);
w1[1] = l32_from_64_S (tmp.h[2]);
w1[2] = h32_from_64_S (tmp.h[3]);
w1[3] = l32_from_64_S (tmp.h[3]);
w2[0] = h32_from_64_S (tmp.h[4]);
w2[1] = l32_from_64_S (tmp.h[4]);
w2[2] = h32_from_64_S (tmp.h[5]);
w2[3] = l32_from_64_S (tmp.h[5]);
w3[0] = h32_from_64_S (tmp.h[6]);
w3[1] = l32_from_64_S (tmp.h[6]);
w3[2] = h32_from_64_S (tmp.h[7]);
w3[3] = l32_from_64_S (tmp.h[7]);
w4[0] = 0;
w4[1] = 0;
w4[2] = 0;
w4[3] = 0;
w5[0] = 0;
w5[1] = 0;
w5[2] = 0;
w5[3] = 0;
w6[0] = 0;
w6[1] = 0;
w6[2] = 0;
w6[3] = 0;
w7[0] = 0;
w7[1] = 0;
w7[2] = 0;
w7[3] = 0;
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
w4[0] = swap32_S (w[16]);
w4[1] = swap32_S (w[17]);
w4[2] = swap32_S (w[18]);
w4[3] = swap32_S (w[19]);
w5[0] = swap32_S (w[20]);
w5[1] = swap32_S (w[21]);
w5[2] = swap32_S (w[22]);
w5[3] = swap32_S (w[23]);
w6[0] = swap32_S (w[24]);
w6[1] = swap32_S (w[25]);
w6[2] = swap32_S (w[26]);
w6[3] = swap32_S (w[27]);
w7[0] = swap32_S (w[28]);
w7[1] = swap32_S (w[29]);
w7[2] = swap32_S (w[30]);
w7[3] = swap32_S (w[31]);
}
sha512_hmac_init_128 (ctx, w0, w1, w2, w3, w4, w5, w6, w7);
}
void sha512_hmac_init_global (sha512_hmac_ctx_t *ctx, __global const u32 *w, const int len)
{
u32 w0[4];

@ -2082,6 +2082,63 @@ void whirlpool_hmac_init (whirlpool_hmac_ctx_t *ctx, const u32 *w, const int len
whirlpool_hmac_init_64 (ctx, w0, w1, w2, w3, s_Ch, s_Cl);
}
void whirlpool_hmac_init_swap (whirlpool_hmac_ctx_t *ctx, const u32 *w, const int len, __local u32 (*s_Ch)[256], __local u32 (*s_Cl)[256])
{
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
if (len > 64)
{
whirlpool_ctx_t tmp;
whirlpool_init (&tmp, s_Ch, s_Cl);
whirlpool_update_swap (&tmp, w, len);
whirlpool_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] = tmp.h[10];
w2[3] = tmp.h[11];
w3[0] = tmp.h[12];
w3[1] = tmp.h[13];
w3[2] = tmp.h[14];
w3[3] = tmp.h[15];
}
else
{
w0[0] = swap32_S (w[ 0]);
w0[1] = swap32_S (w[ 1]);
w0[2] = swap32_S (w[ 2]);
w0[3] = swap32_S (w[ 3]);
w1[0] = swap32_S (w[ 4]);
w1[1] = swap32_S (w[ 5]);
w1[2] = swap32_S (w[ 6]);
w1[3] = swap32_S (w[ 7]);
w2[0] = swap32_S (w[ 8]);
w2[1] = swap32_S (w[ 9]);
w2[2] = swap32_S (w[10]);
w2[3] = swap32_S (w[11]);
w3[0] = swap32_S (w[12]);
w3[1] = swap32_S (w[13]);
w3[2] = swap32_S (w[14]);
w3[3] = swap32_S (w[15]);
}
whirlpool_hmac_init_64 (ctx, w0, w1, w2, w3, s_Ch, s_Cl);
}
void whirlpool_hmac_init_global (whirlpool_hmac_ctx_t *ctx, __global const u32 *w, const int len, __local u32 (*s_Ch)[256], __local u32 (*s_Cl)[256])
{
u32 w0[4];

Loading…
Cancel
Save