Example #1
0
HashReturn hash_echo(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval)
{
	HashReturn hRet;
	hashState_echo hs;

	/////
	/*
	__m128i a, b, c, d, t[4], u[4], v[4];

	a = _mm_set_epi32(0x0f0e0d0c, 0x0b0a0908, 0x07060504, 0x03020100);
	b = _mm_set_epi32(0x1f1e1d1c, 0x1b1a1918, 0x17161514, 0x13121110);
	c = _mm_set_epi32(0x2f2e2d2c, 0x2b2a2928, 0x27262524, 0x23222120);
	d = _mm_set_epi32(0x3f3e3d3c, 0x3b3a3938, 0x37363534, 0x33323130);

	t[0] = _mm_unpacklo_epi8(a, b);
	t[1] = _mm_unpackhi_epi8(a, b);
	t[2] = _mm_unpacklo_epi8(c, d);
	t[3] = _mm_unpackhi_epi8(c, d);

	u[0] = _mm_unpacklo_epi16(t[0], t[2]);
	u[1] = _mm_unpackhi_epi16(t[0], t[2]);
	u[2] = _mm_unpacklo_epi16(t[1], t[3]);
	u[3] = _mm_unpackhi_epi16(t[1], t[3]);


	t[0] = _mm_unpacklo_epi16(u[0], u[1]);
	t[1] = _mm_unpackhi_epi16(u[0], u[1]);
	t[2] = _mm_unpacklo_epi16(u[2], u[3]);
	t[3] = _mm_unpackhi_epi16(u[2], u[3]);

	u[0] = _mm_unpacklo_epi8(t[0], t[1]);
	u[1] = _mm_unpackhi_epi8(t[0], t[1]);
	u[2] = _mm_unpacklo_epi8(t[2], t[3]);
	u[3] = _mm_unpackhi_epi8(t[2], t[3]);

	a = _mm_unpacklo_epi8(u[0], u[1]);
	b = _mm_unpackhi_epi8(u[0], u[1]);
	c = _mm_unpacklo_epi8(u[2], u[3]);
	d = _mm_unpackhi_epi8(u[2], u[3]);
	*/
	/////

	hRet = init_echo(&hs, hashbitlen);
	if(hRet != SUCCESS)
		return hRet;

	hRet = update_echo(&hs, data, databitlen);
	if(hRet != SUCCESS)
		return hRet;

	hRet = final_echo(&hs, hashval);
	if(hRet != SUCCESS)
		return hRet;

	return SUCCESS;
}
Example #2
0
void qubithash(void *output, const void *input)
{
        unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
        #define hashB hash+64

        qubit_ctx_holder ctx;
        memcpy( &ctx, &qubit_ctx, sizeof(qubit_ctx) );

#ifdef LUFFA_SSE2_BROKEN
        sph_luffa512 (&ctx.luffa, input, 80);
        sph_luffa512_close(&ctx.luffa, (void*) hash);
#else
//        init_luffa(&qubit_ctx.luffa,512);
        update_luffa( &ctx.luffa, (const BitSequence*)input, 80 );
        final_luffa( &ctx.luffa, (BitSequence*)hash);
#endif

        cubehashUpdate( &ctx.cubehash, (const byte*) hash,64);
        cubehashDigest( &ctx.cubehash, (byte*)hash);

        sph_shavite512( &ctx.shavite, hash, 64);
        sph_shavite512_close( &ctx.shavite, hash);

        update_sd( &ctx.simd, (const BitSequence *)hash,512);
        final_sd( &ctx.simd, (BitSequence *)hash);

#ifdef NO_AES_NI
        sph_echo512 (&ctx.echo, (const void*) hash, 64);
        sph_echo512_close(&ctx.echo, (void*) hash);
#else
        update_echo ( &ctx.echo, (const BitSequence *) hash, 512);
        final_echo( &ctx.echo, (BitSequence *) hash);
#endif

        asm volatile ("emms");
        memcpy(output, hash, 32);
}
Example #3
0
static void x14hash(void *output, const void *input)
{
	unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
	#define hashB hash+64

        x14_ctx_holder ctx;
        memcpy(&ctx, &x14_ctx, sizeof(x14_ctx));

#ifdef NO_AES_NI
      grsoState sts_grs;
#endif

        unsigned char hashbuf[128];
        size_t hashptr;
        sph_u64 hashctA;
        sph_u64 hashctB;

        //---blake1---
        
        DECL_BLK;
        BLK_I;
        BLK_W;
        BLK_C;

        //---bmw2---

        DECL_BMW;
        BMW_I;
        BMW_U;

        #define M(x)    sph_dec64le_aligned(data + 8 * (x))
        #define H(x)    (h[x])
        #define dH(x)   (dh[x])

        BMW_C;

        #undef M
        #undef H
        #undef dH

        //---groestl----

#ifdef NO_AES_NI
// use SSE2 optimized GRS if possible
         GRS_I;
         GRS_U;
         GRS_C;
//        sph_groestl512 (&ctx.groestl, hash, 64);
//        sph_groestl512_close(&ctx.groestl, hash);
#else
        update_groestl( &ctx.groestl, (char*)hash,512);
        final_groestl( &ctx.groestl, (char*)hash);
#endif

        //---skein4---

        DECL_SKN;
        SKN_I;
        SKN_U;
        SKN_C;

        //---jh5------

        DECL_JH;
        JH_H;

        //---keccak6---

        DECL_KEC;
        KEC_I;
        KEC_U;
        KEC_C;

        //--- luffa7
        update_luffa( &ctx.luffa, (const BitSequence*)hash,512);
        final_luffa( &ctx.luffa, (BitSequence*)hashB);

        // 8 Cube
        cubehashUpdate( &ctx.cubehash, (const byte*) hashB,64);
        cubehashDigest( &ctx.cubehash, (byte*)hash);

        // 9 Shavite
        sph_shavite512( &ctx.shavite, hash, 64);
        sph_shavite512_close( &ctx.shavite, hashB);

        // 10 Simd
        update_sd( &ctx.simd, (const BitSequence *)hashB,512);
        final_sd( &ctx.simd, (BitSequence *)hash);

        //11---echo---

#ifdef NO_AES_NI
        sph_echo512(&ctx.echo, hash, 64);
        sph_echo512_close(&ctx.echo, hashB);
#else
        update_echo ( &ctx.echo, (const BitSequence *) hash, 512);
        final_echo( &ctx.echo, (BitSequence *) hashB);
#endif

        // X13 algos

        // 12 Hamsi
        sph_hamsi512(&ctx.hamsi, hashB, 64);
        sph_hamsi512_close(&ctx.hamsi, hash);

        // 13 Fugue
        sph_fugue512(&ctx.fugue, hash, 64);
        sph_fugue512_close(&ctx.fugue, hashB);

        // X14 Shabal
	sph_shabal512(&ctx.shabal, hashB, 64);
	sph_shabal512_close(&ctx.shabal, hash);


        asm volatile ("emms");
	memcpy(output, hash, 32);
}
inline void Xhash(void *state, const void *input)
{
	Xhash_context_holder ctx;

//	uint32_t hashA[16], hashB[16];


	memcpy(&ctx, &base_contexts, sizeof(base_contexts));
	#ifdef AES_NI_GR
	init_groestl(&ctx.groestl);
	#endif

	DATA_ALIGNXY(unsigned char hashbuf[128],16);
	size_t hashptr;
	DATA_ALIGNXY(sph_u64 hashctA,8);
	DATA_ALIGNXY(sph_u64 hashctB,8);

	#ifndef AES_NI_GR
	grsoState sts_grs;
	#endif


	DATA_ALIGNXY(unsigned char hash[128],16);
	/* proably not needed */
	memset(hash, 0, 128);
	//blake1-bmw2-grs3-skein4-jh5-keccak6-luffa7-cubehash8-shavite9-simd10-echo11
	//---blake1---
/*	  //blake init
	blake512_init(&base_contexts.blake1, 512);
	blake512_update(&ctx.blake1, input, 512);
	blake512_final(&ctx.blake1, hash);
*/
	DECL_BLK;
	BLK_I;
	BLK_W;
	BLK_C;

	//---bmw2---
	DECL_BMW;
	BMW_I;
	BMW_U;
	#define M(x)    sph_dec64le_aligned(data + 8 * (x))
	#define H(x)    (h[x])
	#define dH(x)   (dh[x])
        BMW_C;
	#undef M
	#undef H
	#undef dH
	//---grs3----

	#ifdef AES_NI_GR
	update_groestl(&ctx.groestl, (char*)hash,512);
	final_groestl(&ctx.groestl, (char*)hash);
	#else
	GRS_I;
	GRS_U;
	GRS_C;
	#endif
	//---skein4---
	DECL_SKN;
	SKN_I;
	SKN_U;
	SKN_C;
	//---jh5------
	DECL_JH;
	JH_H;
	//---keccak6---
	DECL_KEC;
	KEC_I;
	KEC_U;
	KEC_C;

//	asm volatile ("emms");
	//--- luffa7
	update_luffa(&ctx.luffa,(const BitSequence*)hash,512);
	final_luffa(&ctx.luffa,(BitSequence*)hash+64);
	//---cubehash---
	cubehashUpdate(&ctx.cubehash,(const byte*) hash+64,64);
	cubehashDigest(&ctx.cubehash,(byte*)hash);
	//---shavite---
	sph_shavite512 (&ctx.shavite1, hash, 64);
	sph_shavite512_close(&ctx.shavite1, hash+64);
	//sph_simd512 (&ctx.simd1, hashA, 64);
	// sph_simd512_close(&ctx.simd1, hashB);
	//-------simd512 vect128 --------------
	update_sd(&ctx.ctx_simd1,(const BitSequence *)hash+64,512);
	final_sd(&ctx.ctx_simd1,(BitSequence *)hash);
	//---echo---
	#ifdef AES_NI
	update_echo (&ctx.echo1,(const BitSequence *) hash, 512);
	final_echo(&ctx.echo1, (BitSequence *) hash+64);
	#else
	sph_echo512 (&ctx.echo1, hash, 64);
	sph_echo512_close(&ctx.echo1, hash+64);
	#endif

	memcpy(state, hash+64, 32);
}