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