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

mbed TLS Benchmark example on mbed OS

This application performs authenticated encryption and authenticated decryption of a buffer. It serves as a tutorial for the basic authenticated encryption functions 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

plaintext message: 536f6d65207468696e67732061726520626574746572206c65667420756e7265616400
ciphertext: c57f7afb94f14c7977d785d08682a2596bd62ee9dcf216b8cccd997afee9b402f5de1739e8e6467aa363749ef39392e5c66622b01c7203ec0a3d14
decrypted: 536f6d65207468696e67732061726520626574746572206c65667420756e7265616400

DONE
Committer:
mbed_official
Date:
Mon Nov 18 14:00:18 2019 +0000
Revision:
87:5d1395cd812c
Parent:
81:81b73a469c70
Merge pull request #264 from dgreen-arm/point-master-at-mbed-os-master

Point master branch at Mbed OS master
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-tls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Janos Follath 0:9a918c8d34dc 1 /*
mbed_official 48:6b6340f5cdc3 2 * Hello world example of using the authenticated encryption with Mbed TLS
Janos Follath 0:9a918c8d34dc 3 *
mbed_official 48:6b6340f5cdc3 4 * Copyright (C) 2016-2017, Arm Limited, All Rights Reserved
Janos Follath 0:9a918c8d34dc 5 * SPDX-License-Identifier: Apache-2.0
Janos Follath 0:9a918c8d34dc 6 *
Janos Follath 0:9a918c8d34dc 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Janos Follath 0:9a918c8d34dc 8 * not use this file except in compliance with the License.
Janos Follath 0:9a918c8d34dc 9 * You may obtain a copy of the License at
Janos Follath 0:9a918c8d34dc 10 *
Janos Follath 0:9a918c8d34dc 11 * http://www.apache.org/licenses/LICENSE-2.0
Janos Follath 0:9a918c8d34dc 12 *
Janos Follath 0:9a918c8d34dc 13 * Unless required by applicable law or agreed to in writing, software
Janos Follath 0:9a918c8d34dc 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Janos Follath 0:9a918c8d34dc 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Janos Follath 0:9a918c8d34dc 16 * See the License for the specific language governing permissions and
Janos Follath 0:9a918c8d34dc 17 * limitations under the License.
Janos Follath 0:9a918c8d34dc 18 */
Janos Follath 0:9a918c8d34dc 19
Janos Follath 0:9a918c8d34dc 20 #include "mbed.h"
Janos Follath 0:9a918c8d34dc 21
mbed_official 36:454dcefc8453 22 #include "authcrypt.h"
Janos Follath 0:9a918c8d34dc 23
Janos Follath 0:9a918c8d34dc 24 #include "mbedtls/platform.h"
Janos Follath 0:9a918c8d34dc 25
mbed_official 36:454dcefc8453 26 int main() {
mbed_official 81:81b73a469c70 27 int exit_code = MBEDTLS_EXIT_SUCCESS;
mbed_official 81:81b73a469c70 28 int ret;
Janos Follath 0:9a918c8d34dc 29
mbed_official 81:81b73a469c70 30 if ((ret = mbedtls_platform_setup(NULL)) != 0) {
mbed_official 81:81b73a469c70 31 printf("Platform initialization failed with error %d\n", ret);
mbed_official 63:5e7be856a68b 32 return MBEDTLS_EXIT_FAILURE;
mbed_official 63:5e7be856a68b 33 }
mbed_official 63:5e7be856a68b 34
mbed_official 78:2749cf972e5f 35 Authcrypt *authcrypt = new Authcrypt();
mbed_official 63:5e7be856a68b 36
mbed_official 81:81b73a469c70 37 if ((ret = authcrypt->run()) != 0) {
mbed_official 81:81b73a469c70 38 mbedtls_printf("Example failed with error %d\n", ret);
mbed_official 36:454dcefc8453 39 exit_code = MBEDTLS_EXIT_FAILURE;
Janos Follath 0:9a918c8d34dc 40 }
Janos Follath 0:9a918c8d34dc 41
mbed_official 36:454dcefc8453 42 delete authcrypt;
Janos Follath 0:9a918c8d34dc 43
mbed_official 78:2749cf972e5f 44 mbedtls_platform_teardown(NULL);
mbed_official 36:454dcefc8453 45 return exit_code;
Janos Follath 0:9a918c8d34dc 46 }