blob: c029e9b33d94c9cb0ba22224ba912d30733ced00 [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
Manuel Pégourié-Gonnard79afaa02014-01-31 11:12:09 +010031#include "polarssl/hmac_drbg.h"
Paul Bakker0e04d0e2011-11-27 14:46:59 +000032#include "polarssl/ctr_drbg.h"
Paul Bakker40ce79f2013-09-15 17:43:54 +020033#include "polarssl/dhm.h"
Paul Bakker89e80c92012-03-20 13:50:09 +000034#include "polarssl/gcm.h"
Paul Bakker40e46942009-01-03 21:51:57 +000035#include "polarssl/md2.h"
36#include "polarssl/md4.h"
37#include "polarssl/md5.h"
Paul Bakker61b699e2014-01-22 13:35:29 +010038#include "polarssl/ripemd160.h"
Paul Bakker40e46942009-01-03 21:51:57 +000039#include "polarssl/sha1.h"
Paul Bakkerd2681d82013-06-30 14:49:12 +020040#include "polarssl/sha256.h"
41#include "polarssl/sha512.h"
Paul Bakker40e46942009-01-03 21:51:57 +000042#include "polarssl/arc4.h"
43#include "polarssl/des.h"
44#include "polarssl/aes.h"
Paul Bakker026c03b2009-03-28 17:53:03 +000045#include "polarssl/camellia.h"
Paul Bakker40e46942009-01-03 21:51:57 +000046#include "polarssl/base64.h"
47#include "polarssl/bignum.h"
48#include "polarssl/rsa.h"
49#include "polarssl/x509.h"
Paul Bakker7a7c78f2009-01-04 18:15:48 +000050#include "polarssl/xtea.h"
Manuel Pégourié-Gonnard486485b2014-03-20 09:59:51 +010051#include "polarssl/pkcs5.h"
Manuel Pégourié-Gonnard388dac42014-03-27 18:57:52 +010052#include "polarssl/pbkdf2.h"
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +010053#include "polarssl/ecp.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000054
Paul Bakker6e339b52013-07-03 13:37:05 +020055#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
56#include "polarssl/memory.h"
57#endif
58
Paul Bakker5121ce52009-01-03 21:22:43 +000059int main( int argc, char *argv[] )
60{
Paul Bakker135b98e2011-05-25 11:13:47 +000061 int ret = 0, v;
Paul Bakker6e339b52013-07-03 13:37:05 +020062#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
63 unsigned char buf[1000000];
64#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000065
66 if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
67 v = 0;
68 else
69 {
70 v = 1;
71 printf( "\n" );
72 }
73
Paul Bakker135b98e2011-05-25 11:13:47 +000074#if defined(POLARSSL_SELF_TEST)
75
Paul Bakker6e339b52013-07-03 13:37:05 +020076#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
77 memory_buffer_alloc_init( buf, sizeof(buf) );
78#endif
79
Paul Bakker40e46942009-01-03 21:51:57 +000080#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000081 if( ( ret = md2_self_test( v ) ) != 0 )
82 return( ret );
83#endif
84
Paul Bakker40e46942009-01-03 21:51:57 +000085#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000086 if( ( ret = md4_self_test( v ) ) != 0 )
87 return( ret );
88#endif
89
Paul Bakker40e46942009-01-03 21:51:57 +000090#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000091 if( ( ret = md5_self_test( v ) ) != 0 )
92 return( ret );
93#endif
94
Paul Bakker61b699e2014-01-22 13:35:29 +010095#if defined(POLARSSL_RIPEMD160_C)
96 if( ( ret = ripemd160_self_test( v ) ) != 0 )
Manuel Pégourié-Gonnard1744d722014-01-17 14:44:38 +010097 return( ret );
98#endif
99
Paul Bakker40e46942009-01-03 21:51:57 +0000100#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000101 if( ( ret = sha1_self_test( v ) ) != 0 )
102 return( ret );
103#endif
104
Paul Bakker9e36f042013-06-30 14:34:05 +0200105#if defined(POLARSSL_SHA256_C)
106 if( ( ret = sha256_self_test( v ) ) != 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000107 return( ret );
108#endif
109
Paul Bakker5a1d6872014-03-26 11:20:05 +0100110#if defined(POLARSSL_SHA512_C)
Paul Bakker9e36f042013-06-30 14:34:05 +0200111 if( ( ret = sha512_self_test( v ) ) != 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000112 return( ret );
113#endif
114
Paul Bakker40e46942009-01-03 21:51:57 +0000115#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000116 if( ( ret = arc4_self_test( v ) ) != 0 )
117 return( ret );
118#endif
119
Paul Bakker40e46942009-01-03 21:51:57 +0000120#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000121 if( ( ret = des_self_test( v ) ) != 0 )
122 return( ret );
123#endif
124
Paul Bakker40e46942009-01-03 21:51:57 +0000125#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 if( ( ret = aes_self_test( v ) ) != 0 )
127 return( ret );
128#endif
129
Paul Bakker89e80c92012-03-20 13:50:09 +0000130#if defined(POLARSSL_GCM_C)
131 if( ( ret = gcm_self_test( v ) ) != 0 )
132 return( ret );
133#endif
134
Paul Bakker40e46942009-01-03 21:51:57 +0000135#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 if( ( ret = base64_self_test( v ) ) != 0 )
137 return( ret );
138#endif
139
Paul Bakker40e46942009-01-03 21:51:57 +0000140#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000141 if( ( ret = mpi_self_test( v ) ) != 0 )
142 return( ret );
143#endif
144
Manuel Pégourié-Gonnard79afaa02014-01-31 11:12:09 +0100145#if defined(POLARSSL_RSA_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000146 if( ( ret = rsa_self_test( v ) ) != 0 )
147 return( ret );
148#endif
149
Paul Bakker7504d7f2013-09-16 22:56:18 +0200150#if defined(POLARSSL_X509_USE_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000151 if( ( ret = x509_self_test( v ) ) != 0 )
152 return( ret );
153#endif
154
Paul Bakker7a7c78f2009-01-04 18:15:48 +0000155#if defined(POLARSSL_XTEA_C)
156 if( ( ret = xtea_self_test( v ) ) != 0 )
157 return( ret );
158#endif
159
Paul Bakker38119b12009-01-10 23:31:23 +0000160#if defined(POLARSSL_CAMELLIA_C)
161 if( ( ret = camellia_self_test( v ) ) != 0 )
162 return( ret );
163#endif
164
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000165#if defined(POLARSSL_CTR_DRBG_C)
166 if( ( ret = ctr_drbg_self_test( v ) ) != 0 )
167 return( ret );
168#endif
169
Manuel Pégourié-Gonnard79afaa02014-01-31 11:12:09 +0100170#if defined(POLARSSL_HMAC_DRBG_C)
171 if( ( ret = hmac_drbg_self_test( v ) ) != 0 )
172 return( ret );
173#endif
174
Manuel Pégourié-Gonnard388dac42014-03-27 18:57:52 +0100175#if defined(POLARSSL_PBKDF2_C)
176 if( ( ret = pbkdf2_self_test( v ) ) != 0 )
177 return( ret );
178#else
Manuel Pégourié-Gonnard486485b2014-03-20 09:59:51 +0100179#if defined(POLARSSL_PKCS5_C)
180 if( ( ret = pkcs5_self_test( v ) ) != 0 )
Paul Bakkerf518b162012-08-23 13:03:18 +0000181 return( ret );
182#endif
Manuel Pégourié-Gonnard388dac42014-03-27 18:57:52 +0100183#endif
Paul Bakkerf518b162012-08-23 13:03:18 +0000184
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +0100185#if defined(POLARSSL_ECP_C)
186 if( ( ret = ecp_self_test( v ) ) != 0 )
187 return( ret );
188#endif
189
Paul Bakker40ce79f2013-09-15 17:43:54 +0200190#if defined(POLARSSL_DHM_C)
191 if( ( ret = dhm_self_test( v ) ) != 0 )
192 return( ret );
193#endif
194
Paul Bakker135b98e2011-05-25 11:13:47 +0000195#else
196 printf( " POLARSSL_SELF_TEST not defined.\n" );
197#endif
198
Paul Bakker5121ce52009-01-03 21:22:43 +0000199 if( v != 0 )
200 {
Paul Bakker6e339b52013-07-03 13:37:05 +0200201#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && defined(POLARSSL_MEMORY_DEBUG)
202 memory_buffer_alloc_status();
203#endif
204
Paul Bakker5121ce52009-01-03 21:22:43 +0000205 printf( " [ All tests passed ]\n\n" );
Paul Bakkercce9d772011-11-18 14:26:47 +0000206#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000207 printf( " Press Enter to exit this program.\n" );
208 fflush( stdout ); getchar();
209#endif
210 }
Paul Bakker1337aff2013-09-29 14:45:34 +0200211#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
212 memory_buffer_alloc_free();
213#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000214
215 return( ret );
216}