Skip to content

Commit

Permalink
engines/ccgost/gosthash.c: simplify and avoid SEGV.
Browse files Browse the repository at this point in the history
PR: 3275
  • Loading branch information
Andy Polyakov committed Mar 7, 2014
1 parent 5e44c14 commit ea38f02
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions engines/ccgost/gosthash.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ int start_hash(gost_hash_ctx *ctx)
*/
int hash_block(gost_hash_ctx *ctx,const byte *block, size_t length)
{
const byte *curptr=block;
const byte *barrier=block+(length-32);/* Last byte we can safely hash*/
if (ctx->left)
{
/*There are some bytes from previous step*/
Expand All @@ -196,24 +194,25 @@ int hash_block(gost_hash_ctx *ctx,const byte *block, size_t length)
{
return 1;
}
curptr=block+add_bytes;
block+=add_bytes;
length-=add_bytes;
hash_step(ctx->cipher_ctx,ctx->H,ctx->remainder);
add_blocks(32,ctx->S,ctx->remainder);
ctx->len+=32;
ctx->left=0;
}
while (curptr<=barrier)
while (length>=32)
{
hash_step(ctx->cipher_ctx,ctx->H,curptr);
hash_step(ctx->cipher_ctx,ctx->H,block);

add_blocks(32,ctx->S,curptr);
add_blocks(32,ctx->S,block);
ctx->len+=32;
curptr+=32;
block+=32;
length-=32;
}
if (curptr!=block+length)
if (length)
{
ctx->left=block+length-curptr;
memcpy(ctx->remainder,curptr,ctx->left);
memcpy(ctx->remainder,block,ctx->left=length);
}
return 1;
}
Expand Down

0 comments on commit ea38f02

Please sign in to comment.