void blake256_hash( uint8_t *out, const uint8_t *in, uint64_t inlen ) { state256 S; blake256_init( &S ); blake256_update( &S, in, inlen ); blake256_final( &S, out ); }
unsigned char *blake256_file(unsigned char *out, FILE *fp) { state256 context; size_t ret = 0; int errsv = 0; unsigned char buf[8192], *digest = NULL; blake256_init(&context); for (;;) { ret = fread(buf, 1, 8192, fp); errsv = errno; if ((ret != 8192) && ferror(fp)) { errno = errsv; return NULL; } blake256_update(&context, (const uint8_t *) buf, ret); if (feof(fp)) break; } if (!out) { if (!(digest = malloc(32))) return NULL; } else { digest = out; } blake256_final(&context, (uint8_t *) digest); return digest; }
void blake256(void* dest, const void* msg, uint32_t length_b){ blake_small_ctx_t ctx; blake256_init(&ctx); while(length_b>=BLAKE_SMALL_BLOCKSIZE){ blake_small_nextBlock(&ctx, msg); msg = (uint8_t*)msg + BLAKE_SMALL_BLOCKSIZE_B; length_b -= BLAKE_SMALL_BLOCKSIZE; } blake_small_lastBlock(&ctx, msg, length_b); blake256_ctx2hash(dest, &ctx); }
int main( int argc, char **argv ) { #define BLOCK256 64 FILE *fp; int i, j, bytesread; uint8_t in[BLOCK256], out[32]; state256 S; blake256_test(); for( i = 1; i < argc; ++i ) { fp = fopen( *( argv + i ), "r" ); if ( fp == NULL ) { printf( "Error: unable to open %s\n", *( argv + i ) ); return 1; } blake256_init( &S ); while( 1 ) { bytesread = fread( in, 1, BLOCK256, fp ); if ( bytesread ) blake256_update( &S, in, bytesread ); else break; } blake256_final( &S, out ); for( j = 0; j < 32; ++j ) printf( "%02x", out[j] ); printf( " %s\n", *( argv + i ) ); fclose( fp ); } return 0; }
void precalc_hash_blake256(dev_blk_ctx *blk, uint32_t *data) { blake_state256 S; blake256_init(&S); blake256_update(&S, data); blk->ctx_a = S.h[0]; blk->ctx_b = S.h[1]; blk->ctx_c = S.h[2]; blk->ctx_d = S.h[3]; blk->ctx_e = S.h[4]; blk->ctx_f = S.h[5]; blk->ctx_g = S.h[6]; blk->ctx_h = S.h[7]; blk->cty_a = data[16]; blk->cty_b = data[17]; blk->cty_c = data[18]; }
/* BLAKE-256 Generic Interface */ unsigned char *blake256_buffer( unsigned char *out, const unsigned char *in, size_t in_len) { state256 context; unsigned char *digest = NULL; blake256_init(&context); if (!out) { if (!(digest = malloc(32))) return NULL; } else { digest = out; } blake256_update(&context, (const uint8_t *) in, in_len); blake256_final(&context, (uint8_t *) digest); return digest; }