Mật mã học (Cryptography) trong an ninh mạng là gì?
Là khoa học và nghệ thuật bảo vệ thông tin bằng cách biến đổi dữ liệu thành dạng không thể đọc hiểu (ciphertext) trừ khi có khóa bí mật (key). Trong an ninh mạng, mật mã học cung cấp 4 trụ cột:
- Tính bảo mật (Confidentiality): Mã hóa (Encryption) - Chỉ người có khóa mới đọc được
- Tính toàn vẹn (Integrity): Hash function, MAC, Chữ ký số - Phát hiện thay đổi dữ liệu
- Xác thực (Authentication): Xác thực thực thể (Entity auth), Xác thực dữ liệu (Data origin auth) - Chứng minh danh tính
- Không thể chối cãi (Non-repudiation): Chữ ký số (Digital Signature) - Không thể phủ nhận đã ký/gửi
Các loại mật mã học chính
| Loại | Đặc điểm | Thuật toán điển hình | Ứng dụng mạng |
|---|---|---|---|
| Đối xứng (Symmetric) | Một khóa (secret key) dùng cho cả mã hóa & giải mã. Nhanh, hiệu quả cho dữ liệu lớn | AES-256/128 (GCM, CCM, CTR), ChaCha20-Poly1305, Camellia | TLS record layer, IPsec ESP, Wi-Fi (WPA2/WPA3), Disk encryption, VPN data plane |
| Bất đối xứng (Asymmetric / Public Key) | Cặp khóa: Public key (mã hóa/verify) & Private key (giải mã/sign). Chậm, dùng cho key exchange, chữ ký | RSA-2048/3072/4096, ECC (P-256, P-384, Curve25519, Ed25519), ML-KEM (Kyber - PQC) | TLS handshake (Key exchange, Auth), SSH, IPsec IKE, PKI, Code signing, Email encryption (S/MIME, PGP) |
| Hàm băm (Hash Function) | Một chiều, deterministic, fixed output. Collision resistance, Preimage resistance | SHA-256/384/512, SHA-3 (Keccak), BLAKE2/3, HMAC-SHA256 | TLS certificate, Integrity check, Password hashing (bcrypt, Argon2, PBKDF2), Blockchain, Git commit |
| MAC (Message Authentication Code) | Symmetric key + Hash → Integrity + Authenticity | HMAC-SHA256, CMAC-AES, GMAC (AES-GCM), Poly1305 | TLS record (AEAD), IPsec, JWT (HS256), API authentication |
| Chữ ký số (Digital Signature) | Asymmetric: Private key sign, Public key verify. Non-repudiation | RSA-PSS, ECDSA (P-256), EdDSA (Ed25519), Dilithium (PQC) | TLS Certificate, Code signing, Document signing, Blockchain, Firmware verification |
| Key Derivation (KDF) | Tạo khóa từ password/master key | PBKDF2, HKDF, scrypt, Argon2, bcrypt | Password hashing, TLS key schedule, Signal Double Ratchet, WireGuard |
Ứng dụng trong các giao thức an ninh mạng
TLS/SSL (HTTPS, API, gRPC, LDAPS, SMTPS, IMAPS...)
- Handshake: Asymmetric (ECDHE/RSA) → Key exchange + Server Auth (Cert) + Optional Client Auth
- Record Layer: Symmetric AEAD (AES-GCM, ChaCha20-Poly1305) - Confidentiality + Integrity
- TLS 1.3 (RFC 8446): Bắt buộc Forward Secrecy (ECDHE), loại bỏ RSA key exchange, 0-RTT, Encrypted Client Hello (ECH)
IPsec (VPN Site-to-Site, Remote Access)
- IKEv2 (Internet Key Exchange): Asymmetric auth (Cert/PSK/EAP) → Derive symmetric keys
- ESP (Encapsulating Security Payload): AES-GCM / AES-CBC + HMAC-SHA256 - Confidentiality + Integrity + Anti-replay
- AH (Authentication Header): Chỉ Integrity/Auth (hiếm dùng do NAT issue)
SSH (Secure Shell)
- Key Exchange: Curve25519, ECDH, DH Group Exchange
- Host Auth: Host Key (Ed25519, ECDSA, RSA) - Trust on First Use (TOFU) hoặc CA-signed
- User Auth: Public Key (Ed25519 khuyên dùng), Password, Keyboard-interactive, Certificate
- Transport: AES-GCM, ChaCha20-Poly1305 - Encrypted channel
Wireless (Wi-Fi - WPA2/WPA3)
- WPA2-Personal: PBKDF2(SSID, Passphrase) → PMK → 4-way Handshake → PTK (AES-CCMP)
- WPA3-Personal: SAE (Simultaneous Authentication of Equals) - Dragonfly handshake, Forward Secrecy, Offline dictionary attack resistant
- WPA2/3-Enterprise: 802.1X/EAP (EAP-TLS, PEAP-MSCHAPv2, EAP-TTLS) → RADIUS → PMK → 4-way handshake
WireGuard (Modern VPN)
- Noise Protocol Framework: Curve25519 (DH), ChaCha20-Poly1305 (AEAD), BLAKE2s (Hash), HKDF (KDF)
- Static key pairs (Public/Private) - No handshake latency, Forward Secrecy qua key rotation
- Cryptokey Routing: Public key = Identity = AllowedIPs
MACsec (802.1AE - Layer 2 Encryption)
- Hopping hop encryption trên Ethernet (Switch-to-Switch, Server-to-Switch)
- AES-GCM (GCM-AES-128/256, GCM-AES-XPN-128/256)
- Key Agreement: MKA (MACsec Key Agreement) over EAP-TLS hoặc PSK
Quản trị Khóa (Key Management) - Yếu tố thành bại
- Key Generation: CSPRNG (Cryptographically Secure PRNG) - `/dev/urandom`, `getrandom()`, HSM, Cloud KMS
- Key Storage: HSM (Hardware Security Module - FIPS 140-2/3 Level 3), TPM, Secure Enclave, Cloud KMS (AWS KMS, Azure Key Vault, GCP KMS, HashiCorp Vault)
- Key Rotation: Định kỳ (90 ngày - 1 năm), tự động hóa, zero-downtime rotation
- Key Revocation & Destruction: Certificate Revocation (CRL, OCSP), Key destruction (NIST SP 800-88)
- Key Hierarchy: Master Key → Key Encryption Key (KEK) → Data Encryption Key (DEK) - Envelope Encryption
- Post-Quantum Cryptography (PQC) Readiness: Chuẩn bị ML-KEM (Kyber-768), ML-DSA (Dilithium), SLH-DSA (SPHINCS+) - NIST PQC Standard 2024
Best Practice Triển khai Mật mã học
- ĐỪNG tự implement crypto: Dùng thư viện đã audit: OpenSSL, BoringSSL, libsodium, Go crypto/std, Rust ring, Java/JCA, .NET System.Security.Cryptography
- Dùng AEAD (Authenticated Encryption with Associated Data): AES-GCM, ChaCha20-Poly1305 - Cung cấp Confidentiality + Integrity + Authenticity trong một phép toán
- Không dùng thuật toán yếu: DES, 3DES, RC4, MD5, SHA-1, RSA < 2048-bit, ECC < P-256, ECB mode, CBC không MAC (padding oracle)
- Quản trị khóa đúng cách: HSM/Cloud KMS, Rotation, Separation of duties, Audit logging
- TLS Everywhere: Mọi service (internal cũng vậy) - mTLS cho service-to-service (SPIFFE/SPIRE, Istio, Linkerd, Consul Connect)
- Certificate Management Automation: ACME (Let's Encrypt), cert-manager (K8s), Smallstep, Venafi, HashiCorp Vault PKI
- Password Hashing: Argon2id (khuyên dùng), bcrypt, scrypt, PBKDF2 - KHÔNG dùng SHA-256/MD5 cho password
- Crypto Agility: Thiết kế cho phép thay thuật toán/khóa dễ dàng (Algorithm identifier, Version negotiation)
- Side-channel Resistance: Constant-time implementation, Blinding (cho RSA/ECC), Memory protection
Mật mã học sau lượng tử (Post-Quantum Cryptography - PQC)
| Chức năng | Thuật toán NIST PQC (2024) | Thay thế |
|---|---|---|
| Key Encapsulation (KEM) / Key Exchange | ML-KEM (Kyber-768) - Module-Lattice | RSA, ECDH, DH |
| Digital Signature | ML-DSA (Dilithium) - Module-Lattice | RSA, ECDSA, EdDSA |
| Digital Signature (Stateless, Hash-based) | SLH-DSA (SPHINCS+) | Backup cho Dilithium |
| Key Encapsulation (Code-based) | Classic McEliece (Round 4 - conservative) | Backup cho Kyber |