elgamal

package
v0.0.3-gama Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

elgamal

import "github.com/coinbase/kryptology/pkg/verenc/elgamal"

Index

func NewKeys

func NewKeys(curve *curves.Curve) (*EncryptionKey, *DecryptionKey, error)

NewKeys creates a new key pair for El-Gamal encryption

type CipherText

CipherText represents verifiably encrypted ciphertext using El-Gamal encryption

type CipherText struct {
    // contains filtered or unexported fields
}
func (CipherText) MarshalBinary
func (c CipherText) MarshalBinary() ([]byte, error)
func (CipherText) ToHomomorphicCipherText
func (c CipherText) ToHomomorphicCipherText() *HomomorphicCipherText

ToHomomorphicCipherText returns the El-Gamal points that can be homomorphically multiplied

func (*CipherText) UnmarshalBinary
func (c *CipherText) UnmarshalBinary(data []byte) error

type DecryptionKey

DecryptionKey decrypts verifiable ciphertext and verifies proofs

type DecryptionKey struct {
    // contains filtered or unexported fields
}
func (*DecryptionKey) Decrypt
func (dk *DecryptionKey) Decrypt(cipherText *HomomorphicCipherText) curves.Point

Decrypt returns the resulting point from El-Gamal decryption. No checking is performed whether the ciphertext has been modified. M = H * m = C2 - C1 * x

func (DecryptionKey) EncryptionKey
func (dk DecryptionKey) EncryptionKey() *EncryptionKey

EncryptionKey returns the corresponding encryption key for this decryption key

func (DecryptionKey) MarshalBinary
func (dk DecryptionKey) MarshalBinary() ([]byte, error)

MarshalBinary serializes a key to bytes

func (*DecryptionKey) UnmarshalBinary
func (dk *DecryptionKey) UnmarshalBinary(data []byte) error

UnmarshalBinary deserializes a key from bytes

func (DecryptionKey) VerifiableDecrypt
func (dk DecryptionKey) VerifiableDecrypt(cipherText *CipherText) ([]byte, curves.Scalar, error)

VerifiableDecrypt the ciphertext. This performs verifiable decryption such that the decrypted data is checked against El-Gamal C2 value. If the plaintext does not match, an error is returned been generated by Encrypt

func (DecryptionKey) VerifiableDecryptWithDomain
func (dk DecryptionKey) VerifiableDecryptWithDomain(domain []byte, cipherText *CipherText) ([]byte, curves.Scalar, error)

VerifiableDecryptWithDomain the ciphertext. This performs verifiable decryption such that the decrypted data is checked against El-Gamal C2 value. If the plaintext does not match, an error is returned The Domain component is meant for scenarios where `msg` is used in more than just one setting and should be contextualized. The ciphertext must have been generated by EncryptWithDomain

type EncryptParams

EncryptParams is all the options for doing verifiable encryption. Message must be supplied and is the value to be encrypted. MessageIsHashed defines whether Message represents an unhashed arbitrary byte sequence or already represents a scalar in the elliptic curve. Domain is an optional domain separation tag and used to generate a separate point for the pedersen commitment in El-Gamal ciphertexts. Blinding is blinding factor (bf) of the El-Gamal ciphertext. If nil a bf is generated at random. GenProof indicates whether to return a proof of encryption correctness to the corresponding public key. ProofNonce is the nonce used to generate the one time proof. This value is required if GenProof is true.

type EncryptParams struct {
    MessageIsHashed bool
    Domain          []byte
    Blinding        curves.Scalar
    GenProof        bool
    ProofNonce      []byte
}

type EncryptionKey

EncryptionKey encrypts a message to a ciphertext from which zero-knowledge proofs can be derived

type EncryptionKey struct {
    // contains filtered or unexported fields
}
func (EncryptionKey) HomomorphicEncrypt
func (ek EncryptionKey) HomomorphicEncrypt(msg curves.Scalar) (*HomomorphicCipherText, error)
func (EncryptionKey) MarshalBinary
func (ek EncryptionKey) MarshalBinary() ([]byte, error)

MarshalBinary serializes a key to bytes

func (*EncryptionKey) UnmarshalBinary
func (ek *EncryptionKey) UnmarshalBinary(data []byte) error

UnmarshalBinary deserializes a key from bytes

func (EncryptionKey) VerifiableEncrypt
func (ek EncryptionKey) VerifiableEncrypt(msg []byte, params *EncryptParams) (*CipherText, *ProofVerEnc, error)

VerifiableEncrypt a message using El-Gamal. This also functions as an ECIES encryption algorithm. The advantage here is proofs can be made about the ciphertext versus plain ECIES if desired and/or linked to external proofs.

func (EncryptionKey) VerifyDomainEncryptProof
func (ek EncryptionKey) VerifyDomainEncryptProof(nonce []byte, ciphertext *CipherText, proof *ProofVerEnc) error

VerifyDomainEncryptProof a Proof of Verifiable Encryption that was generated with EncryptDomainAndProve or EncryptDomainAndProveBlinding.

func (EncryptionKey) VerifyEncryptProof
func (ek EncryptionKey) VerifyEncryptProof(nonce []byte, ciphertext *CipherText, proof *ProofVerEnc) error

VerifyEncryptProof a Proof of Verifiable Encryption that was generated with EncryptAndProve or EncryptAndProveBlinding

type HomomorphicCipherText

HomomorphicCipherText represents encrypted ciphertexts that have been added together. The result when decrypted does not include the AEAD encrypted ciphertexts since these are not homomorphic. This is solely for checking results or ignoring the AEAD ciphertext.

type HomomorphicCipherText struct {
    // contains filtered or unexported fields
}
func (HomomorphicCipherText) Add
func (c HomomorphicCipherText) Add(rhs *HomomorphicCipherText) *HomomorphicCipherText

Add combines two ciphertexts multiplicatively homomorphic

func (HomomorphicCipherText) Decrypt
func (c HomomorphicCipherText) Decrypt(dk *DecryptionKey) (curves.Point, error)

Decrypt returns the C2 - C1

func (HomomorphicCipherText) MarshalBinary
func (c HomomorphicCipherText) MarshalBinary() ([]byte, error)
func (*HomomorphicCipherText) UnmarshalBinary
func (c *HomomorphicCipherText) UnmarshalBinary(in []byte) error

type ProofVerEnc

ProofVerEnc is a proof of verifiable encryption for a discrete log

type ProofVerEnc struct {
    // contains filtered or unexported fields
}
func (ProofVerEnc) MarshalBinary
func (pf ProofVerEnc) MarshalBinary() ([]byte, error)
func (*ProofVerEnc) UnmarshalBinary
func (pf *ProofVerEnc) UnmarshalBinary(data []byte) error

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKeys

func NewKeys(curve *curves.Curve) (*EncryptionKey, *DecryptionKey, error)

NewKeys creates a new key pair for El-Gamal encryption

Types

type CipherText

type CipherText struct {
	// contains filtered or unexported fields
}

CipherText represents verifiably encrypted ciphertext using El-Gamal encryption

func (CipherText) MarshalBinary

func (c CipherText) MarshalBinary() ([]byte, error)

func (CipherText) ToHomomorphicCipherText

func (c CipherText) ToHomomorphicCipherText() *HomomorphicCipherText

ToHomomorphicCipherText returns the El-Gamal points that can be homomorphically multiplied

func (*CipherText) UnmarshalBinary

func (c *CipherText) UnmarshalBinary(data []byte) error

type DecryptionKey

type DecryptionKey struct {
	// contains filtered or unexported fields
}

DecryptionKey decrypts verifiable ciphertext and verifies proofs

func (*DecryptionKey) Decrypt

func (dk *DecryptionKey) Decrypt(cipherText *HomomorphicCipherText) curves.Point

Decrypt returns the resulting point from El-Gamal decryption. No checking is performed whether the ciphertext has been modified. M = H * m = C2 - C1 * x

func (DecryptionKey) EncryptionKey

func (dk DecryptionKey) EncryptionKey() *EncryptionKey

EncryptionKey returns the corresponding encryption key for this decryption key

func (DecryptionKey) MarshalBinary

func (dk DecryptionKey) MarshalBinary() ([]byte, error)

MarshalBinary serializes a key to bytes

func (*DecryptionKey) UnmarshalBinary

func (dk *DecryptionKey) UnmarshalBinary(data []byte) error

UnmarshalBinary deserializes a key from bytes

func (DecryptionKey) VerifiableDecrypt

func (dk DecryptionKey) VerifiableDecrypt(cipherText *CipherText) ([]byte, curves.Scalar, error)

VerifiableDecrypt the ciphertext. This performs verifiable decryption such that the decrypted data is checked against El-Gamal C2 value. If the plaintext does not match, an error is returned been generated by Encrypt

func (DecryptionKey) VerifiableDecryptWithDomain

func (dk DecryptionKey) VerifiableDecryptWithDomain(domain []byte, cipherText *CipherText) ([]byte, curves.Scalar, error)

VerifiableDecryptWithDomain the ciphertext. This performs verifiable decryption such that the decrypted data is checked against El-Gamal C2 value. If the plaintext does not match, an error is returned The Domain component is meant for scenarios where `msg` is used in more than just one setting and should be contextualized. The ciphertext must have been generated by EncryptWithDomain

type EncryptParams

type EncryptParams struct {
	MessageIsHashed bool
	Domain          []byte
	Blinding        curves.Scalar
	GenProof        bool
	ProofNonce      []byte
}

EncryptParams is all the options for doing verifiable encryption. Message must be supplied and is the value to be encrypted. MessageIsHashed defines whether Message represents an unhashed arbitrary byte sequence or already represents a scalar in the elliptic curve. Domain is an optional domain separation tag and used to generate a separate point for the pedersen commitment in El-Gamal ciphertexts. Blinding is blinding factor (bf) of the El-Gamal ciphertext. If nil a bf is generated at random. GenProof indicates whether to return a proof of encryption correctness to the corresponding public key. ProofNonce is the nonce used to generate the one time proof. This value is required if GenProof is true.

type EncryptionKey

type EncryptionKey struct {
	// contains filtered or unexported fields
}

EncryptionKey encrypts a message to a ciphertext from which zero-knowledge proofs can be derived

func (EncryptionKey) HomomorphicEncrypt

func (ek EncryptionKey) HomomorphicEncrypt(msg curves.Scalar) (*HomomorphicCipherText, error)

func (EncryptionKey) MarshalBinary

func (ek EncryptionKey) MarshalBinary() ([]byte, error)

MarshalBinary serializes a key to bytes

func (*EncryptionKey) UnmarshalBinary

func (ek *EncryptionKey) UnmarshalBinary(data []byte) error

UnmarshalBinary deserializes a key from bytes

func (EncryptionKey) VerifiableEncrypt

func (ek EncryptionKey) VerifiableEncrypt(msg []byte, params *EncryptParams) (*CipherText, *ProofVerEnc, error)

VerifiableEncrypt a message using El-Gamal. This also functions as an ECIES encryption algorithm. The advantage here is proofs can be made about the ciphertext versus plain ECIES if desired and/or linked to external proofs.

func (EncryptionKey) VerifyDomainEncryptProof

func (ek EncryptionKey) VerifyDomainEncryptProof(nonce []byte, ciphertext *CipherText, proof *ProofVerEnc) error

VerifyDomainEncryptProof a Proof of Verifiable Encryption that was generated with EncryptDomainAndProve or EncryptDomainAndProveBlinding.

func (EncryptionKey) VerifyEncryptProof

func (ek EncryptionKey) VerifyEncryptProof(nonce []byte, ciphertext *CipherText, proof *ProofVerEnc) error

VerifyEncryptProof a Proof of Verifiable Encryption that was generated with EncryptAndProve or EncryptAndProveBlinding

type HomomorphicCipherText

type HomomorphicCipherText struct {
	// contains filtered or unexported fields
}

HomomorphicCipherText represents encrypted ciphertexts that have been added together. The result when decrypted does not include the AEAD encrypted ciphertexts since these are not homomorphic. This is solely for checking results or ignoring the AEAD ciphertext.

func (HomomorphicCipherText) Add

Add combines two ciphertexts multiplicatively homomorphic

func (HomomorphicCipherText) Decrypt

Decrypt returns the C2 - C1

func (HomomorphicCipherText) MarshalBinary

func (c HomomorphicCipherText) MarshalBinary() ([]byte, error)

func (*HomomorphicCipherText) UnmarshalBinary

func (c *HomomorphicCipherText) UnmarshalBinary(in []byte) error

type ProofVerEnc

type ProofVerEnc struct {
	// contains filtered or unexported fields
}

ProofVerEnc is a proof of verifiable encryption for a discrete log

func (ProofVerEnc) MarshalBinary

func (pf ProofVerEnc) MarshalBinary() ([]byte, error)

func (*ProofVerEnc) UnmarshalBinary

func (pf *ProofVerEnc) UnmarshalBinary(data []byte) error

Jump to

Keyboard shortcuts

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