Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Self-test demonstration program |
| 3 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 6 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 23 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 24 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 25 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 26 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 28 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 29 | #include "mbedtls/entropy.h" |
| 30 | #include "mbedtls/hmac_drbg.h" |
| 31 | #include "mbedtls/ctr_drbg.h" |
| 32 | #include "mbedtls/dhm.h" |
| 33 | #include "mbedtls/gcm.h" |
| 34 | #include "mbedtls/ccm.h" |
| 35 | #include "mbedtls/md2.h" |
| 36 | #include "mbedtls/md4.h" |
| 37 | #include "mbedtls/md5.h" |
| 38 | #include "mbedtls/ripemd160.h" |
| 39 | #include "mbedtls/sha1.h" |
| 40 | #include "mbedtls/sha256.h" |
| 41 | #include "mbedtls/sha512.h" |
| 42 | #include "mbedtls/arc4.h" |
| 43 | #include "mbedtls/des.h" |
| 44 | #include "mbedtls/aes.h" |
| 45 | #include "mbedtls/camellia.h" |
| 46 | #include "mbedtls/base64.h" |
| 47 | #include "mbedtls/bignum.h" |
| 48 | #include "mbedtls/rsa.h" |
| 49 | #include "mbedtls/x509.h" |
| 50 | #include "mbedtls/xtea.h" |
| 51 | #include "mbedtls/pkcs5.h" |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 52 | #include "mbedtls/ecp.h" |
| 53 | #include "mbedtls/timing.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 55 | #include <stdio.h> |
| 56 | #include <string.h> |
| 57 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 59 | #include "mbedtls/platform.h" |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 60 | #else |
| 61 | #include <stdio.h> |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | #define mbedtls_printf printf |
Manuel Pégourié-Gonnard | 7b6dcbe | 2015-06-22 10:48:01 +0200 | [diff] [blame] | 63 | #define mbedtls_snprintf snprintf |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 64 | #endif |
| 65 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 67 | #include "mbedtls/memory_buffer_alloc.h" |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 68 | #endif |
| 69 | |
Manuel Pégourié-Gonnard | 7b6dcbe | 2015-06-22 10:48:01 +0200 | [diff] [blame] | 70 | static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret ) |
| 71 | { |
| 72 | int ret; |
| 73 | char buf[10] = "xxxxxxxxx"; |
Manuel Pégourié-Gonnard | 4b00f08 | 2015-06-26 11:24:32 +0200 | [diff] [blame^] | 74 | const char ref[10] = "xxxxxxxxx"; |
Manuel Pégourié-Gonnard | 7b6dcbe | 2015-06-22 10:48:01 +0200 | [diff] [blame] | 75 | |
| 76 | ret = mbedtls_snprintf( buf, n, "%s", "123" ); |
| 77 | if( ret < 0 || (size_t) ret >= n ) |
| 78 | ret = -1; |
| 79 | |
Manuel Pégourié-Gonnard | 4b00f08 | 2015-06-26 11:24:32 +0200 | [diff] [blame^] | 80 | if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 || |
| 81 | ref_ret != ret || |
| 82 | memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 ) |
Manuel Pégourié-Gonnard | 7b6dcbe | 2015-06-22 10:48:01 +0200 | [diff] [blame] | 83 | { |
| 84 | return( 1 ); |
| 85 | } |
| 86 | |
| 87 | return( 0 ); |
| 88 | } |
| 89 | |
| 90 | static int run_test_snprintf( void ) |
| 91 | { |
| 92 | return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 || |
Manuel Pégourié-Gonnard | 4b00f08 | 2015-06-26 11:24:32 +0200 | [diff] [blame^] | 93 | test_snprintf( 1, "", -1 ) != 0 || |
| 94 | test_snprintf( 2, "1", -1 ) != 0 || |
| 95 | test_snprintf( 3, "12", -1 ) != 0 || |
| 96 | test_snprintf( 4, "123", 3 ) != 0 || |
| 97 | test_snprintf( 5, "123", 3 ) != 0 ); |
Manuel Pégourié-Gonnard | 7b6dcbe | 2015-06-22 10:48:01 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 100 | int main( int argc, char *argv[] ) |
| 101 | { |
Paul Bakker | 135b98e | 2011-05-25 11:13:47 +0000 | [diff] [blame] | 102 | int ret = 0, v; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 103 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 104 | unsigned char buf[1000000]; |
| 105 | #endif |
Manuel Pégourié-Gonnard | d14acbc | 2015-05-29 11:26:37 +0200 | [diff] [blame] | 106 | void *pointer; |
| 107 | |
| 108 | /* |
| 109 | * The C standard doesn't guarantee that all-bits-0 is the representation |
| 110 | * of a NULL pointer. We do however use that in our code for initializing |
| 111 | * structures, which should work on every modern platform. Let's be sure. |
| 112 | */ |
| 113 | memset( &pointer, 0, sizeof( void * ) ); |
| 114 | if( pointer != NULL ) |
| 115 | { |
| 116 | mbedtls_printf( "all-bits-zero is not a NULL pointer\n" ); |
| 117 | return( 1 ); |
| 118 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | |
Manuel Pégourié-Gonnard | 7b6dcbe | 2015-06-22 10:48:01 +0200 | [diff] [blame] | 120 | /* |
| 121 | * Make sure we have a snprintf that correctly zero-terminates |
| 122 | */ |
| 123 | if( run_test_snprintf() != 0 ) |
| 124 | { |
| 125 | mbedtls_printf( "the snprintf implementation is broken\n" ); |
| 126 | return( 0 ); |
| 127 | } |
| 128 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 129 | if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 ) |
| 130 | v = 0; |
| 131 | else |
| 132 | { |
| 133 | v = 1; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 134 | mbedtls_printf( "\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 137 | #if defined(MBEDTLS_SELF_TEST) |
Paul Bakker | 135b98e | 2011-05-25 11:13:47 +0000 | [diff] [blame] | 138 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 139 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
| 140 | mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) ); |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 141 | #endif |
| 142 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 143 | #if defined(MBEDTLS_MD2_C) |
| 144 | if( ( ret = mbedtls_md2_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 145 | return( ret ); |
| 146 | #endif |
| 147 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 148 | #if defined(MBEDTLS_MD4_C) |
| 149 | if( ( ret = mbedtls_md4_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 150 | return( ret ); |
| 151 | #endif |
| 152 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 153 | #if defined(MBEDTLS_MD5_C) |
| 154 | if( ( ret = mbedtls_md5_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 155 | return( ret ); |
| 156 | #endif |
| 157 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 158 | #if defined(MBEDTLS_RIPEMD160_C) |
| 159 | if( ( ret = mbedtls_ripemd160_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | 1744d72 | 2014-01-17 14:44:38 +0100 | [diff] [blame] | 160 | return( ret ); |
| 161 | #endif |
| 162 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 163 | #if defined(MBEDTLS_SHA1_C) |
| 164 | if( ( ret = mbedtls_sha1_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 165 | return( ret ); |
| 166 | #endif |
| 167 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 168 | #if defined(MBEDTLS_SHA256_C) |
| 169 | if( ( ret = mbedtls_sha256_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 170 | return( ret ); |
| 171 | #endif |
| 172 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 173 | #if defined(MBEDTLS_SHA512_C) |
| 174 | if( ( ret = mbedtls_sha512_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 175 | return( ret ); |
| 176 | #endif |
| 177 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 178 | #if defined(MBEDTLS_ARC4_C) |
| 179 | if( ( ret = mbedtls_arc4_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 180 | return( ret ); |
| 181 | #endif |
| 182 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 183 | #if defined(MBEDTLS_DES_C) |
| 184 | if( ( ret = mbedtls_des_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 185 | return( ret ); |
| 186 | #endif |
| 187 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 188 | #if defined(MBEDTLS_AES_C) |
| 189 | if( ( ret = mbedtls_aes_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 190 | return( ret ); |
| 191 | #endif |
| 192 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 193 | #if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C) |
| 194 | if( ( ret = mbedtls_gcm_self_test( v ) ) != 0 ) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 195 | return( ret ); |
| 196 | #endif |
| 197 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 198 | #if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C) |
| 199 | if( ( ret = mbedtls_ccm_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 200 | return( ret ); |
| 201 | #endif |
| 202 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 203 | #if defined(MBEDTLS_BASE64_C) |
| 204 | if( ( ret = mbedtls_base64_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 205 | return( ret ); |
| 206 | #endif |
| 207 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 208 | #if defined(MBEDTLS_BIGNUM_C) |
| 209 | if( ( ret = mbedtls_mpi_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 210 | return( ret ); |
| 211 | #endif |
| 212 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 213 | #if defined(MBEDTLS_RSA_C) |
| 214 | if( ( ret = mbedtls_rsa_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 215 | return( ret ); |
| 216 | #endif |
| 217 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 218 | #if defined(MBEDTLS_X509_USE_C) |
| 219 | if( ( ret = mbedtls_x509_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 220 | return( ret ); |
| 221 | #endif |
| 222 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | #if defined(MBEDTLS_XTEA_C) |
| 224 | if( ( ret = mbedtls_xtea_self_test( v ) ) != 0 ) |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 225 | return( ret ); |
| 226 | #endif |
| 227 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 228 | #if defined(MBEDTLS_CAMELLIA_C) |
| 229 | if( ( ret = mbedtls_camellia_self_test( v ) ) != 0 ) |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 230 | return( ret ); |
| 231 | #endif |
| 232 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 233 | #if defined(MBEDTLS_CTR_DRBG_C) |
| 234 | if( ( ret = mbedtls_ctr_drbg_self_test( v ) ) != 0 ) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 235 | return( ret ); |
| 236 | #endif |
| 237 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 238 | #if defined(MBEDTLS_HMAC_DRBG_C) |
| 239 | if( ( ret = mbedtls_hmac_drbg_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | 79afaa0 | 2014-01-31 11:12:09 +0100 | [diff] [blame] | 240 | return( ret ); |
| 241 | #endif |
| 242 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 243 | #if defined(MBEDTLS_ECP_C) |
| 244 | if( ( ret = mbedtls_ecp_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | b4a310b | 2012-11-13 20:57:00 +0100 | [diff] [blame] | 245 | return( ret ); |
| 246 | #endif |
| 247 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 248 | #if defined(MBEDTLS_DHM_C) |
| 249 | if( ( ret = mbedtls_dhm_self_test( v ) ) != 0 ) |
Paul Bakker | 40ce79f | 2013-09-15 17:43:54 +0200 | [diff] [blame] | 250 | return( ret ); |
| 251 | #endif |
| 252 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 253 | #if defined(MBEDTLS_ENTROPY_C) |
| 254 | if( ( ret = mbedtls_entropy_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | 4dd7392 | 2014-05-30 10:34:15 +0200 | [diff] [blame] | 255 | return( ret ); |
| 256 | #endif |
| 257 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 258 | #if defined(MBEDTLS_PKCS5_C) |
| 259 | if( ( ret = mbedtls_pkcs5_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | 13a1ef8 | 2014-03-27 20:12:44 +0100 | [diff] [blame] | 260 | return( ret ); |
| 261 | #endif |
Manuel Pégourié-Gonnard | b6b16bd | 2015-03-11 11:20:43 +0000 | [diff] [blame] | 262 | |
| 263 | /* Slow tests last */ |
Manuel Pégourié-Gonnard | 13a1ef8 | 2014-03-27 20:12:44 +0100 | [diff] [blame] | 264 | |
Manuel Pégourié-Gonnard | 7680698 | 2014-06-13 18:04:42 +0200 | [diff] [blame] | 265 | /* Not stable enough on Windows and FreeBSD yet */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 266 | #if __linux__ && defined(MBEDTLS_TIMING_C) |
| 267 | if( ( ret = mbedtls_timing_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | 470fc93 | 2014-03-27 20:07:08 +0100 | [diff] [blame] | 268 | return( ret ); |
| 269 | #endif |
| 270 | |
Paul Bakker | 135b98e | 2011-05-25 11:13:47 +0000 | [diff] [blame] | 271 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 272 | mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" ); |
Paul Bakker | 135b98e | 2011-05-25 11:13:47 +0000 | [diff] [blame] | 273 | #endif |
| 274 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 275 | if( v != 0 ) |
| 276 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 277 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG) |
| 278 | mbedtls_memory_buffer_alloc_status(); |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 279 | #endif |
Manuel Pégourié-Gonnard | 5ba1d52 | 2014-11-27 11:33:55 +0100 | [diff] [blame] | 280 | } |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 281 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 282 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
| 283 | mbedtls_memory_buffer_alloc_free(); |
Manuel Pégourié-Gonnard | 5ba1d52 | 2014-11-27 11:33:55 +0100 | [diff] [blame] | 284 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 285 | if( ( ret = mbedtls_memory_buffer_alloc_self_test( v ) ) != 0 ) |
Manuel Pégourié-Gonnard | 5ba1d52 | 2014-11-27 11:33:55 +0100 | [diff] [blame] | 286 | return( ret ); |
| 287 | #endif |
| 288 | |
| 289 | if( v != 0 ) |
| 290 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 291 | mbedtls_printf( " [ All tests passed ]\n\n" ); |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 292 | #if defined(_WIN32) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 293 | mbedtls_printf( " Press Enter to exit this program.\n" ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 294 | fflush( stdout ); getchar(); |
| 295 | #endif |
| 296 | } |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 297 | |
| 298 | return( ret ); |
| 299 | } |