blob: 19408f37fef2458593d342c3a2503c65c8bf0ea0 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Classic "Hello, world" demonstration program
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker5121ce52009-01-03 21:22:43 +00006 */
7
Felix Conway998760a2025-03-24 11:37:33 +00008#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
9
Bence Szépkútic662b362021-05-27 11:25:03 +020010#include "mbedtls/build_info.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000011
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000012#include "mbedtls/platform.h"
Rich Evansf90016a2015-01-19 14:26:37 +000013
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020014#if defined(MBEDTLS_MD5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000015#include "mbedtls/md5.h"
Rich Evans18b78c72015-02-11 14:06:19 +000016#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000017
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020018#if !defined(MBEDTLS_MD5_C)
Gilles Peskine449bd832023-01-11 14:50:10 +010019int main(void)
Paul Bakker5690efc2011-05-26 13:16:06 +000020{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020021 mbedtls_printf("MBEDTLS_MD5_C not defined.\n");
Gilles Peskine449bd832023-01-11 14:50:10 +010022 mbedtls_exit(0);
Paul Bakker5690efc2011-05-26 13:16:06 +000023}
24#else
Manuel Pégourié-Gonnard3ef6a6d2018-12-10 14:31:45 +010025
Manuel Pégourié-Gonnard3ef6a6d2018-12-10 14:31:45 +010026
Gilles Peskine449bd832023-01-11 14:50:10 +010027int main(void)
Paul Bakker5121ce52009-01-03 21:22:43 +000028{
Andres Amaya Garcia1ff60f42017-06-28 13:26:36 +010029 int i, ret;
Paul Bakker5121ce52009-01-03 21:22:43 +000030 unsigned char digest[16];
31 char str[] = "Hello, world!";
32
Gilles Peskine449bd832023-01-11 14:50:10 +010033 mbedtls_printf("\n MD5('%s') = ", str);
Paul Bakker5121ce52009-01-03 21:22:43 +000034
Gilles Peskine449bd832023-01-11 14:50:10 +010035 if ((ret = mbedtls_md5((unsigned char *) str, 13, digest)) != 0) {
36 mbedtls_exit(MBEDTLS_EXIT_FAILURE);
37 }
Paul Bakker5121ce52009-01-03 21:22:43 +000038
Gilles Peskine449bd832023-01-11 14:50:10 +010039 for (i = 0; i < 16; i++) {
40 mbedtls_printf("%02x", digest[i]);
41 }
Paul Bakker5121ce52009-01-03 21:22:43 +000042
Gilles Peskine449bd832023-01-11 14:50:10 +010043 mbedtls_printf("\n\n");
Paul Bakker5121ce52009-01-03 21:22:43 +000044
Gilles Peskine449bd832023-01-11 14:50:10 +010045 mbedtls_exit(MBEDTLS_EXIT_SUCCESS);
Paul Bakker5121ce52009-01-03 21:22:43 +000046}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#endif /* MBEDTLS_MD5_C */