static void bmw32_close(sph_bmw_small_context *sc, unsigned ub, unsigned n, void *dst, size_t out_size_w32) { unsigned char *buf, *out; size_t ptr, u, v; unsigned z; sph_u32 h1[16], h2[16], *h; buf = sc->buf; ptr = sc->ptr; z = 0x80 >> n; buf[ptr ++] = ((ub & -z) | z) & 0xFF; h = sc->H; if (ptr > (sizeof sc->buf) - 8) { memset(buf + ptr, 0, (sizeof sc->buf) - ptr); compress_small(buf, h, h1); ptr = 0; h = h1; } memset(buf + ptr, 0, (sizeof sc->buf) - 8 - ptr); #if SPH_64 sph_enc64le_aligned(buf + (sizeof sc->buf) - 8, SPH_T64(sc->bit_count + n)); #else sph_enc32le_aligned(buf + (sizeof sc->buf) - 8, sc->bit_count_low + n); sph_enc32le_aligned(buf + (sizeof sc->buf) - 4, SPH_T32(sc->bit_count_high)); #endif compress_small(buf, h, h2); for (u = 0; u < 16; u ++) sph_enc32le_aligned(buf + 4 * u, h2[u]); compress_small(buf, final_s, h1); out = dst; for (u = 0, v = 16 - out_size_w32; u < out_size_w32; u ++, v ++) sph_enc32le(out + 4 * u, h1[v]); }
static void shabal_close(void *cc, unsigned ub, unsigned n, void *dst, unsigned size_words) { sph_shabal_context *sc; unsigned char *buf; size_t ptr; int i; unsigned z; union { unsigned char tmp_out[64]; sph_u32 dummy; } u; size_t out_len; DECL_STATE sc = cc; buf = sc->buf; ptr = sc->ptr; z = 0x80 >> n; buf[ptr] = ((ub & -z) | z) & 0xFF; memset(buf + ptr + 1, 0, (sizeof sc->buf) - (ptr + 1)); READ_STATE(sc); DECODE_BLOCK; INPUT_BLOCK_ADD; XOR_W; APPLY_P; for (i = 0; i < 3; i ++) { SWAP_BC; XOR_W; APPLY_P; } /* * We just use our local variables; no need to go through * the state structure. In order to share some code, we * emit the relevant words into a temporary buffer, which * we finally copy into the destination array. */ switch (size_words) { case 16: sph_enc32le_aligned(u.tmp_out + 0, B0); sph_enc32le_aligned(u.tmp_out + 4, B1); sph_enc32le_aligned(u.tmp_out + 8, B2); sph_enc32le_aligned(u.tmp_out + 12, B3); /* fall through */ case 12: sph_enc32le_aligned(u.tmp_out + 16, B4); sph_enc32le_aligned(u.tmp_out + 20, B5); sph_enc32le_aligned(u.tmp_out + 24, B6); sph_enc32le_aligned(u.tmp_out + 28, B7); /* fall through */ case 8: sph_enc32le_aligned(u.tmp_out + 32, B8); /* fall through */ case 7: sph_enc32le_aligned(u.tmp_out + 36, B9); /* fall through */ case 6: sph_enc32le_aligned(u.tmp_out + 40, BA); sph_enc32le_aligned(u.tmp_out + 44, BB); sph_enc32le_aligned(u.tmp_out + 48, BC); sph_enc32le_aligned(u.tmp_out + 52, BD); sph_enc32le_aligned(u.tmp_out + 56, BE); sph_enc32le_aligned(u.tmp_out + 60, BF); break; default: return; } out_len = size_words << 2; memcpy(dst, u.tmp_out + (sizeof u.tmp_out) - out_len, out_len); shabal_init(sc, size_words << 5); }
static void test_types32(void) { unsigned i; union { unsigned char bytes[64]; sph_u32 v32; } u; #if SPH_LITTLE_ENDIAN || SPH_BIG_ENDIAN ASSERT(sizeof(sph_u32) == 4); #else ASSERT(sizeof(sph_u32) >= 4); #endif for (i = 0; i < sizeof u.bytes; i ++) u.bytes[i] = i; for (i = 0; (i + 3) < sizeof u.bytes; i ++) { sph_u32 v, w; v = ((sph_u32)i << 24) | ((sph_u32)(i + 1) << 16) | ((sph_u32)(i + 2) << 8) | (sph_u32)(i + 3); w = ((sph_u32)(i + 3) << 24) | ((sph_u32)(i + 2) << 16) | ((sph_u32)(i + 1) << 8) | (sph_u32)i; ASSERT(sph_dec32be(u.bytes + i) == v); ASSERT(sph_dec32le(u.bytes + i) == w); if (i % 4 == 0) { ASSERT(sph_dec32be_aligned(u.bytes + i) == v); ASSERT(sph_dec32le_aligned(u.bytes + i) == w); } } memset(u.bytes, 0, sizeof u.bytes); for (i = 0; (i + 3) < sizeof u.bytes; i ++) { sph_u32 v, w; v = ((sph_u32)i << 24) | ((sph_u32)(i + 1) << 16) | ((sph_u32)(i + 2) << 8) | (sph_u32)(i + 3); w = ((sph_u32)(i + 3) << 24) | ((sph_u32)(i + 2) << 16) | ((sph_u32)(i + 1) << 8) | (sph_u32)i; if (i % 4 == 0) { sph_enc32be_aligned(u.bytes + i, v); } else { sph_enc32be(u.bytes + i, v); } ASSERT(u.bytes[i + 0] == i + 0); ASSERT(u.bytes[i + 1] == i + 1); ASSERT(u.bytes[i + 2] == i + 2); ASSERT(u.bytes[i + 3] == i + 3); memset(u.bytes, 0, sizeof u.bytes); if (i % 4 == 0) { sph_enc32le_aligned(u.bytes + i, w); } else { sph_enc32le(u.bytes + i, w); } ASSERT(u.bytes[i + 0] == i + 0); ASSERT(u.bytes[i + 1] == i + 1); ASSERT(u.bytes[i + 2] == i + 2); ASSERT(u.bytes[i + 3] == i + 3); } }