Application of the Lucas–Lehmer test and Lucas functions in cryptanalysis of Bitcoin ECDSA

21.10.2026

Abstract.  This paper examines the mathematical foundations of the deterministic Lucas–Lehmer primality test (LLT) for Mersenne integers and its generalization to Lucas sequences and functions. It demonstrates how these objects can be used to analyze the security of the ECDSA signature used in the Bitcoin blockchain. The primary focus is on the problem of recovering a private key from a hidden number (nonce) of the signature. A theoretical approach is proposed that relates the properties of Lucas sequences to the hidden number problem (HNP) and lattice methods. Pseudocode for a hypothetical attack is presented, and directions for further research are outlined.

1. Introduction

The Lucas–Lehmer test (LLT) is a polynomial, deterministic, and unconditional primality test for Mersenne primes. Mp=2p–1, Where p — simple. It allows for polynomial time in bit length p determine whether Mp prime or composite. The proof of the test relies on the properties of Lucas functions, which made it possible to generalize the test to several other classes of numbers.

Elliptic curve cryptosystems, particularly ECDSA (Elliptic Curve Digital Signature Algorithm), form the basis for Bitcoin transaction signing. ECDSA’s security critically depends on the secrecy and uniqueness of the nonce. k (nonce). Compromise k or the presence of a statistical relationship between different k allows you to recover your private key d.

The purpose of this paper is to show how the mathematical apparatus of LLT and generalized Lucas sequences can be applied to cryptanalysis of ECDSA, in particular to solving the recovery problem d by known signatures in the presence of partial information about the nonce.

2. Lucas-Lehmer test: mathematical foundations

Let p — a prime number, Mp=2p–1Let’s define the sequence sn recurrently:

s0=4,sn+1=sn2–2(modMp).

Theorem (Luc–Lehmer).  Mersenne number Mp

 prime if and only if sp–2≡0(modMp)

.

An equivalent formulation uses the Lucas sequence Vn(P,Q) with parameters P=4, Q=1. Then sn=V2n(4,1)The test checks that V2p–1(4,1)≡0(modMp).

The proof relies heavily on the fact that the ring ZMp with a simple Mp is a field, and the order of the element is α=2+3 in a multiplicative group FMp2∗ equal Mp+1=2p.

3. Generalization: Luke sequences and functions

Luke Sequences Un(P,Q) And Vn(P,Q) are determined recursively:

U0=0,U1=1,Un=PUn–1–QUn–2,

V0=2,V1=P,Vn=PVn–1–QVn–2.

They are connected to the roots α,β characteristic polynomial x2–Px+Q=0:

Un=αn–βnα–β,Vn=αn+βn.

Luke’s function Vn(P,Q) can be viewed as an analogue of exponentiation in quadratic expansion. This makes it convenient for cryptographic primitives (for example, the LUC cryptosystem).

Important property: if N — simple, then for any P,Q With gcd(Q,N)=1 and discriminant D=P2–4Q, which is not a quadratic residue modulo N, is performed:

VN+1(P,Q)≡2Q(modN).

This generalization of Fermat’s little theorem underlies Lucas-type primality tests and can be used to test the order of points on elliptic curves.

4. ECDSA: Signature and Hidden Number Problem

In ECDSA over a finite field Fp with a base point G order n message signature m with a private key d is formed as follows:

  1. A random one is selected k∈[1,n–1].
  2. The point is calculated R=kG, r=xRmodn. If r=0, a new one is selected k.
  3. It is being calculated e=H(m) (message hash truncated to bit length n).
  4. It is being calculated s=k–1(e+rd)modn. If s=0, a new one is selected k.
  5. Signature – couple (r,s).

The signature equation can be rewritten as:

k≡s–1e+s–1rd(modn).

If the attacker knows multiple signatures (ri,si,ei) and can obtain information about the relevant ki (for example, that they have low entropy, are repeated, or are related by a linear relationship), the problem of recovery d comes down to  the Hidden Number Problem  (HNP).

HNP (Boneh–Venkatesan).  Dans ti

 And ai

 such that |ki–ai|<B

 for some boundary B

, Where ki≡ti+aid(modn)

. Need to find d

With a sufficient number of signatures and a small B

 The problem is effectively solved by lattice reduction methods (LLL, BKZ).

5. Application of LLT and Lucas functions to ECDSA cryptanalysis

5.1. Checking the order of the dot and “simple” nonces

In the Lucas-Lehmer test, the key role is played by checking that some element has an order equal to 2pIn the context of ECDSA, the order of the base point G equal n. If n — a prime number (as in secp256k1, where n — 256-bit prime), then this already guarantees the absence of small subgroups. However, when generating a nonce k it may happen that k has common divisors with n or what point kG lies in a subgroup of low order. The Lucas-type test can be used to quickly check that k generates the entire group (or a subgroup of large prime order), which potentially allows filtering out “weak” nonces.

If an attacker can influence the generation k (for example, through an attack on the signing side), he may try to force k, for which Vn+1(P,Q)≢2Q(modn), which indicates compositeness n or that k is not a generator. This creates a theoretical possibility for an attack based on incorrect ordering.

5.2. Recovering nonce via logarithm in Lucas sequence

Suppose that the nonce generator in some implementation is designed such that k is calculated as the value of the Lucas function of some secret index m: k=Vm(P,Q)modnIf the attacker manages to obtain k (or part of it), then the problem of finding m reduces to  the Lucas logarithm problem  . It is known that this problem is computationally equivalent to the discrete logarithm in Fp2, which allows the use of Pollard-type algorithms.

A more realistic scenario: the nonce is generated as k=Hash(d,m)modnIf the hash function has a structure close to the iteration of a quadratic mapping (for example, x↦x2–2), then the sequence of hash values ​​can be described through the Lucas sequence. Then, knowing several consecutive values ki, we can try to restore the internal state of the generator and, therefore, d.

5.3 Using LLT to Check the Primeness of the Order of a Subgroup Generated by a Nonce

Some attacks on ECDSA exploit the fact that the order of the dot R=kG may have small prime factors. If an attacker can guess k so that there is order R is composite with known divisors, he can use the Pohlig–Hellman attack to recover d modulo these divisors, and then combine the results using the Chinese remainder theorem. The Lucas–Lehmer test and its analogs for elliptic curves allow one to effectively check whether the order of a point is prime (or has a given structure). This provides a tool for finding “weak” nonces that can be used in an attack.

5.4 Hybrid approach: LLT + lattice methods

The most promising approach appears to be combining LLT ideas with lattice algorithms for solving HNP. The idea is as follows:

  1. Collect a set of signatures (ri,si,ei), for which it is known that nonce ki lie in some interval or have known high-order bits (for example, due to side-channel leakage).
  2. Use properties of Lucas sequences to refine the boundaries of possible values kiFor example, if it is known that ki=Vmi(P,Q), then we can estimate the range mi and therefore the range ki.
  3. Construct a lattice corresponding to the extended HNP and apply LLL/BKZ to search d.

This approach can reduce the requirements for the number of known nonce bits needed for a successful attack.

6. Pseudocode of a hypothetical attack

Below is some conceptual pseudocode illustrating the combination of LLT checks and lattice key recovery.

Input: set of signatures (r_i, s_i, e_i) for i = 1..N,
       information about the structure of the nonce generator (for example, k_i = V_{m_i}(P,Q)),
       B-bound for the deviation of nonce from the expected value.

Output: private key d.

1. For each signature, calculate t_i = s_i^{-1} e_i mod n.
2. For each signature, calculate u_i = s_i^{-1} r_i mod n.
   Then k_i ≡ t_i + u_i d (mod n).
3. Using the knowledge of the nonce generator, for each i estimate
   approximate value of k_i^* (for example, through V_{m_i}(P,Q)).
4. Calculate the deviations δ_i = k_i - k_i^*.
   If |δ_i| < B for all i, then we have an instance of HNP.
5. Construct a lattice of dimension N+1:
   Basis vectors:

[n, 0, 0, …, 0, 0]

[0, n, 0, …, 0, 0] …

[u_1, u_2, …, u_N, 1/B, 0]

[t_1, t_2, …, t_N, 0, B] 6. Apply LLL reduction to the basis. 7. Find a short vector corresponding to (δ_1, δ_2, …, δ_N, d/B, 1). 8. Extract d from the coordinates of the found vector. 9. (Optional) Check that for all i, V_{n+1}(P_i, Q_i) ≡ 2Q_i (mod n) — a Lucas-type test confirming that the k_i found generate a proper subgroup. 10. Return d.

7. Conclusion

The Lucas-Lehmer test and generalized Lucas sequences provide a powerful mathematical framework that can be adapted to analyze elliptic curve cryptographic protocols. In the context of Bitcoin’s ECDSA, these tools allow:

  • effectively check the order of points and identify “weak” nonces;
  • link nonce generation to quadratic maps and Lucas sequences, which opens the way to recovering the internal state of the generator;
  • to clarify the boundaries of possible nonce values ​​for subsequent HNP solution using lattice methods;
  • build hybrid attacks that combine deterministic primality tests (LLTs) with probabilistic lattice algorithms.

Although no direct public attacks using the described approach are known at the time of writing, the theoretical premises appear sound. Further research in this direction could lead to new practical methods for cryptanalyzing ECDSA, especially in scenarios where nonce generation deviates from perfectly random.

Directions for further research for cryptanalysis based on this area

  1. Formalizing the relationship between nonce generators and Lucas sequences.  It is necessary to rigorously demonstrate which classes of practical generators (based on hash functions, counters, hardware RNGs) can be described using Vm(P,Q) or Um(P,Q), and estimate the computational complexity of recovery m according to well-known k.
  2. Development of elliptic analogs of the Lucas–Lehmer test.  Although primality tests for elliptic curves exist (ECPP), adapting them to check the order of points in the context of ECDSA requires optimization. The goal is to create a fast, deterministic test that, point by point, R=kG determines whether the order is R simple, without knowledge k.
  3. Analysis of the stability of HNP with a known nonce structure.  If nonces are generated as Lucas sequence values, then the distribution k may be uneven. It is necessary to study how this affects the constants in lattice attacks and how many signatures are required to recover d under different parameters P,Q.
  4. Finding weak parameters of curves.  Some elliptic curves can have order n, for which the discrete logarithm in the Lucas sequence is solved faster than in the general case. Known curves (secp256k1, secp256r1, etc.) should be scanned for such anomalies.
  5. Practical implementation and benchmarking.  Create a prototype attack on GPU/FPGAs combining LLT checks, LLL/BKZ, and possibly Fourier transform-based methods (as in attacks on HNP with noise). Evaluate real-world performance on data from the Bitcoin blockchain.
  6. Studying quantum aspects.  Although LLT does not provide a direct advantage over Shor’s algorithm, quantum versions of algorithms for Lucas sequences may prove useful for analyzing post-quantum signature schemes based on isogenies or lattices.
  7. Extension to other signature schemes.  The ideas outlined for ECDSA can be adapted to Schnorr signatures (used in Taproot), EdDSA, and other schemes where nonces play a critical role.

© 2025. This document is for research purposes only. All mathematical constructions are provided to demonstrate the theoretical capabilities of cryptanalysis and do not constitute a description of a complete attack.