HNP-SUM: Hidden Number Problem With Small Unknown Multipliers in Python
Python and Sage Reproduction of HNP-SUM paper

This is part of our series on Practical Hidden Number Problems for Programmers:
*These links are paywalled. (It’s how I’ll afford grad school lol)
Part 1: Quantum Computing and Intro to Hidden Number Problems
Part 2: Increasing Lattice Volume for Improved HNP Attacks
Part 3: Hidden Number Problems with Multiple Noise Holes
Part 4: Hidden Number Problems with Chosen Multipliers
Part 5: Hidden Number Problems with Chosen Errors
Part 6 : Solving Hidden Number Problems Without Lattices
Part 7 : Fourier Analysis Attacks on HNPs with Bleichenbacher’s algorithm.
Part 8 (we are here): Hidden Number Problems with Small Unknown Multipliers.
As usual, code is available on GitHub and Google Colab.
1.0 Introduction
The Hidden Number Problem with Small Unknown Multipliers: Cryptanalyzing MEGA in Six Queries and Other Applications (Heninger & Ryan, 2023)1 introduces the HNP-SUM problem, the challenge of recovering unknown multipliers (not unknown keys) using a lattice approach.
The author’s approach can be summarized in three steps (Ryan, 2023)2:
Eliminate the private key x from the system of equations:
Reduce the lattice basis:
Find the Hermite Normal Form of the reduced basis to obtain target multipliers.
We saw how to find the Hermite Normal Form earlier:
2.0 Coding HNP-SUM in Python
Code is available on GitHub and Google Colab.
We install fpylll and cysignals to proceed:
2.1 Theorem 1: Testing for Solution Existence
Where T and E are known size bounds for the multiplier and error term, N is our field characteristic, and n is the number of samples, the authors prove that HNP-SUM can be solved in polynomial time.
Python code resembles:
2.2 HNP-SUM Dataset Generator
HNP-SUM is unlike other HNPs because we only know the observation. We don’t know the multipliers, errors or secret key:
We proceed to generate a dataset for the HNP-SUM problem.
2.3 Lattice Construction
We follow the basis construction above. For the curious, here’s an example with 3 samples to demonstrate how the basis works:
In Python, we use fpylll to construct the lattice as:
2.4 Finding Solutions with Hermite Normal Form
Simple lattice reduction won’t reveal our desired basis vectors since t1 and t2 are not coprime:

(Heninger & Ryan, 2023) overcome this ‘non-coprime’ challenge by finding the Hermite Normal Form of a sub-lattice of the reduced basis.
Lemma 2 proves that this sub-lattice is equivalent to taking out the final 2 rows of the reduced basis:
Python code t0 extract this sub-lattice resembles:
2.4.1 Testing Code
We test our code with the lattice from (Ryan, 2023):
In Python, we do this to obtain the sub-lattice:
Then we use Sage Math’s HNF as stated in (Heninger & Ryan, 2023):
The sage code resembles:
As expected, it works!
For the curious, this is how one interprets the reduced basis and the expected HNF result:
2.4.2 Cryptographic Example
We run our Python sub-lattice generator with a 237-bit prime:
Observe that our expected multipliers are:
We export our sub-lattice to Sage and find the HNF:
Then we print our HNF results and observe that it works!
Our results have 8 and 13 (the signs may be wrong but we still have them, lol). It works!
References
Heninger, N., Ryan, K. (2023). The Hidden Number Problem with Small Unknown Multipliers: Cryptanalyzing MEGA in Six Queries and Other Applications. In: Boldyreva, A., Kolesnikov, V. (eds) Public-Key Cryptography – PKC 2023. PKC 2023. Lecture Notes in Computer Science, vol 13940. Springer, Cham. DOI.
























