
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
        <title><![CDATA[ The Cloudflare Blog ]]></title>
        <description><![CDATA[ Get the latest news on how products at Cloudflare are built, technologies used, and join the teams helping to build a better Internet. ]]></description>
        <link>https://blog.cloudflare.com</link>
        <atom:link href="https://blog.cloudflare.com/" rel="self" type="application/rss+xml"/>
        <language>en-us</language>
        <image>
            <url>https://blog.cloudflare.com/favicon.png</url>
            <title>The Cloudflare Blog</title>
            <link>https://blog.cloudflare.com</link>
        </image>
        <lastBuildDate>Sat, 04 Apr 2026 18:46:34 GMT</lastBuildDate>
        <item>
            <title><![CDATA[Post-quantumify internal services: Logfwrdr, Tunnel, and gokeyless]]></title>
            <link>https://blog.cloudflare.com/post-quantumify-cloudflare/</link>
            <pubDate>Fri, 25 Feb 2022 16:03:12 GMT</pubDate>
            <description><![CDATA[ A big challenge is coming: to change all internal connections at Cloudflare to use post-quantum cryptography. Read how we are tackling this challenge! ]]></description>
            <content:encoded><![CDATA[ <p></p><p>Theoretically, there is no impediment to adding <a href="/post-quantum-taxonomy">post-quantum cryptography</a> to any system. But the reality is harder. In the middle of last year, we posed ourselves a big challenge: <b>to change all</b> <b><i>internal connections</i></b> <b>at Cloudflare to use post-quantum cryptography</b>. We call this, in a cheeky way, “post-quantum-ifying” our services. Theoretically, this should be simple: swap algorithms for post-quantum ones and move along. But with dozens of different services in various programming languages (as we have at Cloudflare), it is not so simple. The challenge is big, but we are here and up for the task! In this blog post, we will look at what our plan was, where we are now, and what we have learned so far. Welcome to the first announcement of a post-quantum future at Cloudflare: our connections are going to be quantum-secure!</p>
    <div>
      <h3>What are we doing?</h3>
      <a href="#what-are-we-doing">
        
      </a>
    </div>
    <p>The life of most requests at Cloudflare <a href="/more-data-more-data/">begins and ends at the edge</a> of our global network. Not all requests are equal and on their path they are transmitted by several protocols. Some of those protocols provide security properties whilst others do not. For the protocols that do, for context, Cloudflare uses: <a href="/rfc-8446-aka-tls-1-3/">TLS</a>, <a href="/tag/quic/">QUIC</a>, <a href="/1111-warp-better-vpn/">WireGuard</a>, <a href="/tag/dnssec/">DNSSEC</a>, <a href="/anycast-ipsec/">IPsec</a>, <a href="/privacy-pass-v3/">Privacy Pass</a>, and more. Migrating all of these protocols and connections to use post-quantum cryptography is a formidable task. It is also a task that we do not treat lightly because:</p><ul><li><p>We have to be assured that the security properties provided by the protocols are not diminished.</p></li><li><p>We have to be assured that performance is not negatively affected.</p></li><li><p>We have to be wary of other requirements of our ever-changing ecosystem (like, for example, keeping in mind our <a href="https://www.cloudflare.com/en-gb/press-releases/2021/cloudflare-hits-milestone-in-fedramp-approval/">FedRAMP certification efforts</a>).</p></li></ul><p>Given these requirements, we had to decide on the following:</p><ul><li><p>How are we going to introduce post-quantum cryptography into the protocols?</p></li><li><p>Which protocols will we be migrating to post-quantum cryptography?</p></li><li><p>Which Cloudflare services will be targeted for this migration?</p></li></ul><p>Let’s explore now what we chose: welcome to our path!</p>
    <div>
      <h3>TLS and post-quantum in the real world</h3>
      <a href="#tls-and-post-quantum-in-the-real-world">
        
      </a>
    </div>
    <p>One of the most used security protocols is Transport Layer Security (TLS). It is the vital protocol that protects most of the data that flows over the Internet today. Many of Cloudflare’s internal services also rely on TLS for security. It seemed natural that, for our migration to post-quantum cryptography, we would start with this protocol.</p><p>The protocol provides three security properties: integrity, authentication, and confidentiality. The algorithms used to provide the first property, integrity, seem to not be <a href="https://research.kudelskisecurity.com/2017/02/01/defeating-quantum-algorithms-with-hash-functions/">quantum-threatened</a> (there is <a href="https://eprint.iacr.org/2012/606.pdf">some research</a> on the matter). The second property, authentication, is under quantum threat, but we will not focus on it for reasons detailed later. The third property, confidentiality, is the one that we are interested in protecting as it is urgent to do this now.</p><p>Confidentiality assures that no one other than the intended receiver and sender of a message can read the transmitted message. Confidentiality is especially threatened by quantum computers as an attacker can record traffic now and decrypt it in the future (when they get access to a quantum computer): this means that all past and current traffic, not just future traffic, is vulnerable to be read by anyone who obtains a quantum computer (and has stored the encrypted traffic captured today).</p><p>At Cloudflare, to protect many of our connections, we use TLS. We mainly use the latest version of the protocol, TLS 1.3, but we sometimes do still use TLS 1.2 (as seen in the image, though, it only shows the connections between websites to our network).  As we are a company that pushes for innovation, this means that we are intent on using this time of migration to post-quantum cryptography as an opportunity to also update TLS handshakes to 1.3 and be assured that we are using TLS in the right way (by, for example, ensuring that we are not using deprecated features of TLS).</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5toLKjOnOcTdY4jkqTodFb/80452cac0010e2311e76e31c0a138820/image2-24.png" />
            
            </figure><p>Cloudflare’s TLS and QUIC usage <a href="https://radar.cloudflare.com/#anchor-tls-versions-vs">taken on</a> the 17/02/2022 and showing the last 7 days.</p><p>Changing TLS 1.3 to provide quantum-resistant security for its confidentiality means changing the ‘key exchange’ phase of the TLS handshake. Let’s briefly look at how the TLS 1.3 handshake works.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5qFzOkZw6F47b7q1FeoJrf/c781aa2f7621d61664b7f7efafe3927e/image3-26.png" />
            
            </figure><p>The TLS 1.3 handshake</p><p>In <a href="https://datatracker.ietf.org/doc/html/rfc8446">TLS 1.3</a>, there will always be two parties: a client and a server. A client is a party that wants the server to “serve” them something, which could be a website, emails, chat messages, voice messages, and more. The handshake is the process by which the server and client attempt to agree on a shared secret, which will be used to encrypt the subsequent exchange of data (this shared secret is called the “master secret”). The client selects their favorite key exchange algorithms and submits one or more “key shares” to the server (they send both the name of the key share and its public key parameter). The server picks one of the key exchange algorithms (assuming that it supports one of them), and replies with their own key share. Both the server and the client then combine the key shares to compute a shared secret (the “master secret”), which is used to protect the remainder of the connection. If the client only chooses algorithms that the server does not support, the server instead replies with the algorithms that it does support and asks the client to try again. During this initial conversation, the client and server also agree on authentication methods and the parameters for encryption, but we can leave that aside for today in this blog post. This description is also simplified to focus only in the “key exchange” phase.</p><p>There is a mechanism to add post-quantum cryptography to this procedure: you advertise post-quantum algorithms in the list of key shares, so the final derived shared key (the “master secret”) is quantum secure. But there are requirements we had to take into account when doing this with our connections: the security of much post-quantum cryptography is still under debate, and we need to respect our <a href="https://www.cloudflare.com/en-gb/trust-hub/compliance-resources/">compliance efforts</a>. The solution to these requirements is to use a <a href="https://datatracker.ietf.org/doc/draft-ietf-tls-hybrid-design/">“hybrid” mechanism</a>.</p><p>A “hybrid” mechanism means to use both a “pre-quantum” or “classical” algorithm and a “post-quantum” algorithm, and mixing both generated shared secrets into the derivation of the “master secret”. The combination of both shared secrets is of the form \Z′ = Z || T\ (for TLS and with the fixed size shared secrets, simple concatenation is secure. In other cases, you have to be a bit more careful). This procedure is a concatenation consisting of:</p><ul><li><p>A “classical” shared secret <i>Z</i>, derived following the guidelines of <a href="https://www.nist.gov/standardsgov/compliance-faqs-federal-information-processing-standards-fips#:~:text=are%20FIPS%20developed%3F-,What%20are%20Federal%20Information%20Processing%20Standards%20(FIPS)%3F,by%20the%20Secretary%20of%20Commerce.">Federal Information Processing Standards</a> (FIPS 104-2) <a href="https://en.wikipedia.org/wiki/FIPS_140-2">approved mechanisms</a> (as recommended <a href="https://csrc.nist.gov/publications/detail/sp/800-56a/rev-3/final">over</a> <a href="https://csrc.nist.gov/publications/detail/sp/800-56b/rev-2/final">here</a>), like, for example, the <a href="https://csrc.nist.gov/csrc/media/events/workshop-on-elliptic-curve-cryptography-standards/documents/papers/session6-adalier-mehmet.pdf">P-256 elliptic curve</a>.</p></li><li><p>An auxiliary shared secret <i>T</i>, derived with some other method: in this case, in a quantum-secure way.</p></li></ul><p>The usage of a “hybrid” approach allows us to safeguard our connections in case the security of the post-quantum algorithm fails. It also results in a suitable-for-FIPS secret, as it is approved in the <a href="https://csrc.nist.gov/publications/detail/sp/800-56c/rev-2/final">“Recommendation for Key-Derivation Methods in Key-Establishment Schemes”</a> (SP 800-56C Rev. 2), which is listed in the <a href="https://csrc.nist.gov/csrc/media/publications/fips/140/2/final/documents/fips1402annexd.pdf">Annex D</a>, as an approved key establishing technique for FIPS 140-2.</p><p>At Cloudflare, we are using different TLS libraries. We decided to add post-quantum cryptography to those, specifically, to the <a href="https://csrc.nist.gov/projects/cryptographic-module-validation-program/Certificate/3318"><i>BoringCrypto</i></a> library or the compiled version of <a href="https://github.com/golang/go/tree/dev.boringcrypto.go1.8">Golang with <i>BoringCrypto</i></a>. We added <a href="https://github.com/cloudflare/circl/tree/master/kem/kyber">our implementation</a> of the <a href="https://pq-crystals.org/kyber/resources.shtml">Kyber-512</a> algorithm (this algorithm can be eventually swapped by another one; we’re not picking any here. Not only that, but we are using it for our testing phase) to those libraries and implemented the “hybrid” mechanism as part of the TLS handshake. For the “classical” algorithm we used <a href="https://en.wikipedia.org/wiki/Elliptic-curve_cryptography">curve P-256</a>. We then compiled certain services with these new TLS libraries.</p><table><tr><td><p><b>Name of algorithm</b></p></td><td><p><b>Number of times loop executed</b></p></td><td><p><b>Average runtime per operation</b></p></td><td><p><b>Number of bytes required per operation</b></p></td><td><p><b>Number of allocations</b></p></td></tr><tr><td><p>Curve P-256</p></td><td><p>23,056</p></td><td><p>52,204 ns/op</p></td><td><p>256™p</p></td><td><p>5 allocs/op</p></td></tr><tr><td><p>Kyber-512</p></td><td><p>100,977</p></td><td><p>11,793 ns/op</p></td><td><p>832 B/op</p></td><td><p>3 allocs/op</p></td></tr></table><p>Table 1: Benchmarks of the “key share” operation of Curve P-256 and Kyber-512: Scalar Multiplication and Encapsulation respectively. Benchmarks ran on Darwin, amd64, Intel(R) Core(TM) i7-9750H CPU @ 2.60 GHz.</p><p>Note that as TLS supports the described “negotiation” mechanism for the key exchange, the client and server have a way of mutually deciding what algorithms they want to use. This means that it is not required that both a client or a server support or even prefer the exact same algorithms: they just need to share support for a single algorithm for a handshake to succeed. In turn, herewith, even if we advertise post-quantum cryptography and a server/client does not support it, they will not fail but rather agree on some other algorithm they share.</p><p>A note on a matter we left on hold above: why are we not migrating the authentication phase of TLS to post-quantum? Certificate-based authentication in TLS, which is the one we commonly use at Cloudflare, also depends on systems on the wider Internet. Thus, changes to authentication require a coordinated and much wider effort to change. Certificates are attested as proofs of identity by outside parties: migrating authentication means coordinating a ceremony of migration with these outside parties. Note though that at Cloudflare we use a <a href="/how-to-build-your-own-public-key-infrastructure/">PKI with internally-hosted Certificate Authorities (CAs)</a>, which means that we can more easily change our algorithms. This will still need careful planning. We will not do this today, but we will in the near future.</p>
    <div>
      <h3>Cloudflare services</h3>
      <a href="#cloudflare-services">
        
      </a>
    </div>
    <p>The first step of our post-quantum migration is done. We have TLS libraries with post-quantum cryptography using a hybrid mechanism. The second step is to test this new mechanism in specific Cloudflare connections and services. We will look at three systems from Cloudflare that we have started migrating to post-quantum cryptography. The services in question are: Logfwrdr, Cloudflare Tunnel, and GoKeyless.</p>
    <div>
      <h3>A post-quantum Logfwdr</h3>
      <a href="#a-post-quantum-logfwdr">
        
      </a>
    </div>
    <p><a href="/more-data-more-data/">Logfwdr</a> is an internal service, written in Golang, that handles structured logs, and sends them from our servers for processing (to a subservice called ‘Logreceiver’) where they write them to Kafka. The connection between Logfwdr and Logreceiver is protected by TLS. The same goes for the connection between Logreceiver and <a href="https://kafka.apache.org/">Kafka</a> in core. Logfwdr pushes its logs through “streams” for processing.</p><p>This service seemed an ideal candidate for migrating to post-quantum cryptography as its architecture is simple, it has long-lived connections, and it handles a lot of traffic. In order to first test the viability of using post-quantum cryptography, and, we created our own instance of Logreceiver and deployed it. We also created our own stream (the “pq-stream”), which is basically a copy of a HTTP stream (which was remarkably easy to add). We then compiled these services with the modified TLS library, and we got a post-quantum protected Logfwdr.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2YlRJqczYHpPshoEZzpu9b/160d794b37b407bb09fd345b889101c7/image7-5.png" />
            
            </figure><p>Figure 1: TLS latency of Logfwdr for selected metals. Notice how post-quantum cryptography is faster than non-post-quantum one (it is labeled with a “PQ” acronym).</p><p>What we found was that using post-quantum cryptography is faster than using “classical” cryptography! This was expected, though, as we are using a lattice-based post-quantum algorithm (Kyber512). The TLS latency of both post-quantum handshakes and “classical” ones can be noted in Figure 1. The figure shows more handshakes are executed than usual behavior as these servers are frequently restarted.</p><p>Note though that we are not using “only” post-quantum cryptography but rather the “hybrid” mechanism described above. This could increase performance times: in this case, the increase was minimal and still kept the post-quantum handshakes faster than the classical ones. Perhaps what makes the TLS handshakes faster in the post-quantum case is the usage of TLS 1.3, as the “classical” Logfwdr is using TLS 1.2. Logfwdr, though, is a service that executes long-lived handshakes, so in aggregate TLS 1.2 is not “slower” but it does have a slower start time.</p><p>As shown in Figure 2, the average batch duration of the post-quantum stream is lower than when not using post-quantum cryptography. This may be in part due to the fact that we are not sending the quantum-protected data all the way to Kafka (as the non-post-quantum stream is doing). We didn’t yet change the connection to Kafka post-quantum.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/7s0OprfksLusP0685ydiYl/69af1192a703c1224f746673d83c44d2/image8-3.png" />
            
            </figure><p>Figure 2: Average batch send duration: post-quantum (orange) and non-post-quantum streams (green).</p><p>We didn’t encounter any failures during this testing that ran for about some weeks. This gave us good insight that putting post-quantum cryptography into our internal network with actual data is possible. It also gave us confidence to begin migrating codebases to modified TLS libraries, which we will maintain.</p><p>What are the next steps for Logfwdr? Now that we confirmed it is possible, we will first start migrating stream by stream to this hybrid mechanism until we reach full post-quantum migration.</p>
    <div>
      <h3>A post-quantum gokeyless</h3>
      <a href="#a-post-quantum-gokeyless">
        
      </a>
    </div>
    <p><a href="/going-keyless-everywhere/"><i>gokeyless</i></a> is our own way to separate servers and TLS long-term private keys. With it, private keys are kept on a specialized key server operated by customers on their own architecture or, if using <a href="/introducing-cloudflare-geo-key-manager/">Geo Key Manager</a>, in selected Cloudflare locations. We also use it for Cloudflare-held private keys with a service creatively known as <i>gokeyless-internal</i>. The final piece of this architecture is another service called <a href="/scaling-geo-key-manager/"><i>Keynotto</i></a>. Keynotto is a service written in Rust that only mints RSA and <a href="https://www.cloudflare.com/learning/dns/dnssec/ecdsa-and-dnssec/">ECDSA</a> key signatures (that are executed with the stored private key).</p><p>How does the overall architecture of gokeyless work? Let’s start with a request. The request arrives at the Cloudflare network, and we perform TLS termination. Any signing request is forwarded to Keynotto. A small portion of requests (specifically from GeoKDL or external gokeyless) cannot be handled by Keynotto directly, and are instead forwarded to gokeyless-internal. gokeyless-internal also acts as a key server proxy, as it redirects connections to the customer’s keyservers (external gokeyless). <a href="https://github.com/cloudflare/gokeyless">External gokeyless</a> is both the server that a customer runs and the client that will be used to contact it. The architecture can be seen in Figure 3.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5c2XtFKTmHLgy9XNmAfJsh/496e49511e6aea34309abbae92b846f5/image5-10.png" />
            
            </figure><p>Figure 3: The life of a gokeyless request.</p><p>Migrating the transport that this architecture uses to post-quantum cryptography is a bigger challenge, as it involves migrating a service that lives on the customer side. So, for our testing phase, we decided to go for the simpler path that we are able to change ourselves: the TLS handshake between Keynotto and gokeyless-internal. This small test-bed means two things: first, that we needed to change another TLS library (as Keynotto is written in Rust) and, second, that we needed to change gokeyless-internal in such a way that it used post-quantum cryptography only for the handshakes with Keynotto and for nothing else. Note that we did not migrate the signing operations that gokeyless or Keynotto executes with the stored private key; we just migrated the transport connections.</p><p>Adding post-quantum cryptography to the <a href="https://github.com/rustls/rustls">rustls codebase</a> was a straightforward exercise and we exposed an easy-to-use API call to signal the usage of post-quantum cryptography (as seen in Figure 4 and Figure 5). One thing that we noted when reviewing the TLS usage in several Cloudflare services is that giving the option to choose the algorithms for a ciphersuite, key share, and authentication in the TLS handshake confuses users. It seemed more straightforward to define the algorithm at the library level, and have a boolean or API call signal the need for this post-quantum algorithm.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4i2qzprdHeQ5F7Y9CLn1S2/354947695ac81ead9fd7e414a562bc37/image9-3.png" />
            
            </figure><p>Figure 4: post-Quantum API for rustls.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5rk2okKUdjZmpisim3f5bk/bd2b2bec41309221236591c53b071d6d/image4-16.png" />
            
            </figure><p>Figure 5: usage of the post-quantum API for rustls.</p><p>We ran a small test between Keynotto and gokeyless-internal with much success. Our next steps are to integrate this test into the real connection between Keynotto and gokeyless-internal, and to devise a plan for a customer post-quantum protected gokeyless external. This is the first instance in which our migration to post-quantum will not be ending at our edge but rather at the customer’s connection point.</p>
    <div>
      <h3>A post-quantum Cloudflare Tunnel</h3>
      <a href="#a-post-quantum-cloudflare-tunnel">
        
      </a>
    </div>
    <p><a href="https://www.cloudflare.com/en-gb/products/tunnel/">Cloudflare Tunnel</a> is a reverse proxy that allows customers to quickly connect their private services and networks to the Cloudflare network without having to expose their public IPs or ports through their firewall. It is mainly managed at the customer level through the <a href="https://github.com/cloudflare/cloudflared">usage of <i>cloudflared</i></a><i>,</i> a lightweight server-side daemon_,_ in their infrastructure. <i>cloudflared</i> opens several long-lived TCP connections (although, <i>cloudflared</i> is <a href="/getting-cloudflare-tunnels-to-connect-to-the-cloudflare-network-with-quic/">increasingly using the QUIC</a> protocol) to servers on <a href="https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-edge-computing/">Cloudflare’s global network</a>. When a request to a hostname comes, it is proxied through these connections to the origin service behind <i>cloudflared</i>.</p><p>The easiest part of the service to make post-quantum secure appears to be the connection between our network (with a service part of Tunnel called <i>origintunneld</i> located there) and <i>cloudflared</i>, which we have started migrating. While exploring this path and looking at the whole life of a Tunnel connection, we found something more interesting, though. When the Tunnel connections eventually reach core, they end up going to a service called <i>Tunnelstore</i>. <i>Tunnelstore</i> runs as a stateless application in a Kubernetes deployment, and to provide TLS termination (alongside load balancing and more) it uses a <a href="https://kubernetes.io/">Kubernetes</a> <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">ingress</a>.</p><p>The <a href="/cloudflare-ingress-controller/">Kubernetes ingress</a> we use at Cloudflare is made of <a href="https://www.envoyproxy.io/">Envoy</a> and <a href="https://projectcontour.io/">Contour</a>. The latter configures the former depending on Kubernetes resources. Envoy uses the <a href="https://www.envoyproxy.io/docs/envoy/latest/faq/build/boringssl">BoringSSL library</a> for TLS. Switching TLS libraries in Envoy seemed difficult: there are <a href="https://github.com/envoyproxy/envoy-openssl">thoughts</a> on how to integrate OpenSSL to it (and <a href="https://github.com/open-quantum-safe/oqs-demos/issues/79">even some thoughts</a> on adding post-quantum cryptography) and <a href="https://github.com/envoyproxy/envoy/pull/7377">ways to switch TLS libraries</a>. Adding post-quantum cryptography to a modified version of BoringSSL, and then specifying <a href="https://github.com/google/boringssl/blob/master/INCORPORATING.md">that dependency</a> in the <a href="https://github.com/envoyproxy/envoy/blob/main/bazel/repository_locations.bzl#L74">Bazel file of Envoy</a> seems to be the path to go for, as our internal test has confirmed (as seen in Figure 6). As for Contour, for many years, Cloudflare has been running their own patched version of it: we will have to again patch this version with our Golang library to provide post-quantum cryptography. We will make these libraries (and the TLS ones) available for usage.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/itO6WZ2vhxBBR8Jy8iWRp/5c435ec9ccac61b74fe0f9499b171011/image1-27.png" />
            
            </figure><p>Figure 6: Option to allow post-quantum cryptography in Envoy.</p><p>Changing the Kubernetes ingress at Cloudflare not only makes Tunnel completely quantum-safe (beyond the connection between our global network and <i>cloudflared</i>), but it also makes any other services using ingress safe. Our first tests on migrating Envoy and Contour to TLS libraries that contain post-quantum protections have been successful, and now we have to test how it behaves in the whole ingress ecosystem.</p>
    <div>
      <h3>What is next?</h3>
      <a href="#what-is-next">
        
      </a>
    </div>
    <p>The main tests are now done. We now have TLS libraries (in Go, Rust, and C) that give us post-quantum cryptography. We have two systems ready to deploy post-quantum cryptography, and a shared service (Kubernetes ingress) that we can change. At the beginning of the blog post, we said that “the life of most requests at Cloudflare begins and ends at the edge of our global network”: our aim is that post-quantum cryptography does not end there, but rather reaches all the way to where customers connect as well. Let’s explore the future challenges and this customer post-quantum path in this <a href="/post-quantum-future">other blog post</a>!</p> ]]></content:encoded>
            <category><![CDATA[Research]]></category>
            <category><![CDATA[Cryptography]]></category>
            <category><![CDATA[Post-Quantum]]></category>
            <guid isPermaLink="false">6Idg7A13yPnfsxtQpwQXs1</guid>
            <dc:creator>Sofía Celi</dc:creator>
            <dc:creator>Goutam Tamvada</dc:creator>
            <dc:creator>Thom Wiggers</dc:creator>
        </item>
        <item>
            <title><![CDATA[Building Confidence in Cryptographic Protocols]]></title>
            <link>https://blog.cloudflare.com/post-quantum-formal-analysis/</link>
            <pubDate>Thu, 24 Feb 2022 17:30:00 GMT</pubDate>
            <description><![CDATA[ This blogpost refers to the efforts to use formal/verification/implementation for post-quantum algorithms to achieve better assurance for them. It also touches on our Cloudflare efforts on this ]]></description>
            <content:encoded><![CDATA[ <p><b>An introduction to formal analysis and our proof of the security of KEMTLS</b></p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/393auOPCMHtWuvmZxJZ44s/a634d8c90882e32c599268fddd3cfc6b/Blog-827---KEMs-and-KEMTLS.png" />
            
            </figure><p>Good morning everyone, and welcome to another Post-Quantum–themed blog post! Today we’re going to look at something a little different. Rather than look into the past or future quantum we’re going to look as far back as the ‘80s and ‘90s, to try and get some perspective on how we can determine whether a protocol is or is not secure. Unsurprisingly, this question comes up all the time. Cryptographers like to build fancy new cryptosystems, but just because we, the authors, can’t break our own designs, it doesn’t mean they are secure: it just means we are not smart enough to break them.</p><p>One might at this point wonder why in a post-quantum themed blog post we are talking about security proofs. The reason is simple: the new algorithms that claim to be safe against quantum threats need proofs showing that they actually are safe. In this blog post, not only are we going to introduce how we go about proving a protocol is secure, we’re going to introduce the security proofs of KEMTLS, a version of TLS designed to be more secure against quantum computers, and give you a whistle-stop tour of the formal analysis we did of it.</p><p>Let’s go back for the moment to not being smart enough to break a cryptosystem. Saying “I tried very hard to break this, and couldn’t” isn’t a very satisfying answer, and so for many years cryptographers (and others) have been trying to find a better one. There are some obvious approaches to building confidence in your cryptosystem, for example you could <a href="https://github.com/google/wycheproof">try all previously known attacks</a>, and see if the system breaks. This approach will probably weed out any simple flaws, but it doesn’t mean that some new <a href="https://en.wikipedia.org/wiki/Cryptanalysis_of_the_Enigma">attack won’t be found</a> or even that some new twist on an old one <a href="https://ieeexplore.ieee.org/document/8835216">won’t be discovered</a>.</p><p>Another approach you can take is to offer a large prize to anyone who can break your new system; but to do that not only do you need a <a href="https://en.wikipedia.org/wiki/RSA_Factoring_Challenge">big</a> <a href="https://www.microsoft.com/en-us/msrc/sike-cryptographic-challenge">prize</a> that you can afford to give away if you’re wrong, you can’t be sure that everyone would prefer your prize to, for example, selling an attack to cybercriminals, or even to a government.</p><p>Simply trying hard, and inducing other people to do so too still felt unsatisfactory, so in the late ‘80s researchers started trying to use mathematical techniques to prove that their protocol <a href="https://en.wikipedia.org/wiki/Burrows%E2%80%93Abadi%E2%80%93Needham_logic">was secure</a>. Now, if you aren’t versed in theoretical computer science you might not even have a clear idea of what it even means to “prove” a protocol is secure, let alone how you might go about it, so let’s start at the very beginning.</p>
    <div>
      <h3>A proof</h3>
      <a href="#a-proof">
        
      </a>
    </div>
    <p>First things first: let’s nail down what we mean by a <i>proof</i>. At its most general level, a mathematical proof starts with some assumptions, and by making logical inferences it builds towards a statement. If you can derive your target statement from your initial assumptions then you can be sure that, if your assumptions are right, then your final statement is true.</p><p>Euclid’s famous work, <i>The Elements</i>, a standard math textbook for over 2,000 years, is written in this style. Euclid gives five “postulates”, or assumptions, from which he can derive a huge portion of the geometry known in his day. Euclid’s first postulate, that you can draw a straight line between any two points, is never proven, but taken as read. You can take his first postulate, and his third, that you can draw a circle with any center and radius, and use it to prove his first proposition, that you can draw an equilateral triangle given any finite line. For the curious, you can find <a href="https://gutenberg.org/ebooks/21076">public-domain translations of Euclid’s work</a>.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2qV3nhDT4bKQvndrAnbw9N/a167c02b1a7127c6b2e7207a69a44ea8/Screenshot-2022-02-15-at-22.27.54.png" />
            
            </figure><p>Euclid’s method of drawing an equilateral triangle based on the finite line AB, by drawing two circles around points A and B, with the radius AB. The intersection finds point C of the triangle. Original raster file uploader was Mcgill at en.wikibooks SVG: Beao, Public domain, via Wikimedia Commons.</p><p>Whilst it’s fairly easy to intuit how such geometry proofs work, it’s not immediately clear how one could prove something as abstract as the security of a cryptographic protocol. Proofs of protocols operate in a similar way. We build a logical argument starting from a set of assumptions. Security proofs, however, can be much, much bigger than anything in <i>The Elements</i> (for example, our proof of the security properties of <a href="https://thomwiggers.nl/publication/kemtls/kemtls.pdf">KEMTLS</a>, which we will talk about later, is nearly 500,000 lines long) and the only reason we are able to do such complex proofs is that we have something of an advantage over Euclid. We have computers. Using a mix of human-guided theorem proving and automated algorithms we can prove incredibly complex things, such as the security of protocols as the one we will discuss.</p><p>Now we know that a proof is a set of logical steps built from a set of assumptions, let’s talk a bit about how security proofs work. First, we need to work out how to describe the protocol in terms that we can reason about. Over the years researchers have come up with many ways for describing computer processes mathematically, most famously <a href="https://www.wolframscience.com/prizes/tm23/images/Turing.pdf">Alan Turing defined a-machines, which we now know as Turing Machines</a>, which describe a <i>computer program</i> in an <i>algebraic form</i>. A protocol is slightly more complex than a single program. A protocol can be seen as a number of computers running a set of computer programs that interact with each other.</p><p>We’re going to use a class of techniques called <a href="https://en.wikipedia.org/wiki/Process_calculus"><i>process algebras</i></a> to describe the interacting processes of a protocol. At its most basic level, algebra is the art of generalizing a statement by replacing specific values with general symbols. In standard algebra, these specific values are numbers, so for example we can write <code>(cos 37)² + (sin 37)² = 1</code>, which is true, but we can generalize it to <code>(cos θ)² + (sin θ)² = 1</code>, replacing the specific value, 37, with the symbol θ.</p><p>Now you might be wondering why it’s useful to replace things with symbols. The answer is it lets us solve entire classes of problems instead of solving each individual instance. When it comes to security protocols, this is especially important. We can’t possibly try every possible set of inputs to a protocol and check nothing weird happens to one of them. In fact, one of the assumptions we’re going to make when we prove KEMTLS secure is that trying every possible value for some inputs is impossible<sup>1</sup>. By representing the protocol symbolically, we can write a proof that applies to all possible inputs of the protocol.</p><p>Let’s go back to algebra. A <i>process algebra</i> is similar to the kind of algebra you might have learnt in high school: we represent a computer program with symbols for the specific values. We also treat functions symbolically. Rather than try and compute what happens when we apply a function <code>f</code> to a value <code>x</code>, we just create a new symbol <code>f(x)</code>. An algebra also provides rules for manipulating expressions. For example, in standard algebra we can <i>transform</i> <code>y + 5 = x² - x</code> into <code>y = x² - x - 5</code>. A process algebra is the same: it not only defines a language to describe interacting processes, it also defines rules for how we can manipulate those expressions.</p><p>We can use tools, such as the one we use called <a href="https://tamarin-prover.github.io/">Tamarin</a>, to help us do this reasoning. Every protocol has its own rules for what transformations are allowed. It is very useful to have a tool, like Tamarin, to which we can tell these rules and allow it to do all the work of symbol manipulation. Tamarin does far, far more than that, though.</p><p>A rule, that we tell Tamarin, might look like this:</p>
            <pre><code>rule Register_pk:
  [ Fr(~ltkA) ]
--[ GenLtk($A, ~ltkA)]-&gt;
  [ !Ltk($A, ~ltkA), !Pk($A, pk(~ltkA)), Out(pk(~ltkA)) ]</code></pre>
            <p>This rule is used to represent that a protocol participant has acquired a new public/private key pair. The rule has three parts:</p><ul><li><p>The first part lists the preconditions. In this case, there is only one: we take a <code>Fr</code>esh value called <code>~ltkA</code>, the “long-term key of A”. This precondition is always met, because Tamarin always allows us to generate fresh values.</p></li><li><p>The third part lists the postconditions (what we get back when we apply the rule). Rather than operating on an initial statement, as in high-school algebra, Tamarin instead operates on what we call a model of “bag of facts”. Instead of starting with <code>y + 5 = x² - x</code>, we start with an empty “bag”, and from there, apply rules. These rules take facts out of the bag and put new ones in. In this case, we put in:</p><ul><li><p><code>!Ltk($A, ~ltkA)</code> which represents the private portion of the key, <code>~ltkA</code>, and the name of the participant it was issued to, <code>$A</code>.</p></li><li><p><code>!Pk($A, pk(~ltkA))</code>, which represents the public portion of the key, <code>pk(~ltkA)</code>, and the participant was issued to, <code>$A</code>.</p></li><li><p><code>Out(pk(~ltkA))</code>, which represents us publishing the public portion of the key, <code>pk(~ltkA)</code> to the network. Tamarin is based on the <a href="https://en.wikipedia.org/wiki/Dolev%E2%80%93Yao_model">Dolev-Yao model</a>, which assumes the attacker controls the network. Thus, this fact makes <code>$A</code>’s public key available to the attacker.</p></li></ul></li></ul><p>We can only apply a rule if the preconditions are met: the facts we need appear in the bag. By having rules for each step of the protocol, we can apply the rules in order and simulate a run of the protocol. But, as I’m sure you’ve noticed, we skipped the second part of the rule. The second part of the rule is where we list what we call <i>actions</i>.</p><p>We use actions to record what happened in a protocol run. In our example, we have the action <code>GenLtk($A, ~ltkA)</code>. <code>GenLtk</code> means that a new Long-Term Key (LTK) has been <code>Gen</code>erated. Whenever we trigger the <code>Register_pk</code> rule, we note this with the two parameters:, <code>$A</code>, the party to whom the new key pair belongs; and <code>~ltkA</code>, the private part of the generated key<sup>2</sup>.</p><p>If we simulate a single run of the protocol, we can record a list of all the actions executed and put them in a list. However, at any point in the protocol, there may be multiple rules that can be triggered. A list only captures a single run of a protocol, but we want to reason about all possible runs of the protocol. We can arrange our rules into a tree: every time we have multiple rules that could be executed, we give each one of them its own branch.</p><p>If we could write this entire tree, it would represent every possible run of the protocol. Because every possible run appears in this tree, if we can show that there are no “bad” runs on this tree, we can be sure that the protocol is “secure”. We put “bad” and “secure” in quotation marks here because we <i>still</i> haven’t actually defined what those terms actually mean.</p><p>But before we get to that, let’s quickly recap what we have so far. We have:</p><ul><li><p>A protocol we want to prove.</p></li><li><p>A definition of <i>protocol,</i> as a number of computers running a set of computer programs that interact with each other.</p></li><li><p>A technique, <i>process algebras</i>, to describe the interacting processes of the protocol: this technique provides us with symbols and rules for manipulating them.</p></li><li><p>A tree that represents every possible run of the protocol.</p></li></ul><p>We can reason about a protocol by looking at properties that our tree gives. As we are interested in cryptographic protocols, we would like to reason about its security. “Security” is a pretty abstract concept and its meaning changes in different contexts. In our case, to prove something is secure, we first have to say <i>what our security goals</i> are. One thing we might want to prove is, for example, that an attacker can never learn the encryption key of a session. We capture this idea with a <i>reachability</i> lemma.</p><p>A reachability lemma asks whether there is a path in the tree that leads to a specific state: can we “reach” this state? In this case, we ask: “can we reach a state where the attacker knows the session key?” If the answer is “no”, we are sure that our protocol has that property (an attacker never learns the session key), or at least that that property is true in our protocol model.</p><p>So, if we want to prove the security of a cryptographic protocol, we need to:</p><ol><li><p>Define the goals of the security that is being proven.</p></li><li><p>Describe the protocol as an interacting process of symbols, rules, and expressions.</p></li><li><p>Build a tree of all the steps the protocol can take.</p></li><li><p>Check that the trees of protocol runs attain the goals of security we specified.</p></li></ol><p>This process of creating a model of a program and writing rigorous proofs about that model is called “formal analysis”.</p><p>Writing formal proofs of protocol correctness has been very effective at finding and fixing all kinds of issues. During the design of TLS 1.3, for example, it uncovered a number of serious security flaws that were eventually fixed prior to standardization. However, something we need to be wary of with formal analysis is being over-reliant on its results. It’s very possible to be so taken with the rigour of the process and of its mathematical proofs, that the result gets overinterpreted. Not only can a mistake exist in a proof, even in a machine-checked one, the proof may not actually prove what you think it does. There are many examples of this: <a href="https://en.wikipedia.org/wiki/Needham%E2%80%93Schroeder_protocol">Needham-Schroeder</a> had a <a href="https://www.cs.cmu.edu/afs/cs/academic/class/17654-f01/www/refs/BAN.pdf">proof of security written in the BAN logic</a>, before Lowe found <a href="https://www.sciencedirect.com/science/article/abs/pii/0020019095001442">an attack on a case that the BAN logic did not cover</a>.</p><p>In fact, the initial specification of the TLS 1.3 proof made the assumption that nobody uses the same certificate for both a client and a server, even though this is not explicitly disallowed in the specification. This gap led to the <a href="https://eprint.iacr.org/2019/347">“Selfie” vulnerability</a> where a client could be tricked into connecting to itself, potentially leading to resource exhaustion attacks.</p><p>Formal analysis of protocol designs also tells you nothing about whether a particular implementation correctly implements a protocol. In other <a href="/post-quantum-easycrypt-jasmin">blog posts</a>, we will talk about this. Let’s now return to our core topic: the formal analysis of KEMTLS.</p>
    <div>
      <h3>Proving KEMTLS’s security</h3>
      <a href="#proving-kemtlss-security">
        
      </a>
    </div>
    <p>Now that we have the needed notions, let’s get down to the nitty-gritty: we show you how we proved KEMTLS is secure. KEMTLS is a proposal to do authentication in TLS handshakes using key exchange (via key encapsulation mechanisms or KEMs). <a href="/making-protocols-post-quantum">KEMTLS examines</a> the trade-offs between post-quantum signature schemes and post-quantum key exchange, as we discussed in <a href="/making-protocols-post-quantum">other blog posts</a>.</p><p>The main idea of KEMTLS is the following: instead of using a signature to prove that you have access to the private key that corresponds to the (signing) public key in the certificate presented, we derive a shared secret <i>encapsulated to</i> a (KEM) public key. The party that presented the certificate can only derive (<i>decapsulate</i>) it from the resulting <i>encapsulation</i> (often also called the ciphertext) if they have access to the correct private key; and only then can they read encrypted traffic. A brief overview of how this looks in the “traditional arrows on paper” form is given below.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4mgeVds1Jxd59Qoy4QT187/0c5b8f84c1e4195904982efe5149400f/image3-24.png" />
            
            </figure><p>Brief overview of the core idea of KEMTLS.</p><p>We want to show that the KEMTLS handshake is secure, no matter how an adversary might mess with, reorder, or even create new protocol messages. Symbolic analysis tools such as Tamarin or <a href="https://bblanche.gitlabpages.inria.fr/proverif/">ProVerif</a> are well suited to this task: as said, they allow us to consider every possible combination or manipulation of protocol messages, participants, and key information. We can then write lemmas about the behavior of the protocol.</p>
    <div>
      <h3>Why prove it in Tamarin?</h3>
      <a href="#why-prove-it-in-tamarin">
        
      </a>
    </div>
    <p>There exists a pen-and-paper proof of the KEMTLS handshake. You might ask: why should we still invest the effort of modeling it in a tool like Tamarin?</p><p>Pen-and-paper proofs are in theory fairly straightforward. However, they are <i>very hard</i> to get right. We need to carefully express the security properties of the protocol, and it is very easy to let assumptions lead you to write something that your model does not correctly cover. Verifying that a proof has been done correctly is also very difficult and requires almost as much careful attention as writing the proof itself. In fact, several mistakes in definitions of the properties of the model of the original KEMTLS proof were found, after the paper had been accepted and published at a top-tier security conference.</p><blockquote><p><i>? For those familiar with these kinds of game-based proofs, another “war story”: while modeling the ephemeral key exchange, the authors of KEMTLS initially assumed all we needed was an </i><a href="https://en.wikipedia.org/wiki/Ciphertext_indistinguishability#Indistinguishability_under_chosen-plaintext_attack_(IND-CPA)"><i>IND-CPA</i></a><i> secure KEM. After writing out all the simulations in pseudo code (which is not part of the proof or the paper otherwise!), it turned out that we needed an additional oracle to answer a single decapsulation query, resulting in requiring a weaker variant of IND-CCA security of our KEM (namely, IND-1CCA security). Using an “only” IND-CPA-secure KEM turned out to not be secure!</i></p></blockquote><p>Part of the problem with pen-and-paper proofs is perhaps the human nature to read between the lines: we quickly figure out what is intended by a certain sentence, even if the intent is not strictly clarified. Computers do not allow that: to everyone’s familiar frustration whenever a computer has not done what you wanted, but just what you told it to do.</p><p>A benefit of computer code, though, is that all the effort is in writing the instructions. A carefully constructed model and proof result in an executable program: verifying should be as simple as being able to run it to the end. However, as always we need to:</p><ol><li><p>Be very careful that we have modeled the right thing and,</p></li><li><p>Note that even the machine prover might have bugs: this second computer-assisted proof is a complement to, and not a replacement of, the pen-and-paper proof.</p></li></ol><p>Another reason why computer proofs are interesting is because they give the ability to construct extensions. The <a href="https://eprint.iacr.org/2021/779">“pre-distributed keys” extension of KEMTLS</a>, for example, has been only proven on paper in isolation. Tamarin allows us to construct that extension in the same space as the main proof, which will help rule out any cross-functional attacks. With this, the complexity of the proof is increased exponentially, but Tamarin allows us to handle that just by using more computer power. Doing the same on paper requires very, very careful consideration.</p><p>One final reason we wanted to perform this computer analysis is because whilst the pen-and-paper proof was in the computational model, our computer analysis is in the symbolic model. Computational proofs attain “high resolution” proofs, giving very tight bounds on exactly how secure a protocol is. Symbolic models are “low resolution”: giving a binary yes/no answer on whether a protocol meets the security goals (with the assumption that the underlying cryptographic primitives are secure). This might sound like computational proofs are the best: their downside is that one has to simplify the model in other areas. The computational proof of KEMTLS, for example, does not model TLS message formats, which a symbolic model can.</p>
    <div>
      <h3>Modeling KEMTLS in Tamarin</h3>
      <a href="#modeling-kemtls-in-tamarin">
        
      </a>
    </div>
    <p>Before we can start making security claims and asking Tamarin to prove them, we first need to explain to Tamarin what KEMTLS is. As we mentioned earlier, Tamarin treats the world as a “bag of facts”. Keys, certificates, identities, and protocol messages are all facts. Tamarin can take those facts and apply rules to them to construct (or deconstruct) new facts. Executing steps in the KEMTLS protocol is, in a very literal sense, just another way to perform such transformations — and if everything is well-designed, the only “honest” way to reach the end state of the protocol.</p><p>We need to start by modeling the protocol. We were fortunate to be able to reuse the work of <a href="https://tls13tamarin.github.io/TLS13Tamarin/">Cremers et al.</a>, who contributed their significant modeling talent to the TLS 1.3 standardization effort. They created a very complete model of the TLS 1.3 protocol, which showed that the protocol is generally secure. For more details, see <a href="https://tls13tamarin.github.io/TLS13Tamarin/">their paper</a>.</p><p>We modified the ephemeral key exchange by substituting the Diffie-Hellman operations in TLS 1.3 with the appropriate KEM operations. Similarly, we modified the messages that perform the certificate handling: instead of verifying a signature, we send back a KemEncapsulation message with the ciphertext. Let’s have a look at one of the changed rules. Don’t worry, it looks a bit scary, but we’re going to break it down for you. And also, don’t worry if you do not grasp all the details: we will cover the most necessary bits when they come up again, so you can also just skip to the next section “Modeling the adversary” instead.</p>
            <pre><code>rule client_recv_server_cert_emit_kex:
let
  // … snip
  ss = kemss($k, ~saseed)
  ciphertext = kemencaps($k, ss, certpk)
  // NOTE: the TLS model uses M4 preprocessor macros for notation
  // We also made some edits for clarity
in
  [
    State(C2d, tid, $C, $S, PrevClientState),
    In(senc{&lt;'certificate', certpk&gt;}hs_keys),
    !Pk($S, certpk),
    Fr(~saseed)
  ]
  --[
    C2d(tid),
    KemEncap($k, certpk, ss)
  ]-&gt;
  [
    State(C3, tid, $C, $S, ClientState),
    Out(senc{&lt;'encaps', ciphertext&gt;}hs_keyc)
  ]</code></pre>
            <p>This rule represents the client getting the server’s certificate and encapsulating a fresh key to it. It then sends the encapsulated key back to the server.</p><p>Note that the <code>let … in</code> part of the rule is used to assign expressions to variables. The real meat of the rule starts with the preconditions. As we can see, in this rule there are four preconditions that Tamarin needs to already have in its bag for this rule to be triggered:</p><ul><li><p>The first precondition is <code>State(C2d, …)</code>. This condition tells us that we have some client that has reached the stage <code>C2d</code>, which is what we call this stage in our representation. The remaining variables define the state of that client.</p></li><li><p>The second precondition is an <code>In</code> one. This is how Tamarin denotes messages received from the network. As we mentioned before, we assume that the network is controlled by the attacker. Until we can prove otherwise, we don’t know whether this message was created by the honest server, if it has been manipulated by the attacker, or even forged. The message contents, <code>senc{&lt;'certificate', certpk&gt;}hs_keys</code>, is symmetrically encrypted ( <code>senc{}</code>) under the server’s handshake key (we’ve slightly edited this message for clarity, and removed various other bits to keep this at least somewhat readable, but you can see the whole definition in <a href="https://github.com/thomwiggers/TLS13Tamarin">our model</a>).</p></li><li><p>The third precondition states the public key of the server, <code>!Pk(S, certpk)</code>. This condition is preceded by a <code>!</code> symbol, which means that it’s a permanent fact to be consumed many times. Usually, once a fact is removed from the bag, it is gone; but permanent facts remain. <code>S</code> is the name of the server, and <code>certpk</code> is the KEM public key.</p></li><li><p>The fourth precondition states the fresh random value, <code>~saseed</code>.</p></li></ul><p>The postconditions of this rule are a little simpler. We have:</p><ul><li><p><code>State(C3, …)</code>, which represents that the client (which was at the start of the rule in state <code>C2d</code>) is now in state <code>C3</code>.</p></li><li><p><code>Out(senc{&lt;'encaps', ciphertext&gt;}hs_keyc)</code>, which represents the action of the client sending the encapsulated key to the network, encrypted under the client’s handshake key.</p></li></ul><p>The four actions recorded in this rule are:</p><ul><li><p>First, we record that the client with thread id <code>tid</code> reached the state <code>C2d</code>.</p></li><li><p>Second and third, we record that the client was running the protocol with various intermediate values. We use the phrase “running with” to indicate that although the client believes these values to be the correct, it can’t yet be certain that they haven’t been tampered with, so the client hasn’t committed yet to them.</p></li><li><p>Finally, we record the parameters we put into the KEM with the <code>KemEncap</code> action.</p></li></ul><p>We modify and add such rules to the TLS 1.3 model, so we can run KEMTLS instead of TLS 1.3. For a sanity check, we need to make sure that the protocol can actually be executed: a protocol that can not run, can not leak your secrets. We use a <i>reachability lemma</i> to do that:</p>
            <pre><code>lemma exists_C2d:
    exists-trace
    "Ex tid #j. C2d(tid)@#j"</code></pre>
            <p>This was the first lemma that we asked Tamarin to prove. Because we’ve marked this lemma <code>exists-trace</code>, it does not need to hold in all traces, all runs of the protocol. It just needs one. This lemma asks if there exists a trace ( <code>exists-trace</code>), where there exists ( <code>Ex</code> ) a variable <code>tid</code> and a time <code>#j</code> (times are marked with <code>#</code>) at which action <code>C2d(tid)</code> is recorded. What this captures is that Tamarin could find a branch of the tree where the rule described above was triggered. Thus, we know that our model can be executed, at least as far as <code>C2d</code>.</p>
    <div>
      <h3>Modeling the adversary</h3>
      <a href="#modeling-the-adversary">
        
      </a>
    </div>
    <p>In the symbolic model, all cryptography is perfect: if the adversary does not have a particular key, they can not perform any deconstructions to, for example, decrypt a message or decapsulate a ciphertext. Although a proof with this default adversary would show the protocol to be secure against, for example, reordering or replaying messages, we want it to be secure against a slightly stronger adversary. Fortunately, we can model this adversary. Let’s see how.</p><p>Let’s take an example. We have a rule that honestly generates long-term keys (certificates) for participants:</p>
            <pre><code>rule Register_pk:
  [ Fr(~ltkA) ] 
  --[  GenLtk($A, ~ltkA)  ]-&gt;
  [ !Ltk($A, ~ltkA), 
    !Pk($A, kempk($k, ~ltkA)), 
    Out(kempk($k, ~ltkA))
  ]</code></pre>
            <p>This rule is very similar to the one we saw at the beginning of this blog post, but we’ve tweaked it to generate KEM public keys. It goes as follows: it generates a fresh value, and registers it as the actor <code>$A</code>’s long-term private key symbol <code>!Ltk</code> and <code>$A</code>’s public key symbol <code>!Pk</code> that we use to model our certificate infrastructure. It also sends ( <code>Out</code> ) the public key to the network such that the adversary has access to it.</p><p>The adversary can not deconstruct symbols like <code>Ltk</code> without rules to do so. Thus, we provide the adversary with a special <code>Reveal</code> query, that takes the <code>!Ltk</code> fact and reveals the private key:</p>
            <pre><code>rule Reveal_Ltk:
   [ !Ltk($A, ~ltkA) ] --[ RevLtk($A) ]-&gt; [ Out(~ltkA) ]</code></pre>
            <p>Executing this rule registers the <code>RevLtk($A)</code> action, so that we know that <code>$A</code>’s certificate can no longer be trusted after <code>RevLtk</code> occurred.</p>
    <div>
      <h3>Writing security lemmas</h3>
      <a href="#writing-security-lemmas">
        
      </a>
    </div>
    <p>KEMTLS, like TLS, is a cryptographic handshake protocol. These protocols have the general goal to generate session keys that we can use to encrypt user’s traffic, preferably as quickly as possible. One thing we might want to prove is that these session keys are secret:</p>
            <pre><code>lemma secret_session_keys [/*snip*/]:
  "All tid actor peer kw kr aas #i.
      SessionKey(tid, actor, peer, &lt;aas, 'auth'&gt;, &lt;kw, kr&gt;)@#i &amp;
      not (Ex #r. RevLtk(peer)@#r &amp; #r &lt; #i) &amp;
      not (Ex tid3 esk #r. RevEKemSk(tid3, peer, esk)@#r &amp; #r &lt; #i) &amp;
      not (Ex tid4 esk #r. RevEKemSk(tid4, actor, esk)@#r &amp; #r &lt; #i)
    ==&gt; not Ex #j. K(kr)@#j"</code></pre>
            <p>This lemma states that if the actor has completed the protocol and the attacker hasn’t used one of their special actions, then the attacker doesn’t know the actor’s read key, <code>kr</code>. We’ll go through the details of the lemma in a moment, but first let’s address some questions you might have about this proof statement.</p><p>The first question that might arise is: “If we are only secure in the case the attacker doesn’t use their special abilities then why bother modeling those abilities?” The answer has two parts:</p><ol><li><p>We do not restrict the attacker from using their abilities: they can compromise every key except the ones used by the participants in this session. If they managed to somehow make a different participant use the same ephemeral key, then this lemma wouldn’t hold, and we would not be able to prove it.</p></li><li><p>We allow the attacker to compromise keys used in this session <i>after</i> the session has completed. This means that what we are proving is: an attacker who recorded this session in the past and now has access to the long-term keys (by using their shiny new quantum computer, for example) can’t decrypt what happened in the session. This property is also known as <a href="https://en.wikipedia.org/wiki/Forward_secrecy">forward secrecy</a>.</p></li></ol><p>The second question you might ask is: “Why do we only care about the read key?”. We only care about the read key because this lemma is symmetric, it holds for all actors. When a client and server have established a TLS session, the client’s read key is the server’s write key and vice versa. Because this lemma applies symmetrically to the client and the server, we prove that the attacker doesn’t know either of those keys.</p><p>Let’s return now to the syntax of this lemma.</p><p>This first line of this lemma is a “For all” statement over seven variables, which means that we are trying to prove that no matter what values these seven variables hold, the rest of the statement is true. These variables are:</p><ul><li><p>the thread id <code>tid</code>,</p></li><li><p>a protocol participant, <code>actor</code>,</p></li><li><p>the person they think they’re talking to, <code>peer</code>,</p></li><li><p>the final read and write keys, <code>kr</code> and <code>kw</code> respectively,</p></li><li><p>the actor’s authentication status, <code>aas</code>,</p></li><li><p>and a time <code>#i</code>.</p></li></ul><p>The next line of the lemma is about the <code>SessionKey</code> action. We record the <code>SessionKey</code> action when the client or the server thinks they have completed the protocol.</p><p>The next lines are about two attacker abilities: <code>RevLtk</code>, as discussed earlier; and <code>RevEKemSk</code>, which the attacker can use to reveal ephemeral secrets. The <code>K(x)</code> action means that the attacker learns (or rather, <code>K</code>nows) <code>x</code>. We, then, assert that if there does not <code>Ex</code>ist a <code>RevEKemSk</code> or <code>RevLtk</code> action on one of the keys used in the session, then there also does not exist a time when <code>K(kr)</code> (when the attacker learns the read key). <a href="https://en.wikipedia.org/wiki/Q.E.D."><i>Quod erat demonstrandum</i></a>. Let’s run the proofs now.</p>
    <div>
      <h3>Proving lemmas in Tamarin</h3>
      <a href="#proving-lemmas-in-tamarin">
        
      </a>
    </div>
    <p>Tamarin offers two methods to prove security lemmas: it has an autoprover that can try to find the solution for you, or you can do it manually. Tamarin sometimes has a hard time figuring out what is important for proving a particular security property, and so manual effort is sometimes unavoidable.</p><p>The manual prover interface allows you to select what goal Tamarin should pursue step by step. A proof quickly splits into separate branches: in the picture, you see that Tamarin has already been able to prove the branches that are green, leaving us to make a choice for case 1.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/39wLyAIAVaVCmfgpQRrq7o/798666afd187a98809b4706bb8e62faa/pasted-image-0.png" />
            
            </figure><p>Screenshot from the Tamarin user interface, showing a prompt for the next step in a proof. The branches of the proof that are marked green have already been proven.</p><p>Sometimes whilst working in the manual interface, you realize that there are certain subgoals that Tamarin is trying to prove while working on a bigger lemma. By writing what we call a helper lemma we can give Tamarin a shortcut of sorts. Rather than trying to solve all the subgoals of one big lemma, we can split the proof into more digestible chunks. Tamarin can then later reuse these helper lemmas when trying to prove bigger lemmas; much like factoring out functions while programming. Sometimes this even allows us to make lemmas auto-provable. Other times we can extract the kinds of decisions we’re making and heuristics we’re manually applying into a separate “oracle” script: a script that interacts with Tamarin’s prover heuristics on our behalf. This can also automate proving tricky lemmas.</p><p>Once you realize how much easier certain things are to prove with helper lemmas, you can get a bit carried away. However, you quickly find that Tamarin is being “distracted” by one of the helper lemmas and starts going down long chains of irrelevant reasoning. When this happens, you can hide the helper lemma from the main lemma you’re trying to prove, and sometimes that allows the autoprover to figure out the rest.</p><p>Unfortunately, all these strategies require a lot of intuition that is very hard to obtain without spending a lot of time hands-on with Tamarin. Tamarin can sometimes be a bit unclear about what lemmas it’s trying to apply. We had to resort to tricks, like using unique, highly recognizable variable names in lemmas, such that we can reconstruct where a certain goal in the Tamarin interface is coming from.</p><p>While doing this work, auto-proving lemmas has been incredibly helpful. Each time you make a tiny change in either a lemma (or any of the lemmas that are reused by it) or in the whole model, you have to re-prove everything. If we needed to put in lots of manual effort each time, this project would be nowhere near done.</p><p>This was demonstrated by two bugs we found in one of the core lemmas of the TLS 1.3 model. It turned out that after completing the proof, some <a href="https://www.cloudflare.com/learning/cloud/how-to-refactor-applications/">refactoring</a> changes were made to the <code>session_key_agreement</code> lemma. These changes seemed innocent, but actually changed the meaning of the lemma, so that it didn’t make sense anymore (the original definition did cover the right security properties, so luckily this doesn’t cause a security problem). Unfortunately, this took a lot of our time to figure out. However, after a huge effort, we’ve done it. We have a proof that <a href="https://github.com/thomwiggers/TLS13Tamarin">KEMTLS achieves its security goals</a>.</p>
    <div>
      <h3>Conclusions</h3>
      <a href="#conclusions">
        
      </a>
    </div>
    <p>Formal methods definitely have a place in the development of security protocols; the development process of TLS 1.3 has really demonstrated this. We think that any proposal for new security protocols should be accompanied by a machine-verified proof of its security properties. Furthermore, because many protocols are currently specified in natural language, formal specification languages should definitely be under consideration. Natural language is inherently ambiguous, and the inevitable differences in interpretation that come from that lead to all kinds of problems.</p><p>However, this work cannot be done by academics alone. Many protocols come out of industry who will need to do this for themselves. We would be the first to admit that the usability of these tools for non-experts is not all the way there yet — and industry and academia should collaborate on making these tools more accessible for everyone. We welcome and look forward to these collaborations in the future!</p>
    <div>
      <h4>References</h4>
      <a href="#references">
        
      </a>
    </div>
    <ul><li><p><a href="https://dl.acm.org/doi/10.1145/2637166.2637237">“Why does cryptographic software fail?: a case study and open problems”</a> by David Lazar, Haogang Chen, Xi Wang and Nickolai Zeldovich</p></li><li><p><a href="https://eprint.iacr.org/2019/1393.pdf">“SoK: Computer-Aided Cryptography”</a> by Manuel Barbosa, Gilles Barthe, Karthik Bhargavan, Bruno Blanchet, Cas Cremers, Kevin Liao and Bryan Parno</p></li><li><p><a href="https://eprint.iacr.org/2020/534/">“Post-quantum TLS without handshake signatures”</a> by Peter Schwabe and Douglas Stebila and Thom Wiggers(*)</p></li><li><p><a href="https://eprint.iacr.org/2021/779/">“More efficient post-quantum KEMTLS with pre-distributed public keys”</a> by Peter Schwabe and Douglas Stebila and Thom Wiggers (*)</p></li><li><p><a href="https://londmathsoc.onlinelibrary.wiley.com/doi/10.1112/plms/s2-42.1.230">"On computable numbers, with an application to the Entscheidungsproblem."</a> by Alan Turing</p></li><li><p><a href="https://dl.acm.org/doi/pdf/10.1145/3133956.3134063">"A comprehensive symbolic analysis of TLS 1.3."</a> by Cas Cremers, Marko Horvat, Jonathan Hoyland, Sam Scott, and Thyla van der Merwe (*)</p></li><li><p><a href="https://www.cs.cmu.edu/afs/cs/academic/class/17654-f01/www/refs/BAN.pdf">"A Logic of Authentication"</a> by Michael Burrows, Martin Abadi, and Roger Michael Needham</p></li></ul><p>* The authors of this blog post were authors on these papers</p><p>.....</p><p><sup>1</sup>Of course, trying every value isn’t technically impossible, it’s just infeasible, so we make the simplifying assumption that it’s impossible, and just say our proof only applies if the attacker can’t just try every value. Other styles of proof that don’t make that assumption are possible, but we’re not going to go into them.</p><p><sup>2</sup>For simplicity, this representation assumes that the public portion of a key pair can be derived from the private part, which may not be true in practice. Usually this simplification won’t affect the analysis.</p> ]]></content:encoded>
            <category><![CDATA[Research]]></category>
            <category><![CDATA[Cryptography]]></category>
            <category><![CDATA[Post-Quantum]]></category>
            <guid isPermaLink="false">7erNSwLGj4BHA9bhRf2HOq</guid>
            <dc:creator>Thom Wiggers</dc:creator>
            <dc:creator>Jonathan Hoyland</dc:creator>
        </item>
        <item>
            <title><![CDATA[Making protocols post-quantum]]></title>
            <link>https://blog.cloudflare.com/making-protocols-post-quantum/</link>
            <pubDate>Wed, 23 Feb 2022 13:59:42 GMT</pubDate>
            <description><![CDATA[ Post-quantum key exchange and signature algorithms come with different trade-offs that we’re familiar. How do we handle that when updating protocols, is this an opportunity to revisit the status quo? ]]></description>
            <content:encoded><![CDATA[ <p></p><p>Ever since the (public) invention of cryptography based on mathematical trap-doors by <a href="https://ieeexplore.ieee.org/document/1055638">Whitfield Diffie, Martin Hellman</a>, and Ralph Merkle, the world has had key agreement and signature schemes based on discrete logarithms. <a href="https://patents.google.com/patent/US4405829">Rivest, Shamir, and Adleman</a> invented integer factorization-based signature and encryption schemes a few years later. The core idea, that has perhaps changed the world in ways that are hard to comprehend, is that of public key cryptography. We can give you a piece of information that is completely public (the <i>public key</i>), known to all our adversaries, and yet we can still securely communicate as long as we do not reveal our piece of extra information (the <i>private key</i>). With the private key, we can then efficiently solve mathematical problems that, without the secret information, would be practically unsolvable.</p><p>In later decades, there were advancements in our understanding of integer factorization that required us to bump up the key sizes for finite-field based schemes. The cryptographic community largely solved that problem by figuring out how to base the same schemes on elliptic curves. The world has since then grown accustomed to having algorithms where public keys, secret keys, and signatures are just a handful of bytes and the speed is measured in the tens of microseconds. This allowed cryptography to be bolted onto previously insecure protocols such as HTTP or <a href="https://www.cloudflare.com/learning/dns/what-is-dns/">DNS</a> without much overhead in either time or the data transmitted. We previously wrote about <a href="/sizing-up-post-quantum-signatures/">how TLS loves small signatures</a>; similar things can probably be said for a lot of present-day protocols.</p><p>But this blog has “post-quantum” in the title; quantum computers are likely to make our cryptographic lives significantly harder by undermining many of the assurances we previously took for granted. The old schemes are no longer secure because new algorithms can efficiently solve their particular mathematical trapdoors. We, together with everyone on the Internet, will need to swap them out. There are whole suites of <a href="https://www.cloudflare.com/learning/ssl/quantum/what-is-post-quantum-cryptography/">quantum-resistant replacement algorithms</a>; however, right now it seems that we need to choose between “fast” and “small”. The new alternatives also do not always have the same properties that we have based some protocols on.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3DEjVrUy9g5YErrYBWnxwh/398bd862409ed0d2c8f880c0d2e1e4e6/image4-13.png" />
            
            </figure><p>Fast or small: Cloudflare <a href="/the-tls-post-quantum-experiment/">previously experimented</a> with NTRU-HRSS (a fast key exchange scheme with large public keys and ciphertexts) and SIKE (a scheme with very small public keys and ciphertexts, but much slower algorithm operations).</p><p>In this blog post, we will discuss how one might upgrade cryptographic protocols to make them secure against quantum computers. We will focus on the cryptography that they use and see what the challenges are in making them secure against quantum computers. We will show how trade-offs might motivate completely new protocols for some applications. We will use TLS here as a stand-in for other protocols, as it is one of the most deployed protocols.</p>
    <div>
      <h3>Making TLS post-quantum</h3>
      <a href="#making-tls-post-quantum">
        
      </a>
    </div>
    <p>TLS, from SSL and HTTPS fame, gets discussed a lot. We keep it brief here. TLS 1.3 consists of an Ephemeral Elliptic curve Diffie-Hellman (ECDH) key exchange which is authenticated by a digital signature that’s verified by using a public key that’s provided by the server in a certificate. We know that this public key is the right one because the certificate contains another signature by the issuer of the certificate and our client has a repository of valid issuer (“certificate authority”) public keys that it can use to verify the authenticity of the server’s certificate.</p><p>In principle, TLS can become post-quantum straightforwardly: we just write “PQ” in front of the algorithms. We replace ECDH key exchange by post-quantum (PQ) key exchange provided by a post-quantum Key Encapsulation Mechanism (KEM). For the signatures on the handshake, we just use a post-quantum signature scheme instead of an elliptic curve or RSA signature scheme. No big changes to the actual “arrows” of the protocol necessary, which is super convenient because we don’t need to revisit our security proofs. Mission accomplished, cake for everyone, right?</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/7CWLpWVAzCcJ5cmwcFneEt/118fb95c11ef060e250545f9fd2962e1/image3-22.png" />
            
            </figure><p>Upgrading the cryptography in TLS seems as easy as scribbling in “PQ-”.</p>
    <div>
      <h3>Key exchange</h3>
      <a href="#key-exchange">
        
      </a>
    </div>
    <p>Of course, it’s not so simple. There are nine different suites of post-quantum key exchange algorithms still in the running in round three of the NIST Post-Quantum standardization project: Kyber, SABER, NTRU, and Classic McEliece (the “finalists”); and SIKE, BIKE, FrodoKEM, HQC, and NTRU Prime (“alternates”). These schemes have wildly different characteristics. This means that for step one, replacing the key exchange by post-quantum key exchange, we need to understand the differences between these schemes and decide which one fits best in TLS. Because we’re doing ephemeral key exchange, we consider the size of the public key and the ciphertext since they need to be transmitted for every handshake. We also consider the “speed” of the key generation, encapsulation, and decapsulation operations, because these will affect how many servers we will need to handle these connections.</p><p><i><b>Table 1: Post-Quantum KEMs at security level comparable with AES128. Sizes in bytes.</b></i></p><table><tr><td><p><b>Scheme</b></p></td><td><p><b>Transmission size (pk+ct)</b></p></td><td><p><b>Speed of operations</b></p></td></tr><tr><td><p><i>Finalists</i></p></td><td><p></p></td><td><p></p></td></tr><tr><td><p>Kyber512</p></td><td><p>1,632</p></td><td><p>Very fast</p></td></tr><tr><td><p>NTRU-HPS-2048-509</p></td><td><p>1,398</p></td><td><p>Very fast</p></td></tr><tr><td><p>SABER (LightSABER)</p></td><td><p>1,408</p></td><td><p>Very fast</p></td></tr><tr><td><p>Classic McEliece</p></td><td><p>261,248</p></td><td><p>Very slow</p></td></tr><tr><td><p><i>Alternate candidates</i></p></td><td><p></p></td><td><p></p></td></tr><tr><td><p>SIKEp434</p></td><td><p>676</p></td><td><p>Slow</p></td></tr><tr><td><p>NTRU Prime (ntrulpr)</p></td><td><p>1,922</p></td><td><p>Very fast</p></td></tr><tr><td><p>NTRU Prime (sntru)</p></td><td><p>1,891</p></td><td><p>Fast</p></td></tr><tr><td><p>BIKE</p></td><td><p>5,892</p></td><td><p>Slow</p></td></tr><tr><td><p>HQC</p></td><td><p>6,730</p></td><td><p>Reasonable</p></td></tr><tr><td><p>FrodoKEM</p></td><td><p>19,336</p></td><td><p>Reasonable</p></td></tr></table><p>Fortunately, once we make this table the landscape for KEMs that are suitable for use in TLS quickly becomes clear. We will have to sacrifice an additional 1,400 - 2,000 bytes, assuming SIKE’s slow runtime is a bigger penalty to the connection establishment (<a href="/the-tls-post-quantum-experiment/">see our previous work here</a>). So we can choose one of the lattice-based finalists (Kyber, SABER or NTRU) and call it a day.<sup>1</sup></p>
    <div>
      <h3>Signature schemes</h3>
      <a href="#signature-schemes">
        
      </a>
    </div>
    <p>For our post-quantum signature scheme, we can draw a similar table. In TLS, we generally care about the sizes of public keys and signatures. In terms of runtime, we care about signing and verification times, as key generation is only done once for each certificate, offline. The round three candidates for signature schemes are: Dilithium, Falcon, Rainbow (the three finalists), and SPHINCS+, Picnic, and GeMSS.</p><p><i><b>Table 2: Post-Quantum signature schemes at security level comparable with AES128 (or smallest parameter set). Sizes in bytes.</b></i></p><table><tr><td><p><b>Scheme</b></p></td><td><p><b>Public key size</b></p></td><td><p><b>Signature size</b></p></td><td><p><b>Speed of operations</b></p></td></tr><tr><td><p><i>Finalists</i></p></td><td><p></p></td><td><p></p></td><td><p></p></td></tr><tr><td><p>Dilithium2</p></td><td><p>1,312</p></td><td><p>2,420</p></td><td><p>Very fast</p></td></tr><tr><td><p>Falcon-512</p></td><td><p>897</p></td><td><p>690</p></td><td><p>Fast if you have the right hardware</p></td></tr><tr><td><p>Rainbow-I-CZ</p></td><td><p>103,648</p></td><td><p>66</p></td><td><p>Fast</p></td></tr><tr><td><p><i>Alternate Candidates</i></p></td><td><p></p></td><td><p></p></td><td><p></p></td></tr><tr><td><p>SPHINCS+-128f</p></td><td><p>32</p></td><td><p>17,088</p></td><td><p>Slow</p></td></tr><tr><td><p>SPHINCS+-128s</p></td><td><p>32</p></td><td><p>7,856</p></td><td><p>Very slow</p></td></tr><tr><td><p>GeMSS-128</p></td><td><p>352,188</p></td><td><p>33</p></td><td><p>Very slow</p></td></tr><tr><td><p>Picnic3</p></td><td><p>35</p></td><td><p>14,612</p></td><td><p>Very slow</p></td></tr></table><p>There are many signatures in a TLS handshake. Aside from the handshake signature that the server creates to authenticate the handshake (with public key in the server certificate), there are signatures on the certificate chain (with public keys for intermediate certificates), as well as OCSP Stapling (1) and Certificate Transparency (2) signatures (without public keys).</p><p>This means that if we used Dilithium for all of these, we require 17KB of public keys and signatures. Falcon is looking very attractive here, only requiring 6KB, but it might not run fast enough on embedded devices that don’t have special hardware to accelerate 64-bit floating point computations in constant time. SPHINCS+, GeMSS, or Rainbow each have significant deployment challenges, so it seems that there is no one-scheme-fits-all solution.</p><p>Picking and choosing specific algorithms for particular use cases, such as using a scheme with short signatures for root certificates, OCSP Stapling, and CT might help to alleviate the problems a bit. We might use Rainbow for the CA root, OCSP staples, and CT logs, which would mean we only need 66 bytes for each signature. It is very nice that Rainbow signatures are only very slightly larger than 64-byte ed25519 elliptic curve signatures, and they are significantly smaller than 256-byte RSA-2048 signatures. This gives us a lot of space to absorb the impact of the larger handshake signatures required. For intermediate certificates, where both the public key and the signature are transmitted, we might use Falcon because it’s nice and small, and the client only needs to do signature verification.</p>
    <div>
      <h3>Using KEMs for authentication</h3>
      <a href="#using-kems-for-authentication">
        
      </a>
    </div>
    <p>In the pre-quantum world, key exchange and signature schemes used to be roughly equivalent in terms of work required or bytes transmitted. As we saw in the previous section, this doesn’t hold up in the post-quantum world. This means that this might be a good opportunity to also investigate alternatives to the classic “signed key exchange” model. Deploying significant changes to an existing protocol might be harder than just swapping out primitives, but we might gain better characteristics. We will look at such a proposed redesign for TLS here.</p><p>The idea is to use key exchange not just for confidentiality, but also for authentication. This uses the following idea: what a signature in a protocol like TLS is actually proving is that the person signing has possession of the secret key that corresponds to the public key that’s in the certificate. But we can also do this with a key exchange key by showing you can derive the same shared secret (if you want to prove this explicitly, you might do so by computing a <a href="https://en.wikipedia.org/wiki/Message_authentication_code">Message Authentication Code</a> using the established shared secret).</p><p>This isn’t new; many modern cryptographic protocols, such as the Signal messaging protocol, have used such mechanisms. They offer privacy benefits like (offline) <a href="https://en.wikipedia.org/wiki/Deniable_authentication">deniability</a>. But now we might also use this to obtain a faster or “smaller” protocol.</p><p>However, this does not come for free. Because authentication via key exchange (via KEM at least) inherently requires two participants to exchange keys, we need to send more messages. In TLS, this means that the server that wants to authenticate first needs to give the client their public key. The client obviously can not encapsulate a shared secret to a key he does not know.</p><p>We also still need to verify signatures on the certificate chain and the signatures for OCSP stapling and Certificate Transparency are still necessary. Because we need to do “offline” verification for those elements of the handshake, it is hard to get rid of those signatures. So we will still need to carefully look at those signatures and pick an algorithm that fits there.</p>
            <pre><code>   Client                                  Server
 ClientHello         --------&gt;
                     &lt;--------         ServerHello
                                             &lt;...&gt;
                     &lt;--------       &lt;Certificate&gt;  ^
 &lt;KEMEncapsulation&gt;                                 | Auth
 {Finished}          --------&gt;                      |
 [Application Data]  --------&gt;                      |
                     &lt;--------          {Finished}  v
 [Application Data]  &lt;-------&gt;  [Application Data]

&lt;msg&gt;: encrypted w/ keys derived from ephemeral KEX (HS)
{msg}: encrypted w/ keys derived from HS+KEM (AHS)
[msg]: encrypted w/ traffic keys derived from AHS (MS)

Authentication via KEM in TLS from the AuthKEM proposal</code></pre>
            <p>Authentication via KEM in TLS from the AuthKEM proposal</p><p></p><p>If we put the necessary arrows to authenticate via KEM into TLS it looks something like Figure 2. This is actually a fully-fledged proposal for an alternative to the usual TLS handshake. The academic proposal KEMTLS was published at the ACM CCS conference in 2020; a proposal to integrate this into TLS 1.3 is described in the <code>draft-celi-wiggers-tls-authkem</code> draft RFC.</p><p>What this proposal illustrates is that the transition to post-quantum cryptography might motivate, or even require, us to have a brand-new look at what the desired characteristics of our protocol are and what properties we need, like what budget we have for round-trips versus the budget for data transmitted. We might even pick up some properties, like deniability, along the way. For some protocols this is somewhat easy, like TLS; in other protocols there isn’t even a clear idea of where to start (<a href="https://www.cloudflare.com/learning/dns/dnssec/ecdsa-and-dnssec/">DNSSEC</a> has very tight limits).</p>
    <div>
      <h3>Conclusions</h3>
      <a href="#conclusions">
        
      </a>
    </div>
    <p>We should not wait until NIST has finished standardizing post-quantum key exchange and signature schemes before thinking about whether our protocols are ready for the post-quantum world. For our current protocols, we should investigate how the proposed post-quantum key exchange and signature schemes can be fitted in. At the same time, we might use this opportunity for careful protocol redesigns, especially if the constraints are so tight that it is not easy to fit in post-quantum cryptography. Cloudflare is participating in the IETF and working with partners in both academia and the industry to investigate the impact of post-quantum cryptography and make the transition as easy as possible.</p><p>If you want to be a part of the future of cryptography on the Internet, either as an academic or an engineer, be sure to check out our <a href="https://research.cloudflare.com/outreach/">academic outreach</a> or <a href="https://www.cloudflare.com/careers/jobs/">jobs</a> pages.</p>
    <div>
      <h3>Reference</h3>
      <a href="#reference">
        
      </a>
    </div>
    <ul><li><p>Post-Quantum TLS without Handshake Signatures by Peter Schwabe, Douglas Stebila and Thom Wiggers: <a href="https://eprint.iacr.org/2020/534/">https://eprint.iacr.org/2020/534/</a></p></li></ul><hr /><p><sup>1</sup>Of course, it’s not so simple. The performance measurements were done on a beefy Macbook, using AVX2 intrinsics. For stuff like IoT (yes, your smart washing machine will also need to go post-quantum) or a smart card you probably want to add another few columns to this table before making a choice, such as code size, side channel considerations, power consumption, and execution time on your platform.</p> ]]></content:encoded>
            <category><![CDATA[Research]]></category>
            <category><![CDATA[Cryptography]]></category>
            <category><![CDATA[Post-Quantum]]></category>
            <guid isPermaLink="false">1GCkhPqo2EcYKHgs43NWvA</guid>
            <dc:creator>Thom Wiggers</dc:creator>
        </item>
        <item>
            <title><![CDATA[KEMTLS: Post-quantum TLS without signatures]]></title>
            <link>https://blog.cloudflare.com/kemtls-post-quantum-tls-without-signatures/</link>
            <pubDate>Fri, 15 Jan 2021 12:00:00 GMT</pubDate>
            <description><![CDATA[ The TLS 1.3 protocol has been around for quite some time, but it will be broken once quantum computers arrive. What can we do? In this blog post, we will examine a technique for achieving full post-quantum security for TLS 1.3 in the face of quantum computers: KEMTLS. ]]></description>
            <content:encoded><![CDATA[ 
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/TYxahpsj66q7L2bERLIZa/537157a1eecaedcbd187f9b1d391523d/KEMTLS--Post-quantum-TLS-without-signatures-blog-home-2.png" />
            
            </figure><p>The Transport Layer Security protocol (TLS), which secures most Internet connections, has mainly been a protocol consisting of a key exchange authenticated by digital signatures used to encrypt data at transport[1]. Even though it has undergone major changes since 1994, when SSL 1.0 was introduced by Netscape, its main mechanism has remained the same. The key exchange was first based on RSA, and later on traditional Diffie-Hellman (DH) and Elliptic-curve Diffie-Hellman (ECDH). The signatures used for authentication have almost always been RSA-based, though in recent years other kinds of signatures have been adopted, mainly <a href="https://www.cloudflare.com/learning/dns/dnssec/ecdsa-and-dnssec/">ECDSA</a> and Ed25519. This recent change to elliptic curve cryptography in both at the key exchange and at the signature level has resulted in considerable speed and bandwidth benefits in comparison to traditional Diffie-Hellman and RSA.</p><p>TLS is the main protocol that protects the connections we use everyday. It’s everywhere: we use it when we buy products online, when we register for a newsletter — when we access any kind of website, IoT device, API for mobile apps and more, really. But with the imminent threat of the arrival of <a href="/securing-the-post-quantum-world/">quantum computers</a> (a threat that seems to be getting closer and closer), we need to reconsider the future of TLS once again. <a href="/the-tls-post-quantum-experiment/">A wide-scale post-quantum experiment</a> was carried out by Cloudflare and Google: two post-quantum key exchanges were integrated into our TLS stack and deployed at our edge servers as well as in Chrome Canary clients. The goal of that experiment was to evaluate the performance and feasibility of deployment of two post-quantum key exchanges in TLS.</p><p>Similar experiments have been proposed for introducing post-quantum algorithms into the TLS handshake itself. Unfortunately, it seems infeasible to replace both the key exchange and signature with post-quantum primitives, because post-quantum cryptographic primitives are bigger, or slower (or both), than their predecessors. The proposed algorithms under consideration in the <a href="https://csrc.nist.gov/Projects/post-quantum-cryptography/round-3-submissions">NIST post-quantum standardization process</a> use mathematical objects that are larger than the ones used for elliptic curves, traditional Diffie-Hellman, or RSA. As a result, the overall size of public keys, signatures and key exchange material is much bigger than those from elliptic curves, Diffie-Hellman, or RSA.</p><p>How can we solve this problem? How can we use post-quantum algorithms as part of the TLS handshake without making the material too big to be transmitted? In this blogpost, we will introduce a new mechanism for making this happen. We’ll explain how it can be integrated into the handshake and we’ll cover implementation details. The key observation in this mechanism is that, while post-quantum algorithms have bigger communication size than their predecessors, post-quantum <i>key exchanges</i> have somewhat smaller sizes than post-quantum <i>signatures</i>, so we can try to replace signatures with key exchanges in some places to save space.  We will only focus on the TLS 1.3 handshake as it is the TLS version that should be currently used.</p>
    <div>
      <h3>Past experiments: making the TLS 1.3 handshake post-quantum</h3>
      <a href="#past-experiments-making-the-tls-1-3-handshake-post-quantum">
        
      </a>
    </div>
    
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/589KMSU0NPVnVGNPCiWIXg/b12d643b105956d0c452dbdcb122ce61/image2-5.png" />
            
            </figure><p><a href="https://tools.ietf.org/html/rfc8446">TLS 1.3</a> was introduced in August 2018, and it brought many security and performance improvements (notably, having only one round-trip to complete the handshake). But TLS 1.3 is designed for a world with classical computers, and some of its functionality will be broken by quantum computers when they do arrive.</p><p>The primary goal of TLS 1.3 is to provide authentication (the server side of the channel is always authenticated, the client side is optionally authenticated), confidentiality, and integrity by using a handshake protocol and a record protocol. The handshake protocol, the one of interest for us today, establishes the cryptographic parameters for securing and authenticating a connection. It can be thought of as having three main phases, as defined in <a href="https://tools.ietf.org/html/rfc8446">RFC8446</a>:</p><p>-  The <b>Parameter Negotiation</b> phase (referred to as ‘Server Parameters’ in RFC8446), which establishes other handshake parameters (whether the client is authenticated, application-layer protocol support, etc).</p><p>-  The <b>Key Exchange</b> phase, which establishes shared keying material and selects the cryptographic parameters to be used. Everything after this phase will be encrypted.</p><p>-  The <b>Authentication</b> phase, which authenticates the server (and, optionally, the client) and provides key confirmation and handshake integrity.</p><p>The main idea of past experiments that introduced post-quantum algorithms into the handshake of TLS 1.3 was to use them in place of classical algorithms by advertising them as part of the <a href="https://tools.ietf.org/html/rfc8446#section-4.2.7">supported groups</a>[2] and <a href="https://tools.ietf.org/html/rfc8446#section-4.2.8">key share</a>[3] extensions, and, therefore, establishing with them the negotiated connection parameters. Key encapsulation mechanisms (KEMs) are an abstraction of the basic key exchange primitive, and were used to generate the shared secrets. When using a <a href="https://tools.ietf.org/html/rfc8446#section-4.2.11">pre-shared key</a>, its symmetric algorithms can be easily replaced by post-quantum KEMs as well; and, in the case of password-authenticated TLS, some <a href="https://eprint.iacr.org/2017/1192.pdf">ideas</a> have been proposed on how to use post-quantum algorithms with them.</p><p>Most of the above ideas only provide what is often defined as ‘transitional security’, because its main focus is to provide quantum-resistant confidentiality, and not to take quantum-resistant authentication into account. It is possible to use post-quantum signatures for TLS authentication, but the post-quantum signatures are larger than traditional ones. Furthermore, it is <a href="https://csrc.nist.gov/Presentations/2019/the-2nd-round-of-the-nist-pqc-standardization-proc">worth noting</a> that using post-quantum signatures is much more expensive than using post-quantum KEMs.</p><p>We can estimate the impact of such a replacement on network traffic by simply looking at the sum of the cryptographic objects that are transmitted during the handshake. A typical TLS 1.3 handshake using elliptic curve X25519 and RSA-2048 would transmit 1,376 bytes, which would correspond to the public keys for key exchange, the certificate, the signature of the handshake, and the certificate chain. If we were to replace X25519 by the post-quantum KEM <a href="https://pq-crystals.org/kyber/">Kyber512</a> and RSA by the post-quantum signature <a href="https://pq-crystals.org/dilithium/">Dilithium II</a>, two of the more efficient proposals, the size transmitted data would increase to 10,036 bytes[4]. The increase is mostly due to the size of the post-quantum signature algorithm.</p><p>The question then is: how can we achieve full post-quantum security and give a handshake that is efficient to be used?</p>
    <div>
      <h3>A more efficient proposal: KEMTLS</h3>
      <a href="#a-more-efficient-proposal-kemtls">
        
      </a>
    </div>
    <p>There is a long history of other mechanisms, besides signatures, being used for authentication. Modern protocols, such as the Signal protocol, the Noise framework, or WireGuard, rely on key exchange mechanisms for authentication; but they are unsuitable for the TLS 1.3 case as they expect the long-term key material to be known in advance by the interested parties.</p><p>The <a href="https://eprint.iacr.org/2015/978.pdf">OPTLS proposal</a> by Krawczyk and Wee authenticates the TLS handshake without signatures by using a non-interactive key exchange (NIKE). However, the only somewhat efficient construction for a post-quantum NIKE is CSIDH, the security of which is the subject of an ongoing debate. But we can build on this idea, and use KEMs for authentication. KEMTLS, the current proposed experiment, replaces the handshake signature by a post-quantum KEM key exchange. It was designed and introduced by Peter Schwabe, Douglas Stebila and Thom Wiggers in the publication <a href="https://thomwiggers.nl/publication/kemtls/kemtls.pdf">‘Post-Quantum TLS Without Handshake Signatures’</a>.</p><p>KEMTLS, therefore, achieves the same goals as TLS 1.3 (authentication, confidentiality and integrity) in the face of quantum computers. But there’s one small difference compared to the TLS 1.3 handshake. KEMTLS allows the client to send encrypted application data in the second client-to-server TLS message flow when client authentication is not required, and in the third client-to-server TLS message flow when mutual authentication is required. Note that with TLS 1.3, the server is able to send encrypted and authenticated application data in its first response message (although, in most uses of TLS 1.3, this feature is not actually used). With KEMTLS, when client authentication is not required, the client is able to send its first encrypted application data after the same number of handshake round trips as in TLS 1.3.</p><p>Intuitively, the handshake signature in TLS 1.3 proves possession of the private key corresponding to the public key certified in the TLS 1.3 server certificate. For these signature schemes, this is the straightforward way to prove possession; another way to prove possession is through key exchanges. By carefully considering the key derivation sequence, a server can decrypt any messages sent by the client only if it holds the private key corresponding to the certified public key. Therefore, implicit authentication is fulfilled. It is worth noting that KEMTLS still relies on signatures by certificate authorities to authenticate the long-term KEM keys.</p><p>With KEMTLS, application data transmitted during the handshake is implicitly authenticated rather than explicitly (as in TLS 1.3), and has slightly weaker downgrade resilience and forward secrecy; but full downgrade resilience and forward secrecy are achieved once the KEMTLS handshake completes.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/UREaRAF5rjwsKtO4HpZ2I/96dcf49355e3f1f67d88bcb336515dd1/image1-7.png" />
            
            </figure><p>By replacing the handshake signature by a KEM key exchange, we reduce the size of the data transmitted in the example handshake to 8,344 bytes, using Kyber512 and Dilithium II — a significant reduction. We can reduce the handshake size even for algorithms such as the NTRU-assumption based KEM NTRU and signature algorithm Falcon, which have a less-pronounced size gap. Typically, KEM operations are computationally much lighter than signing operations, which makes the reduction even more significant.</p><p>KEMTLS was presented at ACM CCS 2020. You can read more about its details in <a href="https://thomwiggers.nl/publication/kemtls/kemtls.pdf">the paper</a>. It was initially <a href="https://github.com/thomwiggers/kemtls-experiment">implemented in the RustTLS library</a> by Thom Wiggers using optimized C/assembly implementations of the post-quantum algorithms provided by the <a href="https://github.com/PQClean/PQClean">PQClean</a> and <a href="https://openquantumsafe.org/">Open Quantum Safe</a> projects.</p>
    <div>
      <h3>Cloudflare and KEMTLS: the implementation</h3>
      <a href="#cloudflare-and-kemtls-the-implementation">
        
      </a>
    </div>
    <p>As part of our effort to show that TLS can be completely post-quantum safe, we implemented the full KEMTLS handshake in Golang’s TLS 1.3 suite. The implementation was done in several steps:</p><ol><li><p>We first needed to clone our own version of Golang, so we could add different post-quantum algorithms to it. You can find our own version <a href="https://github.com/cloudflare/go/">here</a>. This code gets constantly updated with every release of Golang, following <a href="https://github.com/cloudflare/go/wiki/Starting-out">these steps</a>.</p></li><li><p>We needed to implement post-quantum algorithms in Golang, which we did on our own cryptographic library, <a href="https://github.com/cloudflare/circl/tree/master/kem">CIRCL</a>.</p></li><li><p>As we cannot force certificate authorities to use certificates with long-term post-quantum KEM keys, we decided to use <a href="/keyless-delegation/">Delegated Credentials</a>. A delegated credential is a short-lasting key that the certificate’s owner has delegated for use in TLS. Therefore, they can be used for post-quantum KEM keys. See its implementation in our Golang code <a href="https://github.com/cloudflare/go/tree/cf-delegated-credentials">here</a>.</p></li><li><p>We implemented mutual auth (client and server authentication) KEMTLS by using <a href="/keyless-delegation/">Delegated Credentials</a> for the authentication process. See its implementation in our Golang code <a href="https://github.com/cloudflare/go/tree/cf-pq-kemtls">here</a>. You can also check its <a href="https://github.com/cloudflare/go/blob/cf-pq-kemtls/src/crypto/tls/delegated_credentials_test.go#L774">test</a> for an overview of how it works.</p></li></ol><p>Implementing KEMTLS was a straightforward process, although it did require changes to the way Golang handles a TLS 1.3 handshake and how the key schedule works.</p><p>A “regular” TLS 1.3 handshake in Golang (from the server perspective) looks like this:</p>
            <pre><code>func (hs *serverHandshakeStateTLS13) handshake() error {
    c := hs.c

    // For an overview of the TLS 1.3 handshake, see RFC 8446, Section 2.
    if err := hs.processClientHello(); err != nil {
   	 return err
    }
    if err := hs.checkForResumption(); err != nil {
   	 return err
    }
    if err := hs.pickCertificate(); err != nil {
   	 return err
    }
    c.buffering = true
    if err := hs.sendServerParameters(); err != nil {
   	 return err
    }
    if err := hs.sendServerCertificate(); err != nil {
   	 return err
    }
    if err := hs.sendServerFinished(); err != nil {
   	 return err
    }
    // Note that at this point we could start sending application data without
    // waiting for the client's second flight, but the application might not
    // expect the lack of replay protection of the ClientHello parameters.
    if _, err := c.flush(); err != nil {
   	 return err
    }
    if err := hs.readClientCertificate(); err != nil {
   	 return err
    }
    if err := hs.readClientFinished(); err != nil {
   	 return err
    }

    atomic.StoreUint32(&amp;c.handshakeStatus, 1)

    return nil
}</code></pre>
            <p>We had to interrupt the process when the server sends the Certificate (<code>sendServerCertificate()</code>) in order to send the KEMTLS specific messages. In the same way, we had to add the appropriate KEM TLS messages to the client’s handshake. And, as we didn’t want to change so much the way Golang handles TLS 1.3, we only added one new constant to the configuration that can be used by a server in order to ask for the Client’s Certificate (the constant is <code>serverConfig.ClientAuth = RequestClientKEMCert</code>).</p><p>The implementation is easy to work with: if a delegated credential or a certificate has a public key of a supported post-quantum KEM algorithm, the handshake will proceed with KEMTLS. If the server requests a Client KEMTLS Certificate, the handshake will use client KEMTLS authentication.</p>
    <div>
      <h3>Running the Experiment</h3>
      <a href="#running-the-experiment">
        
      </a>
    </div>
    <p>So, what’s next? We’ll take the code we have produced and run it on actual Cloudflare infrastructure to measure how efficiently it works.</p>
    <div>
      <h3>Thanks</h3>
      <a href="#thanks">
        
      </a>
    </div>
    <p>Many thanks to everyone involved in the project: Chris Wood, Armando Faz-Hernández, Thom Wiggers, Bas Westerbaan, Peter Wu, Peter Schwabe, Goutam Tamvada, Douglas Stebila, Thibault Meunier, and the whole Cloudflare Research team.</p><p><sup>1</sup>It is worth noting that the RSA key transport in TLS ≤1.2 has the server only authenticated by RSA public key encryption, although the server's RSA public key is certified using RSA signatures by Certificate Authorities.</p><p><sup>2</sup>An extension used by the client to indicate which named groups -Elliptic Curve Groups, Finite Field Groups- it supports for key exchange.</p><p><sup>3</sup>An extension which contains the endpoint’s cryptographic parameters.</p><p><sup>4</sup>These numbers, as it is noted in the paper, are based on the round-2 submissions.</p> ]]></content:encoded>
            <category><![CDATA[Cryptography]]></category>
            <category><![CDATA[TLS]]></category>
            <category><![CDATA[Research]]></category>
            <category><![CDATA[Post-Quantum]]></category>
            <guid isPermaLink="false">5jJAu3Wf2WiwWl9zjhkHTV</guid>
            <dc:creator>Sofía Celi</dc:creator>
            <dc:creator>Thom Wiggers</dc:creator>
        </item>
    </channel>
</rss>