Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
Embed:
(wiki syntax)
Show/hide line numbers
threading.c
00001 /* 00002 * Threading abstraction layer 00003 * 00004 * Copyright (C) 2006-2013, Brainspark B.V. 00005 * 00006 * This file is part of PolarSSL (http://www.polarssl.org) 00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> 00008 * 00009 * All rights reserved. 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License along 00022 * with this program; if not, write to the Free Software Foundation, Inc., 00023 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 */ 00025 00026 #if !defined(POLARSSL_CONFIG_FILE) 00027 #include "polarssl/config.h" 00028 #else 00029 #include POLARSSL_CONFIG_FILE 00030 #endif 00031 00032 #if defined(POLARSSL_THREADING_C) 00033 00034 #include "polarssl/threading.h" 00035 00036 #if defined(POLARSSL_THREADING_PTHREAD) 00037 static int threading_mutex_init_pthread( threading_mutex_t *mutex ) 00038 { 00039 if( mutex == NULL ) 00040 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00041 00042 if( pthread_mutex_init( mutex, NULL ) != 0 ) 00043 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00044 00045 return( 0 ); 00046 } 00047 00048 static int threading_mutex_free_pthread( threading_mutex_t *mutex ) 00049 { 00050 if( mutex == NULL ) 00051 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00052 00053 if( pthread_mutex_destroy( mutex ) != 0 ) 00054 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00055 00056 return( 0 ); 00057 } 00058 00059 static int threading_mutex_lock_pthread( threading_mutex_t *mutex ) 00060 { 00061 if( mutex == NULL ) 00062 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00063 00064 if( pthread_mutex_lock( mutex ) != 0 ) 00065 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00066 00067 return( 0 ); 00068 } 00069 00070 static int threading_mutex_unlock_pthread( threading_mutex_t *mutex ) 00071 { 00072 if( mutex == NULL ) 00073 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00074 00075 if( pthread_mutex_unlock( mutex ) != 0 ) 00076 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00077 00078 return( 0 ); 00079 } 00080 00081 int (*polarssl_mutex_init)( threading_mutex_t * ) = threading_mutex_init_pthread; 00082 int (*polarssl_mutex_free)( threading_mutex_t * ) = threading_mutex_free_pthread; 00083 int (*polarssl_mutex_lock)( threading_mutex_t * ) = threading_mutex_lock_pthread; 00084 int (*polarssl_mutex_unlock)( threading_mutex_t * ) = threading_mutex_unlock_pthread; 00085 #endif /* POLARSSL_THREADING_PTHREAD */ 00086 00087 #if defined(POLARSSL_THREADING_ALT) 00088 static int threading_mutex_fail( threading_mutex_t *mutex ) 00089 { 00090 ((void) mutex ); 00091 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00092 } 00093 00094 int (*polarssl_mutex_init)( threading_mutex_t * ) = threading_mutex_fail; 00095 int (*polarssl_mutex_free)( threading_mutex_t * ) = threading_mutex_fail; 00096 int (*polarssl_mutex_lock)( threading_mutex_t * ) = threading_mutex_fail; 00097 int (*polarssl_mutex_unlock)( threading_mutex_t * ) = threading_mutex_fail; 00098 00099 int threading_set_alt( int (*mutex_init)( threading_mutex_t * ), 00100 int (*mutex_free)( threading_mutex_t * ), 00101 int (*mutex_lock)( threading_mutex_t * ), 00102 int (*mutex_unlock)( threading_mutex_t * ) ) 00103 { 00104 polarssl_mutex_init = mutex_init; 00105 polarssl_mutex_free = mutex_free; 00106 polarssl_mutex_lock = mutex_lock; 00107 polarssl_mutex_unlock = mutex_unlock; 00108 00109 return( 0 ); 00110 } 00111 #endif /* POLARSSL_THREADING_ALT_C */ 00112 00113 #endif /* POLARSSL_THREADING_C */ 00114 00115
Generated on Tue Jul 12 2022 19:40:21 by 1.7.2