Tiếp nối từ Phần 1, hôm nay chúng ta cover hai chương quan trọng: Mật mã học và SDN Security / Network Programmability.
CHƯƠNG 2: Cryptography
Symmetric Encryption
Dùng cùng 1 key để encrypt và decrypt. Vấn đề chính: làm sao chia sẻ key an toàn?
Algorithms:
| Thuật toán | Key Size | Ghi chú |
|-----------|---------|---------|
| DES | 56-bit | Đã bị phá — tránh dùng |
| 3DES | 112/168-bit | Legacy, đang thay thế |
| AES-128 | 128-bit | Đủ cho most use cases |
| AES-256 | 256-bit | Recommended, post-quantum resistant |
| ChaCha20 | 256-bit | Nhanh hơn AES trên mobile |
Modes of Operation trong AES:
- ECB (Electronic Codebook): Dangerous! Same plaintext → same ciphertext. KHÔNG dùng.
- CBC (Cipher Block Chaining): Mỗi block XOR với block trước. Cần IV (Initialization Vector).
- GCM (Galois/Counter Mode): Authenticated encryption (encrypt + integrity). Khuyến nghị.
Asymmetric Encryption
Dùng cặp key: Public Key + Private Key. Giải quyết key distribution problem.
RSA:
- Security dựa trên độ khó factoring large numbers.
- Key sizes: 1024-bit (đã yếu), 2048-bit (minimum hiện nay), 4096-bit (cho long-term).
- Chậm hơn AES ~100x.
Elliptic Curve Cryptography (ECC):
- Cùng security level với RSA nhưng key ngắn hơn nhiều.
- P-256 (256-bit ECC) ≈ RSA-3072 về security.
- Phổ biến trên mobile, IoT, TLS 1.3.
Diffie-Hellman (DH):
- Key exchange protocol — tạo shared secret qua kênh không bảo mật.
- DH Groups: Group 1 (768-bit, broken), Group 2 (1024-bit, weak), Group 14+ (2048-bit, OK), Group 19/20/21 (ECC, recommended).
Hashing
One-way function. Input bất kỳ → output fixed-length.
| Algorithm | Output Size | Trạng thái |
|-----------|------------|------------|
| MD5 | 128-bit | Broken — chỉ dùng cho checksums không nhạy cảm |
| SHA-1 | 160-bit | Legacy — deprecated cho certs |
| SHA-256 | 256-bit | ✅ Recommended |
| SHA-384 | 384-bit | ✅ Cho thông tin phân loại cao |
| SHA-512 | 512-bit | ✅ Post-quantum secure |
| SHA-3 | Variable | Thiết kế khác hoàn toàn SHA-2 |
Tính chất quan trọng:
- Collision resistance: Khó tìm 2 inputs cho cùng hash.
- Avalanche effect: Thay 1 bit → hash thay đổi hoàn toàn.
- Pre-image resistance: Không thể reverse hash → plaintext.
HMAC (Hash-based Message Authentication Code):
HMAC = Hash(Key || Message)
Kết hợp hash với secret key → xác thực cả integrity lẫn authenticity.
HMAC-SHA256 là recommended. HMAC-MD5 là legacy (acceptable nhưng nên tránh).
Salted Hashing:
hash = SHA-256(salt + password)
Salt là random string thêm vào trước khi hash, stored cùng hash.
Ngăn rainbow table attacks. Bcrypt, Argon2 là các algorithm thiết kế đặc biệt cho password hashing (slow by design).
Digital Signatures
Cung cấp 3 đảm bảo:
1. Authentication: Ai đã ký?
2. Integrity: Dữ liệu chưa bị sửa?
3. Non-repudiation: Người ký không thể phủ nhận.
Process:
Signing: Hash(document) → Encrypt(hash, PrivateKey) = Signature
Verifying: Decrypt(signature, PublicKey) = hash1
Hash(received_document) = hash2
If hash1 == hash2 → Valid!
PKI (Public Key Infrastructure)
Components:
- CA (Certificate Authority): Tổ chức uy tín cấp digital certificates.
- RA (Registration Authority): Xác minh identity trước khi CA cấp cert.
- CRL (Certificate Revocation List): Danh sách certs đã bị thu hồi. Nhược: không real-time.
- OCSP (Online Certificate Status Protocol): Real-time cert status check.
- Certificate (X.509): Gồm Public Key + Subject info + Issuer info + Validity + CA signature.
Chain of Trust:
Root CA (self-signed, offline)
└── Intermediate CA
└── End-entity Certificate (website, user, device)
Root CA phải được browsers/OS tin tưởng để chain work.
Certificate Types:
- DV (Domain Validation): Chỉ verify domain ownership. Let's Encrypt.
- OV (Organization Validation): Verify organization info.
- EV (Extended Validation): Strict verification. Hiển thị company name trong thanh địa chỉ (cũ).
Perfect Forward Secrecy (PFS):
Mỗi session dùng ephemeral key khác nhau (DHE, ECDHE).
Kể cả server private key bị lộ sau này, các session cũ vẫn không decrypt được.
TLS 1.3 bắt buộc PFS. TLS 1.0/1.1 đã bị deprecated.
CHƯƠNG 2: Cryptography
Symmetric Encryption
Dùng cùng 1 key để encrypt và decrypt. Vấn đề chính: làm sao chia sẻ key an toàn?
Algorithms:
| Thuật toán | Key Size | Ghi chú |
|-----------|---------|---------|
| DES | 56-bit | Đã bị phá — tránh dùng |
| 3DES | 112/168-bit | Legacy, đang thay thế |
| AES-128 | 128-bit | Đủ cho most use cases |
| AES-256 | 256-bit | Recommended, post-quantum resistant |
| ChaCha20 | 256-bit | Nhanh hơn AES trên mobile |
Modes of Operation trong AES:
- ECB (Electronic Codebook): Dangerous! Same plaintext → same ciphertext. KHÔNG dùng.
- CBC (Cipher Block Chaining): Mỗi block XOR với block trước. Cần IV (Initialization Vector).
- GCM (Galois/Counter Mode): Authenticated encryption (encrypt + integrity). Khuyến nghị.
Asymmetric Encryption
Dùng cặp key: Public Key + Private Key. Giải quyết key distribution problem.
RSA:
- Security dựa trên độ khó factoring large numbers.
- Key sizes: 1024-bit (đã yếu), 2048-bit (minimum hiện nay), 4096-bit (cho long-term).
- Chậm hơn AES ~100x.
Elliptic Curve Cryptography (ECC):
- Cùng security level với RSA nhưng key ngắn hơn nhiều.
- P-256 (256-bit ECC) ≈ RSA-3072 về security.
- Phổ biến trên mobile, IoT, TLS 1.3.
Diffie-Hellman (DH):
- Key exchange protocol — tạo shared secret qua kênh không bảo mật.
- DH Groups: Group 1 (768-bit, broken), Group 2 (1024-bit, weak), Group 14+ (2048-bit, OK), Group 19/20/21 (ECC, recommended).
Hashing
One-way function. Input bất kỳ → output fixed-length.
| Algorithm | Output Size | Trạng thái |
|-----------|------------|------------|
| MD5 | 128-bit | Broken — chỉ dùng cho checksums không nhạy cảm |
| SHA-1 | 160-bit | Legacy — deprecated cho certs |
| SHA-256 | 256-bit | ✅ Recommended |
| SHA-384 | 384-bit | ✅ Cho thông tin phân loại cao |
| SHA-512 | 512-bit | ✅ Post-quantum secure |
| SHA-3 | Variable | Thiết kế khác hoàn toàn SHA-2 |
Tính chất quan trọng:
- Collision resistance: Khó tìm 2 inputs cho cùng hash.
- Avalanche effect: Thay 1 bit → hash thay đổi hoàn toàn.
- Pre-image resistance: Không thể reverse hash → plaintext.
HMAC (Hash-based Message Authentication Code):
HMAC = Hash(Key || Message)
Kết hợp hash với secret key → xác thực cả integrity lẫn authenticity.
HMAC-SHA256 là recommended. HMAC-MD5 là legacy (acceptable nhưng nên tránh).
Salted Hashing:
hash = SHA-256(salt + password)
Salt là random string thêm vào trước khi hash, stored cùng hash.
Ngăn rainbow table attacks. Bcrypt, Argon2 là các algorithm thiết kế đặc biệt cho password hashing (slow by design).
Digital Signatures
Cung cấp 3 đảm bảo:
1. Authentication: Ai đã ký?
2. Integrity: Dữ liệu chưa bị sửa?
3. Non-repudiation: Người ký không thể phủ nhận.
Process:
Signing: Hash(document) → Encrypt(hash, PrivateKey) = Signature
Verifying: Decrypt(signature, PublicKey) = hash1
Hash(received_document) = hash2
If hash1 == hash2 → Valid!
PKI (Public Key Infrastructure)
Components:
- CA (Certificate Authority): Tổ chức uy tín cấp digital certificates.
- RA (Registration Authority): Xác minh identity trước khi CA cấp cert.
- CRL (Certificate Revocation List): Danh sách certs đã bị thu hồi. Nhược: không real-time.
- OCSP (Online Certificate Status Protocol): Real-time cert status check.
- Certificate (X.509): Gồm Public Key + Subject info + Issuer info + Validity + CA signature.
Chain of Trust:
Root CA (self-signed, offline)
└── Intermediate CA
└── End-entity Certificate (website, user, device)
Root CA phải được browsers/OS tin tưởng để chain work.
Certificate Types:
- DV (Domain Validation): Chỉ verify domain ownership. Let's Encrypt.
- OV (Organization Validation): Verify organization info.
- EV (Extended Validation): Strict verification. Hiển thị company name trong thanh địa chỉ (cũ).
Perfect Forward Secrecy (PFS):
Mỗi session dùng ephemeral key khác nhau (DHE, ECDHE).
Kể cả server private key bị lộ sau này, các session cũ vẫn không decrypt được.
TLS 1.3 bắt buộc PFS. TLS 1.0/1.1 đã bị deprecated.