Submitted:
12 September 2024
Posted:
16 September 2024
You are already at the latest version
Abstract
In this paper we present two algorithms for computing discrete logarithms. We present some properties and show how we break the Diffie-Hellman protocol, which is considered to be very secure.
Keywords:
algorithm
; congruence
; discrete logarithm
; protocol
MSC: Primary 11T71; Secondary 11A07
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. □
3. Some Examples
In this Section we will show three examples illustrating our three cases. In the first example we have the case of using the first algorithm and obtaining the result. In the second case similarly but for the logarithm that has no solution. In the third example we have the use of the second algorithm.
Example 3.1.
We will calculate . So we need to calculate the congruence . We will use our algorithm.
- (1)
- We calculate from the congruence . It is easy to calculate that .
- (2)
- Since , we substitute into . After reduction we get .
- (3)
- We calculate from the congruence . It is easy to calculate that .
- (4)
- Since , we substitute into . After reduction we get .
- (5)
- We calculate from the congruence . It is easy to calculate that .
- (6)
- Since , we substitute into . We get .
- (7)
- From the congruence property we get , so , which is our particular solution.
- (8)
- Since , the general solution is for all .
Example 3.2.
We will calculate . So we need to calculate the congruence . We will use our algorithm.
- (1)
- We calculate from the congruence . It is easy to calculate that .
- (2)
- Since , we substitute into . After reduction we obtain .
- (3)
- We calculate from the congruence . It is easy to calculate that .
- (4)
- Since , we substitute into . After reduction we get .
- (5)
- We calculate from the congruence . It is easy to calculate that .
- (6)
- Since , we substitute into . After reduction we get .
- (7)
- We calculate from the congruence . It is easy to calculate that .
- (8)
- Since , we substitute into . After reduction we get .
- (9)
- We calculate from the congruence . It is easy to calculate that .
- (10)
- Since , we substitute into . After reduction we get .
- (11)
- We calculate from the congruence . It is easy to calculate that .
- (12)
- Since , we substitute into . After reduction we get .
- (13)
- Notice that we repeat the value . Counting further we see that , , …. Therefore has no solution.
Example 3.3.
We will calculate . So we need to calculate the congruence . We will use our algorithm.
- (1)
- We have . So we can consider the system of congruences:
- (2)
- The first two congruences in the system are identical. So let’s calculate only the last one, which is . After reduction we have .
- (3)
- We calculate from the congruence . It is easy to calculate that .
- (4)
- Since , then substituting into we have .
- (5)
- The particular solution is . The general solution is , .
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,
More specifically,
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.
References
- Adrian, David; Imperfect Forward Secrecy: How Diffie–Hellman Fails in Practice, Archived (PDF) from the original on 2015-09-06, (October 2015). [CrossRef]
- Diffie, Whitfield; Hellman, Martin E., New Directions in Cryptography, IEEE Transactions on Information Theory. 22 (6): 644–654, (November 1976).
- Ellis, J. H., The possibility of Non-Secret digital encryption, CESG Research Report. Retrieved 2015-08-28. (January 1970).
- Menezes, A. J.; van Oorschot, P. C.; Vanstone, S. A., Chapter 8.4 ElGamal public-key encryption, Handbook of Applied Cryptography. CRC Press. [CrossRef]
- Merkle, Ralph C., Secure Communications Over Insecure Channels. Communications of the ACM. 21 (4): 294–299, (April 1978), CiteSeerX 10.1.1.364.5157. [CrossRef]
- Wong, David, Key exchange standards, Real World Cryptography. Manning. ISBN 9781617296710 – via Google Books, 2021.
- GCHQ trio recognised for key to secure shopping online, BBC News. 5 October 2010. Retrieved 5 August 2014.
- The Possibility of Secure Secret Digital Encryption, Retrieved 2017-07-08.
- US patent 4200770.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.