GithubHelp home page GithubHelp logo

go-go-gadget-paillier's Introduction

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

go-go-gadget-paillier's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-go-gadget-paillier's Issues

How to ensure that r and N are relatively prime

line 106 func EncryptAndNonce(pubKey *PublicKey, plainText []byte) ([]byte, *big.Int, error)
line 107 r, err := rand.Int(rand.Reader, pubKey.N)
r just a random int,
How to ensure that r and N are relatively prime , gcd(r,N)=1?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.