基于GPU加速的快速全同态加密算法设计与实现
网络出版日期: 2024-11-16
基金资助
国家重点研发计划项目(2022YFB3102100)
版权
Design and implementation of fast fully homomorphic encryption algorithm based on GPU acceleration
Online published: 2024-11-16
Copyright
全同态加密算法支持直接对加密数据(密文)执行代数运算,但其密文评估中的数论变换(NTT)涉及大量高维度整系数多项式环运算,限制了其在隐私计算中的应用。针对CPU实现方案对NTT算法计算并行度较低的问题,提出一种CPU+GPU异构的CKKS全同态加密实现方案。首先,根据NTT算法数据内存访问规律,设计一种数据暂存共享内存策略,有效减少频繁的全局内存访问。其次,针对数据规模可变导致内核出现部分空闲线程的问题,设计线程工作负载动态分配机制,并采用不同基数的蝴蝶变换结构,提高数据输入的灵活性并优化并行策略。再次,提出单—多内核混合调用模式,通过NTT算法蝶形变换分组大小动态切换内核调用模式,充分利用GPU多核调用的并行潜力。最后,设计并实现并行程度更高、计算复杂度更低的NTT算法,利用该算法实现并行的同态乘法运算,并基于HElib库实现CPU+GPU异构的CKKS全同态加密算法。实验结果表明,与使用AVX-512加速的HElib库相比,所提的NTT/INTT计算时间减短近65%。
谭泽玖 , 赵鑫 , 万俊平 , 刘虎成 , 蒋琳 , 徐金明 , 纪守领 , 王轩 . 基于GPU加速的快速全同态加密算法设计与实现[J]. 网络空间安全科学学报, 2024 , 2(3) : 41 -52 . DOI: 10.20172/j.issn.2097-3136.240304
Fully homomorphic encryption supports direct algebraic operations on encrypted data (ciphertext), with the foundation of its ciphertext evaluation phase involving numerous high-dimensional integer coefficient polynomial ring additions and multiplications. This limits its widespread application in the field of privacy computing. The CPU implementation scheme offers low parallelism for the Number Theoretic Transform (NTT) algorithm calculations. A CPU+GPU heterogeneous fully homomorphic encryption implementation scheme was proposed. Firstly, a cache strategy of data temporarily stored in shared memory was introduced, which stored repeatedly read and unchanging data, including NTT input data and rotation factors, in shared memory to reduce frequent global memory access. Secondly, to address the issue of partially idle threads caused by variable data sizes, it dynamically allocates thread workloads based on data size and hardware resources, adopting butterfly transformation structures of different radices to achieve optimal parallel strategies while enhancing the flexibility of data input. Thirdly, it introduces a single-multi-core mixed invocation mode, dynamically switching the kernel invocation mode based on the group size of butterfly transformations in each NTT iteration, to fully utilize the parallel potential of multi-core invocations on GPU. Finally, it designs and implements a higher parallelism, lower computational complexity NTT algorithm for GPU, uses this algorithm to perform parallel homomorphic multiplication operations, and implements a CPU+GPU heterogeneous CKKS fully homomorphic encryption algorithm based on the HElib library. Experimental results show NTT/INTT computation time is reduced by nearly 65% compared to HElib library using AVX-512 acceleration technology.
表 1 不同基数的NTT对比Table 1 Comparison of NTT with different cardinals |
| NTT基数 | 计算规模 | 迭代次数 | 单次迭代访存次数 | 蝶形变换乘法次数 |
| Radix2 | ||||
| Radix4 | ||||
| Radix8 | ||||
| Radix16 |
表 2 CKKS参数Table 2 Parameters of CKKS |
| 分圆多项 式次数 | 密文模位数 bits | 精度位数 precision | 密钥切换矩 阵的列数c |
| 216 | 1 445 | 20 | 8 |
表 3 GPU参数Table 3 GPU parameters |
| GTX 980 | GTX 1050ti | Quadro RTX 8000 | |
| CUDA核心 | 768 | ||
| 显存/GB | 4 | 4 | 48 |
| 核心频率/MHz | |||
| 显存带宽/GB·s−1 | 224 | 112 | 672 |
表 4 GTX 1050ti 上优化的性能结果Table 4 Performance results optimized on GTX 1050ti |
| 操作 | 方案 | 计算规模(log2N) | |||||
| 11 | 12 | 13 | 14 | 15 | 16 | ||
| NTT | 1 | 12 | 21 | 38 | 73 | 149 | 309 |
| 2 | 95 | 98 | 103 | 109 | 117 | 127 | |
| 3 | 10 | 16 | 32 | − | − | − | |
| 4 | 16 | 32 | 42 | 49 | 61 | ||
| INTT | 1 | 14 | 24 | 40 | 75 | 151 | 315 |
| 2 | 88 | 102 | 108 | 111 | 114 | 118 | |
| 3 | 13 | 17 | 33 | − | − | − | |
| 4 | 13 | 17 | 21 | 30 | 36 | 46 | |
表 5 NTT和INTT实现的性能结果Table 5 Performance results of NTT and INTT |
| 操作 | 平台 | 模数大小( | 计算规模(log2N) | ||||
| NTT | GTX 980 | ||||||
| GTX 1050ti | |||||||
| RTX | |||||||
| INTT | GTX 980 | ||||||
| GTX 1050ti | |||||||
| RTX | |||||||
表 6 不同方案密文乘法时间Table 6 Ciphertext multiplication time of different schemes |
| 参数 | 乘法时间/ms | |
| HElib库 | 本方案 | |
表 7 不同参数下密文推理时间Table 7 Ciphertext inference time under different parameters |
| 计算层 | ||||||||
| HElib库 | 本方案 | HElib库 | 本方案 | HElib库 | 本方案 | |||
| conv2d_1 | ||||||||
| conv2d_2 | ||||||||
| flatten_1 | ||||||||
| dense_1 | ||||||||
| dense_2 | ||||||||
| 总时间 | ||||||||
| 1 |
GENTRY C. A fully homomorphic encryption scheme[M]. California:Stanford University,2009.
|
| 2 |
DUCAS L,MICCIANCIO D. Fhew:Bootstrapping homomorphic encryption in less than a second[C]//Annual International Conference on the Theory and Applications of Cryptographic Techniques. Springer,2015:617-640.
|
| 3 |
CHILLOTTI I,GAMA N,GEORGIEVA M,et al. Faster fully homomorphic encryption:Bootstrapping in less than 0.1 seconds[C]// Advances in Cryptology - ASIACRYPT 2016:22nd International Conference on the Theory and Application of Cryptology and Information Security,Hanoi,Vietnam,December 4-8,2016,Proceedings,Part I,2016:3-33.
|
| 4 |
CHEN H,HAN K. Homomorphic lower digits removal and improved FHE bootstrapping[C]// Annual International Conference on the Theory and Applications of Cryptographic Techniques. Cham:Springer International Publishing,2018:315-337.
|
| 5 |
SMART N P, VERCAUTEREN F. Fully homomorphic SIMD operations[J]. Designs, Codes and Cryptography, 2014, 71, 57- 81.
|
| 6 |
CASTRYCK W,ILIASHENKO I,VERCAUTEREN F. Homomorphic SIM D operations:Single instruction much more data[C]//Annual International Conference on the Theory and Applications of Cryptographic Techniques. Cham:Springer International Publishing,2018:338-359.
|
| 7 |
王励成, 李婧. 无噪声全同态加密浅析[J]. 密码学报, 2017, 4 (6): 579- 595.
WANG L C, LI J. Simple snalysis on noiseless fully homomorphic encryptions[J]. Journal of Cryptologic Research, 2017, 4 (6): 579- 595.
|
| 8 |
NUIDA K,KUROSAWA K. (Batch) fully homomorphic encryption over integers for non-binary message spaces[C]//Annual International Conference on the Theory and Applications of Cryptographic Techniques. Berlin,Heidelberg:Springer Berlin Heidelberg,2015:537-555.
|
| 9 |
AGARWAL R C, BURRUS C S. Number theoretic transforms to implement fast digital convolution[J]. Proceedings of the IEEE, 1975, 63 (4): 550- 560.
|
| 10 |
PANDEY M, FERNANDEZ M, GENTILE F, et al. The transformational role of GPU computing and deep learning in drug discovery[J]. Nature Machine Intelligence, 2022, 4 (3): 211- 221.
|
| 11 |
WANG W,HU Y,CHEN L,et al. Accelerating fully homomorphic encryption using GPU[C]//2012 IEEE Conference on High Performance Extreme Computing. IEEE,2012:1-5.
|
| 12 |
DAI W,DORÖZ Y,SUNAR B. Accelerating NTRU based homomorphic encryption using GPUs[C]//2014 IEEE High Performance Extreme Computing Conference (HPEC). IEEE,2014:1-6.
|
| 13 |
LEI X,GUO R,ZHANG F,et al. Accelerating homomorphic full adder based on fhew using multicore CPU and GPUS[C]//2019 IEEE 21st International Conference on High Performance Computing and Communications; IEEE 17th International Conference on Smart City; IEEE 5th International Conference on Data Science and Systems (HPCC/SmartCity/DSS). IEEE,2019:2508-2513.
|
| 14 |
BERTELS J,VAN BEIRENDONCK M,TURAN F,et al. Hardware acceleration of FHEW[C]//2023 26th International Symposium on Design and Diagnostics of Electronic Circuits and Systems (DDECS). IEEE,2023:57-60.
|
| 15 |
CHEON J H,KIM A,KIM M,et al. Homomorphic encryption for arithmetic of approximate numbers[C]//Advances in Cryptology - ASIACRYPT 2017:23rd International Conference on the Theory and Applications of Cryptology and Information Security,2017:409-437.
|
| 16 |
BRAKERSKI Z, GENTRY C, VAIKUNTANATHAN V. (Leveled) fully homomorphic encryption without bootstrapping[J]. ACM Transactions on Computation Theory (TOCT), 2014, 6 (3): 1- 36.
|
| 17 |
RIAZI M S,LAINE K,PELTON B,et al. HEAX:An architecture for computing on encrypted data[C]//Proceedings of the Twenty-fifth International Conference on Architectural Support for Programming Languages and Operating Systems,2020:1295-1309.
|
| 18 |
REAGEN B,CHOI W S,KO Y,et al. Cheetah:Optimizing and accelerating homomorphic encryption for private inference[C]//2021 IEEE International Symposium on High-Performance Computer Architecture (HPCA). IEEE,2021:26-39.
|
| 19 |
SAMARDZIC N,FELDMANN A,KRASTEV A,et al. F1:A fast and programmable accelerator for fully homomorphic encryption[C]//MICRO-54:54th Annual IEEE/ACM International Symposium on Microarchitecture,2021:238-252.
|
| 20 |
SAMARDZIC N,FELDMANN A,KRASTEV A,et al. Craterlake:A hardware accelerator for efficient unbounded computation on encrypted data[C]//Proceedings of the 49th Annual International Symposium on Computer Architecture,2022:173-187.
|
| 21 |
KIM J,LEE G,KIM S,et al. Ark:Fully homomorphic encryption accelerator with runtime data generation and inter-operation key reuse[C]//2022 55th IEEE/ACM International Symposium on Microarchitecture (MICRO). IEEE,2022:1237-1254.
|
| 22 |
JIANG L,LOU Q,JOSHI N. Matcha:A fast and energy-efficient accelerator for fully homomorphic encryption over the torus[C]// Proceedings of the 59th ACM/IEEE Design Automation Conference,2022:235-240.
|
| 23 |
VAN BEIRENDONCK M,D'ANVERS J P,TURAN F,et al. FPT:A fixed-point accelerator for torus fully homomorphic encryption[C]//Proceedings of the 2023 ACM SIGSAC Conference on Computer and Communications Security,2023:741-755.
|
| 24 |
YANG Y,ZHANG H,FAN S,et al. Poseidon:Practical homomorphic encryption accelerator [C]//2023 IEEE International Symposium on High-Performance Computer Architecture (HPCA). IEEE,2023:870-881.
|
| 25 |
ZHU Y,WANG X,JU L,et al. FxHENN:FPGA-based acceleration framework for homomorphic encrypted CNN inference[C]//2023 IEEE International Symposium on High-Performance Computer Architecture (HPCA). IEEE,2023:896-907.
|
| 26 |
BRUTZKUS A,GILAD-BACHRACH R,ELISHA O. Low latency privacy preserving inference[C]// International Conference on Machine Learning. PMLR,2019:812-821.
|
| 27 |
FAN S,WANG Z,XU W,et al. Tensorfhe:Achieving practical computation on encrypted datausing gpgpu[C]//2023 IEEE International Symposium on High Performance Computer Architecture (HPCA). IEEE,2023:922-934.
|
/
| 〈 |
|
〉 |