hello.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Classic "Hello, world" demonstration program
  3. *
  4. * Copyright The Mbed TLS Contributors
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. * not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. #if !defined(MBEDTLS_CONFIG_FILE)
  20. #include "mbedtls/config.h"
  21. #else
  22. #include MBEDTLS_CONFIG_FILE
  23. #endif
  24. #if defined(MBEDTLS_PLATFORM_C)
  25. #include "mbedtls/platform.h"
  26. #else
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #define mbedtls_printf printf
  30. #define mbedtls_exit exit
  31. #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
  32. #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
  33. #endif
  34. #if defined(MBEDTLS_MD5_C)
  35. #include "mbedtls/md5.h"
  36. #endif
  37. #if !defined(MBEDTLS_MD5_C)
  38. int main( void )
  39. {
  40. mbedtls_printf("MBEDTLS_MD5_C not defined.\n");
  41. mbedtls_exit( 0 );
  42. }
  43. #else
  44. int main( void )
  45. {
  46. int i, ret;
  47. unsigned char digest[16];
  48. char str[] = "Hello, world!";
  49. mbedtls_printf( "\n MD5('%s') = ", str );
  50. if( ( ret = mbedtls_md5_ret( (unsigned char *) str, 13, digest ) ) != 0 )
  51. mbedtls_exit( MBEDTLS_EXIT_FAILURE );
  52. for( i = 0; i < 16; i++ )
  53. mbedtls_printf( "%02x", digest[i] );
  54. mbedtls_printf( "\n\n" );
  55. #if defined(_WIN32)
  56. mbedtls_printf( " Press Enter to exit this program.\n" );
  57. fflush( stdout ); getchar();
  58. #endif
  59. mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
  60. }
  61. #endif /* MBEDTLS_MD5_C */