Overview
Keystore security relies on password strength, KDF parameters, and proper handling. Understanding the security model helps make informed decisions about parameter selection and usage patterns.Security Properties
What Keystore Protects
- Private key confidentiality: Key cannot be recovered without password
- Password verification: Wrong passwords are detected via MAC
- Data integrity: Modifications to ciphertext are detected
What Keystore Does NOT Protect
- Weak passwords: Low-entropy passwords can be brute-forced
- Memory attacks: Key exists in plaintext in memory during use
- Side-channel attacks: Timing, power analysis (mostly mitigated)
- Keyloggers/malware: Password can be captured during entry
Password Security
Password Strength Requirements
The keystore is only as secure as the password:
Recommendations:
- Minimum 16 characters
- Use passphrase (4+ random words) or random characters
- Include mixed case, numbers, symbols
- Never reuse passwords across keystores
Password Attacks
Dictionary Attack:KDF Security
Scrypt (Recommended)
Scrypt is memory-hard, making it resistant to parallel attacks:- Memory-hard: Requires ~256 MB RAM per attempt
- GPU-resistant: Memory bandwidth limits parallelization
- ASIC-resistant: Hard to build specialized hardware
128 * N * r * p bytes
- Default:
128 * 262144 * 8 * 1 = 256 MB
PBKDF2 (Less Secure)
PBKDF2 is not memory-hard, making it vulnerable to parallel attacks:- GPU-parallelizable: Attackers can try millions of passwords/second
- ASIC-parallelizable: Custom hardware can be built
- Lower security per iteration: Compared to scrypt
KDF Parameter Guidelines
Attack Scenarios
Stolen Keystore File
Scenario: Attacker obtains keystore JSON file. Attack: Offline password cracking- Strong password (16+ chars, high entropy)
- High KDF parameters (N=262144+)
- Don’t store keystores on shared/cloud storage without additional encryption
Timing Attack on MAC
Scenario: Attacker measures time to verify passwords. Attack: Learn partial MAC by timing differencesMemory Dump
Scenario: Attacker dumps process memory while wallet is unlocked. Attack: Find private key in memory Defense:- Clear private key from memory when done
- Use hardware wallets for high-value keys
- Minimize time wallet is unlocked
IV Corruption Attack
Scenario: Attacker modifies IV without detection. Attack: Causes wrong decryption outputBest Practices
Password Management
KDF Parameter Selection
Keystore Storage
Keystore Handling
Error Handling
Security Checklist
Before deploying keystore encryption:- Using strong passwords (16+ chars, high entropy)
- Using scrypt KDF (not PBKDF2) when possible
- KDF parameters appropriate for use case (N >= 16384)
- Keystore files encrypted at rest (if stored)
- Private keys cleared from memory after use
- Address verification after decryption
- Generic error messages to users
- No keystores in version control
- No keystores on unencrypted cloud storage
- Backup procedures documented and tested
Compliance
Standards Alignment
- Web3 Secret Storage v3: Full compliance
- NIST SP 800-132: PBKDF2 usage follows recommendations
- OWASP: Password hashing guidelines followed
Known Limitations
- IV not in MAC: Corrupted IV produces wrong output without error
- No key stretching metadata: Can’t verify KDF parameters were followed
- Password in memory: Brief exposure during KDF computation

