-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add leichi algorithm to HEU #80
base: main
Are you sure you want to change the base?
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所有的代码需要 format 一下
# c++
echo 'Formatting c++ code'
find . -type f -name '*.h' -o -name '*.cc' | xargs clang-format -i
# bazel
echo 'Formatting bazel code'
buildifier -r .
do{ | ||
get_prime(key_size/2,sk->p_); | ||
get_prime(key_size/2,sk->q_); | ||
}while(sk->p_ == sk->q_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 判断 gcd(p-1 ,q-1) == 2,从而确保 n - 1 没有小因子
- 防止 square-root attacks, 需确保 p-q 是一个大整数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
namespace heu::lib::algorithms::leichi_paillier::test { | ||
class KeyGenTest : public ::testing::TestWithParam<size_t> {}; | ||
INSTANTIATE_TEST_SUITE_P(SubTest, KeyGenTest, | ||
::testing::Values(1024)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据安全要求,即使 UT 代码也不再允许出现 1024 keysize,以避免对用户产生误导
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
TEST_P(KeyGenTest, SubTest) { | ||
SecretKey sk; | ||
PublicKey pk; | ||
KeyGenerator::Generate(GetParam(), &sk, &pk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个单测啥都没测吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我把这个单测加上
|
||
namespace heu::lib::algorithms::leichi_paillier::test { | ||
|
||
class LEICHITest : public testing::Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
命名风格: LeichiTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
return BN_cmp(bn1, bn2); | ||
} | ||
|
||
TEST_F(LEICHITest, DISABLE_EncDec) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的单测为什么都 Disable 了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR提交测试时需要硬件支持,否则会failed,把单测都Disable了
}; | ||
void Deserialize(yacl::ByteContainerView in){ | ||
std::istringstream is((std::string)in); | ||
BN_bin2bn((uint8_t *)(is.str().data()), is.str().size(),n_.bn_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要先转换成 istringstream ?
std::vector<uint8_t> Tobin(T &op) | ||
{ | ||
uint32_t n_bits_len = op.numBits(); | ||
uint8_t* n_arr = new uint8_t[n_bits_len]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,不允许直接操作裸指针
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
|
||
Runtime _runtime; | ||
std::vector<Plaintext> _pts(in_cts.size()); | ||
uint8_t *ct_bytes = new uint8_t[in_cts.size()*BYTECOUNT(pk_.n_.numBits()*2)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请去掉 new
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -56,6 +56,9 @@ TEST_P(EncryptorTest, EncryptZero) { | |||
} | |||
|
|||
TEST_P(EncryptorTest, MinMaxEnc) { | |||
// if (GetParam() == SchemaType::Leichi) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没用的注释去掉吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
@@ -87,6 +89,8 @@ std::string format_as(SchemaType i); | |||
INVOKE(true, func_or_macro, ::heu::lib::algorithms::ou, ##__VA_ARGS__) \ | |||
INVOKE(ENABLE_IPCL, func_or_macro, ::heu::lib::algorithms::paillier_ipcl, ##__VA_ARGS__) \ | |||
INVOKE(true, func_or_macro, ::heu::lib::algorithms::paillier_z, ##__VA_ARGS__) \ | |||
INVOKE(true, func_or_macro, ::heu::lib::algorithms::paillier_f, ##__VA_ARGS__) \ | |||
INVOKE(ENABLE_LEICHI, func_or_macro, ::heu::lib::algorithms::leichi_paillier, ##__VA_ARGS__) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leichi_paillier 加到 elgamal 之后,顺序与SchemaType enum相同
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
} | ||
} | ||
|
||
OPERATION_TYPE Runtime::operation_trans(std::string operation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
入参类型改成 const std::string &
or std::string_view
break; | ||
case 512: | ||
count = 1; | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加 default 语句并报错
}; | ||
|
||
std::map<std::string, int> CHIP_TABLE = { | ||
{"CHIP_0", (int) std::pow(2, 15)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以用移位代替
[Feature] Add algorithm(leichi_paillier) which uses leichi to speed up Paillier