elgamal

package
v0.0.0-...-729ab49 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: MIT Imports: 7 Imported by: 0

README

#ElGamal

In cryptography, the ElGamal encryption system is an asymmetric key encryption algorithm for public-key cryptography which is based on the Diffie–Hellman key exchange. It was described by Taher Elgamal in 1985. ElGamal encryption is used in the free GNU Privacy Guard software, recent versions of PGP, and other cryptosystems. The Digital Signature Algorithm (DSA) is a variant of the ElGamal signature scheme, which should not be confused with ElGamal encryption.

ElGamal encryption can be defined over any cyclic group G, such as multiplicative group of integers modulo n. Its security depends upon the difficulty of a certain problem in G related to computing discrete logarithms.

Description

The algorithm ElGamal encryption consists of three components:

  • the key generator
  • the encryption algorithm
  • the decryption algorithm.

The ElGamal paper and the Handbook of Applied Cryptography state to select the private key x in the range { 1 , … , p − 1 } Tsiounis and Yung showed the lower limit as { 1 , … , q − 1 } in On the Security of ElGamal Based Encryption

Documentation

Overview

Package elgamal implements ElGamal encryption, suitable for OpenPGP, as specified in "A Public-Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms," IEEE Transactions on Information Theory, v. IT-31, n. 4, 1985, pp. 469-472.

This form of ElGamal embeds PKCS#1 v1.5 padding, which may make it unsuitable for other protocols. RSA should be used in preference in any case.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMessageTooLong = errors.New("elgamal: message too long")
)

Functions

This section is empty.

Types

type Cypher

type Cypher struct {
	C1, C2, P *big.Int
}

ElGamal cryptosystem ELGamal Ciphertext

func (*Cypher) FromJSON

func (cs *Cypher) FromJSON(json map[string]string) (*Cypher, error)

func (*Cypher) GetJson

func (cs *Cypher) GetJson() ([]byte, error)

Encodes crypto message as JSON

func (*Cypher) Mul

func (cs *Cypher) Mul(cypher1, cypher2 *Cypher) *Cypher

func (*Cypher) ToJSON

func (cs *Cypher) ToJSON() map[string]string

Encodes public key as hexadecimal JSON map

func (*Cypher) UnmarshalJSON

func (cs *Cypher) UnmarshalJSON(bytes []byte) error

type PrivateKey

type PrivateKey struct {
	PublicKey
	X *big.Int
}

PrivateKey represents an ElGamal private key.

func (*PrivateKey) DecryptNoPadding

func (sk *PrivateKey) DecryptNoPadding(cypher *Cypher) (msg []byte, err error)

func (*PrivateKey) DecryptPadded

func (sk *PrivateKey) DecryptPadded(cypher *Cypher) (msg []byte, err error)

DecryptPadded takes two integers, resulting from an ElGamal encryption, and returns the plaintext of the message. An error can result only if the ciphertext is invalid. Users should keep in mind that this is a padding oracle and thus, if exposed to an adaptive chosen ciphertext attack, can be used to break the cryptosystem. See “Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1”, Daniel Bleichenbacher, Advances in Cryptology (Crypto '98),

type PublicKey

type PublicKey struct {
	G, P, Y *big.Int
}

PublicKey represents an ElGamal public key.

func (*PublicKey) EncryptNoPadding

func (pk *PublicKey) EncryptNoPadding(random io.Reader, msg []byte) (cypher *Cypher, err error)

func (*PublicKey) EncryptPadded

func (pk *PublicKey) EncryptPadded(random io.Reader, msg []byte) (*Cypher, error)

EncryptPadded encrypts the given message to the given public key. The result is a pair of integers. Errors can result from reading random, or because msg is too large to be encrypted to the public key.

func (*PublicKey) GetJson

func (pk *PublicKey) GetJson() ([]byte, error)

Encodes public key as hexadecimal JSON

Jump to

Keyboard shortcuts

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