Skip to main content

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:
Mitigation: Use random passwords, avoid dictionary words. Brute Force Attack:
Mitigation: Use long passwords (16+ chars). Rainbow Table Attack:
Mitigation: Salt prevents this (built into keystore).

KDF Security

Scrypt is memory-hard, making it resistant to parallel attacks:
Security properties:
  • Memory-hard: Requires ~256 MB RAM per attempt
  • GPU-resistant: Memory bandwidth limits parallelization
  • ASIC-resistant: Hard to build specialized hardware
Memory requirement: 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:
Security concerns:
  • GPU-parallelizable: Attackers can try millions of passwords/second
  • ASIC-parallelizable: Custom hardware can be built
  • Lower security per iteration: Compared to scrypt
Use PBKDF2 only when scrypt is unavailable or too slow. Increase iterations (1M+) for better security.

KDF Parameter Guidelines

Attack Scenarios

Stolen Keystore File

Scenario: Attacker obtains keystore JSON file. Attack: Offline password cracking
Defense:
  • 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 differences
Defense: Constant-time MAC comparison (built-in)

Memory 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 output
Defense: Always verify decrypted key produces expected address

Best 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

  1. IV not in MAC: Corrupted IV produces wrong output without error
  2. No key stretching metadata: Can’t verify KDF parameters were followed
  3. Password in memory: Brief exposure during KDF computation

Hardware Wallet Alternative

For high-value keys, consider hardware wallets instead of keystores:
Use keystores for convenience (hot wallets) and hardware wallets for security (cold storage).

References