コード例 #1
0
ファイル: HashUtils.cpp プロジェクト: EasyIME/PIME
static inline bool HashFunction_Init(const int hashType, hash_ctx *const ctx)
{
	memset(ctx, 0, sizeof(hash_ctx));
	switch(ctx->hashType = hashType)
	{
		case STD_HASHTYPE_CRC_32:   rhash_crc32_init(&ctx->data.crc32);   return true;
		case STD_HASHTYPE_MD5_128:  rhash_md5_init(&ctx->data.md5);       return true;
		case STD_HASHTYPE_SHA1_160: rhash_sha1_init(&ctx->data.sha1);     return true;
		case STD_HASHTYPE_SHA2_224: rhash_sha224_init(&ctx->data.sha256); return true;
		case STD_HASHTYPE_SHA2_256: rhash_sha256_init(&ctx->data.sha256); return true;
		case STD_HASHTYPE_SHA2_384: rhash_sha384_init(&ctx->data.sha512); return true;
		case STD_HASHTYPE_SHA2_512: rhash_sha512_init(&ctx->data.sha512); return true;
		case STD_HASHTYPE_SHA3_224: rhash_sha3_224_init(&ctx->data.sha3); return true;
		case STD_HASHTYPE_SHA3_256: rhash_sha3_256_init(&ctx->data.sha3); return true;
		case STD_HASHTYPE_SHA3_384: rhash_sha3_384_init(&ctx->data.sha3); return true;
		case STD_HASHTYPE_SHA3_512: rhash_sha3_512_init(&ctx->data.sha3); return true;
		case STD_HASHTYPE_BLK2_224:
		case STD_HASHTYPE_BLK2_256:
		case STD_HASHTYPE_BLK2_384:
		case STD_HASHTYPE_BLK2_512:
			if(blake2b_init(&ctx->data.balke2, Blake2_Size(ctx->hashType)) != 0)
			{
				MessageBox(NULL, T("Blake2_Init internal error, going to abort!"), T("StdUtils::HashFunction_Init"), MB_ICONSTOP | MB_TOPMOST);
				abort();
			}
			return true;
		default:
			ERROR_MSG(T("The specified hash type is unknown/unsupported!"));
			return false;
	}
}
コード例 #2
0
ファイル: checkV4.c プロジェクト: Durant35/mentohust-SYSU
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;

}