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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers platform.c Source File

platform.c

00001 /*
00002  *  Platform abstraction layer
00003  *
00004  *  Copyright (C) 2006-2014, 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_PLATFORM_C)
00033 
00034 #include "polarssl/platform.h"
00035 
00036 #if defined(POLARSSL_PLATFORM_MEMORY)
00037 #if !defined(POLARSSL_PLATFORM_STD_MALLOC)
00038 static void *platform_malloc_uninit( size_t len )
00039 {
00040     ((void) len);
00041     return( NULL );
00042 }
00043 
00044 #define POLARSSL_PLATFORM_STD_MALLOC   platform_malloc_uninit
00045 #endif /* !POLARSSL_PLATFORM_STD_MALLOC */
00046 
00047 #if !defined(POLARSSL_PLATFORM_STD_FREE)
00048 static void platform_free_uninit( void *ptr )
00049 {
00050     ((void) ptr);
00051 }
00052 
00053 #define POLARSSL_PLATFORM_STD_FREE     platform_free_uninit
00054 #endif /* !POLARSSL_PLATFORM_STD_FREE */
00055 
00056 void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC;
00057 void (*polarssl_free)( void * )     = POLARSSL_PLATFORM_STD_FREE;
00058 
00059 int platform_set_malloc_free( void * (*malloc_func)( size_t ),
00060                               void (*free_func)( void * ) )
00061 {
00062     polarssl_malloc = malloc_func;
00063     polarssl_free = free_func;
00064     return( 0 );
00065 }
00066 #endif /* POLARSSL_PLATFORM_MEMORY */
00067 
00068 #if defined(POLARSSL_PLATFORM_PRINTF_ALT)
00069 #if !defined(POLARSSL_PLATFORM_STD_PRINTF)
00070 /*
00071  * Make dummy function to prevent NULL pointer dereferences
00072  */
00073 static int platform_printf_uninit( const char *format, ... )
00074 {
00075     ((void) format);
00076     return( 0 );
00077 }
00078 
00079 #define POLARSSL_PLATFORM_STD_PRINTF    platform_printf_uninit
00080 #endif /* !POLARSSL_PLATFORM_STD_PRINTF */
00081 
00082 int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF;
00083 
00084 int platform_set_printf( int (*printf_func)( const char *, ... ) )
00085 {
00086     polarssl_printf = printf_func;
00087     return( 0 );
00088 }
00089 #endif /* POLARSSL_PLATFORM_PRINTF_ALT */
00090 
00091 #if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
00092 #if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
00093 /*
00094  * Make dummy function to prevent NULL pointer dereferences
00095  */
00096 static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
00097 {
00098     ((void) stream);
00099     ((void) format);
00100     return( 0 );
00101 }
00102 
00103 #define POLARSSL_PLATFORM_STD_FPRINTF   platform_fprintf_uninit
00104 #endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
00105 
00106 int (*polarssl_fprintf)( FILE *, const char *, ... ) =
00107                                         POLARSSL_PLATFORM_STD_FPRINTF;
00108 
00109 int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
00110 {
00111     polarssl_fprintf = fprintf_func;
00112     return( 0 );
00113 }
00114 #endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
00115 
00116 #endif /* POLARSSL_PLATFORM_C */
00117 
00118