• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 10 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Go implementation of the partially homomorphic Paillier Cryptosystem.

go-go-gadget-paillier

A Go implementation of the partially homomorphic Paillier Cryptosystem.

Inspector Paillier

Explanation

Homomorphic cryptosystems are a family of cryptosystems that allow computations to be performed on generated ciphertexts. The general idea is that: within one of these systems, one is able to perform certain computations on a chiper text, which when decrypted reflects those operations on the corresponding plaintext.

Cryptosystems from this family that support arbitary computations are known as Fully Homomorphic Cryptosystems (FHE). This powerful property would allow for the creation extremely useful systems whose functionality operates on inputs which are entirely encrypted, subsequently producing encrypted output. With the ability to perform arbitary computation on encrypted data, one could outsource sensitive private data to third-parties who are then able to perform useful operations without ever decrypting the data. Applications of this technology are extremley wide reaching, and could be applied to services such as: Search Engines, Cloud Computing Providers, E-Mail spam detection, etc.

However, most FHE systems are too inefficient for practical use, and are an on-going research area in the field of Cryptography.

Instead, this package contains an implementation of a Partially Homomorphic Cryptosystem. Partially homomorphic encryption instead only supports a subset of operations on ciphertexts. Examples of such systems are those that support addition or multiplication on ciphertexts.

The Paillier Cryptosystem is an additive cryptosystem. This means that given two ciphertexts, one can perform operations equivalent to adding the respective plaintexts. Additionally, Paillier Cryptosystem supports further computations:

  • Encrypted integers can be added together
  • Encrypted integers can be multiplied by an unencrypted integer
  • Encrypted integers and unencrypted integers can be added together

Example Usage

// Generate a 128-bit private key.
privKey, _ := paillier.GenerateKey(rand.Reader, 128)

// Encrypt the number "15".
m15 := new(big.Int).SetInt64(15)
c15, _ := paillier.Encrypt(&privKey.PublicKey, m15.Bytes())

// Decrypt the number "15".
d, _ := paillier.Decrypt(privKey, c15)
plainText := new(big.Int).SetBytes(d)
fmt.Println("Decryption Result of 15: ", plainText.String()) // 15

// Now for the fun stuff.
        
// Encrypt the number "20".
m20 := new(big.Int).SetInt64(20)
c20, _ := paillier.Encrypt(&privKey.PublicKey, m20.Bytes())

// Add the encrypted integers 15 and 20 together.
plusM16M20 := paillier.AddCipher(&privKey.PublicKey, c15, c20)
decryptedAddition, _ := paillier.Decrypt(privKey, plusM16M20)
fmt.Println("Result of 15+20 after decryption: ",
        new(big.Int).SetBytes(decryptedAddition).String()) // 35!

// Add the encrypted integer 15 to plaintext constant 10.
plusE15and10 := paillier.Add(&privKey.PublicKey, c15, new(big.Int).SetInt64(10).Bytes())
decryptedAddition, _ = paillier.Decrypt(privKey, plusE15and10)
fmt.Println("Result of 15+10 after decryption: ",
        new(big.Int).SetBytes(decryptedAddition).String()) // 25!

// Multiply the encrypted integer 15 by the plaintext constant 10.
mulE15and10 := paillier.Mul(&privKey.PublicKey, c15, new(big.Int).SetInt64(10).Bytes())
decryptedMul, _ := paillier.Decrypt(privKey, mulE15and10)
fmt.Println("Result of 15*10 after decryption: ",
        new(big.Int).SetBytes(decryptedMul).String()) // 150!

Installation

$ go get github.com/roasbeef/go-go-gadget-paillier

Warning

This library was created primarily for education purposes, with future application for a course project. You should NOT USE THIS CODE IN PRODUCTION SYSTEMS.

Benchmarks

$ go test -timeout 5h -bench=. -benchtime=1m

More Repositories

1

btcd-in-a-box

Your favorite alternative full node Bitcoin implementation...dockerized!
Dockerfile
41
star
2

btcdmon

A system for monitoring+querying real-time Bitcoin P2P network data pulled from a btcd full-node. Built using InfluxDB, NGINX, Grafana, and Docker.
Shell
33
star
3

FlaskrNews

A reddit/hackernews clone created in python with flask and app engine
Python
10
star
4

perm-crypt

A Golang implementation of the AES-FFX Format-Preserving Encryption Scheme
Go
9
star
5

sidechains-playground

Playground for prototyping sidechains ideas/components.
Go
6
star
6

satori

HTTP/2.0 Client+Server implementation with Python 3.4 asyncio
Python
6
star
7

bitcoin-alloy

A lightweight formal model of Bitcoin Script (post BIP-0342) using the Alloy model Analyzer
Alloy
5
star
8

iTunes-Notify

A little hack I threw together that uses growl to send notifications of the current iTunes song playing
Python
4
star
9

finial

Aperture L402 Proxy to the OpenAI API
Go
4
star
10

lndmon

lndmon
Go
4
star
11

rando

Trivial P.R.N.G implementation in Rust. Linear Congruential Generator + Linear Feedback Shift Register Generator.
Rust
4
star
12

pool

The Lightning Liquidity Marketplace: a non-custodial batched uniform clearing-price auction for Channel Liquidity Bonds (CLBs). A CLB packages up inbound channel liquidity (ability to receive funds) as a fixed income asset with a maturity date expressed in blocks.
Go
4
star
13

seneca

Bitcoin half-node leveraging Python 3.4's asycnio
Python
3
star
14

Project-Euler-Solutions-

All written in python
Python
3
star
15

GauchoSwap

A web app to facilitate and aggregate the swapping/trading of classes by UCSB students.
JavaScript
3
star
16

btc-pebble

Pebble Bitcoin Ticker Watchface
JavaScript
2
star
17

Simple-Url-Shortener

A simple url shortener hosted on Google App Engine
Python
1
star
18

DuckDuckXor

A Symmetrically Encrypted Search Engine with Support for Boolean Queries
Go
1
star