← Cryptography guide

K044 / Asymmetric encryption, signatures and key exchange

ElGamal

ElGamal encryption · Survey date 2026-12-05

ElGamal is a public-key encryption scheme proposed as an alternative to RSA.

CRYPTOGRAPHY LAB / K044

Cryptography Lab · ElGamal

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Toy educational example

ElGamal (toy p=23, g=5)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Open lab →

Definition and overview
ElGamal is a public-key encryption scheme proposed as an alternative to RSA. Source document ↗
Classification and reversibility
Asymmetric public-key encryption decryptable with private key. Source document ↗
Key or secret requirements
Requires public y, private x and public parameters p,g. Source document ↗
Operating principle and structure
Discrete-log based; encryption uses two exponentiations, decryption one exponentiation and inverse. Source document ↗
Key size, block size and parameters
p,g are domain parameters; bit length of p determines key size. Source document ↗
Security strength and recommendation
Retire ElGamal keys and migrate to RSA/ECC or alternatives. Source document ↗
Known attacks and vulnerabilities
Implementation flaws may allow side-channel attacks (e.g. CVE-2021-33560). Source document ↗
Standards and certification
OpenPGP RFC 9580 specifies ElGamal encryption fields. Source document ↗
Typical uses
Representative use: OpenPGP email encryption. Source document ↗
Implementations, libraries and tools
Libraries include Rust rust-elgamal. Source document ↗
Decryption or decoding
Decrypt through private-key exponentiation and modular inverse. Source document ↗
Advantages
Probabilistic encryption produces different ciphertext for the same plaintext. Source document ↗
Limitations and cautions
Ciphertext about twice plaintext length; storage/transmission overhead. Source document ↗
Distinguishing encryption, encoding and hashing
Reversible public-key encryption, not irreversible hashing or simple encoding. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Sender uses recipient public key and one-time randomness to produce two ciphertext components. Recipient computes plaintext with private key. No real secret keys in examples.

Procedure

Confirm recipient public key, generate fresh randomness, compute/send ciphertext components. Confirm private-key custody, calculate plaintext and check padding/format. Encoding is keyless; ElGamal needs private key.

Scenario

Handle legacy OpenPGP mail or verify existing-key decryption compatibility. New key issuance/long-term storage is not recommended; migrate to RSA/ECC.

Pitfalls and alternatives

Avoid randomness reuse, improper group parameters, inconsistent padding and side-channel-prone implementations. Prefer vetted RSA-OAEP/ECC or hybrid encryption.

References