Lattice-based cryptography
Basic Lattice Cryptography (opens new window) by Vadim Lyubashevsky is an excellent introduction to lattice-based cryptography. Below are the notes I took while reading the first part.
Some notation first: means rounding up, means rounding down, means the nearest integer,
All operations in what follows are performed in the ring , with the usual addition and multiplication of integers modulo . For a set , we write to mean that is chosen uniformly at random from the set . For any positive integer , we will define the set
A motivating example
Let’s pretend that for positive integers , , and , the following two distributions are computationally indistinguishable:
This indistinguishability assumption is clearly false because one can use Gauss elimination to invert (or an submatrix of ) and check whether there is indeed an such that .
We will see later that a slightly modified version of this assumption forms the foundation of lattice-based cryptography.
We will now use this (false) assumption to construct a simple CPA-secure public key encryption scheme that is very similar to the discrete logarithm-based El Gamal encryption scheme:
To encrypt a message , the encryptor picks a random and outputs:
To decrypt, one simply computes
The LWE problem
The following adjustment to the assumption from the previous section is needed to make it plausibly valid and still allow us to construct a cryptosystem following the same outline. A simple version of the Learning with Errors Problem (LWE), on which a lot of lattice-based cryptography rests is given next.
Definition: For positive integers , , , and , the problem asks to distinguish between the following two distributions:
The crucial part that makes hard is the presence of the additional “error” vector which makes the Gaussian elimination attack inapplicable. The problem becomes harder as and grow. The parameter is not known to have a large impact on the hardness of the problem except in extreme cases.
In the original definition of LWE, a rounded Gaussian distribution was used, but it was later shown that other distributions, such as uniform or binomial (used in Kyber), can also be used.
To account for the different distributions that one could use, we can define the LWE problem relative to the distribution of the secrets as:
Definition: For positive integers , , , and , the problem asks to distinguish between the following two distributions:
The hardness of the problem depends on the parameters , , , and . What’s interesting is that you can make it even too hard - having for example and large enough, then the distribution could be statistically close to , which would make it impossible to build an encryption scheme based on just this assumption. On the other hand, if we set , then the problem becomes too easy because it’s not difficult to figure out whether is close to a multiple of .
Also, can be chosen from , but it can be shown the LWE problem would be equally hard. For efficiency, is usually choosen from a smaller set.
An LWE-Based Encryption Scheme
Finally, let’s fix the (broken) scheme from above. This scheme is due to Oded Regev and his famous paper from 2009.
The key generation is as follows:
The scheme is able to encrypt only one bit at a time, so . To encrypt a message , the encryptor picks a random and outputs:
Note that is the closest integer to (there is no computation in here).
To decrypt:
The decryption is then if this value is closer to and it is if this value is closer to .
Note that this would work as long as . That means we need to choose parameters such that is smaller than .
Public key and ciphertext size trade-offs
Instead of storing the entire (which would require bits), we can use a cryptographic PRF and 256-bit seed . The other part of the public key, , depends on the secret key and cannot be compressed in a similar way. Thus, the total size of the public key is bits.
The ciphertext can be represented using bits. Concrete secure parameter settings will require taking and , making it somewhat inefficient for the encryption of just one plaintext bit to be so large.
There is a generalization of the LWE encryption scheme that allows for various trade-offs between the public key and ciphertext sizes. We modify the sceme above as follows.
Now we can encrypt bits, which we arrange in the matrix . To encrypt , the encryptor picks a random and outputs:
The decryption works as in the previous scheme, but we need to round up elements. We can see that by using different , we obtain a trade-off between the public key and ciphertext sizes.
Optimizations
The ciphertext part contributes bits to the total ciphertext size. Instead of the encryptor publishing all bits of each coefficient of as part of the ciphertext, the encryptor can transmit only bits per coefficient. This is possible but introduces a further error to the decryption equation.
We choose a set with elements. We want for elements to be "nicely" distributed in . For example:
Then instead of using an element from , we use its closest element from , denoting it by . We denote . Instead of transmitting as part of the ciphertext, one could transmit .
Note that there exists such that .
If the ciphertext is created in this fashion, then the decryption produces where the only difference from the above is the presence of the term. However, if this term is small (and we chose such that the elements of are small), it can be considered just as an additional error, and the decryption process still works.
Modulus switching
Definition: For an element and some positive integer , we define a mapping from to as
We can relate the modulus switching and the compression to the set as described above as:
It can be shown that if one first compresses an element in into an element in (where ) and then decompresses back to , the result won’t be too far from the original element, so is small. To reduced the size of the ciphertext, we use instead of .
Learning with rounding
It turns out that when the compression is used, we can omit adding the error because it’s already added by the compression/decompression step. Therefore, instead of using , we can simply use because the probability that is high.
The advantage of making the LWR assumption is that it allows for smaller parameters because it does not add the error .
Encrypting more bits per slot
The encryption scheme above packed the -bit message into a matrix . However, it could also be packed into a matrix .
For decryption to work, the encryption needs to be modified to use instead of . The parameters need to be adjusted such that the error is smaller than rather than .
Non-interactive key exchange
What follows is a protocol for two parties to agree on a single bit . To agree on a shared key of more bits, the techniques described above can be employed.
There is a public random matrix that is trusted by everyone to have been honestly generated. The first party chooses , and the second party chooses . The first party computes
and sends it to the second party. The second party computes
and sends it to the first party.
The first party computes
If this value is closer to , it sets . If it is closer to , it sets .
The second party computes
If this value is closer to , it sets . If it is closer to , it sets .
If the error terms are small enough, it holds , and the two parties agreed on a shared bit.