Discrete Logarithm in Fp\mathbb{F}_p: Pohlig⁠-⁠Hellman

17 Dec 2021


§ Motivation

For some cases of the discrete logarithm problem, gxphg^x \equiv_p h, it is relatively easy to solve; for instance, when ordp(g)\text{ord}_p(g) is "highly" composite, i.e. factorable by many small primes.

§ The Generalised Algorithm

Sps. we have an algorithm (\dagger) to solve the discrete log over (Zp)×\left(\mathbb{Z}_p\right)^\times when gg has prime power order, and pp prime. The generalised Pohlig-Hellman algorithm is dependent on the existence of (\dagger).

About algorithm (\dagger):

  • If using (\dagger) on the discrete log described by gxphg^x \equiv_p h, if ordp(g)=qe\text{ord}_p(g) = q^{e} for some qP<pq \in \mathbb{P_{\lt p}}, then suppose we can solve it in O(Sqe)\mathcal{O}(S_{q^e}) time.
  • In the case where eqe \ll q, then the value of SqeS_{q^e} can be expressed as epe\sqrt{p}, which means (\dagger) can also be done in O(ep)\mathcal{O}(e\sqrt{p}) time.
  • The algorithm exists and is described in Discrete Logarithm in Fp\mathbb{F}_p: ordp(g)\text{ord}_p(g) is a Prime Power.

Generalised Pohlig-Hellman

Given gxphg^x \equiv_p h, and N=ordp(g)=i=1tqieiN = \text{ord}_p(g) = \prod_{i = 1}^{t} q_i^{e_i}. Then, the discrete log can be solved using the Pohlig-Hellman algorithm:

  1. For all i[1t]i \in [1 \dots t], let

    gi=gN/qiei and hi=hN/qiei.g_i = g^{N/q_i^{e_i}}\ \text{and}\ h_i = h^{N/q_i^{e_i}}.

    Use alg. (\dagger) to compute a sol'n for yiy_i in giyiphig_i^{y_i} \equiv_p h_i.

  2. Using CRT, solve the following system of congruences:

    x{y1(modq1e1)y2(modq1e1)yt(modqtet)x \equiv \begin{cases} y_1 & \pmod{q_1^{e_1}}\\ y_2 & \pmod{q_1^{e_1}}\\ & \vdots\\ y_t & \pmod{q_t^{e_t}} \end{cases}

The value of xx then satisfies gxphg^x \equiv_p h.

The discrete log can be solved by Pohlig-Hellman in O(i=1tSqiei+logN)\mathcal{O}\left(\sum_{i=1}^{t} S_{q_i^{e_i}} + \log N\right), assuming the complexity of (\dagger) holds.

§ Computation

The Magma computational algebra system uses Pohlig-Hellman[1] for the discrete log over Fp\mathbb{F}_p for p<236p \lt 2^{36}. Using Magma, we can compute

gxphg^x \equiv_p h

with the following code:

// Replace g, h, p with values from the discrete log 
F<x> := FiniteField(p);

// The value satisfying the discrete log is stored in the variable x.
x := Log(F ! g, F ! h);

§ Sketch of Proofs

Complexity

In step (1) of Pohlig-Hellman, we solve tt discrete logs using (\dagger); we assume that (\dagger) is in O(Sqe)\mathcal{O}(S_{q^e}). Then, the upper bound of the first step is O(i=1tSqiei)\mathcal{O}\left(\sum_{i=1}^{t} S_{q_i^{e_i}}\right).

In step (2) we solve a system of congruences using CRT. The CRT can be reduced into:

xi=1t(N/qiei)yibi,x \equiv \sum_{i=1}^{t}\left(N/q_i^{e_i}\right)y_ib_i,

where bib_i satisfies bi(N/qiei)1(modqiei)b_i(N/q_i^{e_i}) \equiv 1 \pmod{q_i^{e_i}}. We compute tt $b_i$s with each taking O(log(qiei))\mathcal{O}\left(\log\left(q_i^{e_i}\right)\right), for all $b_i$s the time is O(log(N))\mathcal{O}(\log(N)).

Then, the total runtime is indeed O(i=1tSqiei+logN)\mathcal{O}\left(\sum_{i=1}^{t} S_{q_i^{e_i}} + \log N\right).

Correctness

In step (2), by CRT xx satisfies all the congruences. Then, x=yi+qieizi ()x = y_i + q_i^{e_i}z_i\ (\ddagger) for some ziZz_i \in \mathbb{Z}.

(gx)N/qiei=(gyi+qieizi)N/qiei=(gN/qiei)yigNzi=(gN/qiei)yi=giyi=hi=hN/qiei\begin{align*} \left(g^x\right)^{N/q_i^{e_i}} &= \left(g^{y_i + q_i^{e_i}z_i}\right)^{N/q_i^{e_i}}\\ &= \left(g^{N/q_i^{e_i}}\right)^{y_i}g^{Nz_i}\\ &= \left(g^{N/q_i^{e_i}}\right)^{y_i}\\ &= g_i^{y_i}\\ &= h_i\\ &= h^{N/q_i^{e_i}} \end{align*}

Then, we notice that (N/q1e1,,N/qtet)=1(N/q_1^{e_1}, \dots, N/q_t^{e_t}) = 1, and that there exists c1,,ctc_1, \dots, c_t satisfying

(c1N/q1e1,,ctN/qtet)=1.(c_1N/q_1^{e_1}, \dots, c_tN/q_t^{e_t}) = 1.

Finally,

gx=g(i=1tciN/qiei)x=hi=1tciN/qiei=h.g^x = g^{(\sum_{i=1}^{t}c_iN/q_i^{e_i})x}=h^{\sum_{i=1}^{t}c_iN/q_i^{e_i}}=h.


  1. Magma Handbook, Discrete Logarithms. ↩︎