# jordi-r66/cryptography architecture

> Architecture diagram of the GitHub repository jordi-r66/cryptography, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jordi-r66/cryptography
- Repository: https://github.com/jordi-r66/cryptography

## Overview

This repository is a C cryptography toolkit with command-line programs for file encryption and file hashing, plus ElGamal and ChaCha20-Poly1305 APIs. The principal user workflow is generating or supplying a key and nonce, then encrypting a file with ChaCha20; a separate utility streams a file through SHA-256 and prints its digest. ElGamal provides key generation, encryption/decryption, signatures, and key-file serialization. The README is empty, and sampled source does not establish every subsystem’s wiring, so uncertain links are omitted.

Main entry points: [`src/apps/file_cipher/main.c`](https://github.com/jordi-r66/cryptography/blob/main/src/apps/file_cipher/main.c) (File cipher CLI), [`src/cipher/asymmetric/elgamal/elgamal.c`](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/asymmetric/elgamal/elgamal.c) (ElGamal operations), [`src/apps/hash_file/main.c`](https://github.com/jordi-r66/cryptography/blob/main/src/apps/hash_file/main.c) (File hash CLI), [`src/main.c`](https://github.com/jordi-r66/cryptography/blob/main/src/main.c) (Crypto demo entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Command-line tools"]
  node_fileapp["File cipher CLI<br/>[main.c]"]
  node_hashapp["File hash CLI<br/>[main.c]"]
  node_demo["Crypto demo entry<br/>[main.c]"]
end

subgraph group_symmetric["Symmetric cryptography"]
  node_keygen["Key and nonce<br/>[chacha20.c]"]
  node_chacha["ChaCha20<br/>[chacha20.c]"]
  node_aead["ChaCha20-Poly1305<br/>[chacha20poly1305.c]"]
  node_poly["Poly1305 MAC<br/>[poly1305.c]"]
  node_secureblock["Secure block I/O<br/>[chacha20poly1305.c]"]
end

subgraph group_asymmetric["ElGamal cryptography"]
  node_elgamal["ElGamal operations<br/>[elgamal.c]"]
  node_prime["Prime generation<br/>[utils.c]"]
end

subgraph group_hashing["Hashing"]
  node_sha["SHA-256<br/>[sha256.c]"]
end

node_user(("CLI user"))
node_keyfile["Key file"]
node_noncefile["Nonce file"]
node_inputfile["Input file"]
node_cipherfile["Cipher output"]
node_file["File input"]
node_digest["SHA-256 digest"]
node_egkeys["ElGamal keys"]
node_signature["Signature"]
node_integerlib["Integer arithmetic"]

node_user -->|"runs"| node_fileapp
node_fileapp -->|"generates keys"| node_keygen
node_keygen -->|"exports key"| node_keyfile
node_fileapp -->|"imports key"| node_keyfile
node_fileapp -->|"writes nonce"| node_noncefile
node_fileapp -->|"reads chunks"| node_inputfile
node_fileapp -->|"encrypts chunks"| node_chacha
node_fileapp -->|"writes ciphertext"| node_cipherfile
node_aead -->|"uses stream"| node_chacha
node_aead -->|"authenticates data"| node_poly
node_secureblock -.->|"stores blocks"| node_cipherfile
node_user -->|"runs"| node_hashapp
node_hashapp -->|"reads chunks"| node_file
node_hashapp -->|"updates and finalizes"| node_sha
node_hashapp -->|"prints digest"| node_digest
node_elgamal -->|"generates primes"| node_prime
node_elgamal -.->|"uses arithmetic"| node_integerlib
node_elgamal -->|"hashes signed data"| node_sha
node_demo -->|"demonstrates operations"| node_elgamal
node_demo -->|"demonstrates encryption"| node_chacha
node_demo -->|"demonstrates AEAD"| node_aead
node_elgamal -->|"exports keys"| node_egkeys
node_elgamal -->|"creates or verifies"| node_signature

click node_fileapp "https://github.com/jordi-r66/cryptography/blob/main/src/apps/file_cipher/main.c"
click node_keygen "https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20/chacha20.c"
click node_chacha "https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20/chacha20.c"
click node_aead "https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20poly1305/chacha20poly1305.c"
click node_poly "https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/poly1305/poly1305.c"
click node_secureblock "https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20poly1305/chacha20poly1305.c"
click node_hashapp "https://github.com/jordi-r66/cryptography/blob/main/src/apps/hash_file/main.c"
click node_sha "https://github.com/jordi-r66/cryptography/blob/main/src/hash/sha256.c"
click node_elgamal "https://github.com/jordi-r66/cryptography/blob/main/src/cipher/asymmetric/elgamal/elgamal.c"
click node_prime "https://github.com/jordi-r66/cryptography/blob/main/src/cipher/asymmetric/common/utils.c"
click node_demo "https://github.com/jordi-r66/cryptography/blob/main/src/main.c"
click node_integerlib "https://github.com/jordi-r66/cryptography/tree/main/libs/myOwnCLib"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_fileapp,node_hashapp,node_demo,node_user toneBlue
class node_keygen,node_chacha,node_aead,node_poly,node_secureblock toneAmber
class node_elgamal,node_prime toneMint
class node_sha toneRose
class node_keyfile,node_noncefile,node_inputfile,node_cipherfile,node_file,node_digest,node_egkeys,node_signature toneIndigo
class node_integerlib toneTeal
```

## Components

### Command-line tools

- [File cipher CLI](https://github.com/jordi-r66/cryptography/blob/main/src/apps/file_cipher/main.c): `src/apps/file_cipher/main.c`
- [File hash CLI](https://github.com/jordi-r66/cryptography/blob/main/src/apps/hash_file/main.c): `src/apps/hash_file/main.c`
- [Crypto demo entry](https://github.com/jordi-r66/cryptography/blob/main/src/main.c): `src/main.c`

### Symmetric cryptography

- [Key and nonce](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20/chacha20.c): `src/cipher/symmetric/chacha20/chacha20.c`
- [ChaCha20](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20/chacha20.c): `src/cipher/symmetric/chacha20/chacha20.c`
- [ChaCha20-Poly1305](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20poly1305/chacha20poly1305.c): `src/cipher/symmetric/chacha20poly1305/chacha20poly1305.c`
- [Poly1305 MAC](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/poly1305/poly1305.c): `src/cipher/symmetric/poly1305/poly1305.c`
- [Secure block I/O](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/symmetric/chacha20poly1305/chacha20poly1305.c): `src/cipher/symmetric/chacha20poly1305/chacha20poly1305.c`

### ElGamal cryptography

- [ElGamal operations](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/asymmetric/elgamal/elgamal.c): `src/cipher/asymmetric/elgamal/elgamal.c`
- [Prime generation](https://github.com/jordi-r66/cryptography/blob/main/src/cipher/asymmetric/common/utils.c): `src/cipher/asymmetric/common/utils.c`

### Hashing

- [SHA-256](https://github.com/jordi-r66/cryptography/blob/main/src/hash/sha256.c): `src/hash/sha256.c`

### Other components

- **CLI user**
- **Key file**
- **Nonce file**
- **Input file**
- **Cipher output**
- **File input**
- **SHA-256 digest**
- **ElGamal keys**
- **Signature**
- [Integer arithmetic](https://github.com/jordi-r66/cryptography/tree/main/libs/myOwnCLib): `libs/myOwnCLib`

## Connections

- CLI user → File cipher CLI: runs
- File cipher CLI → Key and nonce: generates keys
- Key and nonce → Key file: exports key
- File cipher CLI → Key file: imports key
- File cipher CLI → Nonce file: writes nonce
- File cipher CLI → Input file: reads chunks
- File cipher CLI → ChaCha20: encrypts chunks
- File cipher CLI → Cipher output: writes ciphertext
- ChaCha20-Poly1305 → ChaCha20: uses stream
- ChaCha20-Poly1305 → Poly1305 MAC: authenticates data
- Secure block I/O → Cipher output: stores blocks
- CLI user → File hash CLI: runs
- File hash CLI → File input: reads chunks
- File hash CLI → SHA-256: updates and finalizes
- File hash CLI → SHA-256 digest: prints digest
- ElGamal operations → Prime generation: generates primes
- ElGamal operations → Integer arithmetic: uses arithmetic
- ElGamal operations → SHA-256: hashes signed data
- Crypto demo entry → ElGamal operations: demonstrates operations
- Crypto demo entry → ChaCha20: demonstrates encryption
- Crypto demo entry → ChaCha20-Poly1305: demonstrates AEAD
- ElGamal operations → ElGamal keys: exports keys
- ElGamal operations → Signature: creates or verifies
