paillier

package module
v0.0.0-...-72e3ef3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMessageTooLong = errors.New("paillier: message too long for Paillier public key size")

ErrMessageTooLong is returned when attempting to encrypt a message which is too large for the size of the public key.

Functions

func Add

func Add(pubKey *PublicKey, cipher, constant []byte) []byte

Add homomorphically adds a passed constant to the encrypted integer (our cipher text). We do this by multiplying the constant with our ciphertext. Upon decryption, the resulting plain text will be the sum of the plaintext integer and the constant.

func AddCipher

func AddCipher(pubKey *PublicKey, cipher1, cipher2 []byte) []byte

AddCipher homomorphically adds together two cipher texts. To do this we multiply the two cipher texts, upon decryption, the resulting plain text will be the sum of the corresponding plain texts.

func Decrypt

func Decrypt(privKey *PrivateKey, cipherText []byte) ([]byte, error)

Decrypt decrypts the passed cipher text.

func Encrypt

func Encrypt(pubKey *PublicKey, plainText []byte) ([]byte, error)

Encrypt encrypts a plain text represented as a byte array. The passed plain text MUST NOT be larger than the modulus of the passed public key.

func EncryptAndNonce

func EncryptAndNonce(pubKey *PublicKey, plainText []byte) ([]byte, *big.Int, error)

EncryptAndNonce encrypts a plain text represented as a byte array, and in addition, returns the nonce used during encryption. The passed plain text MUST NOT be larger than the modulus of the passed public key.

func EncryptWithNonce

func EncryptWithNonce(pubKey *PublicKey, r *big.Int, plainText []byte) (*big.Int, error)

EncryptWithNonce encrypts a plain text represented as a byte array using the provided nonce to perform encryption. The passed plain text MUST NOT be larger than the modulus of the passed public key.

func Mul

func Mul(pubKey *PublicKey, cipher []byte, constant []byte) []byte

Mul homomorphically multiplies an encrypted integer (cipher text) by a constant. We do this by raising our cipher text to the power of the passed constant. Upon decryption, the resulting plain text will be the product of the plaintext integer and the constant.

Types

type PrivateKey

type PrivateKey struct {
	PublicKey
	// contains filtered or unexported fields
}

PrivateKey represents a Paillier key.

func GenerateKey

func GenerateKey(random io.Reader, bits int) (*PrivateKey, error)

GenerateKey generates an Paillier keypair of the given bit size using the random source random (for example, crypto/rand.Reader).

type PublicKey

type PublicKey struct {
	N        *big.Int // modulus
	G        *big.Int // n+1, since p and q are same length
	NSquared *big.Int
}

PublicKey represents the public part of a Paillier key.

Jump to

Keyboard shortcuts

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