2021SC@SDUSC
这一篇来分析一下
这个子模块位于
是bfv的一种特殊实现方案
先进行Enable这个函数的分析
这可以提供Enable可以配置哪些选项的相关信息
可以看到可以点出 ENCRYPTION SHE-Hash PRE MULTIPARTY
FHE LEVELEDFHE ADVANCEDFHE 则还没有被实现
如果点出这个选项会立刻抛出异常
// Enable for LPPublicKeyEncryptionSchemeBFVrnsB
template <class Element>
void LPPublicKeyEncryptionSchemeBFVrnsB<Element>::Enable(
PKESchemeFeature feature) {
switch (feature) {
case ENCRYPTION:
if (this->m_algorithmEncryption == nullptr)
this->m_algorithmEncryption =
std::make_shared<LPAlgorithmBFVrnsB<Element>>();
break;
case SHE:
if (this->m_algorithmEncryption == nullptr)
this->m_algorithmEncryption =
std::make_shared<LPAlgorithmBFVrnsB<Element>>();
if (this->m_algorithmSHE == nullptr)
this->m_algorithmSHE =
std::make_shared<LPAlgorithmSHEBFVrnsB<Element>>();
break;
case PRE:
if (this->m_algorithmEncryption == nullptr)
this->m_algorithmEncryption =
std::make_shared<LPAlgorithmBFVrnsB<Element>>();
if (this->m_algorithmSHE == nullptr)
this->m_algorithmSHE =
std::make_shared<LPAlgorithmSHEBFVrnsB<Element>>();
if (this->m_algorithmPRE == nullptr)
this->m_algorithmPRE =
std::make_shared<LPAlgorithmPREBFVrnsB<Element>>();
break;
case MULTIPARTY:
if (this->m_algorithmEncryption == nullptr)
this->m_algorithmEncryption =
std::make_shared<LPAlgorithmBFVrnsB<Element>>();
if (this->m_algorithmPRE == nullptr)
this->m_algorithmPRE =
std::make_shared<LPAlgorithmPREBFVrnsB<Element>>();
if (this->m_algorithmSHE == nullptr)
this->m_algorithmSHE =
std::make_shared<LPAlgorithmSHEBFVrnsB<Element>>();
if (this->m_algorithmMultiparty == nullptr)
this->m_algorithmMultiparty =
std::make_shared<LPAlgorithmMultipartyBFVrnsB<Element>>();
break;
case FHE:
PALISADE_THROW(not_implemented_error,
"FHE feature not supported for BFVrnsB scheme");
case LEVELEDSHE:
PALISADE_THROW(not_implemented_error,
"LEVELEDSHE feature not supported for BFVrnsB scheme");
case ADVANCEDSHE:
PALISADE_THROW(not_implemented_error,
"ADVANCEDSHE feature not supported for BFVrnsB scheme");
}
}
往下翻阅则主要的实现过程都不在这个文件内
此处的实现是调用了 LPAlgorithmPREBFV的固有能力
再来看看implement里头的内容
前面做了大量的调用提醒
告诉用户BFVRNSB不支持一些多项式类型
需要进行一个转化 这个地方应该是告诉用户先去调用其它模块里头的编码转化工具
转成特定格式后再进行输入
这些是宏定义
#define NOPOLY \
std::string errMsg = "BFVrnsB does not support Poly. Use DCRTPoly instead."; \
PALISADE_THROW(not_implemented_error, errMsg);
#define NONATIVEPOLY \
std::string errMsg = \
"BFVrnsB does not support NativePoly. Use DCRTPoly instead."; \
PALISADE_THROW(not_implemented_error, errMsg);
BFVrnsB之支持DCRTPoly
来看看主体部分 此部分起至 line:318 bfvrnsB-impl
// Precomputation of CRT tables encryption, decryption, and homomorphic
// multiplication
对于CRT加解密和同态分类的预计算
进行一个预先的演算 目的可能是为了提升之后复杂加密工作中的效率
此处特意增加了对中文的适配
检测msk是否过大
如果过大则会中止计算流程
因为会造成大于容忍的精度损失
这里的msk的设置界限为60bits
接下来仍是按照公式进行计算
return true;
最后的结果是加密是否顺利完成的标识
紧接着的是ParamgGen 至此已是634行
可见上面的CRT table 的预计算是非常复杂的一个流程
也正因如此才将这个过程当作预计算来做
从而减少进步加密和同态评估时的时间