homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.12k stars 763 forks source link

Help running HElib on Windows 10 #220

Closed PhantomR closed 1 year ago

PhantomR commented 6 years ago

I'm trying to run HElib on Windows 10 x64. I compiled NTL using Visual Studio 2017 (I had to disable error 4146 and set preprocessor define _CRT_SECURE_NO_WARNINGS for it to compile successfully). Then I compiled HElib, but this required quite a bit of tinkering:

Still, I could not get the binaryArith test to pass.. NTL and HElib were properly linked to the Visual Studio project running the test, but the program somehow enters the bootstrapping part of the function 'addTwoNumbers' and fails upon reaching the assertion in 'packedRecrypt'. I assume it should not go into the boostrapping part since bootstrapping is disabled for this test as far as I'm aware and the test runs just fine on Linux.

IMPORTANT NOTE: I really need to make this work on Windows since my CPU semmingly has some known segmentation fault issues on Linux (things 'randomly' segfault..) .... I tried Cygwin, but although the test passes, it still seems to somehow have some segfault problems itself, not to mention it seems to actually be quite slow. I'd really like to make HElib run natively on Windows. Thank you!

fionser commented 6 years ago

Have you try to use cmake ?

PhantomR commented 6 years ago

Thank you for the advice. I just tried building it with cmake. However, it still required the same modifications (it tries to load tr1 STL libraries instead of the usual ones (e.g tr1/memory instead of memory etc.) and the binaryArith test still fails: testAdd passes (pretty sure it did before as well), but in the multiplication test it tries to bootstrap for some unknown reason and crashes since bootstrapping is disabled in that test... So, sadly, I reached the same result :(.

fionser commented 6 years ago
PhantomR commented 6 years ago

Which flags exactly :)? Maybe -std=c++0x?

fionser commented 6 years ago

@PhantomR c++0x was too old, try to use std=c++11

shaih commented 6 years ago

If I remember correctly, long is defined as 32-bit integers on Windows. If this is the case, then it is very unlikely that you will get HElib to work in any reasonable way. We never seriously tested HElib in such environments, and there are many places in the code where we use 'long' and expect it to be large enough to allow some algebraic structures that we need, which may not hold for 32-bit numbers.

You should be able to compile everything, I think, once you have the right compiler flags (certainly std=c++11). But I expect that once you try to run things, you'll see some assertions triggered.

shaih commented 6 years ago

Your best bet of being able to use it with 32-bit 'long' is to use the pre-processor directive -DNO_HALF_SIZE_PRIME

PhantomR commented 6 years ago

Thank you both very much !!! I'm going to give it a try (though I don't know if I'll be able to do it very soon) and report back. Still, I'd like to suggest something: I do not know if Windows portability is actually seen as important for HElib, but couldn't a typedef be used instead of long, allowing for easy change on different OSs (manual/automatic)? This is actually my first time I see a good use for something like this, although I've seen things like 'int32, int64' before. I did not even know long was 32-bit on Windows, but that seems to be the case (confirmed by Microsoft's website).