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
22 #if !defined(MBEDTLS_CONFIG_FILE)
23 #include "mbedtls/config.h"
24 #else
25 #include MBEDTLS_CONFIG_FILE
26 #endif
27
28 #if defined(MBEDTLS_PLATFORM_C)
29 #include "mbedtls/platform.h"
30 #else
31 #include <stdlib.h>
32 #include <stdio.h>
33 #define mbedtls_printf printf
34 #define mbedtls_exit exit
35 #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
36 #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
37 #endif
38
39 #if defined(MBEDTLS_MD5_C)
40 #include "mbedtls/md5.h"
41 #endif
42
43 #if !defined(MBEDTLS_MD5_C)
main(void)44 int main( void )
45 {
46 mbedtls_printf("MBEDTLS_MD5_C not defined.\n");
47 return( 0 );
48 }
49 #else
50
51 #if defined(MBEDTLS_CHECK_PARAMS)
52 #include "mbedtls/platform_util.h"
mbedtls_param_failed(const char * failure_condition,const char * file,int line)53 void mbedtls_param_failed( const char *failure_condition,
54 const char *file,
55 int line )
56 {
57 mbedtls_printf( "%s:%i: Input param failed - %s\n",
58 file, line, failure_condition );
59 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
60 }
61 #endif
62
main(void)63 int main( void )
64 {
65 int i, ret;
66 unsigned char digest[16];
67 char str[] = "Hello, world!";
68
69 mbedtls_printf( "\n MD5('%s') = ", str );
70
71 if( ( ret = mbedtls_md5_ret( (unsigned char *) str, 13, digest ) ) != 0 )
72 return( MBEDTLS_EXIT_FAILURE );
73
74 for( i = 0; i < 16; i++ )
75 mbedtls_printf( "%02x", digest[i] );
76
77 mbedtls_printf( "\n\n" );
78
79 #if defined(_WIN32)
80 mbedtls_printf( " Press Enter to exit this program.\n" );
81 fflush( stdout ); getchar();
82 #endif
83
84 return( MBEDTLS_EXIT_SUCCESS );
85 }
86 #endif /* MBEDTLS_MD5_C */
87