Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

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?

UserRevisionLine numberNew contents of line
HannesTschofenig 0:796d0f61a05b 1 /*
HannesTschofenig 0:796d0f61a05b 2 * SSL session cache implementation
HannesTschofenig 0:796d0f61a05b 3 *
HannesTschofenig 0:796d0f61a05b 4 * Copyright (C) 2006-2014, Brainspark B.V.
HannesTschofenig 0:796d0f61a05b 5 *
HannesTschofenig 0:796d0f61a05b 6 * This file is part of PolarSSL (http://www.polarssl.org)
HannesTschofenig 0:796d0f61a05b 7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
HannesTschofenig 0:796d0f61a05b 8 *
HannesTschofenig 0:796d0f61a05b 9 * All rights reserved.
HannesTschofenig 0:796d0f61a05b 10 *
HannesTschofenig 0:796d0f61a05b 11 * This program is free software; you can redistribute it and/or modify
HannesTschofenig 0:796d0f61a05b 12 * it under the terms of the GNU General Public License as published by
HannesTschofenig 0:796d0f61a05b 13 * the Free Software Foundation; either version 2 of the License, or
HannesTschofenig 0:796d0f61a05b 14 * (at your option) any later version.
HannesTschofenig 0:796d0f61a05b 15 *
HannesTschofenig 0:796d0f61a05b 16 * This program is distributed in the hope that it will be useful,
HannesTschofenig 0:796d0f61a05b 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
HannesTschofenig 0:796d0f61a05b 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
HannesTschofenig 0:796d0f61a05b 19 * GNU General Public License for more details.
HannesTschofenig 0:796d0f61a05b 20 *
HannesTschofenig 0:796d0f61a05b 21 * You should have received a copy of the GNU General Public License along
HannesTschofenig 0:796d0f61a05b 22 * with this program; if not, write to the Free Software Foundation, Inc.,
HannesTschofenig 0:796d0f61a05b 23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
HannesTschofenig 0:796d0f61a05b 24 */
HannesTschofenig 0:796d0f61a05b 25 /*
HannesTschofenig 0:796d0f61a05b 26 * These session callbacks use a simple chained list
HannesTschofenig 0:796d0f61a05b 27 * to store and retrieve the session information.
HannesTschofenig 0:796d0f61a05b 28 */
HannesTschofenig 0:796d0f61a05b 29
HannesTschofenig 0:796d0f61a05b 30 #if !defined(POLARSSL_CONFIG_FILE)
HannesTschofenig 0:796d0f61a05b 31 #include "polarssl/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 #if defined(POLARSSL_SSL_CACHE_C)
HannesTschofenig 0:796d0f61a05b 37
HannesTschofenig 0:796d0f61a05b 38 #include "polarssl/ssl_cache.h"
HannesTschofenig 0:796d0f61a05b 39
HannesTschofenig 0:796d0f61a05b 40 #if defined(POLARSSL_PLATFORM_C)
HannesTschofenig 0:796d0f61a05b 41 #include "polarssl/platform.h"
HannesTschofenig 0:796d0f61a05b 42 #else
HannesTschofenig 0:796d0f61a05b 43 #define polarssl_malloc malloc
HannesTschofenig 0:796d0f61a05b 44 #define polarssl_free free
HannesTschofenig 0:796d0f61a05b 45 #endif
HannesTschofenig 0:796d0f61a05b 46
HannesTschofenig 0:796d0f61a05b 47 #include <stdlib.h>
HannesTschofenig 0:796d0f61a05b 48
HannesTschofenig 0:796d0f61a05b 49 void ssl_cache_init( ssl_cache_context *cache )
HannesTschofenig 0:796d0f61a05b 50 {
HannesTschofenig 0:796d0f61a05b 51 memset( cache, 0, sizeof( ssl_cache_context ) );
HannesTschofenig 0:796d0f61a05b 52
HannesTschofenig 0:796d0f61a05b 53 cache->timeout = SSL_CACHE_DEFAULT_TIMEOUT;
HannesTschofenig 0:796d0f61a05b 54 cache->max_entries = SSL_CACHE_DEFAULT_MAX_ENTRIES;
HannesTschofenig 0:796d0f61a05b 55
HannesTschofenig 0:796d0f61a05b 56 #if defined(POLARSSL_THREADING_C)
HannesTschofenig 0:796d0f61a05b 57 polarssl_mutex_init( &cache->mutex );
HannesTschofenig 0:796d0f61a05b 58 #endif
HannesTschofenig 0:796d0f61a05b 59 }
HannesTschofenig 0:796d0f61a05b 60
HannesTschofenig 0:796d0f61a05b 61 int ssl_cache_get( void *data, ssl_session *session )
HannesTschofenig 0:796d0f61a05b 62 {
HannesTschofenig 0:796d0f61a05b 63 int ret = 1;
HannesTschofenig 0:796d0f61a05b 64 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 65 time_t t = time( NULL );
HannesTschofenig 0:796d0f61a05b 66 #endif
HannesTschofenig 0:796d0f61a05b 67 ssl_cache_context *cache = (ssl_cache_context *) data;
HannesTschofenig 0:796d0f61a05b 68 ssl_cache_entry *cur, *entry;
HannesTschofenig 0:796d0f61a05b 69
HannesTschofenig 0:796d0f61a05b 70 #if defined(POLARSSL_THREADING_C)
HannesTschofenig 0:796d0f61a05b 71 if( polarssl_mutex_lock( &cache->mutex ) != 0 )
HannesTschofenig 0:796d0f61a05b 72 return( 1 );
HannesTschofenig 0:796d0f61a05b 73 #endif
HannesTschofenig 0:796d0f61a05b 74
HannesTschofenig 0:796d0f61a05b 75 cur = cache->chain;
HannesTschofenig 0:796d0f61a05b 76 entry = NULL;
HannesTschofenig 0:796d0f61a05b 77
HannesTschofenig 0:796d0f61a05b 78 while( cur != NULL )
HannesTschofenig 0:796d0f61a05b 79 {
HannesTschofenig 0:796d0f61a05b 80 entry = cur;
HannesTschofenig 0:796d0f61a05b 81 cur = cur->next;
HannesTschofenig 0:796d0f61a05b 82
HannesTschofenig 0:796d0f61a05b 83 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 84 if( cache->timeout != 0 &&
HannesTschofenig 0:796d0f61a05b 85 (int) ( t - entry->timestamp ) > cache->timeout )
HannesTschofenig 0:796d0f61a05b 86 continue;
HannesTschofenig 0:796d0f61a05b 87 #endif
HannesTschofenig 0:796d0f61a05b 88
HannesTschofenig 0:796d0f61a05b 89 if( session->ciphersuite != entry->session.ciphersuite ||
HannesTschofenig 0:796d0f61a05b 90 session->compression != entry->session.compression ||
HannesTschofenig 0:796d0f61a05b 91 session->length != entry->session.length )
HannesTschofenig 0:796d0f61a05b 92 continue;
HannesTschofenig 0:796d0f61a05b 93
HannesTschofenig 0:796d0f61a05b 94 if( memcmp( session->id, entry->session.id,
HannesTschofenig 0:796d0f61a05b 95 entry->session.length ) != 0 )
HannesTschofenig 0:796d0f61a05b 96 continue;
HannesTschofenig 0:796d0f61a05b 97
HannesTschofenig 0:796d0f61a05b 98 memcpy( session->master, entry->session.master, 48 );
HannesTschofenig 0:796d0f61a05b 99
HannesTschofenig 0:796d0f61a05b 100 session->verify_result = entry->session.verify_result;
HannesTschofenig 0:796d0f61a05b 101
HannesTschofenig 0:796d0f61a05b 102 #if defined(POLARSSL_X509_CRT_PARSE_C)
HannesTschofenig 0:796d0f61a05b 103 /*
HannesTschofenig 0:796d0f61a05b 104 * Restore peer certificate (without rest of the original chain)
HannesTschofenig 0:796d0f61a05b 105 */
HannesTschofenig 0:796d0f61a05b 106 if( entry->peer_cert.p != NULL )
HannesTschofenig 0:796d0f61a05b 107 {
HannesTschofenig 0:796d0f61a05b 108 session->peer_cert =
HannesTschofenig 0:796d0f61a05b 109 (x509_crt *) polarssl_malloc( sizeof(x509_crt) );
HannesTschofenig 0:796d0f61a05b 110
HannesTschofenig 0:796d0f61a05b 111 if( session->peer_cert == NULL )
HannesTschofenig 0:796d0f61a05b 112 {
HannesTschofenig 0:796d0f61a05b 113 ret = 1;
HannesTschofenig 0:796d0f61a05b 114 goto exit;
HannesTschofenig 0:796d0f61a05b 115 }
HannesTschofenig 0:796d0f61a05b 116
HannesTschofenig 0:796d0f61a05b 117 x509_crt_init( session->peer_cert );
HannesTschofenig 0:796d0f61a05b 118 if( x509_crt_parse( session->peer_cert, entry->peer_cert.p,
HannesTschofenig 0:796d0f61a05b 119 entry->peer_cert.len ) != 0 )
HannesTschofenig 0:796d0f61a05b 120 {
HannesTschofenig 0:796d0f61a05b 121 polarssl_free( session->peer_cert );
HannesTschofenig 0:796d0f61a05b 122 session->peer_cert = NULL;
HannesTschofenig 0:796d0f61a05b 123 ret = 1;
HannesTschofenig 0:796d0f61a05b 124 goto exit;
HannesTschofenig 0:796d0f61a05b 125 }
HannesTschofenig 0:796d0f61a05b 126 }
HannesTschofenig 0:796d0f61a05b 127 #endif /* POLARSSL_X509_CRT_PARSE_C */
HannesTschofenig 0:796d0f61a05b 128
HannesTschofenig 0:796d0f61a05b 129 ret = 0;
HannesTschofenig 0:796d0f61a05b 130 goto exit;
HannesTschofenig 0:796d0f61a05b 131 }
HannesTschofenig 0:796d0f61a05b 132
HannesTschofenig 0:796d0f61a05b 133 exit:
HannesTschofenig 0:796d0f61a05b 134 #if defined(POLARSSL_THREADING_C)
HannesTschofenig 0:796d0f61a05b 135 if( polarssl_mutex_unlock( &cache->mutex ) != 0 )
HannesTschofenig 0:796d0f61a05b 136 ret = 1;
HannesTschofenig 0:796d0f61a05b 137 #endif
HannesTschofenig 0:796d0f61a05b 138
HannesTschofenig 0:796d0f61a05b 139 return( ret );
HannesTschofenig 0:796d0f61a05b 140 }
HannesTschofenig 0:796d0f61a05b 141
HannesTschofenig 0:796d0f61a05b 142 int ssl_cache_set( void *data, const ssl_session *session )
HannesTschofenig 0:796d0f61a05b 143 {
HannesTschofenig 0:796d0f61a05b 144 int ret = 1;
HannesTschofenig 0:796d0f61a05b 145 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 146 time_t t = time( NULL ), oldest = 0;
HannesTschofenig 0:796d0f61a05b 147 ssl_cache_entry *old = NULL;
HannesTschofenig 0:796d0f61a05b 148 #endif
HannesTschofenig 0:796d0f61a05b 149 ssl_cache_context *cache = (ssl_cache_context *) data;
HannesTschofenig 0:796d0f61a05b 150 ssl_cache_entry *cur, *prv;
HannesTschofenig 0:796d0f61a05b 151 int count = 0;
HannesTschofenig 0:796d0f61a05b 152
HannesTschofenig 0:796d0f61a05b 153 #if defined(POLARSSL_THREADING_C)
HannesTschofenig 0:796d0f61a05b 154 if( ( ret = polarssl_mutex_lock( &cache->mutex ) ) != 0 )
HannesTschofenig 0:796d0f61a05b 155 return( ret );
HannesTschofenig 0:796d0f61a05b 156 #endif
HannesTschofenig 0:796d0f61a05b 157
HannesTschofenig 0:796d0f61a05b 158 cur = cache->chain;
HannesTschofenig 0:796d0f61a05b 159 prv = NULL;
HannesTschofenig 0:796d0f61a05b 160
HannesTschofenig 0:796d0f61a05b 161 while( cur != NULL )
HannesTschofenig 0:796d0f61a05b 162 {
HannesTschofenig 0:796d0f61a05b 163 count++;
HannesTschofenig 0:796d0f61a05b 164
HannesTschofenig 0:796d0f61a05b 165 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 166 if( cache->timeout != 0 &&
HannesTschofenig 0:796d0f61a05b 167 (int) ( t - cur->timestamp ) > cache->timeout )
HannesTschofenig 0:796d0f61a05b 168 {
HannesTschofenig 0:796d0f61a05b 169 cur->timestamp = t;
HannesTschofenig 0:796d0f61a05b 170 break; /* expired, reuse this slot, update timestamp */
HannesTschofenig 0:796d0f61a05b 171 }
HannesTschofenig 0:796d0f61a05b 172 #endif
HannesTschofenig 0:796d0f61a05b 173
HannesTschofenig 0:796d0f61a05b 174 if( memcmp( session->id, cur->session.id, cur->session.length ) == 0 )
HannesTschofenig 0:796d0f61a05b 175 break; /* client reconnected, keep timestamp for session id */
HannesTschofenig 0:796d0f61a05b 176
HannesTschofenig 0:796d0f61a05b 177 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 178 if( oldest == 0 || cur->timestamp < oldest )
HannesTschofenig 0:796d0f61a05b 179 {
HannesTschofenig 0:796d0f61a05b 180 oldest = cur->timestamp;
HannesTschofenig 0:796d0f61a05b 181 old = cur;
HannesTschofenig 0:796d0f61a05b 182 }
HannesTschofenig 0:796d0f61a05b 183 #endif
HannesTschofenig 0:796d0f61a05b 184
HannesTschofenig 0:796d0f61a05b 185 prv = cur;
HannesTschofenig 0:796d0f61a05b 186 cur = cur->next;
HannesTschofenig 0:796d0f61a05b 187 }
HannesTschofenig 0:796d0f61a05b 188
HannesTschofenig 0:796d0f61a05b 189 if( cur == NULL )
HannesTschofenig 0:796d0f61a05b 190 {
HannesTschofenig 0:796d0f61a05b 191 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 192 /*
HannesTschofenig 0:796d0f61a05b 193 * Reuse oldest entry if max_entries reached
HannesTschofenig 0:796d0f61a05b 194 */
HannesTschofenig 0:796d0f61a05b 195 if( count >= cache->max_entries )
HannesTschofenig 0:796d0f61a05b 196 {
HannesTschofenig 0:796d0f61a05b 197 if( old == NULL )
HannesTschofenig 0:796d0f61a05b 198 {
HannesTschofenig 0:796d0f61a05b 199 ret = 1;
HannesTschofenig 0:796d0f61a05b 200 goto exit;
HannesTschofenig 0:796d0f61a05b 201 }
HannesTschofenig 0:796d0f61a05b 202
HannesTschofenig 0:796d0f61a05b 203 cur = old;
HannesTschofenig 0:796d0f61a05b 204 }
HannesTschofenig 0:796d0f61a05b 205 #else /* POLARSSL_HAVE_TIME */
HannesTschofenig 0:796d0f61a05b 206 /*
HannesTschofenig 0:796d0f61a05b 207 * Reuse first entry in chain if max_entries reached,
HannesTschofenig 0:796d0f61a05b 208 * but move to last place
HannesTschofenig 0:796d0f61a05b 209 */
HannesTschofenig 0:796d0f61a05b 210 if( count >= cache->max_entries )
HannesTschofenig 0:796d0f61a05b 211 {
HannesTschofenig 0:796d0f61a05b 212 if( cache->chain == NULL )
HannesTschofenig 0:796d0f61a05b 213 {
HannesTschofenig 0:796d0f61a05b 214 ret = 1;
HannesTschofenig 0:796d0f61a05b 215 goto exit;
HannesTschofenig 0:796d0f61a05b 216 }
HannesTschofenig 0:796d0f61a05b 217
HannesTschofenig 0:796d0f61a05b 218 cur = cache->chain;
HannesTschofenig 0:796d0f61a05b 219 cache->chain = cur->next;
HannesTschofenig 0:796d0f61a05b 220 cur->next = NULL;
HannesTschofenig 0:796d0f61a05b 221 prv->next = cur;
HannesTschofenig 0:796d0f61a05b 222 }
HannesTschofenig 0:796d0f61a05b 223 #endif /* POLARSSL_HAVE_TIME */
HannesTschofenig 0:796d0f61a05b 224 else
HannesTschofenig 0:796d0f61a05b 225 {
HannesTschofenig 0:796d0f61a05b 226 /*
HannesTschofenig 0:796d0f61a05b 227 * max_entries not reached, create new entry
HannesTschofenig 0:796d0f61a05b 228 */
HannesTschofenig 0:796d0f61a05b 229 cur = (ssl_cache_entry *)
HannesTschofenig 0:796d0f61a05b 230 polarssl_malloc( sizeof(ssl_cache_entry) );
HannesTschofenig 0:796d0f61a05b 231 if( cur == NULL )
HannesTschofenig 0:796d0f61a05b 232 {
HannesTschofenig 0:796d0f61a05b 233 ret = 1;
HannesTschofenig 0:796d0f61a05b 234 goto exit;
HannesTschofenig 0:796d0f61a05b 235 }
HannesTschofenig 0:796d0f61a05b 236
HannesTschofenig 0:796d0f61a05b 237 memset( cur, 0, sizeof(ssl_cache_entry) );
HannesTschofenig 0:796d0f61a05b 238
HannesTschofenig 0:796d0f61a05b 239 if( prv == NULL )
HannesTschofenig 0:796d0f61a05b 240 cache->chain = cur;
HannesTschofenig 0:796d0f61a05b 241 else
HannesTschofenig 0:796d0f61a05b 242 prv->next = cur;
HannesTschofenig 0:796d0f61a05b 243 }
HannesTschofenig 0:796d0f61a05b 244
HannesTschofenig 0:796d0f61a05b 245 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 246 cur->timestamp = t;
HannesTschofenig 0:796d0f61a05b 247 #endif
HannesTschofenig 0:796d0f61a05b 248 }
HannesTschofenig 0:796d0f61a05b 249
HannesTschofenig 0:796d0f61a05b 250 memcpy( &cur->session, session, sizeof( ssl_session ) );
HannesTschofenig 0:796d0f61a05b 251
HannesTschofenig 0:796d0f61a05b 252 #if defined(POLARSSL_X509_CRT_PARSE_C)
HannesTschofenig 0:796d0f61a05b 253 /*
HannesTschofenig 0:796d0f61a05b 254 * If we're reusing an entry, free its certificate first
HannesTschofenig 0:796d0f61a05b 255 */
HannesTschofenig 0:796d0f61a05b 256 if( cur->peer_cert.p != NULL )
HannesTschofenig 0:796d0f61a05b 257 {
HannesTschofenig 0:796d0f61a05b 258 polarssl_free( cur->peer_cert.p );
HannesTschofenig 0:796d0f61a05b 259 memset( &cur->peer_cert, 0, sizeof(x509_buf) );
HannesTschofenig 0:796d0f61a05b 260 }
HannesTschofenig 0:796d0f61a05b 261
HannesTschofenig 0:796d0f61a05b 262 /*
HannesTschofenig 0:796d0f61a05b 263 * Store peer certificate
HannesTschofenig 0:796d0f61a05b 264 */
HannesTschofenig 0:796d0f61a05b 265 if( session->peer_cert != NULL )
HannesTschofenig 0:796d0f61a05b 266 {
HannesTschofenig 0:796d0f61a05b 267 cur->peer_cert.p = (unsigned char *)
HannesTschofenig 0:796d0f61a05b 268 polarssl_malloc( session->peer_cert->raw.len );
HannesTschofenig 0:796d0f61a05b 269 if( cur->peer_cert.p == NULL )
HannesTschofenig 0:796d0f61a05b 270 {
HannesTschofenig 0:796d0f61a05b 271 ret = 1;
HannesTschofenig 0:796d0f61a05b 272 goto exit;
HannesTschofenig 0:796d0f61a05b 273 }
HannesTschofenig 0:796d0f61a05b 274
HannesTschofenig 0:796d0f61a05b 275 memcpy( cur->peer_cert.p, session->peer_cert->raw.p,
HannesTschofenig 0:796d0f61a05b 276 session->peer_cert->raw.len );
HannesTschofenig 0:796d0f61a05b 277 cur->peer_cert.len = session->peer_cert->raw.len;
HannesTschofenig 0:796d0f61a05b 278
HannesTschofenig 0:796d0f61a05b 279 cur->session.peer_cert = NULL;
HannesTschofenig 0:796d0f61a05b 280 }
HannesTschofenig 0:796d0f61a05b 281 #endif /* POLARSSL_X509_CRT_PARSE_C */
HannesTschofenig 0:796d0f61a05b 282
HannesTschofenig 0:796d0f61a05b 283 ret = 0;
HannesTschofenig 0:796d0f61a05b 284
HannesTschofenig 0:796d0f61a05b 285 exit:
HannesTschofenig 0:796d0f61a05b 286 #if defined(POLARSSL_THREADING_C)
HannesTschofenig 0:796d0f61a05b 287 if( polarssl_mutex_unlock( &cache->mutex ) != 0 )
HannesTschofenig 0:796d0f61a05b 288 ret = 1;
HannesTschofenig 0:796d0f61a05b 289 #endif
HannesTschofenig 0:796d0f61a05b 290
HannesTschofenig 0:796d0f61a05b 291 return( ret );
HannesTschofenig 0:796d0f61a05b 292 }
HannesTschofenig 0:796d0f61a05b 293
HannesTschofenig 0:796d0f61a05b 294 #if defined(POLARSSL_HAVE_TIME)
HannesTschofenig 0:796d0f61a05b 295 void ssl_cache_set_timeout( ssl_cache_context *cache, int timeout )
HannesTschofenig 0:796d0f61a05b 296 {
HannesTschofenig 0:796d0f61a05b 297 if( timeout < 0 ) timeout = 0;
HannesTschofenig 0:796d0f61a05b 298
HannesTschofenig 0:796d0f61a05b 299 cache->timeout = timeout;
HannesTschofenig 0:796d0f61a05b 300 }
HannesTschofenig 0:796d0f61a05b 301 #endif /* POLARSSL_HAVE_TIME */
HannesTschofenig 0:796d0f61a05b 302
HannesTschofenig 0:796d0f61a05b 303 void ssl_cache_set_max_entries( ssl_cache_context *cache, int max )
HannesTschofenig 0:796d0f61a05b 304 {
HannesTschofenig 0:796d0f61a05b 305 if( max < 0 ) max = 0;
HannesTschofenig 0:796d0f61a05b 306
HannesTschofenig 0:796d0f61a05b 307 cache->max_entries = max;
HannesTschofenig 0:796d0f61a05b 308 }
HannesTschofenig 0:796d0f61a05b 309
HannesTschofenig 0:796d0f61a05b 310 void ssl_cache_free( ssl_cache_context *cache )
HannesTschofenig 0:796d0f61a05b 311 {
HannesTschofenig 0:796d0f61a05b 312 ssl_cache_entry *cur, *prv;
HannesTschofenig 0:796d0f61a05b 313
HannesTschofenig 0:796d0f61a05b 314 cur = cache->chain;
HannesTschofenig 0:796d0f61a05b 315
HannesTschofenig 0:796d0f61a05b 316 while( cur != NULL )
HannesTschofenig 0:796d0f61a05b 317 {
HannesTschofenig 0:796d0f61a05b 318 prv = cur;
HannesTschofenig 0:796d0f61a05b 319 cur = cur->next;
HannesTschofenig 0:796d0f61a05b 320
HannesTschofenig 0:796d0f61a05b 321 ssl_session_free( &prv->session );
HannesTschofenig 0:796d0f61a05b 322
HannesTschofenig 0:796d0f61a05b 323 #if defined(POLARSSL_X509_CRT_PARSE_C)
HannesTschofenig 0:796d0f61a05b 324 if( prv->peer_cert.p != NULL )
HannesTschofenig 0:796d0f61a05b 325 polarssl_free( prv->peer_cert.p );
HannesTschofenig 0:796d0f61a05b 326 #endif /* POLARSSL_X509_CRT_PARSE_C */
HannesTschofenig 0:796d0f61a05b 327
HannesTschofenig 0:796d0f61a05b 328 polarssl_free( prv );
HannesTschofenig 0:796d0f61a05b 329 }
HannesTschofenig 0:796d0f61a05b 330
HannesTschofenig 0:796d0f61a05b 331 #if defined(POLARSSL_THREADING_C)
HannesTschofenig 0:796d0f61a05b 332 polarssl_mutex_free( &cache->mutex );
HannesTschofenig 0:796d0f61a05b 333 #endif
HannesTschofenig 0:796d0f61a05b 334 }
HannesTschofenig 0:796d0f61a05b 335
HannesTschofenig 0:796d0f61a05b 336 #endif /* POLARSSL_SSL_CACHE_C */
HannesTschofenig 0:796d0f61a05b 337
HannesTschofenig 0:796d0f61a05b 338