コード例 #1
0
ファイル: aggie_skein.c プロジェクト: bitcars/xkcd-1193
/**
 * @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);
}
コード例 #2
0
ファイル: skein.c プロジェクト: 2asoft/freebsd
/* [identical to Skein1024_Init() when keyBytes == 0 && treeInfo == SKEIN_CFG_TREE_INFO_SEQUENTIAL] */
int Skein1024_InitExt(Skein1024_Ctxt_t *ctx,size_t hashBitLen,u64b_t treeInfo, const u08b_t *key, size_t keyBytes)
    {
    union
        {
        u08b_t  b[SKEIN1024_STATE_BYTES];
        u64b_t  w[SKEIN1024_STATE_WORDS];
        } cfg;                              /* config block */
        
    Skein_Assert(hashBitLen > 0,SKEIN_BAD_HASHLEN);
    Skein_Assert(keyBytes == 0 || key != NULL,SKEIN_FAIL);

    /* compute the initial chaining values ctx->X[], based on key */
    if (keyBytes == 0)                          /* is there a key? */
        {                                   
        memset(ctx->X,0,sizeof(ctx->X));        /* no key: use all zeroes as key for config block */
        }
    else                                        /* here to pre-process a key */
        {
        Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X));
        /* do a mini-Init right here */
        ctx->h.hashBitLen=8*sizeof(ctx->X);     /* set output hash bit count = state size */
        Skein_Start_New_Type(ctx,KEY);          /* set tweaks: T0 = 0; T1 = KEY type */
        memset(ctx->X,0,sizeof(ctx->X));        /* zero the initial chaining variables */
        Skein1024_Update(ctx,key,keyBytes);     /* hash the key */
        Skein1024_Final_Pad(ctx,cfg.b);         /* put result into cfg.b[] */
        memcpy(ctx->X,cfg.b,sizeof(cfg.b));     /* copy over into ctx->X[] */
#if SKEIN_NEED_SWAP
        {
        uint_t i;
        for (i=0;i<SKEIN1024_STATE_WORDS;i++)   /* convert key bytes to context words */
            ctx->X[i] = Skein_Swap64(ctx->X[i]);
        }
#endif
        }
    /* build/process the config block, type == CONFIG (could be precomputed for each key) */
    ctx->h.hashBitLen = hashBitLen;             /* output hash bit count */
    Skein_Start_New_Type(ctx,CFG_FINAL);

    memset(&cfg.w,0,sizeof(cfg.w));             /* pre-pad cfg.w[] with zeroes */
    cfg.w[0] = Skein_Swap64(SKEIN_SCHEMA_VER);
    cfg.w[1] = Skein_Swap64(hashBitLen);        /* hash result length in bits */
    cfg.w[2] = Skein_Swap64(treeInfo);          /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */

    Skein_Show_Key(1024,&ctx->h,key,keyBytes);

    /* compute the initial chaining values from config block */
    Skein1024_Process_Block(ctx,cfg.b,1,SKEIN_CFG_STR_LEN);

    /* The chaining vars ctx->X are now initialized */
    /* Set up to process the data message portion of the hash (default) */
    ctx->h.bCnt = 0;                            /* buffer b[] starts out empty */
    Skein_Start_New_Type(ctx,MSG);
    
    return SKEIN_SUCCESS;
    }
コード例 #3
0
ファイル: fast_skein.c プロジェクト: rfw/xkcd_externalities
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;
}
コード例 #4
0
ファイル: bruteforce.c プロジェクト: Gerst20051/C
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);
}
コード例 #5
0
ファイル: skeinApi.c プロジェクト: dyfet/ccrtp
int skeinUpdate(SkeinCtx_t *ctx, const uint8_t *msg,
                size_t msgByteCnt)
{
    int ret = SKEIN_FAIL;
    Skein_Assert(ctx, SKEIN_FAIL);

    switch (ctx->skeinSize) {
    case Skein256:
        ret = Skein_256_Update(&ctx->m.s256, (const u08b_t*)msg, msgByteCnt);
        break;
    case Skein512:
        ret = Skein_512_Update(&ctx->m.s512, (const u08b_t*)msg, msgByteCnt);
        break;
    case Skein1024:
        ret = Skein1024_Update(&ctx->m.s1024, (const u08b_t*)msg, msgByteCnt);
        break;
    }
    return ret;

}
コード例 #6
0
ファイル: skein.c プロジェクト: 2asoft/freebsd
void
SKEIN1024_Update(SKEIN1024_CTX * ctx, const void *in, size_t len)
{

	Skein1024_Update(ctx, in, len);
}