# emanorabi254/rsa architecture

> Architecture diagram of the GitHub repository emanorabi254/rsa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emanorabi254/rsa
- Repository: https://github.com/emanorabi254/rsa

## Overview

##### Project Type and Purpose
- This is an embedded‐systems/cryptography demonstration project targeting an 8051‐class microcontroller, simulated in Proteus.
- Purpose: implement RSA encryption/decryption (optimized with CRT) and exchange ciphertext over a UART link.

##### File Structure
- Top level:
- Proteus/ (simulation project file: RSA.pdsprj)
- README.md (project description)
- code/ (all C source and headers plus Keil/UVision project files)
- In code/:
- main.c (application entry point: orchestrates key generation, encryption, decryption, UART I/O)
- rsa.h (RSA routines: keygen, encrypt, CRT‐based decrypt)
- uart.h (UART initialization and transmit/receive APIs)
- project.uvproj / uvopt / uvgui.Original (Keil project configs)

##### Extract Architecture Insights from README
- Four logical stages:
1. Key Generation
2. Encryption
3. UART Communication
4. Decryption (CRT‐optimized)
- Hardware constraints: 8051 limited RAM/compute, requiring custom big‐integer handling and CRT optimization.
- Simulation environment: Proteus ties together virtual 8051, UART terminal, and possible external peripherals.

##### Main Components and Their Relationships
a. Hardware Layer
- 8051 MCU (CPU + on‐chip RAM/ROM)
- UART transceiver (pins TX/RX)
- Proteus virtual terminal or external UART device
b. Software Layer (on the MCU)
- Application (main.c)
- Crypto Module (rsa.h + implementation)
– KeyGen subcomponent
– Encrypt subcomponent
– CRT‐Decrypt subcomponent
- UART Module (uart.h + implementation)
– Init UART
– Send/Receive routines
c. Simulation Environment
- Proteus simulator orchestrating clock, wires, and virtual terminal
d. Data Flows & Interactions
1. At startup, Application invokes Crypto.KeyGen → generates public/private keys.
2. Application takes plaintext → Crypto.Encrypt → ciphertext.
3. UART.Tx → sends ciphertext over serial link.
4. UART.Rx → receives ciphertext (could loop back in Proteus).
5. Crypto.CRT_Decrypt → recovers plaintext.
6. Application outputs decrypted text to terminal/display.

##### Architectural Patterns and Design Principles
- Layered Separation: hardware abstraction (UART module), crypto logic (RSA module), application logic (main).
- Modularity: each header/source pair encapsulates one concern.
- Optimization: CRT is a performance optimization sub‐layer within the crypto component.

##### Step‐by‐Step for the Principal Software Engineer
2. In Simulation lane, place a “Proteus” container around the Hardware blocks.
5. Connect:
6. Notes or stereotypes for CRT optimization inside the RSA Module, and mention 8051 resource constraints next to the MCU block.

##### Essential Elements
- Clear, unique labels for each block (e.g., “8051 MCU”, “RSA Module”)
- Callouts or side notes for key design points (CRT, big‐integer handling, UART baud rate/config)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Simulation Layer
    subgraph "Proteus Simulator" 
        direction TB
        proteus["Proteus Simulation\n(RSA.pdsprj)"] 
    end
    class proteus simulation
    click proteus "https://github.com/emanorabi254/rsa/blob/main/Proteus/RSA.pdsprj"

    %% Hardware Layer
    subgraph "Hardware Layer"
        direction TB
        mcu["8051 MCU\n(RAM/ROM)"] 
        uart_hw["UART Interface\nPins TX/RX"] 
        virt_term["Virtual Terminal"]
    end
    class mcu hardware
    class uart_hw hardware
    class virt_term hardware

    %% Software Layer
    subgraph "Software Layer"
        direction TB
        readme["Project Overview\n(README.md)"] 
        app["Application\n(main.c)"] 
        rsa_mod["RSA Module\n(rsa.h/.c)\n(CRT Optimization)"] 
        uart_mod["UART Module\n(uart.h/.c)"]
        proj1["Keil Project\n(project.uvproj)"]
        proj2["Keil Config\n(project.uvopt)"]
        proj3["Keil GUI Backup\n(project.uvgui.Original)"]
    end
    class readme simulation
    class app app
    class rsa_mod crypto
    class uart_mod comm
    class proj1 simulation
    class proj2 simulation
    class proj3 simulation

    click readme "https://github.com/emanorabi254/rsa/blob/main/README.md"
    click app "https://github.com/emanorabi254/rsa/blob/main/code/main.c"
    click rsa_mod "https://github.com/emanorabi254/rsa/blob/main/code/RSA.h"
    click uart_mod "https://github.com/emanorabi254/rsa/blob/main/code/Uart.h"
    click proj1 "https://github.com/emanorabi254/rsa/blob/main/code/project.uvproj"
    click proj2 "https://github.com/emanorabi254/rsa/blob/main/code/project.uvopt"
    click proj3 "https://github.com/emanorabi254/rsa/blob/main/code/project.uvgui.Original"

    %% Connections Simulation -> Hardware
    proteus --> mcu
    proteus --> virt_term

    %% Hardware Connections
    mcu --> uart_hw
    uart_hw --> virt_term
    virt_term --> uart_hw

    %% Software to Hardware Interfaces
    app --> rsa_mod
    rsa_mod --> app
    app --> uart_mod
    uart_mod --> mcu

    %% Data Flows
    app -->|"generate keys / encrypt"| rsa_mod
    rsa_mod -->|"plaintext / ciphertext"| app
    app -->|"TX buffer"| uart_mod
    uart_mod -->|"serial data"| uart_hw
    virt_term -->|"serial I/O"| uart_hw
    uart_hw -->|"serial data"| uart_mod
    uart_mod -->|"RX buffer"| app
    app -->|"decrypt with CRT"| rsa_mod

    %% Styles
    classDef simulation fill:#ffe4b5,stroke:#cc8400,color:#000;
    classDef hardware fill:#bbdefb,stroke:#0b5394,color:#000;
    classDef crypto fill:#f8cbad,stroke:#a61c00,color:#000;
    classDef comm fill:#d9ead3,stroke:#38761d,color:#000;
    classDef app fill:#eeeeee,stroke:#888888,color:#000;
```
