Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Self-test demonstration program |
| 3 | * |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2011, Brainspark B.V. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 5 | * |
| 6 | * This file is part of PolarSSL (http://www.polarssl.org) |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 8 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 9 | * All rights reserved. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 10 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | */ |
| 25 | |
| 26 | #ifndef _CRT_SECURE_NO_DEPRECATE |
| 27 | #define _CRT_SECURE_NO_DEPRECATE 1 |
| 28 | #endif |
| 29 | |
| 30 | #include <string.h> |
| 31 | #include <stdio.h> |
| 32 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 33 | #include "polarssl/config.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 34 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 35 | #include "polarssl/ctr_drbg.h" |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 36 | #include "polarssl/gcm.h" |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 37 | #include "polarssl/md2.h" |
| 38 | #include "polarssl/md4.h" |
| 39 | #include "polarssl/md5.h" |
| 40 | #include "polarssl/sha1.h" |
| 41 | #include "polarssl/sha2.h" |
| 42 | #include "polarssl/sha4.h" |
| 43 | #include "polarssl/arc4.h" |
| 44 | #include "polarssl/des.h" |
| 45 | #include "polarssl/aes.h" |
Paul Bakker | 026c03b | 2009-03-28 17:53:03 +0000 | [diff] [blame] | 46 | #include "polarssl/camellia.h" |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 47 | #include "polarssl/base64.h" |
| 48 | #include "polarssl/bignum.h" |
| 49 | #include "polarssl/rsa.h" |
| 50 | #include "polarssl/x509.h" |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 51 | #include "polarssl/xtea.h" |
Paul Bakker | f518b16 | 2012-08-23 13:03:18 +0000 | [diff] [blame] | 52 | #include "polarssl/pbkdf2.h" |
Manuel Pégourié-Gonnard | b4a310b | 2012-11-13 20:57:00 +0100 | [diff] [blame] | 53 | #include "polarssl/ecp.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | |
| 55 | int main( int argc, char *argv[] ) |
| 56 | { |
Paul Bakker | 135b98e | 2011-05-25 11:13:47 +0000 | [diff] [blame] | 57 | int ret = 0, v; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 58 | |
| 59 | if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 ) |
| 60 | v = 0; |
| 61 | else |
| 62 | { |
| 63 | v = 1; |
| 64 | printf( "\n" ); |
| 65 | } |
| 66 | |
Paul Bakker | 135b98e | 2011-05-25 11:13:47 +0000 | [diff] [blame] | 67 | #if defined(POLARSSL_SELF_TEST) |
| 68 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 69 | #if defined(POLARSSL_MD2_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 70 | if( ( ret = md2_self_test( v ) ) != 0 ) |
| 71 | return( ret ); |
| 72 | #endif |
| 73 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 74 | #if defined(POLARSSL_MD4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 75 | if( ( ret = md4_self_test( v ) ) != 0 ) |
| 76 | return( ret ); |
| 77 | #endif |
| 78 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 79 | #if defined(POLARSSL_MD5_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 80 | if( ( ret = md5_self_test( v ) ) != 0 ) |
| 81 | return( ret ); |
| 82 | #endif |
| 83 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 84 | #if defined(POLARSSL_SHA1_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 85 | if( ( ret = sha1_self_test( v ) ) != 0 ) |
| 86 | return( ret ); |
| 87 | #endif |
| 88 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame^] | 89 | #if defined(POLARSSL_SHA256_C) |
| 90 | if( ( ret = sha256_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 91 | return( ret ); |
| 92 | #endif |
| 93 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame^] | 94 | #if defined(POLARSSL_SHA512_C) |
| 95 | if( ( ret = sha512_self_test( v ) ) != 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 96 | return( ret ); |
| 97 | #endif |
| 98 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 99 | #if defined(POLARSSL_ARC4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 100 | if( ( ret = arc4_self_test( v ) ) != 0 ) |
| 101 | return( ret ); |
| 102 | #endif |
| 103 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 104 | #if defined(POLARSSL_DES_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 105 | if( ( ret = des_self_test( v ) ) != 0 ) |
| 106 | return( ret ); |
| 107 | #endif |
| 108 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 109 | #if defined(POLARSSL_AES_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 110 | if( ( ret = aes_self_test( v ) ) != 0 ) |
| 111 | return( ret ); |
| 112 | #endif |
| 113 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 114 | #if defined(POLARSSL_GCM_C) |
| 115 | if( ( ret = gcm_self_test( v ) ) != 0 ) |
| 116 | return( ret ); |
| 117 | #endif |
| 118 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 119 | #if defined(POLARSSL_BASE64_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 120 | if( ( ret = base64_self_test( v ) ) != 0 ) |
| 121 | return( ret ); |
| 122 | #endif |
| 123 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 124 | #if defined(POLARSSL_BIGNUM_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 125 | if( ( ret = mpi_self_test( v ) ) != 0 ) |
| 126 | return( ret ); |
| 127 | #endif |
| 128 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 129 | #if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 130 | if( ( ret = rsa_self_test( v ) ) != 0 ) |
| 131 | return( ret ); |
| 132 | #endif |
| 133 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 134 | #if defined(POLARSSL_X509_PARSE_C) && defined(POLARSSL_BIGNUM_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 135 | if( ( ret = x509_self_test( v ) ) != 0 ) |
| 136 | return( ret ); |
| 137 | #endif |
| 138 | |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 139 | #if defined(POLARSSL_XTEA_C) |
| 140 | if( ( ret = xtea_self_test( v ) ) != 0 ) |
| 141 | return( ret ); |
| 142 | #endif |
| 143 | |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 144 | #if defined(POLARSSL_CAMELLIA_C) |
| 145 | if( ( ret = camellia_self_test( v ) ) != 0 ) |
| 146 | return( ret ); |
| 147 | #endif |
| 148 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 149 | #if defined(POLARSSL_CTR_DRBG_C) |
| 150 | if( ( ret = ctr_drbg_self_test( v ) ) != 0 ) |
| 151 | return( ret ); |
| 152 | #endif |
| 153 | |
Paul Bakker | f518b16 | 2012-08-23 13:03:18 +0000 | [diff] [blame] | 154 | #if defined(POLARSSL_PBKDF2_C) |
| 155 | if( ( ret = pbkdf2_self_test( v ) ) != 0 ) |
| 156 | return( ret ); |
| 157 | #endif |
| 158 | |
Manuel Pégourié-Gonnard | b4a310b | 2012-11-13 20:57:00 +0100 | [diff] [blame] | 159 | #if defined(POLARSSL_ECP_C) |
| 160 | if( ( ret = ecp_self_test( v ) ) != 0 ) |
| 161 | return( ret ); |
| 162 | #endif |
| 163 | |
Paul Bakker | 135b98e | 2011-05-25 11:13:47 +0000 | [diff] [blame] | 164 | #else |
| 165 | printf( " POLARSSL_SELF_TEST not defined.\n" ); |
| 166 | #endif |
| 167 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 168 | if( v != 0 ) |
| 169 | { |
| 170 | printf( " [ All tests passed ]\n\n" ); |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 171 | #if defined(_WIN32) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 172 | printf( " Press Enter to exit this program.\n" ); |
| 173 | fflush( stdout ); getchar(); |
| 174 | #endif |
| 175 | } |
| 176 | |
| 177 | return( ret ); |
| 178 | } |