bignum: make mpi_init() and mpi_free() accept a single argument
[tropicssl.git] / programs / test / selftest.c
blob3f2cf2914f3f8fad7358d23bee444b47f49515f8
1 /*
2 * Self-test demonstration program
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
6 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #ifndef _CRT_SECURE_NO_DEPRECATE
37 #define _CRT_SECURE_NO_DEPRECATE 1
38 #endif
40 #include <string.h>
41 #include <stdio.h>
43 #include "tropicssl/config.h"
45 #include "tropicssl/md2.h"
46 #include "tropicssl/md4.h"
47 #include "tropicssl/md5.h"
48 #include "tropicssl/sha1.h"
49 #include "tropicssl/sha2.h"
50 #include "tropicssl/sha4.h"
51 #include "tropicssl/arc4.h"
52 #include "tropicssl/des.h"
53 #include "tropicssl/aes.h"
54 #include "tropicssl/base64.h"
55 #include "tropicssl/bignum.h"
56 #include "tropicssl/camellia.h"
57 #include "tropicssl/rsa.h"
58 #include "tropicssl/x509.h"
59 #include "tropicssl/xtea.h"
61 int main(int argc, char *argv[])
63 int ret, v;
65 if (argc == 2 && strcmp(argv[1], "-quiet") == 0)
66 v = 0;
67 else {
68 v = 1;
69 printf("\n");
72 #if defined(TROPICSSL_MD2_C)
73 if ((ret = md2_self_test(v)) != 0)
74 return (ret);
75 #endif
77 #if defined(TROPICSSL_MD4_C)
78 if ((ret = md4_self_test(v)) != 0)
79 return (ret);
80 #endif
82 #if defined(TROPICSSL_MD5_C)
83 if ((ret = md5_self_test(v)) != 0)
84 return (ret);
85 #endif
87 #if defined(TROPICSSL_SHA1_C)
88 if ((ret = sha1_self_test(v)) != 0)
89 return (ret);
90 #endif
92 #if defined(TROPICSSL_SHA2_C)
93 if ((ret = sha2_self_test(v)) != 0)
94 return (ret);
95 #endif
97 #if defined(TROPICSSL_SHA4_C)
98 if ((ret = sha4_self_test(v)) != 0)
99 return (ret);
100 #endif
102 #if defined(TROPICSSL_ARC4_C)
103 if ((ret = arc4_self_test(v)) != 0)
104 return (ret);
105 #endif
107 #if defined(TROPICSSL_DES_C)
108 if ((ret = des_self_test(v)) != 0)
109 return (ret);
110 #endif
112 #if defined(TROPICSSL_AES_C)
113 if ((ret = aes_self_test(v)) != 0)
114 return (ret);
115 #endif
117 #if defined(TROPICSSL_BASE64_C)
118 if ((ret = base64_self_test(v)) != 0)
119 return (ret);
120 #endif
122 #if defined(TROPICSSL_BIGNUM_C)
123 if ((ret = mpi_self_test(v)) != 0)
124 return (ret);
125 #endif
127 #if defined(TROPICSSL_RSA_C)
128 if ((ret = rsa_self_test(v)) != 0)
129 return (ret);
130 #endif
132 #if defined(TROPICSSL_X509_C)
133 if ((ret = x509_self_test(v)) != 0)
134 return (ret);
135 #endif
137 #if defined(TROPICSSL_XTEA_C)
138 if ((ret = xtea_self_test(v)) != 0)
139 return (ret);
140 #endif
142 #if defined(TROPICSSL_CAMELLIA_C)
143 if ((ret = camellia_self_test(v)) != 0)
144 return (ret);
145 #endif
147 if (v != 0) {
148 printf(" [ All tests passed ]\n\n");
149 #ifdef WIN32
150 printf(" Press Enter to exit this program.\n");
151 fflush(stdout);
152 getchar();
153 #endif
156 return (ret);