paillier

package
v0.0.0-...-2db71d7 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCiphertext = errors.New("paillier: invalid ciphertext")
View Source
var ErrInvalidMismatch = errors.New("paillier: key mismatch")
View Source
var ErrInvalidPlaintext = errors.New("paillier: invalid plaintext")
View Source
var ErrInvalidPrivateKey = errors.New("paillier: invalid private key")
View Source
var ErrInvalidPublicKey = errors.New("paillier: invalid public key")
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 AdjustDecryptedDomain

func AdjustDecryptedDomain(pk *PubKey, plaintext *big.Int) (*big.Int, error)

func AdjustPlaintextDomain

func AdjustPlaintextDomain(pk *PubKey, plaintext *big.Int) (*big.Int, error)

func EncryptAndNonce

func EncryptAndNonce(pubKey *PubKey, plainText *big.Int) (*big.Int, *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 *PubKey, r *big.Int, pt *big.Int) (*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 GetCiphertextFromHex

func GetCiphertextFromHex(content string) (string, error)

func GetCiphertextHex

func GetCiphertextHex(cipher string) (string, error)

ciphertext io

func GetPrivateKeyHex

func GetPrivateKeyHex(sk *PrvKey) string

private key io

func GetPublicKeyHex

func GetPublicKeyHex(pk *PubKey) string

public key io

func ReadCiphertextFromFile

func ReadCiphertextFromFile(file string) (string, error)

func WriteCiphertextToFile

func WriteCiphertextToFile(cipher string, file string) error

func WriteEncryptedPrivateKeyToFile

func WriteEncryptedPrivateKeyToFile(sk *PrvKey, file, password string) error

func WritePrivateKeyToFile

func WritePrivateKeyToFile(sk *PrvKey, file string) error

func WritePublicKeyToFile

func WritePublicKeyToFile(pk *PubKey, file string) error

Types

type Ciphertext

type Ciphertext struct {
	Ct       *big.Int
	Checksum []byte
}

func Neg

func Neg(pk *PubKey, cipher *Ciphertext) (*Ciphertext, error)

func (*Ciphertext) GetChecksum

func (ct *Ciphertext) GetChecksum() ([]byte, error)

func (*Ciphertext) GetCtBytes

func (ct *Ciphertext) GetCtBytes() ([]byte, error)

func (*Ciphertext) GetCtStr

func (ct *Ciphertext) GetCtStr() (string, error)

func (*Ciphertext) Marshal

func (ct *Ciphertext) Marshal() ([]byte, error)

func (*Ciphertext) Unmarshal

func (ct *Ciphertext) Unmarshal(ctBytes []byte) error

type PrvKey

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

PrvKey represents a Paillier key.

func GenKey

func GenKey() (*PrvKey, error)

func GetPrivateKeyFromHex

func GetPrivateKeyFromHex(content string) (*PrvKey, error)

func ReadEncryptedPrivateKeyFromFile

func ReadEncryptedPrivateKeyFromFile(file, password string) (*PrvKey, error)

func ReadPrivateKeyFromFile

func ReadPrivateKeyFromFile(file string) (*PrvKey, error)

func (*PrvKey) Decrypt

func (key *PrvKey) Decrypt(cipherText *Ciphertext) (*big.Int, error)

Decrypt decrypts the passed cipher text.

func (*PrvKey) GetPubKey

func (key *PrvKey) GetPubKey() (*PubKey, error)

func (*PrvKey) Marshal

func (key *PrvKey) Marshal() ([]byte, error)

Marshal encodes the PrvKey as a byte slice.

func (*PrvKey) Unmarshal

func (key *PrvKey) Unmarshal(prvKeyBytes []byte) error

Unmarshal recovers the PrvKey from an encoded byte slice.

type PubKey

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

PubKey represents the public part of a Paillier key.

func GetPublicKeyFromHex

func GetPublicKeyFromHex(content string) (*PubKey, error)

func ReadPublicKeyFromFile

func ReadPublicKeyFromFile(file string) (*PubKey, error)

func (*PubKey) AddCiphertext

func (key *PubKey) AddCiphertext(cipher1, cipher2 *Ciphertext) (*Ciphertext, error)

AddCiphertext 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 (*PubKey) AddPlaintext

func (key *PubKey) AddPlaintext(cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)

AddPlaintext 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 (*PubKey) ChecksumVerify

func (key *PubKey) ChecksumVerify(ct *Ciphertext) bool

ChecksumVerify verifying public key ciphertext pairs

func (*PubKey) Encrypt

func (key *PubKey) Encrypt(plainText *big.Int) (*Ciphertext, 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 (*PubKey) Marshal

func (key *PubKey) Marshal() ([]byte, error)

Marshal encodes the PubKey as a byte slice.

func (*PubKey) NumMul

func (key *PubKey) NumMul(cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)

NumMul 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.

func (*PubKey) SubByConstant

func (key *PubKey) SubByConstant(pubKey *PubKey, cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)

func (*PubKey) SubCiphertext

func (key *PubKey) SubCiphertext(cipher1, cipher2 *Ciphertext) (*Ciphertext, error)

func (*PubKey) SubPlaintext

func (key *PubKey) SubPlaintext(cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)

func (*PubKey) Unmarshal

func (key *PubKey) Unmarshal(pubKeyBytes []byte) error

Unmarshal recovers the PubKey from an encoded byte slice.

Jump to

Keyboard shortcuts

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