tor  master
Macros | Functions
crypto_util.c File Reference

Common cryptographic utilities. More...

#include "crypto_util.h"
#include <string.h>
#include "util.h"
#include <openssl/crypto.h>
Include dependency graph for crypto_util.c:

Functions

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

Detailed Description

Common cryptographic utilities.

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().

Here is the caller graph for this function: