Files
hfe_knn/writeup.md
2025-08-10 03:39:33 +08:00

35 lines
821 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 0xfa队 writeup
## 全同态加密算法介绍
加密算法方面选择了thfe算法库方面选择了较为成熟的thfe-rs算法库。
### 算法参数
使用的是默认的算法参数设置位置在src/bin/enc.rs:117
Message bits: 2位
Carry bits: 2位
噪声分布: TUniform (tweaked uniform)
Bootstrap失败概率: ≤ 2^-128 (CPU后端)
## knn算法实现细节
将欧式距离公式拆分:
> sum((a-b)^2)=sum(a^2) - sum(2a\*b) + sum(b^2)
减少了密文态的乘法和加法操作
选择上实现了双调排序将100个距离结果用最大值填充至128个结果。
然后进行并行排序,最后选择前十个密文。
两个操作都使用了rayon库做多核并行计算
## 本地测试结果
在本地i9-10920X12核24线程)情况下运行时间约9min(4min+5min)