Encrypted Lookup Table
The article details the solution provided by the winner of the Lookup Table challenge
Author: Jules Dumezy, MSc Student at the Ecole Centrale de Lille.
Introduction
A lookup table, specifically A[i] for a list A and an index i, is a fundamental concept in computer science and plays a vital role in efficient algorithm design and implementation. At their core, LUTs provide a mechanism for efficiently retrieving precomputed values based on an index, thereby allowing for constant-time access to data, which is crucial for performance-critical applications.
Aside from the obvious use of LUT to retrieve data and use it in calculation, it can also be used to evaluate an arbitrary function f. By precomputing its outputs and storing them in an encrypted vector, f's computation can be reduced to a simple lookup operation, which can be far less resource-intensive. This capability can be essential in applications such as encrypted neural networks, and allows to easily evaluate non-smooth functions.
The challenge
We are working with BFV using the plaintext modulus 65537. Given an encrypted vector of size 2048 and an encrypted index , we want to extract . Specifically, we want to obtain an encrypted vector with in the first slot.
Although the challenge specifies that the values are bounded between 0 and 255, the proposed solution does not rely on this restriction. Additionally, the solution can be easily adapted for larger vectors (with more than 2048 values) or for larger plaintext moduli.
The algorithm
The algorithm can be divided into two main steps :
- Creating a mask vector with a at the -th element and zeros everywhere else
- Extracting the value from and placing it in the first slot
Step 1
Since we use packing, the encrypted index vector has the following form: . We start by rotating this vector by -2047, resulting in a vector with 2047 zeros and the index at the 2048th position (index 2047).
This approach is used because rotations are generally faster with positive values, and it also minimizes the number of rotation keys required—we only need 12 rotation keys in total by reusing them, instead of 22.
By applying 11 rotations and additions (using rotation keys 1, 2, 4, 8, ..., 1024), we obtain a new encrypted vector with in the first slots .
Next we create a packed plaintext for the vector . We then add this plaintext to the previous ciphertext to produce a new ciphertext of the form . This new ciphertext has exactly one zero at the -th slot, with non-zero values in every other slot.
By Fermat's Little Theorem, and because operations are performed modulo (a prime number), we know that for all , .
Using fast exponentiation, we only need 16 multiplications to exponentiate each value of to , creating , a ciphertext containing ones in all slots except for -th slot, since .
Finally, we create a packed plaintext filled with ones, and subtract from it, giving us the desired mask vector with zeros everywhere except for the -th slot.
Step 2
Given the mask vector and the original encrypted vector , we use a seventeenth multiplication to multiply by , resulting in the partial result ciphertext : .
Knowing that is in the first slots, we apply the same strategy of rotations and additions (with the same rotation keys) to bring to the first slot.
References
[1] Ilia Iliashenko and Vincent Zucca, "Faster homomorphic comparison operations for BGV and BFV". Cryptology ePrint Archive, Paper 2021/315, 2021. Available online at https://eprint.iacr.org/2021/315
CITING THIS WORK
This write-up documents a component of the FHERMA library. If it informs your work, cite the two papers below rather than the article URL.
- 01FHERMA Cookbook: FHE Components for Privacy-Preserving ApplicationsJanis Adamek, Aikata Aikata, Ahmad Al Badawi, Andreea Alexandru, Armen Arakelov, Philipp Binfet, Victor Correa, Jules Dumezy, Sergey Gomenyuk, Valentina Kononova, Dmitrii Lekomtsev, Vivian Maloney, Chi-Hieu Nguyen, Yuriy Polyakov, Daria Pianykh, Hayim Shaul, Moritz Schulze Darup, Dieter Teichrib, Dmitry Tronin, Gurgen ArakelovCryptology ePrint Archive, Paper 2025/1302 · doi:10.1145/3733811.3767313
- 02FHERMA: Building the Open-Source FHE Components Library for Practical UseGurgen Arakelov, Nikita Kaskov, Daria Pianykh, Yuriy PolyakovCryptology ePrint Archive, Paper 2024/612
