On the (in)security of ElGamal in OpenPGP (RWC’22)

In this blog post we will talk about a cross-configuration attack of ElGamal encryption in the OpenPGP ecosystem discovered by three IBM researchers: Luca De Feo, Bertram Poettering and Alessandro Sorniotti and presented at RWC’22 in Amsterdam.

In the early 90’s, when crypto wasn’t yet short for cryptocurrency, the work of cryptographers began with enforcing the privacy of the users . With the beginning of the Internet came the need to secure communication on bulletin boards. That is how PGP (Pretty Good Privacy), which latter was standardized by the IETF (Internet Engineering Task Force) and became OpenPGP, was born. Metaphorically, or almost literally if you are a US citizen living before 1996, giving munitions to the people to freely discuss and share their ideas.

Even though it was recognized to be one of the most secure encryption program available to the public, it has its flaws. One of its flaws might not even be technical, but rather the complexity of the OpenPGP standard, which in some aspects may explain in part the attack we are focusing on today.

To understand where the security problem discovered by De Feo, Poettering and Sorniotti hides, we need to have a deeper look at the ElGamal public-key encryption scheme which is one of the required public-key algorithms specified in RFC4880 (the technical document that describes how OpenPGP should operate). For history’s sake, we should point out here that ElGamal was chosen at the beginning of the standard, after patent issues with RSA.

ElGamal is a public-key encryption scheme and is thus described by three algorithms:

  • \( \mathsf{KeyGen} \): Let \( (G, \times) \) be a group and \(g \in G\) a generator. Pick a random integer \( x \) and output the secret key, public key pair \( (sk, pk) = (x, g^x) \).
  • \( \mathsf{Encrypt} \): Given \(pk\), to encrypt an element of the group \( M \in G \), pick a random integer \( y \) and output the ciphertext \( C = (g^y, M \cdot g^{xy}) \).
  • \( \mathsf{Decrypt} \) Given \(sk \) and \(C = (g^y, M \cdot g^{xy}) \), to decrypt, first compute \(g^{xy} = (g^{y})^x \) and then compute \( M = \frac{M \cdot g^{xy}}{g^{xy}} \) where the dividend is the second component of the ciphertext and the divisor has been computed in the first decryption step.

Although this description looks very formal and one may think at first it doesn’t leave much room for interpretation, the authors of the attack point out that so far, a few crucial questions haven’t been answered:

  • Which group \((G, \times) \) should one use ?
  • How do we choose the generator \(g\), and what exactly should \(g\) generate ?
  • From which sets are \(x\) and \(y\) picked and following what distribution ?

Looking for answers to these questions in the context of OpenPGP, the authors note that the RFC4880 gives references to where to find exact specifications for those parameters but looking at three libraries: Go, Crypto++ and gcrypt they show that in practice the standard has been implemented using different parameters.

Without going into too much details, the authors show two kinds of attacks. First, one which demonstrates that there exists two interpretations of Elgamal, actually used in the wild, such that if one is used for \(\mathsf{KeyGen}\) and another one for \(\mathsf{Encrypt}\), this could allow an attacker to practically recover the plaintext. The second attack also relies on misconfiguration but requires side channel analysis. In brief, in some cases if a Crypto++ key is used inside gcrypt for decryption, the author show a practical key recovery attack. Such an attack can be conducted if the attacker and the victim are using co-located Virtual Machines for example.

It’s not the first time bugs were found in OpenPGP, and being a somewhat old standard it was designed without some features like forward secrecy that we now consider essential. This raises the question of what to expect for a new standard for secure messaging. As we are talking about standardizing new cryptographic technologies, reflecting on the evolution of OpenPGP may also give us opportunity to learn about how standards should evolve along with progress in fundamental research.

If you want to dig deeper into the topic:

  • The paper: https://eprint.iacr.org/2021/923
  • An history of OpenPGP: https://arxiv.org/abs/2008.06913
  • RFC4880: https://datatracker.ietf.org/doc/html/rfc4880
  • Effort for standardizing MLS: https://en.m.wikipedia.org/wiki/Messaging_Layer_Security