# aidanaden/shamir-zig architecture

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

- Interactive diagram: https://gitdiagram.com/aidanaden/shamir-zig
- Repository: https://github.com/aidanaden/shamir-zig

## Overview

**[CLI Interface Layer]**
- ↓
**[Core Cryptographic Implementations]**
- ↓
**[Mathematical Foundation Layer]**

##### Component Details

A. CLI Interface Layer (Top)
- Three main commands as sub-components:
- "generate" command
- "reconstruct" command
- "verify" command (for Feldman/Pedersen variants)

B. Core Cryptographic Implementations (Middle)
1. GF(256) Implementation
2. Ristretto255 Implementation
3. Verifiable Implementations
- Feldman
- Pedersen

C. Mathematical Foundation Layer (Bottom)
- GF(256) Operations
- Ristretto255 Curve Operations
- Polynomial Interpolation

Following interactions:
**User Input → CLI Interface → Implementation Selection → Mathematical Operations → Output**

##### Additional Elements

- Input Validation
- Share Generation
- Share Reconstruction
- Verification (for Feldman/Pedersen)

##### Important Notes

Callouts highlighting:
- Security considerations (as mentioned in README)
- Threshold requirements
- Share format specifications
- Hash and reduction operations for Ed25519

##### Implementation Details

Relationship between files:
- main.zig → CLI entry point
- shamir.zig → Core SSS implementation
- gf256.zig → Finite field operations
- ristretto255.zig → Curve operations
- feldman.zig/pedersen.zig → Verifiable schemes

##### The relationship between the three main implementation variants

Keep the abstraction level focused on the architectural components while maintaining enough detail to show the cryptographic workflow and security boundaries. This will help developers understand both the high-level structure and the security-critical paths in the system.

Remember to add a note about the security disclaimer mentioned in the README, indicating that this implementation is for educational purposes and not audited for production use.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main Layers
    subgraph CLI
        CLI_MAIN["CLI Interface"]
        click CLI_MAIN "https://github.com/aidanaden/shamir-zig/blob/main/src/main.zig"
        CLI_ROOT["Root Module"]
        click CLI_ROOT "https://github.com/aidanaden/shamir-zig/blob/main/src/root.zig"
        
        COMMANDS{"Commands"}
        GEN["Generate"]
        REC["Reconstruct"]
        VER["Verify"]
        
        CLI_MAIN --> CLI_ROOT
        CLI_ROOT --> COMMANDS
        COMMANDS --> GEN
        COMMANDS --> REC
        COMMANDS --> VER
    end
    
    subgraph CRYPTO["Core Cryptographic Implementations"]
        SSS["Basic SSS Implementation"]
        click SSS "https://github.com/aidanaden/shamir-zig/blob/main/src/shamir.zig"
        
        VERI["Verifiable Schemes"]
        FELD["Feldman's Scheme"]
        click FELD "https://github.com/aidanaden/shamir-zig/blob/main/src/feldman.zig"
        PED["Pedersen's Scheme"]
        click PED "https://github.com/aidanaden/shamir-zig/blob/main/src/pedersen.zig"
        
        VERI --> FELD
        VERI --> PED
    end
    
    subgraph MATH["Mathematical Foundation Layer"]
        GF["GF(256) Operations"]
        click GF "https://github.com/aidanaden/shamir-zig/blob/main/src/gf256.zig"
        RIST["Ristretto255 Operations"]
        click RIST "https://github.com/aidanaden/shamir-zig/blob/main/src/ristretto255.zig"
        POLY["Polynomial Interpolation"]
    end
    
    %% Cross-layer connections
    GEN --> SSS
    GEN --> VERI
    REC --> SSS
    VER --> VERI
    
    SSS --> GF
    SSS --> POLY
    FELD --> RIST
    PED --> RIST
    
    %% Testing and Build
    TEST["Testing Framework"]
    click TEST "https://github.com/aidanaden/shamir-zig/blob/main/src/test.zig"
    BUILD["Build System"]
    click BUILD "https://github.com/aidanaden/shamir-zig/blob/main/build.zig"
    
    %% Security Note
    NOTE["Educational Purpose Only<br/>Not Audited for Production"]
    
    %% Styling
    classDef cli fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef crypto fill:#90EE90,stroke:#333,stroke-width:2px
    classDef math fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef warning fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef test fill:#E6E6FA,stroke:#333,stroke-width:2px
    
    class CLI_MAIN,CLI_ROOT,COMMANDS,GEN,REC,VER cli
    class SSS,VERI,FELD,PED crypto
    class GF,RIST,POLY math
    class NOTE warning
    class TEST,BUILD test
    
    %% Legend
    subgraph Legend
        L1["CLI Components"]:::cli
        L2["Cryptographic Components"]:::crypto
        L3["Mathematical Components"]:::math
        L4["Testing & Build"]:::test
        L5["Security Notes"]:::warning
    end
```
