Macros | Functions
crypto_util.c File Reference
#include "lib/crypt_ops/crypto_util.h"
#include "lib/cc/compat_compiler.h"
#include <string.h>
#include <stdlib.h>
#include "lib/log/log.h"
#include "lib/log/util_bug.h"

Go to the source code of this file.


void memwipe (void *mem, uint8_t byte, size_t sz)

Detailed Description

Common cryptographic utilities.

Definition in file crypto_util.c.

Function Documentation

◆ memwipe()

void memwipe ( void *  mem,
uint8_t  byte,
size_t  sz 

Destroy the sz bytes of data stored at mem, setting them to the value byte. If mem is NULL or sz is zero, nothing happens.

This function is preferable to memset, since many compilers will happily optimize out memset() when they can convince themselves that the data being cleared will never be read.

Right now, our convention is to use this function when we are wiping data that's about to become inaccessible, such as stack buffers that are about to go out of scope or structures that are about to get freed. (In practice, it appears that the compilers we're currently using will optimize out the memset()s for stack-allocated buffers, but not those for about-to-be-freed structures. That could change, though, so we're being wary.) If there are live reads for the data, then you can just use memset().

Definition at line 57 of file crypto_util.c.

References SIZE_T_CEILING, and tor_assert().

Referenced by control_cmd_args_wipe(), cpuworker_cancel_circ_handshake(), crypto_digest_free_(), crypto_expand_key_material_rfc5869_sha256_legacy(), crypto_fast_rng_free_(), crypto_pk_private_sign_digest(), crypto_pk_write_private_key_to_filename(), crypto_strongest_rand_raw(), crypto_xof_free_(), curve25519_impl(), ed25519_keypair_free_(), ed25519_secret_key_generate(), fast_handshake_state_free_(), make_ntor_onion_key_crosscert(), ntor_handshake_state_free_(), ntor_key_map_free_helper(), rend_service_free_intro_(), tor_cert_free_(), and tor_x509_cert_free_().