Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Self-test demonstration program |
| 3 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame^] | 4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine |
| 5 | * |
| 6 | * Copyright (C) 2009 Paul Bakker |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 7 | * |
| 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 | |
| 23 | #ifndef _CRT_SECURE_NO_DEPRECATE |
| 24 | #define _CRT_SECURE_NO_DEPRECATE 1 |
| 25 | #endif |
| 26 | |
| 27 | #include <string.h> |
| 28 | #include <stdio.h> |
| 29 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 30 | #include "polarssl/config.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 31 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 32 | #include "polarssl/md2.h" |
| 33 | #include "polarssl/md4.h" |
| 34 | #include "polarssl/md5.h" |
| 35 | #include "polarssl/sha1.h" |
| 36 | #include "polarssl/sha2.h" |
| 37 | #include "polarssl/sha4.h" |
| 38 | #include "polarssl/arc4.h" |
| 39 | #include "polarssl/des.h" |
| 40 | #include "polarssl/aes.h" |
| 41 | #include "polarssl/base64.h" |
| 42 | #include "polarssl/bignum.h" |
| 43 | #include "polarssl/rsa.h" |
| 44 | #include "polarssl/x509.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 45 | |
| 46 | int main( int argc, char *argv[] ) |
| 47 | { |
| 48 | int ret, v; |
| 49 | |
| 50 | if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 ) |
| 51 | v = 0; |
| 52 | else |
| 53 | { |
| 54 | v = 1; |
| 55 | printf( "\n" ); |
| 56 | } |
| 57 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 58 | #if defined(POLARSSL_MD2_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 59 | if( ( ret = md2_self_test( v ) ) != 0 ) |
| 60 | return( ret ); |
| 61 | #endif |
| 62 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 63 | #if defined(POLARSSL_MD4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 64 | if( ( ret = md4_self_test( v ) ) != 0 ) |
| 65 | return( ret ); |
| 66 | #endif |
| 67 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 68 | #if defined(POLARSSL_MD5_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 69 | if( ( ret = md5_self_test( v ) ) != 0 ) |
| 70 | return( ret ); |
| 71 | #endif |
| 72 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 73 | #if defined(POLARSSL_SHA1_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 74 | if( ( ret = sha1_self_test( v ) ) != 0 ) |
| 75 | return( ret ); |
| 76 | #endif |
| 77 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 78 | #if defined(POLARSSL_SHA2_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 79 | if( ( ret = sha2_self_test( v ) ) != 0 ) |
| 80 | return( ret ); |
| 81 | #endif |
| 82 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 83 | #if defined(POLARSSL_SHA4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 84 | if( ( ret = sha4_self_test( v ) ) != 0 ) |
| 85 | return( ret ); |
| 86 | #endif |
| 87 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 88 | #if defined(POLARSSL_ARC4_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 89 | if( ( ret = arc4_self_test( v ) ) != 0 ) |
| 90 | return( ret ); |
| 91 | #endif |
| 92 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 93 | #if defined(POLARSSL_DES_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 94 | if( ( ret = des_self_test( v ) ) != 0 ) |
| 95 | return( ret ); |
| 96 | #endif |
| 97 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 98 | #if defined(POLARSSL_AES_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 99 | if( ( ret = aes_self_test( v ) ) != 0 ) |
| 100 | return( ret ); |
| 101 | #endif |
| 102 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 103 | #if defined(POLARSSL_BASE64_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 104 | if( ( ret = base64_self_test( v ) ) != 0 ) |
| 105 | return( ret ); |
| 106 | #endif |
| 107 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 108 | #if defined(POLARSSL_BIGNUM_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 109 | if( ( ret = mpi_self_test( v ) ) != 0 ) |
| 110 | return( ret ); |
| 111 | #endif |
| 112 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 113 | #if defined(POLARSSL_RSA_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 114 | if( ( ret = rsa_self_test( v ) ) != 0 ) |
| 115 | return( ret ); |
| 116 | #endif |
| 117 | |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 118 | #if defined(POLARSSL_X509_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | if( ( ret = x509_self_test( v ) ) != 0 ) |
| 120 | return( ret ); |
| 121 | #endif |
| 122 | |
| 123 | if( v != 0 ) |
| 124 | { |
| 125 | printf( " [ All tests passed ]\n\n" ); |
| 126 | #ifdef WIN32 |
| 127 | printf( " Press Enter to exit this program.\n" ); |
| 128 | fflush( stdout ); getchar(); |
| 129 | #endif |
| 130 | } |
| 131 | |
| 132 | return( ret ); |
| 133 | } |