Last edited one year ago

STPM4RasPI expansion board

Applicable for STM32MP13x lines, STM32MP15x lines

1. Article purpose[edit source]

The purpose of this article is to explain how to integrate the STPM4RasPI expansion board with STM32MP157F-DK2 Discovery kit More info green.png and STM32MP135F-DK Discovery kit More info green.png. A signature verification usecase is included, in order to verify the TPM integration.
Multiple services are available using TPM (mostly on PC and mobile devices):

  • Cryptographic keys generation, protection, management and usage
  • Cryptographic device identity
  • Secure logging, log-reporting and, certification or authentication
  • Secure non volatile storage
  • Other functions including hashing, random number generation and secure clock

Several use cases are available:

  • Platform integrity: the boot process relies on TPM for software integrity and authentication during each boot stage
  • Disk encryption: encrypt and decrypt drive using TPM crypto core
  • Password protection, and so on.

The usecase described in this article uses the cryptographic key generation functionality on the TPM.

2. Prerequisites[edit source]

2.1. Hardware prerequisites[edit source]

  • STM32MP157C-DK2 Discovery kit Warning.png or STM32MP135F-DK Discovery kit More info green.png

For more information on the STM32 discovery board and how to start it up, go to section Getting started with STM32MP157x-DK2 or Getting started with STM32MP135x-DK

  • LAN connectivity.
  • STPM4RasPI expansion board[1]
Image.PF267656.en.feature-description-include-personalized-no-cpn-medium.jpg

The STPM4RasPI is an official extension board to connect the ST33 TPM products to the Raspberry Pi® device. It is designed for development, proof of concept or demonstration activities. The board is shipped with one soldered trusted platform module. The ST33 TPM device soldered is the ST33TPHF20SPI, and is a TPM V2.0 specification implementation.

2.2. Software prerequisites[edit source]

The STM32MP1 distribution package must be installed on a host PC. For more information on the OpenSTLinux distribution package go to STM32MP1 Distribution Package article.

For demonstration purposes, the TPM is used at runtime only, on top of the LinuxTM kernel. It uses the TPM2 software stack (TSS) [2] implemented in the OpenSTLinux distribution. The TPM can be handled by the tpm2-tools delivered with the TSS.

TSS2 tpm.png

To check the TPM features, we use the tool openssl (for the signature verification usecase).

3. Software customization to support STPM4RasPI expansion board[edit source]

The LinuxTM kernel must be configured to control the STPM4RasPI expansion board on the STM32MP157C-DK2 Warning.png or STM32MP135F-DK More info green.png.

The customization consists in modifying the Linux kernel configuration, managing the appropriate device tree elements and including TSS components.

Note that:

  • The software customization has been validated in the OpenSTLinux distribution environment and with the configuration (DISTRO="openstlinux-weston", MACHINE="<stm32mp13-disco|stm32mp15-disco>", IMAGE="st-image-weston").

3.1. Kernel configuration[edit source]

The LinuxTM kernel must be updated to include the TPM driver for SPI.

The ST33TPHF20SPI is TCG-compliant and supports the following standard TCG Linux SPI drivers:

To check whether associated drivers are enabled inside the kernel, executes the following instructions on the target:

  cat /proc/config.gz | gunzip | grep TCG
CONFIG_TCG_TPM=y
CONFIG_TCG_TIS=y
CONFIG_TCG_TIS_SPI=y

If the above configuration are not enabled, the kernel config has to be modified:

bitbake linux-stm32mp -c menuconfig

Select in the kernel menu config :

Device Drivers  --->
   Character devices --->
   <*>   TPM Harware Support ---> 
         <*>   TPM Interface Specification 1.3 Interface / TPM 2.0 FIFO Interface - (SPI)

For more information on the LinuxTM Kernel configuration refer to How to configure the Kernel with Menuconfig

3.2. Kernel device tree configuration[edit source]

The TPM driver uses the SPI5 on the GPIO expansion connector.

The device tree must be updated to declare and initialize them.

Information to update the device tree in the OpenSTLinux distribution is written in How to cross-compile with the Distribution Package

3.2.1. DTS board STM32MP157C-DK2 Warning.png[edit source]

  • Go to the <build dir>/workspace/sources/<name of kernel recipe>/ directory
 cd <build dir>/workspace/sources/<name of kernel recipe>/
  • Edit the arch/arm/boot/dts/stm32mp157c-dk2.dts Device Tree Source file, add the following lines to update the node spi5.
&spi5{
	cs-gpios = <&gpiof 6 0>;
	status = "okay";

	st33htpm0: st33htpm@0{
		status="okay";
		compatible = "st,st33htpm-spi";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0>; /* CS #0 */
		spi-max-frequency = <10000000>;
		};
}; 

3.2.2. DTS board STM32MP135F-DK More info green.png[edit source]

  • Go to the <build dir>/workspace/sources/<name of kernel recipe>/ directory
 cd <build dir>/workspace/sources/<name of kernel recipe>/
  • Edit the arch/arm/boot/dts/stm32mp135f-dk.dts Device Tree Source file, add the following lines to update the node spi5.
&spi5{
	cs-gpios = <&gpioh 11 0>;
	status = "okay";

	st33htpm0: st33htpm@0{
		status="okay";
		compatible = "st,st33htpm-spi";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0>; /* CS #0 */
		spi-max-frequency = <10000000>;
		};
}; 

3.3. tpm2 TSS components software[edit source]

Add the "tpm2 TSS" component software in the following image file (layers/meta-st/meta-st-openstlinux/conf/distro/include/openstlinux.inc)

DISTRO_FEATURES:append = " tpm2 "

Add the yocto layer meta-security

cd <working directory path of distribution>/layers
git clone git://git.yoctoproject.org/meta-security -b kirkstone

3.4. Image build and flash[edit source]

Go the article STM32MP1 Distribution Package for the process to adapt and flash an image for any LinuxTM distributions.

4. TPM driver loading check[edit source]

When the TPM driver is loaded, /dev/tpm0 and /dev/tpmrm0 are present, as shown in the figure below.

dmesg | grep tpm
[    1.525447] tpm_tis_spi spi0.0: 2.0 TPM (device-id 0x0, rev-id 78)
ls -l /dev | grep tpm
crw------- 1 tss  tss    10,   224 Oct 11 15:27 tpm0
crw------- 1 root root  253, 65536 Oct 11 15:27 tpmrm0

5. Sign data with TPM2 key & signature verification with OpenSSL[edit source]

This is an example of using the TPM to perform signature of a file "msg.txt" hash (digest). A verification is done with the openssl "dgst -verify" command.

Message creation example :

 echo dzeydezyetrefygzuedghdgie > msg.txt

Primary key creation :

tpm2_createprimary -C o -c pri.txt

Signature key creation :

tpm2_create -C pri.txt -g sha256 -G rsa -u kpub.bin -r kpriv.bin

Loading of the created signature key in TPM :

tpm2_load -u kpub.bin -r kpriv.bin -C pri.txt -c key.txt

Signature of the hash with the TPM signed key

tpm2_sign -c key.txt -g sha256 -f plain -o hash.plain msg.txt

Read of the public part of the TPM signing key

tpm2_readpublic -c key.txt -f der -o key_sig_pub.der

Verification with openssl dgst

openssl dgst -verify key_sig_pub.der -keyform der -sha256 -signature hash.plain msg.txt

6. References[edit source]