
암호학
Cryptographic Agility암호화 민첩성
암호화 민첩성(Cryptographic Agility)은 현재 사용 중인 암호화 알고리즘을 최소한의 변경으로 교체할 수 있도록 시스템을 설계하는 원칙이다. 양자 컴퓨터 위협, 알고리즘 폐기 등에 유연하게 대응하기 위해 필수적이다.
왜 중요한가
역사적 사례:
- MD5 → SHA-1 → SHA-256: 해시 함수 교체
- DES → 3DES → AES: 대칭 암호 교체
- RSA-1024 → RSA-2048: 키 길이 확장
- SHA-1 인증서: 2016년 브라우저 차단
미래 위협:
- 양자 컴퓨터: RSA, ECC 등 비대칭 암호 파괴
- NIST PQC (2024): ML-KEM, ML-DSA 표준화
→ 빠른 교체 능력 = 암호화 민첩성나쁜 설계 (하드코딩)
python
# 나쁜 예: 알고리즘 하드코딩
def encrypt(data: bytes, key: bytes) -> bytes:
from Crypto.Cipher import AES
cipher = AES.new(key, AES.MODE_GCM) # AES 하드코딩
ciphertext, tag = cipher.encrypt_and_digest(data)
return cipher.nonce + tag + ciphertext
# 교체 시: 모든 호출부 수정 필요민첩한 설계 (추상화)
python
from abc import ABC, abstractmethod
from cryptography.hazmat.primitives.ciphers.aead import AESGCM, ChaCha20Poly1305
class EncryptionProvider(ABC):
@abstractmethod
def encrypt(self, data: bytes, key: bytes) -> bytes: ...
@abstractmethod
def decrypt(self, ciphertext: bytes, key: bytes) -> bytes: ...
class AESGCMProvider(EncryptionProvider):
def encrypt(self, data: bytes, key: bytes) -> bytes:
import os
nonce = os.urandom(12)
return nonce + AESGCM(key).encrypt(nonce, data, None)
def decrypt(self, ct: bytes, key: bytes) -> bytes:
return AESGCM(key).decrypt(ct[:12], ct[12:], None)
class ChaCha20Provider(EncryptionProvider):
def encrypt(self, data: bytes, key: bytes) -> bytes:
import os
nonce = os.urandom(12)
return nonce + ChaCha20Poly1305(key).encrypt(nonce, data, None)
def decrypt(self, ct: bytes, key: bytes) -> bytes:
return ChaCha20Poly1305(key).decrypt(ct[:12], ct[12:], None)
# 알고리즘 ID를 데이터와 함께 저장
class CryptoManager:
providers = {
1: AESGCMProvider(),
2: ChaCha20Provider(),
}
CURRENT = 2 # 현재 기본 알고리즘
def encrypt(self, data: bytes, key: bytes) -> bytes:
algo_id = self.CURRENT
ct = self.providers[algo_id].encrypt(data, key)
return bytes([algo_id]) + ct # 알고리즘 ID 앞에 붙임
def decrypt(self, data: bytes, key: bytes) -> bytes:
algo_id = data[0]
return self.providers[algo_id].decrypt(data[1:], key)마이그레이션 전략
단계적 마이그레이션:
1. 새 알고리즘으로 암호화 시작 (쓰기)
2. 구/신 알고리즘 모두 복호화 지원 (읽기)
3. 기존 데이터 점진적 재암호화
4. 구 알고리즘 지원 제거
TLS 예: 서버가 구/신 cipher suite 모두 지원
→ 클라이언트 업그레이드 후 구 제거