hello.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include "mbedtls/build_info.h"
  20. #include "mbedtls/platform.h"
  21. #if defined(MBEDTLS_MD5_C)
  22. #include "mbedtls/md5.h"
  23. #endif
  24. #if !defined(MBEDTLS_MD5_C)
  25. int main(void)
  26. {
  27. mbedtls_printf("MBEDTLS_MD5_C not defined.\n");
  28. mbedtls_exit(0);
  29. }
  30. #else
  31. int main(void)
  32. {
  33. int i, ret;
  34. unsigned char digest[16];
  35. char str[] = "Hello, world!";
  36. mbedtls_printf("\n MD5('%s') = ", str);
  37. if ((ret = mbedtls_md5((unsigned char *) str, 13, digest)) != 0) {
  38. mbedtls_exit(MBEDTLS_EXIT_FAILURE);
  39. }
  40. for (i = 0; i < 16; i++) {
  41. mbedtls_printf("%02x", digest[i]);
  42. }
  43. mbedtls_printf("\n\n");
  44. mbedtls_exit(MBEDTLS_EXIT_SUCCESS);
  45. }
  46. #endif /* MBEDTLS_MD5_C */