selftest.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #include <stdio.h>
  30. #include "polarssl/config.h"
  31. #include "polarssl/md2.h"
  32. #include "polarssl/md4.h"
  33. #include "polarssl/md5.h"
  34. #include "polarssl/sha1.h"
  35. #include "polarssl/sha2.h"
  36. #include "polarssl/sha4.h"
  37. #include "polarssl/arc4.h"
  38. #include "polarssl/des.h"
  39. #include "polarssl/aes.h"
  40. #include "polarssl/camellia.h"
  41. #include "polarssl/base64.h"
  42. #include "polarssl/bignum.h"
  43. #include "polarssl/rsa.h"
  44. #include "polarssl/x509.h"
  45. #include "polarssl/xtea.h"
  46. int main( int argc, char *argv[] )
  47. {
  48. int ret = 0, v;
  49. if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
  50. v = 0;
  51. else
  52. {
  53. v = 1;
  54. printf( "\n" );
  55. }
  56. #if defined(POLARSSL_SELF_TEST)
  57. #if defined(POLARSSL_MD2_C)
  58. if( ( ret = md2_self_test( v ) ) != 0 )
  59. return( ret );
  60. #endif
  61. #if defined(POLARSSL_MD4_C)
  62. if( ( ret = md4_self_test( v ) ) != 0 )
  63. return( ret );
  64. #endif
  65. #if defined(POLARSSL_MD5_C)
  66. if( ( ret = md5_self_test( v ) ) != 0 )
  67. return( ret );
  68. #endif
  69. #if defined(POLARSSL_SHA1_C)
  70. if( ( ret = sha1_self_test( v ) ) != 0 )
  71. return( ret );
  72. #endif
  73. #if defined(POLARSSL_SHA2_C)
  74. if( ( ret = sha2_self_test( v ) ) != 0 )
  75. return( ret );
  76. #endif
  77. #if defined(POLARSSL_SHA4_C)
  78. if( ( ret = sha4_self_test( v ) ) != 0 )
  79. return( ret );
  80. #endif
  81. #if defined(POLARSSL_ARC4_C)
  82. if( ( ret = arc4_self_test( v ) ) != 0 )
  83. return( ret );
  84. #endif
  85. #if defined(POLARSSL_DES_C)
  86. if( ( ret = des_self_test( v ) ) != 0 )
  87. return( ret );
  88. #endif
  89. #if defined(POLARSSL_AES_C)
  90. if( ( ret = aes_self_test( v ) ) != 0 )
  91. return( ret );
  92. #endif
  93. #if defined(POLARSSL_BASE64_C)
  94. if( ( ret = base64_self_test( v ) ) != 0 )
  95. return( ret );
  96. #endif
  97. #if defined(POLARSSL_BIGNUM_C)
  98. if( ( ret = mpi_self_test( v ) ) != 0 )
  99. return( ret );
  100. #endif
  101. #if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C)
  102. if( ( ret = rsa_self_test( v ) ) != 0 )
  103. return( ret );
  104. #endif
  105. #if defined(POLARSSL_X509_PARSE_C) && defined(POLARSSL_BIGNUM_C)
  106. if( ( ret = x509_self_test( v ) ) != 0 )
  107. return( ret );
  108. #endif
  109. #if defined(POLARSSL_XTEA_C)
  110. if( ( ret = xtea_self_test( v ) ) != 0 )
  111. return( ret );
  112. #endif
  113. #if defined(POLARSSL_CAMELLIA_C)
  114. if( ( ret = camellia_self_test( v ) ) != 0 )
  115. return( ret );
  116. #endif
  117. #else
  118. printf( " POLARSSL_SELF_TEST not defined.\n" );
  119. #endif
  120. if( v != 0 )
  121. {
  122. printf( " [ All tests passed ]\n\n" );
  123. #ifdef WIN32
  124. printf( " Press Enter to exit this program.\n" );
  125. fflush( stdout ); getchar();
  126. #endif
  127. }
  128. return( ret );
  129. }