Skip to content

Infineon/mtb-t2g-example-crypto-performance

Repository files navigation

CRYPTO Performance Measurement

This code example shows the performance differences of crypto hardware block and the one that is performed by CPU. The result should be printed to the terminal along with the approximate time taken for each method.

Device

The device used in this code example (CE) is:

Board

The board used for testing is:

Scope of work

In this example, the performance is analyzed while generating a 32-byte hash value or message digest for a given data with the SHA256 algorithm using the Cryptographic hardware block in the MCU. The cipher procedure on CPU is done by MbedTLS library.

Introduction

Cryptography Block

  • Supports Enhanced Secure Hardware Extension (eSHE) and Hardware Security Module (HSM)
  • Secure boot and authentication
    • Using digital signature verification
    • Using fast secure boot
  • AES: 128-bit blocks, 128-/192-/256-bit keys
  • 3DES: 64-bit blocks, 64-bit key
  • Vector unit supporting asymmetric key cryptography such as Rivest-Shamir-Adleman (RSA) and Elliptic Curve (ECC)
  • SHA-1/2/3: SHA-512, SHA-256, SHA-160 with variable length input data
  • CRC: supports CCITT CRC16 and IEEE-802.3 CRC32
  • True random number generator (TRNG) and pseudo random number generator (PRNG)
  • Galois/Counter Mode (GCM)

More details can be found in:

Hardware setup

This CE has been developed for:

The example uses the default configuration of the board. Refer to the kit user guide to verify that the board is properly configured.

Implementation

In this example, the message with size 256 Bytes is hardcoded. A 32-byte long hash value is generated using the SHA-256 algorithm. The 32-byte hash value generated for the given message using MbedTLS library and crypto block is then displayed on the UART terminal emulator along with the approximate time taken for generating the hash values calculated using TCPWM counter.

SHA-256 Calculation

  • Crypto hardware
  • CPU (MbedTLS library)
    • A series of processing steps are contained in the ComputeHash() function. For details about MbedTLS, please refer the README on here
    • MTB provides a library named mbedTLS Crypto acceleration which provides the same interface with MbedTLS which can use the Crypto hardware in its computation. A SHA-256 calculation is supported and available in this code example. To use this feature, delete the definition of DISABLE_MBEDTLS_ACCELERATION in the project Makefile
    • However, the library does not support the full set of the hardware features. For details, check the README on here

Time Measurement

Miscellaneous settings

  • STDOUT setting

    • Calling cy_retarget_io_init() function to use UART as STDIN / STDOUT
      • Initialize the port defined as CYBSP_DEBUG_UART_TX as UART TX and CYBSP_DEBUG_UART_RX as UART RX (these pins are connected to KitProg3 COM port)
      • The serial port parameters are 8N1 and 115200 baudrate

Compiling and programming

Before testing this code example:

  • Connect the board to your PC using the provided USB cable through the KitProg3 USB connector
  • Build the project using the dedicated Build button or by right-clicking the project name and selecting "Build Project"

Run and Test

For this example, a terminal emulator is required to display outputs and receive keys pressed. You can install a terminal emulator if you do not have one. In this example, Tera Term was used as the terminal emulator.

After code compilation, perform the following steps to flashing the device:

  1. Open a terminal program and select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud
  2. Program the board using one of the following:
    • Select the code example project in the Project Explorer
    • In the Quick Panel, scroll down, and click [Project Name] Program (KitProg3_MiniProg4)
  3. After programming, the code example starts automatically
  4. The result will be shown as in below figure
    Figure: Terminal Output

Debug Mode

You can debug the example to step through the code. In the IDE, use the <Application Name> Debug (KitProg3_MiniProg4) configuration in the Quick Panel.For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ software user guide

Note: (Only while debugging) On the CM7 CPU, some code in main() may execute before the debugger halts at the beginning of main(). This means that some code executes twice: once before the debugger stops execution, and again after the debugger resets the program counter to the beginning of main(). See KBA231071 to learn about this and for the workaround.

References

Relevant Application notes are:

  • AN235305 - Getting started with TRAVEO™ T2G family MCUs in ModusToolbox™
  • AN220253 - Using the CRYPTO Module in TRAVEO™ II Family

ModusToolbox™ is available online:

Associated TRAVEO™ T2G MCUs can be found on:

More code examples can be found on the GIT repository:

For additional trainings, visit our webpage:

For questions and support, use the TRAVEO™ T2G Forum: