This example uses hardware accelerators of the supported devices to perform AES encryption and decryption on the supported device.
Build the example and flash it to a supported device. Open a terminal emulator and follow the the instructions shown on the console.
When starting the application, the user will get the option to run the program in encryption mode or decryption mode.
In ecryption mode, the example will ask the user for a short phrase to generate an initial vector used in the AES encryption process. The user may type any phrase ended by newline or limited to a maximum of 16 bytes. After the short phrase, the user should start typing in the message to be encrypted, followed by a newline to mark the end of the message. The message length is limited to the #define MAX_MESSAGE_SIZE_ENCRYPTION. Then the program will encrypt the message (plaintext), and print out the ciphertext, preceded with the initial vector of 16 bytes and followed by a message digest tag of 32 bytes. All data is converted to hexadecimal readable text format before sent to the serial port.
The format is:
Initial Vector(16 bytes) | Ciphertext | Message Digest Tag (32 bytes)
The user can copy the output and feed it back to the program for decryption later. The user need to reset the kit in order to run decryption mode.
In decryption mode, the example will expect to receive a decrypted message in the same format as generated by the encryption.
To check the performance gain of the hardware acceleration, the user can switch it off. This is done by switching the value of Enable hardware acceleration of crypto operations in the component Mbed TLS common functionality. This is found under the tab SOFTWARE COMPONENTS → Platform → Security.
Useful tip: Tick the boxes of Configurable Components and Installed Components to find the configuration file more easily.
The AES is operations are accelerated by the CRYPTO AES accelerator.
The SHA operations are accelerated by the CRYPTO SHA-256 accelerator.
The example redirects standard I/O to the VCOM virtual serial port.The user can use a terminal emulator program to connect to the serial port with the default settings of 115200-8-N-1.