Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
Embed:
(wiki syntax)
Show/hide line numbers
memory_buffer_alloc.h
Go to the documentation of this file.
00001 /** 00002 * \file memory_buffer_alloc.h 00003 * 00004 * \brief Buffer-based memory allocator 00005 * 00006 * Copyright (C) 2006-2014, Brainspark B.V. 00007 * 00008 * This file is part of PolarSSL (http://www.polarssl.org) 00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> 00010 * 00011 * All rights reserved. 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2 of the License, or 00016 * (at your option) any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License along 00024 * with this program; if not, write to the Free Software Foundation, Inc., 00025 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00026 */ 00027 #ifndef POLARSSL_MEMORY_BUFFER_ALLOC_H 00028 #define POLARSSL_MEMORY_BUFFER_ALLOC_H 00029 00030 #if !defined(POLARSSL_CONFIG_FILE) 00031 #include "config.h" 00032 #else 00033 #include POLARSSL_CONFIG_FILE 00034 #endif 00035 00036 #include <stdlib.h> 00037 00038 /** 00039 * \name SECTION: Module settings 00040 * 00041 * The configuration options you can set for this module are in this section. 00042 * Either change them in config.h or define them on the compiler command line. 00043 * \{ 00044 */ 00045 00046 #if !defined(POLARSSL_MEMORY_ALIGN_MULTIPLE) 00047 #define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ 00048 #endif 00049 00050 /* \} name SECTION: Module settings */ 00051 00052 #define MEMORY_VERIFY_NONE 0 00053 #define MEMORY_VERIFY_ALLOC (1 << 0) 00054 #define MEMORY_VERIFY_FREE (1 << 1) 00055 #define MEMORY_VERIFY_ALWAYS (MEMORY_VERIFY_ALLOC | MEMORY_VERIFY_FREE) 00056 00057 #ifdef __cplusplus 00058 extern "C" { 00059 #endif 00060 00061 /** 00062 * \brief Initialize use of stack-based memory allocator. 00063 * The stack-based allocator does memory management inside the 00064 * presented buffer and does not call malloc() and free(). 00065 * It sets the global polarssl_malloc() and polarssl_free() pointers 00066 * to its own functions. 00067 * (Provided polarssl_malloc() and polarssl_free() are thread-safe if 00068 * POLARSSL_THREADING_C is defined) 00069 * 00070 * \note This code is not optimized and provides a straight-forward 00071 * implementation of a stack-based memory allocator. 00072 * 00073 * \param buf buffer to use as heap 00074 * \param len size of the buffer 00075 * 00076 * \return 0 if successful 00077 */ 00078 int memory_buffer_alloc_init( unsigned char *buf, size_t len ); 00079 00080 /** 00081 * \brief Free the mutex for thread-safety and clear remaining memory 00082 */ 00083 void memory_buffer_alloc_free( void ); 00084 00085 /** 00086 * \brief Determine when the allocator should automatically verify the state 00087 * of the entire chain of headers / meta-data. 00088 * (Default: MEMORY_VERIFY_NONE) 00089 * 00090 * \param verify One of MEMORY_VERIFY_NONE, MEMORY_VERIFY_ALLOC, 00091 * MEMORY_VERIFY_FREE or MEMORY_VERIFY_ALWAYS 00092 */ 00093 void memory_buffer_set_verify( int verify ); 00094 00095 #if defined(POLARSSL_MEMORY_DEBUG) 00096 /** 00097 * \brief Print out the status of the allocated memory (primarily for use 00098 * after a program should have de-allocated all memory) 00099 * Prints out a list of 'still allocated' blocks and their stack 00100 * trace if POLARSSL_MEMORY_BACKTRACE is defined. 00101 */ 00102 void memory_buffer_alloc_status( void ); 00103 #endif /* POLARSSL_MEMORY_DEBUG */ 00104 00105 /** 00106 * \brief Verifies that all headers in the memory buffer are correct 00107 * and contain sane values. Helps debug buffer-overflow errors. 00108 * 00109 * Prints out first failure if POLARSSL_MEMORY_DEBUG is defined. 00110 * Prints out full header information if POLARSSL_MEMORY_DEBUG_HEADERS 00111 * is defined. (Includes stack trace information for each block if 00112 * POLARSSL_MEMORY_BACKTRACE is defined as well). 00113 * 00114 * \returns 0 if verified, 1 otherwise 00115 */ 00116 int memory_buffer_alloc_verify( void ); 00117 00118 #ifdef __cplusplus 00119 } 00120 #endif 00121 00122 #endif /* memory_buffer_alloc.h */ 00123 00124
Generated on Tue Jul 12 2022 19:40:17 by 1.7.2