Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
SSL/include/polarssl/ssl_cache.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 ssl_cache.h |
HannesTschofenig | 0:796d0f61a05b | 3 | * |
HannesTschofenig | 0:796d0f61a05b | 4 | * \brief SSL session cache implementation |
HannesTschofenig | 0:796d0f61a05b | 5 | * |
HannesTschofenig | 0:796d0f61a05b | 6 | * Copyright (C) 2006-2013, 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_SSL_CACHE_H |
HannesTschofenig | 0:796d0f61a05b | 28 | #define POLARSSL_SSL_CACHE_H |
HannesTschofenig | 0:796d0f61a05b | 29 | |
HannesTschofenig | 0:796d0f61a05b | 30 | #include "ssl.h" |
HannesTschofenig | 0:796d0f61a05b | 31 | |
HannesTschofenig | 0:796d0f61a05b | 32 | #if defined(POLARSSL_THREADING_C) |
HannesTschofenig | 0:796d0f61a05b | 33 | #include "threading.h" |
HannesTschofenig | 0:796d0f61a05b | 34 | #endif |
HannesTschofenig | 0:796d0f61a05b | 35 | |
HannesTschofenig | 0:796d0f61a05b | 36 | /** |
HannesTschofenig | 0:796d0f61a05b | 37 | * \name SECTION: Module settings |
HannesTschofenig | 0:796d0f61a05b | 38 | * |
HannesTschofenig | 0:796d0f61a05b | 39 | * The configuration options you can set for this module are in this section. |
HannesTschofenig | 0:796d0f61a05b | 40 | * Either change them in config.h or define them on the compiler command line. |
HannesTschofenig | 0:796d0f61a05b | 41 | * \{ |
HannesTschofenig | 0:796d0f61a05b | 42 | */ |
HannesTschofenig | 0:796d0f61a05b | 43 | |
HannesTschofenig | 0:796d0f61a05b | 44 | #if !defined(SSL_CACHE_DEFAULT_TIMEOUT) |
HannesTschofenig | 0:796d0f61a05b | 45 | #define SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */ |
HannesTschofenig | 0:796d0f61a05b | 46 | #endif |
HannesTschofenig | 0:796d0f61a05b | 47 | |
HannesTschofenig | 0:796d0f61a05b | 48 | #if !defined(SSL_CACHE_DEFAULT_MAX_ENTRIES) |
HannesTschofenig | 0:796d0f61a05b | 49 | #define SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */ |
HannesTschofenig | 0:796d0f61a05b | 50 | #endif |
HannesTschofenig | 0:796d0f61a05b | 51 | |
HannesTschofenig | 0:796d0f61a05b | 52 | /* \} name SECTION: Module settings */ |
HannesTschofenig | 0:796d0f61a05b | 53 | |
HannesTschofenig | 0:796d0f61a05b | 54 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 55 | extern "C" { |
HannesTschofenig | 0:796d0f61a05b | 56 | #endif |
HannesTschofenig | 0:796d0f61a05b | 57 | |
HannesTschofenig | 0:796d0f61a05b | 58 | typedef struct _ssl_cache_context ssl_cache_context; |
HannesTschofenig | 0:796d0f61a05b | 59 | typedef struct _ssl_cache_entry ssl_cache_entry; |
HannesTschofenig | 0:796d0f61a05b | 60 | |
HannesTschofenig | 0:796d0f61a05b | 61 | /** |
HannesTschofenig | 0:796d0f61a05b | 62 | * \brief This structure is used for storing cache entries |
HannesTschofenig | 0:796d0f61a05b | 63 | */ |
HannesTschofenig | 0:796d0f61a05b | 64 | struct _ssl_cache_entry |
HannesTschofenig | 0:796d0f61a05b | 65 | { |
HannesTschofenig | 0:796d0f61a05b | 66 | #if defined(POLARSSL_HAVE_TIME) |
HannesTschofenig | 0:796d0f61a05b | 67 | time_t timestamp; /*!< entry timestamp */ |
HannesTschofenig | 0:796d0f61a05b | 68 | #endif |
HannesTschofenig | 0:796d0f61a05b | 69 | ssl_session session; /*!< entry session */ |
HannesTschofenig | 0:796d0f61a05b | 70 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
HannesTschofenig | 0:796d0f61a05b | 71 | x509_buf peer_cert; /*!< entry peer_cert */ |
HannesTschofenig | 0:796d0f61a05b | 72 | #endif |
HannesTschofenig | 0:796d0f61a05b | 73 | ssl_cache_entry *next; /*!< chain pointer */ |
HannesTschofenig | 0:796d0f61a05b | 74 | }; |
HannesTschofenig | 0:796d0f61a05b | 75 | |
HannesTschofenig | 0:796d0f61a05b | 76 | /** |
HannesTschofenig | 0:796d0f61a05b | 77 | * \brief Cache context |
HannesTschofenig | 0:796d0f61a05b | 78 | */ |
HannesTschofenig | 0:796d0f61a05b | 79 | struct _ssl_cache_context |
HannesTschofenig | 0:796d0f61a05b | 80 | { |
HannesTschofenig | 0:796d0f61a05b | 81 | ssl_cache_entry *chain; /*!< start of the chain */ |
HannesTschofenig | 0:796d0f61a05b | 82 | int timeout; /*!< cache entry timeout */ |
HannesTschofenig | 0:796d0f61a05b | 83 | int max_entries; /*!< maximum entries */ |
HannesTschofenig | 0:796d0f61a05b | 84 | #if defined(POLARSSL_THREADING_C) |
HannesTschofenig | 0:796d0f61a05b | 85 | threading_mutex_t mutex; /*!< mutex */ |
HannesTschofenig | 0:796d0f61a05b | 86 | #endif |
HannesTschofenig | 0:796d0f61a05b | 87 | }; |
HannesTschofenig | 0:796d0f61a05b | 88 | |
HannesTschofenig | 0:796d0f61a05b | 89 | /** |
HannesTschofenig | 0:796d0f61a05b | 90 | * \brief Initialize an SSL cache context |
HannesTschofenig | 0:796d0f61a05b | 91 | * |
HannesTschofenig | 0:796d0f61a05b | 92 | * \param cache SSL cache context |
HannesTschofenig | 0:796d0f61a05b | 93 | */ |
HannesTschofenig | 0:796d0f61a05b | 94 | void ssl_cache_init( ssl_cache_context *cache ); |
HannesTschofenig | 0:796d0f61a05b | 95 | |
HannesTschofenig | 0:796d0f61a05b | 96 | /** |
HannesTschofenig | 0:796d0f61a05b | 97 | * \brief Cache get callback implementation |
HannesTschofenig | 0:796d0f61a05b | 98 | * (Thread-safe if POLARSSL_THREADING_C is enabled) |
HannesTschofenig | 0:796d0f61a05b | 99 | * |
HannesTschofenig | 0:796d0f61a05b | 100 | * \param data SSL cache context |
HannesTschofenig | 0:796d0f61a05b | 101 | * \param session session to retrieve entry for |
HannesTschofenig | 0:796d0f61a05b | 102 | */ |
HannesTschofenig | 0:796d0f61a05b | 103 | int ssl_cache_get( void *data, ssl_session *session ); |
HannesTschofenig | 0:796d0f61a05b | 104 | |
HannesTschofenig | 0:796d0f61a05b | 105 | /** |
HannesTschofenig | 0:796d0f61a05b | 106 | * \brief Cache set callback implementation |
HannesTschofenig | 0:796d0f61a05b | 107 | * (Thread-safe if POLARSSL_THREADING_C is enabled) |
HannesTschofenig | 0:796d0f61a05b | 108 | * |
HannesTschofenig | 0:796d0f61a05b | 109 | * \param data SSL cache context |
HannesTschofenig | 0:796d0f61a05b | 110 | * \param session session to store entry for |
HannesTschofenig | 0:796d0f61a05b | 111 | */ |
HannesTschofenig | 0:796d0f61a05b | 112 | int ssl_cache_set( void *data, const ssl_session *session ); |
HannesTschofenig | 0:796d0f61a05b | 113 | |
HannesTschofenig | 0:796d0f61a05b | 114 | #if defined(POLARSSL_HAVE_TIME) |
HannesTschofenig | 0:796d0f61a05b | 115 | /** |
HannesTschofenig | 0:796d0f61a05b | 116 | * \brief Set the cache timeout |
HannesTschofenig | 0:796d0f61a05b | 117 | * (Default: SSL_CACHE_DEFAULT_TIMEOUT (1 day)) |
HannesTschofenig | 0:796d0f61a05b | 118 | * |
HannesTschofenig | 0:796d0f61a05b | 119 | * A timeout of 0 indicates no timeout. |
HannesTschofenig | 0:796d0f61a05b | 120 | * |
HannesTschofenig | 0:796d0f61a05b | 121 | * \param cache SSL cache context |
HannesTschofenig | 0:796d0f61a05b | 122 | * \param timeout cache entry timeout in seconds |
HannesTschofenig | 0:796d0f61a05b | 123 | */ |
HannesTschofenig | 0:796d0f61a05b | 124 | void ssl_cache_set_timeout( ssl_cache_context *cache, int timeout ); |
HannesTschofenig | 0:796d0f61a05b | 125 | #endif /* POLARSSL_HAVE_TIME */ |
HannesTschofenig | 0:796d0f61a05b | 126 | |
HannesTschofenig | 0:796d0f61a05b | 127 | /** |
HannesTschofenig | 0:796d0f61a05b | 128 | * \brief Set the cache timeout |
HannesTschofenig | 0:796d0f61a05b | 129 | * (Default: SSL_CACHE_DEFAULT_MAX_ENTRIES (50)) |
HannesTschofenig | 0:796d0f61a05b | 130 | * |
HannesTschofenig | 0:796d0f61a05b | 131 | * \param cache SSL cache context |
HannesTschofenig | 0:796d0f61a05b | 132 | * \param max cache entry maximum |
HannesTschofenig | 0:796d0f61a05b | 133 | */ |
HannesTschofenig | 0:796d0f61a05b | 134 | void ssl_cache_set_max_entries( ssl_cache_context *cache, int max ); |
HannesTschofenig | 0:796d0f61a05b | 135 | |
HannesTschofenig | 0:796d0f61a05b | 136 | /** |
HannesTschofenig | 0:796d0f61a05b | 137 | * \brief Free referenced items in a cache context and clear memory |
HannesTschofenig | 0:796d0f61a05b | 138 | * |
HannesTschofenig | 0:796d0f61a05b | 139 | * \param cache SSL cache context |
HannesTschofenig | 0:796d0f61a05b | 140 | */ |
HannesTschofenig | 0:796d0f61a05b | 141 | void ssl_cache_free( ssl_cache_context *cache ); |
HannesTschofenig | 0:796d0f61a05b | 142 | |
HannesTschofenig | 0:796d0f61a05b | 143 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 144 | } |
HannesTschofenig | 0:796d0f61a05b | 145 | #endif |
HannesTschofenig | 0:796d0f61a05b | 146 | |
HannesTschofenig | 0:796d0f61a05b | 147 | #endif /* ssl_cache.h */ |
HannesTschofenig | 0:796d0f61a05b | 148 | |
HannesTschofenig | 0:796d0f61a05b | 149 |