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
- Variables
- type Ciphertext
- func (ct *Ciphertext) Equal(other *Ciphertext) bool
- func (ct *Ciphertext) HashCode() base.HashCode
- func (ct *Ciphertext) HomAdd(other *Ciphertext) *Ciphertext
- func (ct *Ciphertext) HomSub(other *Ciphertext) *Ciphertext
- func (ct *Ciphertext) MarshalCBOR() ([]byte, error)
- func (ct *Ciphertext) N2() *num.NatPlus
- func (ct *Ciphertext) Op(other *Ciphertext) *Ciphertext
- func (ct *Ciphertext) ReRandomise(pk *PublicKey, prng io.Reader) (*Ciphertext, *Nonce, error)
- func (ct *Ciphertext) ReRandomiseWithNonce(pk *PublicKey, nonce *Nonce) (*Ciphertext, error)
- func (ct *Ciphertext) ScalarMul(scalar *num.Nat) *Ciphertext
- func (ct *Ciphertext) ScalarMulBounded(scalar *num.Nat, bits uint) *Ciphertext
- func (ct *Ciphertext) ScalarOp(scalar *num.Nat) *Ciphertext
- func (ct *Ciphertext) ScalarOpBounded(scalar *num.Nat, bits uint) *Ciphertext
- func (ct *Ciphertext) Shift(pk *PublicKey, message *Plaintext) (*Ciphertext, error)
- func (ct *Ciphertext) UnmarshalCBOR(data []byte) error
- func (ct *Ciphertext) Value() *znstar.PaillierGroupElementUnknownOrder
- func (ct *Ciphertext) ValueCT() *numct.Nat
- type CiphertextSpace
- func (cts *CiphertextSpace) Contains(ct *Ciphertext) bool
- func (cts *CiphertextSpace) Group() *znstar.PaillierGroupUnknownOrder
- func (cts *CiphertextSpace) N2() *num.NatPlus
- func (cts *CiphertextSpace) New(x *numct.Nat) (*Ciphertext, error)
- func (cts *CiphertextSpace) Sample(prng io.Reader) (*Ciphertext, error)
- type Decrypter
- type DecrypterOption
- type Encrypter
- func (e *Encrypter) Encrypt(plaintext *Plaintext, receiver *PublicKey, prng io.Reader) (*Ciphertext, *Nonce, error)
- func (e *Encrypter) EncryptMany(plaintexts []*Plaintext, receiver *PublicKey, prng io.Reader) ([]*Ciphertext, []*Nonce, error)
- func (e *Encrypter) EncryptManyWithNonces(plaintexts []*Plaintext, receiver *PublicKey, nonces []*Nonce) ([]*Ciphertext, error)
- func (*Encrypter) EncryptWithNonce(plaintext *Plaintext, receiver *PublicKey, nonce *Nonce) (*Ciphertext, error)
- type EncrypterOption
- type KeyGenerator
- type KeyGeneratorOption
- type Nonce
- func (n *Nonce) Equal(other *Nonce) bool
- func (n *Nonce) MarshalCBOR() ([]byte, error)
- func (n *Nonce) Mul(other *Nonce) *Nonce
- func (n *Nonce) N() *num.NatPlus
- func (n *Nonce) Op(other *Nonce) *Nonce
- func (n *Nonce) UnmarshalCBOR(data []byte) error
- func (n *Nonce) Value() *znstar.RSAGroupElementUnknownOrder
- func (n *Nonce) ValueCT() *numct.Nat
- type NonceSpace
- type Plaintext
- func (pt *Plaintext) Add(other *Plaintext) *Plaintext
- func (pt *Plaintext) Bytes() []byte
- func (pt *Plaintext) Equal(other *Plaintext) bool
- func (pt *Plaintext) IsLessThanOrEqual(other *Plaintext) bool
- func (pt *Plaintext) MarshalCBOR() ([]byte, error)
- func (pt *Plaintext) N() *num.NatPlus
- func (pt *Plaintext) Neg() *Plaintext
- func (pt *Plaintext) Normalise() *num.Uint
- func (pt *Plaintext) Op(other *Plaintext) *Plaintext
- func (pt *Plaintext) OpInv() *Plaintext
- func (pt *Plaintext) PartialCompare(other *Plaintext) base.PartialOrdering
- func (pt *Plaintext) Sub(other *Plaintext) *Plaintext
- func (pt *Plaintext) UnmarshalCBOR(data []byte) error
- func (pt *Plaintext) Value() *num.Int
- func (pt *Plaintext) ValueCT() *numct.Int
- type PlaintextSpace
- func (pts *PlaintextSpace) Contains(m *Plaintext) bool
- func (pts *PlaintextSpace) FromBytes(b []byte) (*Plaintext, error)
- func (pts *PlaintextSpace) FromInt(x *numct.Int) (*Plaintext, error)
- func (pts *PlaintextSpace) FromNat(x *numct.Nat) (*Plaintext, error)
- func (pts *PlaintextSpace) N() *num.NatPlus
- func (pts *PlaintextSpace) Sample(lowInclusive, highExclusive *Plaintext, prng io.Reader) (*Plaintext, error)
- func (pts *PlaintextSpace) Zero() *Plaintext
- type PrivateKey
- func (sk *PrivateKey) Arithmetic() *modular.OddPrimeSquareFactors
- func (sk *PrivateKey) Equal(other *PrivateKey) bool
- func (sk *PrivateKey) Group() *znstar.PaillierGroupKnownOrder
- func (sk *PrivateKey) MarshalCBOR() ([]byte, error)
- func (sk *PrivateKey) PublicKey() *PublicKey
- func (sk *PrivateKey) UnmarshalCBOR(data []byte) error
- type PublicKey
- func (pk *PublicKey) CiphertextSpace() *CiphertextSpace
- func (pk *PublicKey) Clone() *PublicKey
- func (pk *PublicKey) Equal(other *PublicKey) bool
- func (pk *PublicKey) Group() *znstar.PaillierGroupUnknownOrder
- func (pk *PublicKey) HashCode() base.HashCode
- func (pk *PublicKey) MarshalCBOR() ([]byte, error)
- func (pk *PublicKey) Modulus() *numct.Modulus
- func (pk *PublicKey) N() *numct.Modulus
- func (pk *PublicKey) N2() *numct.Modulus
- func (pk *PublicKey) NonceSpace() *NonceSpace
- func (pk *PublicKey) PlaintextSpace() *PlaintextSpace
- func (pk *PublicKey) UnmarshalCBOR(data []byte) error
- type Scheme
- func (*Scheme) Decrypter(sk *PrivateKey, opts ...DecrypterOption) (*Decrypter, error)
- func (*Scheme) Encrypter(opts ...EncrypterOption) (*Encrypter, error)
- func (*Scheme) Keygen(opts ...KeyGeneratorOption) (*KeyGenerator, error)
- func (*Scheme) Name() encryption.Name
- func (*Scheme) SelfEncrypter(sk *PrivateKey, opts ...SelfEncrypterOption) (*SelfEncrypter, error)
- type SelfEncrypter
- func (se *SelfEncrypter) PrivateKey() *PrivateKey
- func (se *SelfEncrypter) SelfEncrypt(plaintext *Plaintext, prng io.Reader) (*Ciphertext, *Nonce, error)
- func (se *SelfEncrypter) SelfEncryptMany(plaintexts []*Plaintext, prng io.Reader) ([]*Ciphertext, []*Nonce, error)
- func (se *SelfEncrypter) SelfEncryptManyWithNonces(plaintexts []*Plaintext, nonces []*Nonce) ([]*Ciphertext, error)
- func (se *SelfEncrypter) SelfEncryptWithNonce(plaintext *Plaintext, nonce *Nonce) (*Ciphertext, error)
- type SelfEncrypterOption
Constants ¶
const ( Name encryption.Name = "paillier" MinKeyLen = base.IFCKeyLength )
Name is the identifier for the Paillier encryption scheme.
Variables ¶
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 ¶
func (ct *Ciphertext) Value() *znstar.PaillierGroupElementUnknownOrder
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 ¶
func (cts *CiphertextSpace) Group() *znstar.PaillierGroupUnknownOrder
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.
type DecrypterOption ¶
type DecrypterOption = encryption.DecrypterOption[*Decrypter, *Plaintext, *Ciphertext]
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 ¶
type EncrypterOption = encryption.EncrypterOption[*Encrypter, *PublicKey, *Plaintext, *Ciphertext, *Nonce]
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 ¶
type KeyGeneratorOption = encryption.KeyGeneratorOption[*KeyGenerator, *PrivateKey, *PublicKey]
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) MarshalCBOR ¶
MarshalCBOR serialises the nonce to CBOR format.
func (*Nonce) UnmarshalCBOR ¶
UnmarshalCBOR deserializes the nonce from CBOR format.
func (*Nonce) Value ¶
func (n *Nonce) Value() *znstar.RSAGroupElementUnknownOrder
Value returns the underlying RSA group element.
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.
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 ¶
Add adds two plaintexts and returns the result reduced to the centred range.
func (*Plaintext) IsLessThanOrEqual ¶
IsLessThanOrEqual returns true if this plaintext is less than or equal to another.
func (*Plaintext) MarshalCBOR ¶
MarshalCBOR serialises the plaintext to CBOR format.
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) UnmarshalCBOR ¶
UnmarshalCBOR deserializes the plaintext from CBOR format.
type PlaintextSpace ¶
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 ¶
func (sk *PrivateKey) Group() *znstar.PaillierGroupKnownOrder
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) Group ¶
func (pk *PublicKey) Group() *znstar.PaillierGroupUnknownOrder
Group returns the underlying Paillier group with unknown order.
func (*PublicKey) MarshalCBOR ¶
MarshalCBOR serialises the public key to CBOR format.
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 ¶
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.