Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Self-test demonstration program |
| 3 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame^] | 4 | * Copyright (C) 2006-2009, Paul Bakker <polarssl_maintainer at polarssl.org> |
| 5 | * All rights reserved. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 6 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame^] | 7 | * Joined copyright on original XySSL code with: Christophe Devine |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | */ |
| 23 | |
| 24 | #ifndef _CRT_SECURE_NO_DEPRECATE |
| 25 | #define _CRT_SECURE_NO_DEPRECATE 1 |
| 26 | #endif |
| 27 | |
| 28 | #include <string.h> |
| 29 | #include <stdio.h> |
| 30 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 31 | #include "polarssl/config.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 32 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 33 | #include "polarssl/md2.h" |
| 34 | #include "polarssl/md4.h" |
| 35 | #include "polarssl/md5.h" |
| 36 | #include "polarssl/sha1.h" |
| 37 | #include "polarssl/sha2.h" |
| 38 | #include "polarssl/sha4.h" |
| 39 | #include "polarssl/arc4.h" |
| 40 | #include "polarssl/des.h" |
| 41 | #include "polarssl/aes.h" |
Paul Bakker | 026c03b | 2009-03-28 17:53:03 +0000 | [diff] [blame] | 42 | #include "polarssl/camellia.h" |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 43 | #include "polarssl/base64.h" |
| 44 | #include "polarssl/bignum.h" |
| 45 | #include "polarssl/rsa.h" |
| 46 | #include "polarssl/x509.h" |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 47 | #include "polarssl/xtea.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 48 | |
| 49 | int main( int argc, char *argv[] ) |
| 50 | { |
| 51 | int ret, v; |
| 52 | |
| 53 | if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 ) |
| 54 | v = 0; |
| 55 | else |
| 56 | { |
| 57 | v = 1; |
| 58 | printf( "\n" ); |
| 59 | } |
| 60 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 61 | #if defined(POLARSSL_MD2_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 62 | if( ( ret = md2_self_test( v ) ) != 0 ) |
| 63 | return( ret ); |
| 64 | #endif |
| 65 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 66 | #if defined(POLARSSL_MD4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 67 | if( ( ret = md4_self_test( v ) ) != 0 ) |
| 68 | return( ret ); |
| 69 | #endif |
| 70 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 71 | #if defined(POLARSSL_MD5_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 72 | if( ( ret = md5_self_test( v ) ) != 0 ) |
| 73 | return( ret ); |
| 74 | #endif |
| 75 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 76 | #if defined(POLARSSL_SHA1_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 77 | if( ( ret = sha1_self_test( v ) ) != 0 ) |
| 78 | return( ret ); |
| 79 | #endif |
| 80 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 81 | #if defined(POLARSSL_SHA2_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 82 | if( ( ret = sha2_self_test( v ) ) != 0 ) |
| 83 | return( ret ); |
| 84 | #endif |
| 85 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 86 | #if defined(POLARSSL_SHA4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 87 | if( ( ret = sha4_self_test( v ) ) != 0 ) |
| 88 | return( ret ); |
| 89 | #endif |
| 90 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 91 | #if defined(POLARSSL_ARC4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 92 | if( ( ret = arc4_self_test( v ) ) != 0 ) |
| 93 | return( ret ); |
| 94 | #endif |
| 95 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 96 | #if defined(POLARSSL_DES_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 97 | if( ( ret = des_self_test( v ) ) != 0 ) |
| 98 | return( ret ); |
| 99 | #endif |
| 100 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 101 | #if defined(POLARSSL_AES_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 102 | if( ( ret = aes_self_test( v ) ) != 0 ) |
| 103 | return( ret ); |
| 104 | #endif |
| 105 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 106 | #if defined(POLARSSL_BASE64_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 107 | if( ( ret = base64_self_test( v ) ) != 0 ) |
| 108 | return( ret ); |
| 109 | #endif |
| 110 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 111 | #if defined(POLARSSL_BIGNUM_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 112 | if( ( ret = mpi_self_test( v ) ) != 0 ) |
| 113 | return( ret ); |
| 114 | #endif |
| 115 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 116 | #if defined(POLARSSL_RSA_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 117 | if( ( ret = rsa_self_test( v ) ) != 0 ) |
| 118 | return( ret ); |
| 119 | #endif |
| 120 | |
Paul Bakker | 1973e4c | 2009-07-10 22:32:40 +0000 | [diff] [blame] | 121 | #if defined(POLARSSL_X509_PARSE_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 122 | if( ( ret = x509_self_test( v ) ) != 0 ) |
| 123 | return( ret ); |
| 124 | #endif |
| 125 | |
Paul Bakker | 7a7c78f | 2009-01-04 18:15:48 +0000 | [diff] [blame] | 126 | #if defined(POLARSSL_XTEA_C) |
| 127 | if( ( ret = xtea_self_test( v ) ) != 0 ) |
| 128 | return( ret ); |
| 129 | #endif |
| 130 | |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 131 | #if defined(POLARSSL_CAMELLIA_C) |
| 132 | if( ( ret = camellia_self_test( v ) ) != 0 ) |
| 133 | return( ret ); |
| 134 | #endif |
| 135 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 136 | if( v != 0 ) |
| 137 | { |
| 138 | printf( " [ All tests passed ]\n\n" ); |
| 139 | #ifdef WIN32 |
| 140 | printf( " Press Enter to exit this program.\n" ); |
| 141 | fflush( stdout ); getchar(); |
| 142 | #endif |
| 143 | } |
| 144 | |
| 145 | return( ret ); |
| 146 | } |