Quantum Discrete Log
Quantum Discrete Log
Quantum Discrete Log
Abstract
We revisit Shor’s algorithm for computing discrete logarithms in F∗p on
a quantum computer and modify it to compute logarithms d in groups hgi
of prime order q in the special case where d ≪ q. As a stepping stone to
performing this modification, we first introduce a modified algorithm for
computing logarithms on the general interval 0 < d < q for comparison.
We demonstrate conservative lower bounds on the success probability
of our algorithms in both the general and the special case. In both cases,
our algorithms initially set the index registers to a uniform superposition
of all states, compared to p − 1 states in Shor’s original algorithm.
In the special case where d ≪ q, our algorithm uses 3 dlog2 de qubits
for the two index registers and computes two QFTs of size 2dlog2 de and
22 dlog2 de , compared to 2 blog2 qc qubits for the index registers and two
QFTs both of size 2blog2 qc in the general case.
A quantum circuit for computing [a − bd] g is furthermore required,
where 0 ≤ a < 22 dlog2 de and 0 ≤ b < 2dlog2 de in the special case, compared
to 0 ≤ a, b < 2blog2 qc in the general case.
This implies that the complexity of computing discrete logarithms on
a quantum computer can be made to depend not only on the choice of
group, and on its order q, but also on the logarithm d.
In the special case where d ≪ q, our algorithm does not require q to
be prime. It may hence be generalized to finite abelian groups.
1 Introduction
In a groundbreaking paper [10] from 1994, subsequently extended and revised
in a later publication [11], Shor introduced polynomial time quantum computer
algorithms for factoring integers over Z and for computing discrete logarithms
in the multiplicative group F∗p of the finite field Fp .
Although Shor’s algorithm for computing discrete logarithms was originally
described for F∗p , it may be generalized to any finite abelian group, provided the
group operation may be implemented efficiently using quantum circuits. This
generalization was first described by Boneh and Lipton [1]. Shor’s algorithms
may furthermore be generalized by perceiving them as algorithms for solving
special instances of the finite abelian hidden subgroup problem [4].
∗ KTH Royal Institute of Technology, SE-100 44 Stockholm, Sweden and Swedish NCSA,
Swedish Armed Forces, SE-107 85 Stockholm, Sweden. Use ekera@kth.se to e-mail author.
1
Virtually all asymmetric cryptographic schemes that are widely deployed
today rely on the computational intractability of either the integer factoring
problem or the discrete logarithm problem in some abelian group that meets
the above criteria. Consequently the work of Shor has the potential to greatly
impact the field of asymmetric cryptography.
In this paper, we revisit Shor’s algorithm for solving the discrete logarithm
problem. In section 1.1 below, we introduce the discrete logarithm problem,
discuss the choice of groups and introduce a special case of the discrete logarithm
problem that we study in this paper along with a rationale for why it merits
study. In section 1.2 we proceed to describe our contributions and in section
1.3 we give an overview of the remainder of this paper.
2
field sieve (GNFS). The time complexity of the GNFS when adapted to compute
1 1 2
discrete logarithms is O(exp[( 649 ) (ln p) (ln ln p) ]) as shown in Schirokauer’s
3 3 3
3
This implies that any algorithm for efficiently computing d when d ≪ q
may be used to also efficiently compute d when d is on a short interval.
2 Notation
In this section, we introduce some notation for norms, rounding operations and
modular reduction operations that are used throughout this paper.
4
• due denotes u rounded to the closest integer greater than or equal to u.
• u mod n denotes u reduced modulo n and constrained to the interval
0 ≤ u mod n < n.
3 Quantum computing
In this section, we provide a brief introduction to quantum computing and
introduce some notation and terminology that is used throughout this paper.
The contents of this section is to some extent a layman’s description of quantum
computing, in that it may leave out or overly simplify important details.
There is much more to be said on the topic of quantum computing. However,
such elaborations are beyond the scope of this paper. For more information, the
reader is instead referred to [3]. The extended paper [11] by Shor also contains
a very good introduction and many references to the literature.
5
3.2 Measurements
Similar to reading a register in a classical computer, the qubits in a register may
be observed by measuring the quantum system.
The result of such a measurement is to collapse the quantum system, and
hence the system function, to a distinct state. The probability of the system
function | Ψ i collapsing to | j i is | cj |2 = a2j .
6
collapses to some distinct state | j i then | Ψ2 i collapses accordingly to a system
that represents the original probability distribution conditioned on | Ψ1 i = | j i.
The ability of quantum systems to be in superpositions of many different
quantum states simultaneously, of quantum circuits to operate on all states in
a quantum system simultaneously, and of quantum systems to be entangled,
seemingly enables quantum computers to perform certain computations much
faster than is theoretically possible with classical computers.
It is easy to see that the QFT is a unitary operator and hence permissible. It
is furthermore efficient from an implementation perspective, see Shor’s original
paper [11] for more information.
Perceive the terms in the sum as vectors in C. If the vectors are of approximately
the same norm and point in approximately the same direction, then the norm
of their sum is likely to be great giving rise to a large probability. For k such
that this is indeed the case, constructive interference is said to arise.
The claim below summarizes the notion of constructive interference that we
use in this paper. Note that in our case, all vectors in the sum are unit vectors.
7
π
Claim 1. Let θj for 0 ≤ j < N be phase angles such that | θj | ≤ 4. Then
2
−1 iθ
NX
N2
e j
≥ .
j=0
2
Proof.
2 2 2
N −1 N −1 N −1 2
≥N
X iθ X X
e j
= (cos θ j + i sin θ j ) ≥ cos θj
j=0
j=0
j=0
2
π
since for j on the interval 0 ≤ j < N we have | θj | ≤ 4 which implies
1
√ ≤ cos θj ≤ 1
2
and so the claim follows.
8
2. Compute [a] g [−b] x and store the result in the third register
` `
2 −1 2 −1
1 X X
|Ψi = ` · | a, b, [a] g [−b] x i
2 a=0
b=0
` `
2X −1 2X −1
1
= · | a, b, [a − bd] g i .
2` a = 0
b=0
where the sum is over all pairs (a, b) that produce this specific e.
1. Since e = a − bd mod q we have a = e + bd mod q so
e + bd
aj + bk = ((e + bd) mod q)j + bk = ej + bdj − jq + bk
q
since u mod q = u − bu/qc q. Therefore the probability may be written
2
1 X 2πi e + bd
· exp ej + b(dj + k) − jq .
24` 2` q
b
9
2. Extracting the term containing e yields
2 X 2
1 2πi 2πi e + bd
· exp ej · exp b(dj + k) − jq .
24` 2` 2` q
| {z } b
=1
and k ≡ fj − dj (mod 2` ).
10
Proof. From definition 1 it follows that a pair (j, k) where j is an integer on the
interval 0 ≤ j < 2` and k = fj − dj mod 2` is good if
d
| {jq}2` | ≤ 2`−4 and | α{jq}2` − bα{jq}2` e | ≤ 2−3 where α= ∈ R.
q
To lower-bound the number of j that meet this definition, consider the points
and partition the space into rectangles of side length 2`−4 in the x-direction and
2−3 in the y-direction. If pj1 and pj2 are any two points
As two numbers that are equal modulo 2` and both less than 2`−1 are in fact
equal, equations (1) and (2) imply
Hence, if pj1 and pj2 are in the same rectangle, with j2 ≥ j1 , and we let
Our goal is now to count the number of points that fulfill these conditions.
11
Let Ri denote the number of points that fall into rectangle i. There are then
Ri (Ri + 1) R2
> i (6)
2 2
pairwise combinations (pj1 , pj2 ) of the Ri points in rectangle i such that j2 ≥ j1 .
To lower-bound the number of good pairs (j, k), we therefore lower-bound
7
2 −1
1 X 2
R
2 i=0 i
e ≡ a − bd (mod q)
Proof. Since a, b may independently assume 2` values, there are 22` distinct
pairs (a, b), from which the above claim follows.
Claim 3.
q−1
X 24`
Te2 ≥ .
e=0
q
12
Proof. The claim follows from the Cauchy–Schwarz inequality and claim 2 since
q−1
!2 q−1
! q−1
! q−1
4`
X X
2
X X 24`
2 = Te ≤ 1 Te2 ⇒ Te2 ≥ .
e=0 e=0 e=0 e=0
q
13
where we have used that 0 ≤ b < 2` . Combining the above results yields
{jq}2` e + bd − (b − 2`−1 )fj − 2`−1 {jq}2` d ≤ | {jq}2` | + 2`−4 ≤ 2`−3
q q
It therefore follows from claim 1 in section 3.5.2 that the sum
2 2
Te2
1 X 2πi e + bd 1 X iθb
· exp bf − {jq} = · e ≥
j 2`
24` 2` q 24` 2 · 24·`
b b
since | θb | ≤ 2π/8 = π/4 for all Te values of b. Summing over all e, we obtain
q−1
X Te2 24` 1 1
4`
≥ · 4`
=
e=0
2 · 2 q 2 · 2 2q
Note that this is exactly the same algorithm as was originally proposed by Shor.
k ≡ fj − dj (mod 2l )
which yields
d
{jq}2` − k − dj + n2l = δ.
q
14
Multiplying by q yields
provided that t 6≡ 0 (mod q). Since j > 0 we have jq > 2` and | {jq}2` | ≤ 2` /2
which implies 0 < | t |. Furthermore
1 (2` − 1)q
{jq}2` − jq 1 jq 1 q
|t| =
≤ + ≤ + ≤ + q − ` < q.
2` 2 2` 2 2` 2 2
|{z}
>1
Hence 0 < | t | < q which implies t 6≡ 0 (mod q) and so the lemma follows.
15
It should be stressed that we have have not sought the best lower bound
on the success probability in this paper. Rather we have sought a lower bound
that is easy to prove and that is sufficiently good to show that the algorithm
is practical. We expect the actual success probability to be much greater than
what is indicated by the bound.
– The two index registers are however now of length ` and 2` qubits,
compared to both being of length blog2 qc qubits in section 4.1.
– Consequently, when [a] g [−b] x is now computed 0 ≤ a < 22` and
0 ≤ b < 2` compared to 0 ≤ a, b < 2blog2 qc in section 4.1.
– Furthermore, the two QFTs are now of size 2` and 22` , compared to
both being of size 2blog2 qc in section 4.1.
1. Let
2` `
2 −1 2 −1
1 X X
|Ψi = √ |ai|bi|0i
23` a = 0 b = 0
where the first and second registers are of length ` and 2` qubits.
16
2. Compute [a] g [−b] x and store the result in the third register
2` `
2 −1 2 −1
1 X X
|Ψi = √ | a, b, [a] g [−b] x i
23` a = 0 b = 0
2` `
2 −1 2 −1
1 X X
=√ | a, b, [a − bd] g i .
23` a = 0 b = 0
3. Compute a QFT of size 22` of the first register and a QFT of size 2` of
the second register to obtain
2` `
2 −1 2 −1
1 X X QFT
|Ψi = √ | a, b, [a − bd] g i −−−→
23` a = 0 b = 0
2` ` 2` `
2 −1 2 −1 2 −1 2 −1
1 X X X X 2πi (aj+2` bk)/22`
√ e | j, k, [a − bd] g i .
26` a = 0 b = 0 j = 0 k = 0
Note that the size of the two first registers and the size of the QFT is now
determined by d and not by q as was the case in section 4.1.
where the sum is over all pairs (a, b) that produce this specific e. Note that the
assumption that q ≥ 22` + (2` − 1)d implies that no reduction modulo q occurs
when e is computed. In what follows, we re-write the above expression for the
probability on a form that is easier to use in practice.
where the sum is over all b in the set { 0 ≤ b < 2` | 0 ≤ a = e + bd < 22` }.
17
3. Centering b around zero yields
2
1 X 2πi `−1 `−1
`
· exp 2` b + 2 −2 (dj + 2 k) =
26` 2
b
2 X 2
1 πi 2πi
· exp ` (dj + 2` k) · exp 2` b − 2`−1 (dj + 2` k) .
26` 2 2
| {z } b
=1
18
5.1.4 Lower-bounding the probability of a good pair (j, k)
To lower-bound the probability of a good pair we first need to lower-bound the
number of pairs (a, b) that yield a certain e.
Definition 4. Let Te denote the number of pairs (a, b) such that
e = a − bd
| e = a − bd | < 22`
Proof. The claim follows from 0 ≤ a < 22` , 0 ≤ b < 2` and 0 < d < 2` .
Claim 5.
2`
2X −1
Te = 23` .
e = −22`
Proof. Since a, b may independently assume 22` and 2` values respectively, there
are 23` distinct pairs (a, b). From this fact and claim 4 the claim follows.
Claim 6.
2`
2X −1
Te2 ≥ 24`−1 .
e = −22`
Proof. The claim follows from the Cauchy–Schwarz inequality and claim 5 since
2` 2 2` 2` 2`
2X −1 2X−1 2X −1 2X −1
6` 2 2
2 = Te ≤ 1 Te ⇒ Te2 ≥ 24`−1 .
e = −22` e = −22` e = −22` e = −22`
for any integer b on the interval 0 ≤ b < 2` . It therefore follows from claim 1 in
section 3.5.2 that the probability
2
Te2
1 X 2πi `−1 `
· exp (b − 2 ) {dj + 2 k} ≥
22`
26` 22` 2 · 26`
b
19
for a specific e. Summing this over all e and using claim 6 yields
2`
2X −1
Te2
≥ 2−2`−2
2 · 26`
e = −22`
since d < 2` and |{dj + 2` k}22` | ≤ 2`−2 by the definition of a good pair, and
since m may be freely selected to obtain equality.
Whether the search is computationally
√ feasible depends on the number of
vectors in L(j) that lie within distance 2 · 2` of ~v . Lemma 6 below relates this
number to the norm of the shortest non-zero vector in the lattice. To introduce
the lemma, we first need some additional details.
Definition 6. Let ~s1 be the shortest non-zero vector in L(j), and let ~s2 be the
shortest non-zero vector in L(j) that is linearly independent to ~s1 .
20
The vectors ~s1 and ~s2 form a reduced basis for L(j). Such a basis may be
computed using standard lattice basis reduction algorithms such as Lenstra-
Lenstra-Lováz (LLL) [5].
//
Definition 7. Let ~s2 be the component of ~s2 parallel to ~s1 and let ~s2⊥ be the
component of ~s2 orthogonal to ~s1 .
π 2π
Claim 7. The angle α between ~s1 and ~s2 is such that 3 ≤α≤ 3 .
//
Proof. From definition 6, it follows that | ~s2 | ≤ | ~s1 | / 2 and | ~s1 | ≤ | ~s2 |, so
// 1
| ~s2 | = | ~s2 | · | cos α | ≤ | ~s1 | /2 ≤ | ~s2 | /2 ⇒ | cos α | ≤
2
from which the claim follows, by solving for α on the interval 0 ≤ α ≤ π.
Lemma
√ 6. For ~v ∈ R2 the number of lattice vectors ~u ∈ L(j) within distance
`
2 · 2 of ~v is lower-bounded by
$ √ % !
2 2 · 2`
max 12, +1 .
| ~s1 |
Proof. Any vector in L(j) may be written on the form i1~s1 +i2~s2 where i1 , i2 ∈ Z.
For fixed i2 ∈ Z and variable i1 ∈ Z the vectors i1~s1 + i2~s2 ∈ L(j)
√ are on a line
l in R2 . The number of vectors on l in any circle with radius 2 · 2` is at most
$ √ %
2 2 · 2`
+ 1.
| ~s1 |
The orthogonal distance between two consecutive lines on the above form is
| s⊥
2 |. The vector ~v ∈ R2 may be written on the form ~v√= a1~s1 + a2~s2 for some
a1 , a2 ∈ R. For l to at all intersect the √ circle of radius 2 · 2` around v it must
⊥ `
therefore be that | i2 − a2 | · |~s2 | ≤ 2 · 2 and this is the case for at most
$ √ %
2 2 · 2`
+ 1.
| ~s⊥
2 |
21
Furthermore, the area of the fundamental parallelogram in L(j) is
| ~s1 | · | ~s⊥
2 | = | det L(j) | = 4 · 2
2`
⇒ | ~s⊥ 2`
2 | = 4 · 2 /|~
s1 |
Assume that | ~s1 | > 2` . Then, equation (8) implies S ≤ 12. Conversely, assume
that | ~s1 | ≤ 2` . Then, equation (9) implies
$ √ %
2 2 · 2`
S= +1
| ~s1 |
To perform the search in practice, √ all vectors on the form i1~s1 + i2~s2 where
i1 , i2 ∈ Z that lie within distance of 2 · 2` of ~v are exhaustively searched. The
starting point is easily found by writing ~v = a1~s1 + a2~s2 where a1 , a2 ∈ R and
rounding a1 , a2 to the nearest integers.
Basis reduction algorithms such as LLL are practical for lattices of dimension
two so it is practical to compute ~s1 and √ ~s2 . Therefore the above algorithm is
practical if | ~s1 | is large in relation to 2 · 2` so that the search space is small.
To demonstrate that the algorithm is practical we lower-bound | ~s1 | by first
introducing the notion of good integers j.
Definition 8. An integer j on the interval 0 ≤ j < 22` is said to be bad if there
exists an integer ξ on the interval 0 < ξ < 2`−3 such that | {ξj}22` | < 2`−5 .
Otherwise, j is said to be good.
Lemma 7. If j is good then the shortest non-zero vector ~s1 ∈ L(j) has norm
| ~s1 | ≥ 2`−3 .
Proof. The shortest non-zero vector ~s1 ∈ L(j) may be written on the form
4j 1
= 4 (ξj + λ22` ) ξ = 4 {ξj}22` ξ
~s1 = ξ λ 2`
4·2 0
which implies that | ~s1 | ≥ | 4 {ξj}22` | and that | ~s1 | ≥ | ξ |. Since | {u}22` | =
| {−u}22` | for all u ∈ Z we only consider positive ξ. If j is good then | {ξj}22` | ≥
2`−5 for all 0 < ξ < 2`−3 by definition 8 and so the lemma follows.
This implies that if j is good then the exhaustive search needs explore only
a small number of vectors to recover ~u and hence d.
22
5.2.2 Proof of correctness
Lemma 8 summarizes the above analysis and provides a proof of correctness.
Claim 8. For a fixed ξ on the interval 0 < ξ < 2`−3 there are less than 2`−4
integers j on the interval 0 ≤ j < 22` such that | {ξj}22` | < 2`−5 .
Proof. Let 2κ be the largest power of two that divides ξ. Since ξ < 2`−3 it must
be that κ < ` − 3. As j runs through all integers 0 ≤ j < 22` , the function
ξj mod 22` assumes the value of each multiple of 2κ exactly 22`−κ times.
Only the 2 · 2`−κ−5 − 1 values congruent to values on (−2`−5 , 2`−5 ) are such
that | {ξj}22` | < 2`−5 so with multiplicity 2κ there are 2κ ·(2·2`−κ−5 −1) < 2`−4
integers j such that | {ξj}22` | < 2`−5 for a fixed ξ.
Proof. By definition 8 there are 2`−3 − 1 values of ξ since 0 < ξ < 2`−3 and by
claim 8 there are less than 2`−4 bad integers j for a fixed ξ. In total, there are
therefore less than (2`−3 − 1) · 2`−4 < 22`−7 bad integers j.
23
Proof. By lemma 4 there are at least 22`−1 good pairs (j, k). It follows from
definition 3 of a good pair that j is distinct. By lemma 9 there are less than
22`−7 bad j. It follows that there must be at least 22`−1 − 22`−7 good pairs (j, k)
for which j is good.
By lemma 5 the probability of obtaining a specific good pair from a single
execution of the algorithm in section 5.1 is at least 2−2`−2 . The probability of
obtaining a good pair (j, k) for which j is good must therefore be at least
By lemma 8 the classical algorithm in section 5.2 will upon input of a pair
(j, k) for which j is good output d and so the theorem follows.
Again, it should be stressed that we have have not sought the best lower bound
on the success probability in this paper.
24
both cases, the choice of group operation and element representation affects the
complexity of computing and storing [e] g.
These results imply that the complexity of computing discrete logarithms in
prime order groups on a quantum computer can be made to depend not only
on the choice of group, and on its order q, but also on the logarithm d.
In the special case where d ≪ q, our algorithm does not require q to be
prime, so this result generalizes to finite abelian group. Furthermore, as per the
description of the algorithm, q does not need to be explicitly known.
The reduction in size of the first two registers is in itself not very significant
since many additional qubits will typically be required to implement the two
exponentiation operations. However, the fact that the exponents that enter into
these operations are now short, and that the QFTs are of smaller sizes, reduces
the complexity in the special case where d ≪ q.
Remarks
The quantum algorithms in this paper are described in purely mathematical
terms. It is assumed that some quantum registers are first initialized, that a
quantum circuit is then executed and that the system is then finally observed
in a measurement. The extent to which the specialized algorithm for the case
where d ≪ q provides an advantage over the general algorithm depends on how
this mathematical description is translated into a physical implementation.
Note furthermore that in the case of subgroups of prime order q to F∗p , for
fixed p and d ≪ p the general algorithm has lower complexity when d ∼ q ≪ p
than does the specialized algorithm when d ≪ q ∼ p. It is possible that the
specialized algorithm may be further optimized in this respect.
Acknowledgments
Many thanks to Johan Håstad for providing key comments, suggestions and
guidance. A note of thanks also goes to Lennart Brynielsson for correcting
several minor errors in early draft versions of this paper.
Funding and support for this work was provided by the Swedish NCSA that
is a part of the Swedish Armed Forces.
References
[1] D. Boneh, R. J. Lipton, “Quantum Cryptanalysis of Hidden Linear Func-
tions”, in proceedings from the International Cryptology Conference, Ad-
vances in Cryptology – CRYPTO ’95, volume 963, 1995, pp. 424-437.
[2] D. Gordon, “Discrete logarithms in GF(p) using the Number Field Sieve”,
in SIAM Journal on Discrete Mathematics, volume 6, 1993, pp. 124-138.
[3] M. Hirvensalo, “Quantum Computing”, 2nd edition, Natural Computing
Series, Springer Verlag, 2004.
[4] R. Josza, “Quantum Factoring, Discrete Logarithms, and the Hidden Sub-
group Problem”, in Computing in Science and Engineering, volume 3, no
2, 2001, pp. 34-43.
25
[5] A. K. Lenstra, H. W. Lenstra, L. Lovász, “Factoring polynomials with ra-
tional coefficients”, in Mathematische Annalen, volume 261, no 4, 1982,
p.p. 515-534.
26