paillier

package
v0.0.0-...-d2b8996 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2019 License: BSD-3-Clause Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeyPair

func GenerateKeyPair(bitlen int) (*PubKey, *PrvKey, error)

GenerateKeyPair -- returns a Paillier key pair.

Types

type PrvKey

type PrvKey struct {
	// contains filtered or unexported fields
}

PrvKey -- used to perform decryption.

func (*PrvKey) Decrypt

func (sk *PrvKey) Decrypt(ct *big.Int) (*big.Int, error)

Decrypt -- returns the plaintext corresponding to the ciphertext (ct).

type PubKey

type PubKey struct {
	G  *big.Int `json:"G"`
	N  *big.Int `json:"N"`
	NN *big.Int `json:"NN"`
}

PubKey -- used to perform encryption and homomorphic operations.

func (*PubKey) Add

func (pk *PubKey) Add(ct1, ct2 *big.Int) (*big.Int, error)

Add -- returns a ciphertext `ct3` that will decipher to the sum of the corresponding plaintext messages (`m1`, `m2`) ciphered to (`ct1`, `ct2`) (i.e if ct1 = Enc(m1) and ct2 = Enc(m2), then Dec(Add(ct1, ct2)) = m1 + m2 mod N)

func (*PubKey) AddPlaintext

func (pk *PubKey) AddPlaintext(ct *big.Int, msg *big.Int) (*big.Int, error)

AddPlaintext -- returns the ciphertext the will decipher to addition of the plaintexts (i.e if ct = Enc(m1), then Dec(AddPlaintext(ct, m2)) = m1 + m2 mod N)

func (*PubKey) DivPlaintext

func (pk *PubKey) DivPlaintext(ct *big.Int, msg *big.Int) (*big.Int, error)

DivPlaintext -- returns the ciphertext the will decipher to division of the plaintexts (i.e if ct = Enc(m1), then Dec(DivPlaintext(ct, m2)) = m1 / m2 mod N)

func (*PubKey) Encrypt

func (pk *PubKey) Encrypt(msg *big.Int) (*big.Int, error)

Encrypt -- returns a IND-CPA secure ciphertext for the message `msg`.

func (*PubKey) MultPlaintext

func (pk *PubKey) MultPlaintext(ct *big.Int, msg *big.Int) (*big.Int, error)

MultPlaintext -- returns the ciphertext the will decipher to multiplication of the plaintexts (i.e. if ct = Enc(m1), then Dec(MultPlaintext(ct, m2)) = m1 * m2 mod N).

func (*PubKey) Sub

func (pk *PubKey) Sub(ct1, ct2 *big.Int) *big.Int

Sub -- executes homomorphic subtraction, which corresponds to the addition with the modular inverse. That is, it computes a ciphertext ct3 that will decipher to the subtration of the corresponding plaintexts. So, if ct1 = Enc(m1) and ct2 = Enc(m2), and m1 > m2, then Dec(Sub(ct1, ct2)) = ct1 - ct2 mod N. Note that the ciphertext produced by this operation will only make sense if m1>m2.

Jump to

Keyboard shortcuts

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