ST25DV-I2C Crypto Demonstration: User Manual
ST25DV-I2C Crypto Demonstration: User Manual
User manual
Introduction
This user manual shows how to run the "ST25DV-I2C Crypto Demo", using the ST25DV-I2C fast transfer mode (FTM) to
establish a secure transfer channel (STC) over NFC between an STM32 microcontroller and an Android™ smartphone.
The ST25DV-I2C is a dynamic NFC tag IC able to communicate with NFC readers and smartphones, and also with a
microcontroller through an I2C interface. The FTM feature allows to speed up the communication between these two interfaces.
This demonstration establishes an STC by using cryptography to perform a mutual authentication, and to encrypt the
communications over NFC. This STC is used during the demonstration to securely:
• Send and retrieve data
• Set the device settings
• Upload new firmware
Only the granted user / smartphone is able to communicate with the STM32 device to perform these operations.
The STC over NFC has applications in different sectors (such as industrial, home appliance and consumer) where the control of
a device is restricted to authorized users, and when the personal data must be protected.
The following packages are available on www.st.com for this demonstration:
• STSW-ST25DV003 firmware
• STSW-ST25003 Android™ application
1 General information
The "ST25DV-I2C Crypto Demo" runs on the ST25DV-I2C-DISCO kit, featuring a ST25DV-I2C tag connected to a
STM32L476 device through the I2C bus. The ST25DV-I2C-DISCO kit represents an IOT sensor device, which is
controlled by an Android™ smartphone through the NFC.
NFC ST25DV-I2C-DISCO
I2C
ST25DV-I2C STM32 device
Secure transfer
channel
When a communication between the device and a smartphone is started, a mutual authentication is done. It
ensures that:
• The user of the smartphone has a permission to communicate with this device
• The device is not counterfeited
Once the mutual authentication is done, all the communications between the microcontroller and the Android™
phone are encrypted, so the user can configure the product or retrieve data securely. Anyone who spies on the
data exchanged on the NFC is not able to interpret them. The key used to encrypt the communication changes
each time a mutual authentication is done, this action prevents someone from recording the encrypted content
and replaying it.
In this demonstration, the first user of the device becomes the administrator of the product so the device refuses
any request from other users.
More details on the cryptographic processing used in the demonstration are provided in Section 2 Security
processes.
Additional details on the implementation are provided in the AN5323 ST25DV-I2C crypto demonstration.
1.2 Acronyms
Table 1. Acronyms
Acronyms Meaning
1.4 Installation
This demonstration requires to download the firmware (STSW-ST25DV003 on www.st.com) for the ST25DV-I2C-
DISCO board and the Android executable (APK, STSW-ST25003 on www.st.com) to use on the Android phone.
With a file explorer, browse the memory of the phone and go to the folder where the APK was copied. Click on the
file to install it.
Note: If there is no file explorer, the program "File commander" is available for free on Google Play™.
The STSW-ST25DV003 package contains a second firmware binary file (“ST25DV-
I2C_Demo_FwUpgrd_MB1396.bin”) intended to be used for the secure firmware upgrade demonstration. This file
has to be downloaded on the Android smartphone.
Then by starting the demonstration and establishing a secure channel (as described in section Section
3.2.1 Secure transfer channel setup), the ST25DV-I2C-DISCO saves the connection data (smartphone "Login"
and "Public key") and only accepts the forecoming connections with same smartphone credentials.
Note: As these data are saved in the flash memory of the STM32, the ST25DV-I2C-DISCO firmware restore them after
a reset.
Once an "Authorized User" is set, the login (the name of the smartphone) is displayed, and the “key exchange”
box is now checked.
Any other user / smartphone trying to connect to this ST25DV-I2C-DISCO board is rejected.
It is possible to set a new "Authorized User" by pushing the user button (blue) of the ST25DV-I2C-DISCO
motherboard (any previously stored "Authorized User" is erased by the firmware).
1.5 Disclaimer
The Android application and the associated firmware are provided under the SLA0052 license agreement,
available on www.st.com
2 Security processes
This section describes the security processes used to perform a mutual authentication and establish a secure
transfer channel (SFC) where all the communications are encrypted.
To establish an encrypted channel, the Android phone and the ST25DV-I2C-DISCO kit have to agree on a
symmetric key used to encrypt all the communications between the two devices. This key cannot be exchanged
over NFC because someone may spy all the data exchanged and get the key.
Elliptic curve Diffie–Hellman (aka “ECDH”) is a well known “key agreement protocol” used to establish a “Shared
Secret” over an insecure channel. Section 2.3 Derivation of a public key describes how this "Shared Secret" is
used to define a symmetric key used to encrypt all the communications of this session.
The two communicating devices must both have an ECC key pair. They exchange their public keys (the private
key remain secret and is not shared). Each device use ECDH scheme to combine its own private key with the
public key of the peer device. Thanks to ECC, these two operations leads to the exact same result, that is called
“Shared Secret” (see Figure 5).
Someone who has spied the communication has seen the public keys exchanged but this is not sufficient to find
the "Shared Secret".
Discovery Android
Android phone public key public key ST25DV-I2C-DISCO
Pub Pub
The two devices have been able to define a "Shared Secret" that nobody else can find. Only the ones knowing
the private keys can get the "Shared Secret".
The "Shared Secret" can be used to encrypt the communications between the two devices but it has a weakness:
the ECC key pairs of the Android and ST25DV-I2C-DISCO devices do not change, so the "Shared Secret" is
always the same. Someone can record the data exchanged over NFC and re-execute them. This is called "replay
attack".
To avoid this problem, a key is derived from the "Shared Secret" plus a random number (changing every times).
The key obtained is called “AES Session key” and is used to encrypt all the exchanges between the two devices.
The random number changes every times so the session key is different every times.
By convention, the random number used for key derivation is chosen by the ST25DV-I2C-DISCO and shared not
encrypted with the Android phone.
In this demonstration, an AES-256-GCM encryption is used. GCM (Galois counter mode) allows authentication of
the encrypted messages received (GMAC). Each encrypted message is authenticated so the receiver detects if
the received encrypted message has been modified.
When the communication between the Android phone and the ST25DV-I2C-DISCO starts, the Android phone
sends a “Login” to the ST25DV-I2C-DISCO. This "Login" corresponds to the "Login" received by the ST25DV-I2C-
DISCO during the keys exchange phase when the product has been used for the very first time. The ST25DV-
I2C-DISCO board has saved this "Login name" and the corresponding "Public key" in its static memory.
The ST25DV-I2C-DISCO sends a challenge to the Android phone to check if it really knows the "Private key"
corresponding to this "Public key":
1. The ST25DV-I2C-DISCO generates a random number, encrypts it with the AES session key and sends it to
the Android phone.
2. If the smartphone owns the "Private key" corresponding to the "Login name", it computes the "AES Session
key" and decrypts the message received.
3. The smartphone sends a SHA256 hash of the random number in order to prove that it has been able to
decrypt the challenge.
4. The ST25DV-I2C-DISCO also computes the SHA256 hash and then knows if the answer is correct.
Decrypt Encrypt
This authentication protects the device from someone trying to usurp the "Login" of a valid user. A hacker may
know the "Login" and the associated "Public key" (since they are exchanged not encrypted over NFC) but does
not know the "Private key" so the "Shared Secret" or the "AES Session key" cannot be computed.
The Android phone performs an authentication of the ST25DV-I2C-DISCO. This is done to be sure that the board
is genuine and corresponds to the "Public key" that has been saved in the smartphone during the key exchange
phase.
The procedure is the same but in the opposite direction: now the Android phone generates a challenge, encrypts
it with the "AES Session key" and sends it to the ST25DV-I2C-DISCO.
The ST25DV-I2C-DISCO decrypts it and sends a SHA256 hash to prove that the decryption is correct.
Encrypt Decrypt
This authentication protects from counterfeited products: a counterfeited product can contain a valid "Public key"
taken on a valid product. However it does not contain the "Secret Key" that is stored in the product and which is
not readable. So here also, the counterfeited products is not able to compute the "Shared Secret" nor the "AES
Session key". So it fails to pass this authentication phase.
Once the mutual authentication has been run, all the forecoming communications over NFC are encrypted using
the current AES session key, which means:
• Someone spying the NFC communication is not able to decrypt the transmitted data (because the current
"AES Session key" is unknown).
• A message not encrypted with the current "AES Session key" is rejected
• A valid message (encrypted with the current "AES Session key") maliciously modified is rejected too (thanks
to the message authentication).
The AES encryption is performed by using the GCM.
This encryption method requires to transmit additional metadata along with the encrypted data:
1. An initialization vector (12 bytes) required to initialize the decryption process. This initialisation vector
changes for every new encrypted message.
2. A GMAC of 16 bytes used to ensure the message integrity and source.
Note: No block-padding is required by this encryption method.
Manually launch the application “ST25DV-I2C-Crypto Demo” or simply tap the ST25DV-I2C NFC tag, Android
automatically launches the “ST25DV-I2C-Crypto Demo” application, if it is installed.
When the application starts, it initializes the Android KeyStore and some cryptography elements.
By default, the “User authentication” is disabled but this can be changed in the "Settings" menu. If enabled, the
user has to enter its pin-code or fingerprint every times this application is started.
This section describes how the "ST25DV-I2C Crypto Demo" application works.
On the ST25DV-I2C-DISCO board, similar information is displayed to show what is the current security status,
and which user is logged.
2. The ST25DV-I2C-DISCO firmware reads the mailbox buffer and decrypts the command.
3. The ST25DV-I2C-DISCO firmware encrypts and writes the data through I2C to the ST25DV-I2C FTM
mailbox buffer.
4. The Android phone reads over NFC and decrypts the mailbox buffer content to finally display the
corresponding graph. The same graph is displayed on the ST25DV-I2C-DISCO board.
Note: The shape of the curve can be changed, simply by touching the plot on the ST25DV-I2C-DISCO screen. The
user then restarts the transfer to receive the new set of points.
Note: A progress bar is displayed during the download. On the Android phone, two progress bars are visible, a blue
one and a light blue one.
• The blue one corresponds to the data received and acknowledged (data integrity has been checked)
• The light blue one corresponds to data received but not yet acknowledged. They might be flushed if the
integrity verification detects an error.
The message sent is displayed as well on the screen of the ST25DV-I2C-DISCO board.
Various cryptographic keys are used in the "ST25DV-I2C Crypto Demo". This screen has been added to help the
user to understand the role of each of them. In the Android applications, click on a key to get information about it.
This screen is used to change some settings of the "ST25DV-I2C Crypto Demo" application.
• Use Addressed NFC command: Communication between the Android phone and the ST25DV-I2C-DISCO
board is done through NFC Type 5. Two modes are available for NFC Type5 commands:
– Addressed
– Non-addressed
When using addressed commands, the NFC Tag UID (on 8 bytes) is included in the command. This is safer
because only the targeted tag processes the command but the communication is slower due to those extra
bytes to send for every packet exchanged.
This screen shows the software license agreement that user accepts when using this program. It also indicates
the version number of the program.
Revision history
Contents
1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 Purpose and scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Hardware equipment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4.1 ST25DV-I2C-DISCO kit setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Security processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1 Public key exchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Definition of a "Shared Secret" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Derivation of a public key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Authentication of the Android phone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.5 Authentication of the connected device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.6 Encrypted data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
List of tables
Table 1. Acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Table 2. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
List of figures
Figure 1. Connection scheme with ST25DV-I2C-DISCO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Figure 2. ST25DV-I2C-DISCO screen - no user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 3. ST25DV-I2C-DISCO screen - registered user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 4. ST25DV-I2C-DISCO screen - denied access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 5. Elliptic curve Diffie-Hellman over NFC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 6. Android phone authentication over NFC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 7. ST25DV-I2C-DISCO authentication over NFC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 8. "ST25DV-I2C Crypto Demo" - home screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 9. "ST25DV-I2C-Crypto Demo" - secure transfer channel setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 10. ST25DV-I2C-DISCO screen when no user has been registered . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 11. ST25DV-I2C-DISCO screen after mutual authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 12. "ST25DV-I2C-Crypto Demo" - step by step mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 13. "ST25DV-I2C Crypto Demo" - data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 14. "ST25DV-I2C Crypto Demo" - picture transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 15. "ST25DV-I2C-Crypto Demo" - progress bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 16. "ST25DV-I2C Crypto Demo" - firmware upgrade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 17. "ST25DV-I2C Crypto Demo" - eavesdropper. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 18. "ST25DV-I2C-DISCO Crypto Demo" - displayed message screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 19. "ST25DV-I2C-Crypto Demo" - keys overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 20. "ST25DV-I2C-Crypto Demo" - settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 21. "ST25DV-I2C-Crypto Demo" - license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18