Modern Block Cipher (ví dụ: AES, Twofish, Serpent, Camellia) được xây dựng từ các primitive cốt lõi lặp lại qua nhiều vòng (rounds) để đạt Confusion (phi tuyến) và Diffusion (khuếc tán).
1. S-box (Substitution Box) — Confusion
Chức năng: Thay thế phi tuyến (non-linear substitution) — nguồn duy nhất của phi tuyến trong hầu hết block cipher. Đầu vào n-bit, đầu ra m-bit (thường n=m=8 cho AES).
- Yêu cầu bảo mật: Non-linearity cao (bias tuyến tính thấp), Differential uniformity thấp (APN/near-APN), Strict Avalanche Criterion (SAC), Bit Independence Criterion (BIC), không fixed point, không opposite fixed point.
- AES S-box: x ↦ x⁻¹ trên GF(2⁸) + affine transform. Non-linearity = 112 (tối đa cho 8-bit), Diff uniformity = 4.
- Triển khai: Lookup table (256 byte) — nhanh nhưng dễ side-channel (cache timing). Bitslicing / constant-time / AES-NI khuyến nghị.
2. P-box / D-box (Permutation / Diffusion Box) — Diffusion
Chức năng: Hoán vị bit/word để lan tỏa thay đổi. Ba loại:
| Loại | Đầu vào → Đầu ra | Mục đích | Ví dụ |
|---|---|---|---|
| Straight D-box | n-bit → n-bit (hoán vị) | Đơn thuần tráo đổi vị trí bit | DES Initial/Final Permutation, AES ShiftRows |
| Compression D-box | n-bit → m-bit (m < n) | Giảm số bit, chọn lọc | DES Compression Permutation (56→48 bit round key) |
| Expansion D-box | n-bit → m-bit (m > n) | Mở rộng, lặp bit để khớp kích thước | DES Expansion (32→48 bit cho S-box input) |
3. Linear Diffusion Layer (MDS Matrix / Mixing Layer)
Mạnh hơn P-box đơn thuần: dùng phép nhân ma trận MDS (Maximum Distance Separable) trên trường hữu hạn.
- AES MixColumns: Nhân cột 4-byte với ma trận MDS 4×4 trên GF(2⁸). Branch number = 5 (tối đa).
- Twofish / Camellia / SHARK / Square: MDS matrix 4×4 hoặc 8×8.
- ARX ciphers (ChaCha20, BLAKE2): Diffusion qua Add-Rotate-XOR quarter round — không cần S-box/P-box tách biệt.
4. Circular Shift / Rotation
- Dịch vòng (rotate left/right) bit/word.
- Dùng trong: RC5/RC6 (data-dependent rotation), ChaCha20 (rotate 16/12/8/7), Simon/Speck (rotate fixed).
- Giúp lan tỏa bit giữa các word, phá vỡ ranh giới byte/word.
5. Key Schedule (Key Expansion)
Mở rộng khóa master thành các round key. Yêu cầu:
- Key separation: Round key khác nhau, không có quan hệ tuyến tính đơn giản.
- Diffusion trong key schedule: 1 bit master key ảnh hưởng nhiều round key.
- Chống related-key attack: AES-128 key schedule tốt; AES-192/256 yếu hơn (related-key attack 9/10 vòng).
6. Round Structure (Cấu trúc vòng)
| Kiến trúc | Mô tả | Ví dụ |
|---|---|---|
| SPN (Substitution-Permutation Network) | S-box → P-box/Linear layer → Add Round Key. Lặp nhiều vòng. | AES, PRESENT, SKINNY, GIFT |
| Feistel Network | Chia 2 nửa, F-function trên nửa + key, swap. Có thể dùng F không khả nghịch. | DES, Camellia, SM4, Simon |
| Generalized Feistel (Type-1/2/3) | Mở rộng Feistel cho nhiều nhánh (4, 8 nhánh). | CAST-256, CLEFIA, SMS4 |
| ARX (Add-Rotate-XOR) | Chỉ dùng ADD mod 2ⁿ, ROTATE, XOR. Không S-box, không table lookup. | ChaCha20, BLAKE2/3, Speck, Chaskey |
| Lai-Massey | Biến thể Feistel, dùng orthomorphism. | IDEA, FOX |
Tóm tắt: AES-128 Round Function
Round(i):
SubBytes(state) # S-box 8-bit (Confusion)
ShiftRows(state) # Permutation (Diffusion - byte level)
MixColumns(state) # MDS Matrix (Diffusion - column level) ← full diffusion sau 2 vòng
AddRoundKey(state, RK[i]) # XOR round key
Nguyên tắc thiết kế: Mỗi primitive đơn giản, nhưng lặp lại đủ vòng (AES: 10) với key schedule tốt → bảo mật provable against linear/differential (wide-trail strategy).