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