1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 14:48:12 +00:00

Refactor UTF8 to UTF16 conversion from fixed size to a dynamic size using a context struct. This allows handle buffer sizes of arbitrary length for conversion

This commit is contained in:
Jens Steube 2021-05-01 12:49:43 +02:00
parent db6f93b159
commit 0439f0c4a1
12 changed files with 1018 additions and 407 deletions

View File

@ -1981,13 +1981,29 @@ DECLSPEC int find_hash (const u32 *digest, const u32 digests_cnt, GLOBAL_AS cons
}
#endif
// Input has to be zero padded and buffer size has to be multiple of 4
// Input has to be zero padded and buffer size has to be multiple of 4 and at least of length 24
// We simply ignore buffer length for the first 24 bytes for some extra speed boost :)
// Number of unrolls found by simply testing what gave best results
DECLSPEC int test_any_8th_bit (const u32 *buf, const int len)
DECLSPEC int hc_enc_scan (const u32 *buf, const int len)
{
// we simply ignore buffer length for the first 24 bytes for some extra speed boost :)
// number of unrolls found by simply testing what gave best results
if (buf[0] & 0x80808080) return 1;
if (buf[1] & 0x80808080) return 1;
if (buf[2] & 0x80808080) return 1;
if (buf[3] & 0x80808080) return 1;
if (buf[4] & 0x80808080) return 1;
if (buf[5] & 0x80808080) return 1;
for (int i = 24, j = 6; i < len; i += 4, j += 1)
{
if (buf[j] & 0x80808080) return 1;
}
return 0;
}
DECLSPEC int hc_enc_scan_global (GLOBAL_AS const u32 *buf, const int len)
{
if (buf[0] & 0x80808080) return 1;
if (buf[1] & 0x80808080) return 1;
if (buf[2] & 0x80808080) return 1;
@ -2031,124 +2047,41 @@ DECLSPEC int test_any_8th_bit (const u32 *buf, const int len)
#define offsetsFromUTF8_4 0xFA082080UL
#define offsetsFromUTF8_5 0x82082080UL
DECLSPEC int utf8_to_utf16le (const u32 *src_buf, int src_len, int src_size, u32 *dst_buf, int dst_size)
DECLSPEC void hc_enc_init (hc_enc_t *hc_enc)
{
const u8 *src_ptr = (const u8 *) src_buf;
u16 *dst_ptr = ( u16 *) dst_buf;
hc_enc->pos = 0;
int src_pos = 0;
int dst_pos = 0;
int dst_len = 0;
while (src_pos < src_len)
{
const u8 c = src_ptr[src_pos];
int extraBytesToRead = 0;
if (c >= 0xfc)
{
extraBytesToRead = 5;
}
else if (c >= 0xf8)
{
extraBytesToRead = 4;
}
else if (c >= 0xf0)
{
extraBytesToRead = 3;
}
else if (c >= 0xe0)
{
extraBytesToRead = 2;
}
else if (c >= 0xc0)
{
extraBytesToRead = 1;
}
if ((src_pos + extraBytesToRead) >= src_size) return dst_len;
u32 ch = 0;
switch (extraBytesToRead)
{
case 5:
ch += src_ptr[src_pos++]; ch <<= 6; /* remember, illegal UTF-8 */
ch += src_ptr[src_pos++]; ch <<= 6; /* remember, illegal UTF-8 */
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_5;
break;
case 4:
ch += src_ptr[src_pos++]; ch <<= 6; /* remember, illegal UTF-8 */
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_4;
break;
case 3:
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_3;
break;
case 2:
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_2;
break;
case 1:
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_1;
break;
case 0:
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_0;
break;
}
/* Target is a character <= 0xFFFF */
if (ch <= UNI_MAX_BMP)
{
if ((dst_len + 2) >= dst_size) return dst_len;
dst_ptr[dst_pos++] = (u16) ch;
dst_len += 2;
}
else
{
if ((dst_len + 4) >= dst_size) return dst_len;
ch -= halfBase;
dst_ptr[dst_pos++] = (u16) ((ch >> halfShift) + UNI_SUR_HIGH_START);
dst_ptr[dst_pos++] = (u16) ((ch & halfMask) + UNI_SUR_LOW_START);
dst_len += 4;
}
}
return dst_len;
hc_enc->cbuf = 0;
hc_enc->clen = 0;
}
DECLSPEC int utf8_to_utf16le_global (GLOBAL_AS const u32 *src_buf, int src_len, int src_size, u32 *dst_buf, int dst_size)
DECLSPEC int hc_enc_has_next (hc_enc_t *hc_enc, const int sz)
{
GLOBAL_AS const u8 *src_ptr = (GLOBAL_AS const u8 *) src_buf;
u16 *dst_ptr = ( u16 *) dst_buf;
if (hc_enc->pos < sz) return 1;
int src_pos = 0;
int dst_pos = 0;
int dst_len = 0;
if (hc_enc->clen) return 1;
while (src_pos < src_len)
return 0;
}
// Input buffer and Output buffer size has to be multiple of 16 and at least of size 16
// The output buffer will by zero padded
DECLSPEC int hc_enc_next (hc_enc_t *hc_enc, const u32 *src_buf, const int src_len, const int src_sz, u32 *dst_buf, const int dst_sz)
{
const u8 *src_ptr = (const u8 *) src_buf;
u8 *dst_ptr = ( u8 *) dst_buf;
int src_pos = hc_enc->pos;
int dst_pos = hc_enc->clen;
dst_buf[0] = hc_enc->cbuf;
hc_enc->clen = 0;
hc_enc->cbuf = 0;
while ((src_pos < src_len) && (dst_pos < dst_sz))
{
const u8 c = src_ptr[src_pos];
@ -2175,7 +2108,14 @@ DECLSPEC int utf8_to_utf16le_global (GLOBAL_AS const u32 *src_buf, int src_len,
extraBytesToRead = 1;
}
if ((src_pos + extraBytesToRead) >= src_size) return dst_len;
if ((src_pos + extraBytesToRead) >= src_sz)
{
// broken input
hc_enc->pos = src_len;
return dst_pos;
}
u32 ch = 0;
@ -2225,26 +2165,196 @@ DECLSPEC int utf8_to_utf16le_global (GLOBAL_AS const u32 *src_buf, int src_len,
/* Target is a character <= 0xFFFF */
if (ch <= UNI_MAX_BMP)
{
if ((dst_len + 2) >= dst_size) return dst_len;
dst_ptr[dst_pos++] = (u16) ch;
dst_len += 2;
dst_ptr[dst_pos++] = (ch >> 0) & 0xff;
dst_ptr[dst_pos++] = (ch >> 8) & 0xff;
}
else
{
if ((dst_len + 4) >= dst_size) return dst_len;
ch -= halfBase;
dst_ptr[dst_pos++] = (u16) ((ch >> halfShift) + UNI_SUR_HIGH_START);
dst_ptr[dst_pos++] = (u16) ((ch & halfMask) + UNI_SUR_LOW_START);
const u32 a = ((ch >> halfShift) + UNI_SUR_HIGH_START);
const u32 b = ((ch & halfMask) + UNI_SUR_LOW_START);
dst_len += 4;
if ((dst_pos + 2) == dst_sz)
{
dst_ptr[dst_pos++] = (a >> 0) & 0xff;
dst_ptr[dst_pos++] = (a >> 8) & 0xff;
hc_enc->cbuf = b & 0xffff;
hc_enc->clen = 2;
}
else
{
dst_ptr[dst_pos++] = (a >> 0) & 0xff;
dst_ptr[dst_pos++] = (a >> 8) & 0xff;
dst_ptr[dst_pos++] = (b >> 0) & 0xff;
dst_ptr[dst_pos++] = (b >> 8) & 0xff;
}
}
}
return dst_len;
if (dst_pos < dst_sz)
{
const int dst_block = dst_pos / 16;
truncate_block_4x4_le_S (dst_buf + (dst_block * 4), dst_pos & 15);
const int zero_block = dst_block + 1;
for (int i = zero_block * 16, j = zero_block * 4; i < dst_sz; i += 4, j += 1)
{
dst_buf[j] = 0;
}
}
hc_enc->pos = src_pos;
return dst_pos;
}
DECLSPEC int hc_enc_next_global (hc_enc_t *hc_enc, GLOBAL_AS const u32 *src_buf, const int src_len, const int src_sz, u32 *dst_buf, const int dst_sz)
{
GLOBAL_AS const u8 *src_ptr = (GLOBAL_AS const u8 *) src_buf;
u8 *dst_ptr = ( u8 *) dst_buf;
int src_pos = hc_enc->pos;
int dst_pos = hc_enc->clen;
dst_buf[0] = hc_enc->cbuf;
hc_enc->clen = 0;
hc_enc->cbuf = 0;
while ((src_pos < src_len) && (dst_pos < dst_sz))
{
const u8 c = src_ptr[src_pos];
int extraBytesToRead = 0;
if (c >= 0xfc)
{
extraBytesToRead = 5;
}
else if (c >= 0xf8)
{
extraBytesToRead = 4;
}
else if (c >= 0xf0)
{
extraBytesToRead = 3;
}
else if (c >= 0xe0)
{
extraBytesToRead = 2;
}
else if (c >= 0xc0)
{
extraBytesToRead = 1;
}
if ((src_pos + extraBytesToRead) >= src_sz)
{
// broken input
hc_enc->pos = src_len;
return dst_pos;
}
u32 ch = 0;
switch (extraBytesToRead)
{
case 5:
ch += src_ptr[src_pos++]; ch <<= 6; /* remember, illegal UTF-8 */
ch += src_ptr[src_pos++]; ch <<= 6; /* remember, illegal UTF-8 */
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_5;
break;
case 4:
ch += src_ptr[src_pos++]; ch <<= 6; /* remember, illegal UTF-8 */
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_4;
break;
case 3:
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_3;
break;
case 2:
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_2;
break;
case 1:
ch += src_ptr[src_pos++]; ch <<= 6;
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_1;
break;
case 0:
ch += src_ptr[src_pos++];
ch -= offsetsFromUTF8_0;
break;
}
/* Target is a character <= 0xFFFF */
if (ch <= UNI_MAX_BMP)
{
dst_ptr[dst_pos++] = (ch >> 0) & 0xff;
dst_ptr[dst_pos++] = (ch >> 8) & 0xff;
}
else
{
ch -= halfBase;
const u32 a = ((ch >> halfShift) + UNI_SUR_HIGH_START);
const u32 b = ((ch & halfMask) + UNI_SUR_LOW_START);
if ((dst_pos + 2) == dst_sz)
{
dst_ptr[dst_pos++] = (a >> 0) & 0xff;
dst_ptr[dst_pos++] = (a >> 8) & 0xff;
hc_enc->cbuf = b & 0xffff;
hc_enc->clen = 2;
}
else
{
dst_ptr[dst_pos++] = (a >> 0) & 0xff;
dst_ptr[dst_pos++] = (a >> 8) & 0xff;
dst_ptr[dst_pos++] = (b >> 0) & 0xff;
dst_ptr[dst_pos++] = (b >> 8) & 0xff;
}
}
}
if (dst_pos < dst_sz)
{
const int dst_block = dst_pos / 16;
truncate_block_4x4_le_S (dst_buf + (dst_block * 4), dst_pos & 15);
const int zero_block = dst_block + 1;
for (int i = zero_block * 16, j = zero_block * 4; i < dst_sz; i += 4, j += 1)
{
dst_buf[j] = 0;
}
}
hc_enc->pos = src_pos;
return dst_pos;
}
#undef halfShift

View File

@ -236,9 +236,13 @@ DECLSPEC int hash_comp (const u32 *d1, GLOBAL_AS const u32 *d2);
DECLSPEC int find_hash (const u32 *digest, const u32 digests_cnt, GLOBAL_AS const digest_t *digests_buf);
#endif
DECLSPEC int test_any_8th_bit (const u32 *buf, const int len);
DECLSPEC int utf8_to_utf16le (const u32 *src_buf, int src_len, int src_size, u32 *dst_buf, int dst_size);
DECLSPEC int utf8_to_utf16le_global (GLOBAL_AS const u32 *src_buf, int src_len, int src_size, u32 *dst_buf, int dst_size);
DECLSPEC int hc_enc_scan (const u32 *buf, const int len);
DECLSPEC int hc_enc_scan_global (GLOBAL_AS const u32 *buf, const int len);
DECLSPEC void hc_enc_init (hc_enc_t *hc_enc);
DECLSPEC int hc_enc_has_next (hc_enc_t *hc_enc, const int sz);
DECLSPEC int hc_enc_next (hc_enc_t *hc_enc, const u32 *src_buf, const int src_len, const int src_sz, u32 *dst_buf, const int dst_sz);
DECLSPEC int hc_enc_next_global (hc_enc_t *hc_enc, GLOBAL_AS const u32 *src_buf, const int src_len, const int src_sz, u32 *dst_buf, const int dst_sz);
DECLSPEC int pkcs_padding_bs8 (const u32 *data_buf, const int data_len);
DECLSPEC int pkcs_padding_bs16 (const u32 *data_buf, const int data_len);
DECLSPEC int asn1_detect (const u32 *buf, const int len);

View File

@ -363,19 +363,20 @@ DECLSPEC void md4_update_swap (md4_ctx_t *ctx, const u32 *w, const int len)
DECLSPEC void md4_update_utf16le (md4_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
md4_update (ctx, w_utf16_buf, w_utf16_len);
md4_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -422,19 +423,37 @@ DECLSPEC void md4_update_utf16le (md4_ctx_t *ctx, const u32 *w, const int len)
DECLSPEC void md4_update_utf16le_swap (md4_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
md4_update_swap (ctx, w_utf16_buf, w_utf16_len);
md4_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -653,19 +672,20 @@ DECLSPEC void md4_update_global_swap (md4_ctx_t *ctx, GLOBAL_AS const u32 *w, co
DECLSPEC void md4_update_global_utf16le (md4_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
md4_update (ctx, w_utf16_buf, w_utf16_len);
md4_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -712,19 +732,37 @@ DECLSPEC void md4_update_global_utf16le (md4_ctx_t *ctx, GLOBAL_AS const u32 *w,
DECLSPEC void md4_update_global_utf16le_swap (md4_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
md4_update_swap (ctx, w_utf16_buf, w_utf16_len);
md4_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}

View File

@ -399,19 +399,20 @@ DECLSPEC void md5_update_swap (md5_ctx_t *ctx, const u32 *w, const int len)
DECLSPEC void md5_update_utf16le (md5_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
md5_update (ctx, w_utf16_buf, w_utf16_len);
md5_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -458,19 +459,37 @@ DECLSPEC void md5_update_utf16le (md5_ctx_t *ctx, const u32 *w, const int len)
DECLSPEC void md5_update_utf16le_swap (md5_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
md5_update_swap (ctx, w_utf16_buf, w_utf16_len);
md5_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -689,19 +708,20 @@ DECLSPEC void md5_update_global_swap (md5_ctx_t *ctx, GLOBAL_AS const u32 *w, co
DECLSPEC void md5_update_global_utf16le (md5_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
md5_update (ctx, w_utf16_buf, w_utf16_len);
md5_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -748,19 +768,37 @@ DECLSPEC void md5_update_global_utf16le (md5_ctx_t *ctx, GLOBAL_AS const u32 *w,
DECLSPEC void md5_update_global_utf16le_swap (md5_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
md5_update_swap (ctx, w_utf16_buf, w_utf16_len);
md5_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}

View File

@ -497,19 +497,20 @@ DECLSPEC void ripemd160_update_swap (ripemd160_ctx_t *ctx, const u32 *w, const i
DECLSPEC void ripemd160_update_utf16le (ripemd160_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
ripemd160_update (ctx, w_utf16_buf, w_utf16_len);
ripemd160_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -556,19 +557,37 @@ DECLSPEC void ripemd160_update_utf16le (ripemd160_ctx_t *ctx, const u32 *w, cons
DECLSPEC void ripemd160_update_utf16le_swap (ripemd160_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
ripemd160_update_swap (ctx, w_utf16_buf, w_utf16_len);
ripemd160_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -787,19 +806,20 @@ DECLSPEC void ripemd160_update_global_swap (ripemd160_ctx_t *ctx, GLOBAL_AS cons
DECLSPEC void ripemd160_update_global_utf16le (ripemd160_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
ripemd160_update (ctx, w_utf16_buf, w_utf16_len);
ripemd160_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -846,19 +866,37 @@ DECLSPEC void ripemd160_update_global_utf16le (ripemd160_ctx_t *ctx, GLOBAL_AS c
DECLSPEC void ripemd160_update_global_utf16le_swap (ripemd160_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
ripemd160_update_swap (ctx, w_utf16_buf, w_utf16_len);
ripemd160_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}

View File

@ -612,19 +612,20 @@ DECLSPEC void sha1_update_swap (sha1_ctx_t *ctx, const u32 *w, const int len)
DECLSPEC void sha1_update_utf16le (sha1_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha1_update (ctx, w_utf16_buf, w_utf16_len);
sha1_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -671,19 +672,37 @@ DECLSPEC void sha1_update_utf16le (sha1_ctx_t *ctx, const u32 *w, const int len)
DECLSPEC void sha1_update_utf16le_swap (sha1_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
sha1_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha1_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -1020,19 +1039,20 @@ DECLSPEC void sha1_update_global_swap (sha1_ctx_t *ctx, GLOBAL_AS const u32 *w,
DECLSPEC void sha1_update_global_utf16le (sha1_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha1_update (ctx, w_utf16_buf, w_utf16_len);
sha1_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -1079,19 +1099,37 @@ DECLSPEC void sha1_update_global_utf16le (sha1_ctx_t *ctx, GLOBAL_AS const u32 *
DECLSPEC void sha1_update_global_utf16le_swap (sha1_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
sha1_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha1_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}

View File

@ -414,19 +414,20 @@ DECLSPEC void sha224_update_swap (sha224_ctx_t *ctx, const u32 *w, const int len
DECLSPEC void sha224_update_utf16le (sha224_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha224_update (ctx, w_utf16_buf, w_utf16_len);
sha224_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -473,19 +474,37 @@ DECLSPEC void sha224_update_utf16le (sha224_ctx_t *ctx, const u32 *w, const int
DECLSPEC void sha224_update_utf16le_swap (sha224_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
sha224_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha224_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -704,19 +723,20 @@ DECLSPEC void sha224_update_global_swap (sha224_ctx_t *ctx, GLOBAL_AS const u32
DECLSPEC void sha224_update_global_utf16le (sha224_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha224_update (ctx, w_utf16_buf, w_utf16_len);
sha224_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -763,19 +783,37 @@ DECLSPEC void sha224_update_global_utf16le (sha224_ctx_t *ctx, GLOBAL_AS const u
DECLSPEC void sha224_update_global_utf16le_swap (sha224_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
sha224_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha224_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}

View File

@ -414,19 +414,20 @@ DECLSPEC void sha256_update_swap (sha256_ctx_t *ctx, const u32 *w, const int len
DECLSPEC void sha256_update_utf16le (sha256_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha256_update (ctx, w_utf16_buf, w_utf16_len);
sha256_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -473,19 +474,37 @@ DECLSPEC void sha256_update_utf16le (sha256_ctx_t *ctx, const u32 *w, const int
DECLSPEC void sha256_update_utf16le_swap (sha256_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
sha256_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha256_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -704,19 +723,20 @@ DECLSPEC void sha256_update_global_swap (sha256_ctx_t *ctx, GLOBAL_AS const u32
DECLSPEC void sha256_update_global_utf16le (sha256_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha256_update (ctx, w_utf16_buf, w_utf16_len);
sha256_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -763,19 +783,37 @@ DECLSPEC void sha256_update_global_utf16le (sha256_ctx_t *ctx, GLOBAL_AS const u
DECLSPEC void sha256_update_global_utf16le_swap (sha256_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
sha256_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha256_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}

View File

@ -622,19 +622,20 @@ DECLSPEC void sha384_update_swap (sha384_ctx_t *ctx, const u32 *w, const int len
DECLSPEC void sha384_update_utf16le (sha384_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha384_update (ctx, w_utf16_buf, w_utf16_len);
sha384_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}
@ -705,19 +706,53 @@ DECLSPEC void sha384_update_utf16le (sha384_ctx_t *ctx, const u32 *w, const int
DECLSPEC void sha384_update_utf16le_swap (sha384_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
enc_buf[16] = hc_swap32_S (enc_buf[16]);
enc_buf[17] = hc_swap32_S (enc_buf[17]);
enc_buf[18] = hc_swap32_S (enc_buf[18]);
enc_buf[19] = hc_swap32_S (enc_buf[19]);
enc_buf[20] = hc_swap32_S (enc_buf[20]);
enc_buf[21] = hc_swap32_S (enc_buf[21]);
enc_buf[22] = hc_swap32_S (enc_buf[22]);
enc_buf[23] = hc_swap32_S (enc_buf[23]);
enc_buf[24] = hc_swap32_S (enc_buf[24]);
enc_buf[25] = hc_swap32_S (enc_buf[25]);
enc_buf[26] = hc_swap32_S (enc_buf[26]);
enc_buf[27] = hc_swap32_S (enc_buf[27]);
enc_buf[28] = hc_swap32_S (enc_buf[28]);
enc_buf[29] = hc_swap32_S (enc_buf[29]);
enc_buf[30] = hc_swap32_S (enc_buf[30]);
enc_buf[31] = hc_swap32_S (enc_buf[31]);
sha384_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha384_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}
@ -1096,19 +1131,20 @@ DECLSPEC void sha384_update_global_swap (sha384_ctx_t *ctx, GLOBAL_AS const u32
DECLSPEC void sha384_update_global_utf16le (sha384_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha384_update (ctx, w_utf16_buf, w_utf16_len);
sha384_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}
@ -1179,19 +1215,53 @@ DECLSPEC void sha384_update_global_utf16le (sha384_ctx_t *ctx, GLOBAL_AS const u
DECLSPEC void sha384_update_global_utf16le_swap (sha384_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
enc_buf[16] = hc_swap32_S (enc_buf[16]);
enc_buf[17] = hc_swap32_S (enc_buf[17]);
enc_buf[18] = hc_swap32_S (enc_buf[18]);
enc_buf[19] = hc_swap32_S (enc_buf[19]);
enc_buf[20] = hc_swap32_S (enc_buf[20]);
enc_buf[21] = hc_swap32_S (enc_buf[21]);
enc_buf[22] = hc_swap32_S (enc_buf[22]);
enc_buf[23] = hc_swap32_S (enc_buf[23]);
enc_buf[24] = hc_swap32_S (enc_buf[24]);
enc_buf[25] = hc_swap32_S (enc_buf[25]);
enc_buf[26] = hc_swap32_S (enc_buf[26]);
enc_buf[27] = hc_swap32_S (enc_buf[27]);
enc_buf[28] = hc_swap32_S (enc_buf[28]);
enc_buf[29] = hc_swap32_S (enc_buf[29]);
enc_buf[30] = hc_swap32_S (enc_buf[30]);
enc_buf[31] = hc_swap32_S (enc_buf[31]);
sha384_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha384_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}

View File

@ -622,19 +622,20 @@ DECLSPEC void sha512_update_swap (sha512_ctx_t *ctx, const u32 *w, const int len
DECLSPEC void sha512_update_utf16le (sha512_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha512_update (ctx, w_utf16_buf, w_utf16_len);
sha512_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}
@ -705,19 +706,53 @@ DECLSPEC void sha512_update_utf16le (sha512_ctx_t *ctx, const u32 *w, const int
DECLSPEC void sha512_update_utf16le_swap (sha512_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
enc_buf[16] = hc_swap32_S (enc_buf[16]);
enc_buf[17] = hc_swap32_S (enc_buf[17]);
enc_buf[18] = hc_swap32_S (enc_buf[18]);
enc_buf[19] = hc_swap32_S (enc_buf[19]);
enc_buf[20] = hc_swap32_S (enc_buf[20]);
enc_buf[21] = hc_swap32_S (enc_buf[21]);
enc_buf[22] = hc_swap32_S (enc_buf[22]);
enc_buf[23] = hc_swap32_S (enc_buf[23]);
enc_buf[24] = hc_swap32_S (enc_buf[24]);
enc_buf[25] = hc_swap32_S (enc_buf[25]);
enc_buf[26] = hc_swap32_S (enc_buf[26]);
enc_buf[27] = hc_swap32_S (enc_buf[27]);
enc_buf[28] = hc_swap32_S (enc_buf[28]);
enc_buf[29] = hc_swap32_S (enc_buf[29]);
enc_buf[30] = hc_swap32_S (enc_buf[30]);
enc_buf[31] = hc_swap32_S (enc_buf[31]);
sha512_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha512_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}
@ -1096,19 +1131,20 @@ DECLSPEC void sha512_update_global_swap (sha512_ctx_t *ctx, GLOBAL_AS const u32
DECLSPEC void sha512_update_global_utf16le (sha512_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
sha512_update (ctx, w_utf16_buf, w_utf16_len);
sha512_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}
@ -1179,19 +1215,53 @@ DECLSPEC void sha512_update_global_utf16le (sha512_ctx_t *ctx, GLOBAL_AS const u
DECLSPEC void sha512_update_global_utf16le_swap (sha512_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[32];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
enc_buf[16] = hc_swap32_S (enc_buf[16]);
enc_buf[17] = hc_swap32_S (enc_buf[17]);
enc_buf[18] = hc_swap32_S (enc_buf[18]);
enc_buf[19] = hc_swap32_S (enc_buf[19]);
enc_buf[20] = hc_swap32_S (enc_buf[20]);
enc_buf[21] = hc_swap32_S (enc_buf[21]);
enc_buf[22] = hc_swap32_S (enc_buf[22]);
enc_buf[23] = hc_swap32_S (enc_buf[23]);
enc_buf[24] = hc_swap32_S (enc_buf[24]);
enc_buf[25] = hc_swap32_S (enc_buf[25]);
enc_buf[26] = hc_swap32_S (enc_buf[26]);
enc_buf[27] = hc_swap32_S (enc_buf[27]);
enc_buf[28] = hc_swap32_S (enc_buf[28]);
enc_buf[29] = hc_swap32_S (enc_buf[29]);
enc_buf[30] = hc_swap32_S (enc_buf[30]);
enc_buf[31] = hc_swap32_S (enc_buf[31]);
sha512_update_swap (ctx, w_utf16_buf, w_utf16_len);
sha512_update_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28, enc_len);
}
return;
}
@ -1842,19 +1912,101 @@ DECLSPEC void sha512_hmac_init_global_swap (sha512_hmac_ctx_t *ctx, GLOBAL_AS co
DECLSPEC void sha512_hmac_init_global_utf16le_swap (sha512_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
// forced full decode in one round
u32 *w_ptr = w_utf16_buf + blkoff;
u32 enc_buf[256];
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
sha512_hmac_init_swap (ctx, w_utf16_buf, w_utf16_len);
if (enc_len > 128)
{
sha512_ctx_t tmp;
sha512_init (&tmp);
sha512_update_global_utf16le_swap (&tmp, enc_buf, enc_len);
sha512_final (&tmp);
enc_buf[ 0] = h32_from_64_S (tmp.h[0]);
enc_buf[ 1] = l32_from_64_S (tmp.h[0]);
enc_buf[ 2] = h32_from_64_S (tmp.h[1]);
enc_buf[ 3] = l32_from_64_S (tmp.h[1]);
enc_buf[ 4] = h32_from_64_S (tmp.h[2]);
enc_buf[ 5] = l32_from_64_S (tmp.h[2]);
enc_buf[ 6] = h32_from_64_S (tmp.h[3]);
enc_buf[ 7] = l32_from_64_S (tmp.h[3]);
enc_buf[ 8] = h32_from_64_S (tmp.h[4]);
enc_buf[ 9] = l32_from_64_S (tmp.h[4]);
enc_buf[10] = h32_from_64_S (tmp.h[5]);
enc_buf[11] = l32_from_64_S (tmp.h[5]);
enc_buf[12] = h32_from_64_S (tmp.h[6]);
enc_buf[13] = l32_from_64_S (tmp.h[6]);
enc_buf[14] = h32_from_64_S (tmp.h[7]);
enc_buf[15] = l32_from_64_S (tmp.h[7]);
enc_buf[16] = 0;
enc_buf[17] = 0;
enc_buf[18] = 0;
enc_buf[19] = 0;
enc_buf[20] = 0;
enc_buf[21] = 0;
enc_buf[22] = 0;
enc_buf[23] = 0;
enc_buf[24] = 0;
enc_buf[25] = 0;
enc_buf[26] = 0;
enc_buf[27] = 0;
enc_buf[28] = 0;
enc_buf[29] = 0;
enc_buf[30] = 0;
enc_buf[31] = 0;
}
else
{
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]);
enc_buf[16] = hc_swap32_S (enc_buf[16]);
enc_buf[17] = hc_swap32_S (enc_buf[17]);
enc_buf[18] = hc_swap32_S (enc_buf[18]);
enc_buf[19] = hc_swap32_S (enc_buf[19]);
enc_buf[20] = hc_swap32_S (enc_buf[20]);
enc_buf[21] = hc_swap32_S (enc_buf[21]);
enc_buf[22] = hc_swap32_S (enc_buf[22]);
enc_buf[23] = hc_swap32_S (enc_buf[23]);
enc_buf[24] = hc_swap32_S (enc_buf[24]);
enc_buf[25] = hc_swap32_S (enc_buf[25]);
enc_buf[26] = hc_swap32_S (enc_buf[26]);
enc_buf[27] = hc_swap32_S (enc_buf[27]);
enc_buf[28] = hc_swap32_S (enc_buf[28]);
enc_buf[29] = hc_swap32_S (enc_buf[29]);
enc_buf[30] = hc_swap32_S (enc_buf[30]);
enc_buf[31] = hc_swap32_S (enc_buf[31]);
}
sha512_hmac_init_128 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_buf + 16, enc_buf + 20, enc_buf + 24, enc_buf + 28);
}
return;
}

View File

@ -1018,19 +1018,20 @@ DECLSPEC void whirlpool_update_swap (whirlpool_ctx_t *ctx, const u32 *w, const i
DECLSPEC void whirlpool_update_utf16le (whirlpool_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
whirlpool_update (ctx, w_utf16_buf, w_utf16_len);
whirlpool_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -1077,19 +1078,37 @@ DECLSPEC void whirlpool_update_utf16le (whirlpool_ctx_t *ctx, const u32 *w, cons
DECLSPEC void whirlpool_update_utf16le_swap (whirlpool_ctx_t *ctx, const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
whirlpool_update_swap (ctx, w_utf16_buf, w_utf16_len);
whirlpool_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -1308,19 +1327,20 @@ DECLSPEC void whirlpool_update_global_swap (whirlpool_ctx_t *ctx, GLOBAL_AS cons
DECLSPEC void whirlpool_update_global_utf16le (whirlpool_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
whirlpool_update (ctx, w_utf16_buf, w_utf16_len);
whirlpool_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}
@ -1367,19 +1387,37 @@ DECLSPEC void whirlpool_update_global_utf16le (whirlpool_ctx_t *ctx, GLOBAL_AS c
DECLSPEC void whirlpool_update_global_utf16le_swap (whirlpool_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len)
{
if (test_any_8th_bit (w, len) == 1)
if (hc_enc_scan_global (w, len))
{
u32 w_utf16_buf[256];
hc_enc_t hc_enc;
const int w_utf16_len = utf8_to_utf16le_global (w, len, 256, w_utf16_buf, sizeof (w_utf16_buf));
hc_enc_init (&hc_enc);
const int blkoff = (w_utf16_len / 64) * 16;
while (hc_enc_has_next (&hc_enc, len))
{
u32 enc_buf[16];
u32 *w_ptr = w_utf16_buf + blkoff;
const int enc_len = hc_enc_next_global (&hc_enc, w, len, 256, enc_buf, sizeof (enc_buf));
truncate_block_16x4_le_S (w_ptr + 0, w_ptr + 4, w_ptr + 8, w_ptr + 12, w_utf16_len & 63);
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]);
whirlpool_update_swap (ctx, w_utf16_buf, w_utf16_len);
whirlpool_update_64 (ctx, enc_buf + 0, enc_buf + 4, enc_buf + 8, enc_buf + 12, enc_len);
}
return;
}

View File

@ -1726,4 +1726,13 @@ typedef struct keyboard_layout_mapping
} keyboard_layout_mapping_t;
typedef struct hc_enc
{
int pos; // source offset
u32 cbuf; // carry buffer
int clen; // carry length
} hc_enc_t;
#endif