GithubHelp home page GithubHelp logo

primihub / hehub Goto Github PK

View Code? Open in Web Editor NEW
87.0 7.0 18.0 2.31 MB

HEhub is a library for homomorphic encryption and its applications, and is part of the PrimiHub project.

License: Apache License 2.0

CMake 13.78% C++ 86.22%
bgv ckks cryptography fhe fully-homomorphic-encryption homomorphic-encryption privacy-enhancing-technologies privacy-protection tfhe

hehub's Introduction

HEhub

HEhub is a library for homomorphic encryption and its applications, and is part of the PrimiHub project.

Introduction

What is homomorphic encryption?

Homomorphic encryption (HE) is a cryptographic primitive which allows computation on encrypted messages without the need of decryption or revealing of any infomation about the messages. The notion of fully homomorphic encryption (FHE) is specified by those HE schemes that allow to evaluate circuits of arbituary depth composed with any type of gates, and was first instantiated by Craig Gentry in 2009. Ever since the breakthrough of Gentry, the field of FHE has gone through years of rapid development, and has become a crucial part of state-of-the-art privacy enhancing technologies. In view of the great impact FHE technology has had on cryptography and privacy technology, the authors of papers BV11 and BGV12 about the BGV scheme were awarded Gödel Prize recently.

There are four generations of FHE schemes so far. The schemes of BFV, BGV, and CKKS are currently often applied in leveled mode, in which no bootstrapping procedure will be run and the circuits to evaluate need to be of limited depth. These schemes support SIMD evalutation natively. On the other hand, the scheme of FHEW/TFHE has practical solution of bootstrapping, which enables FHE mode natively.

Why yet another HE library?

There are several open-sourced HE libraries so far. However, the technology of homomorphic encryption is evolving continuously, and we aim to provide an easy-to-use, scalable and efficient library, so as to help developers catch up with the latest development of this field, and to faciliate further research on it. We hope that HEhub can help the cummunity to utilize and explore the future of homomorphic encryption.

HEhub currently includes the homomorphic encryption schemes BGV, CKKS, and TFHE, etc., and will further feature various schemes, frequent circuits and application interface on homomorphic encryption. As part of the PrimiHub project, HEhub is an essential tool helping us explore the field of privacy enhancing technologies.

Building and Installation

Currently the library only requires header-only third-party dependencies, which need no manual pre-installation. The library is built with CMake (>= 3.14), and tested on Linux with toolchain GCC (>= 8.0) and on MacOS with toolchain Clang (>= 12.0).

To build the library, use the following command to configure and build:

cmake -S . -B build
cmake --build build

To install the library, run the following command:

sudo cmake --install build

Usage

The usage of homomorphic encryption with HEhub is very simple. Below is an example computing the Basel series with the CKKS scheme.

#include "fhe/ckks/ckks.h"
#include <cmath>
#include <iostream>

using namespace hehub;

int main() {
    int precision_bits = 30;
    auto params = ckks::create_params(4096, precision_bits);
    CkksSk sk(params);
    auto relin_key = get_relin_key(sk, params.additional_mod);

    CkksCt ct_sum;
    for (int i = 1; i <= 100000; i++) {
        auto pt = ckks::encode(1.0 / i, params);
        auto ct = ckks::encrypt(pt, sk);
        auto ct_squared = ckks::mult(ct, ct, relin_key);

        if (i == 1) {
            ct_sum = ct_squared;
        } else {
            ct_sum = ckks::add(ct_sum, ct_squared);
        }
    }

    double sum = ckks::decode(ckks::decrypt(ct_sum, sk));
    std::cout << "(" << sum << ", " << M_PI * M_PI / 6 << ")" << std::endl;
}

Benchmarks

We tested the performance of HEhub compiled with Clang-12.0.5 and run on an Intel i7-9750H @ 2.60GHz. Note: The code for benchmark is still incomplete since our effort is limited currently. We will list more benchmark results later.

parameter set NTT INTT CKKS
encode +
encrypt
CKKS
decrypt +
decode
N = 1024 7 us 9 us
N = 2048 14 us 19 us
N = 4096 30 us 37 us 426 us 237 us
N = 8192 68 us 85 us 1.730 ms 842 us
N = 16384 142 us 195 us 6.776 ms 3.824 ms
N = 32768 330 us 406 us 27.414 ms 18.623 ms

How to contribute

If you want to contribute to this project, feel free to create an issue at our Issue page (e.g., documentation, new idea and proposal).

Also, you can learn about our community PrimiHub Open Source Community Governance

This is an active open source project for everyone, and we are always open to everyone who want to use this system or contribute to it.

Community

wechat_helper

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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hehub's Issues

示例程序编译失败

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

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

编译错误 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"找不到的错误。

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加密方案。我不清楚是不是我的代码有问题。感谢!

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

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

运行了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.