hello.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <stdio.h>
  30. #define mbedtls_printf printf
  31. #endif
  32. #if defined(MBEDTLS_MD5_C)
  33. #include "mbedtls/md5.h"
  34. #endif
  35. #if !defined(MBEDTLS_MD5_C)
  36. int main( void )
  37. {
  38. mbedtls_printf("MBEDTLS_MD5_C not defined.\n");
  39. return( 0 );
  40. }
  41. #else
  42. int main( void )
  43. {
  44. int i;
  45. unsigned char digest[16];
  46. char str[] = "Hello, world!";
  47. mbedtls_printf( "\n MD5('%s') = ", str );
  48. mbedtls_md5( (unsigned char *) str, 13, digest );
  49. for( i = 0; i < 16; i++ )
  50. mbedtls_printf( "%02x", digest[i] );
  51. mbedtls_printf( "\n\n" );
  52. #if defined(_WIN32)
  53. mbedtls_printf( " Press Enter to exit this program.\n" );
  54. fflush( stdout ); getchar();
  55. #endif
  56. return( 0 );
  57. }
  58. #endif /* MBEDTLS_MD5_C */