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 #if defined(MBEDTLS_PLATFORM_C)
23 #include "mbedtls/platform.h"
24 #else
25 #include <stdlib.h>
26 #include <stdio.h>
27 #define mbedtls_printf       printf
28 #define mbedtls_exit         exit
29 #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
30 #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
31 #endif
32 
33 #if defined(MBEDTLS_MD5_C)
34 #include "mbedtls/md5.h"
35 #endif
36 
37 #if !defined(MBEDTLS_MD5_C)
main(void)38 int main( void )
39 {
40     mbedtls_printf("MBEDTLS_MD5_C not defined.\n");
41     mbedtls_exit( 0 );
42 }
43 #else
44 
45 
main(void)46 int main( void )
47 {
48     int i, ret;
49     unsigned char digest[16];
50     char str[] = "Hello, world!";
51 
52     mbedtls_printf( "\n  MD5('%s') = ", str );
53 
54     if( ( ret = mbedtls_md5( (unsigned char *) str, 13, digest ) ) != 0 )
55         mbedtls_exit( MBEDTLS_EXIT_FAILURE );
56 
57     for( i = 0; i < 16; i++ )
58         mbedtls_printf( "%02x", digest[i] );
59 
60     mbedtls_printf( "\n\n" );
61 
62 #if defined(_WIN32)
63     mbedtls_printf( "  Press Enter to exit this program.\n" );
64     fflush( stdout ); getchar();
65 #endif
66 
67     mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
68 }
69 #endif /* MBEDTLS_MD5_C */
70