42 #if SPH_SMALL_FOOTPRINT && !defined SPH_SMALL_FOOTPRINT_HAMSI 43 #define SPH_SMALL_FOOTPRINT_HAMSI 1 99 #if !defined SPH_HAMSI_EXPAND_SMALL 100 #if SPH_SMALL_FOOTPRINT_HAMSI 101 #define SPH_HAMSI_EXPAND_SMALL 4 103 #define SPH_HAMSI_EXPAND_SMALL 8 107 #if !defined SPH_HAMSI_EXPAND_BIG 108 #define SPH_HAMSI_EXPAND_BIG 8 112 #pragma warning (disable: 4146) 117 static const sph_u32 IV224[] = {
135 static const sph_u32 IV256[] = {
141 static const sph_u32 IV384[] = {
150 static const sph_u32 IV512[] = {
159 static const sph_u32 alpha_n[] = {
173 static const sph_u32 alpha_f[] = {
187 #define DECL_STATE_SMALL \ 188 sph_u32 c0, c1, c2, c3, c4, c5, c6, c7; 190 #define READ_STATE_SMALL(sc) do { \ 201 #define WRITE_STATE_SMALL(sc) do { \ 229 #define SBOX(a, b, c, d) do { \ 252 #define L(a, b, c, d) do { \ 253 (a) = SPH_ROTL32(a, 13); \ 254 (c) = SPH_ROTL32(c, 3); \ 256 (d) ^= (c) ^ SPH_T32((a) << 3); \ 257 (b) = SPH_ROTL32(b, 1); \ 258 (d) = SPH_ROTL32(d, 7); \ 260 (c) ^= (d) ^ SPH_T32((b) << 7); \ 261 (a) = SPH_ROTL32(a, 5); \ 262 (c) = SPH_ROTL32(c, 22); \ 265 #define ROUND_SMALL(rc, alpha) do { \ 267 s1 ^= alpha[0x01] ^ (sph_u32)(rc); \ 282 SBOX(s0, s4, s8, sC); \ 283 SBOX(s1, s5, s9, sD); \ 284 SBOX(s2, s6, sA, sE); \ 285 SBOX(s3, s7, sB, sF); \ 292 #define P_SMALL do { \ 293 ROUND_SMALL(0, alpha_n); \ 294 ROUND_SMALL(1, alpha_n); \ 295 ROUND_SMALL(2, alpha_n); \ 298 #define PF_SMALL do { \ 299 ROUND_SMALL(0, alpha_f); \ 300 ROUND_SMALL(1, alpha_f); \ 301 ROUND_SMALL(2, alpha_f); \ 302 ROUND_SMALL(3, alpha_f); \ 303 ROUND_SMALL(4, alpha_f); \ 304 ROUND_SMALL(5, alpha_f); \ 307 #define T_SMALL do { \ 309 c7 = (sc->h[7] ^= sB); \ 310 c6 = (sc->h[6] ^= sA); \ 311 c5 = (sc->h[5] ^= s9); \ 312 c4 = (sc->h[4] ^= s8); \ 313 c3 = (sc->h[3] ^= s3); \ 314 c2 = (sc->h[2] ^= s2); \ 315 c1 = (sc->h[1] ^= s1); \ 316 c0 = (sc->h[0] ^= s0); \ 328 sc->count += (sph_u64)num << 5;
338 sph_u32 m0, m1, m2, m3, m4, m5, m6, m7;
351 sph_u32 m0, m1, m2, m3, m4, m5, m6, m7;
387 data = (
const unsigned char *)data + mlen;
388 hamsi_small(sc, sc->
partial, 1);
393 hamsi_small(sc, data, (len >> 2));
394 data = (
const unsigned char *)data + (len & ~(
size_t)3);
402 unsigned ub,
unsigned n,
void *dst,
size_t out_size_w32)
404 unsigned char pad[12];
412 sph_enc64be(pad + 4, sc->count + (ptr << 3) + n);
415 sph_enc32be(pad + 8, sc->
count_low + (ptr << 3) + n);
418 pad[ptr ++] = ((ub & -z) | z) & 0xFF;
421 hamsi_small(sc, pad, 2);
422 hamsi_small_final(sc, pad + 8);
424 for (u = 0; u < out_size_w32; u ++)
425 sph_enc32be(out + (u << 2), sc->
h[u]);
428 #define DECL_STATE_BIG \ 429 sph_u32 c0, c1, c2, c3, c4, c5, c6, c7; \ 430 sph_u32 c8, c9, cA, cB, cC, cD, cE, cF; 432 #define READ_STATE_BIG(sc) do { \ 451 #define WRITE_STATE_BIG(sc) do { \ 503 #define ROUND_BIG(rc, alpha) do { \ 504 s00 ^= alpha[0x00]; \ 505 s01 ^= alpha[0x01] ^ (sph_u32)(rc); \ 506 s02 ^= alpha[0x02]; \ 507 s03 ^= alpha[0x03]; \ 508 s04 ^= alpha[0x04]; \ 509 s05 ^= alpha[0x05]; \ 510 s06 ^= alpha[0x06]; \ 511 s07 ^= alpha[0x07]; \ 512 s08 ^= alpha[0x08]; \ 513 s09 ^= alpha[0x09]; \ 514 s0A ^= alpha[0x0A]; \ 515 s0B ^= alpha[0x0B]; \ 516 s0C ^= alpha[0x0C]; \ 517 s0D ^= alpha[0x0D]; \ 518 s0E ^= alpha[0x0E]; \ 519 s0F ^= alpha[0x0F]; \ 520 s10 ^= alpha[0x10]; \ 521 s11 ^= alpha[0x11]; \ 522 s12 ^= alpha[0x12]; \ 523 s13 ^= alpha[0x13]; \ 524 s14 ^= alpha[0x14]; \ 525 s15 ^= alpha[0x15]; \ 526 s16 ^= alpha[0x16]; \ 527 s17 ^= alpha[0x17]; \ 528 s18 ^= alpha[0x18]; \ 529 s19 ^= alpha[0x19]; \ 530 s1A ^= alpha[0x1A]; \ 531 s1B ^= alpha[0x1B]; \ 532 s1C ^= alpha[0x1C]; \ 533 s1D ^= alpha[0x1D]; \ 534 s1E ^= alpha[0x1E]; \ 535 s1F ^= alpha[0x1F]; \ 536 SBOX(s00, s08, s10, s18); \ 537 SBOX(s01, s09, s11, s19); \ 538 SBOX(s02, s0A, s12, s1A); \ 539 SBOX(s03, s0B, s13, s1B); \ 540 SBOX(s04, s0C, s14, s1C); \ 541 SBOX(s05, s0D, s15, s1D); \ 542 SBOX(s06, s0E, s16, s1E); \ 543 SBOX(s07, s0F, s17, s1F); \ 544 L(s00, s09, s12, s1B); \ 545 L(s01, s0A, s13, s1C); \ 546 L(s02, s0B, s14, s1D); \ 547 L(s03, s0C, s15, s1E); \ 548 L(s04, s0D, s16, s1F); \ 549 L(s05, s0E, s17, s18); \ 550 L(s06, s0F, s10, s19); \ 551 L(s07, s08, s11, s1A); \ 552 L(s00, s02, s05, s07); \ 553 L(s10, s13, s15, s16); \ 554 L(s09, s0B, s0C, s0E); \ 555 L(s19, s1A, s1C, s1F); \ 558 #if SPH_SMALL_FOOTPRINT_HAMSI 562 for (r = 0; r < 6; r ++) \ 563 ROUND_BIG(r, alpha_n); \ 566 #define PF_BIG do { \ 568 for (r = 0; r < 12; r ++) \ 569 ROUND_BIG(r, alpha_f); \ 575 ROUND_BIG(0, alpha_n); \ 576 ROUND_BIG(1, alpha_n); \ 577 ROUND_BIG(2, alpha_n); \ 578 ROUND_BIG(3, alpha_n); \ 579 ROUND_BIG(4, alpha_n); \ 580 ROUND_BIG(5, alpha_n); \ 583 #define PF_BIG do { \ 584 ROUND_BIG(0, alpha_f); \ 585 ROUND_BIG(1, alpha_f); \ 586 ROUND_BIG(2, alpha_f); \ 587 ROUND_BIG(3, alpha_f); \ 588 ROUND_BIG(4, alpha_f); \ 589 ROUND_BIG(5, alpha_f); \ 590 ROUND_BIG(6, alpha_f); \ 591 ROUND_BIG(7, alpha_f); \ 592 ROUND_BIG(8, alpha_f); \ 593 ROUND_BIG(9, alpha_f); \ 594 ROUND_BIG(10, alpha_f); \ 595 ROUND_BIG(11, alpha_f); \ 602 cF = (sc->h[0xF] ^= s17); \ 603 cE = (sc->h[0xE] ^= s16); \ 604 cD = (sc->h[0xD] ^= s15); \ 605 cC = (sc->h[0xC] ^= s14); \ 606 cB = (sc->h[0xB] ^= s13); \ 607 cA = (sc->h[0xA] ^= s12); \ 608 c9 = (sc->h[0x9] ^= s11); \ 609 c8 = (sc->h[0x8] ^= s10); \ 610 c7 = (sc->h[0x7] ^= s07); \ 611 c6 = (sc->h[0x6] ^= s06); \ 612 c5 = (sc->h[0x5] ^= s05); \ 613 c4 = (sc->h[0x4] ^= s04); \ 614 c3 = (sc->h[0x3] ^= s03); \ 615 c2 = (sc->h[0x2] ^= s02); \ 616 c1 = (sc->h[0x1] ^= s01); \ 617 c0 = (sc->h[0x0] ^= s00); \ 629 sc->count += (sph_u64)num << 6;
639 sph_u32 m0, m1, m2, m3, m4, m5, m6, m7;
640 sph_u32 m8, m9, mA, mB, mC, mD, mE, mF;
653 sph_u32 m0, m1, m2, m3, m4, m5, m6, m7;
654 sph_u32 m8, m9, mA, mB, mC, mD, mE, mF;
690 data = (
const unsigned char *)data + mlen;
696 hamsi_big(sc, data, (len >> 3));
697 data = (
const unsigned char *)data + (len & ~(
size_t)7);
705 unsigned ub,
unsigned n,
void *dst,
size_t out_size_w32)
707 unsigned char pad[8];
714 sph_enc64be(pad, sc->count + (ptr << 3) + n);
717 sph_enc32be(pad + 4, sc->
count_low + (ptr << 3) + n);
720 sc->
partial[ptr ++] = ((ub & -z) | z) & 0xFF;
724 hamsi_big_final(sc, pad);
726 if (out_size_w32 == 12) {
727 sph_enc32be(out + 0, sc->
h[ 0]);
728 sph_enc32be(out + 4, sc->
h[ 1]);
729 sph_enc32be(out + 8, sc->
h[ 3]);
730 sph_enc32be(out + 12, sc->
h[ 4]);
731 sph_enc32be(out + 16, sc->
h[ 5]);
732 sph_enc32be(out + 20, sc->
h[ 6]);
733 sph_enc32be(out + 24, sc->
h[ 8]);
734 sph_enc32be(out + 28, sc->
h[ 9]);
735 sph_enc32be(out + 32, sc->
h[10]);
736 sph_enc32be(out + 36, sc->
h[12]);
737 sph_enc32be(out + 40, sc->
h[13]);
738 sph_enc32be(out + 44, sc->
h[15]);
740 for (u = 0; u < 16; u ++)
741 sph_enc32be(out + (u << 2), sc->
h[u]);
749 hamsi_small_init(cc, IV224);
756 hamsi_small_core(cc, data, len);
763 hamsi_small_close(cc, 0, 0, dst, 7);
771 hamsi_small_close(cc, ub, n, dst, 7);
779 hamsi_small_init(cc, IV256);
786 hamsi_small_core(cc, data, len);
793 hamsi_small_close(cc, 0, 0, dst, 8);
801 hamsi_small_close(cc, ub, n, dst, 8);
809 hamsi_big_init(cc, IV384);
816 hamsi_big_core(cc, data, len);
823 hamsi_big_close(cc, 0, 0, dst, 12);
831 hamsi_big_close(cc, ub, n, dst, 12);
839 hamsi_big_init(cc, IV512);
846 hamsi_big_core(cc, data, len);
853 hamsi_big_close(cc, 0, 0, dst, 16);
861 hamsi_big_close(cc, ub, n, dst, 16);
void sph_hamsi224(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_hamsi256(void *cc, const void *data, size_t len)
Process some data bytes.
#define READ_STATE_BIG(sc)
void sph_hamsi512(void *cc, const void *data, size_t len)
Process some data bytes.
#define WRITE_STATE_SMALL(sc)
#define READ_STATE_SMALL(sc)
#define WRITE_STATE_BIG(sc)
void sph_hamsi224_close(void *cc, void *dst)
Terminate the current Hamsi-224 computation and output the result into the provided buffer...
void sph_hamsi384_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
Add a few additional bits (0 to 7) to the current computation, then terminate it and output the resul...
void sph_hamsi256_init(void *cc)
Initialize a Hamsi-256 context.
This structure is a context for Hamsi-384 and Hamsi-512 computations: it contains the intermediate va...
void sph_hamsi512_init(void *cc)
Initialize a Hamsi-512 context.
void sph_hamsi384_init(void *cc)
Initialize a Hamsi-384 context.
void sph_hamsi384_close(void *cc, void *dst)
Terminate the current Hamsi-384 computation and output the result into the provided buffer...
void sph_hamsi224_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
Add a few additional bits (0 to 7) to the current computation, then terminate it and output the resul...
void sph_hamsi512_close(void *cc, void *dst)
Terminate the current Hamsi-512 computation and output the result into the provided buffer...
void * memcpy(void *a, const void *b, size_t c)
void sph_hamsi256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
Add a few additional bits (0 to 7) to the current computation, then terminate it and output the resul...
void sph_hamsi256_close(void *cc, void *dst)
Terminate the current Hamsi-256 computation and output the result into the provided buffer...
void sph_hamsi224_init(void *cc)
Initialize a Hamsi-224 context.
This structure is a context for Hamsi-224 and Hamsi-256 computations: it contains the intermediate va...
void sph_hamsi512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
Add a few additional bits (0 to 7) to the current computation, then terminate it and output the resul...
void sph_hamsi384(void *cc, const void *data, size_t len)
Process some data bytes.