
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
Revision 60:4ca36ac89018, committed 2018-05-10
- Comitter:
- mbed_official
- Date:
- Thu May 10 05:15:45 2018 +0100
- Parent:
- 59:0c156fb8a3ab
- Child:
- 61:ca72542a305a
- Commit message:
- Merge pull request #165 from ARMmbed/feature-platform-init
Add platform setup and teardown support
.
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-os.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed May 02 06:30:27 2018 +0100 +++ b/main.cpp Thu May 10 05:15:45 2018 +0100 @@ -47,8 +47,13 @@ static const unsigned char *hello_buffer = (const unsigned char *) hello_str; static const size_t hello_len = strlen(hello_str); -static int example(void) +static int example(mbedtls_platform_context* ctx) { + // The call below is used to avoid the "unused parameter" warning. + // The context itself can be used by cryptographic calls which require it. + // Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information. + (void)ctx; + mbedtls_printf("\r\n\r\n"); /* @@ -152,8 +157,20 @@ } int main() { - int ret = example(); - if (ret != 0) { - mbedtls_printf("Example failed with error %d\r\n", ret); + mbedtls_platform_context platform_ctx; + 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); + return MBEDTLS_EXIT_FAILURE; } + + exit_code = example(&platform_ctx); + if (exit_code != 0) { + mbedtls_printf("Example failed with error %d\r\n", exit_code); + exit_code = MBEDTLS_EXIT_FAILURE; + } + + mbedtls_platform_teardown(&platform_ctx); + return exit_code; }
--- a/mbed-os.lib Wed May 02 06:30:27 2018 +0100 +++ b/mbed-os.lib Thu May 10 05:15:45 2018 +0100 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#c05d72c3c005fbb7e92c3994c32bda45218ae7fe +https://github.com/ARMmbed/mbed-os/#ae6c7c60f91c89cbf755a2f3c8ec9c66635849fd