Hello world example of using the hashing functions of mbed TLS. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-tls

SHA-256 Hash example on mbed OS

This application performs hashing of a buffer with SHA-256 using various APIs. It serves as a tutorial for the basic hashing APIs of mbed TLS.

Getting started

Building with mbed CLI

If you'd like to use mbed CLI to build this, then you should set up your environment if you have not done so already. For instructions, refer to the main readme. The instructions on this page relate to using the developer.mbed.org Online Compiler

Import the program in to the Online Compiler, select your board from the drop down in the top right hand corner and then compile the application. Once it has built, you can drag and drop the binary onto your device.

Monitoring the application

The output in the terminal window should be similar to this:

terminal output

Method 1: 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3
Method 2: 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3
Method 3: 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3
Method 4: 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3

DONE

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Oct 08 17:00:15 2018 +0100
Parent:
71:4a0865b04f9f
Child:
73:5dac47333167
Commit message:
Merge pull request #126 from andresag01/line-endings

Change line endings from \r\n to \n only
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-tls

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 08 16:00:15 2018 +0100
+++ b/main.cpp	Mon Oct 08 17:00:15 2018 +0100
@@ -40,7 +40,7 @@
     for (size_t i = 0; i < len; i++)
         mbedtls_printf("%02x", buf[i]);
 
-    mbedtls_printf("\r\n");
+    mbedtls_printf("\n");
 }
 
 static const char hello_str[] = "Hello, world!";
@@ -54,7 +54,7 @@
     // Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information.
     (void)ctx;
 
-    mbedtls_printf("\r\n\r\n");
+    mbedtls_printf("\n\n");
 
     /*
      * Method 1: use all-in-one function of a specific SHA-xxx module
@@ -98,7 +98,7 @@
 
     if (md_info3 == NULL)
     {
-        mbedtls_printf("SHA256 not available\r\n");
+        mbedtls_printf("SHA256 not available\n");
         return 1;
     }
 
@@ -106,7 +106,7 @@
 
     if (ret3 != 0)
     {
-        mbedtls_printf("md() returned -0x%04X\r\n", -ret3);
+        mbedtls_printf("md() returned -0x%04X\n", -ret3);
         return 1;
     }
 
@@ -122,7 +122,7 @@
 
     if (md_info4 == NULL)
     {
-        mbedtls_printf("SHA256 not available\r\n");
+        mbedtls_printf("SHA256 not available\n");
         return 1;
     }
 
@@ -133,7 +133,7 @@
     int ret4 = mbedtls_md_init_ctx(&ctx4, md_info4);
     if (ret4 != 0)
     {
-        mbedtls_printf("md_init_ctx() returned -0x%04X\r\n", -ret4);
+        mbedtls_printf("md_init_ctx() returned -0x%04X\n", -ret4);
         return 1;
     }
 
@@ -151,7 +151,7 @@
     mbedtls_md_free(&ctx4);
 
 
-    mbedtls_printf("\r\nDONE\r\n");
+    mbedtls_printf("\nDONE\n");
 
     return 0;
 }
@@ -161,13 +161,13 @@
     int exit_code = MBEDTLS_EXIT_FAILURE;
 
     if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) {
-        printf("Platform initialization failed with error %d\r\n", exit_code);
+        printf("Platform initialization failed with error %d\n", exit_code);
         return MBEDTLS_EXIT_FAILURE;
     }
 
     exit_code = example(&platform_ctx);
     if (exit_code != 0) {
-        mbedtls_printf("Example failed with error %d\r\n", exit_code);
+        mbedtls_printf("Example failed with error %d\n", exit_code);
         exit_code = MBEDTLS_EXIT_FAILURE;
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Oct 08 17:00:15 2018 +0100
@@ -0,0 +1,7 @@
+{
+    "target_overrides": {
+        "*": {
+             "platform.stdio-convert-newlines": true
+        }
+    }
+}