BlockMed is a secure, blockchain-based medical record management system developed for African Leadership University (ALU) coursework. The system implements a complete blockchain with proof-of-work mining, role-based access control, and secure data persistence.
- Role-based Access Control:
- Staff (
@alueducation.com): Full access - Interns (
@si.alueducation.com): Limited write access - Students (
@alustudent.com): View-only access
- Staff (
- SHA-256 Cryptographic Hashing: All blocks and passwords secured
- Input Sanitization: Protection against buffer overflow attacks
- Audit Logging: Complete operation tracking in
access.log - File Integrity Checking: Tamper detection for blockchain files
- Complete Blockchain Implementation: Genesis block + linked chain
- Proof of Work Mining: Adjustable difficulty (1-8 leading zeros)
- Medical Transaction Storage: Patient records with full metadata
- Chain Validation: Integrity verification across entire chain
- Data Persistence: Save/load blockchain to encrypted files
- Structured Medical Transactions: Patient ID, doctor, diagnosis, prescription, notes
- Timestamped Records: Automatic timestamp generation
- Immutable Audit Trail: Blockchain ensures record integrity
- Privacy Protection: Access controls prevent unauthorized viewing
blockmed/
├── src/
│ ├── main.c # Entry point and system initialization
│ ├── blockchain.c/.h # Core blockchain logic and block management
│ ├── transaction.c/.h# Medical transaction handling
│ ├── pow.c/.h # Proof of Work mining implementation
│ ├── cli.c/.h # Command line interface and menus
│ ├── auth.c/.h # Authentication and role management
│ ├── storage.c/.h # File I/O and data persistence
│ ├── utils.c/.h # SHA-256, timestamping, input validation
│ └── log.c/.h # Security and operation logging
├── data/
│ ├── blockchain.dat # Serialized blockchain storage
│ ├── users.csv # User credentials database
│ └── access.log # System audit log
├── Makefile
└── README.md
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install build-essential libssl-dev
# CentOS/RHEL
sudo yum install gcc openssl-devel
# macOS
brew install openssl# Clone and build
git clone <repository>
cd blockmed
make
# Run the system
./blockmed- Email:
admin@alueducation.com - Password:
admin123
Users must log in with valid ALU email addresses:
@alueducation.com- Full system access@si.alueducation.com- Can add records and mine blocks@alustudent.com- View blockchain only
- Login with staff/intern credentials
- Select "Add new medical record"
- Enter patient details:
- Patient ID
- Diagnosis
- Prescription
- Visit notes
- Record is created and ready for mining
- Ensure you have a pending transaction
- Select "Mine pending block"
- System will perform proof-of-work mining
- Block is added to chain when valid hash found
- Select "View entire blockchain"
- All blocks and transactions displayed
- Available to all authenticated users
- Select "Validate chain integrity"
- System verifies all block hashes and links
- Detects any tampering or corruption
- SHA-256 Hashing: OpenSSL implementation for all cryptographic operations
- Salted Password Hashing: Passwords stored as SHA-256 hashes with salt
- Block Hash Chaining: Each block contains cryptographic hash of previous block
- Proof of Work: Computational difficulty prevents easy block manipulation
- Email Domain Validation: Only ALU email addresses accepted
- Role-based Permissions: Different access levels based on email domain
- Operation Logging: All user actions logged with timestamps
- Session Management: Users must authenticate for each session
- Buffer Overflow Protection: All inputs bounded and sanitized
- Email Format Validation: Proper email format checking
- SQL Injection Prevention: No SQL used, CSV-based storage
- Path Traversal Protection: Restricted file access paths
typedef struct block {
int index; // Block number in chain
char timestamp[20]; // Creation timestamp
medical_transaction_t transaction; // Medical record data
unsigned long nonce; // Proof of work nonce
char previous_hash[65]; // Previous block hash
char current_hash[65]; // This block's hash
struct block *next; // Pointer to next block
} block_t;typedef struct {
char patient_id[50]; // Patient identifier
char doctor_email[100]; // Doctor's email
char diagnosis[500]; // Medical diagnosis
char prescription[500]; // Prescribed treatment
char visit_notes[1000]; // Additional notes
char timestamp[20]; // Transaction timestamp
} medical_transaction_t;- Create block with transaction data
- Set nonce to 0
- Calculate SHA-256 hash of block data + nonce
- Check if hash has required leading zeros
- If not, increment nonce and repeat
- When valid hash found, block is mined
- C99 Standard: Compatible with modern C compilers
- Memory Management: Proper malloc/free with leak prevention
- Error Handling: Comprehensive error checking and logging
- Documentation: Inline comments and function documentation
- Modularity: Clear separation of concerns across modules
# Build with debug symbols
make debug
# Run with memory leak detection
make valgrind
# Clean build environment
make clean- Follow existing code style and patterns
- Add comprehensive comments for new functions
- Update documentation for new features
- Test thoroughly before committing
- Ensure all security checks pass
- Immutability: Once mined, blocks cannot be altered without detection
- Hash Chain Integrity: Any modification breaks the cryptographic chain
- Proof of Work: Computational cost prevents easy chain manipulation
- Validation: Regular integrity checks detect tampering
- Access Controls: Role-based permissions protect sensitive data
- Audit Trails: Complete logging of all data access
- Encryption: File storage uses cryptographic integrity checks
- Authentication: Strong password requirements and hashing
- Input Sanitization: All user inputs validated and cleaned
- Buffer Protection: Bounds checking prevents overflow attacks
- File Security: Restricted file system access and validation
- Network Security: Local operation, no network exposure
- OpenSSL not found: Install libssl-dev package
- Permission denied: Check file permissions in data/ directory
- Blockchain corrupt: Delete blockchain.dat to start fresh
- Mining too slow: Reduce difficulty setting (default: 4)
- Login failures: Check users.csv file format
- Linux/Unix/macOS operating system
- GCC compiler with C99 support
- OpenSSL development libraries
- Minimum 512MB RAM for mining operations
- 100MB disk space for blockchain storage
Educational use only - African Leadership University coursework project.
ALU Computer Science Department - Blockchain Systems Course
This system is designed for educational purposes and demonstrates blockchain concepts in healthcare data management. For production use, additional security hardening and compliance measures would be required.