blob: 25b2c21dc7dff27c404704c008422cb2ed5608e3 [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 *
Paul Bakker27db1f52009-01-25 15:27:00 +00006 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
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 Bakker7a7c78f2009-01-04 18:15:48 +000045#include "polarssl/xtea.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000046
47int main( int argc, char *argv[] )
48{
49 int ret, v;
50
51 if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
52 v = 0;
53 else
54 {
55 v = 1;
56 printf( "\n" );
57 }
58
Paul Bakker40e46942009-01-03 21:51:57 +000059#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000060 if( ( ret = md2_self_test( v ) ) != 0 )
61 return( ret );
62#endif
63
Paul Bakker40e46942009-01-03 21:51:57 +000064#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000065 if( ( ret = md4_self_test( v ) ) != 0 )
66 return( ret );
67#endif
68
Paul Bakker40e46942009-01-03 21:51:57 +000069#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000070 if( ( ret = md5_self_test( v ) ) != 0 )
71 return( ret );
72#endif
73
Paul Bakker40e46942009-01-03 21:51:57 +000074#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000075 if( ( ret = sha1_self_test( v ) ) != 0 )
76 return( ret );
77#endif
78
Paul Bakker40e46942009-01-03 21:51:57 +000079#if defined(POLARSSL_SHA2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000080 if( ( ret = sha2_self_test( v ) ) != 0 )
81 return( ret );
82#endif
83
Paul Bakker40e46942009-01-03 21:51:57 +000084#if defined(POLARSSL_SHA4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000085 if( ( ret = sha4_self_test( v ) ) != 0 )
86 return( ret );
87#endif
88
Paul Bakker40e46942009-01-03 21:51:57 +000089#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000090 if( ( ret = arc4_self_test( v ) ) != 0 )
91 return( ret );
92#endif
93
Paul Bakker40e46942009-01-03 21:51:57 +000094#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000095 if( ( ret = des_self_test( v ) ) != 0 )
96 return( ret );
97#endif
98
Paul Bakker40e46942009-01-03 21:51:57 +000099#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000100 if( ( ret = aes_self_test( v ) ) != 0 )
101 return( ret );
102#endif
103
Paul Bakker40e46942009-01-03 21:51:57 +0000104#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000105 if( ( ret = base64_self_test( v ) ) != 0 )
106 return( ret );
107#endif
108
Paul Bakker40e46942009-01-03 21:51:57 +0000109#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 if( ( ret = mpi_self_test( v ) ) != 0 )
111 return( ret );
112#endif
113
Paul Bakker40e46942009-01-03 21:51:57 +0000114#if defined(POLARSSL_RSA_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000115 if( ( ret = rsa_self_test( v ) ) != 0 )
116 return( ret );
117#endif
118
Paul Bakker40e46942009-01-03 21:51:57 +0000119#if defined(POLARSSL_X509_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000120 if( ( ret = x509_self_test( v ) ) != 0 )
121 return( ret );
122#endif
123
Paul Bakker7a7c78f2009-01-04 18:15:48 +0000124#if defined(POLARSSL_XTEA_C)
125 if( ( ret = xtea_self_test( v ) ) != 0 )
126 return( ret );
127#endif
128
Paul Bakker38119b12009-01-10 23:31:23 +0000129#if defined(POLARSSL_CAMELLIA_C)
130 if( ( ret = camellia_self_test( v ) ) != 0 )
131 return( ret );
132#endif
133
Paul Bakker5121ce52009-01-03 21:22:43 +0000134 if( v != 0 )
135 {
136 printf( " [ All tests passed ]\n\n" );
137#ifdef WIN32
138 printf( " Press Enter to exit this program.\n" );
139 fflush( stdout ); getchar();
140#endif
141 }
142
143 return( ret );
144}