Skip to content

Commit dd2044d

Browse files
Andres Amaya Garciasimonbutcher
Andres Amaya Garcia
authored andcommitted
Add mbed TLS benchmark example (#1)
* Add mbed TLS benchmark example Add the mbed TLS benchmark example that runs multiple cryptographic primitives and reports performance. Also, modified the repository's structure so that each example is in a different subdirectory. * Fix benchmark code and documentation Fix the benchmark code to remove the conditional preprocessor directives for platform.h. This code is not meant to be portable to anything other than mbed OS, so these are not required. Also, update documentation according to feedback.
1 parent 006599a commit dd2044d

File tree

9 files changed

+1068
-93
lines changed

9 files changed

+1068
-93
lines changed

README.md

Lines changed: 23 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,51 @@
1-
# HTTPS File Download Example for TLS Client on mbed OS
1+
# mbed TLS Examples on mbedOS
22

3-
This application downloads a file from an HTTPS server (developer.mbed.org) and looks for a specific string in that file.
3+
This repository contains a collection of mbed TLS example applications based on mbed OS. Each subdirectory contains a separate example meant for building as an executable.
44

5-
## Required hardware
5+
# Getting started
66

7+
## Required hardware
78
* An [FRDM-K64F](http://developer.mbed.org/platforms/FRDM-K64F/) development board.
89
* A micro-USB cable.
9-
* An Ethernet cable and connection to the internet.
1010

1111
## Required software
1212
* [mbed CLI](https://github.com/ARMmbed/mbed-cli) - to build the example program. To learn how to build mbed OS applications with mbed CLI, see the [user guide](https://github.com/ARMmbed/mbed-cli/blob/master/README.md)
1313
* [Serial port monitor](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).
1414

15-
## Getting started
16-
17-
1. Clone [this](https://github.com/ARMmbed/mbed-tls-sample) repository.
15+
## Building and running the examples
1816

19-
2. Open a command line tool and navigate to the project’s directory.
17+
1. Clone the repository containing the collection of examples:
18+
```
19+
$ git clone https://github.com/ARMmbed/mbed-os-example-tls
20+
```
2021
21-
3. Update `mbed-os` sources using the `mbed update` command.
22+
1. Open a command line tool and navigate to one of the project’s subdirectories.
2223
23-
4. Build the application by selecting the board and build toolchain using the command `mbed compile -m K64F -t GCC_ARM -c -j0`. mbed-cli builds a binary file under the project’s `.build` directory.
24+
1. Update `mbed-os` sources using the `mbed deploy` command.
2425
25-
5. Connect the FRDM-K64F to the internet using the Ethernet cable.
26+
1. Build the application by selecting the board and build toolchain using the command `mbed compile -m K64F -t GCC_ARM`. mbed-cli builds a binary file under the project’s `.build` directory.
2627
27-
6. Connect the FRDM-K64F to the computer with the micro-USB cable, being careful to use the **OpenSDA** connector on the target board. The board is listed as a mass-storage device.
28+
1. Connect the FRDM-K64F to the computer with the micro-USB cable, being careful to use the **OpenSDA** connector on the target board. The board is listed as a mass-storage device.
2829
29-
7. Drag the binary `.build/K64F/GCC_ARM/mbed-tls-sample.bin` to the board to flash the application.
30+
1. Drag the binary `.build/K64F/GCC_ARM/<EXAMPLE>.bin` to the board to flash the application.
3031
31-
8. The board is automatically programmed with the new binary. A flashing LED on it indicates that it is still working. When the LED stops blinking, the board is ready to work.
32+
1. The board is automatically programmed with the new binary. A flashing LED on it indicates that it is still working. When the LED stops blinking, the board is ready to work.
3233
33-
9. Press the **RESET** button on the board to run the program.
34+
1. Press the **RESET** button on the board to run the program.
3435
3536
## Monitoring the application
3637
38+
Please browse the subdirectories for specific documentation.
39+
* [Benchmark](./benchmark/README.md)
40+
3741
The application prints debug messages over the serial port, so you can monitor its activity with a serial terminal emulator. Start the [serial terminal emulator](https://developer.mbed.org/handbook/Terminals) and connect to the [virtual serial port](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications) presented by FRDM-K64F. Use the following settings:
3842
3943
* 115200 baud (not 9600).
4044
* 8N1.
4145
* No flow control.
4246
43-
After pressing the **RESET** button on the board, the output in the terminal window should be similar to this:
44-
45-
{{timeout;120}}
46-
{{host_test_name;default}}
47-
{{description;mbed TLS example HTTPS client}}
48-
{{test_id;MBEDTLS_EX_HTTPS_CLIENT}}
49-
{{start}}
50-
51-
Client IP Address is 192.168.0.2
52-
Starting DNS lookup for developer.mbed.org
53-
DNS Response Received:
54-
developer.mbed.org: 217.140.101.30
55-
Connecting to 217.140.101.30:443
56-
Connected to 217.140.101.30:443
57-
Starting the TLS handshake...
58-
TLS connection to developer.mbed.org established
59-
Server certificate:
60-
cert. version : 3
61-
serial number : 11:21:4E:4B:13:27:F0:89:21:FB:70:EC:3B:B5:73:5C:FF:B9
62-
issuer name : C=BE, O=GlobalSign nv-sa, CN=GlobalSign Organization Validation CA - SHA256 - G2
63-
subject name : C=GB, ST=Cambridgeshire, L=Cambridge, O=ARM Ltd, CN=*.mbed.com
64-
issued on : 2015-03-05 10:31:02
65-
expires on : 2016-03-05 10:31:02
66-
signed using : RSA with SHA-256
67-
RSA key size : 2048 bits
68-
basic constraints : CA=false
69-
subject alt name : *.mbed.com, *.mbed.org, mbed.org, mbed.com
70-
key usage : Digital Signature, Key Encipherment
71-
ext key usage : TLS Web Server Authentication, TLS Web Client Authentication
72-
Certificate verification passed
73-
74-
HTTPS: Received 473 chars from server
75-
HTTPS: Received 200 OK status ... [OK]
76-
HTTPS: Received 'Hello world!' status ... [OK]
77-
HTTPS: Received message:
78-
79-
HTTP/1.1 200 OK
80-
Server: nginx/1.7.10
81-
Date: Tue, 18 Aug 2015 18:34:04 GMT
82-
Content-Type: text/plain
83-
Content-Length: 14
84-
Connection: keep-alive
85-
Last-Modified: Fri, 27 Jul 2012 13:30:34 GMT
86-
Accept-Ranges: bytes
87-
Cache-Control: max-age=36000
88-
Expires: Wed, 19 Aug 2015 04:34:04 GMT
89-
X-Upstream-L3: 172.17.42.1:8080
90-
X-Upstream-L2: developer-sjc-indigo-2-nginx
91-
X-Upstream-L1-next-hop: 217.140.101.86:8001
92-
X-Upstream-L1: developer-sjc-indigo-border-nginx
93-
94-
Hello world!
95-
{{success}}
96-
{{end}}
97-
98-
## Debugging the TLS connection
99-
100-
To print out more debug information about the TLS connection, edit the file `source/main.cpp` and change the definition of `DEBUG_LEVEL` (near the top of the file) from 0 to a positive number:
101-
102-
* Level 1 only prints non-zero return codes from SSL functions and information about the full certificate chain being verified.
103-
104-
* Level 2 prints more information about internal state updates.
105-
106-
* Level 3 is intermediate.
107-
108-
* Level 4 (the maximum) includes full binary dumps of the packets.
109-
110-
111-
The TLS connection can fail with an error similar to:
112-
113-
mbedtls_ssl_write() failed: -0x2700 (-9984): X509 - Certificate verification failed, e.g. CRL, CA or signature check failed
114-
Failed to fetch /media/uploads/mbed_official/hello.txt from developer.mbed.org:443
115-
116-
This probably means you need to update the contents of the `SSL_CA_PEM` constant (this can happen if you modify `HTTPS_SERVER_NAME`, or when `developer.mbed.org` switches to a new CA when updating its certificate).
117-
118-
Another possible reason for this error is a proxy providing a different certificate. Proxies can be used in some network configurations or for performing man-in-the-middle attacks. If you choose to ignore this error and proceed with the connection anyway, you can change the definition of `UNSAFE` near the top of the file from 0 to 1.
119-
120-
**Warning:** this removes all security against a possible active attacker, so use at your own risk or for debugging only!
47+
After pressing the **RESET** button on the board, you should be able to observe the application's output.
48+
49+
## Debugging mbed TLS
12150
51+
To optionally print out more debug information, edit the `main.cpp` for the sample and change the definition of `DEBUG_LEVEL` (near the top of the file) from 0 to a positive number between 1 and 4.

benchmark/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# mbed TLS Benchmark example on mbed OS
2+
3+
This application benchmarks the various cryptographic primitives offered by mbed TLS.
4+
5+
# Getting started
6+
7+
Set up your environment if you have not done so already. For instructions, refer to the [main readme](../README.md).
8+
9+
## Monitoring the application
10+
11+
The output in the terminal window should be similar to this:
12+
13+
```
14+
SHA-256 : 1673 Kb/s, 70 cycles/byte
15+
SHA-512 : 546 Kb/s, 215 cycles/byte
16+
AES-CBC-128 : 1428 Kb/s, 82 cycles/byte
17+
AES-CBC-192 : 1260 Kb/s, 93 cycles/byte
18+
AES-CBC-256 : 1127 Kb/s, 104 cycles/byte
19+
AES-GCM-128 : 486 Kb/s, 242 cycles/byte
20+
AES-GCM-192 : 464 Kb/s, 253 cycles/byte
21+
AES-GCM-256 : 445 Kb/s, 264 cycles/byte
22+
AES-CCM-128 : 610 Kb/s, 192 cycles/byte
23+
AES-CCM-192 : 547 Kb/s, 214 cycles/byte
24+
AES-CCM-256 : 496 Kb/s, 237 cycles/byte
25+
CTR_DRBG (NOPR) : 1139 Kb/s, 102 cycles/byte
26+
CTR_DRBG (PR) : 826 Kb/s, 142 cycles/byte
27+
HMAC_DRBG SHA-256 (NOPR) : 193 Kb/s, 611 cycles/byte
28+
HMAC_DRBG SHA-256 (PR) : 170 Kb/s, 695 cycles/byte
29+
RSA-2048 : 28 ms/ public
30+
RSA-2048 : 953 ms/private
31+
RSA-4096 : 93 ms/ public
32+
RSA-4096 : 5327 ms/private
33+
ECDSA-secp384r1 : 451 ms/sign
34+
ECDSA-secp256r1 : 304 ms/sign
35+
ECDSA-secp384r1 : 863 ms/verify
36+
ECDSA-secp256r1 : 594 ms/verify
37+
ECDHE-secp384r1 : 829 ms/handshake
38+
ECDHE-secp256r1 : 566 ms/handshake
39+
ECDHE-Curve25519 : 533 ms/handshake
40+
ECDH-secp384r1 : 407 ms/handshake
41+
ECDH-secp256r1 : 281 ms/handshake
42+
ECDH-Curve25519 : 268 ms/handshake
43+
44+
DONE
45+
```

0 commit comments

Comments
 (0)