mirror of
https://github.com/status-im/go-sqlcipher.git
synced 2026-08-31 02:01:15 +00:00
Fixing status-im/status-desktop#10572 Implements a cross-platform version of OP-TEE/optee_os#3102 Remove recursion Use memset instead of while loop A description to understand introduced changes without reading the code. zeromem weights about 50% of the total CPU time on M1 Macs and seems to be major performance offender. It is used to clear the stack when using variables with sensitive information.
42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
/* 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"
|
|
#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
|
|
@param outlen The length of the area to zero (octets)
|
|
*/
|
|
void zeromem(void *out, size_t outlen)
|
|
{
|
|
LTC_ARGCHKVD(out != NULL);
|
|
memset_func((void *)out, 0, outlen);
|
|
}
|
|
|
|
/* $Source$ */
|
|
/* $Revision$ */
|
|
/* $Date$ */
|