Permalink
Browse files

Fix segfault in SHA3 when having message sized aligned with the buffe…

…r size.

When the buffer is full, we need to process it before appending the padding.

fix #18
  • Loading branch information...
vincenthz committed Jan 19, 2014
1 parent e1687b5 commit a69b8c870b8c76786ca84d775f6abb0fd03c0d80
Showing with 6 additions and 0 deletions.
  1. +6 −0 cbits/sha3.c
View
@@ -139,6 +139,12 @@ void sha3_finalize(struct sha3_ctx *ctx, uint8_t *out)
{
uint64_t w[25];
+ /* process full buffer if needed */
+ if (ctx->bufindex == ctx->bufsz) {
+ sha3_do_chunk(ctx->state, (uint64_t *) ctx->buf, ctx->bufsz / 8);
+ ctx->bufindex = 0;
+ }
+
/* add the 10*1 padding */
ctx->buf[ctx->bufindex++] = 1;
memset(ctx->buf + ctx->bufindex, 0, ctx->bufsz - ctx->bufindex);

0 comments on commit a69b8c8

Please sign in to comment.