# vapor/open-crypto architecture

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

- Interactive diagram: https://gitdiagram.com/vapor/open-crypto
- Repository: https://github.com/vapor/open-crypto

## Overview

##### Project type and purpose
- This is an open-source Swift library (“OpenCrypto”) that re-implements Apple’s CryptoKit API on top of OpenSSL, targeting platforms (e.g., Linux) where CryptoKit isn’t available.
- Its purpose is to expose familiar Swift crypto APIs (Digest, HMAC, SymmetricKey, AES GCM, ChaChaPoly, etc.) while delegating actual crypto work to OpenSSL C functions.

##### File structure
- Top-level artifacts:
- Package.swift: Swift Package Manager manifest.
- Sources/: holds two modules:
– COpenCrypto (a C wrapper around OpenSSL calls)
– OpenCrypto (the Swift API layer that users import)
- Tests/: unit tests for each API subset (cipher, digest, MAC).
- Docker/test files: docker-compose.yml and test.Dockerfile for CI/test environment setup.
- .github/workflows/test.yml: CI pipeline.
- Patterns:
- Two-layer architecture (Swift ↔ C ↔ OpenSSL).
- SwiftPM for build & module linking.
- Bridging headers (module.modulemap) to expose C code to Swift.

##### README for additional insights
- Confirms library role as CryptoKit replacement.
- Lists supported algorithms and missing features.
- Mentions dependency on OpenSSL.

##### Final recommendation
- Every layer: API, implementation, external dependency, packaging, tests, and CI.
- Don’t overcomplicate—focus on how data and control flow from Swift calls into OpenSSL and back, how the library is built, and how it’s validated.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Runtime Flow
    subgraph "Runtime Flow"
        OC["OpenCrypto (Swift API)"]:::swift
        CCO["COpenCrypto (C Wrapper)"]:::c
        OSS[(OpenSSL Library)]:::external
        OC -->|"calls C API"| CCO
        CCO -->|"calls OpenSSL"| OSS
    end

    %% C Wrapper Details
    subgraph "C Wrapper Layer"
        CImpl["c_open_crypto.c"]:::c
        CHeader["c_open_crypto.h"]:::c
        CMod["module.modulemap"]:::c
        CCO --> CImpl
        CCO --> CHeader
        CCO --> CMod
    end

    %% Build & Packaging
    subgraph "Build & Packaging"
        PKG["Package.swift"]:::build
        PKG -->|"defines modules"| OC
        PKG -->|"defines modules"| CCO
    end

    %% Test Suite
    subgraph "Test Suite"
        DT["DigestTests.swift"]:::test
        CT["CipherTests.swift"]:::test
        MT["MACTests.swift"]:::test
        DT -->|"tests API"| OC
        CT -->|"tests API"| OC
        MT -->|"tests API"| OC
    end

    %% CI & Docker Environment
    subgraph "CI / Docker"
        CI[".github/workflows/test.yml"]:::ci
        DCCompose["docker-compose.yml"]:::ci
        DFile["test.Dockerfile"]:::ci
        CI -->|orchestrates build| PKG
        CI -->|runs tests| DT
        CI -->|uses config| DCCompose
        CI -->|uses config| DFile
    end

    %% Click Events
    click OC "https://github.com/vapor/open-crypto/tree/master/Sources/OpenCrypto"
    click CImpl "https://github.com/vapor/open-crypto/blob/master/Sources/COpenCrypto/c_open_crypto.c"
    click CHeader "https://github.com/vapor/open-crypto/blob/master/Sources/COpenCrypto/include/c_open_crypto.h"
    click CMod "https://github.com/vapor/open-crypto/blob/master/Sources/COpenCryptoOpenSSL/module.modulemap"
    click PKG "https://github.com/vapor/open-crypto/blob/master/Package.swift"
    click DT "https://github.com/vapor/open-crypto/blob/master/Tests/OpenCryptoTests/DigestTests.swift"
    click CT "https://github.com/vapor/open-crypto/blob/master/Tests/OpenCryptoTests/CipherTests.swift"
    click MT "https://github.com/vapor/open-crypto/blob/master/Tests/OpenCryptoTests/MACTests.swift"
    click CI "https://github.com/vapor/open-crypto/blob/master/.github/workflows/test.yml"
    click DCCompose "https://github.com/vapor/open-crypto/blob/master/docker-compose.yml"
    click DFile "https://github.com/vapor/open-crypto/blob/master/test.Dockerfile"

    %% Styles
    classDef swift fill:#1f77b4,stroke:#000,color:#fff
    classDef c fill:#2ca02c,stroke:#000,color:#fff
    classDef external fill:#7f7f7f,stroke:#000,color:#fff
    classDef build fill:#ffbb78,stroke:#000,color:#000
    classDef test fill:#ff7f0e,stroke:#000,color:#000
    classDef ci fill:#d62728,stroke:#000,color:#000
```
