19extern const char LSH512_AVX_FNAME[] = __FILE__;
21#if defined(CRYPTOPP_AVX2_AVAILABLE) && defined(CRYPTOPP_ENABLE_64BIT_SSE)
23#if defined(CRYPTOPP_AVX2_AVAILABLE)
24# include <emmintrin.h>
25# include <immintrin.h>
28#if defined(CRYPTOPP_GCC_COMPATIBLE)
29# include <x86intrin.h>
32ANONYMOUS_NAMESPACE_BEGIN
36const unsigned int LSH512_MSG_BLK_BYTE_LEN = 256;
39const unsigned int LSH512_HASH_VAL_MAX_BYTE_LEN = 64;
42const unsigned int CV_WORD_LEN = 16;
43const unsigned int CONST_WORD_LEN = 8;
45const unsigned int NUM_STEPS = 28;
47const unsigned int ROT_EVEN_ALPHA = 23;
48const unsigned int ROT_EVEN_BETA = 59;
49const unsigned int ROT_ODD_ALPHA = 7;
50const unsigned int ROT_ODD_BETA = 3;
52const unsigned int LSH_TYPE_512_512 = 0x0010040;
53const unsigned int LSH_TYPE_512_384 = 0x0010030;
54const unsigned int LSH_TYPE_512_256 = 0x0010020;
55const unsigned int LSH_TYPE_512_224 = 0x001001C;
62const unsigned int LSH_SUCCESS = 0x0;
65const unsigned int LSH_ERR_INVALID_DATABITLEN = 0x2403;
66const unsigned int LSH_ERR_INVALID_STATE = 0x2404;
70const unsigned int AlgorithmType = 80;
71const unsigned int RemainingBits = 81;
79extern const word64 LSH512_IV224[CV_WORD_LEN];
80extern const word64 LSH512_IV256[CV_WORD_LEN];
81extern const word64 LSH512_IV384[CV_WORD_LEN];
82extern const word64 LSH512_IV512[CV_WORD_LEN];
83extern const word64 LSH512_StepConstants[CONST_WORD_LEN * NUM_STEPS];
88ANONYMOUS_NAMESPACE_BEGIN
91using CryptoPP::word32;
92using CryptoPP::word64;
93using CryptoPP::rotlFixed;
94using CryptoPP::rotlConstant;
96using CryptoPP::GetBlock;
97using CryptoPP::LittleEndian;
98using CryptoPP::ConditionalByteReverse;
99using CryptoPP::LITTLE_ENDIAN_ORDER;
101using CryptoPP::LSH::LSH512_IV224;
102using CryptoPP::LSH::LSH512_IV256;
103using CryptoPP::LSH::LSH512_IV384;
104using CryptoPP::LSH::LSH512_IV512;
105using CryptoPP::LSH::LSH512_StepConstants;
114struct LSH512_AVX2_Context
117 cv_l(state+0), cv_r(state+8), sub_msgs(state+16),
118 last_block(reinterpret_cast<
byte*>(state+48)),
119 remain_databitlen(remainingBitLength),
120 alg_type(static_cast<lsh_type>(algType)) {}
126 lsh_u64& remain_databitlen;
130struct LSH512_AVX2_Internal
132 LSH512_AVX2_Internal(
word64* state) :
133 submsg_e_l(state+16), submsg_e_r(state+24),
134 submsg_o_l(state+32), submsg_o_r(state+40) { }
158inline bool LSH_IS_LSH512(lsh_uint val) {
159 return (val & 0xf0000) == 0x10000;
162inline lsh_uint LSH_GET_SMALL_HASHBIT(lsh_uint val) {
166inline lsh_uint LSH_GET_HASHBYTE(lsh_uint val) {
170inline lsh_uint LSH_GET_HASHBIT(lsh_uint val) {
171 return (LSH_GET_HASHBYTE(val) << 3) - LSH_GET_SMALL_HASHBIT(val);
174inline lsh_u64 loadLE64(lsh_u64 v) {
178lsh_u64 ROTL64(lsh_u64 x, lsh_u32 r) {
183inline void load_msg_blk(LSH512_AVX2_Internal* i_state,
const lsh_u8 msgblk[LSH512_MSG_BLK_BYTE_LEN])
185 lsh_u64* submsg_e_l = i_state->submsg_e_l;
186 lsh_u64* submsg_e_r = i_state->submsg_e_r;
187 lsh_u64* submsg_o_l = i_state->submsg_o_l;
188 lsh_u64* submsg_o_r = i_state->submsg_o_r;
190 _mm256_storeu_si256(M256_CAST(submsg_e_l+0),
191 _mm256_loadu_si256(CONST_M256_CAST(msgblk+0)));
192 _mm256_storeu_si256(M256_CAST(submsg_e_l+4),
193 _mm256_loadu_si256(CONST_M256_CAST(msgblk+32)));
195 _mm256_storeu_si256(M256_CAST(submsg_e_r+0),
196 _mm256_loadu_si256(CONST_M256_CAST(msgblk+64)));
197 _mm256_storeu_si256(M256_CAST(submsg_e_r+4),
198 _mm256_loadu_si256(CONST_M256_CAST(msgblk+96)));
200 _mm256_storeu_si256(M256_CAST(submsg_o_l+0),
201 _mm256_loadu_si256(CONST_M256_CAST(msgblk+128)));
202 _mm256_storeu_si256(M256_CAST(submsg_o_l+4),
203 _mm256_loadu_si256(CONST_M256_CAST(msgblk+160)));
205 _mm256_storeu_si256(M256_CAST(submsg_o_r+0),
206 _mm256_loadu_si256(CONST_M256_CAST(msgblk+192)));
207 _mm256_storeu_si256(M256_CAST(submsg_o_r+4),
208 _mm256_loadu_si256(CONST_M256_CAST(msgblk+224)));
211inline void msg_exp_even(LSH512_AVX2_Internal* i_state)
215 lsh_u64* submsg_e_l = i_state->submsg_e_l;
216 lsh_u64* submsg_e_r = i_state->submsg_e_r;
217 lsh_u64* submsg_o_l = i_state->submsg_o_l;
218 lsh_u64* submsg_o_r = i_state->submsg_o_r;
220 _mm256_storeu_si256(M256_CAST(submsg_e_l+0), _mm256_add_epi64(
221 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_l+0)),
222 _mm256_permute4x64_epi64(
223 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_l+0)),
224 _MM_SHUFFLE(1,0,2,3))));
225 _mm256_storeu_si256(M256_CAST(submsg_e_l+4), _mm256_add_epi64(
226 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_l+4)),
227 _mm256_permute4x64_epi64(
228 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_l+4)),
229 _MM_SHUFFLE(2,1,0,3))));
231 _mm256_storeu_si256(M256_CAST(submsg_e_r+0), _mm256_add_epi64(
232 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_r+0)),
233 _mm256_permute4x64_epi64(
234 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_r+0)),
235 _MM_SHUFFLE(1,0,2,3))));
236 _mm256_storeu_si256(M256_CAST(submsg_e_r+4), _mm256_add_epi64(
237 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_r+4)),
238 _mm256_permute4x64_epi64(
239 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_r+4)),
240 _MM_SHUFFLE(2,1,0,3))));
243inline void msg_exp_odd(LSH512_AVX2_Internal* i_state)
247 lsh_u64* submsg_e_l = i_state->submsg_e_l;
248 lsh_u64* submsg_e_r = i_state->submsg_e_r;
249 lsh_u64* submsg_o_l = i_state->submsg_o_l;
250 lsh_u64* submsg_o_r = i_state->submsg_o_r;
252 _mm256_storeu_si256(M256_CAST(submsg_o_l+0),
254 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_l+0)),
255 _mm256_permute4x64_epi64(
256 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_l+0)),
257 _MM_SHUFFLE(1,0,2,3))));
258 _mm256_storeu_si256(M256_CAST(submsg_o_l+4),
260 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_l+4)),
261 _mm256_permute4x64_epi64(
262 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_l+4)),
263 _MM_SHUFFLE(2,1,0,3))));
265 _mm256_storeu_si256(M256_CAST(submsg_o_r+0),
267 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_r+0)),
268 _mm256_permute4x64_epi64(
269 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_r+0)),
270 _MM_SHUFFLE(1,0,2,3))));
271 _mm256_storeu_si256(M256_CAST(submsg_o_r+4),
273 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_r+4)),
274 _mm256_permute4x64_epi64(
275 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_r+4)),
276 _MM_SHUFFLE(2,1,0,3))));
279inline void load_sc(
const lsh_u64** p_const_v,
size_t i)
281 *p_const_v = &LSH512_StepConstants[i];
284inline void msg_add_even(lsh_u64 cv_l[8], lsh_u64 cv_r[8], LSH512_AVX2_Internal* i_state)
288 lsh_u64* submsg_e_l = i_state->submsg_e_l;
289 lsh_u64* submsg_e_r = i_state->submsg_e_r;
291 _mm256_storeu_si256(M256_CAST(cv_l), _mm256_xor_si256(
292 _mm256_loadu_si256(CONST_M256_CAST(cv_l)),
293 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_l))));
294 _mm256_storeu_si256(M256_CAST(cv_r), _mm256_xor_si256(
295 _mm256_loadu_si256(CONST_M256_CAST(cv_r)),
296 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_r))));
298 _mm256_storeu_si256(M256_CAST(cv_l+4), _mm256_xor_si256(
299 _mm256_loadu_si256(CONST_M256_CAST(cv_l+4)),
300 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_l+4))));
301 _mm256_storeu_si256(M256_CAST(cv_r+4), _mm256_xor_si256(
302 _mm256_loadu_si256(CONST_M256_CAST(cv_r+4)),
303 _mm256_loadu_si256(CONST_M256_CAST(submsg_e_r+4))));
306inline void msg_add_odd(lsh_u64 cv_l[8], lsh_u64 cv_r[8], LSH512_AVX2_Internal* i_state)
310 lsh_u64* submsg_o_l = i_state->submsg_o_l;
311 lsh_u64* submsg_o_r = i_state->submsg_o_r;
313 _mm256_storeu_si256(M256_CAST(cv_l), _mm256_xor_si256(
314 _mm256_loadu_si256(CONST_M256_CAST(cv_l)),
315 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_l))));
316 _mm256_storeu_si256(M256_CAST(cv_r), _mm256_xor_si256(
317 _mm256_loadu_si256(CONST_M256_CAST(cv_r)),
318 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_r))));
320 _mm256_storeu_si256(M256_CAST(cv_l+4), _mm256_xor_si256(
321 _mm256_loadu_si256(CONST_M256_CAST(cv_l+4)),
322 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_l+4))));
323 _mm256_storeu_si256(M256_CAST(cv_r+4), _mm256_xor_si256(
324 _mm256_loadu_si256(CONST_M256_CAST(cv_r+4)),
325 _mm256_loadu_si256(CONST_M256_CAST(submsg_o_r+4))));
328inline void add_blk(lsh_u64 cv_l[8], lsh_u64 cv_r[8])
330 _mm256_storeu_si256(M256_CAST(cv_l), _mm256_add_epi64(
331 _mm256_loadu_si256(CONST_M256_CAST(cv_l)),
332 _mm256_loadu_si256(CONST_M256_CAST(cv_r))));
333 _mm256_storeu_si256(M256_CAST(cv_l+4), _mm256_add_epi64(
334 _mm256_loadu_si256(CONST_M256_CAST(cv_l+4)),
335 _mm256_loadu_si256(CONST_M256_CAST(cv_r+4))));
338template <
unsigned int R>
339inline void rotate_blk(lsh_u64 cv[8])
341 _mm256_storeu_si256(M256_CAST(cv), _mm256_or_si256(
342 _mm256_slli_epi64(_mm256_loadu_si256(CONST_M256_CAST(cv)), R),
343 _mm256_srli_epi64(_mm256_loadu_si256(CONST_M256_CAST(cv)), 64-R)));
344 _mm256_storeu_si256(M256_CAST(cv+4), _mm256_or_si256(
345 _mm256_slli_epi64(_mm256_loadu_si256(CONST_M256_CAST(cv+4)), R),
346 _mm256_srli_epi64(_mm256_loadu_si256(CONST_M256_CAST(cv+4)), 64-R)));
349inline void xor_with_const(lsh_u64 cv_l[8],
const lsh_u64 const_v[8])
351 _mm256_storeu_si256(M256_CAST(cv_l), _mm256_xor_si256(
352 _mm256_loadu_si256(CONST_M256_CAST(cv_l)),
353 _mm256_loadu_si256(CONST_M256_CAST(const_v))));
354 _mm256_storeu_si256(M256_CAST(cv_l+4), _mm256_xor_si256(
355 _mm256_loadu_si256(CONST_M256_CAST(cv_l+4)),
356 _mm256_loadu_si256(CONST_M256_CAST(const_v+4))));
359inline void rotate_msg_gamma(lsh_u64 cv_r[8])
362 _mm256_storeu_si256(M256_CAST(cv_r+0),
364 _mm256_loadu_si256(CONST_M256_CAST(cv_r+0)),
366 9,8,15,14, 13,12,11,10, 3,2,1,0, 7,6,5,4,
367 13,12,11,10, 9,8,15,14, 7,6,5,4, 3,2,1,0)));
368 _mm256_storeu_si256(M256_CAST(cv_r+4),
370 _mm256_loadu_si256(CONST_M256_CAST(cv_r+4)),
372 8,15,14,13, 12,11,10,9, 2,1,0,7, 6,5,4,3,
373 12,11,10,9, 8,15,14,13, 6,5,4,3, 2,1,0,7)));
376inline void word_perm(lsh_u64 cv_l[8], lsh_u64 cv_r[8])
379 _mm256_storeu_si256(M256_CAST(cv_l+0), _mm256_permute4x64_epi64(
380 _mm256_loadu_si256(CONST_M256_CAST(cv_l+0)), _MM_SHUFFLE(3,1,0,2)));
381 _mm256_storeu_si256(M256_CAST(cv_l+4), _mm256_permute4x64_epi64(
382 _mm256_loadu_si256(CONST_M256_CAST(cv_l+4)), _MM_SHUFFLE(3,1,0,2)));
383 _mm256_storeu_si256(M256_CAST(cv_r+0), _mm256_permute4x64_epi64(
384 _mm256_loadu_si256(CONST_M256_CAST(cv_r+0)), _MM_SHUFFLE(1,2,3,0)));
385 _mm256_storeu_si256(M256_CAST(cv_r+4), _mm256_permute4x64_epi64(
386 _mm256_loadu_si256(CONST_M256_CAST(cv_r+4)), _MM_SHUFFLE(1,2,3,0)));
388 temp[0] = _mm256_loadu_si256(CONST_M256_CAST(cv_l+0));
389 temp[1] = _mm256_loadu_si256(CONST_M256_CAST(cv_r+0));
391 _mm256_storeu_si256(M256_CAST(cv_l+0),
392 _mm256_loadu_si256(CONST_M256_CAST(cv_l+4)));
393 _mm256_storeu_si256(M256_CAST(cv_l+4),
394 _mm256_loadu_si256(CONST_M256_CAST(cv_r+4)));
396 _mm256_storeu_si256(M256_CAST(cv_r+0), temp[0]);
397 _mm256_storeu_si256(M256_CAST(cv_r+4), temp[1]);
404template <
unsigned int Alpha,
unsigned int Beta>
405inline void mix(lsh_u64 cv_l[8], lsh_u64 cv_r[8],
const lsh_u64 const_v[8])
408 rotate_blk<Alpha>(cv_l);
409 xor_with_const(cv_l, const_v);
411 rotate_blk<Beta>(cv_r);
413 rotate_msg_gamma(cv_r);
420inline void compress(LSH512_AVX2_Context* ctx,
const lsh_u8 pdMsgBlk[LSH512_MSG_BLK_BYTE_LEN])
424 LSH512_AVX2_Internal s_state(ctx->cv_l);
425 LSH512_AVX2_Internal* i_state = &s_state;
427 const lsh_u64* const_v = NULL;
428 lsh_u64 *cv_l = ctx->cv_l;
429 lsh_u64 *cv_r = ctx->cv_r;
431 load_msg_blk(i_state, pdMsgBlk);
433 msg_add_even(cv_l, cv_r, i_state);
434 load_sc(&const_v, 0);
435 mix<ROT_EVEN_ALPHA, ROT_EVEN_BETA>(cv_l, cv_r, const_v);
436 word_perm(cv_l, cv_r);
438 msg_add_odd(cv_l, cv_r, i_state);
439 load_sc(&const_v, 8);
440 mix<ROT_ODD_ALPHA, ROT_ODD_BETA>(cv_l, cv_r, const_v);
441 word_perm(cv_l, cv_r);
443 for (
size_t i = 1; i < NUM_STEPS / 2; i++)
445 msg_exp_even(i_state);
446 msg_add_even(cv_l, cv_r, i_state);
447 load_sc(&const_v, 16 * i);
448 mix<ROT_EVEN_ALPHA, ROT_EVEN_BETA>(cv_l, cv_r, const_v);
449 word_perm(cv_l, cv_r);
451 msg_exp_odd(i_state);
452 msg_add_odd(cv_l, cv_r, i_state);
453 load_sc(&const_v, 16 * i + 8);
454 mix<ROT_ODD_ALPHA, ROT_ODD_BETA>(cv_l, cv_r, const_v);
455 word_perm(cv_l, cv_r);
458 msg_exp_even(i_state);
459 msg_add_even(cv_l, cv_r, i_state);
467 _mm256_storeu_si256(M256_CAST(cv_l+0),
468 _mm256_load_si256(CONST_M256_CAST(iv+0)));
469 _mm256_storeu_si256(M256_CAST(cv_l+4),
470 _mm256_load_si256(CONST_M256_CAST(iv+4)));
472 _mm256_storeu_si256(M256_CAST(cv_r+0),
473 _mm256_load_si256(CONST_M256_CAST(iv+8)));
474 _mm256_storeu_si256(M256_CAST(cv_r+4),
475 _mm256_load_si256(CONST_M256_CAST(iv+12)));
478inline void zero_iv(lsh_u64 cv_l[8], lsh_u64 cv_r[8])
480 _mm256_storeu_si256(M256_CAST(cv_l+0), _mm256_setzero_si256());
481 _mm256_storeu_si256(M256_CAST(cv_l+4), _mm256_setzero_si256());
482 _mm256_storeu_si256(M256_CAST(cv_r+0), _mm256_setzero_si256());
483 _mm256_storeu_si256(M256_CAST(cv_r+4), _mm256_setzero_si256());
486inline void zero_submsgs(LSH512_AVX2_Context* ctx)
488 lsh_u64* sub_msgs = ctx->sub_msgs;
490 _mm256_storeu_si256(M256_CAST(sub_msgs+ 0),
491 _mm256_setzero_si256());
492 _mm256_storeu_si256(M256_CAST(sub_msgs+ 4),
493 _mm256_setzero_si256());
495 _mm256_storeu_si256(M256_CAST(sub_msgs+ 8),
496 _mm256_setzero_si256());
497 _mm256_storeu_si256(M256_CAST(sub_msgs+12),
498 _mm256_setzero_si256());
501inline void init224(LSH512_AVX2_Context* ctx)
506 load_iv(ctx->cv_l, ctx->cv_r, LSH512_IV224);
509inline void init256(LSH512_AVX2_Context* ctx)
514 load_iv(ctx->cv_l, ctx->cv_r, LSH512_IV256);
517inline void init384(LSH512_AVX2_Context* ctx)
522 load_iv(ctx->cv_l, ctx->cv_r, LSH512_IV384);
525inline void init512(LSH512_AVX2_Context* ctx)
530 load_iv(ctx->cv_l, ctx->cv_r, LSH512_IV512);
535inline void fin(LSH512_AVX2_Context* ctx)
539 _mm256_storeu_si256(M256_CAST(ctx->cv_l+0), _mm256_xor_si256(
540 _mm256_loadu_si256(CONST_M256_CAST(ctx->cv_l+0)),
541 _mm256_loadu_si256(CONST_M256_CAST(ctx->cv_r+0))));
543 _mm256_storeu_si256(M256_CAST(ctx->cv_l+4), _mm256_xor_si256(
544 _mm256_loadu_si256(CONST_M256_CAST(ctx->cv_l+4)),
545 _mm256_loadu_si256(CONST_M256_CAST(ctx->cv_r+4))));
550inline void get_hash(LSH512_AVX2_Context* ctx, lsh_u8* pbHashVal)
556 lsh_uint alg_type = ctx->alg_type;
557 lsh_uint hash_val_byte_len = LSH_GET_HASHBYTE(alg_type);
558 lsh_uint hash_val_bit_len = LSH_GET_SMALL_HASHBIT(alg_type);
561 std::memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len);
562 if (hash_val_bit_len){
563 pbHashVal[hash_val_byte_len-1] &= (((lsh_u8)0xff) << hash_val_bit_len);
569lsh_err lsh512_init_avx2(LSH512_AVX2_Context* ctx)
574 lsh_u32 alg_type = ctx->alg_type;
575 const lsh_u64* const_v = NULL;
576 ctx->remain_databitlen = 0;
582 case LSH_TYPE_512_512:
585 case LSH_TYPE_512_384:
588 case LSH_TYPE_512_256:
591 case LSH_TYPE_512_224:
598 lsh_u64* cv_l = ctx->cv_l;
599 lsh_u64* cv_r = ctx->cv_r;
602 cv_l[0] = LSH512_HASH_VAL_MAX_BYTE_LEN;
603 cv_l[1] = LSH_GET_HASHBIT(alg_type);
605 for (
size_t i = 0; i < NUM_STEPS / 2; i++)
608 load_sc(&const_v, i * 16);
609 mix<ROT_EVEN_ALPHA, ROT_EVEN_BETA>(cv_l, cv_r, const_v);
610 word_perm(cv_l, cv_r);
612 load_sc(&const_v, i * 16 + 8);
613 mix<ROT_ODD_ALPHA, ROT_ODD_BETA>(cv_l, cv_r, const_v);
614 word_perm(cv_l, cv_r);
620lsh_err lsh512_update_avx2(LSH512_AVX2_Context* ctx,
const lsh_u8* data,
size_t databitlen)
630 if (databitlen == 0){
635 size_t databytelen = databitlen >> 3;
637 const size_t pos2 = 0;
639 size_t remain_msg_byte =
static_cast<size_t>(ctx->remain_databitlen >> 3);
641 const size_t remain_msg_bit = 0;
643 if (remain_msg_byte >= LSH512_MSG_BLK_BYTE_LEN){
644 return LSH_ERR_INVALID_STATE;
646 if (remain_msg_bit > 0){
647 return LSH_ERR_INVALID_DATABITLEN;
650 if (databytelen + remain_msg_byte < LSH512_MSG_BLK_BYTE_LEN){
651 std::memcpy(ctx->last_block + remain_msg_byte, data, databytelen);
652 ctx->remain_databitlen += (lsh_uint)databitlen;
653 remain_msg_byte += (lsh_uint)databytelen;
655 ctx->last_block[remain_msg_byte] = data[databytelen] & ((0xff >> pos2) ^ 0xff);
660 if (remain_msg_byte > 0){
661 size_t more_byte = LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte;
662 std::memcpy(ctx->last_block + remain_msg_byte, data, more_byte);
663 compress(ctx, ctx->last_block);
665 databytelen -= more_byte;
667 ctx->remain_databitlen = 0;
670 while (databytelen >= LSH512_MSG_BLK_BYTE_LEN)
676 data += LSH512_MSG_BLK_BYTE_LEN;
677 databytelen -= LSH512_MSG_BLK_BYTE_LEN;
680 if (databytelen > 0){
681 std::memcpy(ctx->last_block, data, databytelen);
682 ctx->remain_databitlen = (lsh_uint)(databytelen << 3);
686 ctx->last_block[databytelen] = data[databytelen] & ((0xff >> pos2) ^ 0xff);
687 ctx->remain_databitlen += pos2;
692lsh_err lsh512_final_avx2(LSH512_AVX2_Context* ctx, lsh_u8* hashval)
701 size_t remain_msg_byte =
static_cast<size_t>(ctx->remain_databitlen >> 3);
703 const size_t remain_msg_bit = 0;
705 if (remain_msg_byte >= LSH512_MSG_BLK_BYTE_LEN){
706 return LSH_ERR_INVALID_STATE;
710 ctx->last_block[remain_msg_byte] |= (0x1 << (7 - remain_msg_bit));
713 ctx->last_block[remain_msg_byte] = 0x80;
715 std::memset(ctx->last_block + remain_msg_byte + 1, 0, LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte - 1);
717 compress(ctx, ctx->last_block);
720 get_hash(ctx, hashval);
725ANONYMOUS_NAMESPACE_END
730void LSH512_Base_Restart_AVX2(
word64* state)
732 state[RemainingBits] = 0;
733 LSH512_AVX2_Context ctx(state, state[AlgorithmType], state[RemainingBits]);
734 lsh_err err = lsh512_init_avx2(&ctx);
736 if (err != LSH_SUCCESS)
741void LSH512_Base_Update_AVX2(
word64* state,
const byte *input,
size_t size)
743 LSH512_AVX2_Context ctx(state, state[AlgorithmType], state[RemainingBits]);
744 lsh_err err = lsh512_update_avx2(&ctx, input, 8*size);
746 if (err != LSH_SUCCESS)
751void LSH512_Base_TruncatedFinal_AVX2(
word64* state,
byte *hash,
size_t)
753 LSH512_AVX2_Context ctx(state, state[AlgorithmType], state[RemainingBits]);
754 lsh_err err = lsh512_final_avx2(&ctx, hash);
756 if (err != LSH_SUCCESS)
Base class for all exceptions thrown by the library.
@ OTHER_ERROR
Some other error occurred not belonging to other categories.
Library configuration file.
unsigned char byte
8-bit unsigned datatype
unsigned int word32
32-bit unsigned datatype
unsigned long long word64
64-bit unsigned datatype
@ LITTLE_ENDIAN_ORDER
byte order is little-endian
Classes for the LSH hash functions.
Utility functions for the Crypto++ library.
T ConditionalByteReverse(ByteOrder order, T value)
Reverses bytes in a value depending upon endianness.
T rotlFixed(T x, unsigned int y)
Performs a left rotate.
Crypto++ library namespace.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.