--- id: wiki-2026-0508-homomorphic-encryption title: Homomorphic Encryption (HE) category: 10_Wiki/Topics status: verified canonical_id: self aliases: [HE, FHE, homomorphic encryption, fully homomorphic, CKKS, BFV, BGV, TFHE, privacy-preserving ML] duplicate_of: none source_trust_level: A confidence_score: 0.93 verification_status: applied tags: [cryptography, fhe, privacy, encryption, ml-privacy, secure-computation] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: C++ / Python framework: Microsoft SEAL / OpenFHE / Concrete / TFHE-rs --- # Homomorphic Encryption ## 매 한 줄 > **"매 encrypted data 의 의 의 직접 의 compute"**. 매 plaintext 의 reveal X. 매 Gentry 2009 (FHE breakthrough). 매 modern: 매 CKKS (real / approximate), BFV/BGV (integer), TFHE (Boolean). 매 응용: 매 privacy-preserving ML, 매 cloud, 매 medical. ## 매 핵심 ### 매 levels - **Partial HE** (PHE): 매 single op (add or mul). - **Somewhat HE** (SHE): 매 limited depth. - **Leveled HE**: 매 known depth. - **Fully HE** (FHE): 매 unlimited depth via bootstrapping. ### 매 schemes - **CKKS**: 매 approximate arithmetic on real / complex (modern ML). - **BFV / BGV**: 매 exact integer. - **TFHE**: 매 fast bootstrapping, Boolean. - **NTRU**, **GSW**: 매 historical / specialized. ### 매 modern library - **Microsoft SEAL** (CKKS, BFV). - **OpenFHE** (모든 schemes). - **Concrete** (Zama, TFHE). - **TFHE-rs** (Rust). - **PySEAL**, **TenSEAL** (Python). ### 매 응용 1. **Privacy-preserving ML inference**. 2. **Medical** (encrypted genomic). 3. **Financial** (encrypted query). 4. **Cloud compute** (zero-knowledge). 5. **Federated learning** + HE. 6. **Smart contract** (FHEVM). ### 매 cost - 매 100x-10000x slowdown vs plaintext. - 매 modern hardware (GPU FHE) 의 의 의 reduce. - 매 ciphertext 매 100-1000x larger. ## 💻 패턴 ### TenSEAL (CKKS, Python) ```python import tenseal as ts context = ts.context(ts.SCHEME_TYPE.CKKS, poly_modulus_degree=8192, coeff_mod_bit_sizes=[60, 40, 40, 60]) context.global_scale = 2**40 context.generate_galois_keys() # 매 encrypt v1 = ts.ckks_vector(context, [1.0, 2.0, 3.0]) v2 = ts.ckks_vector(context, [4.0, 5.0, 6.0]) # 매 compute on ciphertext add = v1 + v2 # 매 [5, 7, 9] mul = v1 * v2 # 매 [4, 10, 18] dot = v1.dot(v2) # 매 32 # 매 decrypt only when needed print(add.decrypt()) ``` ### Microsoft SEAL (BFV, C++) ```cpp #include "seal/seal.h" using namespace seal; EncryptionParameters parms(scheme_type::bfv); parms.set_poly_modulus_degree(4096); parms.set_coeff_modulus(CoeffModulus::BFVDefault(4096)); parms.set_plain_modulus(1024); SEALContext context(parms); KeyGenerator keygen(context); PublicKey public_key; keygen.create_public_key(public_key); SecretKey secret_key = keygen.secret_key(); Encryptor encryptor(context, public_key); Evaluator evaluator(context); Decryptor decryptor(context, secret_key); Plaintext x_plain("5"); Ciphertext x_encrypted; encryptor.encrypt(x_plain, x_encrypted); Ciphertext result; evaluator.square(x_encrypted, result); // 매 5² = 25 (encrypted) ``` ### Encrypted ML inference (logistic regression) ```python def encrypted_logistic_regression(encrypted_x, weights_plaintext, bias_plaintext): """매 매 매 weights / bias 매 plaintext, 매 input 매 encrypted.""" z = encrypted_x.dot(weights_plaintext) + bias_plaintext # 매 sigmoid approximation (poly degree 3) z2 = z * z z3 = z2 * z sigmoid_approx = 0.5 + 0.197 * z - 0.004 * z3 # 매 around 0 return sigmoid_approx ``` ### Sigmoid polynomial approx (CKKS) ```python def sigmoid_poly_approx(z): """매 매 [-5, 5] 의 의 의 valid.""" # 매 deg 3 Taylor-like z2 = z * z z3 = z2 * z z5 = z3 * z2 return 0.5 + 0.197 * z - 0.004 * z3 + 0.0001 * z5 ``` ### Encrypted neural net (CKKS) ```python def encrypted_dense_layer(enc_x, weights, bias): """매 매 layer 의 linear part 는 가능, 매 ReLU 는 polynomial approx.""" z = enc_x.mm(weights) + bias # 매 matrix-vector return polynomial_relu_approx(z) def polynomial_relu_approx(z): """매 ReLU(x) ≈ a + b*x + c*x².""" z2 = z * z return 0.375 * z + 0.5 + 0.125 * z2 # 매 매 small range ``` ### Bootstrapping (FHE refresh) ```python # 매 SEAL CKKS 의 native bootstrap # 매 OpenFHE import openfhe parameters = openfhe.CCParamsCKKSRNS() parameters.SetMultiplicativeDepth(20) cc = openfhe.GenCryptoContext(parameters) cc.Enable(openfhe.PKESchemeFeature.PKE) cc.Enable(openfhe.PKESchemeFeature.LEVELEDSHE) cc.Enable(openfhe.PKESchemeFeature.ADVANCEDSHE) cc.Enable(openfhe.PKESchemeFeature.FHE) # 매 bootstrap ct_refreshed = cc.EvalBootstrap(ct) ``` ### TFHE (Boolean fast) ```rust use tfhe::boolean::prelude::*; let (client_key, server_key) = gen_keys(); let ct1 = client_key.encrypt(true); let ct2 = client_key.encrypt(false); // 매 server side let result = server_key.and(&ct1, &ct2); // 매 client side let dec = client_key.decrypt(&result); // 매 false ``` ### Concrete-ML (Zama) ```python from concrete.ml.sklearn import LogisticRegression model = LogisticRegression(n_bits=8) model.fit(X_train, y_train) # 매 compile to FHE model.compile(X_train) # 매 encrypted inference y_pred = model.predict(X_test_encrypted) ``` ### Multi-party (HE + secret share) ```python def hybrid_compute(encrypted_data_party_a, encrypted_data_party_b, secure_aggregator): # 매 매 party 매 encrypt own data # 매 aggregator 의 의 의 sum (HE) sum_encrypted = encrypted_data_party_a + encrypted_data_party_b # 매 only authorized 매 decrypt return sum_encrypted ``` ### Performance benchmark ```python import time def benchmark_he(scheme='ckks'): setup_t = time.perf_counter() context = create_context(scheme) keys = setup_keys(context) setup_t = time.perf_counter() - setup_t enc_t = time.perf_counter() ct = encrypt([1, 2, 3], context, keys.pub) enc_t = time.perf_counter() - enc_t op_t = time.perf_counter() ct2 = ct * ct op_t = time.perf_counter() - op_t return {'setup': setup_t, 'encrypt': enc_t, 'op': op_t} ``` ### Threshold HE (multi-key) ```python # 매 multi-party with shared secret # 매 매 party 매 partial decryption share def threshold_decrypt(ciphertext, partial_shares, threshold): if len(partial_shares) >= threshold: return combine_shares(partial_shares, ciphertext) raise ThresholdNotMet() ``` ### FHEVM (smart contract on encrypted) ```solidity // 매 fhEVM (Zama) import "fhevm/lib/TFHE.sol"; contract EncryptedAuction { euint64 highestBid; // 매 encrypted function bid(bytes calldata encryptedAmount) public { euint64 amount = TFHE.asEuint64(encryptedAmount); highestBid = TFHE.max(highestBid, amount); } } ``` ## 매 결정 기준 | 상황 | Scheme | |---|---| | ML inference (real) | CKKS | | Exact integer | BFV / BGV | | Boolean / lookup | TFHE | | Smart contract | FHEVM (TFHE-based) | | Multi-party | Threshold HE | | Best library | OpenFHE / SEAL / Concrete | **기본값**: 매 ML = CKKS + 매 polynomial activation. 매 boolean = TFHE. 매 always benchmark before commit (100-1000x cost). ## 🔗 Graph - 부모: [[Practical-Cryptography|Cryptography]] - 응용: [[Privacy-Preserving-ML]] · [[Federated-Learning]] - Adjacent: [[Differential-Privacy]] · [[Secure Multi-party Computation]] ## 🤖 LLM 활용 **언제**: 매 medical / financial. 매 cloud trust. 매 multi-party compute. **언제 X**: 매 latency-critical. 매 plaintext 의 가능. ## ❌ 안티패턴 - **FHE for everything**: 매 cost overkill. - **No polynomial approx of activation**: 매 deep ReLU 의 hard. - **Wrong scheme**: 매 BFV for real-valued ML. - **No bootstrap when deep**: 매 noise overflow. ## 🧪 검증 / 중복 - Verified (Gentry 2009, CKKS 2017, OpenFHE / SEAL / Concrete docs). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-04-26 | Auto | | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — schemes + 매 TenSEAL / SEAL / TFHE / Concrete / FHEVM code |