/** * @buf - [in] msg input * @outbuf - [out] hash output */ static void get_hash(u08b_t *inbuf, u08b_t *outbuf) { Skein1024_Ctxt_t ctx; Skein1024_Init(&ctx, 1024); Skein1024_Update(&ctx, inbuf, strlen((char *)inbuf)); Skein1024_Final(&ctx, outbuf); }
int main(int argc, char *argv[]) { struct timeval tv; gettimeofday(&tv, NULL); srand(tv.tv_sec ^ tv.tv_usec + getpid() + (getppid() << 12)); Skein1024_Ctxt_t ctx; uint8_t hash[128]; int best = 1024; int current; time_t time_ref = time(NULL); int nhash = 0; int input_length = 0; char input[101]; while (1) { // Only refresh the input with a new random value every so often if (nhash % INC_BEFORE_NEW == 0) { input_length = new_input(input); } else { inc_input(input, input_length); } Skein1024_Init(&ctx, 1024); Skein1024_Update(&ctx, (uint8_t *) input, input_length); Skein1024_Final(&ctx, hash); ++nhash; // Rate reporting // Overflow, stay accurate if (nhash == 0) time_ref = time(NULL); else if (nhash % HASH_BEFORE_REPORT == 0) { double khash = nhash / 1000.0; fprintf(stderr, "%f khash/s\n", khash / (double)(time(NULL) - time_ref)); } current = bitdiff(hash, oracle); if (current < best) { best = current; printf("%d %s\n", best, input); fflush(stdout); } } return 0; }
static inline void checkHash() { assert(Skein1024_Init(&ctx, 1024) == SKEIN_SUCCESS); assert(Skein1024_Update(&ctx, plaintext, DEPTH) == SKEIN_SUCCESS); assert(Skein1024_Final(&ctx, hash) == SKEIN_SUCCESS); unsigned int bits_one = 0; for (unsigned int i = 0; i < 1024/8; i++) { u08b_t bits = hash[i] ^ XOR[i]; for (unsigned char j = 0; j < 8; j++) bits_one += (bits >> j) & 1; } if (bits_one < low_bits) { low_bits = bits_one; fprintf(stdout, "New best: \"%s\" %d\n", plaintext, bits_one); fflush(stdout); } // count++; if (count > 10000000) exit(0); }
int skeinFinal(SkeinCtx_t* ctx, uint8_t* hash) { int ret = SKEIN_FAIL; Skein_Assert(ctx, SKEIN_FAIL); switch (ctx->skeinSize) { case Skein256: ret = Skein_256_Final(&ctx->m.s256, (u08b_t*)hash); break; case Skein512: ret = Skein_512_Final(&ctx->m.s512, (u08b_t*)hash); break; case Skein1024: ret = Skein1024_Final(&ctx->m.s1024, (u08b_t*)hash); break; } return ret; }