42 #if SPH_SMALL_FOOTPRINT && !defined SPH_SMALL_FOOTPRINT_CUBEHASH 43 #define SPH_SMALL_FOOTPRINT_CUBEHASH 1 54 #if SPH_SMALL_FOOTPRINT_CUBEHASH 56 #if !defined SPH_CUBEHASH_UNROLL 57 #define SPH_CUBEHASH_UNROLL 4 59 #if !defined SPH_CUBEHASH_NOCOPY 60 #define SPH_CUBEHASH_NOCOPY 1 65 #if !defined SPH_CUBEHASH_UNROLL 66 #define SPH_CUBEHASH_UNROLL 0 68 #if !defined SPH_CUBEHASH_NOCOPY 69 #define SPH_CUBEHASH_NOCOPY 0 75 #pragma warning (disable: 4146) 135 #define ROTL32 SPH_ROTL32 137 #if SPH_CUBEHASH_NOCOPY 140 #define READ_STATE(cc) 141 #define WRITE_STATE(cc) 143 #define x0 ((sc)->state[ 0]) 144 #define x1 ((sc)->state[ 1]) 145 #define x2 ((sc)->state[ 2]) 146 #define x3 ((sc)->state[ 3]) 147 #define x4 ((sc)->state[ 4]) 148 #define x5 ((sc)->state[ 5]) 149 #define x6 ((sc)->state[ 6]) 150 #define x7 ((sc)->state[ 7]) 151 #define x8 ((sc)->state[ 8]) 152 #define x9 ((sc)->state[ 9]) 153 #define xa ((sc)->state[10]) 154 #define xb ((sc)->state[11]) 155 #define xc ((sc)->state[12]) 156 #define xd ((sc)->state[13]) 157 #define xe ((sc)->state[14]) 158 #define xf ((sc)->state[15]) 159 #define xg ((sc)->state[16]) 160 #define xh ((sc)->state[17]) 161 #define xi ((sc)->state[18]) 162 #define xj ((sc)->state[19]) 163 #define xk ((sc)->state[20]) 164 #define xl ((sc)->state[21]) 165 #define xm ((sc)->state[22]) 166 #define xn ((sc)->state[23]) 167 #define xo ((sc)->state[24]) 168 #define xp ((sc)->state[25]) 169 #define xq ((sc)->state[26]) 170 #define xr ((sc)->state[27]) 171 #define xs ((sc)->state[28]) 172 #define xt ((sc)->state[29]) 173 #define xu ((sc)->state[30]) 174 #define xv ((sc)->state[31]) 179 sph_u32 x0, x1, x2, x3, x4, x5, x6, x7; \ 180 sph_u32 x8, x9, xa, xb, xc, xd, xe, xf; \ 181 sph_u32 xg, xh, xi, xj, xk, xl, xm, xn; \ 182 sph_u32 xo, xp, xq, xr, xs, xt, xu, xv; 184 #define READ_STATE(cc) do { \ 185 x0 = (cc)->state[ 0]; \ 186 x1 = (cc)->state[ 1]; \ 187 x2 = (cc)->state[ 2]; \ 188 x3 = (cc)->state[ 3]; \ 189 x4 = (cc)->state[ 4]; \ 190 x5 = (cc)->state[ 5]; \ 191 x6 = (cc)->state[ 6]; \ 192 x7 = (cc)->state[ 7]; \ 193 x8 = (cc)->state[ 8]; \ 194 x9 = (cc)->state[ 9]; \ 195 xa = (cc)->state[10]; \ 196 xb = (cc)->state[11]; \ 197 xc = (cc)->state[12]; \ 198 xd = (cc)->state[13]; \ 199 xe = (cc)->state[14]; \ 200 xf = (cc)->state[15]; \ 201 xg = (cc)->state[16]; \ 202 xh = (cc)->state[17]; \ 203 xi = (cc)->state[18]; \ 204 xj = (cc)->state[19]; \ 205 xk = (cc)->state[20]; \ 206 xl = (cc)->state[21]; \ 207 xm = (cc)->state[22]; \ 208 xn = (cc)->state[23]; \ 209 xo = (cc)->state[24]; \ 210 xp = (cc)->state[25]; \ 211 xq = (cc)->state[26]; \ 212 xr = (cc)->state[27]; \ 213 xs = (cc)->state[28]; \ 214 xt = (cc)->state[29]; \ 215 xu = (cc)->state[30]; \ 216 xv = (cc)->state[31]; \ 219 #define WRITE_STATE(cc) do { \ 220 (cc)->state[ 0] = x0; \ 221 (cc)->state[ 1] = x1; \ 222 (cc)->state[ 2] = x2; \ 223 (cc)->state[ 3] = x3; \ 224 (cc)->state[ 4] = x4; \ 225 (cc)->state[ 5] = x5; \ 226 (cc)->state[ 6] = x6; \ 227 (cc)->state[ 7] = x7; \ 228 (cc)->state[ 8] = x8; \ 229 (cc)->state[ 9] = x9; \ 230 (cc)->state[10] = xa; \ 231 (cc)->state[11] = xb; \ 232 (cc)->state[12] = xc; \ 233 (cc)->state[13] = xd; \ 234 (cc)->state[14] = xe; \ 235 (cc)->state[15] = xf; \ 236 (cc)->state[16] = xg; \ 237 (cc)->state[17] = xh; \ 238 (cc)->state[18] = xi; \ 239 (cc)->state[19] = xj; \ 240 (cc)->state[20] = xk; \ 241 (cc)->state[21] = xl; \ 242 (cc)->state[22] = xm; \ 243 (cc)->state[23] = xn; \ 244 (cc)->state[24] = xo; \ 245 (cc)->state[25] = xp; \ 246 (cc)->state[26] = xq; \ 247 (cc)->state[27] = xr; \ 248 (cc)->state[28] = xs; \ 249 (cc)->state[29] = xt; \ 250 (cc)->state[30] = xu; \ 251 (cc)->state[31] = xv; \ 256 #define INPUT_BLOCK do { \ 257 x0 ^= sph_dec32le_aligned(buf + 0); \ 258 x1 ^= sph_dec32le_aligned(buf + 4); \ 259 x2 ^= sph_dec32le_aligned(buf + 8); \ 260 x3 ^= sph_dec32le_aligned(buf + 12); \ 261 x4 ^= sph_dec32le_aligned(buf + 16); \ 262 x5 ^= sph_dec32le_aligned(buf + 20); \ 263 x6 ^= sph_dec32le_aligned(buf + 24); \ 264 x7 ^= sph_dec32le_aligned(buf + 28); \ 267 #define ROUND_EVEN do { \ 269 x0 = ROTL32(x0, 7); \ 271 x1 = ROTL32(x1, 7); \ 273 x2 = ROTL32(x2, 7); \ 275 x3 = ROTL32(x3, 7); \ 277 x4 = ROTL32(x4, 7); \ 279 x5 = ROTL32(x5, 7); \ 281 x6 = ROTL32(x6, 7); \ 283 x7 = ROTL32(x7, 7); \ 285 x8 = ROTL32(x8, 7); \ 287 x9 = ROTL32(x9, 7); \ 289 xa = ROTL32(xa, 7); \ 291 xb = ROTL32(xb, 7); \ 293 xc = ROTL32(xc, 7); \ 295 xd = ROTL32(xd, 7); \ 297 xe = ROTL32(xe, 7); \ 299 xf = ROTL32(xf, 7); \ 317 x8 = ROTL32(x8, 11); \ 319 x9 = ROTL32(x9, 11); \ 321 xa = ROTL32(xa, 11); \ 323 xb = ROTL32(xb, 11); \ 325 xc = ROTL32(xc, 11); \ 327 xd = ROTL32(xd, 11); \ 329 xe = ROTL32(xe, 11); \ 331 xf = ROTL32(xf, 11); \ 333 x0 = ROTL32(x0, 11); \ 335 x1 = ROTL32(x1, 11); \ 337 x2 = ROTL32(x2, 11); \ 339 x3 = ROTL32(x3, 11); \ 341 x4 = ROTL32(x4, 11); \ 343 x5 = ROTL32(x5, 11); \ 345 x6 = ROTL32(x6, 11); \ 347 x7 = ROTL32(x7, 11); \ 366 #define ROUND_ODD do { \ 368 xc = ROTL32(xc, 7); \ 370 xd = ROTL32(xd, 7); \ 372 xe = ROTL32(xe, 7); \ 374 xf = ROTL32(xf, 7); \ 376 x8 = ROTL32(x8, 7); \ 378 x9 = ROTL32(x9, 7); \ 380 xa = ROTL32(xa, 7); \ 382 xb = ROTL32(xb, 7); \ 384 x4 = ROTL32(x4, 7); \ 386 x5 = ROTL32(x5, 7); \ 388 x6 = ROTL32(x6, 7); \ 390 x7 = ROTL32(x7, 7); \ 392 x0 = ROTL32(x0, 7); \ 394 x1 = ROTL32(x1, 7); \ 396 x2 = ROTL32(x2, 7); \ 398 x3 = ROTL32(x3, 7); \ 416 x4 = ROTL32(x4, 11); \ 418 x5 = ROTL32(x5, 11); \ 420 x6 = ROTL32(x6, 11); \ 422 x7 = ROTL32(x7, 11); \ 424 x0 = ROTL32(x0, 11); \ 426 x1 = ROTL32(x1, 11); \ 428 x2 = ROTL32(x2, 11); \ 430 x3 = ROTL32(x3, 11); \ 432 xc = ROTL32(xc, 11); \ 434 xd = ROTL32(xd, 11); \ 436 xe = ROTL32(xe, 11); \ 438 xf = ROTL32(xf, 11); \ 440 x8 = ROTL32(x8, 11); \ 442 x9 = ROTL32(x9, 11); \ 444 xa = ROTL32(xa, 11); \ 446 xb = ROTL32(xb, 11); \ 473 #if SPH_CUBEHASH_UNROLL == 2 475 #define SIXTEEN_ROUNDS do { \ 477 for (j = 0; j < 8; j ++) { \ 483 #elif SPH_CUBEHASH_UNROLL == 4 485 #define SIXTEEN_ROUNDS do { \ 487 for (j = 0; j < 4; j ++) { \ 495 #elif SPH_CUBEHASH_UNROLL == 8 497 #define SIXTEEN_ROUNDS do { \ 499 for (j = 0; j < 2; j ++) { \ 513 #define SIXTEEN_ROUNDS do { \ 550 if (len < (
sizeof sc->
buf) - ptr) {
551 memcpy(buf + ptr, data, len);
561 clen = (
sizeof sc->
buf) - ptr;
564 memcpy(buf + ptr, data, clen);
566 data = (
const unsigned char *)data + clen;
568 if (ptr ==
sizeof sc->
buf) {
580 void *dst,
size_t out_size_w32)
582 unsigned char *buf, *out;
591 buf[ptr ++] = ((ub & -z) | z) & 0xFF;
592 memset(buf + ptr, 0, (
sizeof sc->
buf) - ptr);
595 for (i = 0; i < 11; i ++) {
602 for (z = 0; z < out_size_w32; z ++)
void sph_cubehash384_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_cubehash384_close(void *cc, void *dst)
Terminate the current CubeHash-384 computation and output the result into the provided buffer...
void sph_cubehash512_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 IV384[]
void sph_cubehash384(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_cubehash256_init(void *cc)
Initialize a CubeHash-256 context.
void sph_cubehash224_close(void *cc, void *dst)
Terminate the current CubeHash-224 computation and output the result into the provided buffer...
static const sph_u32 IV256[]
static void cubehash_core(sph_cubehash_context *sc, const void *data, size_t len)
void sph_cubehash512(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_cubehash256(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_cubehash256_close(void *cc, void *dst)
Terminate the current CubeHash-256 computation and output the result into the provided buffer...
static void cubehash_close(sph_cubehash_context *sc, unsigned ub, unsigned n, void *dst, size_t out_size_w32)
void sph_cubehash256_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_cubehash512_close(void *cc, void *dst)
Terminate the current CubeHash-512 computation and output the result into the provided buffer...
static SPH_INLINE void sph_enc32le(void *dst, sph_u32 val)
Encode a 32-bit value into the provided buffer (little endian convention).
static const sph_u32 IV224[]
static const sph_u32 IV512[]
void sph_cubehash224(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_cubehash224_init(void *cc)
Initialize a CubeHash-224 context.
void sph_cubehash384_init(void *cc)
Initialize a CubeHash-384 context.
void * memcpy(void *a, const void *b, size_t c)
static void cubehash_init(sph_cubehash_context *sc, const sph_u32 *iv)
void sph_cubehash224_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_cubehash512_init(void *cc)
Initialize a CubeHash-512 context.
This structure is a context for CubeHash computations: it contains the intermediate values and some d...