mem.h

All headers

Memory and string functions, see also buf.h.

BoringSSL has its own set of allocation functions, which keep track of allocation lengths and zero them out before freeing. All memory returned by BoringSSL API calls must therefore generally be freed using OPENSSL_free unless stated otherwise.

  1. OPENSSL_malloc
  2. OPENSSL_free
  3. OPENSSL_realloc
  4. OPENSSL_cleanse
  5. CRYPTO_memcmp
  6. OPENSSL_hash32
  7. OPENSSL_strdup
  8. OPENSSL_strnlen
  9. OPENSSL_tolower
  10. OPENSSL_strcasecmp
  11. OPENSSL_strncasecmp
  12. DECIMAL_SIZE
  13. BIO_snprintf
  14. OPENSSL_PRINTF_FORMAT_FUNC
  15. BIO_vsnprintf
  16. OPENSSL_PRINTF_FORMAT_FUNC
  17. Deprecated functions
  18. CRYPTO_malloc
  19. CRYPTO_realloc
  20. CRYPTO_free

OPENSSL_malloc acts like a regular malloc.

OPENSSL_EXPORT void *OPENSSL_malloc(size_t size);

OPENSSL_free does nothing if ptr is NULL. Otherwise it zeros out the memory allocated at ptr and frees it.

OPENSSL_EXPORT void OPENSSL_free(void *ptr);

OPENSSL_realloc returns a pointer to a buffer of new_size bytes that contains the contents of ptr. Unlike realloc, a new buffer is always allocated and the data at ptr is always wiped and freed.

OPENSSL_EXPORT void *OPENSSL_realloc(void *ptr, size_t new_size);

OPENSSL_cleanse zeros out len bytes of memory at ptr. This is similar to memset_s from C11.

OPENSSL_EXPORT void OPENSSL_cleanse(void *ptr, size_t len);

CRYPTO_memcmp returns zero iff the len bytes at a and b are equal. It takes an amount of time dependent on len, but independent of the contents of a and b. Unlike memcmp, it cannot be used to put elements into a defined order as the return value when a != b is undefined, other than to be non-zero.

OPENSSL_EXPORT int CRYPTO_memcmp(const void *a, const void *b, size_t len);

OPENSSL_hash32 implements the 32 bit, FNV-1a hash.

OPENSSL_EXPORT uint32_t OPENSSL_hash32(const void *ptr, size_t len);

OPENSSL_strdup has the same behaviour as strdup(3).

OPENSSL_EXPORT char *OPENSSL_strdup(const char *s);

OPENSSL_strnlen has the same behaviour as strnlen(3).

OPENSSL_EXPORT size_t OPENSSL_strnlen(const char *s, size_t len);

OPENSSL_tolower is a locale-independent version of tolower(3).

OPENSSL_EXPORT int OPENSSL_tolower(int c);

OPENSSL_strcasecmp is a locale-independent version of strcasecmp(3).

OPENSSL_EXPORT int OPENSSL_strcasecmp(const char *a, const char *b);

OPENSSL_strncasecmp is a locale-independent version of strncasecmp(3).

OPENSSL_EXPORT int OPENSSL_strncasecmp(const char *a, const char *b, size_t n);

DECIMAL_SIZE returns an upper bound for the length of the decimal representation of the given type.

#define DECIMAL_SIZE(type)	((sizeof(type)*8+2)/3+1)

BIO_snprintf has the same behavior as snprintf(3).

OPENSSL_EXPORT int BIO_snprintf(char *buf, size_t n, const char *format, ...)
    OPENSSL_PRINTF_FORMAT_FUNC(3, 4);

BIO_vsnprintf has the same behavior as vsnprintf(3).

OPENSSL_EXPORT int BIO_vsnprintf(char *buf, size_t n, const char *format,
                                 va_list args)
    OPENSSL_PRINTF_FORMAT_FUNC(3, 0);

Deprecated functions.

#define CRYPTO_malloc OPENSSL_malloc
#define CRYPTO_realloc OPENSSL_realloc
#define CRYPTO_free OPENSSL_free