Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElixirPHE

ElixirPHE is a pure Elixir library for experimenting with homomorphic encryption on integer vectors (also supports floating-point numbers with fixed-point scaling). It offers a single, consistent API over multiple cryptosystems, with clear separation between additive and multiplicative homomorphism. The project is designed to stay on the BEAM runtime only: no NIF-based custom crypto code is required.

Different homomorphic schemes support different algebraic operations. In practice, that means your encrypted workflow depends on the scheme:

  • additive schemes let you add encrypted values
  • multiplicative schemes let you multiply encrypted values

ElixirPHE wraps this in one interface and rejects unsupported operations at runtime with explicit errors. A notable potential use of the library is to implement a private vector store, where homomorphically encrypted vectors can still undergo computation to yield encrypted similarity scores.

Supported cryptosystems

Scheme Type Supported homomorphic operations Notes
:paillier Additive ciphertext addition, plaintext scalar multiplication :damgard_jurik when s = 1
:damgard_jurik Additive ciphertext addition, plaintext scalar multiplication s >= 1
:okamoto_uchiyama Additive ciphertext addition, plaintext scalar multiplication Plaintexts in Z_p
:rsa Multiplicative ciphertext multiplication, plaintext exponentiation Textbook RSA, for demonstration
:elgamal (:el_gamal) Multiplicative ciphertext multiplication, plaintext exponentiation ElGamal over Z_p

Additive homomorphism

  • :damgard_jurik (s >= 1, Paillier-compatible when s = 1)
  • :okamoto_uchiyama

Multiplicative homomorphism

  • :rsa (textbook RSA, for homomorphic demonstration)
  • :elgamal (alias: :el_gamal)

Data model and Nx support

Plaintext vectors can be provided as either:

  • numeric lists (integers or reals)
  • rank-1 Nx tensors (integer or floating-point)

Real values are encoded using fixed-point scaling before encryption. Use the precision: option on ElixirPHE.encrypt_vector/3 to control decimal digits (default: 6).

Decryption can return:

  • list output (default)
  • tensor output via as: :tensor

Core API

Common methods:

  • ElixirPHE.keygen/1
  • ElixirPHE.encrypt_vector/2
  • ElixirPHE.encrypt_vector/3
  • ElixirPHE.decrypt_vector/2
  • ElixirPHE.decrypt_vector/3

Additive operations:

  • ElixirPHE.add_encrypted_vectors/2
  • ElixirPHE.scalar_multiply_encrypted_vector/2

Multiplicative operations:

  • ElixirPHE.multiply_encrypted_vectors/2
  • ElixirPHE.power_encrypted_vector/2

For examples, refer to example/usage.exs.

Notes on crypto backend

RSA and ElGamal are backed by official OTP crypto/public_key primitives. Damgard-Jurik and Okamoto-Uchiyama do not have direct OTP scheme primitives, so scheme logic is implemented in this library while core arithmetic and randomness rely on official :crypto operations.

Important caveats

  • RSA here is textbook RSA and intentionally uses raw mode to preserve multiplicative homomorphism.
  • Homomorphic arithmetic is always modular and bounded by each scheme's plaintext space.
  • This project is aimed at learning, prototyping, and controlled experiments.

About

A Partially Homomorphic Encryption (PHE) Library Using Pure Elixir (Elixir部分同态加密库)

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages