blob: 60285731435ac2b6a7cdbeab08e68f51468d68d4 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00004 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 *
6 * Copyright (C) 2009 Paul Bakker
Paul Bakker5121ce52009-01-03 21:22:43 +00007 *
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 Bakker40e46942009-01-03 21:51:57 +000030#include "polarssl/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000031
Paul Bakker40e46942009-01-03 21:51:57 +000032#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 Bakker5121ce52009-01-03 21:22:43 +000045
46int 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 Bakker40e46942009-01-03 21:51:57 +000058#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000059 if( ( ret = md2_self_test( v ) ) != 0 )
60 return( ret );
61#endif
62
Paul Bakker40e46942009-01-03 21:51:57 +000063#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000064 if( ( ret = md4_self_test( v ) ) != 0 )
65 return( ret );
66#endif
67
Paul Bakker40e46942009-01-03 21:51:57 +000068#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000069 if( ( ret = md5_self_test( v ) ) != 0 )
70 return( ret );
71#endif
72
Paul Bakker40e46942009-01-03 21:51:57 +000073#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000074 if( ( ret = sha1_self_test( v ) ) != 0 )
75 return( ret );
76#endif
77
Paul Bakker40e46942009-01-03 21:51:57 +000078#if defined(POLARSSL_SHA2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000079 if( ( ret = sha2_self_test( v ) ) != 0 )
80 return( ret );
81#endif
82
Paul Bakker40e46942009-01-03 21:51:57 +000083#if defined(POLARSSL_SHA4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000084 if( ( ret = sha4_self_test( v ) ) != 0 )
85 return( ret );
86#endif
87
Paul Bakker40e46942009-01-03 21:51:57 +000088#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000089 if( ( ret = arc4_self_test( v ) ) != 0 )
90 return( ret );
91#endif
92
Paul Bakker40e46942009-01-03 21:51:57 +000093#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000094 if( ( ret = des_self_test( v ) ) != 0 )
95 return( ret );
96#endif
97
Paul Bakker40e46942009-01-03 21:51:57 +000098#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000099 if( ( ret = aes_self_test( v ) ) != 0 )
100 return( ret );
101#endif
102
Paul Bakker40e46942009-01-03 21:51:57 +0000103#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000104 if( ( ret = base64_self_test( v ) ) != 0 )
105 return( ret );
106#endif
107
Paul Bakker40e46942009-01-03 21:51:57 +0000108#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000109 if( ( ret = mpi_self_test( v ) ) != 0 )
110 return( ret );
111#endif
112
Paul Bakker40e46942009-01-03 21:51:57 +0000113#if defined(POLARSSL_RSA_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 if( ( ret = rsa_self_test( v ) ) != 0 )
115 return( ret );
116#endif
117
Paul Bakker40e46942009-01-03 21:51:57 +0000118#if defined(POLARSSL_X509_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000119 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}