Documentation ¶
Index ¶
- Variables
- func KeyGen(pl *pool.Pool) (pk *PublicKey, sk *SecretKey)
- func ValidateN(n *safenum.Modulus) error
- func ValidatePrime(p *safenum.Nat) error
- type Ciphertext
- func (ct *Ciphertext) Add(pk *PublicKey, ct2 *Ciphertext) *Ciphertext
- func (ct Ciphertext) Clone() *Ciphertext
- func (*Ciphertext) Domain() string
- func (ct *Ciphertext) Equal(ctA *Ciphertext) bool
- func (ct *Ciphertext) MarshalBinary() ([]byte, error)
- func (ct *Ciphertext) Mul(pk *PublicKey, k *safenum.Int) *Ciphertext
- func (ct *Ciphertext) Nat() *safenum.Nat
- func (ct *Ciphertext) Randomize(pk *PublicKey, nonce *safenum.Nat) *safenum.Nat
- func (ct *Ciphertext) UnmarshalBinary(data []byte) error
- func (ct *Ciphertext) WriteTo(w io.Writer) (int64, error)
- type PublicKey
- func (PublicKey) Domain() string
- func (pk PublicKey) Enc(m *safenum.Int) (*Ciphertext, *safenum.Nat)
- func (pk PublicKey) EncWithNonce(m *safenum.Int, nonce *safenum.Nat) *Ciphertext
- func (pk PublicKey) Equal(other *PublicKey) bool
- func (pk *PublicKey) Modulus() *arith.Modulus
- func (pk *PublicKey) ModulusSquared() *arith.Modulus
- func (pk *PublicKey) N() *safenum.Modulus
- func (pk PublicKey) ValidateCiphertexts(cts ...*Ciphertext) bool
- func (pk *PublicKey) WriteTo(w io.Writer) (int64, error)
- type SecretKey
- func (sk *SecretKey) Dec(ct *Ciphertext) (*safenum.Int, error)
- func (sk *SecretKey) DecWithRandomness(ct *Ciphertext) (*safenum.Int, *safenum.Nat, error)
- func (sk SecretKey) GeneratePedersen() (*pedersen.Parameters, *safenum.Nat)
- func (sk *SecretKey) P() *safenum.Nat
- func (sk *SecretKey) Phi() *safenum.Nat
- func (sk *SecretKey) Q() *safenum.Nat
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ValidateN ¶
ValidateN performs basic checks to make sure the modulus is valid: - log₂(n) = params.BitsPaillier. - n is odd.
func ValidatePrime ¶
ValidatePrime checks whether p is a suitable prime for Paillier. Checks: - log₂(p) ≡ params.BitsBlumPrime. - p ≡ 3 (mod 4). - q := (p-1)/2 is prime.
Types ¶
type Ciphertext ¶
type Ciphertext struct {
// contains filtered or unexported fields
}
Ciphertext represents an integer of the for (1+N)ᵐρᴺ (mod N²), representing the encryption of m ∈ ℤₙˣ.
func (*Ciphertext) Add ¶
func (ct *Ciphertext) Add(pk *PublicKey, ct2 *Ciphertext) *Ciphertext
Add sets ct to the homomorphic sum ct ⊕ ct₂. ct ← ct•ct₂ (mod N²).
func (*Ciphertext) Domain ¶
func (*Ciphertext) Domain() string
Domain implements hash.WriterToWithDomain, and separates this type within hash.Hash.
func (*Ciphertext) Equal ¶
func (ct *Ciphertext) Equal(ctA *Ciphertext) bool
Equal check whether ct ≡ ctₐ (mod N²).
func (*Ciphertext) MarshalBinary ¶
func (ct *Ciphertext) MarshalBinary() ([]byte, error)
func (*Ciphertext) Mul ¶
func (ct *Ciphertext) Mul(pk *PublicKey, k *safenum.Int) *Ciphertext
Mul sets ct to the homomorphic multiplication of k ⊙ ct. ct ← ctᵏ (mod N²).
func (*Ciphertext) Nat ¶
func (ct *Ciphertext) Nat() *safenum.Nat
func (*Ciphertext) Randomize ¶
Randomize multiplies the ciphertext's nonce by a newly generated one. ct ← ct ⋅ nonceᴺ (mod N²). If nonce is nil, a random one is generated. The receiver is updated, and the nonce update is returned.
func (*Ciphertext) UnmarshalBinary ¶
func (ct *Ciphertext) UnmarshalBinary(data []byte) error
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey is a Paillier public key. It is represented by a modulus N.
func NewPublicKey ¶
NewPublicKey returns an initialized paillier.PublicKey and caches N, N² and (N-1)/2.
func (PublicKey) Domain ¶
Domain implements hash.WriterToWithDomain, and separates this type within hash.Hash.
func (PublicKey) Enc ¶
Enc returns the encryption of m under the public key pk. The nonce used to encrypt is returned.
The message m must be in the range [-(N-1)/2, …, (N-1)/2] and panics otherwise.
ct = (1+N)ᵐρᴺ (mod N²).
func (PublicKey) EncWithNonce ¶
EncWithNonce returns the encryption of m under the public key pk. The nonce is not returned.
The message m must be in the range [-(N-1)/2, …, (N-1)/2] and panics otherwise
ct = (1+N)ᵐρᴺ (mod N²).
func (*PublicKey) Modulus ¶
Modulus returns an arith.Modulus for N which may allow for accelerated exponentiation when this public key was generated from a secret key.
func (*PublicKey) ModulusSquared ¶
ModulusSquared returns an arith.Modulus for N² which may allow for accelerated exponentiation when this public key was generated from a secret key.
func (PublicKey) ValidateCiphertexts ¶
func (pk PublicKey) ValidateCiphertexts(cts ...*Ciphertext) bool
ValidateCiphertexts checks if all ciphertexts are in the correct range and coprime to N² ct ∈ [1, …, N²-1] AND GCD(ct,N²) = 1.
type SecretKey ¶
type SecretKey struct { *PublicKey // contains filtered or unexported fields }
SecretKey is the secret key corresponding to a Public Paillier Key.
A public key is a modulus N, and the secret key contains the information needed to factor N into two primes, P and Q. This allows us to decrypt values encrypted using this modulus.
func NewSecretKey ¶
NewSecretKey generates primes p and q suitable for the scheme, and returns the initialized SecretKey.
func NewSecretKeyFromPrimes ¶
NewSecretKeyFromPrimes generates a new SecretKey. Assumes that P and Q are prime.
func (*SecretKey) Dec ¶
func (sk *SecretKey) Dec(ct *Ciphertext) (*safenum.Int, error)
Dec decrypts c and returns the plaintext m ∈ ± (N-2)/2. It returns an error if gcd(c, N²) != 1 or if c is not in [1, N²-1].
func (*SecretKey) DecWithRandomness ¶
DecWithRandomness returns the underlying plaintext, as well as the randomness used.
func (SecretKey) GeneratePedersen ¶
func (sk SecretKey) GeneratePedersen() (*pedersen.Parameters, *safenum.Nat)