Co6GC: An example security proof: LWE Encryption (Part 1)

This is a post in COSIC’s Guide to Crypto! In this series, researchers from COSIC will be informally writing about different concepts in cryptography. Our aim is to introduce the reader to these concepts with explanations, illustrations and examples; so let’s get started!

An earlier Co6GC post introduced provable security. The goal of this post is to put that into practice and give a security proof for a simple encryption scheme. Like most security proofs, our proof is not a direct proof that our encryption scheme is secure. Instead we prove that if a hardness assumption holds, (in our case the LWE assumption) then the cryptosystem must be secure. Reductionist security proof like this allow cryptanalysts to focus on trying to break a handful of problems, rather than having to scrutinize a lot of cryptosystems separately. Therefore, the proofs are most valuable when they reduce the security of a cryptosystem to a well established hardness assumption such as DDH or LWE. Before we can start proving our security reduction we need 3 ingredients: An encryption scheme, a security definition and one or more hardness assumptions. Security definitions and hardness assumptions are formally defined in the language of adversaries and challengers. This will be the subject of this blogpost. In the follow-up post we will do the security proof itself.

Adversaries and challengers.

Security definitions and hardness assumptions state that some task (e.g. deciphering a message, factoring large integers, distinguishing 2 distributions, … ) can not be performed by a certain type of algorithm. This is formalized by defining a probabilistic “checking” algorithm \( C \) (usually called the challenger) that interacts with a probabilistic algorithm \( A \) (usually called the adversary) and outputs \(1\) if \( A \) was able to perform the task or \( 0 \) otherwise. In this post we will denote by \( C^A( 1^\lambda ) \) the output of the challenger algorithm when given input \( 1^\lambda \) and when interacting with the adversary \( A \). The parameter \( \lambda \) is referred to as the security parameter. You can think of this as a parameter that tells the challenger how difficult he should make his challenge. A hardness assumption or a security definition is usually a statement of the form:

For all \( A \) in some class of allowed adversaries, \( \Pr[ C^A(1^\lambda) = 1 ] \) is “small”.

Here, the notion of small depends on the definition. Sometimes we demand that \( \Pr[ C^A(1^\lambda) = 1 ] \leq f(\lambda) \) for some concrete function \( f \), but more often we require that \( \Pr[ C^A(1^\lambda) = 1 ] \) or \( \left| \Pr[ C^A(1^\lambda) = 1 ] – \frac{1}{2} \right| \) is a negligible function of the security parameter, meaning that for every polynomial function \( p (\lambda)\) there exists a value \( \lambda_0 \) such that \( \Pr[ C^A(1^\lambda) = 1 ] \leq \frac{1}{p(\lambda)} \) for all \( \lambda > \lambda_0 \).

The decisional LWE assumption

The LWE problem is for a secret vector \( \mathbf{s} \in \mathbb{Z}_q^n \) and an error distibution \( \chi \) over \( \mathbb{Z}_q \) to distinguish samples of the form \( (\mathbf{a}_i , \langle \mathbf{a}_i , \mathbf{s} \rangle + e_i) \), where the \( \mathbf{a}_i \) are chosen uniformly at random, and where the \( e_i \) are drawn from the error distribution \( \chi \), from samples of the form \( (\mathbf{a}_i , b_i) \), where both the \( \mathbf{a} \) and \( b_i \) are chosen uniformly at random. [ If you are interested in the LWE problem and how it relates to hard problems in lattices you  should have a look at this previous Co6GC post. ]

Informally, the LWE assumption says that there does not exists an efficient algorithm that can accurately distinguish the two distributions. To formally define this assumption, we define a challenger algorithm \( C \) that prepares a set of \( m \) samples and gives it to an adversary, who has to guess what distribution the samples are drawn from:


LWE challenger: \( C_{LWE}^A(1^\lambda) \)


// Choose LWE parameters based on \( \lambda \) \( q,n,m,\chi \gets \mathsf{params}(\lambda) \)

// Choose LWE secret \( \mathbf{s} \gets \mathbb{Z}_q^n \)

For \(i\) from \(1\) to \( m \)

// pick \(\mathbf{a}_i\) uniformly at random \( \mathbf{a}_i \gets \mathbb{Z}_q^n \)

// pick \(b_{0,i}\) uniformly at random \( b_{0,i} \gets \mathbb{Z}_q \)

// compute noisy inner product \(b_{1,i}\) \( b_{1,i} \gets \langle \mathbf{a}_i , \mathbf{s} \rangle + e_i \) , where \( e_i \gets \chi \)

// Decide to give random samples or LWE samples \( \alpha \gets \{0,1\} \)

// Run \( A \) on random samples or LWE samples \( \alpha’ \gets A( \mathbf{a}_1 , b_{\alpha,1},\cdots, \mathbf{a}_m , b_{\alpha,m} ) \)

// \( A \) guesses correctly If \( \alpha = \alpha’ \) output \( 1 \)

// \( A \) guesses incorrectly If \( \alpha \not = \alpha’ \) output \( 0 \)


Of course, and adversary can win the LWE game with probability \(1/2\) by just guessing the bit \( \alpha\). The LWE assumption says that the winning probability of any polynomial-time algorithm is better than \(1/2\) by at most a negligible amount:

LWE assumption: There exists parameter function \( \mathsf{params}(\lambda) \) such that for any probabilistic polynomial-time adversary \( A \) \[ \left| \Pr[ C_{LWE}^A(\lambda) = 1 ]  – \frac{1}{2} \right|  \] is a negligible function of the security parameter.

\( \def\a{{\mathbf{a}}} \def\s{{\mathbf{s}}} \)

Regev Encryption

Now we will introduce the encryption algorithm that we will prove the security of: Regev encryption. This encryption scheme encrypts a message one bit at a time, and is therefore very inefficient. However, the scheme is quite simple and that is the reason we discuss it in this introductory blog post.

Key Generation: A private key for the Regev encryption is just a vector \( \mathbf{s} \) of \(n\) random elements mod \(q\). The corresponding public key is nothing more than a list of \( m \) LWE samples: \[ (\mathbf{a}_1 , b_{1}), \cdots , (\mathbf{a}_m , b_{m})\, , \]
where each of the \(b_i\) is of the form \(b_i = \langle  \mathbf{a}_i ,\mathbf{s} \rangle + e_i \), for an \(e_i\) sampled from the error distibution \( \chi \).

Interestingly, given a list of LWE samples (e.g. a Regev public key), one can create a new LWE sample by simply adding together some of the samples in the list. For example, if \( ( \a_1, b_1 = \langle \a_1 , \s \rangle + e_1 ) \) and \( ( \a_2, b_2 = \langle \a_2 , \s \rangle + e_2 ) \)  are two LWE samples, then the sum \( ( \a_1 + \a_2 , b_1 + b_2 ) \) is an LWE sample with error term \( e_1 + e_2 \). This error term is slightly bigger than the errors of the original LWE samples, but still small. Combining LWE samples to make a new one is what happens to encrypt a message bit:

Encryption: To encrypt a message bit \( m \) with the Regev encryption algorithm, you first construct a new LWE sample \( \a , b \), by picking a random subset \( S \subset \{1, \cdots, m \}\) of the samples in the public key and summing them up: \[ (\a,b) = \left( \sum_{i \in S} \a_i , \sum_{i \in S} b_i \right) \, . \]
The error of this new LWE sample is \( e = \sum_{i \in S} e_i  \), and we assume the parameters \( q,n,m,\chi \) are chosen such that \( |e| < q/4 \). Now, the ciphertext is simply \( ( \a , b + m \lfloor \frac{q}{2} \rfloor ) \). That is, if the message bit is \( 0 \), the ciphertext is an LWE sample with a small error term, and otherwise the ciphertext is an LWE sample with an unusually big error term.

Decryption: To decrypt a ciphertext \( \a, b\), you use the secret key to compute the error \( e = b – \langle \a , \s \rangle \) and then you check if the error is small or not. If \( |e| < q/4 \), then the message bit must have been \( 0 \) and otherwise the message bit must have been \( 1 \) .

IND-CPA security

Now that we have our encryption scheme we need to define what it means for the scheme to be secure. Intuitively, we want to say that the encryption scheme is IND-CPA secure if, given a public key and an encrypted bit the adversary cannot learn what the bit was. This idea is made formal with the help of a challenger algorithm, which generates a public key and encrypts a random bit and gives those to the adversary. The adversary wins if he manages to guess the encrypted bit correctly:


IND-CPA challenger: \( C_{IND-CPA}^A(1^\lambda) \)


// Choose LWE parameters based on \( \lambda \) \( q,n,m,\chi \gets \mathsf{params}(\lambda) \)

// Choose LWE secret \( \mathbf{s} \gets \mathbb{Z}_q^n \)

// Generate LWE samples For \(i\) from \(1\) to \( m \)

// pick \(\a_i\) uniformly at random \( \mathbf{a}_i \gets \mathbb{Z}_q^n \)

// compute noisy inner product \(b_{1,i}\) \( b_i \gets \langle \mathbf{a}_i , \mathbf{s} \rangle + e_i \) , where \( e_i \gets \chi \)

\( \mathsf{pk} \gets (\a_1 , b_1,\cdots, \a_m , b_m ) \)

// Choose message bit \( m \gets \{0,1\} \)

// Choose random subset \( S \subset \{ 1,\cdots, m\} \) \( S \gets P(\{1, \cdots, m\}) \)

// Compute ciphertext \( \mathsf{ct} \gets ( \sum_{i \in S} \a_i , m \cdot \lfloor \frac{q}{2} \rfloor + \sum_{i \in S} b_i ) \)

// Run \( A \) \( \alpha’ \gets A( \mathsf{pk}, (\a , b) ) \)

// \( A \) guesses correctly If \( \alpha = \alpha’ \) output \( 1 \)

// \( A \) guesses incorrectly If \( \alpha \not = \alpha’ \) output \( 0 \)


Now we can formally define what it means for the Regev encryption scheme to be IND-CPA secure:

IND-CPA security: We say that for a parameter function \( \mathsf{params}(\lambda) \) the Regev encryption scheme is IND-CPA secure if for any probabilistic polynomial-time adversary \( A \) \[ \left| \Pr[ C_{IND-CPA}^A(1^\lambda) = 1 ]  – \frac{1}{2} \right| \] is a negligible function of the security parameter.

Now that all the definitions are out of the way we can finally prove the IND-CPA security of the Regev Encryption scheme. This will be the subject of the follow-up blog post: Co6GC: An example security proof: LWE Encryption (Part 2).

To be continued …