paillier

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrExceedMaxRetry is returned if we retried over times
	ErrExceedMaxRetry = errors.New("exceed max retries")
	//ErrInvalidInput is returned if the input is invalid
	ErrInvalidInput = errors.New("invalid input")
	//ErrInvalidMessage is returned if the message is invalid
	ErrInvalidMessage = errors.New("invalid message")
	//ErrSmallPublicKeySize is returned if the size of public key is small
	ErrSmallPublicKeySize = errors.New("small public key")
)
View Source
var File_github_com_getamis_alice_crypto_homo_paillier_message_proto protoreflect.FileDescriptor

Functions

func NewPedersenOpenParameter

func NewPedersenOpenParameter(n, s, t *big.Int) (*zkPaillier.PederssenOpenParameter, error)

Types

type Paillier

type Paillier struct {
	*PublicKey
	PrivateKey *PrivateKey
}

func NewPaillier

func NewPaillier(keySize int) (*Paillier, error)

func NewPaillierSafePrime

func NewPaillierSafePrime(keySize int) (*Paillier, error)

func NewPaillierUnSafe

func NewPaillierUnSafe(keySize int, isSafe bool) (*Paillier, error)

Warning: No check the size of public key.

func (*Paillier) Decrypt

func (p *Paillier) Decrypt(cBytes []byte) ([]byte, error)

Decrypt computes the plaintext from the ciphertext

func (*Paillier) GetNthRoot

func (p *Paillier) GetNthRoot() (*big.Int, error)

func (*Paillier) GetPrivLambda

func (p *Paillier) GetPrivLambda() *big.Int

func (*Paillier) GetPrivMu

func (p *Paillier) GetPrivMu() *big.Int

func (*Paillier) GetPrivP

func (p *Paillier) GetPrivP() *big.Int

func (*Paillier) GetPrivPhiN

func (p *Paillier) GetPrivPhiN() *big.Int

func (*Paillier) GetPrivQ

func (p *Paillier) GetPrivQ() *big.Int

func (*Paillier) GetPubG

func (p *Paillier) GetPubG() *big.Int

func (*Paillier) GetPubN

func (p *Paillier) GetPubN() *big.Int

func (*Paillier) NewPedersenParameterByPaillier

func (paillier *Paillier) NewPedersenParameterByPaillier() (*PederssenParameter, error)

By paillier

type PedPrivKey

type PedPrivKey struct {
	LambdaN *big.Int
	Euler   *big.Int
}

type PedPubKey

type PedPubKey struct {
	N *big.Int
	S *big.Int
	T *big.Int
}

type PederssenParameter

type PederssenParameter struct {
	P      *big.Int
	Q      *big.Int
	Eulern *big.Int
	Lambda *big.Int

	PedersenOpenParameter *zkPaillier.PederssenOpenParameter
}

func (*PederssenParameter) GetEulerValue

func (ped *PederssenParameter) GetEulerValue() *big.Int

func (*PederssenParameter) GetP

func (ped *PederssenParameter) GetP() *big.Int

func (*PederssenParameter) GetQ

func (ped *PederssenParameter) GetQ() *big.Int

func (*PederssenParameter) Getlambda

func (ped *PederssenParameter) Getlambda() *big.Int

type PrivateKey

type PrivateKey struct {
	P      *big.Int
	Q      *big.Int
	Lambda *big.Int // λ=lcm(p−1, q−1)
	PhiN   *big.Int // (p-1) * (q-1)
	Mu     *big.Int // μ=(L(g^λ mod n^2))^-1 mod n
}

Refer: https://en.wikipedia.org/wiki/Paillier_cryptosystem PrivateKey is (λ, μ)

type PubKeyMessage

type PubKeyMessage struct {
	Proof *zkproof.IntegerFactorizationProofMessage `protobuf:"bytes,1,opt,name=proof,proto3" json:"proof,omitempty"`
	G     []byte                                    `protobuf:"bytes,2,opt,name=g,proto3" json:"g,omitempty"`
	// contains filtered or unexported fields
}

func (*PubKeyMessage) Descriptor deprecated

func (*PubKeyMessage) Descriptor() ([]byte, []int)

Deprecated: Use PubKeyMessage.ProtoReflect.Descriptor instead.

func (*PubKeyMessage) GetG

func (x *PubKeyMessage) GetG() []byte

func (*PubKeyMessage) GetProof

func (*PubKeyMessage) ProtoMessage

func (*PubKeyMessage) ProtoMessage()

func (*PubKeyMessage) ProtoReflect

func (x *PubKeyMessage) ProtoReflect() protoreflect.Message

func (*PubKeyMessage) Reset

func (x *PubKeyMessage) Reset()

func (*PubKeyMessage) String

func (x *PubKeyMessage) String() string

func (*PubKeyMessage) ToPubkey

func (msg *PubKeyMessage) ToPubkey() (*PublicKey, error)

type PublicKey

type PublicKey struct {
	N *big.Int
	G *big.Int

	Msg *PubKeyMessage

	// cache value
	NSquare *big.Int
}

PublicKey is (n, g)

func ToPaillierPubKeyWithSpecialG

func ToPaillierPubKeyWithSpecialG(ped *zkPaillier.PederssenOpenParameter) *PublicKey

func (*PublicKey) Add

func (pub *PublicKey) Add(c1Bytes []byte, c2Bytes []byte) ([]byte, error)

1. Check that c1, c2 is correct. 2. Choose (r, N)=1 with r in [1, N-1] randomly. 3. Compute c1*c2*r^N mod N^2.

func (*PublicKey) Encrypt

func (pub *PublicKey) Encrypt(mBytes []byte) ([]byte, error)

func (*PublicKey) EncryptWithOutputSalt

func (pub *PublicKey) EncryptWithOutputSalt(m *big.Int) (*big.Int, *big.Int, error)

func (*PublicKey) GetG

func (pub *PublicKey) GetG() *big.Int

func (*PublicKey) GetMessageRange

func (pub *PublicKey) GetMessageRange(fieldOrder *big.Int) *big.Int

func (*PublicKey) GetN

func (pub *PublicKey) GetN() *big.Int

func (*PublicKey) GetNSquare

func (pub *PublicKey) GetNSquare() *big.Int

func (*PublicKey) MulConst

func (pub *PublicKey) MulConst(cBytes []byte, scalar *big.Int) ([]byte, error)

1. Check that c is correct. 2. Compute scalar mod N. 3. Choose (r, N)=1 with r in [1, N-1] randomly. 4. Compute c^scalar*r^N mod N^2.

func (*PublicKey) ToPubKeyBytes

func (pub *PublicKey) ToPubKeyBytes() []byte

func (*PublicKey) VerifyEnc

func (pub *PublicKey) VerifyEnc([]byte) error

In paillier, we cannot verify enc message. Therefore, we always return nil.

Jump to

Keyboard shortcuts

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