42 #if SPH_SMALL_FOOTPRINT && !defined SPH_SMALL_FOOTPRINT_SHAVITE 43 #define SPH_SMALL_FOOTPRINT_SHAVITE 1 47 #pragma warning (disable: 4146) 64 #define AES_BIG_ENDIAN 0 68 C32(0x6774F31C),
C32(0x990AE210),
C32(0xC87D4274),
C32(0xC9546371),
69 C32(0x62B2AEA8),
C32(0x4B5801D8),
C32(0x1B702860),
C32(0x842F3017)
73 C32(0x49BB3E47),
C32(0x2674860D),
C32(0xA8B392AC),
C32(0x021AC4E6),
74 C32(0x409283CF),
C32(0x620E5D86),
C32(0x6D929DCB),
C32(0x96CC2A8B)
78 C32(0x83DF1545),
C32(0xF9AAEC13),
C32(0xF4803CB0),
C32(0x11FE1F47),
79 C32(0xDA6CD269),
C32(0x4F53FCD7),
C32(0x950529A2),
C32(0x97908147),
80 C32(0xB0A4D7AF),
C32(0x2B9132BF),
C32(0x226E607D),
C32(0x3C0F8D7C),
81 C32(0x487B3F0F),
C32(0x04363E22),
C32(0x0155C99C),
C32(0xEC2E20D3)
85 C32(0x72FCCDD8),
C32(0x79CA4727),
C32(0x128A077B),
C32(0x40D55AEC),
86 C32(0xD1901A06),
C32(0x430AE307),
C32(0xB29F5CD1),
C32(0xDF07FBFC),
87 C32(0x8E45D73D),
C32(0x681AB538),
C32(0xBDE86578),
C32(0xDD577E47),
88 C32(0xE275EADE),
C32(0x502D9FCD),
C32(0xB9357178),
C32(0x022A4B9A)
91 #define AES_ROUND_NOKEY(x0, x1, x2, x3) do { \ 96 AES_ROUND_NOKEY_LE(t0, t1, t2, t3, x0, x1, x2, x3); \ 141 #define KEY_EXPAND_ELT(k0, k1, k2, k3) do { \ 143 AES_ROUND_NOKEY(k1, k2, k3, k0); \ 151 #if SPH_SMALL_FOOTPRINT_SHAVITE 159 sph_u32 p0, p1, p2, p3, p4, p5, p6, p7;
164 #if SPH_LITTLE_ENDIAN 167 for (u = 0; u < 16; u += 4) {
169 (
const unsigned char *)msg + (u << 2) + 0);
171 (
const unsigned char *)msg + (u << 2) + 4);
173 (
const unsigned char *)msg + (u << 2) + 8);
175 (
const unsigned char *)msg + (u << 2) + 12);
179 for (r = 0; r < 4; r ++) {
180 for (s = 0; s < 2; s ++) {
188 rk[u + 0] = x0 ^ rk[u - 4];
189 rk[u + 1] = x1 ^ rk[u - 3];
190 rk[u + 2] = x2 ^ rk[u - 2];
191 rk[u + 3] = x3 ^ rk[u - 1];
195 }
else if (u == 56) {
206 rk[u + 0] = x0 ^ rk[u - 4];
207 rk[u + 1] = x1 ^ rk[u - 3];
208 rk[u + 2] = x2 ^ rk[u - 2];
209 rk[u + 3] = x3 ^ rk[u - 1];
213 }
else if (u == 124) {
219 for (s = 0; s < 4; s ++) {
220 rk[u + 0] = rk[u - 16] ^ rk[u - 3];
221 rk[u + 1] = rk[u - 15] ^ rk[u - 2];
222 rk[u + 2] = rk[u - 14] ^ rk[u - 1];
223 rk[u + 3] = rk[u - 13] ^ rk[u - 0];
237 for (r = 0; r < 6; r ++) {
298 sph_u32 p0, p1, p2, p3, p4, p5, p6, p7;
300 sph_u32 rk0, rk1, rk2, rk3, rk4, rk5, rk6, rk7;
301 sph_u32 rk8, rk9, rkA, rkB, rkC, rkD, rkE, rkF;
723 #if SPH_SMALL_FOOTPRINT_SHAVITE 731 sph_u32 p0, p1, p2, p3, p4, p5, p6, p7;
732 sph_u32 p8, p9, pA, pB, pC, pD, pE, pF;
737 #if SPH_LITTLE_ENDIAN 740 for (u = 0; u < 32; u += 4) {
742 (
const unsigned char *)msg + (u << 2) + 0);
744 (
const unsigned char *)msg + (u << 2) + 4);
746 (
const unsigned char *)msg + (u << 2) + 8);
748 (
const unsigned char *)msg + (u << 2) + 12);
753 for (s = 0; s < 4; s ++) {
761 rk[u + 0] = x0 ^ rk[u - 4];
762 rk[u + 1] = x1 ^ rk[u - 3];
763 rk[u + 2] = x2 ^ rk[u - 2];
764 rk[u + 3] = x3 ^ rk[u - 1];
770 }
else if (u == 440) {
783 rk[u + 0] = x0 ^ rk[u - 4];
784 rk[u + 1] = x1 ^ rk[u - 3];
785 rk[u + 2] = x2 ^ rk[u - 2];
786 rk[u + 3] = x3 ^ rk[u - 1];
792 }
else if (u == 316) {
802 for (s = 0; s < 8; s ++) {
803 rk[u + 0] = rk[u - 32] ^ rk[u - 7];
804 rk[u + 1] = rk[u - 31] ^ rk[u - 6];
805 rk[u + 2] = rk[u - 30] ^ rk[u - 5];
806 rk[u + 3] = rk[u - 29] ^ rk[u - 4];
828 for (r = 0; r < 14; r ++) {
829 #define C512_ELT(l0, l1, l2, l3, r0, r1, r2, r3) do { \ 830 sph_u32 x0, x1, x2, x3; \ 831 x0 = r0 ^ rk[u ++]; \ 832 x1 = r1 ^ rk[u ++]; \ 833 x2 = r2 ^ rk[u ++]; \ 834 x3 = r3 ^ rk[u ++]; \ 835 AES_ROUND_NOKEY(x0, x1, x2, x3); \ 840 AES_ROUND_NOKEY(x0, x1, x2, x3); \ 845 AES_ROUND_NOKEY(x0, x1, x2, x3); \ 850 AES_ROUND_NOKEY(x0, x1, x2, x3); \ 857 #define WROT(a, b, c, d) do { \ 865 C512_ELT(p0, p1, p2, p3, p4, p5, p6, p7);
866 C512_ELT(p8, p9, pA, pB, pC, pD, pE, pF);
868 WROT(p0, p4, p8, pC);
869 WROT(p1, p5, p9, pD);
870 WROT(p2, p6, pA, pE);
871 WROT(p3, p7, pB, pF);
902 sph_u32 p0, p1, p2, p3, p4, p5, p6, p7;
903 sph_u32 p8, p9, pA, pB, pC, pD, pE, pF;
905 sph_u32 rk00, rk01, rk02, rk03, rk04, rk05, rk06, rk07;
906 sph_u32 rk08, rk09, rk0A, rk0B, rk0C, rk0D, rk0E, rk0F;
907 sph_u32 rk10, rk11, rk12, rk13, rk14, rk15, rk16, rk17;
908 sph_u32 rk18, rk19, rk1A, rk1B, rk1C, rk1D, rk1E, rk1F;
1009 for (r = 0; r < 3; r ++) {
1435 rk18 ^= rk14 ^ sc->
count1;
1436 rk19 ^= rk15 ^ sc->
count0;
1437 rk1A ^= rk16 ^ sc->
count3;
1498 clen = (
sizeof sc->
buf) - ptr;
1501 memcpy(buf + ptr, data, clen);
1502 data = (
const unsigned char *)data + clen;
1505 if (ptr ==
sizeof sc->
buf) {
1517 unsigned ub,
unsigned n,
void *dst,
size_t out_size_w32)
1526 count0 = (sc->
count0 += (ptr << 3) + n);
1529 z = ((ub & -z) | z) & 0xFF;
1530 if (ptr == 0 && n == 0) {
1532 memset(buf + 1, 0, 53);
1534 }
else if (ptr < 54) {
1536 memset(buf + ptr, 0, 54 - ptr);
1539 memset(buf + ptr, 0, 64 - ptr);
1546 buf[62] = out_size_w32 << 5;
1547 buf[63] = out_size_w32 >> 3;
1549 for (u = 0; u < out_size_w32; u ++)
1550 sph_enc32le((
unsigned char *)dst + (u << 2), sc->
h[u]);
1575 clen = (
sizeof sc->
buf) - ptr;
1578 memcpy(buf + ptr, data, clen);
1579 data = (
const unsigned char *)data + clen;
1582 if (ptr ==
sizeof sc->
buf) {
1602 unsigned ub,
unsigned n,
void *dst,
size_t out_size_w32)
1607 sph_u32 count0, count1, count2, count3;
1611 count0 = (sc->
count0 += (ptr << 3) + n);
1616 z = ((ub & -z) | z) & 0xFF;
1617 if (ptr == 0 && n == 0) {
1619 memset(buf + 1, 0, 109);
1621 }
else if (ptr < 110) {
1623 memset(buf + ptr, 0, 110 - ptr);
1626 memset(buf + ptr, 0, 128 - ptr);
1628 memset(buf, 0, 110);
1635 buf[126] = out_size_w32 << 5;
1636 buf[127] = out_size_w32 >> 3;
1638 for (u = 0; u < out_size_w32; u ++)
1639 sph_enc32le((
unsigned char *)dst + (u << 2), sc->
h[u]);
static void shavite_big_core(sph_shavite_big_context *sc, const void *data, size_t len)
#define AES_ROUND_NOKEY(x0, x1, x2, x3)
static void c512(sph_shavite_big_context *sc, const void *msg)
void sph_shavite512_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 void shavite_big_init(sph_shavite_big_context *sc, const sph_u32 *iv)
void sph_shavite224_close(void *cc, void *dst)
Terminate the current SHAvite-224 computation and output the result into the provided buffer...
This structure is a context for SHAvite-384 and SHAvite-512 computations: it contains the intermediat...
void sph_shavite256_init(void *cc)
Initialize a SHAvite-256 context.
void sph_shavite384_init(void *cc)
Initialize a SHAvite-384 context.
#define KEY_EXPAND_ELT(k0, k1, k2, k3)
static void shavite_big_close(sph_shavite_big_context *sc, unsigned ub, unsigned n, void *dst, size_t out_size_w32)
static SPH_INLINE sph_u32 sph_dec32le_aligned(const void *src)
Decode a 32-bit value from the provided buffer (little endian convention).
This structure is a context for SHAvite-224 and SHAvite-256 computations: it contains the intermediat...
static const sph_u32 IV224[]
static void shavite_small_init(sph_shavite_small_context *sc, const sph_u32 *iv)
void sph_shavite512_init(void *cc)
Initialize a SHAvite-512 context.
void sph_shavite224_init(void *cc)
Initialize a SHAvite-224 context.
void sph_shavite256_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 IV256[]
static const sph_u32 IV512[]
static SPH_INLINE void sph_enc32le(void *dst, sph_u32 val)
Encode a 32-bit value into the provided buffer (little endian convention).
void sph_shavite512(void *cc, const void *data, size_t len)
Process some data bytes.
static const sph_u32 IV384[]
void sph_shavite256_close(void *cc, void *dst)
Terminate the current SHAvite-256 computation and output the result into the provided buffer...
void sph_shavite224_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 * memcpy(void *a, const void *b, size_t c)
void sph_shavite512_close(void *cc, void *dst)
Terminate the current SHAvite-512 computation and output the result into the provided buffer...
void sph_shavite384_close(void *cc, void *dst)
Terminate the current SHAvite-384 computation and output the result into the provided buffer...
static void shavite_small_close(sph_shavite_small_context *sc, unsigned ub, unsigned n, void *dst, size_t out_size_w32)
void sph_shavite256(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_shavite384_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 void c256(sph_shavite_small_context *sc, const void *msg)
void sph_shavite384(void *cc, const void *data, size_t len)
Process some data bytes.
static void shavite_small_core(sph_shavite_small_context *sc, const void *data, size_t len)
void sph_shavite224(void *cc, const void *data, size_t len)
Process some data bytes.