Tor 0.4.9.0-alpha-dev
Functions
crypto_util.c File Reference

Common cryptographic utilities. More...

#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.

Functions

void memwipe (void *mem, uint8_t byte, size_t sz)
 
void tor_str_wipe_and_free_ (char *str)
 

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 55 of file crypto_util.c.

Referenced by build_secret_key_iv_mac(), build_service_desc_keys(), circuitmux_detach_circuit(), compute_introduce_mac(), control_cmd_args_wipe(), cpuworker_cancel_circ_handshake(), crypto_digest_free_(), crypto_expand_key_material_rfc5869_sha256_legacy(), crypto_fast_rng_free_(), crypto_ope_free_(), crypto_pk_private_sign_digest(), crypto_pk_write_private_key_to_filename(), crypto_strongest_rand_raw(), crypto_xof_free_(), curve25519_impl(), curve25519_keypair_read_from_file(), decrypt_desc_layer(), ed25519_keypair_blind(), ed25519_keypair_free_(), ed25519_secret_key_generate(), encode_superencrypted_data(), encrypt_descriptor_data(), ewma_free_circ_data(), fast_handshake_state_free_(), hs_build_blinded_keypair(), hs_build_blinded_pubkey(), hs_client_decode_descriptor(), hs_ident_circuit_free_(), hs_ident_dir_conn_free_(), hs_ident_edge_conn_free_(), hs_ntor_service_get_introduce1_keys_multi(), ntor3_handshake_state_free_(), ntor3_server_handshake_state_free_(), ntor_handshake_state_free_(), onion_skin_ntor3_create(), onion_skin_ntor3_server_handshake_part2(), reveal_encode(), service_authorized_client_free_(), service_intro_point_free_(), socks_request_free_(), sr_commit_free_(), tor_cert_free_(), tor_str_wipe_and_free_(), and tor_x509_cert_free_().

◆ tor_str_wipe_and_free_()

void tor_str_wipe_and_free_ ( char *  str)

Securely all memory in str, then free it.

As tor_free(), tolerates null pointers.

Definition at line 117 of file crypto_util.c.