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. , Where — simple. It allows for polynomial time in bit length determine whether 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. (nonce). Compromise or the presence of a statistical relationship between different allows you to recover your private key .
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 by known signatures in the presence of partial information about the nonce.
2. Lucas-Lehmer test: mathematical foundations
Let — a prime number, Let’s define the sequence recurrently:
Theorem (Luc–Lehmer). Mersenne number
prime if and only if
.
An equivalent formulation uses the Lucas sequence with parameters , . Then The test checks that .
The proof relies heavily on the fact that the ring with a simple is a field, and the order of the element is in a multiplicative group equal .
3. Generalization: Luke sequences and functions
Luke Sequences And are determined recursively:
They are connected to the roots characteristic polynomial :
Luke’s function 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 — simple, then for any With and discriminant , which is not a quadratic residue modulo , is performed:
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 with a base point order message signature with a private key is formed as follows:
- A random one is selected .
- The point is calculated , . If , a new one is selected .
- It is being calculated (message hash truncated to bit length ).
- It is being calculated . If , a new one is selected .
- Signature – couple .
The signature equation can be rewritten as:
If the attacker knows multiple signatures and can obtain information about the relevant (for example, that they have low entropy, are repeated, or are related by a linear relationship), the problem of recovery comes down to the Hidden Number Problem (HNP).
HNP (Boneh–Venkatesan). Dans
And
such that
for some boundary
, Where
. Need to find
With a sufficient number of signatures and a small
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 In the context of ECDSA, the order of the base point equal . If — a prime number (as in secp256k1, where — 256-bit prime), then this already guarantees the absence of small subgroups. However, when generating a nonce it may happen that has common divisors with or what point lies in a subgroup of low order. The Lucas-type test can be used to quickly check that 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 (for example, through an attack on the signing side), he may try to force , for which , which indicates compositeness or that 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 is calculated as the value of the Lucas function of some secret index : If the attacker manages to obtain (or part of it), then the problem of finding reduces to the Lucas logarithm problem . It is known that this problem is computationally equivalent to the discrete logarithm in , which allows the use of Pollard-type algorithms.
A more realistic scenario: the nonce is generated as If the hash function has a structure close to the iteration of a quadratic mapping (for example, ), then the sequence of hash values can be described through the Lucas sequence. Then, knowing several consecutive values , we can try to restore the internal state of the generator and, therefore, .
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 may have small prime factors. If an attacker can guess so that there is order is composite with known divisors, he can use the Pohlig–Hellman attack to recover 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:
- Collect a set of signatures , for which it is known that nonce lie in some interval or have known high-order bits (for example, due to side-channel leakage).
- Use properties of Lucas sequences to refine the boundaries of possible values For example, if it is known that , then we can estimate the range and therefore the range .
- Construct a lattice corresponding to the extended HNP and apply LLL/BKZ to search .
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
- 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 or , and estimate the computational complexity of recovery according to well-known .
- 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, determines whether the order is simple, without knowledge .
- Analysis of the stability of HNP with a known nonce structure. If nonces are generated as Lucas sequence values, then the distribution may be uneven. It is necessary to study how this affects the constants in lattice attacks and how many signatures are required to recover under different parameters .
- Finding weak parameters of curves. Some elliptic curves can have order , 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.
- 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.
- 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.
- 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.
