# MbedTls with PSA Demo Example Code

## Project Name: MbedTls_with_PSA_Demo

---

## Function description

This project demonstrates the usage of PSA Crypto API for AES encryption:
- **PSA AES**: 
  - Performs AES-128 ECB CBC encryption and decryption using PSA Crypto API
  - Demonstrates encryption and decryption operations, and results display
- **PSA RSA**:
  - Performs RSA 4096 key generation, hash signing and verification using PSA Crypto API
  - Demonstrates key generation, signing and verify operations, and results display
- **PSA ECDSA**:
  - Performs ECC 256 key generation, hash signing and verification using PSA Crypto API
  - Demonstrates key generation, signing and verify operations, and results display
---
- ***NOTE***
  - If key generation is not required, the stack size can be appropriately reduced by YCT tools.
  - For RSA 4096, signing requires a buffer of nearly 35KB, while verification only needs 14KB. Therefore, the buffer size for running the MbedTLS library can be adjusted appropriately based on actual requirements.
---


## HW requirement
+ **EVB**: YTM32B1ME0-EVB-Q144
+ **Debugger**: J-LINK v9.2 or later with YUNTU YTM32B1ME0 patch(support package) installed
+ **Connect**: J32 connector for UART output (baud rate: 115200)

---

## SW requirement

+ **Config & Code Generation Tool**
  + **SDK**: Yuntu Config Tool(YCT) v2.7.0 or later version
+ **Compiler Toolchain**
  + **GCC**: GNU GCC v10.3 or later version
  + **Keil/MDK**: ARM Keil/MDK v5.36 or later version
  + **IAR**: IAR v8.4 or later version
  + **VS Code**: Microsoft Visual Studio Code IDE v1.76 or later version
+ **Debugger driver**
  + **J-LINK**: SEGGER JLINK v6.96 or later version
  + **Ozone**: SEGGER Ozone v3.28 or later version

***Note***: YTM32B1ME0 patch installation required, available via YCT or YUNTU support.

---

## Setup

1. Open the project with your preferred IDE ***(For Keil and IAR, it may be necessary to manually add other files from the app directory) to the IDE)***
2. Build and compile the project
3. Connect the EVB and debugger
4. Download and run the program
5. Monitor the UART output to see the encryption results

---

## Expected Output

The program will display from the UART:
**1. AES ECB encryption and decryption results**
MbedTLS AES ECB Encryption Test:
Key: 000102030405060708090a0b0c0d0e0f020305070b0d1113171d1f25292b2f35
Plaintext: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
Ciphertext: 0a940bb5416ef045f1c39458c653ea5a07feef74e1d5036e900eee118e949293
Decrypted: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
AES encryption test succeeded!

**2. AES CBC encryption and decryption results**
MbedTLS AES CBC Encryption Test:
Key: 000102030405060708090a0b0c0d0e0f020305070b0d1113171d1f25292b2f35
IV: 000102030405060708090a0b0c0d0e0f00000000001000000040400410100000
Plaintext: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
Ciphertext: c6a13b37878f5b826f4f8162a1c8d87935d9dcdb829fec3352e7bf10b84be4a5
Decrypted: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
AES CBC encryption test succeeded!

**3. RSA Sign and Verify results**
MbedTLS RSA Sign and Verify Test:

Test RSA Sign
Signature length: 512
Signature:  
RSA Sign test succeeded!

Test RSA Verify
RSA Verify test succeeded!

**4. ECDSA Sign and Verify results**
MbedTLS ECDSA Sign and Verify Test:

MbedTLS ECDSA Sign Test:
Signature length: 64
Signature: 69d6165d34dda462c5bbdee1b4d8c77df43e165596eedde11a87009ae937feaf21b2cceccc428ba7a8f181ece552d6a80865eda2c1e1d789a23c1e02bc54bdb9
ECDSA sign test succeeded!

MbedTLS ECDSA Verify Test:
Signature verification succeeded!
ECDSA verify test succeeded!


---
