blob: 75bdd1fc87a869e1e84070f14bbb61870e3ff072 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakker5121ce52009-01-03 21:22:43 +000011 * 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 Bakker40e46942009-01-03 21:51:57 +000033#include "polarssl/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000034
Paul Bakker40e46942009-01-03 21:51:57 +000035#include "polarssl/md2.h"
36#include "polarssl/md4.h"
37#include "polarssl/md5.h"
38#include "polarssl/sha1.h"
39#include "polarssl/sha2.h"
40#include "polarssl/sha4.h"
41#include "polarssl/arc4.h"
42#include "polarssl/des.h"
43#include "polarssl/aes.h"
Paul Bakker026c03b2009-03-28 17:53:03 +000044#include "polarssl/camellia.h"
Paul Bakker40e46942009-01-03 21:51:57 +000045#include "polarssl/base64.h"
46#include "polarssl/bignum.h"
47#include "polarssl/rsa.h"
48#include "polarssl/x509.h"
Paul Bakker7a7c78f2009-01-04 18:15:48 +000049#include "polarssl/xtea.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000050
51int main( int argc, char *argv[] )
52{
53 int ret, v;
54
55 if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
56 v = 0;
57 else
58 {
59 v = 1;
60 printf( "\n" );
61 }
62
Paul Bakker40e46942009-01-03 21:51:57 +000063#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000064 if( ( ret = md2_self_test( v ) ) != 0 )
65 return( ret );
66#endif
67
Paul Bakker40e46942009-01-03 21:51:57 +000068#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000069 if( ( ret = md4_self_test( v ) ) != 0 )
70 return( ret );
71#endif
72
Paul Bakker40e46942009-01-03 21:51:57 +000073#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000074 if( ( ret = md5_self_test( v ) ) != 0 )
75 return( ret );
76#endif
77
Paul Bakker40e46942009-01-03 21:51:57 +000078#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000079 if( ( ret = sha1_self_test( v ) ) != 0 )
80 return( ret );
81#endif
82
Paul Bakker40e46942009-01-03 21:51:57 +000083#if defined(POLARSSL_SHA2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000084 if( ( ret = sha2_self_test( v ) ) != 0 )
85 return( ret );
86#endif
87
Paul Bakker40e46942009-01-03 21:51:57 +000088#if defined(POLARSSL_SHA4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000089 if( ( ret = sha4_self_test( v ) ) != 0 )
90 return( ret );
91#endif
92
Paul Bakker40e46942009-01-03 21:51:57 +000093#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000094 if( ( ret = arc4_self_test( v ) ) != 0 )
95 return( ret );
96#endif
97
Paul Bakker40e46942009-01-03 21:51:57 +000098#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000099 if( ( ret = des_self_test( v ) ) != 0 )
100 return( ret );
101#endif
102
Paul Bakker40e46942009-01-03 21:51:57 +0000103#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000104 if( ( ret = aes_self_test( v ) ) != 0 )
105 return( ret );
106#endif
107
Paul Bakker40e46942009-01-03 21:51:57 +0000108#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000109 if( ( ret = base64_self_test( v ) ) != 0 )
110 return( ret );
111#endif
112
Paul Bakker40e46942009-01-03 21:51:57 +0000113#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 if( ( ret = mpi_self_test( v ) ) != 0 )
115 return( ret );
116#endif
117
Paul Bakker40e46942009-01-03 21:51:57 +0000118#if defined(POLARSSL_RSA_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000119 if( ( ret = rsa_self_test( v ) ) != 0 )
120 return( ret );
121#endif
122
Paul Bakker1973e4c2009-07-10 22:32:40 +0000123#if defined(POLARSSL_X509_PARSE_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 if( ( ret = x509_self_test( v ) ) != 0 )
125 return( ret );
126#endif
127
Paul Bakker7a7c78f2009-01-04 18:15:48 +0000128#if defined(POLARSSL_XTEA_C)
129 if( ( ret = xtea_self_test( v ) ) != 0 )
130 return( ret );
131#endif
132
Paul Bakker38119b12009-01-10 23:31:23 +0000133#if defined(POLARSSL_CAMELLIA_C)
134 if( ( ret = camellia_self_test( v ) ) != 0 )
135 return( ret );
136#endif
137
Paul Bakker5121ce52009-01-03 21:22:43 +0000138 if( v != 0 )
139 {
140 printf( " [ All tests passed ]\n\n" );
141#ifdef WIN32
142 printf( " Press Enter to exit this program.\n" );
143 fflush( stdout ); getchar();
144#endif
145 }
146
147 return( ret );
148}