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 * Threading abstraction layer
HannesTschofenig 0:796d0f61a05b 3 *
HannesTschofenig 0:796d0f61a05b 4 * Copyright (C) 2006-2013, 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 #if !defined(POLARSSL_CONFIG_FILE)
HannesTschofenig 0:796d0f61a05b 27 #include "polarssl/config.h"
HannesTschofenig 0:796d0f61a05b 28 #else
HannesTschofenig 0:796d0f61a05b 29 #include POLARSSL_CONFIG_FILE
HannesTschofenig 0:796d0f61a05b 30 #endif
HannesTschofenig 0:796d0f61a05b 31
HannesTschofenig 0:796d0f61a05b 32 #if defined(POLARSSL_THREADING_C)
HannesTschofenig 0:796d0f61a05b 33
HannesTschofenig 0:796d0f61a05b 34 #include "polarssl/threading.h"
HannesTschofenig 0:796d0f61a05b 35
HannesTschofenig 0:796d0f61a05b 36 #if defined(POLARSSL_THREADING_PTHREAD)
HannesTschofenig 0:796d0f61a05b 37 static int threading_mutex_init_pthread( threading_mutex_t *mutex )
HannesTschofenig 0:796d0f61a05b 38 {
HannesTschofenig 0:796d0f61a05b 39 if( mutex == NULL )
HannesTschofenig 0:796d0f61a05b 40 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA );
HannesTschofenig 0:796d0f61a05b 41
HannesTschofenig 0:796d0f61a05b 42 if( pthread_mutex_init( mutex, NULL ) != 0 )
HannesTschofenig 0:796d0f61a05b 43 return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
HannesTschofenig 0:796d0f61a05b 44
HannesTschofenig 0:796d0f61a05b 45 return( 0 );
HannesTschofenig 0:796d0f61a05b 46 }
HannesTschofenig 0:796d0f61a05b 47
HannesTschofenig 0:796d0f61a05b 48 static int threading_mutex_free_pthread( threading_mutex_t *mutex )
HannesTschofenig 0:796d0f61a05b 49 {
HannesTschofenig 0:796d0f61a05b 50 if( mutex == NULL )
HannesTschofenig 0:796d0f61a05b 51 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA );
HannesTschofenig 0:796d0f61a05b 52
HannesTschofenig 0:796d0f61a05b 53 if( pthread_mutex_destroy( mutex ) != 0 )
HannesTschofenig 0:796d0f61a05b 54 return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
HannesTschofenig 0:796d0f61a05b 55
HannesTschofenig 0:796d0f61a05b 56 return( 0 );
HannesTschofenig 0:796d0f61a05b 57 }
HannesTschofenig 0:796d0f61a05b 58
HannesTschofenig 0:796d0f61a05b 59 static int threading_mutex_lock_pthread( threading_mutex_t *mutex )
HannesTschofenig 0:796d0f61a05b 60 {
HannesTschofenig 0:796d0f61a05b 61 if( mutex == NULL )
HannesTschofenig 0:796d0f61a05b 62 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA );
HannesTschofenig 0:796d0f61a05b 63
HannesTschofenig 0:796d0f61a05b 64 if( pthread_mutex_lock( mutex ) != 0 )
HannesTschofenig 0:796d0f61a05b 65 return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
HannesTschofenig 0:796d0f61a05b 66
HannesTschofenig 0:796d0f61a05b 67 return( 0 );
HannesTschofenig 0:796d0f61a05b 68 }
HannesTschofenig 0:796d0f61a05b 69
HannesTschofenig 0:796d0f61a05b 70 static int threading_mutex_unlock_pthread( threading_mutex_t *mutex )
HannesTschofenig 0:796d0f61a05b 71 {
HannesTschofenig 0:796d0f61a05b 72 if( mutex == NULL )
HannesTschofenig 0:796d0f61a05b 73 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA );
HannesTschofenig 0:796d0f61a05b 74
HannesTschofenig 0:796d0f61a05b 75 if( pthread_mutex_unlock( mutex ) != 0 )
HannesTschofenig 0:796d0f61a05b 76 return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
HannesTschofenig 0:796d0f61a05b 77
HannesTschofenig 0:796d0f61a05b 78 return( 0 );
HannesTschofenig 0:796d0f61a05b 79 }
HannesTschofenig 0:796d0f61a05b 80
HannesTschofenig 0:796d0f61a05b 81 int (*polarssl_mutex_init)( threading_mutex_t * ) = threading_mutex_init_pthread;
HannesTschofenig 0:796d0f61a05b 82 int (*polarssl_mutex_free)( threading_mutex_t * ) = threading_mutex_free_pthread;
HannesTschofenig 0:796d0f61a05b 83 int (*polarssl_mutex_lock)( threading_mutex_t * ) = threading_mutex_lock_pthread;
HannesTschofenig 0:796d0f61a05b 84 int (*polarssl_mutex_unlock)( threading_mutex_t * ) = threading_mutex_unlock_pthread;
HannesTschofenig 0:796d0f61a05b 85 #endif /* POLARSSL_THREADING_PTHREAD */
HannesTschofenig 0:796d0f61a05b 86
HannesTschofenig 0:796d0f61a05b 87 #if defined(POLARSSL_THREADING_ALT)
HannesTschofenig 0:796d0f61a05b 88 static int threading_mutex_fail( threading_mutex_t *mutex )
HannesTschofenig 0:796d0f61a05b 89 {
HannesTschofenig 0:796d0f61a05b 90 ((void) mutex );
HannesTschofenig 0:796d0f61a05b 91 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA );
HannesTschofenig 0:796d0f61a05b 92 }
HannesTschofenig 0:796d0f61a05b 93
HannesTschofenig 0:796d0f61a05b 94 int (*polarssl_mutex_init)( threading_mutex_t * ) = threading_mutex_fail;
HannesTschofenig 0:796d0f61a05b 95 int (*polarssl_mutex_free)( threading_mutex_t * ) = threading_mutex_fail;
HannesTschofenig 0:796d0f61a05b 96 int (*polarssl_mutex_lock)( threading_mutex_t * ) = threading_mutex_fail;
HannesTschofenig 0:796d0f61a05b 97 int (*polarssl_mutex_unlock)( threading_mutex_t * ) = threading_mutex_fail;
HannesTschofenig 0:796d0f61a05b 98
HannesTschofenig 0:796d0f61a05b 99 int threading_set_alt( int (*mutex_init)( threading_mutex_t * ),
HannesTschofenig 0:796d0f61a05b 100 int (*mutex_free)( threading_mutex_t * ),
HannesTschofenig 0:796d0f61a05b 101 int (*mutex_lock)( threading_mutex_t * ),
HannesTschofenig 0:796d0f61a05b 102 int (*mutex_unlock)( threading_mutex_t * ) )
HannesTschofenig 0:796d0f61a05b 103 {
HannesTschofenig 0:796d0f61a05b 104 polarssl_mutex_init = mutex_init;
HannesTschofenig 0:796d0f61a05b 105 polarssl_mutex_free = mutex_free;
HannesTschofenig 0:796d0f61a05b 106 polarssl_mutex_lock = mutex_lock;
HannesTschofenig 0:796d0f61a05b 107 polarssl_mutex_unlock = mutex_unlock;
HannesTschofenig 0:796d0f61a05b 108
HannesTschofenig 0:796d0f61a05b 109 return( 0 );
HannesTschofenig 0:796d0f61a05b 110 }
HannesTschofenig 0:796d0f61a05b 111 #endif /* POLARSSL_THREADING_ALT_C */
HannesTschofenig 0:796d0f61a05b 112
HannesTschofenig 0:796d0f61a05b 113 #endif /* POLARSSL_THREADING_C */
HannesTschofenig 0:796d0f61a05b 114
HannesTschofenig 0:796d0f61a05b 115