blob: fc990fe9389de2187485a3f69ee0fde446b7084c [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
Paul Bakkerd2681d82013-06-30 14:49:12 +02004 * Copyright (C) 2006-2013, 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
Manuel Pégourié-Gonnardabd6e022013-09-20 13:30:43 +020026#include "polarssl/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000027
28#include <string.h>
29#include <stdio.h>
30
Paul Bakker0e04d0e2011-11-27 14:46:59 +000031#include "polarssl/ctr_drbg.h"
Paul Bakker40ce79f2013-09-15 17:43:54 +020032#include "polarssl/dhm.h"
Paul Bakker89e80c92012-03-20 13:50:09 +000033#include "polarssl/gcm.h"
Paul Bakker40e46942009-01-03 21:51:57 +000034#include "polarssl/md2.h"
35#include "polarssl/md4.h"
36#include "polarssl/md5.h"
Manuel Pégourié-Gonnard1744d722014-01-17 14:44:38 +010037#include "polarssl/rmd160.h"
Paul Bakker40e46942009-01-03 21:51:57 +000038#include "polarssl/sha1.h"
Paul Bakkerd2681d82013-06-30 14:49:12 +020039#include "polarssl/sha256.h"
40#include "polarssl/sha512.h"
Paul Bakker40e46942009-01-03 21:51:57 +000041#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 Bakkerf518b162012-08-23 13:03:18 +000050#include "polarssl/pbkdf2.h"
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +010051#include "polarssl/ecp.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000052
Paul Bakker6e339b52013-07-03 13:37:05 +020053#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
54#include "polarssl/memory.h"
55#endif
56
Paul Bakker5121ce52009-01-03 21:22:43 +000057int main( int argc, char *argv[] )
58{
Paul Bakker135b98e2011-05-25 11:13:47 +000059 int ret = 0, v;
Paul Bakker6e339b52013-07-03 13:37:05 +020060#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
61 unsigned char buf[1000000];
62#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000063
64 if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
65 v = 0;
66 else
67 {
68 v = 1;
69 printf( "\n" );
70 }
71
Paul Bakker135b98e2011-05-25 11:13:47 +000072#if defined(POLARSSL_SELF_TEST)
73
Paul Bakker6e339b52013-07-03 13:37:05 +020074#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
75 memory_buffer_alloc_init( buf, sizeof(buf) );
76#endif
77
Paul Bakker40e46942009-01-03 21:51:57 +000078#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000079 if( ( ret = md2_self_test( v ) ) != 0 )
80 return( ret );
81#endif
82
Paul Bakker40e46942009-01-03 21:51:57 +000083#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000084 if( ( ret = md4_self_test( v ) ) != 0 )
85 return( ret );
86#endif
87
Paul Bakker40e46942009-01-03 21:51:57 +000088#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000089 if( ( ret = md5_self_test( v ) ) != 0 )
90 return( ret );
91#endif
92
Manuel Pégourié-Gonnard1744d722014-01-17 14:44:38 +010093#if defined(POLARSSL_RMD160_C)
94 if( ( ret = rmd160_self_test( v ) ) != 0 )
95 return( ret );
96#endif
97
Paul Bakker40e46942009-01-03 21:51:57 +000098#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000099 if( ( ret = sha1_self_test( v ) ) != 0 )
100 return( ret );
101#endif
102
Paul Bakker9e36f042013-06-30 14:34:05 +0200103#if defined(POLARSSL_SHA256_C)
104 if( ( ret = sha256_self_test( v ) ) != 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000105 return( ret );
106#endif
107
Paul Bakker9e36f042013-06-30 14:34:05 +0200108#if defined(POLARSSL_SHA512_C)
109 if( ( ret = sha512_self_test( v ) ) != 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 return( ret );
111#endif
112
Paul Bakker40e46942009-01-03 21:51:57 +0000113#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 if( ( ret = arc4_self_test( v ) ) != 0 )
115 return( ret );
116#endif
117
Paul Bakker40e46942009-01-03 21:51:57 +0000118#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000119 if( ( ret = des_self_test( v ) ) != 0 )
120 return( ret );
121#endif
122
Paul Bakker40e46942009-01-03 21:51:57 +0000123#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 if( ( ret = aes_self_test( v ) ) != 0 )
125 return( ret );
126#endif
127
Paul Bakker89e80c92012-03-20 13:50:09 +0000128#if defined(POLARSSL_GCM_C)
129 if( ( ret = gcm_self_test( v ) ) != 0 )
130 return( ret );
131#endif
132
Paul Bakker40e46942009-01-03 21:51:57 +0000133#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000134 if( ( ret = base64_self_test( v ) ) != 0 )
135 return( ret );
136#endif
137
Paul Bakker40e46942009-01-03 21:51:57 +0000138#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000139 if( ( ret = mpi_self_test( v ) ) != 0 )
140 return( ret );
141#endif
142
Paul Bakker5690efc2011-05-26 13:16:06 +0000143#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000144 if( ( ret = rsa_self_test( v ) ) != 0 )
145 return( ret );
146#endif
147
Paul Bakker7504d7f2013-09-16 22:56:18 +0200148#if defined(POLARSSL_X509_USE_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000149 if( ( ret = x509_self_test( v ) ) != 0 )
150 return( ret );
151#endif
152
Paul Bakker7a7c78f2009-01-04 18:15:48 +0000153#if defined(POLARSSL_XTEA_C)
154 if( ( ret = xtea_self_test( v ) ) != 0 )
155 return( ret );
156#endif
157
Paul Bakker38119b12009-01-10 23:31:23 +0000158#if defined(POLARSSL_CAMELLIA_C)
159 if( ( ret = camellia_self_test( v ) ) != 0 )
160 return( ret );
161#endif
162
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000163#if defined(POLARSSL_CTR_DRBG_C)
164 if( ( ret = ctr_drbg_self_test( v ) ) != 0 )
165 return( ret );
166#endif
167
Paul Bakkerf518b162012-08-23 13:03:18 +0000168#if defined(POLARSSL_PBKDF2_C)
169 if( ( ret = pbkdf2_self_test( v ) ) != 0 )
170 return( ret );
171#endif
172
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +0100173#if defined(POLARSSL_ECP_C)
174 if( ( ret = ecp_self_test( v ) ) != 0 )
175 return( ret );
176#endif
177
Paul Bakker40ce79f2013-09-15 17:43:54 +0200178#if defined(POLARSSL_DHM_C)
179 if( ( ret = dhm_self_test( v ) ) != 0 )
180 return( ret );
181#endif
182
Paul Bakker135b98e2011-05-25 11:13:47 +0000183#else
184 printf( " POLARSSL_SELF_TEST not defined.\n" );
185#endif
186
Paul Bakker5121ce52009-01-03 21:22:43 +0000187 if( v != 0 )
188 {
Paul Bakker6e339b52013-07-03 13:37:05 +0200189#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && defined(POLARSSL_MEMORY_DEBUG)
190 memory_buffer_alloc_status();
191#endif
192
Paul Bakker5121ce52009-01-03 21:22:43 +0000193 printf( " [ All tests passed ]\n\n" );
Paul Bakkercce9d772011-11-18 14:26:47 +0000194#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000195 printf( " Press Enter to exit this program.\n" );
196 fflush( stdout ); getchar();
197#endif
198 }
Paul Bakker1337aff2013-09-29 14:45:34 +0200199#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
200 memory_buffer_alloc_free();
201#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000202
203 return( ret );
204}