Add most of an ECH client implementation.

Based on an initial implementation by Dan McArdle at

This CL contains most of a client implementation for
draft-ietf-tls-esni-10. The pieces missing so far, which will be done in
follow-up CLs are:

1. While the ClientHelloInner is padded, the server Certificate message
   is not. I'll add that once we resolve the spec discussions on how to
   do that. (We were originally going to use TLS record-level padding,
   but that doesn't work well with QUIC.)

2. The client should check the public name is a valid DNS name before
   copying it into ClientHelloOuter.server_name.

3. The ClientHelloOuter handshake flow is not yet implemented. This CL
   can detect when the server selects ClientHelloOuter, but for now the
   handshake immediately fails. A follow-up CL will remove that logic
   and instead add the APIs and extra checks needed.

Otherwise, this should be complete, including padding and compression.

The main interesting point design-wise is that we run through
ClientHello construction multiple times. We need to construct
ClientHelloInner and ClientHelloOuter. Then each of those has slight
variants: EncodedClientHelloInner is the compressed form, and
ClientHelloOuterAAD just has the ECH extension erased to avoid a
circular dependency.

I've computed ClientHelloInner and EncodedClientHelloInner concurrently
because the compression scheme requires shifting the extensions around
to be contiguous. However, I've computed ClientHelloOuterAAD and
ClientHelloOuter by running through the logic twice. This probably can
be done better, but the next draft revises the construction anyway, so
I'm thinking I'll rework it then. (In the next draft, we use a
placeholder payload of the same length, so we can construct the
ClientHello once and fill in the payload.)

Additionally, now that we have a client available in ssl_test, this adds
a threading test to confirm that SSL_CTX_set1_ech_keys is properly
synchronized. (Confirmed that, if I drop the lock in
SSL_CTX_set1_ech_keys, TSan notices.)

Change-Id: Icaff68b595035bdcc73c468ff638e67c84239ef4
Reviewed-by: Adam Langley <>
22 files changed
tree: 92124e67e0431fe53bd31862e73975bc5e4f49eb
  1. .clang-format
  2. .github/
  3. .gitignore
  7. CMakeLists.txt
  16. codereview.settings
  17. crypto/
  18. decrepit/
  19. fuzz/
  20. go.mod
  21. go.sum
  22. include/
  23. sources.cmake
  24. ssl/
  25. third_party/
  26. tool/
  27. util/


BoringSSL is a fork of OpenSSL that is designed to meet Google's needs.

Although BoringSSL is an open source project, it is not intended for general use, as OpenSSL is. We don't recommend that third parties depend upon it. Doing so is likely to be frustrating because there are no guarantees of API or ABI stability.

Programs ship their own copies of BoringSSL when they use it and we update everything as needed when deciding to make API changes. This allows us to mostly avoid compromises in the name of compatibility. It works for us, but it may not work for you.

BoringSSL arose because Google used OpenSSL for many years in various ways and, over time, built up a large number of patches that were maintained while tracking upstream OpenSSL. As Google's product portfolio became more complex, more copies of OpenSSL sprung up and the effort involved in maintaining all these patches in multiple places was growing steadily.

Currently BoringSSL is the SSL library in Chrome/Chromium, Android (but it's not part of the NDK) and a number of other apps/programs.

Project links:

There are other files in this directory which might be helpful: