Documentation ¶
Overview ¶
Package elgamal provides primitives required by the ElGamal encryption scheme. It's based on Python's implementation: https://github.com/asonnino/coconut/blob/master/coconut/utils.py.
Index ¶
- Variables
- func Decrypt(g *bpgroup.BpGroup, pk *PrivateKey, enc *Encryption) *Curve.ECP
- func Keygen(g *bpgroup.BpGroup) (*PrivateKey, *PublicKey)
- func ValidateKeyPair(pk *PrivateKey, pub *PublicKey) bool
- type Encryption
- func (e *Encryption) C1() *Curve.ECP
- func (e *Encryption) C2() *Curve.ECP
- func (e *Encryption) FromProto(pe *ProtoEncryption) error
- func (e *Encryption) MarshalBinary() ([]byte, error)
- func (e *Encryption) ToProto() (*ProtoEncryption, error)
- func (e *Encryption) UnmarshalBinary(data []byte) error
- func (e *Encryption) Validate() bool
- type EncryptionResult
- type PrivateKey
- func (pk *PrivateKey) D() *Curve.BIG
- func (pk *PrivateKey) FromPEMFile(f string) error
- func (pk *PrivateKey) FromProto(ppk *ProtoPrivateKey) error
- func (pk *PrivateKey) MarshalBinary() ([]byte, error)
- func (pk *PrivateKey) ToPEMFile(f string) error
- func (pk *PrivateKey) ToProto() (*ProtoPrivateKey, error)
- func (pk *PrivateKey) UnmarshalBinary(data []byte) error
- func (pk *PrivateKey) Validate() bool
- type ProtoEncryption
- func (*ProtoEncryption) Descriptor() ([]byte, []int)
- func (m *ProtoEncryption) GetC1() []byte
- func (m *ProtoEncryption) GetC2() []byte
- func (*ProtoEncryption) ProtoMessage()
- func (m *ProtoEncryption) Reset()
- func (m *ProtoEncryption) String() string
- func (m *ProtoEncryption) XXX_DiscardUnknown()
- func (m *ProtoEncryption) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ProtoEncryption) XXX_Merge(src proto.Message)
- func (m *ProtoEncryption) XXX_Size() int
- func (m *ProtoEncryption) XXX_Unmarshal(b []byte) error
- type ProtoPrivateKey
- func (*ProtoPrivateKey) Descriptor() ([]byte, []int)
- func (m *ProtoPrivateKey) GetD() []byte
- func (*ProtoPrivateKey) ProtoMessage()
- func (m *ProtoPrivateKey) Reset()
- func (m *ProtoPrivateKey) String() string
- func (m *ProtoPrivateKey) XXX_DiscardUnknown()
- func (m *ProtoPrivateKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ProtoPrivateKey) XXX_Merge(src proto.Message)
- func (m *ProtoPrivateKey) XXX_Size() int
- func (m *ProtoPrivateKey) XXX_Unmarshal(b []byte) error
- type ProtoPublicKey
- func (*ProtoPublicKey) Descriptor() ([]byte, []int)
- func (m *ProtoPublicKey) GetG() []byte
- func (m *ProtoPublicKey) GetGamma() []byte
- func (m *ProtoPublicKey) GetP() []byte
- func (*ProtoPublicKey) ProtoMessage()
- func (m *ProtoPublicKey) Reset()
- func (m *ProtoPublicKey) String() string
- func (m *ProtoPublicKey) XXX_DiscardUnknown()
- func (m *ProtoPublicKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ProtoPublicKey) XXX_Merge(src proto.Message)
- func (m *ProtoPublicKey) XXX_Size() int
- func (m *ProtoPublicKey) XXX_Unmarshal(b []byte) error
- type PublicKey
- func (pub *PublicKey) FromPEMFile(f string) error
- func (pub *PublicKey) FromProto(ppub *ProtoPublicKey) error
- func (pub *PublicKey) G() *Curve.ECP
- func (pub *PublicKey) Gamma() *Curve.ECP
- func (pub *PublicKey) MarshalBinary() ([]byte, error)
- func (pub *PublicKey) P() *Curve.BIG
- func (pub *PublicKey) ToPEMFile(f string) error
- func (pub *PublicKey) ToProto() (*ProtoPublicKey, error)
- func (pub *PublicKey) UnmarshalBinary(data []byte) error
- func (pub *PublicKey) Validate() bool
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnmarshalLength represents an error thrown during unmarshal when the byte arrays have unexpected lengths. ErrUnmarshalLength = errors.New("the byte array provided is incomplete") )
Functions ¶
func Decrypt ¶
func Decrypt(g *bpgroup.BpGroup, pk *PrivateKey, enc *Encryption) *Curve.ECP
Decrypt takes the ElGamal encryption of a message and returns a point on the G1 curve that represents original h^m.
func Keygen ¶
func Keygen(g *bpgroup.BpGroup) (*PrivateKey, *PublicKey)
Keygen generates private and public keys required for ElGamal encryption scheme. Passing coconut.Params as an argument would cause issues with cyclic dependencies, passing BpGroup in that case is sufficient.
func ValidateKeyPair ¶
func ValidateKeyPair(pk *PrivateKey, pub *PublicKey) bool
ValidateKeyPair checks if the ElGamal keypair was correctly formed.
Types ¶
type Encryption ¶
type Encryption struct {
// contains filtered or unexported fields
}
Encryption are the two points on the G1 curve that represent encryption of message in form of h^m.
func Encrypt ¶
func Encrypt(g *bpgroup.BpGroup, pub *PublicKey, m *Curve.BIG, h *Curve.ECP) (*Encryption, *Curve.BIG)
Encrypt encrypts the given message in the form of h^m, where h is a point on the G1 curve using the given public key. The random k is returned alongside the encryption as it is required by the Coconut Scheme to create proofs of knowledge.
func NewEncryptionFromPoints ¶
func NewEncryptionFromPoints(c1 *Curve.ECP, c2 *Curve.ECP) *Encryption
NewEncryptionFromPoints wraps two points on G1 curve as ElGamal Encryption.
func (*Encryption) C1 ¶
func (e *Encryption) C1() *Curve.ECP
C1 returns first group element of the ElGamal Encryption.
func (*Encryption) C2 ¶
func (e *Encryption) C2() *Curve.ECP
C2 returns second group element of the ElGamal Encryption.
func (*Encryption) FromProto ¶
func (e *Encryption) FromProto(pe *ProtoEncryption) error
FromProto takes a protobuf representation of the object and unmarshals its attributes.
func (*Encryption) MarshalBinary ¶
func (e *Encryption) MarshalBinary() ([]byte, error)
MarshalBinary is an implementation of a method on the BinaryMarshaler interface defined in https://golang.org/pkg/encoding/
func (*Encryption) ToProto ¶
func (e *Encryption) ToProto() (*ProtoEncryption, error)
ToProto creates a protobuf representation of the object.
func (*Encryption) UnmarshalBinary ¶
func (e *Encryption) UnmarshalBinary(data []byte) error
UnmarshalBinary is an implementation of a method on the BinaryUnmarshaler interface defined in https://golang.org/pkg/encoding/
func (*Encryption) Validate ¶
func (e *Encryption) Validate() bool
Validate checks for nil elements in the encryption.
type EncryptionResult ¶
type EncryptionResult struct {
// contains filtered or unexported fields
}
EncryptionResult encapsulates entire result of ElGamal encryption, including random k.
func NewEncryptionResult ¶
func NewEncryptionResult(enc *Encryption, k *Curve.BIG) *EncryptionResult
NewEncryptionResult returns new instance of EncryptionResult from provided encryption and k.
func (*EncryptionResult) Enc ¶
func (er *EncryptionResult) Enc() *Encryption
Enc returns encryption part of the EncryptionResult.
func (*EncryptionResult) K ¶
func (er *EncryptionResult) K() *Curve.BIG
K returns random k part of the EncryptionResult.
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey represents an ElGamal private key.
func NewPrivateKey ¶
func NewPrivateKey(d *Curve.BIG) *PrivateKey
NewPrivateKey returns new instance of ElGamal private key with the provided argument.
func (*PrivateKey) D ¶
func (pk *PrivateKey) D() *Curve.BIG
D returns the appropriate part of the ElGamal private key.
func (*PrivateKey) FromPEMFile ¶
func (pk *PrivateKey) FromPEMFile(f string) error
FromPEMFile reads out the secret key from a PEM file at path f.
func (*PrivateKey) FromProto ¶
func (pk *PrivateKey) FromProto(ppk *ProtoPrivateKey) error
FromProto takes a protobuf representation of the object and unmarshals its attributes.
func (*PrivateKey) MarshalBinary ¶
func (pk *PrivateKey) MarshalBinary() ([]byte, error)
MarshalBinary is an implementation of a method on the BinaryMarshaler interface defined in https://golang.org/pkg/encoding/
func (*PrivateKey) ToPEMFile ¶
func (pk *PrivateKey) ToPEMFile(f string) error
ToPEMFile writes out the secret key to a PEM file at path f.
func (*PrivateKey) ToProto ¶
func (pk *PrivateKey) ToProto() (*ProtoPrivateKey, error)
ToProto creates a protobuf representation of the object.
func (*PrivateKey) UnmarshalBinary ¶
func (pk *PrivateKey) UnmarshalBinary(data []byte) error
UnmarshalBinary is an implementation of a method on the BinaryUnmarshaler interface defined in https://golang.org/pkg/encoding/
func (*PrivateKey) Validate ¶
func (pk *PrivateKey) Validate() bool
Validate checks for nil elements in the key.
type ProtoEncryption ¶
type ProtoEncryption struct { C1 []byte `protobuf:"bytes,1,opt,name=C1,json=c1,proto3" json:"C1,omitempty"` C2 []byte `protobuf:"bytes,2,opt,name=C2,json=c2,proto3" json:"C2,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*ProtoEncryption) Descriptor ¶
func (*ProtoEncryption) Descriptor() ([]byte, []int)
func (*ProtoEncryption) GetC1 ¶
func (m *ProtoEncryption) GetC1() []byte
func (*ProtoEncryption) GetC2 ¶
func (m *ProtoEncryption) GetC2() []byte
func (*ProtoEncryption) ProtoMessage ¶
func (*ProtoEncryption) ProtoMessage()
func (*ProtoEncryption) Reset ¶
func (m *ProtoEncryption) Reset()
func (*ProtoEncryption) String ¶
func (m *ProtoEncryption) String() string
func (*ProtoEncryption) XXX_DiscardUnknown ¶
func (m *ProtoEncryption) XXX_DiscardUnknown()
func (*ProtoEncryption) XXX_Marshal ¶
func (m *ProtoEncryption) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ProtoEncryption) XXX_Merge ¶
func (m *ProtoEncryption) XXX_Merge(src proto.Message)
func (*ProtoEncryption) XXX_Size ¶
func (m *ProtoEncryption) XXX_Size() int
func (*ProtoEncryption) XXX_Unmarshal ¶
func (m *ProtoEncryption) XXX_Unmarshal(b []byte) error
type ProtoPrivateKey ¶
type ProtoPrivateKey struct { D []byte `protobuf:"bytes,1,opt,name=D,json=d,proto3" json:"D,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
just to keep it consistent when/if writing to a PEM file
func (*ProtoPrivateKey) Descriptor ¶
func (*ProtoPrivateKey) Descriptor() ([]byte, []int)
func (*ProtoPrivateKey) GetD ¶
func (m *ProtoPrivateKey) GetD() []byte
func (*ProtoPrivateKey) ProtoMessage ¶
func (*ProtoPrivateKey) ProtoMessage()
func (*ProtoPrivateKey) Reset ¶
func (m *ProtoPrivateKey) Reset()
func (*ProtoPrivateKey) String ¶
func (m *ProtoPrivateKey) String() string
func (*ProtoPrivateKey) XXX_DiscardUnknown ¶
func (m *ProtoPrivateKey) XXX_DiscardUnknown()
func (*ProtoPrivateKey) XXX_Marshal ¶
func (m *ProtoPrivateKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ProtoPrivateKey) XXX_Merge ¶
func (m *ProtoPrivateKey) XXX_Merge(src proto.Message)
func (*ProtoPrivateKey) XXX_Size ¶
func (m *ProtoPrivateKey) XXX_Size() int
func (*ProtoPrivateKey) XXX_Unmarshal ¶
func (m *ProtoPrivateKey) XXX_Unmarshal(b []byte) error
type ProtoPublicKey ¶
type ProtoPublicKey struct { P []byte `protobuf:"bytes,1,opt,name=P,json=p,proto3" json:"P,omitempty"` G []byte `protobuf:"bytes,2,opt,name=G,json=g,proto3" json:"G,omitempty"` Gamma []byte `protobuf:"bytes,3,opt,name=Gamma,json=gamma,proto3" json:"Gamma,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*ProtoPublicKey) Descriptor ¶
func (*ProtoPublicKey) Descriptor() ([]byte, []int)
func (*ProtoPublicKey) GetG ¶
func (m *ProtoPublicKey) GetG() []byte
func (*ProtoPublicKey) GetGamma ¶
func (m *ProtoPublicKey) GetGamma() []byte
func (*ProtoPublicKey) GetP ¶
func (m *ProtoPublicKey) GetP() []byte
func (*ProtoPublicKey) ProtoMessage ¶
func (*ProtoPublicKey) ProtoMessage()
func (*ProtoPublicKey) Reset ¶
func (m *ProtoPublicKey) Reset()
func (*ProtoPublicKey) String ¶
func (m *ProtoPublicKey) String() string
func (*ProtoPublicKey) XXX_DiscardUnknown ¶
func (m *ProtoPublicKey) XXX_DiscardUnknown()
func (*ProtoPublicKey) XXX_Marshal ¶
func (m *ProtoPublicKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ProtoPublicKey) XXX_Merge ¶
func (m *ProtoPublicKey) XXX_Merge(src proto.Message)
func (*ProtoPublicKey) XXX_Size ¶
func (m *ProtoPublicKey) XXX_Size() int
func (*ProtoPublicKey) XXX_Unmarshal ¶
func (m *ProtoPublicKey) XXX_Unmarshal(b []byte) error
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey represents an ElGamal public key.
func NewPublicKey ¶
NewPublicKey returns new instance of ElGamal public key with the provided arguments.
func PublicKeyFromPrivate ¶
func PublicKeyFromPrivate(pk *PrivateKey) *PublicKey
PublicKeyFromPrivate returns a public key instance corresponding to the provided private key.
func (*PublicKey) FromPEMFile ¶
FromPEMFile reads out the secret key from a PEM file at path f.
func (*PublicKey) FromProto ¶
func (pub *PublicKey) FromProto(ppub *ProtoPublicKey) error
FromProto takes a protobuf representation of the object and unmarshals its attributes.
func (*PublicKey) MarshalBinary ¶
MarshalBinary is an implementation of a method on the BinaryMarshaler interface defined in https://golang.org/pkg/encoding/
func (*PublicKey) ToProto ¶
func (pub *PublicKey) ToProto() (*ProtoPublicKey, error)
ToProto creates a protobuf representation of the object.
func (*PublicKey) UnmarshalBinary ¶
UnmarshalBinary is an implementation of a method on the BinaryUnmarshaler interface defined in https://golang.org/pkg/encoding/