# Project Name：Crypto_Demo

---
## Function description
- **Crypto**:
  - This codes is a Demo to give a example that how to use the Crypto API.The Demo support all services that are supported by the  hardware object, such as ***CMAC Generation***  and ***verification*** , ***Encryption/Encryption***, and ***Random Generation***.Asynchronous job use DMA method to transmit data.
  - In the demo,give the example that service run under the processing type ***synchron***,or ***asynchron***.Also,this demo show how to make the service run under the mode of ***SingleCall***,separately call(***START***,***UPDATE***,***FINISH***),and ***StreamCall***(***START***,***UPDATE***).

- **Use Examples To Generate Keil or IAR Project**
  - Since the files other than main.c under the app directory will not be automatically copied to the Keil or IAR project, it is necessary to manually copy the other files under ***Examples\Crypto\YCT\Crypto_Demo\app*** directory to the project before compiling.
  
- **Data length alignment**
  - ***Random Generation*** Input data not need.Output data length must be 4 byte aligned and must less than 32.
  - ***CMAC Generation*** and ***verification***  Input data length must be 16 byte aligned,If not match,you should fill data with 0x00 or 0xff or others,but calculation result will be chang.Output data length must be 16 byte.Key length in-bits supports 128-bits.
  - ***Encryption/Encryption***  Input data length must be 16 byte aligned,If not match,you should fill data with 0x00 or 0xff or others,but calculation result will be chang.The length of input data and output data must be equal.Key length in-bits supports 128-bits.
  
In this example, after the MCU completes the initialization of modules such as the Clock and Crypto, the main() function will repeatedly perform the tasks (e.g., encryption/decryption, random number generation, CMAC generation/verification) configured in the demo. We can check the results of each task as the following:
  - Upon completion of each encryption/decryption or CMAC generation/verification task, the program checks whether the result is correct. If the result is incorrect, the program will enter while(1). 
  - For the random number generation task, no result verification is performed in demo. Users can verify the output by setting a breakpoint after the random number generation function completes and inspecting the result buffer array (Random_Generate),as showing in following picture:
![API](RandomCheck.png)

---
## Setup
+ ***Step1***: Open the `Crypto_Demo.yct` with the YCT tool, config the toolchain per your required(by default, the VS code + GCC are used)
+ ***Step2***：Generate the codes， you can change the configurations if needed(to adapt to your own HW design), if so, please ensure all the modifications are OK with no any errors exist before generating the code.
+ ***Step3***: Open the generated project with VS code/IAR/Keil IDE per your selected.
+ ***Step4***: Compile the project, power on the EVB and download it to the EVB via the available debugger, such as a J-Link debugger probe.
+ ***Step5***: At last, enjoy the demo example.

---

## Hardware requirement
+ **EVB**: YTM32B1MD1-EVB-Q100-Rev.A/B
+ **Debugger**: J-Link HW v9 or later with YUNTU `YTM32B1MD1` patch(support package) installed.

**Note**: Please check the version number at the bottom of the EVB. If it is `YTM32B1MD1-EVB-Q100-Rev.A/B`, please use the example projects ending with `_RevA` for `Icu_Demo`.
---

## Software requirement

+ **Config & Code Generation Tool**
  + **MCAL**: 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(`armclang v6.18.2` is recommended to be used as the compiler)
  + **IAR**: IAR v9.50 or later version
  + **VS Code**: Microsoft Visual Studio Code IDE v1.76 or later version(C/C++ support, GNU toolchain, CMake v3.25, ninja, Cortex-Debug extensions installation required)
+ **Debugger driver**
    + **J-Link**: SEGGER J-Link v7.82 or later version, YUNTU `YTM32B1MD1` patch(support package) installation required.
    + **Ozone Debugger tool**: SEGGER Ozone v3.28 or later version.

    ***Note***: **YTM32B1MD1** patch install required which can be obtained via **YCT** or contact ***YUNTU sales/FAE team***.

---