Commit 496e1524 authored by Daniel Salzman's avatar Daniel Salzman

contrib: move volatile_memset to string.h as memzero

parent 75ca47f7
......@@ -17,14 +17,9 @@
#include <stdlib.h>
#include "contrib/mempattern.h"
#include "contrib/string.h"
#include "contrib/ucw/mempool.h"
/*
* Inspired by OPENSSL_cleanse. Such a memset shouldn't be optimized out.
*/
typedef void *(*memset_t)(void *, int, size_t);
static volatile memset_t volatile_memset = memset;
static void mm_nofree(void *p)
{
/* nop */
......@@ -59,7 +54,7 @@ void *mm_calloc(knot_mm_t *mm, size_t nmemb, size_t size)
if (mem == NULL) {
return NULL;
}
return volatile_memset(mem, 0, total_size);
return memzero(mem, total_size);
} else {
return calloc(nmemb, size);
}
......
......@@ -102,3 +102,11 @@ int const_time_memcmp(const void *s1, const void *s2, size_t n)
return equal;
}
typedef void *(*memset_t)(void *, int, size_t);
static volatile memset_t volatile_memset = memset;
void *memzero(void *s, size_t n)
{
return volatile_memset(s, 0, n);
}
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -17,13 +17,11 @@
* \file
*
* \brief String manipulations.
*
* \addtogroup contrib
* @{
*/
#pragma once
#include <stddef.h>
#include <stdint.h>
/*!
......@@ -73,4 +71,14 @@ char *strstrip(const char *str);
*/
int const_time_memcmp(const void *s1, const void *s2, size_t n);
/*! @} */
/*!
* \brief Fill memory with zeroes.
*
* Inspired by OPENSSL_cleanse. Such a memset shouldn't be optimized out.
*
* \param s The address to fill.
* \param n The size of memory to fill.
*
* \return Pointer to the memory.
*/
void *memzero(void *s, size_t n);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment