LockBox

LockBox Architecture Documentation

Overview

LockBox is an encrypted file container application that provides a virtual filesystem within a single password-protected file. It combines a custom encryption engine (OpenES) with a tree-based virtual filesystem (iNode) to securely store files and directories.

High-Level Architecture

┌──────────────────────────────────────────────────────────────────────────────┐
│                           APPLICATION LAYER                                  │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────────────┐   │
│  │   Interactive   │  │   CLI Parser    │  │   Command Dispatcher        │   │
│  │   UI/Main Menu  │  │   (argc/argv)   │  │   (ls, cd, cat, etc.)       │   │
│  └────────┬────────┘  └────────┬────────┘  └─────────────┬───────────────┘   │
│           │                    │                         │                   │
│           └────────────────────┴─────────────────────────┘                   │
│                                      │                                       │
│                              main.cpp (Main Entry)                           │
└──────────────────────────────────────┼───────────────────────────────────────┘
                                       │
                                       ▼
┌───────────────────────────────────────────────────────────────────────────────┐
│                        VIRTUAL FILESYSTEM LAYER (iNode/)                      │
│  ┌─────────────────┐  ┌─────────────────┐  ┌───────────────────────────────┐  │
│  │     iNode       │  │      Block      │  │        inode_raw              │  │
│  │  (Tree Manager) │◄─┤  (Data Unit)    │◄─┤   (Memory-Mapped I/O)         │  │
│  │                 │  │                 │  │                               │  │
│  │ • addFile()     │  │ • File/Dir data │  │ • File mapping                │  │
│  │ • addDir()      │  │ • Encrypted     │  │ • Page allocation             │  │
│  │ • remove()      │  │   names         │  │ • Defragmentation             │  │
│  │ • readFile()    │  │ • Tree pointers │  │ • Raw I/O                     │  │
│  │ • listDir()     │  │ • Timestamps    │  │ • Block I/O                   │  │
│  └────────┬────────┘  └────────┬────────┘  └─────────────┬─────────────────┘  │
│           │                    │                         │                    │
│           └────────────────────┴─────────────────────────┘                    │
│                                       │                                       │
│                    Tree Structure:    ▼                                       │
│                    ┌─────────┐                                                │
│                    │  Root   │──┐                                             │
│                    │ Block 0 │  │                                             │
│                    └────┬────┘  │                                             │
│                         │child │                                              │
│                    ┌────▼────┐  │ sibling                                     │
│                    │ Dir A   │◄─┘                                             │
│                    │ Block 1 │                                                │
│                    └────┬────┘                                                │
│                         │                                                     │
│                    ┌────▼────┐                                                │
│                    │ File B  │                                                │
│                    │ Block 2 │                                                │
│                    └─────────┘                                                │
└───────────────────────────────────────┬───────────────────────────────────────┘
                                        │
                                        ▼
┌─────────────────────────────────────────────────────────────────────────────┐
│                      ENCRYPTION LAYER (OpenES/)                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                           OES (Engine)                                │  │
│  │  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  ┌───────────────┐ │  │
│  │  │   enc_*()   │  │   dec_*()   │  │    hash()   │  │     hmac()    │ │  │
│  │  │  ECB/CBC/   │  │  ECB/CBC/   │  │             │  │               │ │  │
│  │  │ CTR/CKE/    │  │ CTR/CKE/    │  │             │  │               │ │  │
│  │  │ adv (SPHINX)│  │ adv (SPHINX)│  │             │  │               │ │  │
│  │  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘  └────────┬──────┘ │  │
│  │         └────────────────┴────────────────┴──────────────────┘        │  │
│  │                                    │                                  │  │
│  │  ┌─────────────────────────────────▼────────────────────────────────┐ │  │
│  │  │                    SPHINX Cipher v3.1                            │ │  │
│  │  │  • Wide-block cipher (1-16 blocks configurable)                  │ │  │
│  │  │  • Key Addition → Wide S-box → Algebraic S-box → Diffusion       │ │  │
│  │  │  • PHT → Round Constants                                         │ │  │
│  │  └──────────────────────────────────────────────────────────────────┘ │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
│                                                                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                      Data Block Layer (layer/)                        │  │
│  │                                                                       │  │
│  │   ┌─────────────┐      ┌─────────────┐      ┌─────────────────────┐   │  │
│  │   │   MBLOCK    │      │   m_block   │      │      defines.h      │   │  │
│  │   │  (Class)    │      │  (Type)     │      │  (Compile-time      │   │  │
│  │   │             │      │  uint8-128  │      │   configuration)    │   │  │
│  │   │ • Memory    │      │             │      │                     │   │  │
│  │   │   management│      │ • Rotations │      │ • Block sizes       │   │  │
│  │   │ • Padding   │      │ • Byte ops  │      │ • Type definitions  │   │  │
│  │   │ • XOR ops   │      │             │      │ • Constants         │   │  │
│  │   └─────────────┘      └─────────────┘      └─────────────────────┘   │  │
│  │                                                                       │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
│                                                                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                    Supporting Algorithms (algo/)                      │  │
│  │                                                                       │  │
│  │   ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  │  │
│  │   │  hashing    │  │  key_mgmt   │  │    PRNG     │  │block_ciphers│  │  │
│  │   │             │  │             │  │             │  │             │  │  │
│  │   │ • SHA-256   │  │ • Key exp.  │  │ • CSPRNG    │  │ • AES       │  │  │
│  │   │ • SHA-512   │  │ • PBKDF-like│  │ • SplitMix  │  │ • ChaCha    │  │  │
│  │   └─────────────┘  └─────────────┘  └─────────────┘  └─────────────┘  │  │
│  │                                                                       │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────────────────┘
                                        │
                                        ▼
┌─────────────────────────────────────────────────────────────────────────────┐
│                      PLATFORM ABSTRACTION LAYER                             │
│  ┌─────────────────────────────┐  ┌─────────────────────────────────────┐   │
│  │     filesystem.cpp/.h       │  │           mman.cpp/.h               │   │
│  │                             │  │                                     │   │
│  │  Cross-platform file I/O:   │  │  Memory-mapped file abstraction:    │   │
│  │  • read/write files         │  │  • Windows: CreateFileMapping       │   │
│  │  • directory operations     │  │  • POSIX: mmap/munmap               │   │
│  │  • path manipulation        │  │  • Page-aligned allocation          │   │
│  └─────────────────────────────┘  └─────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘

Component Details

1. Application Layer

File: main.cpp

The entry point providing multiple interfaces:

Key classes:

Class Line Description
ColorSupport 26-77 Terminal color management with cross-platform support
ProgressTracker 208-243 Progress bar display with ETA calculation
CommandHistory 312-343 Command history navigation (up/down arrows)
LineEditor 347-539 Command-line editing with tab completion
PreCalculatedBatch 89-103 Batch file processing metadata

CLI Commands: | Command | Arguments | Description | |———|———–|————-| | ls | [path] | List directory contents | | cd | <path> | Change current directory | | pwd | - | Print working directory | | cat | <file> | Display file contents | | rm | <path> | Remove file or directory | | mkdir | <path> | Create directory | | mv | <src> <dst> | Move/rename | | cp | <src> <dst> | Copy file/directory | | rename | <path> <name> | Rename file/directory | | find | <pattern> | Search for files | | tree | [path] | Display directory tree | | extract | [src] <dst> | Export files to filesystem | | add | <file> [path] | Add files from filesystem | | info | <path> | Show file/directory details | | limit | [n] | Set list display limit | | clear | - | Clear screen | | help | [cmd] | Show help | | exit | - | Exit CLI mode |

Command-line arguments:

<src> <lockbox> <pass>      Create lockbox from source
-e <lockbox> <dest> <pass>  Extract lockbox to destination
-c <text> <password>        Encrypt text
-d <hex> <password>         Decrypt hex ciphertext
-cf <in> <out> <pass>       Encrypt file (raw)
-df <in> <out> <pass>       Decrypt file (raw)
-h                          Show help

2. Virtual Filesystem Layer (iNode/)

2.1 iNode - Tree Manager

Files: iNode/iNode.h, iNode/iNode.cpp

The main filesystem interface managing a tree of Block objects.

Key responsibilities:

Key methods:

Method Description
addFile() Add or overwrite a file (supports empty files)
addDirectory() Create directory chain
remove() Remove file or recursive directory
readFile() Read and decrypt file content
updateFile() Update existing file content
move() Move/rename files or directories
copy() Copy files or directories recursively
exists() Check if path exists
listDirectory() List directory entries
search() Search files by name pattern
walk() Tree traversal with callback
exportTo() Export to host filesystem
beginBulkUpdate() Start batch operation mode
endBulkUpdate() End batch mode, flush changes
defragment() Compact storage, reclaim space
getLog() Get encrypted activity log
clearLog() Clear activity log

Types:

Type Description
DirEntry Directory entry with encrypted/decrypted names, type, and size
Stats Container statistics (total size, used/free space, file/dir counts)
WalkCallback Callback function for tree traversal

2.2 Block - Storage Unit

Files: iNode/Block.h, iNode/Block.cpp

Represents a single file or directory in the virtual filesystem. Supports both inline and external name storage.

Structure:

Key methods:

Method Description
setName() Set and encrypt name
getPlainName() Get decrypted name
getStoredName() Get encrypted name
nameEquals() Compare with plaintext name
setCreatedNow() Set creation timestamp
setModifiedNow() Set modification timestamp
setAccessedNow() Set access timestamp
isNameInline() Check if name uses inline storage
isValid() Validate block structure
isLeaf() Check if node has no children
hasChildren() Check if directory has entries
linkAfter() Link after another block
unlink() Remove from linked list
clone() Create deep copy
createFile() Factory for file blocks
createDirectory() Factory for directory blocks
createRoot() Factory for root block

Static configuration methods:

2.3 inode_raw - Physical Storage

Files: iNode/inode_raw.h, iNode/inode_raw.cpp

Manages memory-mapped file I/O for the container with page-aligned allocation.

Features:

Key members:

Key methods:

Method Description
open() Open existing container
create() Create new container
allocate() Allocate space at end
reallocate() Reallocate data block
defragment() Compact storage file
write() Write raw data
read() Read raw data
ptr() Get pointer to offset
readBlock() Read Block structure
writeBlock() Write Block structure
appendBlock() Append Block to file
sync() Flush to disk

Defragmentation process:

  1. BFS traversal to find all reachable blocks
  2. Collect blocks, file data, and external names
  3. Calculate new compact layout
  4. Update all internal pointers
  5. Write new image to file
  6. Truncate to new size

3. Encryption Layer (OpenES/)

3.1 OES - Encryption Engine

Files: OpenES/OES.h, OpenES/OES.cpp

Main interface for all cryptographic operations with secure memory management.

Key components:

Supported modes:

Mode Method Description
ECB enc_ecb() Electronic Codebook (deterministic)
CBC enc_cbc() Cipher Block Chaining
CTR enc_ctr() Counter mode (streaming)
CKE enc_cke() Custom CKE mode with stream chaining
ADV enc_adv() SPHINX cipher (recommended, default)

Key management:

Method Description
set_key() Set password from string
deriveWKey() Derive working key with salt
extendWKey() PBKDF-like key expansion
resetBlocks() Securely clear data blocks
resetStreamState() Reset streaming state

Data operations:

Method Description
load_data_raw() Load plaintext data
load_cipher_data_raw() Load ciphertext data
load_cipher_block() Load existing MBLOCK
get_data() Get plaintext (with padding removed)
get_cipher_data() Get ciphertext
get_cipher_data_raw() Get raw ciphertext bytes
get_cipherBlock() Clone cipher block
get_plainBlock() Clone plaintext block

3.2 SPHINX Cipher

Files: OpenES/algo/sphinix.h, OpenES/algo/sphinix.cpp

Custom wide-block cipher designed for high security with configurable block sizes.

Features:

Security levels:

Block Size Max Key Size Security Level
8-bit 64-bit Basic
16-bit 128-bit AES-128 equivalent
32-bit 256-bit AES-256 equivalent
64-bit 512-bit Post-quantum ready
128-bit 1024-bit Quantum-safe

Round structure:

Plaintext → [Key Addition] → [Wide S-box (Feistel)] → [Algebraic S-box]
          → [Diffusion Layer] → [PHT] → [Round Constants] → Ciphertext

Public interface (namespace SPHINX):

3.3 MBLOCK - Core Data Structure

Files: OpenES/layer/m_block.h, OpenES/layer/m_block.cpp

Memory block class managing cryptographic data with secure memory handling.

Key components:

Operations:

The underlying type is configured at compile-time:

Config Type Use Case
8-bit uint8_t Embedded systems
16-bit uint16_t Low memory
32-bit uint32_t General purpose
64-bit uint64_t High performance
128-bit __uint128_t Maximum security

Key methods:

Method Description
fromBytes() Create from bytes (with padding)
fromBytes_raw() Create from bytes (no padding)
toBytes() Export to bytes (strip padding)
toBytes_raw() Export raw bytes
clone() Deep copy
secure_zero() Secure memory wipe
xor_with() XOR with another block
rotr() Rotate right
rotl() Rotate left
extend() Resize with fill value
add_padding_outer() Add PKCS-like padding
get_padding_size_outer() Calculate padding size
dump() Debug output

3.4 Configuration (defines.h)

File: OpenES/layer/defines.h

Compile-time configuration:

Constant Default Description
OES_NUM_OF_BLOCKS 16 Number of parallel blocks (must be even)
OES_LOGIC_BLOCK_SIZE 128 Bits per block (8-128, multiple of 8)
OES_MEM_SIZE 128 Derived memory size

Derived constants:

Data types (configured based on block size):

Export format constants:

3.5 Interface Layer

File: OpenES/layer/interface.h

High-level import/export functions:

4. Platform Abstraction Layer

4.1 Filesystem

Files: filesystem.h, filesystem.cpp

Cross-platform file operations supporting Windows and POSIX systems.

Directory entry structure:

File I/O operations:

Path operations:

File/Directory checks:

Directory operations:

Utilities:

4.2 Memory Mapping

Files: mman.h, mman.cpp

Abstracts platform-specific memory-mapped file APIs:

Protection modes:

Map flags:

Map result contains:

Operations:

Data Flow

Encryption Flow

┌──────────────┐     ┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  Plaintext   │────►│   MBLOCK     │────►│    SPHINX    │────►│   MBLOCK     │
│   (bytes)    │     │  (blocks)    │     │   encrypt()  │     │ (encrypted)  │
└──────────────┘     └──────────────┘     └──────────────┘     └──────┬───────┘
                                                                       │
                                                                       ▼
                                                                ┌──────────────┐
                                                                │  Ciphertext  │
                                                                │   (bytes)    │
                                                                └──────────────┘

File Storage Flow

┌──────────────┐     ┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  User File   │────►│  Encryption  │────►│    Block     │────►│  inode_raw   │
│   (host FS)  │     │    (OES)     │     │  (metadata + │     │  (mmapped)   │
└──────────────┘     └──────────────┘     │ encrypted    │     └──────────────┘
                                          │   data)      │            │
                                          └──────────────┘            │
                                                                       ▼
                                                                ┌──────────────┐
                                                                │  LockBox     │
                                                                │   (.lb file) │
                                                                └──────────────┘

Container File Format

┌─────────────────────────────────────────────────────────────────────────────┐
│                           LockBox File (.lb)                                │
├─────────────────────────────────────────────────────────────────────────────┤
│ Offset 0                                                                    │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │                           Block 0 (Root Directory)                      │ │
│ │  ┌─────────────┬─────────────┬─────────────┬──────────────────────────┐ │ │
│ │  │  Metadata   │  Encrypted  │   Parent    │   Next/Prev/Child ptrs   │ │ │
│ │  │  (headers)  │   name      │   offset    │   (8 bytes each)         │ │ │
│ │  └─────────────┴─────────────┴─────────────┴──────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│                                                                             │
│ Offset N                                                                    │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │                        Block 1..N (Files/Directories)                   │ │
│ │  ┌─────────────┬─────────────┬────────────────────────────────────────┐ │ │
│ │  │  Metadata   │  Encrypted  │      Encrypted file data (if file)     │ │ │
│ │  │             │   name      │      or subdirectory blocks (if dir)   │ │ │
│ │  └─────────────┴─────────────┴────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│                                                                             │
│ ... additional blocks ...                                                   │
│                                                                             │
│ After defragmentation:                                                      │
│ [Blocks Section][Padding][File Data Section][Padding][External Names]       │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Security Architecture

Key Derivation

User Password ──► MBLOCK.fromBytes() ──► oKey (original key)
                                               │
                                               ▼
                                         extendWKey()
                                               │
                                               ▼
                                         wKey (working key)
                                               │
                                               ▼
                                         SPHINX encrypt/decrypt

Key expansion process:

  1. Password converted to MBLOCK (oKey)
  2. oKey cloned to wKey
  3. wKey expanded via PBKDF-like iterative hashing
  4. Expansion strength configurable (default: 16 rounds)
  5. Salt derived from golden ratio constant

Encryption Chain

  1. Name encryption: Every filename encrypted with SPHINX
  2. Data encryption: File contents encrypted with SPHINX cipher
  3. No plaintext metadata: All metadata encrypted (sizes stored as encrypted data length)
  4. Tree obfuscation: Block positions reveal no structural information
  5. Activity logging: Operations logged to encrypted .lockbox_log file

Threat Model

Threat Mitigation
Password guessing Configurable key expansion (default: 16 iterations)
Known-plaintext Wide-block SPHINX cipher with full diffusion
Side-channel Constant-time operations, no table lookups
Quantum computing Support for 1024-bit keys (128-bit blocks)
File carving No magic numbers or predictable headers
Memory dumps Secure zeroing of keys after use
Timing attacks Page-aligned memory, constant-time comparison

Build Configuration

File: CMakeLists.txt

Options

Option Default Description
BUILD_APP ON Build the main application
BUILD_TESTS OFF Build the test suite

Compiler Requirements

Source Organization

Common sources (library core):

Application sources:

Test sources:

Include Directories

Testing

Directory: test/

File Description
oes_tests.cpp Encryption/decryption correctness tests
prngtest.cpp Statistical randomness tests (NIST SP 800-22)
prngtest.h PRNG test headers
tester.h Test framework utilities

Build tests:

cmake -DBUILD_TESTS=ON ..
make LockBoxTests

Performance Considerations

Optimizations

  1. Memory-mapped I/O: Zero-copy access via mmap
  2. Bulk updates: Deferred sync for batch operations
  3. Page alignment: 4KB allocation reduces fragmentation
  4. Configurable block sizes: Tune for target hardware
  5. Context reuse: SPHINX contexts for repeated operations

Bottlenecks

Operation Cost Mitigation
Encryption O(n) per block Parallel SPHINX rounds
Disk sync I/O bound Bulk mode, deferred sync
Tree traversal O(n) Iterative, not recursive
Path lookup O(depth) Cached root block
Defragmentation O(n log n) Background operation

Future Considerations

Extensibility Points

  1. Alternative ciphers: Interface supports plugging in new algorithms
  2. Compression: Could be added before encryption stage
  3. Authentication: HMAC support already present in OES class
  4. Streaming: Large file support via chunking
  5. Snapshots: Copy-on-write for versioning

Planned Features


Documentation generated from codebase analysis. Last updated: 2026-03-02