From f0c26bafb5b307df520eb5c971eb4ef0475fce06 Mon Sep 17 00:00:00 2001 From: Alex Jbanca <47811206+alexjba@users.noreply.github.com> Date: Wed, 10 May 2023 12:22:14 +0300 Subject: [PATCH] chore(cherry-pick): Cherry-picking commit 5d5c005: Fix burn_stack performance issue performance(sqlcipher): Fix burn_stack performance issue --- burn_stack.c | 23 ++++++++++++++++------- zeromem.c | 10 ++++++---- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/burn_stack.c b/burn_stack.c index 5d276a4..9cc9826 100644 --- a/burn_stack.c +++ b/burn_stack.c @@ -1,6 +1,14 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis */ -/* SPDX-License-Identifier: Unlicense */ -#include "tomcrypt_private.h" +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" /** @file burn_stack.c @@ -13,11 +21,12 @@ */ 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)); - } } + +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/zeromem.c b/zeromem.c index 7d14994..b2ae036 100644 --- a/zeromem.c +++ b/zeromem.c @@ -1,6 +1,7 @@ /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ #include "tomcrypt_private.h" +#include /** @file zeromem.c @@ -14,9 +15,10 @@ */ void zeromem(volatile void *out, size_t outlen) { - volatile char *mem = out; LTC_ARGCHKVD(out != NULL); - while (outlen-- > 0) { - *mem++ = '\0'; - } + memset((void *)out, 0, outlen); } + +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */