Exemplo n.º 1
0
static void
cubehash_close(sph_cubehash_context *sc, unsigned ub, unsigned n,
	void *dst, size_t out_size_w32)
{
	unsigned char *buf, *out;
	size_t ptr;
	unsigned z;
	int i;
	DECL_STATE

	buf = sc->buf;
	ptr = sc->ptr;
	z = 0x80 >> n;
	buf[ptr ++] = ((ub & -z) | z) & 0xFF;
	memset(buf + ptr, 0, (sizeof sc->buf) - ptr);
	READ_STATE(sc);
	INPUT_BLOCK;
	for (i = 0; i < 11; i ++) {
		SIXTEEN_ROUNDS;
		if (i == 0)
			xv ^= SPH_C32(1);
	}
	WRITE_STATE(sc);
	out = (unsigned char *)dst;
	for (z = 0; z < out_size_w32; z ++)
		sph_enc32le(out + (z << 2), sc->state[z]);
}
Exemplo n.º 2
0
static void
shavite_big_close(sph_shavite_big_context *sc,
	unsigned ub, unsigned n, void *dst, size_t out_size_w32)
{
	unsigned char *buf;
	size_t ptr, u;
	unsigned z;
	sph_u32 count0, count1, count2, count3;

	buf = sc->buf;
	ptr = sc->ptr;
	count0 = (sc->count0 += (ptr << 3) + n);
	count1 = sc->count1;
	count2 = sc->count2;
	count3 = sc->count3;
	z = 0x80 >> n;
	z = ((ub & -z) | z) & 0xFF;
	if (ptr == 0 && n == 0) {
		buf[0] = 0x80;
		memset(buf + 1, 0, 109);
		sc->count0 = sc->count1 = sc->count2 = sc->count3 = 0;
	} else if (ptr < 110) {
		buf[ptr ++] = z;
		memset(buf + ptr, 0, 110 - ptr);
	} else {
		buf[ptr ++] = z;
		memset(buf + ptr, 0, 128 - ptr);
		c512(sc, buf);
		memset(buf, 0, 110);
		sc->count0 = sc->count1 = sc->count2 = sc->count3 = 0;
	}
	sph_enc32le(buf + 110, count0);
	sph_enc32le(buf + 114, count1);
	sph_enc32le(buf + 118, count2);
	sph_enc32le(buf + 122, count3);
	buf[126] = out_size_w32 << 5;
	buf[127] = out_size_w32 >> 3;
	c512(sc, buf);
	for (u = 0; u < out_size_w32; u ++)
		sph_enc32le((unsigned char *)dst + (u << 2), sc->h[u]);
}
Exemplo n.º 3
0
static void
shavite_small_close(sph_shavite_small_context *sc,
	unsigned ub, unsigned n, void *dst, size_t out_size_w32)
{
	unsigned char *buf;
	size_t ptr, u;
	unsigned z;
	sph_u32 count0, count1;

	buf = sc->buf;
	ptr = sc->ptr;
	count0 = (sc->count0 += (ptr << 3) + n);
	count1 = sc->count1;
	z = 0x80 >> n;
	z = ((ub & -z) | z) & 0xFF;
	if (ptr == 0 && n == 0) {
		buf[0] = 0x80;
		memset(buf + 1, 0, 53);
		sc->count0 = sc->count1 = 0;
	} else if (ptr < 54) {
		buf[ptr ++] = z;
		memset(buf + ptr, 0, 54 - ptr);
	} else {
		buf[ptr ++] = z;
		memset(buf + ptr, 0, 64 - ptr);
		c256(sc, buf);
		memset(buf, 0, 54);
		sc->count0 = sc->count1 = 0;
	}
	sph_enc32le(buf + 54, count0);
	sph_enc32le(buf + 58, count1);
	buf[62] = out_size_w32 << 5;
	buf[63] = out_size_w32 >> 3;
	c256(sc, buf);
	for (u = 0; u < out_size_w32; u ++)
		sph_enc32le((unsigned char *)dst + (u << 2), sc->h[u]);
}
Exemplo n.º 4
0
/* see sph_panama.h */
void
sph_panama_close(void *cc, void *dst)
{
	sph_panama_context *sc;
	unsigned current;
	int i;

	sc = (sph_panama_context *)cc;
	current = sc->data_ptr;
	sc->data[current ++] = 0x01;
	memset(sc->data + current, 0, (sizeof sc->data) - current);
	panama_push(sc, sc->data, 1);
	panama_pull(sc, 32);
	for (i = 0; i < 8; i ++)
		sph_enc32le((unsigned char *)dst + 4 * i, sc->state[i + 9]);
	sph_panama_init(sc);
}
Exemplo n.º 5
0
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]);
}
Exemplo n.º 6
0
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);
	}
}
Exemplo n.º 7
0
/*
 * Write out HAVAL output. The output length is tailored to the requested
 * length.
 */
static void
haval_out(sph_haval_context *sc, void *dst)
{
	DSTATE;
	unsigned char *buf;

	buf = dst;
	RSTATE;
	switch (sc->olen) {
	case 4:
		sph_enc32le(buf,      SPH_T32(s0 + mix128(s7, s4, s5, s6, 24)));
		sph_enc32le(buf + 4,  SPH_T32(s1 + mix128(s6, s7, s4, s5, 16)));
		sph_enc32le(buf + 8,  SPH_T32(s2 + mix128(s5, s6, s7, s4, 8)));
		sph_enc32le(buf + 12, SPH_T32(s3 + mix128(s4, s5, s6, s7, 0)));
		break;
	case 5:
		sph_enc32le(buf,      SPH_T32(s0 + mix160_0(s5, s6, s7)));
		sph_enc32le(buf + 4,  SPH_T32(s1 + mix160_1(s5, s6, s7)));
		sph_enc32le(buf + 8,  SPH_T32(s2 + mix160_2(s5, s6, s7)));
		sph_enc32le(buf + 12, SPH_T32(s3 + mix160_3(s5, s6, s7)));
		sph_enc32le(buf + 16, SPH_T32(s4 + mix160_4(s5, s6, s7)));
		break;
	case 6:
		sph_enc32le(buf,      SPH_T32(s0 + mix192_0(s6, s7)));
		sph_enc32le(buf + 4,  SPH_T32(s1 + mix192_1(s6, s7)));
		sph_enc32le(buf + 8,  SPH_T32(s2 + mix192_2(s6, s7)));
		sph_enc32le(buf + 12, SPH_T32(s3 + mix192_3(s6, s7)));
		sph_enc32le(buf + 16, SPH_T32(s4 + mix192_4(s6, s7)));
		sph_enc32le(buf + 20, SPH_T32(s5 + mix192_5(s6, s7)));
		break;
	case 7:
		sph_enc32le(buf,      SPH_T32(s0 + ((s7 >> 27) & 0x1F)));
		sph_enc32le(buf + 4,  SPH_T32(s1 + ((s7 >> 22) & 0x1F)));
		sph_enc32le(buf + 8,  SPH_T32(s2 + ((s7 >> 18) & 0x0F)));
		sph_enc32le(buf + 12, SPH_T32(s3 + ((s7 >> 13) & 0x1F)));
		sph_enc32le(buf + 16, SPH_T32(s4 + ((s7 >>  9) & 0x0F)));
		sph_enc32le(buf + 20, SPH_T32(s5 + ((s7 >>  4) & 0x1F)));
		sph_enc32le(buf + 24, SPH_T32(s6 + ((s7      ) & 0x0F)));
		break;
	case 8:
		sph_enc32le(buf,      s0);
		sph_enc32le(buf + 4,  s1);
		sph_enc32le(buf + 8,  s2);
		sph_enc32le(buf + 12, s3);
		sph_enc32le(buf + 16, s4);
		sph_enc32le(buf + 20, s5);
		sph_enc32le(buf + 24, s6);
		sph_enc32le(buf + 28, s7);
		break;
	}
}