示例#1
0
void heavycoin_hash(const char* input, int len, char* output)
{
    unsigned char hash1[32];
    HEFTY1((unsigned char *)input, len, hash1);

    /* HEFTY1 is new, so take an extra security measure to eliminate
     * the possiblity of collisions:
     *
     *     Hash(x) = SHA256(x + HEFTY1(x))
     *
     * N.B. '+' is concatenation.
     */
    unsigned char hash2[32];;

    sha256_ctx ctx;
    sha256_init(&ctx);
    sha256_update(&ctx, (const unsigned char *)input, len);
    sha256_update(&ctx, hash1, sizeof(hash1));
    sha256_final(&ctx, hash2);

    /* Additional security: Do not rely on a single cryptographic hash
     * function.  Instead, combine the outputs of 4 of the most secure
     * cryptographic hash functions-- SHA256, KECCAK512, GROESTL512
     * and BLAKE512.
     */

    uint32_t hash3[16];
    sph_keccak512_context keccakCtx;
    sph_keccak512_init(&keccakCtx);
    sph_keccak512(&keccakCtx, input, len);
    sph_keccak512(&keccakCtx, hash1, sizeof(hash1));
    sph_keccak512_close(&keccakCtx, (void *)&hash3);

    uint32_t hash4[16];
    sph_groestl512_context groestlCtx;
    sph_groestl512_init(&groestlCtx);
    sph_groestl512(&groestlCtx, input, len);
    sph_groestl512(&groestlCtx, hash1, sizeof(hash1));
    sph_groestl512_close(&groestlCtx, (void *)&hash4);

    uint32_t hash5[16];
    sph_blake512_context blakeCtx;
    sph_blake512_init(&blakeCtx);
    sph_blake512(&blakeCtx, input, len);
    sph_blake512(&blakeCtx, (unsigned char *)&hash1, sizeof(hash1));
    sph_blake512_close(&blakeCtx, (void *)&hash5);

    uint32_t *final = (uint32_t *)output;
    combine_hashes(final, (uint32_t *)hash2, hash3, hash4, hash5);
}
示例#2
0
int heavycoin_scanhash(unsigned char* output, const unsigned char* input, int len)
{
    DATA_ALIGN64(unsigned char hash1[32]);
    HEFTY1(input, len, hash1);

    DATA_ALIGN64(uint32_t hash5[16]);
    sph_blake512_context blakeCtx;
    sph_blake512_init(&blakeCtx);
    sph_blake512(&blakeCtx, input, len);
    sph_blake512(&blakeCtx, (unsigned char *)&hash1, sizeof(hash1));
    sph_blake512_close(&blakeCtx, (void *)&hash5);
    if ((*((unsigned char *)hash5 + 31) & 0xF0) != 0)
        return 0;

    DATA_ALIGN64(unsigned char hash2[32]);
    SHA256_CTX ctx;
    SHA256_Init(&ctx);
    SHA256_Update(&ctx, input, len);
    SHA256_Update(&ctx, hash1, sizeof(hash1));
    SHA256_Final(hash2, &ctx);
    if ((*((unsigned char *)hash2 + 31) & 0xF0) != 0)
        return 0;

    DATA_ALIGN64(uint32_t hash3[16]);
    sph_keccak512_context keccakCtx;
    sph_keccak512_init(&keccakCtx);
    sph_keccak512(&keccakCtx, input, len);
    sph_keccak512(&keccakCtx, hash1, sizeof(hash1));
    sph_keccak512_close(&keccakCtx, (void *)&hash3);
    if ((*((unsigned char *)hash3 + 31) & 0xF0) != 0)
        return 0;

    DATA_ALIGN64(uint32_t hash4[16]);
    sph_groestl512_context groestlCtx;
    sph_groestl512_init(&groestlCtx);
    sph_groestl512(&groestlCtx, input, len);
    sph_groestl512(&groestlCtx, hash1, sizeof(hash1));
    sph_groestl512_close(&groestlCtx, (void *)&hash4);
    if ((*((unsigned char *)hash4 + 31) & 0xF0) != 0)
        return 0;

    uint32_t *final = (uint32_t *)output;
    combine_hashes(final, (uint32_t *)hash2, hash3, hash4, hash5);

    return 1;
}
示例#3
0
void heavy_hash(void* output, const void* input, int len)
{
	uint32_t hash1[16], hash2[16], hash3[16], hash4[16], hash5[16];

	HEFTY1(input, len, (unsigned char *)hash1);

	/* HEFTY1 is new, so take an extra security measure to eliminate
	 * the possiblity of collisions:
	 *
	 *	 Hash(x) = SHA256(x + HEFTY1(x))
	 *
	 * N.B. '+' is concatenation.
	 */
	SHA256_CTX sha256;
	SHA256_Init(&sha256);
	SHA256_Update(&sha256, input, len);
	SHA256_Update(&sha256, hash1, sizeof(hash1));
	SHA256_Final((unsigned char*)hash2, &sha256);

	/* Additional security: Do not rely on a single cryptographic hash
	 * function.  Instead, combine the outputs of 4 of the most secure
	 * cryptographic hash functions-- SHA256, KECCAK512, GROESTL512
	 * and BLAKE512.
	 */

	sph_keccak512(&ctx.keccak, input, len);
	sph_keccak512(&ctx.keccak, hash1, sizeof(hash1));
	sph_keccak512_close(&ctx.keccak, hash3);

	sph_groestl512(&ctx.groestl, input, len);
	sph_groestl512(&ctx.groestl, hash1, sizeof(hash1));
	sph_groestl512_close(&ctx.groestl, hash4);

	sph_blake512(&ctx.blake, input, len);
	sph_blake512(&ctx.blake, hash1, sizeof(hash1));
	sph_blake512_close(&ctx.blake, hash5);

	combine_hashes((uint32_t *)output, hash2, hash3, hash4, hash5);
}