blob: 11c5b45a351dec6cd4e71c8d4f235e3bea88c2d9 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
Paul Bakker530927b2015-02-13 14:24:10 +01004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00006 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
Paul Bakker5121ce52009-01-03 21:22:43 +00008 * 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 Bakker0e04d0e2011-11-27 14:46:59 +000032#include "polarssl/ctr_drbg.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"
37#include "polarssl/sha1.h"
38#include "polarssl/sha2.h"
39#include "polarssl/sha4.h"
40#include "polarssl/arc4.h"
41#include "polarssl/des.h"
42#include "polarssl/aes.h"
Paul Bakker026c03b2009-03-28 17:53:03 +000043#include "polarssl/camellia.h"
Paul Bakker40e46942009-01-03 21:51:57 +000044#include "polarssl/base64.h"
45#include "polarssl/bignum.h"
46#include "polarssl/rsa.h"
47#include "polarssl/x509.h"
Paul Bakker7a7c78f2009-01-04 18:15:48 +000048#include "polarssl/xtea.h"
Paul Bakkerf518b162012-08-23 13:03:18 +000049#include "polarssl/pbkdf2.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000050
51int main( int argc, char *argv[] )
52{
Paul Bakker135b98e2011-05-25 11:13:47 +000053 int ret = 0, v;
Paul Bakker5121ce52009-01-03 21:22:43 +000054
55 if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
56 v = 0;
57 else
58 {
59 v = 1;
60 printf( "\n" );
61 }
62
Paul Bakker135b98e2011-05-25 11:13:47 +000063#if defined(POLARSSL_SELF_TEST)
64
Paul Bakker40e46942009-01-03 21:51:57 +000065#if defined(POLARSSL_MD2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000066 if( ( ret = md2_self_test( v ) ) != 0 )
67 return( ret );
68#endif
69
Paul Bakker40e46942009-01-03 21:51:57 +000070#if defined(POLARSSL_MD4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000071 if( ( ret = md4_self_test( v ) ) != 0 )
72 return( ret );
73#endif
74
Paul Bakker40e46942009-01-03 21:51:57 +000075#if defined(POLARSSL_MD5_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000076 if( ( ret = md5_self_test( v ) ) != 0 )
77 return( ret );
78#endif
79
Paul Bakker40e46942009-01-03 21:51:57 +000080#if defined(POLARSSL_SHA1_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000081 if( ( ret = sha1_self_test( v ) ) != 0 )
82 return( ret );
83#endif
84
Paul Bakker40e46942009-01-03 21:51:57 +000085#if defined(POLARSSL_SHA2_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000086 if( ( ret = sha2_self_test( v ) ) != 0 )
87 return( ret );
88#endif
89
Paul Bakker40e46942009-01-03 21:51:57 +000090#if defined(POLARSSL_SHA4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000091 if( ( ret = sha4_self_test( v ) ) != 0 )
92 return( ret );
93#endif
94
Paul Bakker40e46942009-01-03 21:51:57 +000095#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000096 if( ( ret = arc4_self_test( v ) ) != 0 )
97 return( ret );
98#endif
99
Paul Bakker40e46942009-01-03 21:51:57 +0000100#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000101 if( ( ret = des_self_test( v ) ) != 0 )
102 return( ret );
103#endif
104
Paul Bakker40e46942009-01-03 21:51:57 +0000105#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000106 if( ( ret = aes_self_test( v ) ) != 0 )
107 return( ret );
108#endif
109
Paul Bakker89e80c92012-03-20 13:50:09 +0000110#if defined(POLARSSL_GCM_C)
111 if( ( ret = gcm_self_test( v ) ) != 0 )
112 return( ret );
113#endif
114
Paul Bakker40e46942009-01-03 21:51:57 +0000115#if defined(POLARSSL_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000116 if( ( ret = base64_self_test( v ) ) != 0 )
117 return( ret );
118#endif
119
Paul Bakker40e46942009-01-03 21:51:57 +0000120#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000121 if( ( ret = mpi_self_test( v ) ) != 0 )
122 return( ret );
123#endif
124
Paul Bakker5690efc2011-05-26 13:16:06 +0000125#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 if( ( ret = rsa_self_test( v ) ) != 0 )
127 return( ret );
128#endif
129
Paul Bakker5690efc2011-05-26 13:16:06 +0000130#if defined(POLARSSL_X509_PARSE_C) && defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 if( ( ret = x509_self_test( v ) ) != 0 )
132 return( ret );
133#endif
134
Paul Bakker7a7c78f2009-01-04 18:15:48 +0000135#if defined(POLARSSL_XTEA_C)
136 if( ( ret = xtea_self_test( v ) ) != 0 )
137 return( ret );
138#endif
139
Paul Bakker38119b12009-01-10 23:31:23 +0000140#if defined(POLARSSL_CAMELLIA_C)
141 if( ( ret = camellia_self_test( v ) ) != 0 )
142 return( ret );
143#endif
144
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000145#if defined(POLARSSL_CTR_DRBG_C)
146 if( ( ret = ctr_drbg_self_test( v ) ) != 0 )
147 return( ret );
148#endif
149
Paul Bakkerf518b162012-08-23 13:03:18 +0000150#if defined(POLARSSL_PBKDF2_C)
151 if( ( ret = pbkdf2_self_test( v ) ) != 0 )
152 return( ret );
153#endif
154
Paul Bakker135b98e2011-05-25 11:13:47 +0000155#else
156 printf( " POLARSSL_SELF_TEST not defined.\n" );
157#endif
158
Paul Bakker5121ce52009-01-03 21:22:43 +0000159 if( v != 0 )
160 {
161 printf( " [ All tests passed ]\n\n" );
Paul Bakkercce9d772011-11-18 14:26:47 +0000162#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 printf( " Press Enter to exit this program.\n" );
164 fflush( stdout ); getchar();
165#endif
166 }
167
168 return( ret );
169}