Merge pull request #1 from status-im/fix/burn-stack
performance(sqlcipher): Fix burn_stack performance issue
This commit is contained in:
commit
5d5c00574f
|
@ -21,10 +21,8 @@
|
|||
*/
|
||||
void burn_stack(unsigned long len)
|
||||
{
|
||||
unsigned char buf[32];
|
||||
unsigned char buf[len];
|
||||
zeromem(buf, sizeof(buf));
|
||||
if (len > (unsigned long)sizeof(buf))
|
||||
burn_stack(len - sizeof(buf));
|
||||
}
|
||||
|
||||
|
||||
|
|
15
zeromem.c
15
zeromem.c
|
@ -9,12 +9,22 @@
|
|||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
@file zeromem.c
|
||||
Zero a block of memory, Tom St Denis
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pointer to memset is volatile so that compiler must de-reference
|
||||
* the pointer and can't assume that it points to any function in
|
||||
* particular (such as memset, which it then might further "optimize")
|
||||
*/
|
||||
typedef void *(*memset_t)(void *, int, size_t);
|
||||
|
||||
static volatile memset_t memset_func = memset;
|
||||
|
||||
/**
|
||||
Zero a block of memory
|
||||
@param out The destination of the area to zero
|
||||
|
@ -22,11 +32,8 @@
|
|||
*/
|
||||
void zeromem(void *out, size_t outlen)
|
||||
{
|
||||
unsigned char *mem = out;
|
||||
LTC_ARGCHKVD(out != NULL);
|
||||
while (outlen-- > 0) {
|
||||
*mem++ = 0;
|
||||
}
|
||||
memset_func((void *)out, 0, outlen);
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
|
|
Loading…
Reference in New Issue