# SCA-Protected RSA with ChipWhisperer-Nano

This repository provides an RSA implementation hardened against side-channel attacks (SCA), together with tooling for power trace acquisition and analysis using the [ChipWhisperer](https://github.com/newaetech/chipwhisperer) platform. It is tailored specifically for **ChipWhisperer-Nano** and supports trace capture, correlation power analysis (CPA), and test vector leakage assessment (TVLA).

---

##  Repository Structure

.
├── cpa # CPA attack scripts and correlation analysis
├── inc # Shared header files
├── src # Firmware source code
│   ├── codec # Encoding/decoding helpers
│   ├── int # Integer arithmetic
│   ├── rand # Random number generators
│   │   ├── hash
│   │   ├── mac
│   │   └── rand
│   └── rsa # Core RSA logic and side-channel protections
└── tvla # Test Vector Leakage Assessment (TVLA)


---

## Prerequisites

1. Install ChipWhisperer by following the [official installation guide](https://chipwhisperer.readthedocs.io/en/latest/installation.html).

2. Clone the ChipWhisperer repository and check out the tested commit for compatibility:

   ```bash
   git clone https://github.com/newaetech/chipwhisperer.git
   cd chipwhisperer
   git checkout c5f01dbc4629d0a10bfe716054a7ee4ddcd4e579
   ```
2. Let's consider chipwshiperer as the base folder. Copy the whole folder `cw` to `./hardware/victims/firmware/`
3. Modifiy the `../Makefile.inc` in the firmware folder to create subfolders in build directory.
```
$(OBJDIR)/%.o : %.c
	@$(ECHO_BLANK)
	@echo $(MSG_COMPILING) $<
	@mkdir -p $(@D)
	$(CC) -c $(ALL_CFLAGS) $< -o $@

...

$(OBJDIR)/%.o : %.cpp
	@$(ECHO_BLANK)
	@echo $(MSG_COMPILING_CPP) $<
	@mkdir -p $(@D)
	$(CC) -c $(ALL_CPPFLAGS) $< -o $@

...

$(OBJDIR)/%.o : %.S
	@$(ECHO_BLANK)
	@echo $(MSG_ASSEMBLING) $<
	@mkdir -p $(@D)
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
```

5. Run `TVLA.ipynb` or `CPA.ipynb` in jupter notebook. 