Skip to content

Commit

Permalink
Fixed valgrind complaint due to BN_consttime_swap reading uninitialis…
Browse files Browse the repository at this point in the history
…ed data.

This is actually ok for this function, but initialised to zero anyway if
PURIFY defined.

This does have the impact of masking any *real* unitialised data reads in bn though.

Patch based on approach suggested by Rich Salz.

PR#3415

(cherry picked from commit 77747e2d9a5573b1dbc15e247ce18c03374c760c)
  • Loading branch information
mattcaswell committed Jul 13, 2014
1 parent f712363 commit 5a0df37
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crypto/bn/bn_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE);
return(NULL);
}
#ifdef PURIFY
/* Valgrind complains in BN_consttime_swap because we process the whole
* array even if it's not initialised yet. This doesn't matter in that
* function - what's important is constant time operation (we're not
* actually going to use the data)
*/
memset(a, 0, sizeof(BN_ULONG)*words);
#endif

#if 1
B=b->d;
/* Check if the previous number needs to be copied */
Expand Down

0 comments on commit 5a0df37

Please sign in to comment.