Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
SSL/include/polarssl/memory_buffer_alloc.h@0:796d0f61a05b, 2018-09-27 (annotated)
- Committer:
- HannesTschofenig
- Date:
- Thu Sep 27 06:34:22 2018 +0000
- Revision:
- 0:796d0f61a05b
Example AES-GCM test program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HannesTschofenig | 0:796d0f61a05b | 1 | /** |
HannesTschofenig | 0:796d0f61a05b | 2 | * \file memory_buffer_alloc.h |
HannesTschofenig | 0:796d0f61a05b | 3 | * |
HannesTschofenig | 0:796d0f61a05b | 4 | * \brief Buffer-based memory allocator |
HannesTschofenig | 0:796d0f61a05b | 5 | * |
HannesTschofenig | 0:796d0f61a05b | 6 | * Copyright (C) 2006-2014, Brainspark B.V. |
HannesTschofenig | 0:796d0f61a05b | 7 | * |
HannesTschofenig | 0:796d0f61a05b | 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
HannesTschofenig | 0:796d0f61a05b | 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
HannesTschofenig | 0:796d0f61a05b | 10 | * |
HannesTschofenig | 0:796d0f61a05b | 11 | * All rights reserved. |
HannesTschofenig | 0:796d0f61a05b | 12 | * |
HannesTschofenig | 0:796d0f61a05b | 13 | * This program is free software; you can redistribute it and/or modify |
HannesTschofenig | 0:796d0f61a05b | 14 | * it under the terms of the GNU General Public License as published by |
HannesTschofenig | 0:796d0f61a05b | 15 | * the Free Software Foundation; either version 2 of the License, or |
HannesTschofenig | 0:796d0f61a05b | 16 | * (at your option) any later version. |
HannesTschofenig | 0:796d0f61a05b | 17 | * |
HannesTschofenig | 0:796d0f61a05b | 18 | * This program is distributed in the hope that it will be useful, |
HannesTschofenig | 0:796d0f61a05b | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
HannesTschofenig | 0:796d0f61a05b | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
HannesTschofenig | 0:796d0f61a05b | 21 | * GNU General Public License for more details. |
HannesTschofenig | 0:796d0f61a05b | 22 | * |
HannesTschofenig | 0:796d0f61a05b | 23 | * You should have received a copy of the GNU General Public License along |
HannesTschofenig | 0:796d0f61a05b | 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
HannesTschofenig | 0:796d0f61a05b | 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
HannesTschofenig | 0:796d0f61a05b | 26 | */ |
HannesTschofenig | 0:796d0f61a05b | 27 | #ifndef POLARSSL_MEMORY_BUFFER_ALLOC_H |
HannesTschofenig | 0:796d0f61a05b | 28 | #define POLARSSL_MEMORY_BUFFER_ALLOC_H |
HannesTschofenig | 0:796d0f61a05b | 29 | |
HannesTschofenig | 0:796d0f61a05b | 30 | #if !defined(POLARSSL_CONFIG_FILE) |
HannesTschofenig | 0:796d0f61a05b | 31 | #include "config.h" |
HannesTschofenig | 0:796d0f61a05b | 32 | #else |
HannesTschofenig | 0:796d0f61a05b | 33 | #include POLARSSL_CONFIG_FILE |
HannesTschofenig | 0:796d0f61a05b | 34 | #endif |
HannesTschofenig | 0:796d0f61a05b | 35 | |
HannesTschofenig | 0:796d0f61a05b | 36 | #include <stdlib.h> |
HannesTschofenig | 0:796d0f61a05b | 37 | |
HannesTschofenig | 0:796d0f61a05b | 38 | /** |
HannesTschofenig | 0:796d0f61a05b | 39 | * \name SECTION: Module settings |
HannesTschofenig | 0:796d0f61a05b | 40 | * |
HannesTschofenig | 0:796d0f61a05b | 41 | * The configuration options you can set for this module are in this section. |
HannesTschofenig | 0:796d0f61a05b | 42 | * Either change them in config.h or define them on the compiler command line. |
HannesTschofenig | 0:796d0f61a05b | 43 | * \{ |
HannesTschofenig | 0:796d0f61a05b | 44 | */ |
HannesTschofenig | 0:796d0f61a05b | 45 | |
HannesTschofenig | 0:796d0f61a05b | 46 | #if !defined(POLARSSL_MEMORY_ALIGN_MULTIPLE) |
HannesTschofenig | 0:796d0f61a05b | 47 | #define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ |
HannesTschofenig | 0:796d0f61a05b | 48 | #endif |
HannesTschofenig | 0:796d0f61a05b | 49 | |
HannesTschofenig | 0:796d0f61a05b | 50 | /* \} name SECTION: Module settings */ |
HannesTschofenig | 0:796d0f61a05b | 51 | |
HannesTschofenig | 0:796d0f61a05b | 52 | #define MEMORY_VERIFY_NONE 0 |
HannesTschofenig | 0:796d0f61a05b | 53 | #define MEMORY_VERIFY_ALLOC (1 << 0) |
HannesTschofenig | 0:796d0f61a05b | 54 | #define MEMORY_VERIFY_FREE (1 << 1) |
HannesTschofenig | 0:796d0f61a05b | 55 | #define MEMORY_VERIFY_ALWAYS (MEMORY_VERIFY_ALLOC | MEMORY_VERIFY_FREE) |
HannesTschofenig | 0:796d0f61a05b | 56 | |
HannesTschofenig | 0:796d0f61a05b | 57 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 58 | extern "C" { |
HannesTschofenig | 0:796d0f61a05b | 59 | #endif |
HannesTschofenig | 0:796d0f61a05b | 60 | |
HannesTschofenig | 0:796d0f61a05b | 61 | /** |
HannesTschofenig | 0:796d0f61a05b | 62 | * \brief Initialize use of stack-based memory allocator. |
HannesTschofenig | 0:796d0f61a05b | 63 | * The stack-based allocator does memory management inside the |
HannesTschofenig | 0:796d0f61a05b | 64 | * presented buffer and does not call malloc() and free(). |
HannesTschofenig | 0:796d0f61a05b | 65 | * It sets the global polarssl_malloc() and polarssl_free() pointers |
HannesTschofenig | 0:796d0f61a05b | 66 | * to its own functions. |
HannesTschofenig | 0:796d0f61a05b | 67 | * (Provided polarssl_malloc() and polarssl_free() are thread-safe if |
HannesTschofenig | 0:796d0f61a05b | 68 | * POLARSSL_THREADING_C is defined) |
HannesTschofenig | 0:796d0f61a05b | 69 | * |
HannesTschofenig | 0:796d0f61a05b | 70 | * \note This code is not optimized and provides a straight-forward |
HannesTschofenig | 0:796d0f61a05b | 71 | * implementation of a stack-based memory allocator. |
HannesTschofenig | 0:796d0f61a05b | 72 | * |
HannesTschofenig | 0:796d0f61a05b | 73 | * \param buf buffer to use as heap |
HannesTschofenig | 0:796d0f61a05b | 74 | * \param len size of the buffer |
HannesTschofenig | 0:796d0f61a05b | 75 | * |
HannesTschofenig | 0:796d0f61a05b | 76 | * \return 0 if successful |
HannesTschofenig | 0:796d0f61a05b | 77 | */ |
HannesTschofenig | 0:796d0f61a05b | 78 | int memory_buffer_alloc_init( unsigned char *buf, size_t len ); |
HannesTschofenig | 0:796d0f61a05b | 79 | |
HannesTschofenig | 0:796d0f61a05b | 80 | /** |
HannesTschofenig | 0:796d0f61a05b | 81 | * \brief Free the mutex for thread-safety and clear remaining memory |
HannesTschofenig | 0:796d0f61a05b | 82 | */ |
HannesTschofenig | 0:796d0f61a05b | 83 | void memory_buffer_alloc_free( void ); |
HannesTschofenig | 0:796d0f61a05b | 84 | |
HannesTschofenig | 0:796d0f61a05b | 85 | /** |
HannesTschofenig | 0:796d0f61a05b | 86 | * \brief Determine when the allocator should automatically verify the state |
HannesTschofenig | 0:796d0f61a05b | 87 | * of the entire chain of headers / meta-data. |
HannesTschofenig | 0:796d0f61a05b | 88 | * (Default: MEMORY_VERIFY_NONE) |
HannesTschofenig | 0:796d0f61a05b | 89 | * |
HannesTschofenig | 0:796d0f61a05b | 90 | * \param verify One of MEMORY_VERIFY_NONE, MEMORY_VERIFY_ALLOC, |
HannesTschofenig | 0:796d0f61a05b | 91 | * MEMORY_VERIFY_FREE or MEMORY_VERIFY_ALWAYS |
HannesTschofenig | 0:796d0f61a05b | 92 | */ |
HannesTschofenig | 0:796d0f61a05b | 93 | void memory_buffer_set_verify( int verify ); |
HannesTschofenig | 0:796d0f61a05b | 94 | |
HannesTschofenig | 0:796d0f61a05b | 95 | #if defined(POLARSSL_MEMORY_DEBUG) |
HannesTschofenig | 0:796d0f61a05b | 96 | /** |
HannesTschofenig | 0:796d0f61a05b | 97 | * \brief Print out the status of the allocated memory (primarily for use |
HannesTschofenig | 0:796d0f61a05b | 98 | * after a program should have de-allocated all memory) |
HannesTschofenig | 0:796d0f61a05b | 99 | * Prints out a list of 'still allocated' blocks and their stack |
HannesTschofenig | 0:796d0f61a05b | 100 | * trace if POLARSSL_MEMORY_BACKTRACE is defined. |
HannesTschofenig | 0:796d0f61a05b | 101 | */ |
HannesTschofenig | 0:796d0f61a05b | 102 | void memory_buffer_alloc_status( void ); |
HannesTschofenig | 0:796d0f61a05b | 103 | #endif /* POLARSSL_MEMORY_DEBUG */ |
HannesTschofenig | 0:796d0f61a05b | 104 | |
HannesTschofenig | 0:796d0f61a05b | 105 | /** |
HannesTschofenig | 0:796d0f61a05b | 106 | * \brief Verifies that all headers in the memory buffer are correct |
HannesTschofenig | 0:796d0f61a05b | 107 | * and contain sane values. Helps debug buffer-overflow errors. |
HannesTschofenig | 0:796d0f61a05b | 108 | * |
HannesTschofenig | 0:796d0f61a05b | 109 | * Prints out first failure if POLARSSL_MEMORY_DEBUG is defined. |
HannesTschofenig | 0:796d0f61a05b | 110 | * Prints out full header information if POLARSSL_MEMORY_DEBUG_HEADERS |
HannesTschofenig | 0:796d0f61a05b | 111 | * is defined. (Includes stack trace information for each block if |
HannesTschofenig | 0:796d0f61a05b | 112 | * POLARSSL_MEMORY_BACKTRACE is defined as well). |
HannesTschofenig | 0:796d0f61a05b | 113 | * |
HannesTschofenig | 0:796d0f61a05b | 114 | * \returns 0 if verified, 1 otherwise |
HannesTschofenig | 0:796d0f61a05b | 115 | */ |
HannesTschofenig | 0:796d0f61a05b | 116 | int memory_buffer_alloc_verify( void ); |
HannesTschofenig | 0:796d0f61a05b | 117 | |
HannesTschofenig | 0:796d0f61a05b | 118 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 119 | } |
HannesTschofenig | 0:796d0f61a05b | 120 | #endif |
HannesTschofenig | 0:796d0f61a05b | 121 | |
HannesTschofenig | 0:796d0f61a05b | 122 | #endif /* memory_buffer_alloc.h */ |
HannesTschofenig | 0:796d0f61a05b | 123 | |
HannesTschofenig | 0:796d0f61a05b | 124 |