o1js-elgamal
TypeScript icon, indicating that this package has built-in type declarations

0.0.10 • Public • Published

o1js Elgamal

This repository implements Elgmal, a partial homomorphic encryption scheme originally described by Taher Elgamal in 1985. This implementation includes the original version of Elgamal, which is multiplicative homomorphic, as well as slightly modified versions called Exponential Elgamal, which is multiplicative homomorphic over the cipher space, but additive homomorphic over the plain text space, and a version implementing Elgamal on elliptic curves.

ElGamal over a finite field

Usage

Install the package npm i o1js-elgamal

Import the ElGamal finite field class as well as the cipher class.

import { Cipher, ElGamalFF } from 'o1js-elgamal';

Generate a secret and public key. The secret key is used to decrypt, whereas the public key is used to encrypt a message.

let { pk, sk } = ElGamalFF.generateKeys();

Encrypt two messages using the public key.

let c1 = ElGamalFF.encrypt(Field(5), pk)
let c2 = ElGamalFF.encrypt(Field(5), pk)

Demonstrate the multiplicative homomorphism over the plain text space by multiplying the ciphers.

let c3 = c1.mul(c2)

Decrypt the cipher c3 using the secret key.

let plain = ElGamalFF.decrypt(c3, sk);

Check that the decrypted text equals the expected output of 5 * 5 = 25.

plain.assertEquals(Field(5).mul(5));

Usage in a Mina smart contract

Take a look at at the example which uses ElGamal within a Mina smart contract.

ElGamal over an elliptic curve

TBD

How to build

npm install
npm run build
npm run test
node build/src/examples/elgamalff.js

License

Apache-2.0

Package Sidebar

Install

npm i o1js-elgamal

Weekly Downloads

4

Version

0.0.10

License

Apache-2.0

Unpacked Size

53.2 kB

Total Files

35

Last publish

Collaborators

  • trivo