43 #if SPH_SMALL_FOOTPRINT && !defined SPH_SMALL_FOOTPRINT_BLAKE 44 #define SPH_SMALL_FOOTPRINT_BLAKE 1 47 #if SPH_SMALL_FOOTPRINT_BLAKE 48 #define SPH_COMPACT_BLAKE_32 1 51 #if SPH_64 && (SPH_SMALL_FOOTPRINT_BLAKE || !SPH_64_TRUE) 52 #define SPH_COMPACT_BLAKE_64 1 56 #pragma warning (disable: 4146) 75 static const sph_u64
IV384[8] = {
76 SPH_C64(0xCBBB9D5DC1059ED8), SPH_C64(0x629A292A367CD507),
77 SPH_C64(0x9159015A3070DD17), SPH_C64(0x152FECD8F70E5939),
78 SPH_C64(0x67332667FFC00B31), SPH_C64(0x8EB44A8768581511),
79 SPH_C64(0xDB0C2E0D64F98FA7), SPH_C64(0x47B5481DBEFA4FA4)
82 static const sph_u64
IV512[8] = {
83 SPH_C64(0x6A09E667F3BCC908), SPH_C64(0xBB67AE8584CAA73B),
84 SPH_C64(0x3C6EF372FE94F82B), SPH_C64(0xA54FF53A5F1D36F1),
85 SPH_C64(0x510E527FADE682D1), SPH_C64(0x9B05688C2B3E6C1F),
86 SPH_C64(0x1F83D9ABFB41BD6B), SPH_C64(0x5BE0CD19137E2179)
91 #if SPH_COMPACT_BLAKE_32 || SPH_COMPACT_BLAKE_64 93 static const unsigned sigma[16][16] = {
94 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
95 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
96 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
97 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
98 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
99 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
100 { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
101 { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
102 { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
103 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
104 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
105 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
106 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
107 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
108 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
109 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
296 #define Mx(r, i) Mx_(Z ## r ## i) 297 #define Mx_(n) Mx__(n) 298 #define Mx__(n) M ## n 300 #define CSx(r, i) CSx_(Z ## r ## i) 301 #define CSx_(n) CSx__(n) 302 #define CSx__(n) CS ## n 304 #define CS0 SPH_C32(0x243F6A88) 305 #define CS1 SPH_C32(0x85A308D3) 306 #define CS2 SPH_C32(0x13198A2E) 307 #define CS3 SPH_C32(0x03707344) 308 #define CS4 SPH_C32(0xA4093822) 309 #define CS5 SPH_C32(0x299F31D0) 310 #define CS6 SPH_C32(0x082EFA98) 311 #define CS7 SPH_C32(0xEC4E6C89) 312 #define CS8 SPH_C32(0x452821E6) 313 #define CS9 SPH_C32(0x38D01377) 314 #define CSA SPH_C32(0xBE5466CF) 315 #define CSB SPH_C32(0x34E90C6C) 316 #define CSC SPH_C32(0xC0AC29B7) 317 #define CSD SPH_C32(0xC97C50DD) 318 #define CSE SPH_C32(0x3F84D5B5) 319 #define CSF SPH_C32(0xB5470917) 321 #if SPH_COMPACT_BLAKE_32 323 static const sph_u32 CS[16] = {
338 #define CBx(r, i) CBx_(Z ## r ## i) 339 #define CBx_(n) CBx__(n) 340 #define CBx__(n) CB ## n 342 #define CB0 SPH_C64(0x243F6A8885A308D3) 343 #define CB1 SPH_C64(0x13198A2E03707344) 344 #define CB2 SPH_C64(0xA4093822299F31D0) 345 #define CB3 SPH_C64(0x082EFA98EC4E6C89) 346 #define CB4 SPH_C64(0x452821E638D01377) 347 #define CB5 SPH_C64(0xBE5466CF34E90C6C) 348 #define CB6 SPH_C64(0xC0AC29B7C97C50DD) 349 #define CB7 SPH_C64(0x3F84D5B5B5470917) 350 #define CB8 SPH_C64(0x9216D5D98979FB1B) 351 #define CB9 SPH_C64(0xD1310BA698DFB5AC) 352 #define CBA SPH_C64(0x2FFD72DBD01ADFB7) 353 #define CBB SPH_C64(0xB8E1AFED6A267E96) 354 #define CBC SPH_C64(0xBA7C9045F12C7F99) 355 #define CBD SPH_C64(0x24A19947B3916CF7) 356 #define CBE SPH_C64(0x0801F2E2858EFC16) 357 #define CBF SPH_C64(0x636920D871574E69) 359 #if SPH_COMPACT_BLAKE_64 361 static const sph_u64 CB[16] = {
362 SPH_C64(0x243F6A8885A308D3), SPH_C64(0x13198A2E03707344),
363 SPH_C64(0xA4093822299F31D0), SPH_C64(0x082EFA98EC4E6C89),
364 SPH_C64(0x452821E638D01377), SPH_C64(0xBE5466CF34E90C6C),
365 SPH_C64(0xC0AC29B7C97C50DD), SPH_C64(0x3F84D5B5B5470917),
366 SPH_C64(0x9216D5D98979FB1B), SPH_C64(0xD1310BA698DFB5AC),
367 SPH_C64(0x2FFD72DBD01ADFB7), SPH_C64(0xB8E1AFED6A267E96),
368 SPH_C64(0xBA7C9045F12C7F99), SPH_C64(0x24A19947B3916CF7),
369 SPH_C64(0x0801F2E2858EFC16), SPH_C64(0x636920D871574E69)
376 #define GS(m0, m1, c0, c1, a, b, c, d) do { \ 377 a = SPH_T32(a + b + (m0 ^ c1)); \ 378 d = SPH_ROTR32(d ^ a, 16); \ 379 c = SPH_T32(c + d); \ 380 b = SPH_ROTR32(b ^ c, 12); \ 381 a = SPH_T32(a + b + (m1 ^ c0)); \ 382 d = SPH_ROTR32(d ^ a, 8); \ 383 c = SPH_T32(c + d); \ 384 b = SPH_ROTR32(b ^ c, 7); \ 387 #if SPH_COMPACT_BLAKE_32 389 #define ROUND_S(r) do { \ 390 GS(M[sigma[r][0x0]], M[sigma[r][0x1]], \ 391 CS[sigma[r][0x0]], CS[sigma[r][0x1]], V0, V4, V8, VC); \ 392 GS(M[sigma[r][0x2]], M[sigma[r][0x3]], \ 393 CS[sigma[r][0x2]], CS[sigma[r][0x3]], V1, V5, V9, VD); \ 394 GS(M[sigma[r][0x4]], M[sigma[r][0x5]], \ 395 CS[sigma[r][0x4]], CS[sigma[r][0x5]], V2, V6, VA, VE); \ 396 GS(M[sigma[r][0x6]], M[sigma[r][0x7]], \ 397 CS[sigma[r][0x6]], CS[sigma[r][0x7]], V3, V7, VB, VF); \ 398 GS(M[sigma[r][0x8]], M[sigma[r][0x9]], \ 399 CS[sigma[r][0x8]], CS[sigma[r][0x9]], V0, V5, VA, VF); \ 400 GS(M[sigma[r][0xA]], M[sigma[r][0xB]], \ 401 CS[sigma[r][0xA]], CS[sigma[r][0xB]], V1, V6, VB, VC); \ 402 GS(M[sigma[r][0xC]], M[sigma[r][0xD]], \ 403 CS[sigma[r][0xC]], CS[sigma[r][0xD]], V2, V7, V8, VD); \ 404 GS(M[sigma[r][0xE]], M[sigma[r][0xF]], \ 405 CS[sigma[r][0xE]], CS[sigma[r][0xF]], V3, V4, V9, VE); \ 410 #define ROUND_S(r) do { \ 411 GS(Mx(r, 0), Mx(r, 1), CSx(r, 0), CSx(r, 1), V0, V4, V8, VC); \ 412 GS(Mx(r, 2), Mx(r, 3), CSx(r, 2), CSx(r, 3), V1, V5, V9, VD); \ 413 GS(Mx(r, 4), Mx(r, 5), CSx(r, 4), CSx(r, 5), V2, V6, VA, VE); \ 414 GS(Mx(r, 6), Mx(r, 7), CSx(r, 6), CSx(r, 7), V3, V7, VB, VF); \ 415 GS(Mx(r, 8), Mx(r, 9), CSx(r, 8), CSx(r, 9), V0, V5, VA, VF); \ 416 GS(Mx(r, A), Mx(r, B), CSx(r, A), CSx(r, B), V1, V6, VB, VC); \ 417 GS(Mx(r, C), Mx(r, D), CSx(r, C), CSx(r, D), V2, V7, V8, VD); \ 418 GS(Mx(r, E), Mx(r, F), CSx(r, E), CSx(r, F), V3, V4, V9, VE); \ 425 #define GB(m0, m1, c0, c1, a, b, c, d) do { \ 426 a = SPH_T64(a + b + (m0 ^ c1)); \ 427 d = SPH_ROTR64(d ^ a, 32); \ 428 c = SPH_T64(c + d); \ 429 b = SPH_ROTR64(b ^ c, 25); \ 430 a = SPH_T64(a + b + (m1 ^ c0)); \ 431 d = SPH_ROTR64(d ^ a, 16); \ 432 c = SPH_T64(c + d); \ 433 b = SPH_ROTR64(b ^ c, 11); \ 436 #if SPH_COMPACT_BLAKE_64 438 #define ROUND_B(r) do { \ 439 GB(M[sigma[r][0x0]], M[sigma[r][0x1]], \ 440 CB[sigma[r][0x0]], CB[sigma[r][0x1]], V0, V4, V8, VC); \ 441 GB(M[sigma[r][0x2]], M[sigma[r][0x3]], \ 442 CB[sigma[r][0x2]], CB[sigma[r][0x3]], V1, V5, V9, VD); \ 443 GB(M[sigma[r][0x4]], M[sigma[r][0x5]], \ 444 CB[sigma[r][0x4]], CB[sigma[r][0x5]], V2, V6, VA, VE); \ 445 GB(M[sigma[r][0x6]], M[sigma[r][0x7]], \ 446 CB[sigma[r][0x6]], CB[sigma[r][0x7]], V3, V7, VB, VF); \ 447 GB(M[sigma[r][0x8]], M[sigma[r][0x9]], \ 448 CB[sigma[r][0x8]], CB[sigma[r][0x9]], V0, V5, VA, VF); \ 449 GB(M[sigma[r][0xA]], M[sigma[r][0xB]], \ 450 CB[sigma[r][0xA]], CB[sigma[r][0xB]], V1, V6, VB, VC); \ 451 GB(M[sigma[r][0xC]], M[sigma[r][0xD]], \ 452 CB[sigma[r][0xC]], CB[sigma[r][0xD]], V2, V7, V8, VD); \ 453 GB(M[sigma[r][0xE]], M[sigma[r][0xF]], \ 454 CB[sigma[r][0xE]], CB[sigma[r][0xF]], V3, V4, V9, VE); \ 459 #define ROUND_B(r) do { \ 460 GB(Mx(r, 0), Mx(r, 1), CBx(r, 0), CBx(r, 1), V0, V4, V8, VC); \ 461 GB(Mx(r, 2), Mx(r, 3), CBx(r, 2), CBx(r, 3), V1, V5, V9, VD); \ 462 GB(Mx(r, 4), Mx(r, 5), CBx(r, 4), CBx(r, 5), V2, V6, VA, VE); \ 463 GB(Mx(r, 6), Mx(r, 7), CBx(r, 6), CBx(r, 7), V3, V7, VB, VF); \ 464 GB(Mx(r, 8), Mx(r, 9), CBx(r, 8), CBx(r, 9), V0, V5, VA, VF); \ 465 GB(Mx(r, A), Mx(r, B), CBx(r, A), CBx(r, B), V1, V6, VB, VC); \ 466 GB(Mx(r, C), Mx(r, D), CBx(r, C), CBx(r, D), V2, V7, V8, VD); \ 467 GB(Mx(r, E), Mx(r, F), CBx(r, E), CBx(r, F), V3, V4, V9, VE); \ 474 #define DECL_STATE32 \ 475 sph_u32 H0, H1, H2, H3, H4, H5, H6, H7; \ 476 sph_u32 S0, S1, S2, S3, T0, T1; 478 #define READ_STATE32(state) do { \ 479 H0 = (state)->H[0]; \ 480 H1 = (state)->H[1]; \ 481 H2 = (state)->H[2]; \ 482 H3 = (state)->H[3]; \ 483 H4 = (state)->H[4]; \ 484 H5 = (state)->H[5]; \ 485 H6 = (state)->H[6]; \ 486 H7 = (state)->H[7]; \ 487 S0 = (state)->S[0]; \ 488 S1 = (state)->S[1]; \ 489 S2 = (state)->S[2]; \ 490 S3 = (state)->S[3]; \ 495 #define WRITE_STATE32(state) do { \ 496 (state)->H[0] = H0; \ 497 (state)->H[1] = H1; \ 498 (state)->H[2] = H2; \ 499 (state)->H[3] = H3; \ 500 (state)->H[4] = H4; \ 501 (state)->H[5] = H5; \ 502 (state)->H[6] = H6; \ 503 (state)->H[7] = H7; \ 504 (state)->S[0] = S0; \ 505 (state)->S[1] = S1; \ 506 (state)->S[2] = S2; \ 507 (state)->S[3] = S3; \ 512 #if SPH_COMPACT_BLAKE_32 514 #define COMPRESS32 do { \ 516 sph_u32 V0, V1, V2, V3, V4, V5, V6, V7; \ 517 sph_u32 V8, V9, VA, VB, VC, VD, VE, VF; \ 535 M[0x0] = sph_dec32be_aligned(buf + 0); \ 536 M[0x1] = sph_dec32be_aligned(buf + 4); \ 537 M[0x2] = sph_dec32be_aligned(buf + 8); \ 538 M[0x3] = sph_dec32be_aligned(buf + 12); \ 539 M[0x4] = sph_dec32be_aligned(buf + 16); \ 540 M[0x5] = sph_dec32be_aligned(buf + 20); \ 541 M[0x6] = sph_dec32be_aligned(buf + 24); \ 542 M[0x7] = sph_dec32be_aligned(buf + 28); \ 543 M[0x8] = sph_dec32be_aligned(buf + 32); \ 544 M[0x9] = sph_dec32be_aligned(buf + 36); \ 545 M[0xA] = sph_dec32be_aligned(buf + 40); \ 546 M[0xB] = sph_dec32be_aligned(buf + 44); \ 547 M[0xC] = sph_dec32be_aligned(buf + 48); \ 548 M[0xD] = sph_dec32be_aligned(buf + 52); \ 549 M[0xE] = sph_dec32be_aligned(buf + 56); \ 550 M[0xF] = sph_dec32be_aligned(buf + 60); \ 551 for (r = 0; r < 14; r ++) \ 553 H0 ^= S0 ^ V0 ^ V8; \ 554 H1 ^= S1 ^ V1 ^ V9; \ 555 H2 ^= S2 ^ V2 ^ VA; \ 556 H3 ^= S3 ^ V3 ^ VB; \ 557 H4 ^= S0 ^ V4 ^ VC; \ 558 H5 ^= S1 ^ V5 ^ VD; \ 559 H6 ^= S2 ^ V6 ^ VE; \ 560 H7 ^= S3 ^ V7 ^ VF; \ 565 #define COMPRESS32 do { \ 566 sph_u32 M0, M1, M2, M3, M4, M5, M6, M7; \ 567 sph_u32 M8, M9, MA, MB, MC, MD, ME, MF; \ 568 sph_u32 V0, V1, V2, V3, V4, V5, V6, V7; \ 569 sph_u32 V8, V9, VA, VB, VC, VD, VE, VF; \ 586 M0 = sph_dec32be_aligned(buf + 0); \ 587 M1 = sph_dec32be_aligned(buf + 4); \ 588 M2 = sph_dec32be_aligned(buf + 8); \ 589 M3 = sph_dec32be_aligned(buf + 12); \ 590 M4 = sph_dec32be_aligned(buf + 16); \ 591 M5 = sph_dec32be_aligned(buf + 20); \ 592 M6 = sph_dec32be_aligned(buf + 24); \ 593 M7 = sph_dec32be_aligned(buf + 28); \ 594 M8 = sph_dec32be_aligned(buf + 32); \ 595 M9 = sph_dec32be_aligned(buf + 36); \ 596 MA = sph_dec32be_aligned(buf + 40); \ 597 MB = sph_dec32be_aligned(buf + 44); \ 598 MC = sph_dec32be_aligned(buf + 48); \ 599 MD = sph_dec32be_aligned(buf + 52); \ 600 ME = sph_dec32be_aligned(buf + 56); \ 601 MF = sph_dec32be_aligned(buf + 60); \ 616 H0 ^= S0 ^ V0 ^ V8; \ 617 H1 ^= S1 ^ V1 ^ V9; \ 618 H2 ^= S2 ^ V2 ^ VA; \ 619 H3 ^= S3 ^ V3 ^ VB; \ 620 H4 ^= S0 ^ V4 ^ VC; \ 621 H5 ^= S1 ^ V5 ^ VD; \ 622 H6 ^= S2 ^ V6 ^ VE; \ 623 H7 ^= S3 ^ V7 ^ VF; \ 630 #define DECL_STATE64 \ 631 sph_u64 H0, H1, H2, H3, H4, H5, H6, H7; \ 632 sph_u64 S0, S1, S2, S3, T0, T1; 634 #define READ_STATE64(state) do { \ 635 H0 = (state)->H[0]; \ 636 H1 = (state)->H[1]; \ 637 H2 = (state)->H[2]; \ 638 H3 = (state)->H[3]; \ 639 H4 = (state)->H[4]; \ 640 H5 = (state)->H[5]; \ 641 H6 = (state)->H[6]; \ 642 H7 = (state)->H[7]; \ 643 S0 = (state)->S[0]; \ 644 S1 = (state)->S[1]; \ 645 S2 = (state)->S[2]; \ 646 S3 = (state)->S[3]; \ 651 #define WRITE_STATE64(state) do { \ 652 (state)->H[0] = H0; \ 653 (state)->H[1] = H1; \ 654 (state)->H[2] = H2; \ 655 (state)->H[3] = H3; \ 656 (state)->H[4] = H4; \ 657 (state)->H[5] = H5; \ 658 (state)->H[6] = H6; \ 659 (state)->H[7] = H7; \ 660 (state)->S[0] = S0; \ 661 (state)->S[1] = S1; \ 662 (state)->S[2] = S2; \ 663 (state)->S[3] = S3; \ 668 #if SPH_COMPACT_BLAKE_64 670 #define COMPRESS64 do { \ 672 sph_u64 V0, V1, V2, V3, V4, V5, V6, V7; \ 673 sph_u64 V8, V9, VA, VB, VC, VD, VE, VF; \ 691 M[0x0] = sph_dec64be_aligned(buf + 0); \ 692 M[0x1] = sph_dec64be_aligned(buf + 8); \ 693 M[0x2] = sph_dec64be_aligned(buf + 16); \ 694 M[0x3] = sph_dec64be_aligned(buf + 24); \ 695 M[0x4] = sph_dec64be_aligned(buf + 32); \ 696 M[0x5] = sph_dec64be_aligned(buf + 40); \ 697 M[0x6] = sph_dec64be_aligned(buf + 48); \ 698 M[0x7] = sph_dec64be_aligned(buf + 56); \ 699 M[0x8] = sph_dec64be_aligned(buf + 64); \ 700 M[0x9] = sph_dec64be_aligned(buf + 72); \ 701 M[0xA] = sph_dec64be_aligned(buf + 80); \ 702 M[0xB] = sph_dec64be_aligned(buf + 88); \ 703 M[0xC] = sph_dec64be_aligned(buf + 96); \ 704 M[0xD] = sph_dec64be_aligned(buf + 104); \ 705 M[0xE] = sph_dec64be_aligned(buf + 112); \ 706 M[0xF] = sph_dec64be_aligned(buf + 120); \ 707 for (r = 0; r < 16; r ++) \ 709 H0 ^= S0 ^ V0 ^ V8; \ 710 H1 ^= S1 ^ V1 ^ V9; \ 711 H2 ^= S2 ^ V2 ^ VA; \ 712 H3 ^= S3 ^ V3 ^ VB; \ 713 H4 ^= S0 ^ V4 ^ VC; \ 714 H5 ^= S1 ^ V5 ^ VD; \ 715 H6 ^= S2 ^ V6 ^ VE; \ 716 H7 ^= S3 ^ V7 ^ VF; \ 721 #define COMPRESS64 do { \ 722 sph_u64 M0, M1, M2, M3, M4, M5, M6, M7; \ 723 sph_u64 M8, M9, MA, MB, MC, MD, ME, MF; \ 724 sph_u64 V0, V1, V2, V3, V4, V5, V6, V7; \ 725 sph_u64 V8, V9, VA, VB, VC, VD, VE, VF; \ 742 M0 = sph_dec64be_aligned(buf + 0); \ 743 M1 = sph_dec64be_aligned(buf + 8); \ 744 M2 = sph_dec64be_aligned(buf + 16); \ 745 M3 = sph_dec64be_aligned(buf + 24); \ 746 M4 = sph_dec64be_aligned(buf + 32); \ 747 M5 = sph_dec64be_aligned(buf + 40); \ 748 M6 = sph_dec64be_aligned(buf + 48); \ 749 M7 = sph_dec64be_aligned(buf + 56); \ 750 M8 = sph_dec64be_aligned(buf + 64); \ 751 M9 = sph_dec64be_aligned(buf + 72); \ 752 MA = sph_dec64be_aligned(buf + 80); \ 753 MB = sph_dec64be_aligned(buf + 88); \ 754 MC = sph_dec64be_aligned(buf + 96); \ 755 MD = sph_dec64be_aligned(buf + 104); \ 756 ME = sph_dec64be_aligned(buf + 112); \ 757 MF = sph_dec64be_aligned(buf + 120); \ 774 H0 ^= S0 ^ V0 ^ V8; \ 775 H1 ^= S1 ^ V1 ^ V9; \ 776 H2 ^= S2 ^ V2 ^ VA; \ 777 H3 ^= S3 ^ V3 ^ VB; \ 778 H4 ^= S0 ^ V4 ^ VC; \ 779 H5 ^= S1 ^ V5 ^ VD; \ 780 H6 ^= S2 ^ V6 ^ VE; \ 781 H7 ^= S3 ^ V7 ^ VF; \ 809 if (len < (
sizeof sc->
buf) - ptr) {
810 memcpy(buf + ptr, data, len);
820 clen = (
sizeof sc->
buf) - ptr;
823 memcpy(buf + ptr, data, clen);
825 data = (
const unsigned char *)data + clen;
827 if (ptr ==
sizeof sc->
buf) {
828 if ((T0 =
SPH_T32(T0 + 512)) < 512)
840 unsigned ub,
unsigned n,
void *dst,
size_t out_size_w32)
843 unsigned char buf[64];
853 bit_len = ((unsigned)ptr << 3) + n;
855 u.buf[ptr] = ((ub & -z) | z) & 0xFF;
856 tl = sc->
T0 + bit_len;
858 if (ptr == 0 && n == 0) {
861 }
else if (sc->
T0 == 0) {
865 sc->
T0 -= 512 - bit_len;
867 if (bit_len <= 446) {
868 memset(u.buf + ptr + 1, 0, 55 - ptr);
869 if (out_size_w32 == 8)
875 memset(u.buf + ptr + 1, 0, 63 - ptr);
879 memset(u.buf, 0, 56);
880 if (out_size_w32 == 8)
887 for (k = 0; k < out_size_w32; k ++)
893 static const sph_u64 salt_zero_big[4] = { 0, 0, 0, 0 };
896 blake64_init(sph_blake_big_context *sc,
897 const sph_u64 *iv,
const sph_u64 *salt)
899 memcpy(sc->H, iv, 8 *
sizeof(sph_u64));
900 memcpy(sc->S, salt, 4 *
sizeof(sph_u64));
906 blake64(sph_blake_big_context *sc,
const void *data,
size_t len)
914 if (len < (
sizeof sc->buf) - ptr) {
915 memcpy(buf + ptr, data, len);
925 clen = (
sizeof sc->buf) - ptr;
928 memcpy(buf + ptr, data, clen);
930 data = (
const unsigned char *)data + clen;
932 if (ptr ==
sizeof sc->buf) {
933 if ((T0 = SPH_T64(T0 + 1024)) < 1024)
934 T1 = SPH_T64(T1 + 1);
944 blake64_close(sph_blake_big_context *sc,
945 unsigned ub,
unsigned n,
void *dst,
size_t out_size_w64)
948 unsigned char buf[128];
958 bit_len = ((unsigned)ptr << 3) + n;
960 u.buf[ptr] = ((ub & -z) | z) & 0xFF;
961 tl = sc->T0 + bit_len;
963 if (ptr == 0 && n == 0) {
964 sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00);
965 sc->T1 = SPH_C64(0xFFFFFFFFFFFFFFFF);
966 }
else if (sc->T0 == 0) {
967 sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00) + bit_len;
968 sc->T1 = SPH_T64(sc->T1 - 1);
970 sc->T0 -= 1024 - bit_len;
972 if (bit_len <= 894) {
973 memset(u.buf + ptr + 1, 0, 111 - ptr);
974 if (out_size_w64 == 8)
976 sph_enc64be_aligned(u.buf + 112, th);
977 sph_enc64be_aligned(u.buf + 120, tl);
978 blake64(sc, u.buf + ptr, 128 - ptr);
980 memset(u.buf + ptr + 1, 0, 127 - ptr);
981 blake64(sc, u.buf + ptr, 128 - ptr);
982 sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00);
983 sc->T1 = SPH_C64(0xFFFFFFFFFFFFFFFF);
984 memset(u.buf, 0, 112);
985 if (out_size_w64 == 8)
987 sph_enc64be_aligned(u.buf + 112, th);
988 sph_enc64be_aligned(u.buf + 120, tl);
989 blake64(sc, u.buf, 128);
992 for (k = 0; k < out_size_w64; k ++)
993 sph_enc64be(out + (k << 3), sc->H[k]);
1060 sph_blake384_init(
void *cc)
1062 blake64_init(cc,
IV384, salt_zero_big);
1067 sph_blake384(
void *cc,
const void *data,
size_t len)
1069 blake64(cc, data, len);
1074 sph_blake384_close(
void *cc,
void *dst)
1076 sph_blake384_addbits_and_close(cc, 0, 0, dst);
1081 sph_blake384_addbits_and_close(
void *cc,
unsigned ub,
unsigned n,
void *dst)
1083 blake64_close(cc, ub, n, dst, 6);
1084 sph_blake384_init(cc);
1089 sph_blake512_init(
void *cc)
1091 blake64_init(cc,
IV512, salt_zero_big);
1096 sph_blake512(
void *cc,
const void *data,
size_t len)
1098 blake64(cc, data, len);
1103 sph_blake512_close(
void *cc,
void *dst)
1105 sph_blake512_addbits_and_close(cc, 0, 0, dst);
1110 sph_blake512_addbits_and_close(
void *cc,
unsigned ub,
unsigned n,
void *dst)
1112 blake64_close(cc, ub, n, dst, 8);
1113 sph_blake512_init(cc);
static const unsigned char sigma[]
static const sph_u32 IV224[8]
This structure is a context for BLAKE-224 and BLAKE-256 computations: it contains the intermediate va...
void sph_blake256_close(void *cc, void *dst)
Terminate the current BLAKE-256 computation and output the result into the provided buffer...
static const sph_u32 IV384[]
#define READ_STATE32(state)
void sph_blake256_init(void *cc)
Initialize a BLAKE-256 context.
void sph_blake224(void *cc, const void *data, size_t len)
Process some data bytes.
#define WRITE_STATE32(state)
static const sph_u32 IV256[8]
static void blake32_init(sph_blake_small_context *sc, const sph_u32 *iv, const sph_u32 *salt)
static void blake32_close(sph_blake_small_context *sc, unsigned ub, unsigned n, void *dst, size_t out_size_w32)
void sph_blake256_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_blake224_close(void *cc, void *dst)
Terminate the current BLAKE-224 computation and output the result into the provided buffer...
void sph_blake224_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...
static const sph_u32 IV512[]
static const sph_u32 salt_zero_small[4]
static SPH_INLINE void sph_enc32be_aligned(void *dst, sph_u32 val)
Encode a 32-bit value into the provided buffer (big endian convention).
static SPH_INLINE void sph_enc32be(void *dst, sph_u32 val)
Encode a 32-bit value into the provided buffer (big endian convention).
void * memcpy(void *a, const void *b, size_t c)
void sph_blake256(void *cc, const void *data, size_t len)
Process some data bytes.
static void blake32(sph_blake_small_context *sc, const void *data, size_t len)
void sph_blake224_init(void *cc)
Initialize a BLAKE-224 context.