Blame lib/mem.h

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
Packit 549fdc
 *
Packit 549fdc
 * Author: Nikos Mavrogiannopoulos
Packit 549fdc
 *
Packit 549fdc
 * This file is part of GnuTLS.
Packit 549fdc
 *
Packit 549fdc
 * The GnuTLS is free software; you can redistribute it and/or
Packit 549fdc
 * modify it under the terms of the GNU Lesser General Public License
Packit 549fdc
 * as published by the Free Software Foundation; either version 2.1 of
Packit 549fdc
 * the License, or (at your option) any later version.
Packit 549fdc
 *
Packit 549fdc
 * This library is distributed in the hope that it will be useful, but
Packit 549fdc
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 549fdc
 * Lesser General Public License for more details.
Packit 549fdc
 *
Packit 549fdc
 * You should have received a copy of the GNU Lesser General Public License
Packit 549fdc
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
Packit 549fdc
 *
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
#ifndef GNUTLS_MEM_H
Packit 549fdc
#define GNUTLS_MEM_H
Packit 549fdc
Packit 549fdc
#include <config.h>
Packit 549fdc
Packit 549fdc
/* this realloc function will return ptr if size==0, and
Packit 549fdc
 * will free the ptr if the new allocation failed.
Packit 549fdc
 */
Packit 549fdc
void *gnutls_realloc_fast(void *ptr, size_t size);
Packit 549fdc
Packit 549fdc
void *_gnutls_calloc(size_t nmemb, size_t size);
Packit 549fdc
char *_gnutls_strdup(const char *);
Packit 549fdc
Packit 549fdc
unsigned _gnutls_mem_is_zero(const uint8_t *ptr, unsigned size);
Packit 549fdc
Packit 549fdc
/* To avoid undefined behavior when s1 or s2 are null and n = 0 */
Packit 549fdc
inline static
Packit 549fdc
int safe_memcmp(const void *s1, const void *s2, size_t n)
Packit 549fdc
{
Packit 549fdc
	if (n == 0)
Packit 549fdc
		return 0;
Packit 549fdc
	return memcmp(s1, s2, n);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
#define zrelease_mpi_key(mpi) if (*mpi!=NULL) { \
Packit 549fdc
		_gnutls_mpi_clear(*mpi); \
Packit 549fdc
		_gnutls_mpi_release(mpi); \
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
#define zeroize_key(x, size) gnutls_memset(x, 0, size)
Packit 549fdc
Packit 549fdc
#define zeroize_temp_key zeroize_key
Packit 549fdc
#define zrelease_temp_mpi_key zrelease_mpi_key
Packit 549fdc
Packit 549fdc
#endif				/* GNUTLS_MEM_H */