paillier

package module
v0.0.0-...-b14d9ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2019 License: MIT Imports: 3 Imported by: 0

README

Paillier

Homomorphic encryption using the Paillier cryptosystem implemented in Go

The following operations are supported

  • Addition of two encrypted integers
  • Subtraction of two encrypted integers
  • Addition of an encrypted and plaintext integer
  • Multiplication of an encrypted and plaintext integer
  • Division of an encrypted integer by a plaintext integer in cases where x mod y == 0

See int_test.go for example usage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKeyPair

func NewKeyPair(keyLength, threshold int) (*PublicKey, *PrivateKey, error)

NewKeyPair generates a new public and private key. The key length must be large enough to encrypt the message. The threshold should be greater than the maximum integer that will be encrypted.

Types

type Int

type Int struct {
	Cipher    *big.Int
	PublicKey *PublicKey
}

Int represents and encrypted integer using the Paillier cryptosystem. The public key used to encrypt the integer is also included. A notable feature of the Paillier cryptosystem is its homomorphic properties along with its non-deterministic encryption.

func NewInt

func NewInt(publicKey *PublicKey, x *big.Int) *Int

NewInt returns the encryption of x using the given public key.

func (*Int) Add

func (z *Int) Add(x, y *Int) *Int

Add sets z to the encrypted sum x+y and returns z. If x.PublicKey != y.PublicKey, a pubic-keys-not-equal run-time panic occurs.

func (*Int) AddPlaintext

func (z *Int) AddPlaintext(x *Int, y *big.Int) *Int

AddPlaintext sets z to the encrypted sum x+y and returns z.

func (*Int) Decrypt

func (z *Int) Decrypt(privateKey *PrivateKey) *big.Int

Decrypt returns the decrypted value of z using the given private key. If z.PublicKey != privateKey.PublicKey, a pubic-keys-not-equal run-time panic occurs.

func (*Int) DivPlaintext

func (z *Int) DivPlaintext(x *Int, y *big.Int) *Int

DivPlaintext sets z to the encrypted quotient x/y and returns z. If y == 0, a division-by-zero run-time panic occurs. DivPlaintext will return an invalid result in cases where y does not divide x.

func (*Int) MulPlaintext

func (z *Int) MulPlaintext(x *Int, y *big.Int) *Int

MulPlaintext sets z to the encrypted product x*y and returns z.

func (*Int) Sub

func (z *Int) Sub(x, y *Int) *Int

Sub sets z to the encrypted difference x-y and returns z. If x.PublicKey != y.PublicKey, a pubic-keys-not-equal run-time panic occurs.

type PrivateKey

type PrivateKey struct {
	Length    int
	PublicKey *PublicKey
	L         *big.Int
	U         *big.Int
	Threshold *big.Int
}

PrivateKey must be kept secret

type PublicKey

type PublicKey struct {
	Length int
	N      *big.Int
	NSq    *big.Int
	G      *big.Int
}

PublicKey is the key that may be shared

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL