Giter Club home page Giter Club logo

hehub's Introduction

Header

由密码学专家团队打造的开源隐私计算平台

GitHub Release Build Status Docker Pulls

中文 | English

隐私计算

数据流动起来才可以创造更大的价值,随着数字经济持续高速增长,数据的互联互通需求越来越旺盛,大到政府机关的机密数据、公司核心商业数据、小到个人信息。近两年,我国也相继出台了 《数据安全法》《个人信息保护法》。因此,如何让数据安全地流通起来,是一个必须要解决的问题

隐私计算技术作为连接数据流通和隐私保护法规的纽带,实现了 “数据可用不可见”。即在保护数据本身不对外泄露的前提下实现数据分析计算的技术集合。隐私计算作为数据流通的重要创新前沿技术,已经广泛应用于金融、医疗、通信、政务等多个行业。

PrimiHub

如果你对隐私计算感兴趣,想近距离体验下隐私计算的魅力,不妨试试 PrimiHub!一款由密码学专家团队打造的开源隐私计算平台,它安全可靠、开箱即用、自主研发、功能丰富。

特性

  • 开源:完全开源、免费
  • 安装简单:支持 Docker 一键部署
  • 开箱即用:拥有 Web界面命令行Python SDK 多种使用方式
  • 功能丰富:支持隐匿查询、隐私求交、联合统计、数据资源管理等功能
  • 灵活配置:支持自定义扩展语法、语义、安全协议等
  • 自主研发:基于安全多方计算、联邦学习、同态加密、可信计算等隐私计算技术

快速开始

推荐使用 Docker 部署 PrimiHub,开启你的隐私计算之旅。

# 第一步:下载
git clone https://github.com/primihub/primihub.git
# 第二步:启动容器
cd primihub && docker-compose up -d
# 第三步:进入容器
docker exec -it primihub-node0 bash
# 第四步:执行隐私求交计算
./primihub-cli --task_config_file="example/psi_ecdh_task_conf.json"
I20230616 13:40:10.683375    28 cli.cc:524] all node has finished
I20230616 13:40:10.683745    28 cli.cc:598] SubmitTask time cost(ms): 1419
# 查看结果
cat data/result/psi_result.csv
"intersection_row"
X3
...

PSI

隐私求交例子 在线尝试命令行

除此之外,PrimiHub 还提供了多种适合不同人群的使用方式:

问题 / 帮助 / Bug

如果您在使用过程中遇到任何问题,需要我们的帮助可以 点击 反馈问题。

欢迎添加我们的微信助手,加入「PrimiHub 开源社区」微信群。“零距离”接触项目核心开发、密码学专家、隐私计算行业大咖,获得更及时的回复和隐私计算的第一手资讯。

Header

许可证

此代码在 Apache 2.0 下发布,参见 LICENSE 文件。

hehub's People

Contributors

ppppbamzy avatar yankaili2006 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hehub's Issues

bgv方案乘法同态问题

bgv方案计算密文乘法出现错误,计算密文状态下的0*1,结果为28733。代码如下:

#include "fhe/bgv/bgv.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <bitset>

using namespace hehub;


int main() {
    // 设置BGV加密环境
    std::vector<u64> ct_moduli{131530753, 130809857}; // 示例模数
    size_t dimension = 1;
    RnsPolyParams ct_params{dimension, ct_moduli.size(), ct_moduli};
    RlweSk sk(ct_params);

    u64 pt_modulus = 65537; // 示例明文模数
    RnsPolyParams pt_params{dimension, 1, std::vector{pt_modulus}};
    
    // 生成重线性化密钥
    u64 additional_mod = 131923969; // 额外模数
    auto relin_key = get_relin_key(sk, additional_mod);

    auto data_count = dimension;
    std::vector<u64> plain_data1(data_count);
    std::vector<u64> plain_data2(data_count);
    u64 seed = 1;
    for (auto &d : plain_data1) {
        d = (seed++) % 2;
    }
    for (auto &d : plain_data2) {
        d = (seed++) % 2;
    }
    for (int i = 0; i < dimension; i++) {
        std::cout<<"plain_data1:"<<plain_data1[i]<<" ";
    }
    std::cout<<std::endl;
     for (int i = 0; i < dimension; i++) {
        std::cout<<"plain_data2:"<<plain_data2[i]<<" ";
    }
    std::cout<<std::endl;
    
    // encode
    auto pt1 = bgv::simd_encode(plain_data1, pt_modulus);
    auto pt2 = bgv::simd_encode(plain_data2, pt_modulus);

    // encrypt & arith
    auto ct1 = bgv::encrypt(pt1, sk);
    auto ct2 = bgv::encrypt(pt2, sk);
    auto ct_prod_quadratic = bgv::mult_low_level(ct1, ct2);
    auto ct_prod = bgv::relinearize(ct_prod_quadratic, relin_key);

    // decrypt
    auto prod_decrypted = bgv::decrypt(ct_prod, sk);
    auto prod_data = bgv::simd_decode(prod_decrypted);

    // check
    for (size_t i = 0; i < data_count; i++) {
        std::cout<<"prod_data"<<i+1<<":"<<prod_data[i]<<std::endl;
    }

    return 0;
}

下面是运行结果:

plain_data1:1
plain_data2:0
prod_data1:28733

因为我需要在同态加密的情况下计算乘法和加法,所以我选择了bgv加密方案。我不清楚是不是我的代码有问题。感谢!

Cmake 报错

再执行cmake --build build 报错如下:
^~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/range/ac
cess.hpp:182:36: note: 'ranges::::begin'
RANGES_DEFINE_CPO(begin::fn, begin)
^~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/detail/c
onfig.hpp:601:31: note: in definition of macro 'RANGES_DEFINE_CPO'
inline constexpr type name{};
^~~~
In file included from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/view/all.hpp:22,
from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/view/zip.hpp:27,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\m
od_arith.h:8,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\r
ns.cpp:2:
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/range/ac
cess.hpp:85:14: note: 'ranges::begin::begin'
void begin(std::initializer_list) = delete;
^~~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:106:20: error:
'end' was not declared in this scope
for (auto &m : moduli_doubled) {
^~~~~~~~~~~~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:106:20: note: s
uggested alternatives:
In file included from D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/
gcc/x86_64-w64-mingw32/8.1.0/include/c++/string:51,
from D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/
gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_classes.h:40,
from D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/
gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/ios_base.h:41,
from D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/
gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:42,
from D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/
gcc/x86_64-w64-mingw32/8.1.0/include/c++/istream:38,
from D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/
gcc/x86_64-w64-mingw32/8.1.0/include/c++/sstream:38,
from D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/
gcc/x86_64-w64-mingw32/8.1.0/include/c++/complex:45,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\t
ype_defs.h:8,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\a
llocator.h:3,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\r
ns.h:8,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\r
ns.cpp:1:
D:/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32
/8.1.0/include/c++/bits/range_access.h:107:37: note: 'std::end'
template const Tp* end(const valarray<Tp>&);
^~~
In file included from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/view/all.hpp:22,
from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/view/zip.hpp:27,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\m
od_arith.h:8,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\r
ns.cpp:2:
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/range/ac
cess.hpp:197:14: note: 'ranges::end::end'
void end(std::initializer_list) = delete;
^~~
In file included from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/range_fwd.hpp:25,
from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/view/zip.hpp:22,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\m
od_arith.h:8,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\r
ns.cpp:2:
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/range/ac
cess.hpp:313:34: note: 'ranges::
::end'
RANGES_DEFINE_CPO(end::fn, end)
^~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/detail/c
onfig.hpp:601:31: note: in definition of macro 'RANGES_DEFINE_CPO'
inline constexpr type name{};
^~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/range/ac
cess.hpp:313:34: note: 'ranges::
::end'
RANGES_DEFINE_CPO(end::fn, end)
^~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/detail/c
onfig.hpp:601:31: note: in definition of macro 'RANGES_DEFINE_CPO'
inline constexpr type name{};
^~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:111:17: error:
no match for 'operator[]' (operand types are 'hehub::RnsIntVec' and 'size_t' {ak
a 'long long unsigned int'})
self[k][i] += moduli_doubled[k] - b[k][i];
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:111:43: error:
invalid types 'int[size_t {aka long long unsigned int}]' for array subscript
self[k][i] += moduli_doubled[k] - b[k][i];
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:111:48: error:
no match for 'operator[]' (operand types are 'const hehub::RnsIntVec' and 'size
t' {aka 'long long unsigned int'})
self[k][i] += moduli_doubled[k] - b[k][i];
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:112:17: error:
no match for 'operator[]' (operand types are 'hehub::RnsIntVec' and 'size_t' {ak
a 'long long unsigned int'})
self[k][i] -=
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:113:22: error:
no match for 'operator[]' (operand types are 'hehub::RnsIntVec' and 'size_t' {ak
a 'long long unsigned int'})
(self[k][i] >= moduli_doubled[k]) ? moduli_doubled[k] : 0;
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:113:48: error:
invalid types 'int[size_t {aka long long unsigned int}]' for array subscript
(self[k][i] >= moduli_doubled[k]) ? moduli_doubled[k] : 0;
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:113:69: error:
invalid types 'int[size_t {aka long long unsigned int}]' for array subscript
(self[k][i] >= moduli_doubled[k]) ? moduli_doubled[k] : 0;
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp: In function 'h
ehub::RnsIntVec hehub::operator*(const hehub::RnsIntVec&, const hehub::RnsIntVec
&)':
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:127:12: error:
request for member 'resize' in 'moduli', which is of non-class type 'int'
moduli.resize(components);
^~~~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:128:14: error:
request for member 'resize' in 'b_moduli', which is of non-class type 'int'
b_moduli.resize(components);
^~~~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:135:45: error:
invalid types 'int[size_t {aka long long unsigned int}]' for array subscript
batched_mul_mod_hybrid_lazy(moduli[k], dimension, a[k].data(),
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:135:60: error:
no match for 'operator[]' (operand types are 'const hehub::RnsIntVec' and 'size_
t' {aka 'long long unsigned int'})
batched_mul_mod_hybrid_lazy(moduli[k], dimension, a[k].data(),
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:136:38: error:
no match for 'operator[]' (operand types are 'const hehub::RnsIntVec' and 'size_
t' {aka 'long long unsigned int'})
b[k].data(), result[k].data());
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:136:56: error:
no match for 'operator[]' (operand types are 'hehub::RnsIntVec' and 'size_t' {ak
a 'long long unsigned int'})
b[k].data(), result[k].data());
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp: At global scop
e:
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:142:52: error:
'u64' does not name a type
const RnsIntVec &operator*=(RnsIntVec &self, const u64 small_scalar) {
^~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp: In function 'c
onst hehub::RnsIntVec& hehub::operator*=(hehub::RnsIntVec&, int)':
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:144:39: error:
invalid types 'int[size_t {aka long long unsigned int}]' for array subscript
auto curr_mod = self.moduli_[k];
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:147:32: error:
no match for 'operator[]' (operand types are 'hehub::RnsIntVec' and 'size_t' {ak
a 'long long unsigned int'})
for (auto &coeff : self[k]) {
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:148:21: error:
'mul_mod_harvey_lazy' was not declared in this scope
coeff = mul_mod_harvey_lazy(curr_mod, coeff, scalar_reduced,
^~~~~~~~~~~~~~~~~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:148:21: note: s
uggested alternative: 'batched_barrett_lazy'
coeff = mul_mod_harvey_lazy(curr_mod, coeff, scalar_reduced,
^~~~~~~~~~~~~~~~~~~
batched_barrett_lazy
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp: At global scop
e:
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:156:47: error:
'u64' was not declared in this scope
const std::vector &rns_scalar) {
^~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:156:50: error:
template argument 1 is invalid
const std::vector &rns_scalar) {
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:156:50: error:
template argument 2 is invalid
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp: In function 'c
onst hehub::RnsIntVec& hehub::operator*=(hehub::RnsIntVec&, const int&)':
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:157:20: error:
request for member 'size' in 'rns_scalar', which is of non-class type 'const int
'
if (rns_scalar.size() != self.component_count()) {
^~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:162:39: error:
invalid types 'int[size_t {aka long long unsigned int}]' for array subscript
auto curr_mod = self.moduli_[k];
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:163:43: error:
invalid types 'const int[size_t {aka long long unsigned int}]' for array subscri
pt
auto scalar_reduced = rns_scalar[k] % curr_mod; // need opt?
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:165:32: error:
no match for 'operator[]' (operand types are 'hehub::RnsIntVec' and 'size_t' {ak
a 'long long unsigned int'})
for (auto &coeff : self[k]) {
^
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:166:21: error:
'mul_mod_harvey_lazy' was not declared in this scope
coeff = mul_mod_harvey_lazy(curr_mod, coeff, scalar_reduced,
^~~~~~~~~~~~~~~~~~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:166:21: note: s
uggested alternative: 'batched_barrett_lazy'
coeff = mul_mod_harvey_lazy(curr_mod, coeff, scalar_reduced,
^~~~~~~~~~~~~~~~~~~
batched_barrett_lazy
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp: In function 's
td::ostream& hehub::operator<<(std::ostream&, const hehub::RnsIntVec&)':
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:179:58: error:
no match for call to '(const ranges::views::zip_fn) (const hehub::RnsIntVec&, co
nst int&)'
for (auto [component, modulus] : zip(rns_poly, moduli)) {
^
In file included from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\m
od_arith.h:8,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\r
ns.cpp:2:
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/view/zip
.hpp:133:48: note: candidate: 'constexpr ranges::empty_view<std::tuple<> > range
s::views::zip_fn::operator()() const'
constexpr empty_view<std::tuple<>> operator()() const noexcept
^~~~~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/view/zip
.hpp:133:48: note: candidate expects 0 arguments, 2 provided
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/view/zip
.hpp:141:38: note: candidate: 'template<class ... Rngs, bool CPP_true, typename
std::enable_if<(and_v<viewable_range...> && CPP_true), int>::type , typename std::enable_if<(and_v<input_range...> && CPP_true), int>::ty
pe , typename std::enable_if<((sizeof... (Rngs) != 0) && CPP_true), i
nt>::type > ranges::zip_view<ranges::views::all_t...> ranges::
views::zip_fn::operator()(Rngs&& ...) const'
zip_view<all_t...> operator()(Rngs &&... rngs) const
^~~~~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/view/zip
.hpp:141:38: note: template argument deduction/substitution failed:
In file included from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/range_fwd.hpp:22,
from D:/test/hehub/hehub-develop/hehub-develop/third-party/rang
e-v3/range/v3/view/zip.hpp:22,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\m
od_arith.h:8,
from D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\r
ns.cpp:2:
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/concepts/concepts
.hpp:334:35: error: no type named 'type' in 'struct std::enable_if<false, int>'
&& CPP_BOOL(CPP_true), int> = 0, std::enable_if_t<
^
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/concepts/concepts
.hpp:66:35: note: in definition of macro 'CPP_PP_CAT_'
#define CPP_PP_CAT_(X, ...) X ## VA_ARGS
^~~~~~~~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/concepts/concepts
.hpp:299:9: note: in expansion of macro 'CPP_PP_CAT'
CPP_PP_CAT(CPP_TEMPLATE_SFINAE_AUX_3_, VA_ARGS) &&

^~~~~~~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/concepts/concepts
.hpp:66:30: note: in expansion of macro 'CPP_TEMPLATE_SFINAE_AUX_0'
#define CPP_PP_CAT_(X, ...) X ## VA_ARGS
^
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/concepts/concepts
.hpp:270:27: note: in expansion of macro 'CPP_TEMPLATE_SFINAE_AUX_'
#define CPP_TEMPLATE_AUX_ CPP_TEMPLATE_SFINAE_AUX_
^~~~~~~~~~~~~~~~~~~~~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/concepts/concepts
.hpp:195:17: note: in expansion of macro 'CPP_and_sfinae'
#define CPP_and CPP_and_sfinae
^~~~~~~~~~~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/detail/p
rologue.hpp:37:13: note: in expansion of macro 'CPP_and'
#define AND CPP_and
^~~~~~~
D:/test/hehub/hehub-develop/hehub-develop/third-party/range-v3/range/v3/view/zip
.hpp:138:57: note: in expansion of macro 'AND'
requires and_v<viewable_range...> AND
^~~
D:\test\hehub\hehub-develop\hehub-develop\src\fhe\common\rns.cpp:181:34: error:
unable to deduce 'auto&&' from 'component'
for (const auto &coeff : component) {
^~~~~~~~~
mingw32-make.exe[2]: *** [src\fhe\CMakeFiles\hehub.dir\build.make:76: src/fhe/CM
akeFiles/hehub.dir/common/rns.cpp.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:273: src/fhe/CMakeFiles/hehub.dir
/all] Error 2
mingw32-make.exe: *** [Makefile:135: all] Error 2

示例程序编译失败

jiang@jiang-virtual-machine:~/hehub/examples$ g++ -Wall -g -o ckks ckks_example.cpp
In file included from ckks_example.cpp:1:
/usr/local/include/fhe/ckks/ckks.h: In function ‘hehub::ckks::CkksPt hehub::ckks::encode(hehub::cc_double, const hehub::ckks::CkksParams&)’:
/usr/local/include/fhe/ckks/ckks.h:124:17: error: missing template arguments before ‘datum_rep’
  124 |     std::vector datum_rep(pt_params.dimension / 2, datum);
      |                 ^~~~~~~~~
/usr/local/include/fhe/ckks/ckks.h:125:24: error: ‘datum_rep’ was not declared in this scope
  125 |     return simd_encode(datum_rep, pt_params);
      |                        ^~~~~~~~~
/usr/local/include/fhe/ckks/ckks.h: In function ‘hehub::ckks::CkksPt hehub::ckks::encode(double, const hehub::ckks::CkksParams&)’:
/usr/local/include/fhe/ckks/ckks.h:137:17: error: missing template arguments before ‘datum_rep’
  137 |     std::vector datum_rep(pt_params.dimension / 2, datum);
      |                 ^~~~~~~~~
/usr/local/include/fhe/ckks/ckks.h:138:24: error: ‘datum_rep’ was not declared in this scope
  138 |     return simd_encode(datum_rep, pt_params);
      |                        ^~~~~~~~~

变量初始化问题,vector似乎没法做到double类型和cc_double类型共同初始化一个vector

inline CkksPt encode(const cc_double datum, const CkksParams &pt_params) {
    std::vector datum_rep(pt_params.dimension / 2, datum);
    return simd_encode(datum_rep, pt_params);
}

密钥问题与乘法同态问题

问题1 密钥是用的对称密钥吗?我看加密和解密都是同一个密钥。
问题2 乘法同态计算错误,代码如下:

int precision_bits = 30;
auto params = ckks::create_params(4096, precision_bits);
std::cout << "(params:" << params << std::endl;
CkksSk sk(params);
auto relin_key = get_relin_key(sk, params.additional_mod);

auto text11 = ckks::encode(text1 , params);
auto textC1 = ckks::encrypt(text11, sk);

auto text22 = ckks::encode(text2 , params);
auto textC2 = ckks::encrypt(text22, sk);

auto text2_sub_c = ckks::sub(textC1, textC2);
double text2_sub = ckks::decode(ckks::decrypt(text2_sub_c, sk));
std::cout << "text1 - text2:" << text2_sub << std::endl;

CkksCt text_sum_c = ckks::add(textC1,textC2);
double text_sum = ckks::decode(ckks::decrypt(text_sum_c, sk));
std::cout << "text1 + text2:" << text_sum << std::endl;

CkksCt text_mult_c = ckks::mult_plain(textC1,text22);
double text_mult = ckks::decode(ckks::decrypt(text_mult_c, sk));
std::cout << "text1 * text2:" << text_mult << std::endl;

入参:
text1 = 100,text2=300
结果:
text1 - text2:-200
text1 + text2:400
text1 * text2:-200.531

编译错误 basics.cpp

image

/home/wsk/code/hehub/src/fhe/ckks/basics.cpp: In function ‘std::vector<std::complex<double> > hehub::ckks::simd_decode_cc(const hehub::ckks::CkksPt&, size_t)’: /home/wsk/code/hehub/src/fhe/ckks/basics.cpp:300:76: error: class template argument deduction failed: vector rest_moduli(pt.modulus_vec().begin() + 1, pt.modulus_vec().end()); ^ /home/wsk/code/hehub/src/fhe/ckks/basics.cpp:300:76: error: no matching function for call to ‘vector(__gnu_cxx::__normal_iterator<const long unsigned int*, std::vector<long unsigned int> >, std::vector<long unsigned int>::const_iterator)’ In file included from /usr/include/c++/7/vector:64:0, from /home/wsk/code/hehub/src/fhe/commo

install 失败

hehub-1
根据 Readme ,我在 install 的时候只有这个输出,cmakelist中的后续部分都没有执行。
在测试 test.cpp 的时候,也会出现“ckks/ckks.h"找不到的错误。

样例巴塞尔问题程序计算的同态计算结果与明文计算结果不一致

按照配置要求完成了环境部署后

运行了build/examples/ckks_example可执行程序

设置循环50次

代码如下

image

运行结果如下

可以看到结果的密文计算和明文计算的结果并不相等

image

为了便于查看中间结果

打印for循环过程中的各个同态乘法运算结果

加入如下代码

image

结果如下

image

可以看到,对于特定的一部分i,运算结果存在问题

即便是同一个i=2,运算执行多次,结果也会不一样

测试代码如下

image

结果如下

image

同样的计算,第二次的计算结果和其他三次差异很大


不确定是我的代码使用存在问题,还是库函数中部分代码存在问题

有矩阵乘的example吗?

CNN或者简单的mnist深度学习例子实现;微软的py-seal已经玩过,Python接口兼容到了pytorch里面,宜用性很好

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.