1. Introduction
In mathematics, for given real numbers a and b, the logarithm is a number x such that . Analogously, in any group G, powers can be defined for all integers k, and the discrete logarithm is an integer k such that . In number theory, the more commonly used term is index: we can write (read "the index of b to the base r modulo m") for if r is a primitive root of m and .
Discrete logarithms are quickly computable in a few special cases. However, no efficient method is known for computing them in general. In cryptography, the computational complexity of the discrete logarithm problem, along with its application, was first proposed in the Diffie–Hellman problem. Several important algorithms in public-key cryptography, such as ElGamal, base their security on the hardness assumption that the discrete logarithm problem (DLP) over carefully chosen groups has no efficient solution ([
4]).
In the
Section 2 we present two algorithms for computing discrete logarithms. The first is for logarithms
, where
. The second is for
, where
. Of course, in both algorithms we also provide the case when
has no solution (see Remark 2.2). In Theorem 2.6 we present a general criterion for when the logarithm
has a solution. And in Proposition 2.7 we present a criterion for when such a logarithm has no solution. In the
Section 3 we present three key examples representing each of the cases considered.
In the
Section 4 we present a very crucial application of discrete logarithms, i.e. how we are able to break the Diffie-Hellman protocol using the algorithms developed in this paper.
Diffie–Hellman (DH) key exchange is a mathematical method of securely exchanging cryptographic keys over a public channel and was one of the first public-key protocols as conceived by Ralph Merkle and named after Whitfield Diffie and Martin Hellman. From [
2,
5] we know that DH is one of the earliest practical examples of public key exchange implemented within the field of cryptography. Published in 1976 by Diffie and Hellman, this is the earliest publicly known work that proposed the idea of a private key and a corresponding public key.
Traditionally, secure encrypted communication between two parties required that they first exchange keys by some secure physical means, such as paper key lists transported by a trusted courier. The Diffie–Hellman key exchange method allows two parties that have no prior knowledge of each other to jointly establish a shared secret key over an insecure channel. This key can then be used to encrypt subsequent communications using a symmetric-key cipher.
Diffie–Hellman is used to secure a variety of Internet services. However, research published in October 2015 ([
1]) suggests that the parameters in use for many DH Internet applications at that time are not strong enough to prevent compromise by very well-funded attackers, such as the security services of some countries.
The scheme was published by Whitfield Diffie and Martin Hellman in 1976 in [
2] but in 1997 it was revealed that James H. Ellis [
3], Clifford Cocks, and Malcolm J. Williamson of GCHQ ([
7]), the British signals intelligence agency, had previously shown in 1969 [
8] how public-key cryptography could be achieved ([
7]).
Although Diffie–Hellman key exchange itself is a non-authenticated key-agreement protocol, it provides the basis for a variety of authenticated protocols, and is used to provide forward secrecy in Transport Layer Security’s ephemeral modes (referred to as EDH or DHE depending on the cipher suite).
The method was followed shortly afterwards by RSA, an implementation of public-key cryptography using asymmetric algorithms.
Expired US patent
([
9]) from 1977 describes the now public-domain algorithm. It credits Hellman, Diffie, and Merkle as inventors.
The simplest and the original implementation in [
2], later formalized as Finite Field Diffie-Hellman in RFC 7919,([
6]) of the protocol uses the multiplicative group of integers modulo
p, where
p is prime, and
g is a primitive root modulo
p. These two values are chosen in this way to ensure that the resulting shared secret can take on any value from 1 to
. Here is an example of the protocol, with non-secret values, and secret values.
2. Discrete Logarithm Calculation Algorithms
In this Section we describe two algorithms for computing discrete logarithms, namely computing in the case where and in the case where .
By definition, the problem comes down to calculating x in the congruence .
Algorithm for computing discrete logarithms , where :
- (1)
We compute the congruence and find .
- (2)
If for some , then is a particular solution and we go to point (6). If , then we go to the next step.
- (3)
Substituting into the initial congruence and after appropriate reduction, we obtain .
- (4)
We calculate the congruence and find .
- (5)
If for some , then is a particular solution and we go to step (6). If , we return to step (1).
- (6)
If x is a particular solution, then the general solution is , where is an Euler function and the number satisfies .
Corollary 2.1. If the algorithm terminates after t steps, then the particular solution is .
Remark 2.2. It is possible that the algorithm will not terminate. Specifically, for some s the sequences will be equal. Then this will mean that has no solution. Unfortunately, we cannot define the conditions when has no solution.
Corollary 2.3. The algorithm implies that if x is a particular solution, then , , …, , if the algorithm terminates in the t-step.
Proof of the algorithm correctness: Assume that a and n are relatively prime. We are looking for x such that .
Assume that x is a solution of the equation . In step 1, we compute from the congruence . If , then is a particular solution. If , then we substitute into the initial congruence, which gives . In step 3, we compute from the congruence . If , then is a particular solution. If , we return to step 1 with a new value .
If the algorithm terminates after t steps, then the particular solution is . Indeed, we have the substitutions , , , …, , . Then: . So the particular solution is .
Since , we know from Euler’s Theorem that . From the previous paragraph, we also know that . Therefore, . So, is a general solution. Such a general solution should satisfy the inequalities . Therefore, from the inequalities we get the inequalities , that is, .
The algorithm may not terminate if for some s the sequences , , …, , are equal. Indeed, let’s assume that and at that point we terminate the algorithm. Then . Then the algorithm never terminates and every s steps the coefficients are repeated. Therefore has no solution. □
We now present an algorithm for computing discrete logarithms when .
Algorithm for computing discrete logarithms , where :
- (1)
We factor n: .
- (2)
For each such that , we proceed to calculate .
- (3)
Since a and are coprime, we use the previous algorithm to compute x.
- (4)
If we compute different x for different i, we use the Chinese Remainder Theorem to obtain the unique result x.
- (5)
If x is a particular solution, then the general solution is , where is an Euler function and the number satisfies .
Remark 2.4. In the above algorithm, in step (3) we can obtain that the given congruence has no solution. Then has no solution.
Before we proceed to prove the correctness of the algorithm, we need the following lemma.
Lemma 2.5. If , where , then , where and .
Proof. Suppose that , where . We want to show that , where d is a divisor of n and .
By assumption,
means that
. In other words, there is an integer
k such that
. Let
d be a factor of
n. This means that
for some integer
m. Substituting
into the equation
, we get:
which means that
. So
.
Now we need to show that . Since , there is a common divisor such that and . Since d is a divisor of n, we can write for some integer . If , then , which contradicts the assumption that . Therefore, . □
Now we give a general criterion when the congruence has a solution if .
Theorem 2.6. The following conditions are equivalent:
- (1)
If , then
- (2)
has a solution where .
Proof. (⇒) Assume that
. This means that
d divides both
a,
b, and
n. Since
d divides
a,
b, and
n, we can write:
,
,
. Then the congruence
can be transformed by substituting the above expressions:
We can divide both sides by
d, since
d is a common divisor:
Now we can see that
is a multiple of
d, and since
d divides
n, we can simplify the congruence to:
In this way, due to the divisibility of d by n, we can simplify the congruence to the form where and are relatively prime (their gcd is 1). This allows us to use theorems from number theory that say that such an equation has a solution.
(⇐) Now suppose that the congruence has a solution where . We will show that .
By assumption, we have that
d divides both
a and
n. Since
, there is an integer
k such that:
Since
d divides
a, we can write
, where
is an integer. Substituting this into the equation, we have:
Since
d divides
, then
d must divide
. That is,
d divides
b, since
d divides
(since
d divides
n). Since
d divides
a,
b, and
n, then
. □
Proposition 2.7. The following conditions are equivalent:
- (1)
or ,
- (2)
, where , has no solution.
Proof. (⇒) Let
and
. Then
,
, where
k,
. So we have
Since
(since
, the left side of the congruence
will always be divisible by
d, while the right side of
b will not be divisible by
d. This means that the left side of the equation will have a factor of
d, and the right side will not, which leads to a contradiction. Therefore,
cannot have a solution when
.
The case when is proved analogously.
(⇐) Now suppose that and . This means that there are numbers and , such that divides a and b, and divides b and n. If divides a and b, then we can write and for some integers and . Similarly, if divides b and n, then we can write and for some integers and . Since divides a and b, and divides b and n, the left side of the congruence will have a factor of , and the right side a factor of . If and are distinct, then b must be divisible by both and . However, if , then a and n have a common factor that does not divide b, leading to a contradiction. □
Proof of the algorithm correctness: By Theorem 2.6 we know that the congruence , where has a solution if and only if .
If
, then the congruence
is equivalent to the system of congruences:
For each such that , we proceed to calculate .
Using Lemma 2.5 we have and we can then use the first algorithm that was proved.
By the Chinese Remainder Theorem we can combine the results from such congruences. □
4. Breaking the Diffie-Hellman Protocol
In this Section, we will show one concrete example showing that our algorithm breaks the Diffie–Hellman protocol. Unfortunately, we are not able to show this in a formal proof due to the complexity of the algorithm.
Alice and Bob publicly agree to use a modulus
and base
(which is a primitive root modulo 23). Alice chooses a secret integer
, then sends Bob
,
(in this example both
A and
a have the same value 4, but this is usually not the case). Bob chooses a secret integer
, then sends Alice
,
. Alice computes
,
. Bob computes
,
. Alice and Bob now share a secret (the number 18). Both Alice and Bob have arrived at the same values because under modulo
p,
Only a and b are kept secret. All the other values – p, g, , and – are sent in the clear. The strength of the scheme comes from the fact that take extremely long times to compute by any known algorithm just from the knowledge of p, g, , and . Such a function that is easy to compute but hard to invert is called a one-way function. Once Alice and Bob compute the shared secret they can use it as an encryption key, known only to them, for sending messages across the same open communications channel.
Of course, much larger values of
a,
b, and
p would be needed to make this example secure, since there are only 23 possible results of
n. However, if
p is a prime of at least 600 digits, then even the fastest modern computers using the fastest known algorithm cannot find a given only
g,
p and
. Such a problem is called the discrete logarithm problem ([
1]).
To summarize, in our example, only Alice’s key and Bob’s key are private and we don’t know about these numbers. We know about , , , .
Now we will try to break this protocol with this example.
- (1)
We want to calculate Alice’s key a from the congruence , which is .
- (2)
According to the algorithm, we calculate the congruence and get , which is not a power of 5.
- (3)
We replace the number 4 with and insert it into . After reduction, we get .
- (4)
We calculate the congruence of and get , which is not a power of 5.
- (5)
We replace the number 10 with and insert it into . After reduction we get .
- (6)
We calculate the congruence of and get , which is a power of 5.
- (7)
We replace the number 2 with the number and insert it into . We get .
- (8)
So , so is the number we are looking for.
- (1)
We want to calculate Bob’s key b from the congruence , which is .
- (2)
According to the algorithm, we calculate the congruence and get , which is not a power of 5.
- (3)
We replace the number 10 with and insert it into . After reduction, we get .
- (4)
We calculate the congruence and get which is a power of 5.
- (5)
We replace the number 2 with the number and insert it into . We get .
- (6)
So , so is the number we are looking for.
Now, without Alice and Bob knowing, we can calculate their common secret number
s:
We broke the Diffie-Hellman protocol.