Simon Butcher | df81924 | 2015-08-19 19:33:27 +0100 | [diff] [blame^] | 1 | # Authenticated Encryption Example |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 2 | |
| 3 | 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. |
| 4 | |
| 5 | ## Pre-requisites |
| 6 | |
Simon Butcher | df81924 | 2015-08-19 19:33:27 +0100 | [diff] [blame^] | 7 | To build and run this example the following requirements are necessary: |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 8 | |
| 9 | * A computer with the following software installed: |
| 10 | * [CMake](http://www.cmake.org/download/). |
| 11 | * [yotta](https://github.com/ARMmbed/yotta). Please note that **yotta has its own set of dependencies**, listed in the [installation instructions](http://armmbed.github.io/yotta/#installing-on-windows). |
| 12 | * [Python](https://www.python.org/downloads/). |
| 13 | * [ARM GCC toolchain](https://launchpad.net/gcc-arm-embedded). |
| 14 | * A serial terminal emulator (e.g. screen, pySerial, cu). |
Simon Butcher | df81924 | 2015-08-19 19:33:27 +0100 | [diff] [blame^] | 15 | * An [FRDM-K64F](http://developer.mbed.org/platforms/FRDM-K64F/) development board, or another board supported by mbed OS (in which case you'll have to substitute frdm-k64f-gcc with the appropriate target in the instructions below). |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 16 | * A micro-USB cable. |
| 17 | * If your OS is Windows, please follow the installation instructions [for the serial port driver](https://developer.mbed.org/handbook/Windows-serial-configuration). |
| 18 | |
| 19 | ## Getting started |
| 20 | |
Simon Butcher | df81924 | 2015-08-19 19:33:27 +0100 | [diff] [blame^] | 21 | 1. Connect the FRDM-K64F to the computer with the micro-USB cable, being careful to use the "OpenSDA" connector on the target board. |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 22 | |
| 23 | 2. Navigate to the mbedtls directory supplied with your release and open a terminal. |
| 24 | |
| 25 | 3. Set the yotta target: |
| 26 | |
| 27 | ``` |
| 28 | yotta target frdm-k64f-gcc |
| 29 | ``` |
| 30 | |
| 31 | 4. Check that there are no missing dependencies: |
| 32 | |
| 33 | ``` |
Simon Butcher | df81924 | 2015-08-19 19:33:27 +0100 | [diff] [blame^] | 34 | $ yotta ls |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 35 | ``` |
| 36 | |
Simon Butcher | df81924 | 2015-08-19 19:33:27 +0100 | [diff] [blame^] | 37 | If there are missing dependencies, yotta will list them in the terminal. Please install these before proceeding. |
| 38 | |
| 39 | 5. Build mbedtls and the examples. This may take a long time if this is your first compilation: |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 40 | |
| 41 | ``` |
Simon Butcher | df81924 | 2015-08-19 19:33:27 +0100 | [diff] [blame^] | 42 | $ yotta build |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 43 | ``` |
| 44 | |
| 45 | 6. Copy `build/frdm-k64f-gcc/test/mbedtls-test-example-authcrypt.bin` to your mbed board and wait until the LED next to the USB port stops blinking. |
| 46 | |
Manuel Pégourié-Gonnard | bd5bbec | 2015-08-06 18:10:17 +0200 | [diff] [blame] | 47 | 7. Start the serial terminal emulator and connect to the virtual serial port presented by FRDM-K64F. For settings, use 115200 baud, 8N1, no flow control. **Warning:** for this example, the baud rate is not the default 9600, it is 115200. |
Manuel Pégourié-Gonnard | 63e7eba | 2015-07-28 14:17:48 +0200 | [diff] [blame] | 48 | |
| 49 | 8. Press the reset button on the board. |
| 50 | |
| 51 | 9. The output in the terminal window should look like: |
| 52 | |
| 53 | ``` |
| 54 | {{timeout;10}} |
| 55 | {{host_test_name;default}} |
| 56 | {{description;mbed TLS example authcrypt}} |
| 57 | {{test_id;MBEDTLS_EX_AUTHCRYPT}} |
| 58 | {{start}} |
| 59 | |
| 60 | |
| 61 | plaintext message: 536f6d65207468696e67732061726520626574746572206c65667420756e7265616400 |
| 62 | ciphertext: c57f7afb94f14c7977d785d08682a2596bd62ee9dcf216b8cccd997afee9b402f5de1739e8e6467aa363749ef39392e5c66622b01c7203ec0a3d14 |
| 63 | decrypted: 536f6d65207468696e67732061726520626574746572206c65667420756e7265616400 |
| 64 | |
| 65 | DONE |
| 66 | {{success}} |
| 67 | {{end}} |
| 68 | ``` |
| 69 | |
| 70 | The actual output for the ciphertext line will vary on each run due to the use of a random nonce in the encryption process. |