Monday, October 26, 2020

Microsoft SEAL installation on macOS

Microsoft SEAL is an easy-to-use open-source (MIT licensed) homomorphic encryption library developed by the Cryptography and Privacy Research Group at Microsoft. Microsoft SEAL is written in modern standard C++ and is easy to compile and run in many different environments. For more information about the Microsoft SEAL project, see sealcrypto.org.


  1. brew install cmake autoconf automake libtool shtool gflags

  2. xcode-select --install

  3. git clone https://github.com/google/googletest

  4. cd googletest-master

  5. cmake .

  6. make

  7. make install

  8. git clone https://github.com/microsoft/SEAL

  9. cd SEAL

  10. cmake -S . -B build

    -- Build type (CMAKE_BUILD_TYPE): Release

    -- Microsoft SEAL debug mode: OFF

    -- SEAL_USE_CXX17: ON

    -- Removing old /Users/devharsh/Downloads/SEAL/native/src/seal/util/config.h

    -- SEAL_BUILD_DEPS: ON

    -- SEAL_USE_MSGSL: ON

    -- Microsoft GSL: download ...

    -- SEAL_USE_ZLIB: ON

    -- ZLIB: download ...

    CMake Deprecation Warning at build/thirdparty/zlib-src/CMakeLists.txt:1 (cmake_minimum_required):

      Compatibility with CMake < 2.8.12 will be removed from a future version of

      CMake.


      Update the VERSION argument <min> value or use a ...<max> suffix to tell

      CMake that the project does not need compatibility with older versions.



    -- SEAL_USE_ZSTD: ON

    -- Zstandard: download ...

    CMake Deprecation Warning at build/thirdparty/zstd-src/build/cmake/CMakeLists.txt:10 (cmake_minimum_required):

      Compatibility with CMake < 2.8.12 will be removed from a future version of

      CMake.


      Update the VERSION argument <min> value or use a ...<max> suffix to tell

      CMake that the project does not need compatibility with older versions.



    -- ZSTD VERSION: 1.4.5

    -- CMAKE_INSTALL_PREFIX: /usr/local

    -- CMAKE_INSTALL_LIBDIR: lib

    -- ZSTD_LEGACY_SUPPORT not defined!

    -- ZSTD_MULTITHREAD_SUPPORT is disabled

    -- SEAL_USE_INTEL_HEXL: OFF

    -- BUILD_SHARED_LIBS: OFF

    -- SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT: ON

    -- SEAL_USE_GAUSSIAN_NOISE: OFF

    -- SEAL_DEFAULT_PRNG: Blake2xb

    -- SEAL_AVOID_BRANCHING: OFF

    -- x86intrin.h - found

    -- SEAL_USE_INTRIN: ON

    -- SEAL_USE_MEMSET_S: ON

    -- SEAL_USE_EXPLICIT_BZERO: OFF

    -- SEAL_USE_EXPLICIT_MEMSET: OFF

    -- SEAL_BUILD_SEAL_C: OFF

    -- SEAL_BUILD_EXAMPLES: OFF

    -- SEAL_BUILD_TESTS: OFF

    -- SEAL_BUILD_BENCH: OFF

    -- Configuring done

    -- Generating done

    -- Build files have been written to: /Users/devharsh/Downloads/SEAL/build


  11. cmake --build build

    Consolidate compiler generated dependencies of target libzstd_static

    [ 37%] Built target libzstd_static

    Consolidate compiler generated dependencies of target zlibstatic

    [ 55%] Built target zlibstatic

    Consolidate compiler generated dependencies of target seal

    [100%] Built target seal

  12. sudo cmake --install build

    -- Install configuration: "Release"

    -- Installing: /usr/local/include/SEAL-4.0/seal/util/config.h

    -- Installing: /usr/local/lib/libseal-4.0.a

    -- Installing: /usr/local/lib/cmake/SEAL-4.0/SEALTargets.cmake

    -- Installing: /usr/local/lib/cmake/SEAL-4.0/SEALTargets-release.cmake

    -- Installing: /usr/local/lib/cmake/SEAL-4.0/SEALConfig.cmake

    -- Installing: /usr/local/lib/cmake/SEAL-4.0/SEALConfigVersion.cmake

    -- Up-to-date: /usr/local/include/SEAL-4.0/gsl

    -- Installing: /usr/local/include/SEAL-4.0/gsl/gsl_util

    -- Installing: /usr/local/include/SEAL-4.0/gsl/gsl_assert

    -- Installing: /usr/local/include/SEAL-4.0/gsl/span

    -- Installing: /usr/local/include/SEAL-4.0/gsl/gsl

    -- Installing: /usr/local/include/SEAL-4.0/gsl/pointers

    -- Installing: /usr/local/include/SEAL-4.0/gsl/gsl_algorithm

    -- Installing: /usr/local/include/SEAL-4.0/gsl/gsl_byte

    -- Installing: /usr/local/include/SEAL-4.0/gsl/multi_span

    -- Installing: /usr/local/include/SEAL-4.0/gsl/span_ext

    -- Installing: /usr/local/include/SEAL-4.0/gsl/string_span

    -- Installing: /usr/local/lib/pkgconfig/seal.pc

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/batchencoder.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/ciphertext.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/ckks.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/modulus.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/context.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/decryptor.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/dynarray.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/encryptionparams.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/encryptor.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/evaluator.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/galoiskeys.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/keygenerator.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/kswitchkeys.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/memorymanager.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/plaintext.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/publickey.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/randomgen.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/randomtostd.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/relinkeys.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/seal.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/secretkey.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/serializable.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/serialization.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/valcheck.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/version.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/blake2.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/blake2-impl.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/clang.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/clipnormal.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/common.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/croots.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/defines.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/dwthandler.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/fips202.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/galois.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/gcc.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/globals.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/hash.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/hestdparms.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/iterator.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/locks.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/mempool.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/msvc.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/numth.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/pointer.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/polyarithsmallmod.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/polycore.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/rlwe.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/rns.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/scalingvariant.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/ntt.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/streambuf.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/uintarith.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/uintarithmod.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/uintarithsmallmod.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/uintcore.h

    -- Up-to-date: /usr/local/include/SEAL-4.0/seal/util/ztools.h

  13. cd native/examples

  14. cmake .

    -- The CXX compiler identification is AppleClang 13.1.6.13160021

    -- Detecting CXX compiler ABI info

    -- Detecting CXX compiler ABI info - done

    -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped

    -- Detecting CXX compile features

    -- Detecting CXX compile features - done

    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD

    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success

    -- Found Threads: TRUE  

    -- Microsoft SEAL -> Version 4.0.0 detected

    -- Microsoft SEAL -> Targets available: SEAL::seal

    -- Configuring done

    -- Generating done

    -- Build files have been written to: /Users/devharsh/Downloads/SEAL/native/examples

  15. make

    [ 10%] Building CXX object CMakeFiles/sealexamples.dir/examples.cpp.o

    [ 20%] Building CXX object CMakeFiles/sealexamples.dir/1_bfv_basics.cpp.o

    [ 30%] Building CXX object CMakeFiles/sealexamples.dir/2_encoders.cpp.o

    [ 40%] Building CXX object CMakeFiles/sealexamples.dir/3_levels.cpp.o

    [ 50%] Building CXX object CMakeFiles/sealexamples.dir/4_bgv_basics.cpp.o

    [ 60%] Building CXX object CMakeFiles/sealexamples.dir/5_ckks_basics.cpp.o

    [ 70%] Building CXX object CMakeFiles/sealexamples.dir/6_rotation.cpp.o

    [ 80%] Building CXX object CMakeFiles/sealexamples.dir/7_serialization.cpp.o

    [ 90%] Building CXX object CMakeFiles/sealexamples.dir/8_performance.cpp.o

    [100%] Linking CXX executable bin/sealexamples

    [100%] Built target sealexamples

  16. cd bin

  17. ./sealexamples

    Microsoft SEAL version: 4.0.0

    +---------------------------------------------------------+

    | The following examples should be executed while reading |

    | comments in associated files in native/examples/.       |

    +---------------------------------------------------------+

    | Examples                   | Source Files               |

    +----------------------------+----------------------------+

    | 1. BFV Basics              | 1_bfv_basics.cpp           |

    | 2. Encoders                | 2_encoders.cpp             |

    | 3. Levels                  | 3_levels.cpp               |

    | 4. BGV Basics              | 4_bgv_basics.cpp           |

    | 5. CKKS Basics             | 5_ckks_basics.cpp          |

    | 6. Rotation                | 6_rotation.cpp             |

    | 7. Serialization           | 7_serialization.cpp        |

    | 8. Performance Test        | 8_performance.cpp          |

    +----------------------------+----------------------------+

    [      0 MB] Total allocation from the memory pool


    > Run example (1 ~ 8) or exit (0): 1


    +-------------------------------------+

    |         Example: BFV Basics         |

    +-------------------------------------+

    Line 132 --> Set encryption parameters and print

    /

    | Encryption parameters :

    |   scheme: BFV

    |   poly_modulus_degree: 4096

    |   coeff_modulus size: 109 (36 + 36 + 37) bits

    |   plain_modulus: 1024

    \

    Parameter validation (success): valid


    ~~~~~~ A naive way to calculate 4(x^2+1)(x+1)^2. ~~~~~~

    Line 212 --> Express x = 6 as a plaintext polynomial 0x6.

    Line 223 --> Encrypt x_plain to x_encrypted.

        + size of freshly encrypted x: 2

        + noise budget in freshly encrypted x: 55 bits

        + decryption of x_encrypted: 0x6 ...... Correct.

    Line 270 --> Compute x_sq_plus_one (x^2+1).

        + size of x_sq_plus_one: 3

        + noise budget in x_sq_plus_one: 33 bits

        + decryption of x_sq_plus_one: 0x25 ...... Correct.

    Line 300 --> Compute x_plus_one_sq ((x+1)^2).

        + size of x_plus_one_sq: 3

        + noise budget in x_plus_one_sq: 33 bits

        + decryption of x_plus_one_sq: 0x31 ...... Correct.

    Line 315 --> Compute encrypted_result (4(x^2+1)(x+1)^2).

        + size of encrypted_result: 5

        + noise budget in encrypted_result: 3 bits

    NOTE: Decryption can be incorrect if noise budget is zero.


    ~~~~~~ A better way to calculate 4(x^2+1)(x+1)^2. ~~~~~~

    Line 353 --> Generate relinearization keys.

    Line 361 --> Compute and relinearize x_squared (x^2),

                 then compute x_sq_plus_one (x^2+1)

        + size of x_squared: 3

        + size of x_squared (after relinearization): 2

        + noise budget in x_sq_plus_one: 33 bits

        + decryption of x_sq_plus_one: 0x25 ...... Correct.

    Line 376 --> Compute x_plus_one (x+1),

                 then compute and relinearize x_plus_one_sq ((x+1)^2).

        + size of x_plus_one_sq: 3

        + noise budget in x_plus_one_sq: 33 bits

        + decryption of x_plus_one_sq: 0x31 ...... Correct.

    Line 390 --> Compute and relinearize encrypted_result (4(x^2+1)(x+1)^2).

        + size of encrypted_result: 3

        + size of encrypted_result (after relinearization): 2

        + noise budget in encrypted_result: 10 bits


    NOTE: Notice the increase in remaining noise budget.

    Line 407 --> Decrypt encrypted_result (4(x^2+1)(x+1)^2).

        + decryption of 4(x^2+1)(x+1)^2 = 0x54 ...... Correct.


    Line 425 --> An example of invalid parameters

    /

    | Encryption parameters :

    |   scheme: BFV

    |   poly_modulus_degree: 2048

    |   coeff_modulus size: 109 (36 + 36 + 37) bits

    |   plain_modulus: 1024

    \

    Parameter validation (failed): parameters are not compliant with HomomorphicEncryption.org security standard


    +---------------------------------------------------------+

    | The following examples should be executed while reading |

    | comments in associated files in native/examples/.       |

    +---------------------------------------------------------+

    | Examples                   | Source Files               |

    +----------------------------+----------------------------+

    | 1. BFV Basics              | 1_bfv_basics.cpp           |

    | 2. Encoders                | 2_encoders.cpp             |

    | 3. Levels                  | 3_levels.cpp               |

    | 4. BGV Basics              | 4_bgv_basics.cpp           |

    | 5. CKKS Basics             | 5_ckks_basics.cpp          |

    | 6. Rotation                | 6_rotation.cpp             |

    | 7. Serialization           | 7_serialization.cpp        |

    | 8. Performance Test        | 8_performance.cpp          |

    +----------------------------+----------------------------+

    [      8 MB] Total allocation from the memory pool

    > Run example (1 ~ 8) or exit (0): 0

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.