Help us shape the future of Go! Take the 2026 Go Developer Survey

paillier

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

Paillier Cryptosystem

This package implements the Paillier cryptosystem, an additive homomorphic public-key encryption scheme that enables computation on encrypted data.

Mathematical Foundation

The Paillier cryptosystem operates over the group (Z/n²Z)* where n = p · q is an RSA modulus. Security relies on the Decisional Composite Residuosity Assumption (DCRA).

Key Structure
  • Public key: modulus n and generator g = 1 + n
  • Private key: prime factors p, q (enables CRT-based decryption)
  • Plaintext space: integers in [-n/2, n/2) (centred representation)
  • Ciphertext space: elements of (Z/n²Z)*
Encryption

For plaintext m and random nonce r ∈ (Z/nZ)*:

Enc(m, r) = g^m · r^n mod n²
         = (1 + m·n) · r^n mod n²
Homomorphic Properties

The scheme supports three homomorphic operations:

Operation Ciphertext Computation Plaintext Effect
HomAdd(c₁, c₂) c₁ · c₂ mod n² m₁ + m₂
HomSub(c₁, c₂) c₁ · c₂⁻¹ mod n² m₁ - m₂
ScalarMul(c, k) c^k mod n² k · m
Shift(c, Δ) c · g^Δ mod n² m + Δ

Note: ScalarMul and Shift differ in an important way:

  • ScalarMul(c, k) exponentiates the ciphertext by scalar k, computing c^k. This multiplies the plaintext by k but also raises the randomness to the k-th power.
  • Shift(c, Δ) multiplies by the representative g^Δ, adding Δ to the plaintext without changing the randomness component. This does not re-randomize the ciphertext.

Usage

Key Generation
import "github.com/bronlabs/bron-crypto/pkg/encryption/paillier"

scheme := paillier.NewScheme()

// Generate with 2048-bit primes (4096-bit modulus)
kg, _ := scheme.Keygen(paillier.WithEachPrimeBitLen(2048))
sk, pk, _ := kg.Generate(rand.Reader)
Encryption and Decryption
enc, _ := scheme.Encrypter()
dec, _ := scheme.Decrypter(sk)

// Create plaintext from integer
ps := pk.PlaintextSpace()
pt, _ := ps.FromInt(value)

// Encrypt (returns ciphertext and nonce)
ct, nonce, _ := enc.Encrypt(pt, pk, rand.Reader)

// Decrypt
decrypted, _ := dec.Decrypt(ct)
Homomorphic Addition and Subtraction
// Given Enc(a) and Enc(b)
ct1, _, _ := enc.Encrypt(ptA, pk, rand.Reader)
ct2, _, _ := enc.Encrypt(ptB, pk, rand.Reader)

// Compute Enc(a + b)
ctSum := ct1.HomAdd(ct2)

// Compute Enc(a - b)
ctDiff := ct1.HomSub(ct2)
Scalar Multiplication
// Given Enc(m) and scalar k
ct, _, _ := enc.Encrypt(pt, pk, rand.Reader)
scalar := num.N().FromUint64(5)

// Compute Enc(k · m) via exponentiation: c^k
ctScaled := ct.ScalarMul(scalar)

// With bounded exponent for efficiency (when k fits in b bits)
ctScaled := ct.ScalarMulBounded(scalar, 16)
Plaintext Shift
// Given Enc(m) and plaintext delta Δ
delta, _ := ps.FromInt(deltaValue)

// Compute Enc(m + Δ) via multiplication by g^Δ
// Note: does not change the randomness component
ctShifted, _ := ct.Shift(pk, delta)
Re-randomization
// Produce unlinkable ciphertext encrypting the same value
// Multiplies by r'^n for fresh random r'
ctNew, nonce, _ := ct.ReRandomise(pk, rand.Reader)
Self-Encryption (CRT Optimization)

When encrypting to your own key, use SelfEncrypter for ~3x speedup via CRT:

se, _ := scheme.SelfEncrypter(sk)
ct, nonce, _ := se.SelfEncrypt(pt, rand.Reader)
Batch Operations
// Encrypt multiple plaintexts in parallel
plaintexts := []*paillier.Plaintext{pt1, pt2, pt3}
cts, nonces, _ := enc.EncryptMany(plaintexts, pk, rand.Reader)

// Self-encrypt multiple plaintexts
cts, nonces, _ := se.SelfEncryptMany(plaintexts, rand.Reader)

Package Structure

File Contents
paillier.go Scheme type and factory methods
keys.go PrivateKey, PublicKey
plaintexts.go PlaintextSpace, Plaintext with arithmetic
ciphertexts.go CiphertextSpace, Ciphertext with homomorphic ops
nonces.go NonceSpace, Nonce
participants.go KeyGenerator, Encrypter, SelfEncrypter, Decrypter
cbor.go CBOR serialization

Security Notes

  • Minimum key size enforced: 1024 bits per prime (2048-bit modulus)
  • Production systems should use 2048+ bits per prime (4096+ bit modulus)
  • Shift does not re-randomize; use ReRandomise when unlinkability is required
  • Plaintexts use centred representation [-n/2, n/2) to support negative values

Documentation

Overview

Package paillier implements the Paillier cryptosystem, an additive homomorphic public-key encryption scheme. It supports homomorphic addition of ciphertexts and scalar multiplication of ciphertexts by plaintexts.

Index

Constants

View Source
const (
	Name      encryption.Name = "paillier"
	MinKeyLen                 = base.IFCKeyLength
)

Name is the identifier for the Paillier encryption scheme.

Variables

View Source
var (
	ErrInvalidArgument = errs.New("invalid argument")
	ErrInvalidRange    = errs.New("invalid range")
)

Functions

This section is empty.

Types

type Ciphertext

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

Ciphertext represents an encrypted Paillier message in the group (Z/n²Z)*.

func NewCiphertextFromUnit

func NewCiphertextFromUnit(u *znstar.PaillierGroupElementUnknownOrder) *Ciphertext

NewCiphertextFromUnit creates a new ciphertext from a Paillier group element.

func (*Ciphertext) Equal

func (ct *Ciphertext) Equal(other *Ciphertext) bool

Equal returns true if two ciphertexts are equal.

func (*Ciphertext) HashCode

func (ct *Ciphertext) HashCode() base.HashCode

HashCode returns a hash code for the ciphertext.

func (*Ciphertext) HomAdd

func (ct *Ciphertext) HomAdd(other *Ciphertext) *Ciphertext

HomAdd performs homomorphic addition of two ciphertexts. The result decrypts to the sum of the two plaintexts: Dec(HomAdd(c1, c2)) = m1 + m2.

func (*Ciphertext) HomSub

func (ct *Ciphertext) HomSub(other *Ciphertext) *Ciphertext

HomSub performs homomorphic subtraction of two ciphertexts. The result decrypts to the difference of the two plaintexts: Dec(HomSub(c1, c2)) = m1 - m2.

func (*Ciphertext) MarshalCBOR

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

MarshalCBOR serialises the ciphertext to CBOR format.

func (*Ciphertext) N2

func (ct *Ciphertext) N2() *num.NatPlus

N2 returns the modulus n² of the ciphertext.

func (*Ciphertext) Op

func (ct *Ciphertext) Op(other *Ciphertext) *Ciphertext

Op multiplies two ciphertexts in the group (Z/n²Z)*, which corresponds to addition of the underlying plaintexts in the Paillier scheme.

func (*Ciphertext) ReRandomise

func (ct *Ciphertext) ReRandomise(pk *PublicKey, prng io.Reader) (*Ciphertext, *Nonce, error)

ReRandomise re-randomises a ciphertext by multiplying it with a fresh encryption of zero. This produces a new ciphertext that decrypts to the same plaintext but is unlinkable to the original. Returns the new ciphertext and the nonce used.

func (*Ciphertext) ReRandomiseWithNonce

func (ct *Ciphertext) ReRandomiseWithNonce(pk *PublicKey, nonce *Nonce) (*Ciphertext, error)

ReRandomiseWithNonce re-randomises a ciphertext using a provided nonce. The result is c' = c * r^n mod n², which decrypts to the same plaintext as c.

func (*Ciphertext) ScalarMul

func (ct *Ciphertext) ScalarMul(scalar *num.Nat) *Ciphertext

ScalarMul performs homomorphic scalar multiplication of a ciphertext. The result decrypts to the product of the plaintext and scalar: Dec(ScalarMul(c, k)) = m * k.

func (*Ciphertext) ScalarMulBounded

func (ct *Ciphertext) ScalarMulBounded(scalar *num.Nat, bits uint) *Ciphertext

ScalarMulBounded performs homomorphic scalar multiplication with a known bit bound. This is more efficient than ScalarMul when the scalar is known to be small.

func (*Ciphertext) ScalarOp

func (ct *Ciphertext) ScalarOp(scalar *num.Nat) *Ciphertext

ScalarOp exponentiates a ciphertext by a scalar, which corresponds to multiplication of the underlying plaintext by the scalar in the Paillier scheme.

func (*Ciphertext) ScalarOpBounded

func (ct *Ciphertext) ScalarOpBounded(scalar *num.Nat, bits uint) *Ciphertext

ScalarOpBounded exponentiates a ciphertext by a scalar with a known bit bound. This is more efficient than ScalarOp when the scalar is known to be small.

func (*Ciphertext) Shift

func (ct *Ciphertext) Shift(pk *PublicKey, message *Plaintext) (*Ciphertext, error)

Shift adds a plaintext value to an encrypted ciphertext without re-randomization. This is useful for adjusting ciphertexts by known values without changing randomness.

func (*Ciphertext) UnmarshalCBOR

func (ct *Ciphertext) UnmarshalCBOR(data []byte) error

UnmarshalCBOR deserializes the ciphertext from CBOR format.

func (*Ciphertext) Value

Value returns the underlying group element.

func (*Ciphertext) ValueCT

func (ct *Ciphertext) ValueCT() *numct.Nat

ValueCT returns the ciphertext value as a constant-time natural number.

type CiphertextSpace

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

CiphertextSpace represents the space of Paillier ciphertexts modulo n^2.

func NewCiphertextSpace

func NewCiphertextSpace(n2, n *num.NatPlus) (*CiphertextSpace, error)

NewCiphertextSpace creates a new ciphertext space for Paillier encryption. The space is the multiplicative group (Z/n²Z)* where n² is the modulus.

func (*CiphertextSpace) Contains

func (cts *CiphertextSpace) Contains(ct *Ciphertext) bool

Contains returns true if the ciphertext belongs to this ciphertext space.

func (*CiphertextSpace) Group

Group returns the underlying Paillier group of unknown order.

func (*CiphertextSpace) N2

func (cts *CiphertextSpace) N2() *num.NatPlus

N2 returns the modulus n^2 of the ciphertext space.

func (*CiphertextSpace) New

func (cts *CiphertextSpace) New(x *numct.Nat) (*Ciphertext, error)

New creates a new ciphertext from a natural number.

func (*CiphertextSpace) Sample

func (cts *CiphertextSpace) Sample(prng io.Reader) (*Ciphertext, error)

Sample samples a random ciphertext from the ciphertext space.

type Decrypter

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

Decrypter performs Paillier decryption using the private key. Uses CRT for efficient decryption.

func (*Decrypter) Decrypt

func (d *Decrypter) Decrypt(ciphertext *Ciphertext) (*Plaintext, error)

Decrypt decrypts a ciphertext and returns the plaintext. Uses CRT-based decryption for efficiency.

type DecrypterOption

DecrypterOption is a functional option for configuring the decrypter.

type Encrypter

type Encrypter struct{}

Encrypter performs Paillier encryption using a receiver's public key.

func (*Encrypter) Encrypt

func (e *Encrypter) Encrypt(plaintext *Plaintext, receiver *PublicKey, prng io.Reader) (*Ciphertext, *Nonce, error)

Encrypt encrypts a plaintext for the given receiver using a fresh random nonce. Returns the ciphertext, the nonce used, and any error encountered.

func (*Encrypter) EncryptMany

func (e *Encrypter) EncryptMany(plaintexts []*Plaintext, receiver *PublicKey, prng io.Reader) ([]*Ciphertext, []*Nonce, error)

EncryptMany encrypts multiple plaintexts in parallel using fresh random nonces. Returns the ciphertexts, the nonces used, and any error encountered.

func (*Encrypter) EncryptManyWithNonces

func (e *Encrypter) EncryptManyWithNonces(plaintexts []*Plaintext, receiver *PublicKey, nonces []*Nonce) ([]*Ciphertext, error)

EncryptManyWithNonces encrypts multiple plaintexts in parallel using provided nonces. The length of plaintexts and nonces must match.

func (*Encrypter) EncryptWithNonce

func (*Encrypter) EncryptWithNonce(plaintext *Plaintext, receiver *PublicKey, nonce *Nonce) (*Ciphertext, error)

EncryptWithNonce encrypts a plaintext using a provided nonce. The ciphertext is computed as c = g^m * r^n mod n².

type EncrypterOption

EncrypterOption is a functional option for configuring the encrypter.

type KeyGenerator

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

KeyGenerator generates Paillier key pairs with configurable parameters.

func (*KeyGenerator) Generate

func (kg *KeyGenerator) Generate(prng io.Reader) (*PrivateKey, *PublicKey, error)

Generate creates a new Paillier key pair using the configured parameters. Returns the private key, public key, and any error encountered.

type KeyGeneratorOption

KeyGeneratorOption is a functional option for configuring the key generator.

func WithKeyLen

func WithKeyLen(bits uint) KeyGeneratorOption

WithKeyLen sets the bit length of the modulus n for the generated Paillier key pair.

type Nonce

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

Nonce represents a Paillier encryption nonce in the group (Z/nZ)*. Nonces provide the randomization needed for semantic security.

func (*Nonce) Equal

func (n *Nonce) Equal(other *Nonce) bool

Equal returns true if two nonces are equal.

func (*Nonce) MarshalCBOR

func (n *Nonce) MarshalCBOR() ([]byte, error)

MarshalCBOR serialises the nonce to CBOR format.

func (*Nonce) Mul

func (n *Nonce) Mul(other *Nonce) *Nonce

Mul multiplies two nonces and returns the result.

func (*Nonce) N

func (n *Nonce) N() *num.NatPlus

N returns the modulus n of the nonce.

func (*Nonce) Op

func (n *Nonce) Op(other *Nonce) *Nonce

Op performs the group operation on two nonces (multiplication modulo n).

func (*Nonce) UnmarshalCBOR

func (n *Nonce) UnmarshalCBOR(data []byte) error

UnmarshalCBOR deserializes the nonce from CBOR format.

func (*Nonce) Value

Value returns the underlying RSA group element.

func (*Nonce) ValueCT

func (n *Nonce) ValueCT() *numct.Nat

ValueCT returns the nonce value as a constant-time natural number.

type NonceSpace

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

NonceSpace represents the space of Paillier nonces (Z/nZ)*. Nonces are used to randomise ciphertexts for semantic security.

func NewNonceSpace

func NewNonceSpace(n *num.NatPlus) (*NonceSpace, error)

NewNonceSpace creates a new nonce space (Z/nZ)* for Paillier encryption. The nonce space is the multiplicative group of units modulo n.

func (*NonceSpace) Contains

func (ns *NonceSpace) Contains(n *Nonce) bool

Contains returns true if the nonce belongs to this nonce space.

func (*NonceSpace) N

func (ns *NonceSpace) N() *num.NatPlus

N returns the modulus n of the nonce space.

func (*NonceSpace) New

func (ns *NonceSpace) New(x *numct.Nat) (*Nonce, error)

New creates a nonce from a constant-time natural number. Returns an error if the value is not a unit modulo n.

func (*NonceSpace) Sample

func (ns *NonceSpace) Sample(prng io.Reader) (*Nonce, error)

Sample samples a random nonce from the nonce space. The nonce is guaranteed to be a unit (coprime to n).

type Plaintext

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

Plaintext represents a Paillier plaintext as a centred integer in [-n/2, n/2). This centred representation allows for both positive and negative values.

func (*Plaintext) Add

func (pt *Plaintext) Add(other *Plaintext) *Plaintext

Add adds two plaintexts and returns the result reduced to the centred range.

func (*Plaintext) Bytes

func (pt *Plaintext) Bytes() []byte

Bytes returns the plaintext value as a big-endian byte slice.

func (*Plaintext) Equal

func (pt *Plaintext) Equal(other *Plaintext) bool

Equal returns true if two plaintexts have the same value.

func (*Plaintext) IsLessThanOrEqual

func (pt *Plaintext) IsLessThanOrEqual(other *Plaintext) bool

IsLessThanOrEqual returns true if this plaintext is less than or equal to another.

func (*Plaintext) MarshalCBOR

func (pt *Plaintext) MarshalCBOR() ([]byte, error)

MarshalCBOR serialises the plaintext to CBOR format.

func (*Plaintext) N

func (pt *Plaintext) N() *num.NatPlus

N returns the modulus n of the plaintext.

func (*Plaintext) Neg

func (pt *Plaintext) Neg() *Plaintext

Neg returns the negation of the plaintext.

func (*Plaintext) Normalise

func (pt *Plaintext) Normalise() *num.Uint

Normalise returns the plaintext value reduced to the range [0, n).

func (*Plaintext) Op

func (pt *Plaintext) Op(other *Plaintext) *Plaintext

Op performs the group operation on two plaintexts (addition modulo n).

func (*Plaintext) OpInv

func (pt *Plaintext) OpInv() *Plaintext

OpInv returns the additive inverse of the plaintext.

func (*Plaintext) PartialCompare

func (pt *Plaintext) PartialCompare(other *Plaintext) base.PartialOrdering

PartialCompare compares two plaintexts and returns their ordering. Returns Incomparable if the plaintexts have different moduli.

func (*Plaintext) Sub

func (pt *Plaintext) Sub(other *Plaintext) *Plaintext

Sub subtracts another plaintext from this one and returns the result.

func (*Plaintext) UnmarshalCBOR

func (pt *Plaintext) UnmarshalCBOR(data []byte) error

UnmarshalCBOR deserializes the plaintext from CBOR format.

func (*Plaintext) Value

func (pt *Plaintext) Value() *num.Int

Value returns the centred integer value of the plaintext.

func (*Plaintext) ValueCT

func (pt *Plaintext) ValueCT() *numct.Int

ValueCT returns the plaintext value as a constant-time signed integer.

type PlaintextSpace

type PlaintextSpace num.ZMod

PlaintextSpace represents the space of Paillier plaintexts modulo n. Plaintexts are centred integers in the range [-n/2, n/2).

func NewPlaintextSpace

func NewPlaintextSpace(n *num.NatPlus) (*PlaintextSpace, error)

NewPlaintextSpace creates a new plaintext space Z_n for Paillier encryption. The space represents integers modulo n, where n is the RSA modulus.

func (*PlaintextSpace) Contains

func (pts *PlaintextSpace) Contains(m *Plaintext) bool

Contains returns true if the plaintext belongs to this plaintext space.

func (*PlaintextSpace) FromBytes

func (pts *PlaintextSpace) FromBytes(b []byte) (*Plaintext, error)

FromBytes creates a plaintext from a byte slice. The bytes are interpreted as a big-endian unsigned integer.

func (*PlaintextSpace) FromInt

func (pts *PlaintextSpace) FromInt(x *numct.Int) (*Plaintext, error)

FromInt creates a plaintext from a constant-time signed integer. Returns an error if the value is outside the valid range [-n/2, n/2).

func (*PlaintextSpace) FromNat

func (pts *PlaintextSpace) FromNat(x *numct.Nat) (*Plaintext, error)

FromNat creates a plaintext from a constant-time natural number. The value is reduced modulo n and centred to the symmetric range.

func (*PlaintextSpace) N

func (pts *PlaintextSpace) N() *num.NatPlus

N returns the modulus n of the plaintext space.

func (*PlaintextSpace) Sample

func (pts *PlaintextSpace) Sample(lowInclusive, highExclusive *Plaintext, prng io.Reader) (*Plaintext, error)

Sample samples a random plaintext from the plaintext space. If both bounds are nil, samples uniformly from the full range [-n/2, n/2). If both bounds are provided, samples uniformly from [lowInclusive, highExclusive).

func (*PlaintextSpace) Zero

func (pts *PlaintextSpace) Zero() *Plaintext

Zero returns the zero plaintext (additive identity).

type PrivateKey

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

PrivateKey represents a Paillier private key containing the prime factorization of the modulus n = p * q. It enables efficient decryption using CRT.

func NewPrivateKey

func NewPrivateKey(group *znstar.PaillierGroupKnownOrder) (*PrivateKey, error)

NewPrivateKey creates a new Paillier private key from a Paillier group with known order. The group must contain the factorization n = p * q where p and q are distinct odd primes.

func (*PrivateKey) Arithmetic

func (sk *PrivateKey) Arithmetic() *modular.OddPrimeSquareFactors

Arithmetic returns the modular arithmetic instance for efficient computations mod n².

func (*PrivateKey) Equal

func (sk *PrivateKey) Equal(other *PrivateKey) bool

Equal returns true if both private keys are equal.

func (*PrivateKey) Group

Group returns the underlying Paillier group with known order.

func (*PrivateKey) MarshalCBOR

func (sk *PrivateKey) MarshalCBOR() ([]byte, error)

MarshalCBOR serialises the private key to CBOR format.

func (*PrivateKey) PublicKey

func (sk *PrivateKey) PublicKey() *PublicKey

PublicKey derives and returns the corresponding public key.

func (*PrivateKey) UnmarshalCBOR

func (sk *PrivateKey) UnmarshalCBOR(data []byte) error

UnmarshalCBOR deserializes the private key from CBOR format.

type PublicKey

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

PublicKey represents a Paillier public key containing the modulus n. It can be used for encryption but not decryption.

func NewPublicKey

func NewPublicKey(group *znstar.PaillierGroupUnknownOrder) (*PublicKey, error)

NewPublicKey creates a new Paillier public key from a Paillier group with unknown order. The public key contains only the modulus n, without knowledge of its factorization.

func (*PublicKey) CiphertextSpace

func (pk *PublicKey) CiphertextSpace() *CiphertextSpace

CiphertextSpace returns the ciphertext space (Z_n²)* for this public key.

func (*PublicKey) Clone

func (pk *PublicKey) Clone() *PublicKey

Clone returns a shallow copy of the public key.

func (*PublicKey) Equal

func (pk *PublicKey) Equal(other *PublicKey) bool

Equal returns true if both public keys are equal.

func (*PublicKey) Group

Group returns the underlying Paillier group with unknown order.

func (*PublicKey) HashCode

func (pk *PublicKey) HashCode() base.HashCode

HashCode returns a hash code for the public key.

func (*PublicKey) MarshalCBOR

func (pk *PublicKey) MarshalCBOR() ([]byte, error)

MarshalCBOR serialises the public key to CBOR format.

func (*PublicKey) Modulus

func (pk *PublicKey) Modulus() *numct.Modulus

Modulus returns the modulus n² as a constant-time modulus.

func (*PublicKey) N

func (pk *PublicKey) N() *numct.Modulus

N returns the modulus n as a constant-time modulus.

func (*PublicKey) N2

func (pk *PublicKey) N2() *numct.Modulus

N2 returns the modulus n² as a constant-time modulus.

func (*PublicKey) NonceSpace

func (pk *PublicKey) NonceSpace() *NonceSpace

NonceSpace returns the nonce space (Z_n)* for this public key.

func (*PublicKey) PlaintextSpace

func (pk *PublicKey) PlaintextSpace() *PlaintextSpace

PlaintextSpace returns the plaintext space Z_n for this public key.

func (*PublicKey) UnmarshalCBOR

func (pk *PublicKey) UnmarshalCBOR(data []byte) error

UnmarshalCBOR deserializes the public key from CBOR format.

type Scheme

type Scheme struct{}

Scheme represents the Paillier encryption scheme and provides factory methods for creating key generators, encrypters, and decrypters.

func NewScheme

func NewScheme() *Scheme

NewScheme returns a new Paillier encryption scheme instance.

func (*Scheme) Decrypter

func (*Scheme) Decrypter(sk *PrivateKey, opts ...DecrypterOption) (*Decrypter, error)

Decrypter creates a new decrypter for the given private key.

func (*Scheme) Encrypter

func (*Scheme) Encrypter(opts ...EncrypterOption) (*Encrypter, error)

Encrypter creates a new encrypter with the given options.

func (*Scheme) Keygen

func (*Scheme) Keygen(opts ...KeyGeneratorOption) (*KeyGenerator, error)

Keygen creates a new key generator with the given options.

func (*Scheme) Name

func (*Scheme) Name() encryption.Name

Name returns the identifier for the Paillier encryption scheme.

func (*Scheme) SelfEncrypter

func (*Scheme) SelfEncrypter(sk *PrivateKey, opts ...SelfEncrypterOption) (*SelfEncrypter, error)

SelfEncrypter creates a new self-encrypter for the given private key. A self-encrypter encrypts messages to the owner of the private key, using CRT optimizations for faster encryption.

type SelfEncrypter

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

SelfEncrypter performs Paillier encryption to oneself using CRT optimizations. This is more efficient than regular encryption when encrypting to one's own public key.

func (*SelfEncrypter) PrivateKey

func (se *SelfEncrypter) PrivateKey() *PrivateKey

PrivateKey returns the private key used by this self-encrypter.

func (*SelfEncrypter) SelfEncrypt

func (se *SelfEncrypter) SelfEncrypt(plaintext *Plaintext, prng io.Reader) (*Ciphertext, *Nonce, error)

SelfEncrypt encrypts a plaintext to oneself using a fresh random nonce. Uses CRT optimizations for faster encryption.

func (*SelfEncrypter) SelfEncryptMany

func (se *SelfEncrypter) SelfEncryptMany(plaintexts []*Plaintext, prng io.Reader) ([]*Ciphertext, []*Nonce, error)

SelfEncryptMany encrypts multiple plaintexts to oneself in parallel. Uses CRT optimizations for faster encryption.

func (*SelfEncrypter) SelfEncryptManyWithNonces

func (se *SelfEncrypter) SelfEncryptManyWithNonces(plaintexts []*Plaintext, nonces []*Nonce) ([]*Ciphertext, error)

SelfEncryptManyWithNonces encrypts multiple plaintexts to oneself using provided nonces. The length of plaintexts and nonces must match.

func (*SelfEncrypter) SelfEncryptWithNonce

func (se *SelfEncrypter) SelfEncryptWithNonce(plaintext *Plaintext, nonce *Nonce) (*Ciphertext, error)

SelfEncryptWithNonce encrypts a plaintext to oneself using a provided nonce. Uses CRT optimizations for faster encryption.

type SelfEncrypterOption

type SelfEncrypterOption = func(*SelfEncrypter) error

SelfEncrypterOption is a functional option for configuring the self-encrypter.

Jump to

Keyboard shortcuts

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