Public key cryptography (PKC) has some features that symmetric key cryptography (SKC) does not and is applied for key management in protocols such as TLS and IPsec.
Discrete log-based ciphers are alternatives to PKC.
One-Way Functions
A function is one-way if
It is not known if one-way functions exist, but there are many functions that are believed to be one-way:
- Multiplication of large primes: the inverse function is integer factorization
- Exponentiation: the inverse function takes discrete logarithms
Trapdoor One-Way Functions
A function such that
Example: let
- The inverse function will be to find
such that - From Euler’s theorem,
for any integer , assuming co-prime to - Hence,
( and are co-prime to each other) -
for some integer - That is,
- Hence,
-
- Integer factorization is assumed to be a hard problem; hence
cannot be computed easily - Hence, only someone with knowledge of
’s factors, the trapdoor, can find the inverse function
Asymmetric Cryptography
Another word to describe public key cryptography.
Public key cryptosystems, such as the Diffie-Hellman key exchange, are designed by using a trapdoor one-way function: the trapdoor is the decryption key.
This allows a public key to be stored in a public directory: anyone can obtain the public key and use it to form an encrypted message that only a person with the private key can decrypt.
Asymmetry: encryption and decryption keys are different. Encryption key is public and known to anybody; the decryption key is private and known only to its owner.
Finding the private key from the public key must be a hard computational problem.
Advantages of shared key/symmetric cryptography:
- Key management is simplified: they dot not need to be transported confidentially
- Digital signatures can be obtained
RSA
Designed in 1977 by Rivest, Shamir, and Adleman from MIT (patent expired 2000).
It is based on integer factorization problem.
Algorithm
Key generation:
- Randomly choose two distinct primes,
and from the set of all primes of a certain size - Compute
- Randomly choose
such that - Compute
- Set the public key
- Set the private key
Encryption:
- Input is value
such that - Compute
Decryption:
- Compute
Any message must be pre-processed:
- Coding it as a number
- Adding randomness (to avoid repeating ciphertext for the same plaintext)
Numerical Example
Key generation:
- Let
, -
-
- Let
-
(Solve using the Euclidean algorithm)
-
Encryption:
- Let
-
Decryption:
Numerical Example 2
Key generation:
- Let
, -
-
- Let
-
Find
-
Solve
using the Euclidean algorithm:
-
Encryption:
- Let
-
Decryption:
Correctness
Decrypting an encrypted message: does
As
Hence,
Now we must show that
Case 1: Coprime to n
Case 2: Multiple of p or q
Since
Supposing that
Applying Fermat’s theorem,
As
- There is a unique solution
to: -
-
- Hence,
-
- And
is satisfied too
Applications
- Message encryption
- Digital signature
- Distribution of key for symmetric key encryption (hybrid encryption)
- User authentication
Implementation
A few implementation details
Key Generation
Generating large primes
- At least 1024 bits recommended for today
- Simple algorithm: select random odd number
of required length, check if prime, incrementing by two if not
Choice of
- Choose at random for best security
- But small values are often used in practice: more efficient
-
is smallest possible value; very fast but has security issues -
is a popular choice -
should be at least to prevent known attacks such as Wiener’s attack
Encryption/decryption
Fast Exponentiation
A square-and-multiply modular exponentiation algorithm.
In binary,
If
Code:
// 2^66 % 100
M = 2 // base
n = 100 // modulus
e = [0, 1, 0, 0, 0, 0, 1] // exponent as bits, LSB first
z = 1; // Result - M^e \bmod n
for(let i = 0; i < e.length - 1; i++) {
if(e[i] == 1) {
z = (z * M) % n;
// z = 1 initially so first multiplication is unnecessary
// Hence e.filter(i => i == 1).length - 1 multiplications
}
M = (M * M) % n; // equals base^{2^{i + 1}}
// When i = 0, M = base^1 - right for the next iteration
// Does not need to be calculated for the i + 1 == e.length
// as the value is used for the next iteration
}
Cost:
- If
the algorithm uses squarings - If
bits of are high, there are multiplications (first computation has , but is initially one) -
is 2048 bits so is at most 2048 bits. Hence, computing requires at most 2048 modular squarings or multiplications - On average, only half of
’s bits are high so there are only 1024 multiplications
Faster Decryption Using CRT
Decrypting
Compute
Solve
Hence,
Then we can output
Speedup
Exponents
Hence, computing each of
Hence, storing
Padding
Encryption directly on the message encoded as a number is bad as it is vulnerable to attacks:
- Building up a dictionary of known plaintexts
- Guessing the plaintext and checking if it encrypts to the ciphertext
- Håstad’s attack
Hence, a padding mechanism must be used to prepare the message for encryption, adding redundancy and randomness.
Håstad’s Attack
The same message
Equations can be solved using the CRT to obtain
Padding Types
- PKCS 1: simple ad-hoc design
- Optimal asymmetric encryption padding (OAEP):
- Bellaware and Rogaway, 1994
- Security proof in a suitable model
- Standardized in IEEE P1363
Security
Attacks
Mostly avoided through the use of standardized padding mechanisms.
Possible attacks:
- Factorization of the modulus
: this is believed to be a hard problem, so should be fine as long as is large enough. - Finding
from and : as hard as factorizing (Miller’s theorem) - Quantum computers: Shor’s theorem can theoretically factorize
in polynomial time - Timing analysis: using timing of decryption process to obtain information about
- Demonstrated in practice in smart cards
- Avoided by randomizing the decryption processes
Practical Problems with Key Generation
- OpenSSL implementation in some systems would use massively-reduced randomness (2008)
- Lenstra in 2012 analyzed 6 million RSA keys:
- Found 4% of keys were identical
- Found 0.2% of keys provided no security as they shared one prime factor with each other
Diffie-Hellman Key Exchange
Two users sharing a secret using only public communication.
Public elements:
- Large prime
- Generator
Alice and Bob randomly select values
Over an insecure channel, Alice sends
Both compute the secret key
Example
Let
- Alice sends
- Bob sends
Both compute
Properties
Security
Relies on the difficulty of the discrete logarithm problem.
If an attacker intercepts
There is no better known way for a passive adversary to find the shared secret.
Authenticated Diffie-Hellman
In the basic protocol, messages are not authenticated: a man-in-the-middle-attack is possible where the attacker acts as a proxy between the two parties, decrypting messages from one party and then re-encrypting messages to send to the other party with the other key.
- Alice chooses
, sending and - Bob chooses
, sending , and - Alice sends
- Both computes
Both parties must know each other’s public signature verification keys,
Static and Ephemeral Diffie-Hellman
The above protocol uses ephemeral keys: keys are used once. In the static protocol:
- Alice chooses a long-term private key
and public key - Bob chooses a long-term private key
and public key - Alice and Bob find a shared secret
which is static -
stays the same until either party changes their public key
-
Elgamal Cryptosystem
Proposed by Elgamal in 1985, turning the Diffie-Hellman protocol into a cryptosystem for encryption and for signature.
Alice combines her ephemeral private key with Bob’s long-term public key
Algorithms
Key generation:
- Select prime
, generator - Select long-term private key
- Compute
- Set the long-term public key
Encryption:
- Select a message
- Choose at random an ephemeral private key
- Compute
and - Compute the ciphertext:
-
Decryption:
- Compute
-
Correctness
- Alice knows ephemeral private key
- Bob knows long-term private key
- Both compute the Diffie-Hellman value for the two public keys:
-
- Diffie-Hellman value
used as the mask for the message
Example
Key generation:
- Prime
- Generator
- Long-term private key
- Compute
- Bob’s public key is
Encryption:
-
Alice wants to send
-
chosen at random -
Computes
Decryption:
-
Bob computes
-
Bob recovers
Security
- Dependent on the difficulty of the discrete logarithm problem: if broken, they could determine the private key
from - Many users could share the same
and - Padding not required: ephemeral key
randomizes the ciphertext
Elliptic Curves
Algebraic structures formed from cubic equations.
Curves are defined over any field.
e.g. set of all
A point on the curve is the identity element, and by defining a binary operation on the points (e.g. multiplication), we can form a group over elliptic curve’s points: the elliptic curve group.
Any elliptic curve can be used but most applications use standardized curves generated in a verifiably random way (e.g. NIST curve P-192 has curve of
Discrete log defined on elliptic curve groups: if elliptic curve operation operation denoted as multiplication, definition is the same as in
Elliptic curve implementations require smaller keys compared to RSA:
| Symmetric key | RSA modulus | EC element length |
|---|---|---|
| 80 | 1024 | 160 |
| 128 | 3072 | 256 |
| 192 | 7680 | 384 |
| 256 | 15360 | 512 |
From Ars:
- Symmetric across horizontal axis
- Any non-vertical line intersects with the curve at most three times. Group operation:
- Infinity,
, is the identity element - Draw line intersecting the two points
- If the points are the same, use the tangent
- Find the third point intersecting the line
- If the points are the same and it is at an inflection point, use the same point
- Find the opposite point
- Infinity,