selftest.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Self-test demonstration program
  3. *
  4. * Copyright (C) 2006-2010, Brainspark B.V.
  5. *
  6. * This file is part of PolarSSL (http://www.polarssl.org)
  7. * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  8. *
  9. * All rights reserved.
  10. *
  11. * 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. #ifndef _CRT_SECURE_NO_DEPRECATE
  26. #define _CRT_SECURE_NO_DEPRECATE 1
  27. #endif
  28. #include <string.h>
  29. #ifdef PRINTF_STDLIB
  30. #include <stdio.h>
  31. #endif
  32. #ifdef PRINTF_CUSTOM
  33. #include "tinystdio.h"
  34. #endif
  35. #include "polarssl/config.h"
  36. #include "polarssl/md2.h"
  37. #include "polarssl/md4.h"
  38. #include "polarssl/md5.h"
  39. #include "polarssl/sha1.h"
  40. #include "polarssl/sha2.h"
  41. #include "polarssl/sha4.h"
  42. #include "polarssl/arc4.h"
  43. #include "polarssl/des.h"
  44. #include "polarssl/aes.h"
  45. #include "polarssl/camellia.h"
  46. #include "polarssl/base64.h"
  47. #include "polarssl/bignum.h"
  48. #include "polarssl/rsa.h"
  49. #include "polarssl/x509.h"
  50. #include "polarssl/xtea.h"
  51. int main( int argc, char *argv[] )
  52. {
  53. int ret = 0, v;
  54. if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
  55. v = 0;
  56. else
  57. {
  58. v = 1;
  59. printf( "\n" );
  60. }
  61. #if defined(POLARSSL_SELF_TEST)
  62. #if defined(POLARSSL_MD2_C)
  63. if( ( ret = md2_self_test( v ) ) != 0 )
  64. return( ret );
  65. #endif
  66. #if defined(POLARSSL_MD4_C)
  67. if( ( ret = md4_self_test( v ) ) != 0 )
  68. return( ret );
  69. #endif
  70. #if defined(POLARSSL_MD5_C)
  71. if( ( ret = md5_self_test( v ) ) != 0 )
  72. return( ret );
  73. #endif
  74. #if defined(POLARSSL_SHA1_C)
  75. if( ( ret = sha1_self_test( v ) ) != 0 )
  76. return( ret );
  77. #endif
  78. #if defined(POLARSSL_SHA2_C)
  79. if( ( ret = sha2_self_test( v ) ) != 0 )
  80. return( ret );
  81. #endif
  82. #if defined(POLARSSL_SHA4_C)
  83. if( ( ret = sha4_self_test( v ) ) != 0 )
  84. return( ret );
  85. #endif
  86. #if defined(POLARSSL_ARC4_C)
  87. if( ( ret = arc4_self_test( v ) ) != 0 )
  88. return( ret );
  89. #endif
  90. #if defined(POLARSSL_DES_C)
  91. if( ( ret = des_self_test( v ) ) != 0 )
  92. return( ret );
  93. #endif
  94. #if defined(POLARSSL_AES_C)
  95. if( ( ret = aes_self_test( v ) ) != 0 )
  96. return( ret );
  97. #endif
  98. #if defined(POLARSSL_BASE64_C)
  99. if( ( ret = base64_self_test( v ) ) != 0 )
  100. return( ret );
  101. #endif
  102. #if defined(POLARSSL_BIGNUM_C)
  103. if( ( ret = mpi_self_test( v ) ) != 0 )
  104. return( ret );
  105. #endif
  106. #if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C)
  107. if( ( ret = rsa_self_test( v ) ) != 0 )
  108. return( ret );
  109. #endif
  110. #if defined(POLARSSL_X509_PARSE_C) && defined(POLARSSL_BIGNUM_C)
  111. if( ( ret = x509_self_test( v ) ) != 0 )
  112. return( ret );
  113. #endif
  114. #if defined(POLARSSL_XTEA_C)
  115. if( ( ret = xtea_self_test( v ) ) != 0 )
  116. return( ret );
  117. #endif
  118. #if defined(POLARSSL_CAMELLIA_C)
  119. if( ( ret = camellia_self_test( v ) ) != 0 )
  120. return( ret );
  121. #endif
  122. #else
  123. printf( " POLARSSL_SELF_TEST not defined.\n" );
  124. #endif
  125. if( v != 0 )
  126. {
  127. printf( " [ All tests passed ]\n\n" );
  128. #ifdef WIN32
  129. printf( " Press Enter to exit this program.\n" );
  130. fflush( stdout ); getchar();
  131. #endif
  132. }
  133. return( ret );
  134. }