《云原生机密计算最佳实践白皮书》——05编程框架——Intel Homomorphic Encryption: Intel平台同态加密加速框架——Intel_HE_Toolkit开发指南(2) https://developer.aliyun.com/article/1231495?groupCode=aliyun_linux
运行示例应用
1、逻辑回归
这是一个用SEAL CKKS实现的逻辑回归推理,可以根据实际需要选择数据和模型都是密文或者其中一方是密文而另一方是明文的配置。通过传递命令行参数 --linear_regression ,也可以实现线性回归推理。
• 编译
cd he-toolkit/he-samples/examples/logistic-regression cmake -S . -B build -DSEAL_DIR=$HOME/.hekit/components/seal/v3.7.2/install/lib64/cmake/ SEAL-3.7 \ -DMicrosoft.GSL_DIR=$HOME/.hekit/components/gsl/v3.1.0/install/share/cmake/ Microsoft.GSL \ -Dzstd_DIR=$HOME/.hekit/components/zstd/v1.4.5/install/lib64/cmake/zstd \ -DHEXL_DIR=$HOME/.hekit/components/hexl/1.2.3/install/lib/cmake/hexl-1.2.3 cmake --build build
• 运行
cd build ./lr_test
• 预期输出结果
INFO: Wed Nov 2 03:21:03 2022: Loading EVAL dataset INFO: Wed Nov 2 03:21:03 2022: dataLoader: datasets/lrtest_mid_eval.csv INFO: Wed Nov 2 03:21:04 2022: Loading EVAL dataset complete Elapsed(s): 0.102 INFO: Wed Nov 2 03:21:04 2022: Input data size: (samples) 2000 (features) 80 INFO: Wed Nov 2 03:21:04 2022: Loading Model INFO: Wed Nov 2 03:21:04 2022: weightsLoader: datasets/lrtest_mid_lrmodel.csv INFO: Wed Nov 2 03:21:04 2022: Loading Model complete Elapsed(s): 0 INFO: Wed Nov 2 03:21:04 2022: Encode/encrypt weights and bias INFO: Wed Nov 2 03:21:04 2022: Encode/encrypt weights and bias complete Elapsed(s): 0.041 INFO: Wed Nov 2 03:21:04 2022: HE LR INFO: Wed Nov 2 03:21:04 2022: # of batches: 1 Batch size: 4096 INFO: Wed Nov 2 03:21:04 2022: Transpose data INFO: Wed Nov 2 03:21:04 2022: - Transpose data complete Elapsed(s): 0.005 INFO: Wed Nov 2 03:21:04 2022: Encode/encrypt data INFO: Wed Nov 2 03:21:04 2022: - Encode/encrypt data complete! Elapsed(s): 0.026 INFO: Wed Nov 2 03:21:04 2022: Logistic Regression HE: 1 batch(es) INFO: Wed Nov 2 03:21:04 2022: - LR HE complete! Elapsed(s): 0.085 INFO: Wed Nov 2 03:21:04 2022: Decrypt/decoding LRHE result INFO: Wed Nov 2 03:21:04 2022: - Decrypt/decode complete! Elapsed(s): 0.003 INFO: Wed Nov 2 03:21:04 2022: HE inference result - accuracy: 0.855
2、安全查询
这个例子演示了如何用同态加密技术(SEAL BFV scheme)实现安全数据库查询。在这个例子中,数据查询条件和数据库本身都是加密的状态。查询客户端负责初始化加密上下文、产生同态加密密钥对、加密查询条件和解密查询结果。查询服务端负责存储加密数据库,并实现加密数据库查询算法。
• 编译
cd he-toolkit/he-samples/examples/logistic-regression cmake -S . -B build -DSEAL_DIR=$HOME/.hekit/components/seal/v3.7.2/install/lib64/cmake /SEAL-3.7 \ -DMicrosoft.GSL_DIR=$HOME/.hekit/components/gsl/v3.1.0/install/share/cmake/ Microsoft.GSL \ -Dzstd_DIR=$HOME/.hekit/components/zstd/v1.4.5/install/lib64/cmake/zstd \ -DHEXL_DIR=$HOME/.hekit/components/hexl/1.2.3/install/lib/cmake/hexl-1.2.3 cmake --build build
• 运行
cd build ./secure-query
• 预期输出结果
Initialize SEAL BFV scheme with default parameters[Y(default)|N]: SEAL BFV context initialized with following parameters Polymodulus degree: 8192 Plain modulus: 17 Key length: 8 Input fifile to use for database or press enter to use default[us_state_capitals.csv]: Number of database entries: 50 Encrypting database entries into Ciphertexts Input key value to use for database query:Oregon Querying database for key: Oregon Decoded database entry: Salem Total query elapsed time(seconds): (Time in seconds for database query) Records searched per second: (number of records searched per second)
二进制包安装
除了直接通过源代码编译安装,Intel HE Toolkit即将在下一个Anolis版本中支持通过二进制包的形式安装。
参考
Intel HE Toolkit: https://github.com/intel/he-toolkit