blob: cf77939bdfcbc376c18e4c1384bb02735f5e051f [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
4 * Copyright (C) 2006-2007 Christophe Devine
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#ifndef _CRT_SECURE_NO_DEPRECATE
22#define _CRT_SECURE_NO_DEPRECATE 1
23#endif
24
25#include <string.h>
26#include <stdio.h>
27
Paul Bakker40e46942009-01-03 21:51:57 +000028#include "polarssl/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker40e46942009-01-03 21:51:57 +000030#include "polarssl/md2.h"
31#include "polarssl/md4.h"
32#include "polarssl/md5.h"
33#include "polarssl/sha1.h"
34#include "polarssl/sha2.h"
35#include "polarssl/sha4.h"
36#include "polarssl/arc4.h"
37#include "polarssl/des.h"
38#include "polarssl/aes.h"
39#include "polarssl/base64.h"
40#include "polarssl/bignum.h"
41#include "polarssl/rsa.h"
42#include "polarssl/x509.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000043
44int main( int argc, char *argv[] )
45{
46 int ret, v;
47
48 if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
49 v = 0;
50 else
51 {
52 v = 1;
53 printf( "\n" );
54 }
55
Paul Bakker40e46942009-01-03 21:51:57 +000056#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000057 if( ( ret = md2_self_test( v ) ) != 0 )
58 return( ret );
59#endif
60
Paul Bakker40e46942009-01-03 21:51:57 +000061#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000062 if( ( ret = md4_self_test( v ) ) != 0 )
63 return( ret );
64#endif
65
Paul Bakker40e46942009-01-03 21:51:57 +000066#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000067 if( ( ret = md5_self_test( v ) ) != 0 )
68 return( ret );
69#endif
70
Paul Bakker40e46942009-01-03 21:51:57 +000071#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000072 if( ( ret = sha1_self_test( v ) ) != 0 )
73 return( ret );
74#endif
75
Paul Bakker40e46942009-01-03 21:51:57 +000076#if defined(POLARSSL_SHA2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000077 if( ( ret = sha2_self_test( v ) ) != 0 )
78 return( ret );
79#endif
80
Paul Bakker40e46942009-01-03 21:51:57 +000081#if defined(POLARSSL_SHA4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000082 if( ( ret = sha4_self_test( v ) ) != 0 )
83 return( ret );
84#endif
85
Paul Bakker40e46942009-01-03 21:51:57 +000086#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000087 if( ( ret = arc4_self_test( v ) ) != 0 )
88 return( ret );
89#endif
90
Paul Bakker40e46942009-01-03 21:51:57 +000091#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000092 if( ( ret = des_self_test( v ) ) != 0 )
93 return( ret );
94#endif
95
Paul Bakker40e46942009-01-03 21:51:57 +000096#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000097 if( ( ret = aes_self_test( v ) ) != 0 )
98 return( ret );
99#endif
100
Paul Bakker40e46942009-01-03 21:51:57 +0000101#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000102 if( ( ret = base64_self_test( v ) ) != 0 )
103 return( ret );
104#endif
105
Paul Bakker40e46942009-01-03 21:51:57 +0000106#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000107 if( ( ret = mpi_self_test( v ) ) != 0 )
108 return( ret );
109#endif
110
Paul Bakker40e46942009-01-03 21:51:57 +0000111#if defined(POLARSSL_RSA_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000112 if( ( ret = rsa_self_test( v ) ) != 0 )
113 return( ret );
114#endif
115
Paul Bakker40e46942009-01-03 21:51:57 +0000116#if defined(POLARSSL_X509_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000117 if( ( ret = x509_self_test( v ) ) != 0 )
118 return( ret );
119#endif
120
121 if( v != 0 )
122 {
123 printf( " [ All tests passed ]\n\n" );
124#ifdef WIN32
125 printf( " Press Enter to exit this program.\n" );
126 fflush( stdout ); getchar();
127#endif
128 }
129
130 return( ret );
131}