Convert Figma logo to code with AI

homenc logoHElib

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.

3,129
765
3,129
176

Top Related Projects

3,519

Microsoft SEAL is an easy-to-use and powerful homomorphic encryption library.

Concrete: TFHE Compiler that converts python programs into FHE equivalent

An FHE compiler for C++

Quick Overview

HElib is an open-source software library that implements homomorphic encryption (HE). It provides a set of tools for performing computations on encrypted data without decrypting it, ensuring privacy and security in various applications. HElib is primarily written in C++ and supports both the Brakerski-Gentry-Vaikuntanathan (BGV) and the Cheon-Kim-Kim-Song (CKKS) schemes.

Pros

  • Implements advanced homomorphic encryption schemes (BGV and CKKS)
  • Provides a comprehensive set of tools for secure computation on encrypted data
  • Actively maintained and regularly updated
  • Offers extensive documentation and examples for users

Cons

  • Steep learning curve due to the complexity of homomorphic encryption
  • Performance can be slow for large-scale computations
  • Requires significant computational resources for complex operations
  • Limited support for high-level programming languages

Code Examples

  1. Initializing the BGV scheme:
#include <helib/helib.h>

int main() {
    long m = 4095;
    long p = 2;
    long r = 1;
    long bits = 500;
    long c = 2;

    helib::Context context = helib::ContextBuilder<helib::BGV>()
        .m(m).p(p).r(r).bits(bits).c(c).build();
    helib::SecKey secret_key(context);
    secret_key.GenSecKey();
    const helib::PubKey& public_key = secret_key;
}
  1. Encrypting and decrypting data:
#include <helib/helib.h>

int main() {
    // Assume context and keys are set up as in the previous example
    helib::Ptxt<helib::BGV> plaintext(context);
    plaintext.random();

    helib::Ctxt ciphertext(public_key);
    public_key.Encrypt(ciphertext, plaintext);

    helib::Ptxt<helib::BGV> decrypted_result(context);
    secret_key.Decrypt(decrypted_result, ciphertext);
}
  1. Performing homomorphic addition:
#include <helib/helib.h>

int main() {
    // Assume context and keys are set up as in the previous examples
    helib::Ptxt<helib::BGV> plaintext1(context), plaintext2(context);
    plaintext1.random();
    plaintext2.random();

    helib::Ctxt ciphertext1(public_key), ciphertext2(public_key);
    public_key.Encrypt(ciphertext1, plaintext1);
    public_key.Encrypt(ciphertext2, plaintext2);

    ciphertext1 += ciphertext2; // Homomorphic addition

    helib::Ptxt<helib::BGV> result(context);
    secret_key.Decrypt(result, ciphertext1);
}

Getting Started

To get started with HElib:

  1. Clone the repository:

    git clone https://github.com/homenc/HElib.git
    
  2. Install dependencies (on Ubuntu):

    sudo apt-get install cmake libgmp-dev libntl-dev
    
  3. Build HElib:

    cd HElib
    mkdir build
    cd build
    cmake ..
    make
    sudo make install
    
  4. Include HElib in your C++ project and link against the library when compiling.

Competitor Comparisons

3,519

Microsoft SEAL is an easy-to-use and powerful homomorphic encryption library.

Pros of SEAL

  • Easier to use and more beginner-friendly
  • Better documentation and examples
  • More active development and frequent updates

Cons of SEAL

  • Limited support for advanced FHE operations
  • Less flexible for customization and research purposes

Code Comparison

SEAL

Encryptor encryptor(context, public_key);
Ciphertext encrypted;
encryptor.encrypt(plaintext, encrypted);

HElib

Ctxt encrypted(publicKey);
publicKey.Encrypt(encrypted, plaintext);

Summary

SEAL is more user-friendly and well-documented, making it a better choice for beginners and industry applications. It has a more active development cycle, ensuring regular updates and improvements.

HElib, on the other hand, offers more advanced FHE operations and greater flexibility for research and customization. It provides a wider range of cryptographic primitives and allows for more fine-grained control over the underlying algorithms.

The code comparison shows that SEAL has a slightly more intuitive syntax, with separate objects for encryption and key management. HElib's approach is more compact but may require a deeper understanding of the library's structure.

Both libraries have their strengths, and the choice between them depends on the specific requirements of the project and the user's expertise in homomorphic encryption.

Concrete: TFHE Compiler that converts python programs into FHE equivalent

Pros of Concrete

  • More user-friendly and accessible for developers new to FHE
  • Focuses on practical applications and performance optimization
  • Provides higher-level abstractions for easier implementation

Cons of Concrete

  • Less mature and battle-tested compared to HElib
  • May have a more limited range of supported cryptographic schemes
  • Potentially less flexible for advanced users requiring fine-grained control

Code Comparison

HElib example:

#include <helib/helib.h>

void example() {
    Context context = helib::ContextBuilder<helib::BGV>().m(4095).bits(500).build();
    SecKey secret_key(context);
    secret_key.GenSecKey();
    const PubKey& public_key = secret_key;
}

Concrete example:

use concrete::*;

fn example() -> Result<(), CryptoAPIError> {
    let (client_key, server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2_KS_PBS);
    let clear = 42;
    let cipher = client_key.encrypt(clear);
    Ok(())
}

The code examples demonstrate that Concrete offers a more straightforward API with higher-level abstractions, while HElib provides more detailed control over the cryptographic parameters. Concrete's Rust implementation may also appeal to developers seeking memory safety and modern language features.

An FHE compiler for C++

Pros of fully-homomorphic-encryption

  • Easier to use and more accessible for beginners
  • Provides a higher-level abstraction for FHE operations
  • Offers integration with TensorFlow for machine learning applications

Cons of fully-homomorphic-encryption

  • Less mature and less extensively tested compared to HElib
  • More limited in terms of advanced FHE features and optimizations
  • Smaller community and fewer resources available

Code Comparison

HElib:

#include <helib/helib.h>

Ctxt encrypted_result(publicKey);
encrypted_result.addCtxt(ciphertext1);
encrypted_result.multByConstant(5);

fully-homomorphic-encryption:

import numpy as np
from fully_homomorphic_encryption import tfhe

encrypted_result = tfhe.add(ciphertext1, tfhe.scalar_mul(5, ciphertext2))

Summary

HElib is a more established and feature-rich library for homomorphic encryption, offering advanced optimizations and a wider range of FHE operations. It's better suited for experienced developers and researchers working on complex FHE applications.

fully-homomorphic-encryption, on the other hand, provides a more user-friendly approach with its integration with TensorFlow and higher-level abstractions. It's ideal for developers who want to experiment with FHE in machine learning contexts or those new to homomorphic encryption.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

HElib

Build and Test

HElib is an open-source (Apache License v2.0) software library that implements homomorphic encryption (HE). Currently available schemes are the implementations of the Brakerski-Gentry-Vaikuntanathan (BGV) scheme with bootstrapping and the Approximate Number scheme of Cheon-Kim-Kim-Song (CKKS), along with many optimizations to make homomorphic evaluation run faster, focusing mostly on effective use of the Smart-Vercauteren ciphertext packing techniques and the Gentry-Halevi-Smart optimizations. See this report for a description of a few of the algorithms using in this library.

Please refer to CKKS-security.md for the latest discussion on the security of the CKKS scheme implementation in HElib.

Since mid-2018 HElib has been under extensive refactoring for Reliability, Robustness & Serviceability, Performance, and most importantly Usability for researchers and developers working on HE and its uses.

HElib supports an "assembly language for HE", providing low-level routines (set, add, multiply, shift, etc.), sophisticated automatic noise management, improved BGV bootstrapping, multi-threading, and also support for Ptxt (plaintext) objects which mimics the functionality of Ctxt (ciphertext) objects. The report Design and implementation of HElib contains additional details. Also, see CHANGES.md for more information on the HElib releases.

Full installation instructions and a list of the required dependencies can be found in INSTALL.md.

For guidance in getting started programming with HElib, take a look at the example programs and our CKKS tutorials located in the examples directory. See examples/README.md.

If you are interested in contributing to HElib, please read our Contributing Guidelines.

HElib is written in C++17 and uses the NTL mathematical library.
HElib is distributed under the terms of the Apache License v2.0.