Exemple #1
0
static inline void HashFunction_Final(hash_ctx *const ctx, unsigned char *const result)
{
	switch(ctx->hashType)
	{
		case STD_HASHTYPE_CRC_32:
			rhash_crc32_final(&ctx->data.crc32, result);
			return;
		case STD_HASHTYPE_MD5_128:
			rhash_md5_final(&ctx->data.md5, result);
			return;
		case STD_HASHTYPE_SHA1_160:
			rhash_sha1_final(&ctx->data.sha1, result);
			return;
		case STD_HASHTYPE_SHA2_224:
		case STD_HASHTYPE_SHA2_256:
			rhash_sha256_final(&ctx->data.sha256, result);
			return;
		case STD_HASHTYPE_SHA2_384:
		case STD_HASHTYPE_SHA2_512:
			rhash_sha512_final(&ctx->data.sha512, result);
			return;
		case STD_HASHTYPE_SHA3_224:
		case STD_HASHTYPE_SHA3_256:
		case STD_HASHTYPE_SHA3_384:
		case STD_HASHTYPE_SHA3_512:
			rhash_sha3_final(&ctx->data.sha3, result);
			return;
		case STD_HASHTYPE_BLK2_224:
		case STD_HASHTYPE_BLK2_256:
		case STD_HASHTYPE_BLK2_384:
		case STD_HASHTYPE_BLK2_512:
			if(blake2b_final(&ctx->data.balke2, result, Blake2_Size(ctx->hashType)) != 0)
			{
				MessageBox(NULL, T("Blake2_Final internal error, going to abort!"), T("StdUtils::HashFunction_Final"), MB_ICONSTOP | MB_TOPMOST);
				abort();
			}
			return;
		default:
			MessageBox(NULL, T("Inconsistent state detected, going to abort!"), T("StdUtils::HashFunction_Final"), MB_ICONSTOP | MB_TOPMOST);
			abort();
	}
}
Exemple #2
0
unsigned char *computeV4(const unsigned char *src, int len)
{
    static unsigned char buf[0x100];
    static unsigned char s[20];
    memcpy(s, src, 16);

    unsigned char wtmp[160];
    int wpos = 0;
    int i;

    uint32_t v4_check_type = ((signed char)s[0] + (signed char)s[3]) % 5u;
    printf("V4 type: %d\n", v4_check_type);
    switch(v4_check_type)
    {
        case 0:
        {
            unsigned char mtmp[16];
            md5_ctx mctx;

            rhash_md5_init(&mctx);
            rhash_md5_update(&mctx, array, 0x71c);
            rhash_md5_final(&mctx, mtmp);
            char tbuf[10];
            for (i=0; i<16; ++i)
            {
                sprintf((char*)wtmp + wpos, "%02x", mtmp[i]);
                wpos += 2;
            }


            for (i=0; i<8; ++i)
            {
                sprintf(tbuf, "%02x", (signed char)(s[2*i]));
                strcpy((char*)wtmp + wpos, tbuf);
                wpos += strlen(tbuf);
            }

            rhash_md5_init(&mctx);
            rhash_md5_update(&mctx, array_1, 0x7f3);
            rhash_md5_final(&mctx, mtmp);
            for (i=0; i<16; ++i)
            {
                sprintf((char*)wtmp + wpos, "%02x", mtmp[i]);
                wpos += 2;
            }
            for (i=0; i<8; ++i)
            {
                sprintf(tbuf, "%02x", (signed char)(s[2*i+1]));
                strcpy((char*)wtmp + wpos, tbuf);
                wpos += strlen(tbuf);
            }
            wpos = 0x60;
            break;

        }
        case 1:
        {
            sha1_ctx sctx;
            rhash_sha1_init(&sctx);
            rhash_sha1_update(&sctx, array_1,0x7f3);
            rhash_sha1_final(&sctx, wtmp);
            wpos += 20;

            memcpy(wtmp + wpos, s, 6);
            wpos += 6;

            rhash_sha1_init(&sctx);
            rhash_sha1_update(&sctx, array,0x71c);
            rhash_sha1_final(&sctx,wtmp + wpos);
            wpos += 20;

            memcpy(wtmp + wpos, s+6, 10);
            wpos += 10;
            break;

        }
        case 2:
        {
            sha1_ctx sctx;
            rhash_sha1_init(&sctx);
            rhash_sha1_update(&sctx,array_1,0x7f3);
            rhash_sha1_final(&sctx,wtmp);
            wpos += 20;

            memcpy(wtmp + wpos, s, 6);
            wpos += 6;

            struct ampheck_ripemd128 rctx;
            ampheck_ripemd128_init(&rctx);
            ampheck_ripemd128_update(&rctx, array, 0x71c);
            ampheck_ripemd128_finish(&rctx, wtmp + wpos);
            wpos += 16;

            memcpy(wtmp + wpos, s+6, 10);
            wpos += 10;
            break;
        }
        case 3:
        {
            tiger_ctx tctx;
            rhash_tiger_init(&tctx);
            rhash_tiger_update(&tctx,array,0x71c);
            rhash_tiger_final(&tctx,wtmp);
            wpos += 24;

            memcpy(wtmp + wpos, s, 10);
            wpos += 10;

            struct ampheck_ripemd128 rctx;
            ampheck_ripemd128_init(&rctx);
            ampheck_ripemd128_update(&rctx, array_1, 0x7f3);
            ampheck_ripemd128_finish(&rctx, wtmp + wpos);
            wpos += 16;

            memcpy(wtmp + wpos, s+10, 6);
            wpos += 6;
            break;
        }
        case 4:
        {
            tiger_ctx tctx;
            rhash_tiger_init(&tctx);
            rhash_tiger_update(&tctx,array_1,0x7f3);
            rhash_tiger_final(&tctx,wtmp);
            wpos += 24;

            memcpy(wtmp + wpos, s, 8);
            wpos += 8;

            sha1_ctx sctx;
            rhash_sha1_init(&sctx);
            rhash_sha1_update(&sctx,array,0x71c);
            rhash_sha1_final(&sctx,wtmp + wpos);
            wpos += 20;

            memcpy(wtmp + wpos, s+8, 8);
            wpos += 8;
            break;
        }
        default:
        {
            return NULL;
        }

    }
    whirlpool_ctx w;
    static unsigned char digest[100];

    rhash_whirlpool_init(&w);
    rhash_whirlpool_update(&w, wtmp, wpos);
    rhash_whirlpool_final(&w, digest);


    char tbuf[10];
    for (i = 0; i<64; ++i)
    {
        sprintf(tbuf, "%02x", digest[i]);
        buf[2*i] = tbuf[0];
        buf[2*i+1] = tbuf[1];
    }
    return buf;

}