void blake224_hash( uint8_t *out, const uint8_t *in, uint64_t inlen ) { state224 S; blake224_init( &S ); blake224_update( &S, in, inlen ); blake224_final( &S, out ); }
unsigned char *blake224_file(unsigned char *out, FILE *fp) { state224 context; size_t ret = 0; int errsv = 0; unsigned char buf[8192], *digest = NULL; blake224_init(&context); for (;;) { ret = fread(buf, 1, 8192, fp); errsv = errno; if ((ret != 8192) && ferror(fp)) { errno = errsv; return NULL; } blake224_update(&context, (const uint8_t *) buf, ret); if (feof(fp)) break; } if (!out) { if (!(digest = malloc(28))) return NULL; } else { digest = out; } blake224_final(&context, (uint8_t *) digest); return digest; }
void blake224(void* dest, const void* msg, uint32_t length_b){ blake_small_ctx_t ctx; blake224_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); blake224_ctx2hash(dest, &ctx); }
/* BLAKE-224 Generic Interface */ unsigned char *blake224_buffer(unsigned char *out, const unsigned char *in, size_t in_len) { state224 context; unsigned char *digest = NULL; blake224_init(&context); if (!out) { if (!(digest = malloc(28))) return NULL; } else { digest = out; } blake224_update(&context, (const uint8_t *) in, in_len); blake224_final(&context, (uint8_t *) digest); return digest; }
int main( int argc, char **argv ) { #define BLOCK224 64 FILE *fp; int i, j, bytesread; uint8_t in[BLOCK224], out[28]; state224 S; blake224_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; } blake224_init( &S ); while( 1 ) { bytesread = fread( in, 1, BLOCK224, fp ); if ( bytesread ) blake224_update( &S, in, bytesread ); else break; } blake224_final( &S, out ); for( j = 0; j < 28; ++j ) printf( "%02x", out[j] ); printf( " %s\n", *( argv + i ) ); fclose( fp ); } return 0; }