Asymmetric Encryption
Public-key cryptography for key exchange, digital signatures, and identity verification
-- Ed25519 for signatures, X25519 for key exchange, RSA-2048+ only for legacy
compatibility
When to Use
- Designing a system where parties need to communicate securely without a pre-shared
secret
- Implementing digital signatures for code signing, document signing, or API request
authentication
- Choosing key types for TLS certificates, SSH keys, or JWT signing
- Evaluating RSA vs elliptic curve algorithms for a new system
- Implementing a key exchange protocol for end-to-end encryption
- Reviewing certificate chains, trust models, or PKI configurations
Threat Context
Asymmetric encryption defends against man-in-the-middle attacks during key exchange,
impersonation (via digital signatures that prove identity), and the key distribution
problem (how to establish a shared secret when no secure channel yet exists). RSA with
keys shorter than 2048 bits is factorable with modern computational resources -- RSA-768
was factored in 2009 by Kleinjung et al., and NIST deprecated 1024-bit RSA in 2013. The
looming threat of quantum computing (Shor's algorithm) will eventually break both RSA
and elliptic curve cryptography by solving integer factorization and the discrete
logarithm problem in polynomial time, driving the transition to post-quantum algorithms
(ML-KEM/Kyber, ML-DSA/Dilithium). Current ECC and RSA-3072+ remain secure against all
known classical attacks.
Instructions
For digital signatures, default to Ed25519. Ed25519 (Edwards-curve Digital
Signature Algorithm over Curve25519) provides 128-bit security with significant
practical advantages: fast signing and verification (tens of thousands of operations
per second on commodity hardware), short signatures (64 bytes) and public keys (32
bytes), and deterministic signature generation. Determinism eliminates the catastrophic
class of bugs where a faulty or biased random number generator leaks the private key
through signatures -- the PlayStation 3 ECDSA key extraction (2010) exploited exactly
this flaw, where Sony reused a static nonce in ECDSA signatures, allowing attackers to
algebraically recover the private signing key. Ed25519 is supported by OpenSSH (since
6.5), TLS 1.3, JWT (EdDSA algorithm), GPG, and all modern cryptographic libraries.
For key exchange, default to X25519 (ECDHE). X25519 performs Elliptic Curve
Diffie-Hellman key exchange over Curve25519, producing a 32-byte shared secret from
two parties' public keys without either party transmitting the secret. X25519 is the
key exchange mechanism in TLS 1.3, the Signal Protocol (used by Signal, WhatsApp, and
others), WireGuard VPN, and the Noise Protocol Framework. Always use ephemeral keys
(ECDHE -- Elliptic Curve Diffie-Hellman Ephemeral) to achieve forward secrecy: each
session generates fresh key pairs, computes the shared secret, derives session keys,
and discards the ephemeral private keys. If a long-term key is later compromised, past
sessions remain protected because the ephemeral keys no longer exist.
Use RSA only for legacy compatibility. RSA-2048 is the minimum acceptable key
size; RSA-3072 is recommended for new deployments that must use RSA (e.g., for
compatibility with systems that do not support ECC). RSA keys are significantly larger
than EC keys for equivalent security: 3072-bit RSA provides approximately 128-bit
security, matching Curve25519 with a key 96x larger. RSA signing and decryption are
computationally expensive (modular exponentiation with large exponents), making RSA
substantially slower than Ed25519 for signature operations. For RSA encryption, use
OAEP padding (PKCS#1 v2.x) exclusively -- never use PKCS#1 v1.5 padding, which is
vulnerable to Bleichenbacher's adaptive chosen-ciphertext attack (1998), a practical
attack that recovers plaintext through repeated oracle queries. For RSA signatures,
prefer PSS padding (PKCS#1 v2.1) over PKCS#1 v1.5 signatures.
Never encrypt large data with asymmetric encryption directly. Asymmetric
encryption is orders of magnitude slower than symmetric encryption and has inherent
message size limits (RSA-2048 with OAEP can encrypt at most ~245 bytes). Use hybrid
encryption: generate a random symmetric key (e.g., AES-256), encrypt the bulk data
with the symmetric key using an AEAD mode (AES-256-GCM), then encrypt the symmetric
key with the recipient's public key. The recipient decrypts the symmetric key with
their private key, then decrypts the data. TLS, PGP, and CMS/S/MIME all use this
exact pattern.
Protect private keys absolutely. Private keys must never appear in logs, be
transmitted over unencrypted channels, or be stored in plaintext on disk. For highest
security, store private keys in Hardware Security Modules (HSMs) or Trusted Platform
Modules (TPMs) where the key material never leaves the secure hardware -- signing
operations are performed inside the HSM. For software-managed keys, encrypt them at
rest with a passphrase or a key encryption key (KEK). Rotate keys on any suspicion of
compromise. Use separate key pairs for different purposes: one pair for signing and a
different pair for key exchange or encryption, because compromise of one does not then
compromise the other.
Understand the security level mapping. Security level describes the computational
effort required to break the algorithm, expressed in bits of equivalent symmetric key
strength:
| Algorithm |
Key Size |
Security Level |
| RSA |
2048-bit |
~112-bit |
| RSA |
3072-bit |
~128-bit |
| RSA |
4096-bit |
~140-bit |
| P-256 (secp256r1/prime256v1) |
256-bit |
~128-bit |
| P-384 (secp384r1) |
384-bit |
~192-bit |
| Curve25519 (Ed25519/X25519) |
256-bit |
~128-bit |
For new systems targeting 128-bit security, Curve25519 is optimal: smallest keys,
fastest operations, simplest implementation (constant-time by design, resistant to
timing side-channels), and no NSA-related provenance concerns that some practitioners
associate with the NIST P-curves.
Details
RSA Internals (Conceptual)
RSA security relies on the computational difficulty of factoring the product of two large
primes. Key generation: choose two large random primes p and q (each ~1536 bits for
RSA-3072), compute n = p * q (the modulus), choose public exponent e (conventionally
65537 = 2^16 + 1, which balances security and verification speed), compute private
exponent d as the modular inverse of e mod lcm(p-1, q-1). The public key is (n, e); the
private key is (n, d). Encryption: ciphertext c = m^e mod n. Decryption: plaintext
m = c^d mod n. Security depends on the assumption that factoring n into p and q is
computationally infeasible for sufficiently large n. The best known classical factoring
algorithm (General Number Field Sieve) has sub-exponential but super-polynomial
complexity, making RSA-3072 secure for the foreseeable classical computing era.
Elliptic Curve Internals (Conceptual)
ECC security relies on the difficulty of the Elliptic Curve Discrete Logarithm Problem
(ECDLP). An elliptic curve over a finite field defines a group structure where point
addition and scalar multiplication are efficient, but the inverse operation (given points
P and Q = kP, finding the scalar k) is computationally infeasible. Key generation: choose
a random scalar k (private key) from the curve's order, compute Q = kP (public key)
where P is the curve's generator point. ECDSA and EdDSA signatures work by encoding a
proof that the signer knows k without revealing it. ECDH key exchange works by having
Alice compute kA * QB = k_A * kB * P and Bob compute kB * QA = k_B * kA * P,
arriving at the same shared point. The best known classical attack against ECDLP on
well-chosen curves is Pollard's rho algorithm with O(sqrt(n)) complexity, making 256-bit
curves provide 128-bit security.
Forward Secrecy with Ephemeral Keys
In TLS 1.3, the handshake mandates ephemeral key exchange. Both client and server
generate fresh X25519 (or P-256) key pairs for each session. The shared secret is
computed via ECDH, used to derive session keys through HKDF, and the ephemeral private
keys are immediately discarded. If the server's long-term private key is later
compromised (through theft, legal compulsion, or cryptanalysis), past session keys cannot
be recovered because the ephemeral private keys no longer exist. This is forward secrecy,
also called perfect forward secrecy (PFS). TLS 1.3 removed all non-forward-secret cipher
suites (static RSA key exchange), making forward secrecy mandatory. Any protocol design
should follow this example.
Post-Quantum Considerations
Shor's algorithm on a sufficiently large, fault-tolerant quantum computer solves integer
factorization and ECDLP in polynomial time, breaking RSA and all standard elliptic curve
schemes regardless of key size. NIST finalized post-quantum standards in 2024: ML-KEM
(Module-Lattice Key Encapsulation Mechanism, derived from Kyber) for key exchange, and
ML-DSA (Module-Lattice Digital Signature Algorithm, derived from Dilithium) for digital
signatures. Hybrid approaches that combine X25519 + ML-KEM-768 are being deployed in
production (Chrome, Cloudflare) to provide quantum resistance while maintaining classical
security as a fallback. Post-quantum signatures (ML-DSA) are significantly larger than
Ed25519 signatures (2420 bytes vs 64 bytes), which has implications for
bandwidth-constrained protocols. Begin planning migration paths now: inventory all
asymmetric cryptographic usage, identify systems most vulnerable to "harvest now, decrypt
later" attacks (where adversaries record encrypted traffic today for future quantum
decryption), and prioritize those for hybrid or post-quantum migration.
Anti-Patterns
RSA-1024 or shorter keys. RSA-768 was factored in 2009; RSA-1024 is within reach
of well-funded adversaries and is deprecated by every major standards body. Minimum
acceptable is RSA-2048; prefer RSA-3072 for new systems or, better, switch to
Ed25519/X25519.
PKCS#1 v1.5 padding for RSA encryption. Bleichenbacher's adaptive
chosen-ciphertext attack (1998) allows an attacker who can submit ciphertexts to an
RSA decryption oracle to recover plaintext through approximately one million queries.
The ROBOT attack (2017) demonstrated that this vulnerability persisted in major TLS
implementations nearly 20 years later. Use OAEP (PKCS#1 v2.x) padding exclusively
for RSA encryption. For signatures, PSS padding is preferred.
Static Diffie-Hellman (no ephemeral keys). Using the same DH or ECDH key pair for
all sessions eliminates forward secrecy. If the static private key is compromised, all
past and future traffic encrypted under that key is decryptable. Always use ephemeral
key exchange (ECDHE) -- generate a fresh key pair per session and discard the private
key after the shared secret is derived.
Encrypting large payloads directly with RSA. RSA-2048 with OAEP can encrypt at
most 245 bytes per operation (key size minus padding overhead). Attempting to encrypt
files, messages, or database records directly with RSA requires chunking, which
introduces complexity, potential padding vulnerabilities, and extreme performance
penalties. Use hybrid encryption: symmetric cipher for bulk data, RSA/ECC only for
encrypting the symmetric key.
Trusting self-signed certificates in production. A self-signed certificate proves
that the presenter possesses the corresponding private key, but provides no identity
verification. Without a certificate authority (CA) chain validating the binding between
the public key and the claimed identity, any attacker can generate their own
self-signed certificate and intercept traffic via man-in-the-middle. Use certificates
issued by trusted CAs (Let's Encrypt for public-facing, internal CA for service mesh).
Certificate pinning provides additional protection against CA compromise but requires
careful rotation planning.
Reusing nonces in ECDSA signing. ECDSA (unlike EdDSA/Ed25519) requires a unique
random nonce k for each signature. If k is reused across two signatures with the same
private key, the private key can be algebraically recovered from the two signatures.
This is not a theoretical concern -- the Sony PS3 breach (2010) and multiple Bitcoin
wallet compromises exploited exactly this flaw. If you must use ECDSA, use RFC 6979
deterministic nonce generation. Prefer Ed25519 which is deterministic by design.
1---2name: security-asymmetric-encryption3description: Asymmetric Encryption4metadata:5 source: https://skillmd.com/skills/intense-visions/security-asymmetric-encryption6---7# Asymmetric Encryption89> Public-key cryptography for key exchange, digital signatures, and identity verification10> -- Ed25519 for signatures, X25519 for key exchange, RSA-2048+ only for legacy11> compatibility1213## When to Use1415- Designing a system where parties need to communicate securely without a pre-shared16 secret17- Implementing digital signatures for code signing, document signing, or API request18 authentication19- Choosing key types for TLS certificates, SSH keys, or JWT signing20- Evaluating RSA vs elliptic curve algorithms for a new system21- Implementing a key exchange protocol for end-to-end encryption22- Reviewing certificate chains, trust models, or PKI configurations2324## Threat Context2526Asymmetric encryption defends against man-in-the-middle attacks during key exchange,27impersonation (via digital signatures that prove identity), and the key distribution28problem (how to establish a shared secret when no secure channel yet exists). RSA with29keys shorter than 2048 bits is factorable with modern computational resources -- RSA-76830was factored in 2009 by Kleinjung et al., and NIST deprecated 1024-bit RSA in 2013. The31looming threat of quantum computing (Shor's algorithm) will eventually break both RSA32and elliptic curve cryptography by solving integer factorization and the discrete33logarithm problem in polynomial time, driving the transition to post-quantum algorithms34(ML-KEM/Kyber, ML-DSA/Dilithium). Current ECC and RSA-3072+ remain secure against all35known classical attacks.3637## Instructions38391. **For digital signatures, default to Ed25519.** Ed25519 (Edwards-curve Digital40 Signature Algorithm over Curve25519) provides 128-bit security with significant41 practical advantages: fast signing and verification (tens of thousands of operations42 per second on commodity hardware), short signatures (64 bytes) and public keys (3243 bytes), and deterministic signature generation. Determinism eliminates the catastrophic44 class of bugs where a faulty or biased random number generator leaks the private key45 through signatures -- the PlayStation 3 ECDSA key extraction (2010) exploited exactly46 this flaw, where Sony reused a static nonce in ECDSA signatures, allowing attackers to47 algebraically recover the private signing key. Ed25519 is supported by OpenSSH (since48 6.5), TLS 1.3, JWT (EdDSA algorithm), GPG, and all modern cryptographic libraries.49502. **For key exchange, default to X25519 (ECDHE).** X25519 performs Elliptic Curve51 Diffie-Hellman key exchange over Curve25519, producing a 32-byte shared secret from52 two parties' public keys without either party transmitting the secret. X25519 is the53 key exchange mechanism in TLS 1.3, the Signal Protocol (used by Signal, WhatsApp, and54 others), WireGuard VPN, and the Noise Protocol Framework. Always use ephemeral keys55 (ECDHE -- Elliptic Curve Diffie-Hellman Ephemeral) to achieve forward secrecy: each56 session generates fresh key pairs, computes the shared secret, derives session keys,57 and discards the ephemeral private keys. If a long-term key is later compromised, past58 sessions remain protected because the ephemeral keys no longer exist.59603. **Use RSA only for legacy compatibility.** RSA-2048 is the minimum acceptable key61 size; RSA-3072 is recommended for new deployments that must use RSA (e.g., for62 compatibility with systems that do not support ECC). RSA keys are significantly larger63 than EC keys for equivalent security: 3072-bit RSA provides approximately 128-bit64 security, matching Curve25519 with a key 96x larger. RSA signing and decryption are65 computationally expensive (modular exponentiation with large exponents), making RSA66 substantially slower than Ed25519 for signature operations. For RSA encryption, use67 OAEP padding (PKCS#1 v2.x) exclusively -- never use PKCS#1 v1.5 padding, which is68 vulnerable to Bleichenbacher's adaptive chosen-ciphertext attack (1998), a practical69 attack that recovers plaintext through repeated oracle queries. For RSA signatures,70 prefer PSS padding (PKCS#1 v2.1) over PKCS#1 v1.5 signatures.71724. **Never encrypt large data with asymmetric encryption directly.** Asymmetric73 encryption is orders of magnitude slower than symmetric encryption and has inherent74 message size limits (RSA-2048 with OAEP can encrypt at most ~245 bytes). Use hybrid75 encryption: generate a random symmetric key (e.g., AES-256), encrypt the bulk data76 with the symmetric key using an AEAD mode (AES-256-GCM), then encrypt the symmetric77 key with the recipient's public key. The recipient decrypts the symmetric key with78 their private key, then decrypts the data. TLS, PGP, and CMS/S/MIME all use this79 exact pattern.80815. **Protect private keys absolutely.** Private keys must never appear in logs, be82 transmitted over unencrypted channels, or be stored in plaintext on disk. For highest83 security, store private keys in Hardware Security Modules (HSMs) or Trusted Platform84 Modules (TPMs) where the key material never leaves the secure hardware -- signing85 operations are performed inside the HSM. For software-managed keys, encrypt them at86 rest with a passphrase or a key encryption key (KEK). Rotate keys on any suspicion of87 compromise. Use separate key pairs for different purposes: one pair for signing and a88 different pair for key exchange or encryption, because compromise of one does not then89 compromise the other.90916. **Understand the security level mapping.** Security level describes the computational92 effort required to break the algorithm, expressed in bits of equivalent symmetric key93 strength:9495 | Algorithm | Key Size | Security Level |96 | ---------------------------- | -------- | -------------- |97 | RSA | 2048-bit | ~112-bit |98 | RSA | 3072-bit | ~128-bit |99 | RSA | 4096-bit | ~140-bit |100 | P-256 (secp256r1/prime256v1) | 256-bit | ~128-bit |101 | P-384 (secp384r1) | 384-bit | ~192-bit |102 | Curve25519 (Ed25519/X25519) | 256-bit | ~128-bit |103104 For new systems targeting 128-bit security, Curve25519 is optimal: smallest keys,105 fastest operations, simplest implementation (constant-time by design, resistant to106 timing side-channels), and no NSA-related provenance concerns that some practitioners107 associate with the NIST P-curves.108109## Details110111### RSA Internals (Conceptual)112113RSA security relies on the computational difficulty of factoring the product of two large114primes. Key generation: choose two large random primes p and q (each ~1536 bits for115RSA-3072), compute n = p \* q (the modulus), choose public exponent e (conventionally11665537 = 2^16 + 1, which balances security and verification speed), compute private117exponent d as the modular inverse of e mod lcm(p-1, q-1). The public key is (n, e); the118private key is (n, d). Encryption: ciphertext c = m^e mod n. Decryption: plaintext119m = c^d mod n. Security depends on the assumption that factoring n into p and q is120computationally infeasible for sufficiently large n. The best known classical factoring121algorithm (General Number Field Sieve) has sub-exponential but super-polynomial122complexity, making RSA-3072 secure for the foreseeable classical computing era.123124### Elliptic Curve Internals (Conceptual)125126ECC security relies on the difficulty of the Elliptic Curve Discrete Logarithm Problem127(ECDLP). An elliptic curve over a finite field defines a group structure where point128addition and scalar multiplication are efficient, but the inverse operation (given points129P and Q = kP, finding the scalar k) is computationally infeasible. Key generation: choose130a random scalar k (private key) from the curve's order, compute Q = kP (public key)131where P is the curve's generator point. ECDSA and EdDSA signatures work by encoding a132proof that the signer knows k without revealing it. ECDH key exchange works by having133Alice compute k*A * Q*B = k_A * k*B * P and Bob compute k*B * Q*A = k_B * k*A * P,134arriving at the same shared point. The best known classical attack against ECDLP on135well-chosen curves is Pollard's rho algorithm with O(sqrt(n)) complexity, making 256-bit136curves provide 128-bit security.137138### Forward Secrecy with Ephemeral Keys139140In TLS 1.3, the handshake mandates ephemeral key exchange. Both client and server141generate fresh X25519 (or P-256) key pairs for each session. The shared secret is142computed via ECDH, used to derive session keys through HKDF, and the ephemeral private143keys are immediately discarded. If the server's long-term private key is later144compromised (through theft, legal compulsion, or cryptanalysis), past session keys cannot145be recovered because the ephemeral private keys no longer exist. This is forward secrecy,146also called perfect forward secrecy (PFS). TLS 1.3 removed all non-forward-secret cipher147suites (static RSA key exchange), making forward secrecy mandatory. Any protocol design148should follow this example.149150### Post-Quantum Considerations151152Shor's algorithm on a sufficiently large, fault-tolerant quantum computer solves integer153factorization and ECDLP in polynomial time, breaking RSA and all standard elliptic curve154schemes regardless of key size. NIST finalized post-quantum standards in 2024: ML-KEM155(Module-Lattice Key Encapsulation Mechanism, derived from Kyber) for key exchange, and156ML-DSA (Module-Lattice Digital Signature Algorithm, derived from Dilithium) for digital157signatures. Hybrid approaches that combine X25519 + ML-KEM-768 are being deployed in158production (Chrome, Cloudflare) to provide quantum resistance while maintaining classical159security as a fallback. Post-quantum signatures (ML-DSA) are significantly larger than160Ed25519 signatures (2420 bytes vs 64 bytes), which has implications for161bandwidth-constrained protocols. Begin planning migration paths now: inventory all162asymmetric cryptographic usage, identify systems most vulnerable to "harvest now, decrypt163later" attacks (where adversaries record encrypted traffic today for future quantum164decryption), and prioritize those for hybrid or post-quantum migration.165166## Anti-Patterns1671681. **RSA-1024 or shorter keys.** RSA-768 was factored in 2009; RSA-1024 is within reach169 of well-funded adversaries and is deprecated by every major standards body. Minimum170 acceptable is RSA-2048; prefer RSA-3072 for new systems or, better, switch to171 Ed25519/X25519.1721732. **PKCS#1 v1.5 padding for RSA encryption.** Bleichenbacher's adaptive174 chosen-ciphertext attack (1998) allows an attacker who can submit ciphertexts to an175 RSA decryption oracle to recover plaintext through approximately one million queries.176 The ROBOT attack (2017) demonstrated that this vulnerability persisted in major TLS177 implementations nearly 20 years later. Use OAEP (PKCS#1 v2.x) padding exclusively178 for RSA encryption. For signatures, PSS padding is preferred.1791803. **Static Diffie-Hellman (no ephemeral keys).** Using the same DH or ECDH key pair for181 all sessions eliminates forward secrecy. If the static private key is compromised, all182 past and future traffic encrypted under that key is decryptable. Always use ephemeral183 key exchange (ECDHE) -- generate a fresh key pair per session and discard the private184 key after the shared secret is derived.1851864. **Encrypting large payloads directly with RSA.** RSA-2048 with OAEP can encrypt at187 most 245 bytes per operation (key size minus padding overhead). Attempting to encrypt188 files, messages, or database records directly with RSA requires chunking, which189 introduces complexity, potential padding vulnerabilities, and extreme performance190 penalties. Use hybrid encryption: symmetric cipher for bulk data, RSA/ECC only for191 encrypting the symmetric key.1921935. **Trusting self-signed certificates in production.** A self-signed certificate proves194 that the presenter possesses the corresponding private key, but provides no identity195 verification. Without a certificate authority (CA) chain validating the binding between196 the public key and the claimed identity, any attacker can generate their own197 self-signed certificate and intercept traffic via man-in-the-middle. Use certificates198 issued by trusted CAs (Let's Encrypt for public-facing, internal CA for service mesh).199 Certificate pinning provides additional protection against CA compromise but requires200 careful rotation planning.2012026. **Reusing nonces in ECDSA signing.** ECDSA (unlike EdDSA/Ed25519) requires a unique203 random nonce k for each signature. If k is reused across two signatures with the same204 private key, the private key can be algebraically recovered from the two signatures.205 This is not a theoretical concern -- the Sony PS3 breach (2010) and multiple Bitcoin206 wallet compromises exploited exactly this flaw. If you must use ECDSA, use RFC 6979207 deterministic nonce generation. Prefer Ed25519 which is deterministic by design.