Documentation ¶
Index ¶
- Variables
- func AdjustDecryptedDomain(pk *PubKey, plaintext *big.Int) (*big.Int, error)
- func AdjustPlaintextDomain(pk *PubKey, plaintext *big.Int) (*big.Int, error)
- func EncryptAndNonce(pubKey *PubKey, plainText *big.Int) (*big.Int, *big.Int, error)
- func EncryptWithNonce(pubKey *PubKey, r *big.Int, pt *big.Int) (*big.Int, error)
- func GetCiphertextFromHex(content string) (string, error)
- func GetCiphertextHex(cipher string) (string, error)
- func GetPrivateKeyHex(sk *PrvKey) string
- func GetPublicKeyHex(pk *PubKey) string
- func ReadCiphertextFromFile(file string) (string, error)
- func WriteCiphertextToFile(cipher string, file string) error
- func WriteEncryptedPrivateKeyToFile(sk *PrvKey, file, password string) error
- func WritePrivateKeyToFile(sk *PrvKey, file string) error
- func WritePublicKeyToFile(pk *PubKey, file string) error
- type Ciphertext
- type PrvKey
- type PubKey
- func (key *PubKey) AddCiphertext(cipher1, cipher2 *Ciphertext) (*Ciphertext, error)
- func (key *PubKey) AddPlaintext(cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)
- func (key *PubKey) ChecksumVerify(ct *Ciphertext) bool
- func (key *PubKey) Encrypt(plainText *big.Int) (*Ciphertext, error)
- func (key *PubKey) Marshal() ([]byte, error)
- func (key *PubKey) NumMul(cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)
- func (key *PubKey) SubByConstant(pubKey *PubKey, cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)
- func (key *PubKey) SubCiphertext(cipher1, cipher2 *Ciphertext) (*Ciphertext, error)
- func (key *PubKey) SubPlaintext(cipher *Ciphertext, constant *big.Int) (*Ciphertext, error)
- func (key *PubKey) Unmarshal(pubKeyBytes []byte) error
Constants ¶
This section is empty.
Variables ¶
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 AdjustPlaintextDomain ¶
func EncryptAndNonce ¶
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 ¶
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 WriteEncryptedPrivateKeyToFile ¶
Types ¶
type Ciphertext ¶
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 ReadEncryptedPrivateKeyFromFile ¶
func (*PrvKey) Decrypt ¶
func (key *PrvKey) Decrypt(cipherText *Ciphertext) (*big.Int, error)
Decrypt decrypts the passed cipher text.
func (*PrvKey) Marshal ¶
Marshal encodes the PrvKey as a 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 (*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 ¶
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)