hello.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Classic "Hello, world" demonstration program
  3. *
  4. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  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. * This file is part of mbed TLS (https://tls.mbed.org)
  20. */
  21. #if !defined(MBEDTLS_CONFIG_FILE)
  22. #include "mbedtls/config.h"
  23. #else
  24. #include MBEDTLS_CONFIG_FILE
  25. #endif
  26. #if defined(MBEDTLS_PLATFORM_C)
  27. #include "mbedtls/platform.h"
  28. #else
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #define mbedtls_printf printf
  32. #define mbedtls_exit exit
  33. #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
  34. #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
  35. #endif
  36. #if defined(MBEDTLS_MD5_C)
  37. #include "mbedtls/md5.h"
  38. #endif
  39. #if !defined(MBEDTLS_MD5_C)
  40. int main( void )
  41. {
  42. mbedtls_printf("MBEDTLS_MD5_C not defined.\n");
  43. return( 0 );
  44. }
  45. #else
  46. int main( void )
  47. {
  48. int i, ret;
  49. unsigned char digest[16];
  50. char str[] = "Hello, world!";
  51. mbedtls_printf( "\n MD5('%s') = ", str );
  52. if( ( ret = mbedtls_md5_ret( (unsigned char *) str, 13, digest ) ) != 0 )
  53. return( MBEDTLS_EXIT_FAILURE );
  54. for( i = 0; i < 16; i++ )
  55. mbedtls_printf( "%02x", digest[i] );
  56. mbedtls_printf( "\n\n" );
  57. #if defined(_WIN32)
  58. mbedtls_printf( " Press Enter to exit this program.\n" );
  59. fflush( stdout ); getchar();
  60. #endif
  61. return( MBEDTLS_EXIT_SUCCESS );
  62. }
  63. #endif /* MBEDTLS_MD5_C */