Co6GC: Hybrid encryption

This post is part of COSIC’s Guide to Crypto, in which researchers from COSIC are informally writing about different concepts in cryptography. Our aim is to introduce the reader to these concepts with explanations, illustrations and examples. In this blog post I will explain a fundamental construction that is behind every day cryptography, that of hybrid encryption.

Motivation

The magic of public key cryptography is that it makes possible data confidentiality between two entities that might not have communicated before. However, in practice, public key encryption schemes are never used alone, pretty much as block ciphers are useless without a mode of operation. Hybrid encryption aims to solve the inherent limitations of public key ciphers, notably large keys and limitation of the plaintext space. As the name suggests, this is achieved by combining a public key algorithm (called key encapsulation mechanism or KEM) and a symmetric key encryption scheme (in this context called data encapsulation mechanism or DEM).

Suppose you want to encrypt a message \( m \). The idea is to generate a shared public key \( \mathfrak{pk}\) that will be used to encrypt (encapsulate) a session (symmetric) key \( k \). The session key is the one meant to encrypt the message \( m \). Therefore, this process will produce two ciphertexts, one encrypting the message \( m \) and another one encrypting the session key \( k \).

Decryption is then straighforward: you have to decapsulate the session key first and with that you can decrypt the ciphertext hiding the message.

The hybrid approach has a number of advantages over general purpose public key encryption: first of all, it follows what is a sacred principle in Computer Science, that is modularity. The single components are way easier to construct and analyze. As a consequence, a modular design is quite flexible, as each of its components can be replaced with better ones if necessary (this very phenomenon is happening now for a family of KEMs – see later).  And of course efficiency: when a fast symmetric key encryption scheme is used in combination with a mode of operation one can efficiently encrypt messages of arbitrary length.

A natural question is how the security of the hybrid scheme is related to the security of its KEM and DEM. In this blog post I will focus on the notion of IND-CCA security, as this is the security level required for modern public key encryption schemes.

First, I will describe the basic components, KEM and DEM, that make up an hybrid scheme.

Key encapsulation mechanism (KEM)

A KEM is described by the following three algorithms:

  • \( \mathsf{KeyGen}(1^{\lambda}) \): a probabilistic algorithm that takes the security parameter \( \lambda \) and outputs a key pair \( (\mathfrak{pk}, \mathfrak{sk}) \).
  •  \( \mathsf{Encaps}_{\mathfrak{pk}}(1^{\lambda}) \): a probabilistic algorithm that takes the security parameter \( \lambda \) and the public key \( \mathfrak{pk} \) and outputs a pair \( (k, c ) \), where \( k \) is a symmetric key and \( c \) is the cipher text that encapsulates \(k \).
  • \( \mathsf{Decaps}_{\mathfrak{sk}}(1^{\lambda}, c) \): a deterministic algorithm that takes the security parameter \( \lambda \), the secret key \( \mathsf{sk} \) and a ciphertext \(c \) and either returns the encapsulated symmetric key \( k \) or aborts if there is no such a key.

We allow a negligible probability that the key pair generated by the algorithm \( \mathsf{KeyGen} \) does not give a valid encapsulation. More precisely, let \( \mathsf{BadKeyPair}(\lambda) \) be the event that \( \mathsf{KeyGen} \) generates a key pair \( ( \mathfrak{pk}, \mathfrak{sk} ) \) such that \( \mathsf{Decaps}_{\mathfrak{sk}} (1^{\lambda}, c) = \perp \) for a ciphertext \( c \) that encapsulates a key \( k \). The KEM is then correct if the probability that \( \mathsf{BadKeyPair} \) happens is negligible in \( \lambda \).

The idea behind the notion of IND-CCA security is that an adversary should not be able to tell whether a key is truly random or is encapsulated into the challenging ciphertext \( c^* \). The security game is explained in the following figure. Note that the oracle queries to the encapsulation algorithm are implicit as the adversary can simply run it on its own using the public key.

We say that the KEM \( \Pi = \left( \mathsf{KeyGen}, \mathsf{Encaps}, \mathsf{Decaps} \right) \) is IND-CCA secure if for any probabilistic polynomial time adversary \( \mathcal{A} \) the advantage of \( \mathcal{A} \) in winning the above game is negligible in the security parameter \( \lambda \), that is

\( \text{Adv}^{\text{IND-CCA}}_{\Pi, \mathcal{A}} = \left| \text{Pr} \left[ b’ = b \right] – \frac{1}{2} \right| = \frac{1}{2} \left| \text{Pr}\left[ \mathcal{A} \text{ outputs }1 \vert b = 1 \right] – \text{Pr}\left[ \mathcal{A} \text{ outputs }1 \vert b = 0 \right] \right| \leq \text{negl}(\lambda) \).

The following KEMs are considered standards [2]:

  • ECIES-KEM, based on discrete logarithm problem
  • PSEC-KEM, based on discrete logarithm problem
  • ACE-KEM, based on discrete logarithm problem
  • RSA-KEM, based on the RSA problem.

Regarding very likely a future migration from classic assumptions to those we believe to be quantum resistant, NIST announced a competition [3] to standardize public key primitives that rely on those problems. Among them are a number of KEMs as these serve as building blocks to construct public key encryption schemes.

Data encapsulation mechanism (DEM)

A DEM will be just an ordinary symmetric key encryption scheme \( \Pi^s = \left( \mathsf{KeyGen}^s, \mathsf{Enc}^s, \mathsf{Dec}^s \right) \) that is IND-CCA secure. Since the session key is only used to encrypt a single message, one can limit themselves to the weaker notion of one time IND-CCA security (ot-IND-CCA). The relevant interactive game is given below:

A DEM \( \Pi^s = \left( \mathsf{KeyGen}^s, \mathsf{Enc}^s, \mathsf{Dec}^s \right) \) is ot-IND-CCA secure if for any PPT adversary \( \mathcal{A} \) the advantage of \( \mathcal{A} \) in winning the above game is negligible in the security parameter \( \lambda \):

\( \text{Adv}^{\text{ot-IND-CCA}}_{\Pi^s, \mathcal{A}} = \left| \text{Pr} \left[ b’ = b \right] – \frac{1}{2} \right| = \frac{1}{2} \left| \text{Pr}\left[ \mathcal{A} \text{ outputs }1 \vert b = 1 \right] – \text{Pr}\left[ \mathcal{A} \text{ outputs }1 \vert b = 0 \right] \right| \leq \text{negl}(\lambda) \).

Note that the adversary is not allowed to query the encryption algorithm as the symmetric key \( k \) is generated each time an encryption request is made. Nevertheless it is still able to call the decryption oracle many times. In [1] it is shown how to construct a DEM by essentially adding a one-time secure MAC to an IND-CPA symmetric key encryption scheme.

Hybrid encryption scheme (KEM/DEM)

Having defined a KEM and a DEM, I will explain how to combine these two parts in order to get a public key encryption scheme. An hybrid encryption scheme \( \Pi^{hy} \) is defined by the following algorithms:

  • \( \mathsf{KeyGen}^{hy}(1^{\lambda}) \): a probabilistic algorithm that takes the security parameter \( \lambda \) and simply runs \( \mathsf{KeyGen}(1^{\lambda}) \) to generate the key pair \( (\mathfrak{pk}, \mathfrak{sk}) \).
  • \( \mathsf{Enc}^{hy}_{\mathfrak{pk}}(1^{\lambda}, m) \): a probabilistic algorithm that on input the security parameter \( \lambda \) and a message \( m \), first runs \( \mathsf{Encaps}_{\mathfrak{pk}}(1^{\lambda}) \) to generate an encapsulation \( c_1 \) of a symmetric key \( k \) and then computes \( c_2 = \mathsf{Enc}^s_k(1^{\lambda}, m) \). The algorithm outputs the ciphertext \( c = ( c_1, c_2 ) \).
  • \( \mathsf{Dec}^{hy}_{\mathfrak{sk}}(1^{\lambda}, c) \): a deterministic algorithm that on input the security parameter \( \lambda \) and a ciphertext \( c = (c_1, c_2 ) \) does the following: first it runs \( \mathsf{Decaps}_{\mathfrak{sk}}(1^{\lambda}, c_1) \); if this step results in an abort then it aborts too. Otherwise it retrieves the symmetric key \( k \) encapsulated by \( c_1 \). Then it runs \( \mathsf{Dec}^s_k(1^{\lambda}, c_2) \) and get the plaintext \( m \). The algorithm outputs the plaintext \( m \).

The IND-CCA security game for \( \Pi^{hy} \) is given below.

Note that the high level design of this game is exactly the same as in an ordinary IND-CCA secure public key encryption scheme, which is consistent with the fact that we do want to design a public key encryption scheme.

The hybrid encryption scheme \( \Pi^{hy} = \left( \mathsf{KeyGen}^{hy}, \mathsf{Enc}^{hy}, \mathsf{Dec}^{hy} \right) \) is IND-CCA secure if for any PPT adversary \( \mathcal{A} \) the advantage of \( \mathcal{A} \) in winning the above game is negligible in the security parameter \( \lambda \):

\( \text{Adv}^{\text{IND-CCA}}_{\Pi^{hy}, \mathcal{A}} = \left| \text{Pr} \left[ b’ = b \right] – \frac{1}{2} \right| = \frac{1}{2} \left| \text{Pr}\left[ \mathcal{A} \text{ outputs }1 \vert b = 1 \right] – \text{Pr}\left[ \mathcal{A} \text{ outputs }1 \vert b = 0 \right] \right| \leq \text{negl}(\lambda) \).

The following result, appeared in [1], shows that in order to build an IND-CCA hybrid scheme it is sufficient that both the KEM and DEM achieve the same security level.

Theorem: given an IND-CCA secure KEM \( \Pi = \left( \mathsf{KeyGen}, \mathsf{Encaps}, \mathsf{Decaps} \right) \) and a ot-IND-CCA secure DEM \( \Pi^s = \left( \mathsf{KeyGen}^s, \mathsf{Enc}^s. \mathsf{Dec}^s \right) \), then the resulting hybrid encryption scheme \( \Pi^{hy} = \left( \mathsf{KeyGen}^{hy}, \mathsf{Enc}^{hy}, \mathsf{Dec}^{hy} \right) \) is IND-CCA secure.

To prove the theorem I am going to define a series of games Game\(_{-1}\), Game\(_0\) and Game\(_1\), each of them being a slight modification of the previous one and study the fluctuations of the probabilities Pr\( \left( \mathsf{E}_i \right) \), where \( \mathsf{E}_i \) is the event that the adversary wins in Game\(_i\). Let \( \mathcal{A} \) be a fixed PPT adversary trying to break the IND-CCA security of the hybrid scheme \( \Pi^{hy} \).

Define Game\(_{-1}\) as the IND-CCA security game for the hybrid encryption scheme. Then modify the decryption oracle of Game\(_{-1} \) so that when a ciphertext \( (c_1, c_2) \) with \( c_1 = c^* \) is queried, then the same key \( k^* \) used to encrypt the message \( m_b \) is used instead of decapsulating \( c_1 \). Call the resulting game Game\(_0\).

There is no way for the adversary to perceive this change unless the event \( \mathsf{BadKeyGen} \) occurs. As long as it does not, the games are identical. In terms of probabilities this means

\( \text{Pr} \left[ \mathsf{E}_{-1} \wedge \neg \mathsf{BadKeyGen} \right] = \text{Pr}\left[ \mathsf{E}_0 \wedge \neg \mathsf{BadKeyGen} \right] \)

from which it follows that

\( 0 \leq \text{Pr}\left[ \mathsf{E}_i \right] – \text{Pr} \left[ \mathsf{E}_{-1-i} \wedge \neg \mathsf{BadKeyGen} \right] =\)

\(  = \text{Pr} \left[ \mathsf{E}_i \right] – 1 + \text{Pr} \left[ \neg \mathsf{E}_{-1-i} \cup \mathsf{BadKeyGen} \right] \leq \)

\( \leq \text{Pr}\left[ \mathsf{E}_i \right] – \text{Pr}\left[ \mathsf{E}_{-1-i} \right] + \text{Pr}\left[ \mathsf{BadKeyGen} \right].\)

This yields

\( \left| \text{Pr}\left[ \mathsf{E}_0 \right] – \text{Pr}\left[ \mathsf{E}_{-1} \right] \right| \leq \text{Pr}\left[ \mathsf{BadKeyGen} \right]. \)

Now I further modify Game\(_0\) so that instead of using the key \( k^* \) the decryption oracle now uses a completely random key \( \hat{k} \). The resulting game Game\(_1 \) is shown below:

I will now construct a distinguisher machine \( \mathcal{D} \) that internally uses the adversary \( \mathcal{A} \) to break the IND-CCA security of the KEM. The distinguisher must create a suitable environment so that the adversary believes it is being used in the IND-CCA security game of \( \Pi^{hy} \).

The distinguisher strategy is to output \( 0 \) if it detects that the adversary is playing in Game\(_0\) and output \(1\) if it detects that the adversary is playing Game\(_1\). It does that by properly constructing the challenge ciphertext \( c^{**}_1, c^{**}_2 \). Clearly the advantage in breaking its own IND-CCA game of the KEM is essentially the same as distinguishing between Game\(_0\) and Game\(_1\):

\( 2 \cdot \text{Adv}^{\text{IND-CCA}}_{\Pi, \mathcal{D}} = \)

\( =  \left| \text{Pr}\left[ \mathcal{D} \text{ outputs }0\vert \mathcal{A} \text{ plays in }\text{Game}_0 \right] -\text{Pr}\left[ \mathcal{D} \text{ outputs }0\vert \mathcal{A} \text{ plays in }\text{Game}_1 \right] \right| = \)

\( =  \left| \text{Pr}\left[ \mathcal{A} \text{ wins in }\text{Game}_0 \right] -\text{Pr}\left[ \mathcal{A} \text{ wins in }\text{Game}_1 \right] \right|. \)

To close the loop I need to bound the advantage of the adversary in winning in Game\(_1\). This is done by showing an efficient algorithm \( \mathcal{B} \) that runs \( \mathcal{A} \) as subroutine to break the ot-IND-CCA security of the DEM. The algorithm is described below

The algorithm \( \mathcal{B} \) is constructed in such a way that any advantage of \( \mathcal{A} \) in distinguishing between two encryptions results in essentially the same advantage for \( \mathcal{B} \) in breaking the ot-IND-CCA security of the DEM. Therefore

\( \text{Adv}^{\text{IND-CCA}}_{\Pi^s, \mathcal{B}} = \left| \text{Pr}\left[ \mathcal{A} \text{ wins in }\mathsf{Game}_1 \right] – \frac{1}{2} \right| \).

Putting it all together

\( \text{Adv}^{\text{IND-CCA}}_{\Pi^{hy}, \mathcal{A}} =  \left| \text{Pr}\left[ \mathcal{A} \text{ wins in }\mathbf{\mathrm{Game}}_{-1} \right] – \frac{1}{2} \right| =\)

\( = \left| \text{Pr}\left[ \mathcal{A} \text{ wins in }\text{Game}_{-1} \right] -\text{Pr}\left[ \mathcal{A} \text{ wins in }\text{Game}_0 \right] + \right.  \)

\( +\text{Pr}\left[ \mathcal{A} \text{ wins in }\text{Game}_0 \right] -\text{Pr}\left[ \mathcal{A} \text{ wins in }\text{Game}_1 \right] + \)

\( + \left.\text{Pr}\left[ \mathcal{A} \text{ wins in }\text{Game}_1 \right] – \frac{1}{2} \right| \leq \)

\( \leq \text{Pr}\left[\mathsf{BadKeyGen}\right] + 2\text{Adv}^{\text{IND-CCA}}_{\Pi, \mathcal{D}} + 2\text{Adv}^{\text{ot-IND-CCA}}_{\Pi^{s}, \mathcal{B}}. \)

As the above terms are negligible by hypothesis, then the statement follows. Q.E.D.

References

[1] R. Cramer & V. Shoup, Design and Analysis of Practical Public-Key Encryption Schemes Secure against Adaptive Chosen Ciphertext Attack. SIAM Journal of Computing, 33(1): 167-226, 2003.

[2] ISO/IEC 18033, a free version available at https://www.shoup.net/iso/

[3] https://csrc.nist.gov/projects/post-quantum-cryptography/post-quantum-cryptography-standardization