blob: ee31fdc8d869a48c1084fdbc84678864f18a0be4 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
Paul Bakkercce9d772011-11-18 14:26:47 +00004 * Copyright (C) 2006-2011, 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 Bakker0e04d0e2011-11-27 14:46:59 +000035#include "polarssl/ctr_drbg.h"
Paul Bakker89e80c92012-03-20 13:50:09 +000036#include "polarssl/gcm.h"
Paul Bakker40e46942009-01-03 21:51:57 +000037#include "polarssl/md2.h"
38#include "polarssl/md4.h"
39#include "polarssl/md5.h"
40#include "polarssl/sha1.h"
41#include "polarssl/sha2.h"
42#include "polarssl/sha4.h"
43#include "polarssl/arc4.h"
44#include "polarssl/des.h"
45#include "polarssl/aes.h"
Paul Bakker026c03b2009-03-28 17:53:03 +000046#include "polarssl/camellia.h"
Paul Bakker40e46942009-01-03 21:51:57 +000047#include "polarssl/base64.h"
48#include "polarssl/bignum.h"
49#include "polarssl/rsa.h"
50#include "polarssl/x509.h"
Paul Bakker7a7c78f2009-01-04 18:15:48 +000051#include "polarssl/xtea.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000052
53int main( int argc, char *argv[] )
54{
Paul Bakker135b98e2011-05-25 11:13:47 +000055 int ret = 0, v;
Paul Bakker5121ce52009-01-03 21:22:43 +000056
57 if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
58 v = 0;
59 else
60 {
61 v = 1;
62 printf( "\n" );
63 }
64
Paul Bakker135b98e2011-05-25 11:13:47 +000065#if defined(POLARSSL_SELF_TEST)
66
Paul Bakker40e46942009-01-03 21:51:57 +000067#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000068 if( ( ret = md2_self_test( v ) ) != 0 )
69 return( ret );
70#endif
71
Paul Bakker40e46942009-01-03 21:51:57 +000072#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000073 if( ( ret = md4_self_test( v ) ) != 0 )
74 return( ret );
75#endif
76
Paul Bakker40e46942009-01-03 21:51:57 +000077#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000078 if( ( ret = md5_self_test( v ) ) != 0 )
79 return( ret );
80#endif
81
Paul Bakker40e46942009-01-03 21:51:57 +000082#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000083 if( ( ret = sha1_self_test( v ) ) != 0 )
84 return( ret );
85#endif
86
Paul Bakker40e46942009-01-03 21:51:57 +000087#if defined(POLARSSL_SHA2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000088 if( ( ret = sha2_self_test( v ) ) != 0 )
89 return( ret );
90#endif
91
Paul Bakker40e46942009-01-03 21:51:57 +000092#if defined(POLARSSL_SHA4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000093 if( ( ret = sha4_self_test( v ) ) != 0 )
94 return( ret );
95#endif
96
Paul Bakker40e46942009-01-03 21:51:57 +000097#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000098 if( ( ret = arc4_self_test( v ) ) != 0 )
99 return( ret );
100#endif
101
Paul Bakker40e46942009-01-03 21:51:57 +0000102#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000103 if( ( ret = des_self_test( v ) ) != 0 )
104 return( ret );
105#endif
106
Paul Bakker40e46942009-01-03 21:51:57 +0000107#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000108 if( ( ret = aes_self_test( v ) ) != 0 )
109 return( ret );
110#endif
111
Paul Bakker89e80c92012-03-20 13:50:09 +0000112#if defined(POLARSSL_GCM_C)
113 if( ( ret = gcm_self_test( v ) ) != 0 )
114 return( ret );
115#endif
116
Paul Bakker40e46942009-01-03 21:51:57 +0000117#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000118 if( ( ret = base64_self_test( v ) ) != 0 )
119 return( ret );
120#endif
121
Paul Bakker40e46942009-01-03 21:51:57 +0000122#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 if( ( ret = mpi_self_test( v ) ) != 0 )
124 return( ret );
125#endif
126
Paul Bakker5690efc2011-05-26 13:16:06 +0000127#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000128 if( ( ret = rsa_self_test( v ) ) != 0 )
129 return( ret );
130#endif
131
Paul Bakker5690efc2011-05-26 13:16:06 +0000132#if defined(POLARSSL_X509_PARSE_C) && defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 if( ( ret = x509_self_test( v ) ) != 0 )
134 return( ret );
135#endif
136
Paul Bakker7a7c78f2009-01-04 18:15:48 +0000137#if defined(POLARSSL_XTEA_C)
138 if( ( ret = xtea_self_test( v ) ) != 0 )
139 return( ret );
140#endif
141
Paul Bakker38119b12009-01-10 23:31:23 +0000142#if defined(POLARSSL_CAMELLIA_C)
143 if( ( ret = camellia_self_test( v ) ) != 0 )
144 return( ret );
145#endif
146
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000147#if defined(POLARSSL_CTR_DRBG_C)
148 if( ( ret = ctr_drbg_self_test( v ) ) != 0 )
149 return( ret );
150#endif
151
Paul Bakker135b98e2011-05-25 11:13:47 +0000152#else
153 printf( " POLARSSL_SELF_TEST not defined.\n" );
154#endif
155
Paul Bakker5121ce52009-01-03 21:22:43 +0000156 if( v != 0 )
157 {
158 printf( " [ All tests passed ]\n\n" );
Paul Bakkercce9d772011-11-18 14:26:47 +0000159#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000160 printf( " Press Enter to exit this program.\n" );
161 fflush( stdout ); getchar();
162#endif
163 }
164
165 return( ret );
166}