external/boringssl: Sync to b1cbe1979008debd0541621584b00e010d9935dd.

This includes the following changes:

https://boringssl.googlesource.com/boringssl/+log/ba94746eb2b4b59a0eb72047e4ca2d2d54454c87..b1cbe1979008debd0541621584b00e010d9935dd

Test: BoringSSL CTS Presubmits.
Change-Id: I143290c32ebd3d98f5a35ec8899df44983b73b8a
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1f2f6ba..338f212 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -338,6 +338,7 @@
 add_library(crypto_test_data OBJECT crypto_test_data.cc)
 
 add_subdirectory(crypto)
+add_subdirectory(third_party/fiat)
 add_subdirectory(ssl)
 add_subdirectory(ssl/test)
 add_subdirectory(fipstools)
diff --git a/src/LICENSE b/src/LICENSE
index a25996f..ff4116f 100644
--- a/src/LICENSE
+++ b/src/LICENSE
@@ -6,7 +6,9 @@
 https://cla.developers.google.com/clas
 
 Some files from Intel are under yet another license, which is also included
-underneath.
+underneath. Files in third_party/ have their own licenses, as described
+therein. The MIT license, for third_party/fiat, which, unlike other third_party
+directories, is compiled into non-test libraries, is included below.
 
 The OpenSSL toolkit stays under a dual license, i.e. both the conditions of the
 OpenSSL License and the original SSLeay license apply to the toolkit. See below
@@ -190,3 +192,27 @@
 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+The code in third_party/fiat carries the MIT license:
+
+Copyright (c) 2015-2016 the fiat-crypto authors (see
+https://github.com/mit-plv/fiat-crypto/blob/master/AUTHORS).
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt
index ae5d0b6..640f206 100644
--- a/src/crypto/CMakeLists.txt
+++ b/src/crypto/CMakeLists.txt
@@ -179,6 +179,7 @@
   $<TARGET_OBJECTS:chacha>
   $<TARGET_OBJECTS:poly1305>
   $<TARGET_OBJECTS:curve25519>
+  $<TARGET_OBJECTS:fiat>
   $<TARGET_OBJECTS:buf>
   $<TARGET_OBJECTS:bn_extra>
   $<TARGET_OBJECTS:bio>
diff --git a/src/crypto/conf/conf.c b/src/crypto/conf/conf.c
index f8ff613..b1982f8 100644
--- a/src/crypto/conf/conf.c
+++ b/src/crypto/conf/conf.c
@@ -791,13 +791,13 @@
   }
 }
 
-int CONF_modules_load_file(CONF_MUST_BE_NULL *filename, const char *appname,
+int CONF_modules_load_file(const char *filename, const char *appname,
                            unsigned long flags) {
   return 1;
 }
 
 void CONF_modules_free(void) {}
 
-void OPENSSL_config(CONF_MUST_BE_NULL *config_name) {}
+void OPENSSL_config(const char *config_name) {}
 
 void OPENSSL_no_config(void) {}
diff --git a/src/crypto/curve25519/CMakeLists.txt b/src/crypto/curve25519/CMakeLists.txt
index c6004d3..6f51d54 100644
--- a/src/crypto/curve25519/CMakeLists.txt
+++ b/src/crypto/curve25519/CMakeLists.txt
@@ -21,7 +21,6 @@
 
   OBJECT
 
-  curve25519.c
   spake25519.c
   x25519-x86_64.c
 
diff --git a/src/crypto/curve25519/curve25519.c b/src/crypto/curve25519/curve25519.c
deleted file mode 100644
index e49a8b3..0000000
--- a/src/crypto/curve25519/curve25519.c
+++ /dev/null
@@ -1,4938 +0,0 @@
-/* Copyright (c) 2015, Google Inc.
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
-
-// This code is mostly taken from the ref10 version of Ed25519 in SUPERCOP
-// 20141124 (http://bench.cr.yp.to/supercop.html). That code is released as
-// public domain but this file has the ISC license just to keep licencing
-// simple.
-//
-// The field functions are shared by Ed25519 and X25519 where possible.
-
-#include <openssl/curve25519.h>
-
-#include <string.h>
-
-#include <openssl/cpu.h>
-#include <openssl/mem.h>
-#include <openssl/rand.h>
-#include <openssl/sha.h>
-
-#include "internal.h"
-#include "../internal.h"
-
-
-static const int64_t kBottom25Bits = INT64_C(0x1ffffff);
-static const int64_t kBottom26Bits = INT64_C(0x3ffffff);
-static const int64_t kTop39Bits = INT64_C(0xfffffffffe000000);
-static const int64_t kTop38Bits = INT64_C(0xfffffffffc000000);
-
-static uint64_t load_3(const uint8_t *in) {
-  uint64_t result;
-  result = (uint64_t)in[0];
-  result |= ((uint64_t)in[1]) << 8;
-  result |= ((uint64_t)in[2]) << 16;
-  return result;
-}
-
-static uint64_t load_4(const uint8_t *in) {
-  uint64_t result;
-  result = (uint64_t)in[0];
-  result |= ((uint64_t)in[1]) << 8;
-  result |= ((uint64_t)in[2]) << 16;
-  result |= ((uint64_t)in[3]) << 24;
-  return result;
-}
-
-static void fe_frombytes(fe h, const uint8_t *s) {
-  // Ignores top bit of h.
-  int64_t h0 = load_4(s);
-  int64_t h1 = load_3(s + 4) << 6;
-  int64_t h2 = load_3(s + 7) << 5;
-  int64_t h3 = load_3(s + 10) << 3;
-  int64_t h4 = load_3(s + 13) << 2;
-  int64_t h5 = load_4(s + 16);
-  int64_t h6 = load_3(s + 20) << 7;
-  int64_t h7 = load_3(s + 23) << 5;
-  int64_t h8 = load_3(s + 26) << 4;
-  int64_t h9 = (load_3(s + 29) & 8388607) << 2;
-  int64_t carry0;
-  int64_t carry1;
-  int64_t carry2;
-  int64_t carry3;
-  int64_t carry4;
-  int64_t carry5;
-  int64_t carry6;
-  int64_t carry7;
-  int64_t carry8;
-  int64_t carry9;
-
-  carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
-  carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
-  carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
-  carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
-  carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-  carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-  carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
-  carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
-
-  h[0] = h0;
-  h[1] = h1;
-  h[2] = h2;
-  h[3] = h3;
-  h[4] = h4;
-  h[5] = h5;
-  h[6] = h6;
-  h[7] = h7;
-  h[8] = h8;
-  h[9] = h9;
-}
-
-// Preconditions:
-//  |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
-//
-// Write p=2^255-19; q=floor(h/p).
-// Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
-//
-// Proof:
-//   Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
-//   Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.
-//
-//   Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
-//   Then 0<y<1.
-//
-//   Write r=h-pq.
-//   Have 0<=r<=p-1=2^255-20.
-//   Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
-//
-//   Write x=r+19(2^-255)r+y.
-//   Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
-//
-//   Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
-//   so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
-static void fe_tobytes(uint8_t *s, const fe h) {
-  int32_t h0 = h[0];
-  int32_t h1 = h[1];
-  int32_t h2 = h[2];
-  int32_t h3 = h[3];
-  int32_t h4 = h[4];
-  int32_t h5 = h[5];
-  int32_t h6 = h[6];
-  int32_t h7 = h[7];
-  int32_t h8 = h[8];
-  int32_t h9 = h[9];
-  int32_t q;
-
-  q = (19 * h9 + (((int32_t) 1) << 24)) >> 25;
-  q = (h0 + q) >> 26;
-  q = (h1 + q) >> 25;
-  q = (h2 + q) >> 26;
-  q = (h3 + q) >> 25;
-  q = (h4 + q) >> 26;
-  q = (h5 + q) >> 25;
-  q = (h6 + q) >> 26;
-  q = (h7 + q) >> 25;
-  q = (h8 + q) >> 26;
-  q = (h9 + q) >> 25;
-
-  // Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20.
-  h0 += 19 * q;
-  // Goal: Output h-2^255 q, which is between 0 and 2^255-20.
-
-  h1 += h0 >> 26; h0 &= kBottom26Bits;
-  h2 += h1 >> 25; h1 &= kBottom25Bits;
-  h3 += h2 >> 26; h2 &= kBottom26Bits;
-  h4 += h3 >> 25; h3 &= kBottom25Bits;
-  h5 += h4 >> 26; h4 &= kBottom26Bits;
-  h6 += h5 >> 25; h5 &= kBottom25Bits;
-  h7 += h6 >> 26; h6 &= kBottom26Bits;
-  h8 += h7 >> 25; h7 &= kBottom25Bits;
-  h9 += h8 >> 26; h8 &= kBottom26Bits;
-                  h9 &= kBottom25Bits;
-                  // h10 = carry9
-
-  // Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.
-  // Have h0+...+2^230 h9 between 0 and 2^255-1;
-  // evidently 2^255 h10-2^255 q = 0.
-  // Goal: Output h0+...+2^230 h9.
-
-  s[0] = h0 >> 0;
-  s[1] = h0 >> 8;
-  s[2] = h0 >> 16;
-  s[3] = (h0 >> 24) | ((uint32_t)(h1) << 2);
-  s[4] = h1 >> 6;
-  s[5] = h1 >> 14;
-  s[6] = (h1 >> 22) | ((uint32_t)(h2) << 3);
-  s[7] = h2 >> 5;
-  s[8] = h2 >> 13;
-  s[9] = (h2 >> 21) | ((uint32_t)(h3) << 5);
-  s[10] = h3 >> 3;
-  s[11] = h3 >> 11;
-  s[12] = (h3 >> 19) | ((uint32_t)(h4) << 6);
-  s[13] = h4 >> 2;
-  s[14] = h4 >> 10;
-  s[15] = h4 >> 18;
-  s[16] = h5 >> 0;
-  s[17] = h5 >> 8;
-  s[18] = h5 >> 16;
-  s[19] = (h5 >> 24) | ((uint32_t)(h6) << 1);
-  s[20] = h6 >> 7;
-  s[21] = h6 >> 15;
-  s[22] = (h6 >> 23) | ((uint32_t)(h7) << 3);
-  s[23] = h7 >> 5;
-  s[24] = h7 >> 13;
-  s[25] = (h7 >> 21) | ((uint32_t)(h8) << 4);
-  s[26] = h8 >> 4;
-  s[27] = h8 >> 12;
-  s[28] = (h8 >> 20) | ((uint32_t)(h9) << 6);
-  s[29] = h9 >> 2;
-  s[30] = h9 >> 10;
-  s[31] = h9 >> 18;
-}
-
-// h = f
-static void fe_copy(fe h, const fe f) {
-  OPENSSL_memmove(h, f, sizeof(int32_t) * 10);
-}
-
-// h = 0
-static void fe_0(fe h) { OPENSSL_memset(h, 0, sizeof(int32_t) * 10); }
-
-// h = 1
-static void fe_1(fe h) {
-  OPENSSL_memset(h, 0, sizeof(int32_t) * 10);
-  h[0] = 1;
-}
-
-// h = f + g
-// Can overlap h with f or g.
-//
-// Preconditions:
-//    |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
-//    |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
-//
-// Postconditions:
-//    |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
-static void fe_add(fe h, const fe f, const fe g) {
-  unsigned i;
-  for (i = 0; i < 10; i++) {
-    h[i] = f[i] + g[i];
-  }
-}
-
-// h = f - g
-// Can overlap h with f or g.
-//
-// Preconditions:
-//    |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
-//    |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
-//
-// Postconditions:
-//    |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
-static void fe_sub(fe h, const fe f, const fe g) {
-  unsigned i;
-  for (i = 0; i < 10; i++) {
-    h[i] = f[i] - g[i];
-  }
-}
-
-// h = f * g
-// Can overlap h with f or g.
-//
-// Preconditions:
-//    |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
-//    |g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
-//
-// Postconditions:
-//    |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
-//
-// Notes on implementation strategy:
-//
-// Using schoolbook multiplication.
-// Karatsuba would save a little in some cost models.
-//
-// Most multiplications by 2 and 19 are 32-bit precomputations;
-// cheaper than 64-bit postcomputations.
-//
-// There is one remaining multiplication by 19 in the carry chain;
-// one *19 precomputation can be merged into this,
-// but the resulting data flow is considerably less clean.
-//
-// There are 12 carries below.
-// 10 of them are 2-way parallelizable and vectorizable.
-// Can get away with 11 carries, but then data flow is much deeper.
-//
-// With tighter constraints on inputs can squeeze carries into int32.
-static void fe_mul(fe h, const fe f, const fe g) {
-  int32_t f0 = f[0];
-  int32_t f1 = f[1];
-  int32_t f2 = f[2];
-  int32_t f3 = f[3];
-  int32_t f4 = f[4];
-  int32_t f5 = f[5];
-  int32_t f6 = f[6];
-  int32_t f7 = f[7];
-  int32_t f8 = f[8];
-  int32_t f9 = f[9];
-  int32_t g0 = g[0];
-  int32_t g1 = g[1];
-  int32_t g2 = g[2];
-  int32_t g3 = g[3];
-  int32_t g4 = g[4];
-  int32_t g5 = g[5];
-  int32_t g6 = g[6];
-  int32_t g7 = g[7];
-  int32_t g8 = g[8];
-  int32_t g9 = g[9];
-  int32_t g1_19 = 19 * g1;  // 1.959375*2^29
-  int32_t g2_19 = 19 * g2;  // 1.959375*2^30; still ok
-  int32_t g3_19 = 19 * g3;
-  int32_t g4_19 = 19 * g4;
-  int32_t g5_19 = 19 * g5;
-  int32_t g6_19 = 19 * g6;
-  int32_t g7_19 = 19 * g7;
-  int32_t g8_19 = 19 * g8;
-  int32_t g9_19 = 19 * g9;
-  int32_t f1_2 = 2 * f1;
-  int32_t f3_2 = 2 * f3;
-  int32_t f5_2 = 2 * f5;
-  int32_t f7_2 = 2 * f7;
-  int32_t f9_2 = 2 * f9;
-  int64_t f0g0    = f0   * (int64_t) g0;
-  int64_t f0g1    = f0   * (int64_t) g1;
-  int64_t f0g2    = f0   * (int64_t) g2;
-  int64_t f0g3    = f0   * (int64_t) g3;
-  int64_t f0g4    = f0   * (int64_t) g4;
-  int64_t f0g5    = f0   * (int64_t) g5;
-  int64_t f0g6    = f0   * (int64_t) g6;
-  int64_t f0g7    = f0   * (int64_t) g7;
-  int64_t f0g8    = f0   * (int64_t) g8;
-  int64_t f0g9    = f0   * (int64_t) g9;
-  int64_t f1g0    = f1   * (int64_t) g0;
-  int64_t f1g1_2  = f1_2 * (int64_t) g1;
-  int64_t f1g2    = f1   * (int64_t) g2;
-  int64_t f1g3_2  = f1_2 * (int64_t) g3;
-  int64_t f1g4    = f1   * (int64_t) g4;
-  int64_t f1g5_2  = f1_2 * (int64_t) g5;
-  int64_t f1g6    = f1   * (int64_t) g6;
-  int64_t f1g7_2  = f1_2 * (int64_t) g7;
-  int64_t f1g8    = f1   * (int64_t) g8;
-  int64_t f1g9_38 = f1_2 * (int64_t) g9_19;
-  int64_t f2g0    = f2   * (int64_t) g0;
-  int64_t f2g1    = f2   * (int64_t) g1;
-  int64_t f2g2    = f2   * (int64_t) g2;
-  int64_t f2g3    = f2   * (int64_t) g3;
-  int64_t f2g4    = f2   * (int64_t) g4;
-  int64_t f2g5    = f2   * (int64_t) g5;
-  int64_t f2g6    = f2   * (int64_t) g6;
-  int64_t f2g7    = f2   * (int64_t) g7;
-  int64_t f2g8_19 = f2   * (int64_t) g8_19;
-  int64_t f2g9_19 = f2   * (int64_t) g9_19;
-  int64_t f3g0    = f3   * (int64_t) g0;
-  int64_t f3g1_2  = f3_2 * (int64_t) g1;
-  int64_t f3g2    = f3   * (int64_t) g2;
-  int64_t f3g3_2  = f3_2 * (int64_t) g3;
-  int64_t f3g4    = f3   * (int64_t) g4;
-  int64_t f3g5_2  = f3_2 * (int64_t) g5;
-  int64_t f3g6    = f3   * (int64_t) g6;
-  int64_t f3g7_38 = f3_2 * (int64_t) g7_19;
-  int64_t f3g8_19 = f3   * (int64_t) g8_19;
-  int64_t f3g9_38 = f3_2 * (int64_t) g9_19;
-  int64_t f4g0    = f4   * (int64_t) g0;
-  int64_t f4g1    = f4   * (int64_t) g1;
-  int64_t f4g2    = f4   * (int64_t) g2;
-  int64_t f4g3    = f4   * (int64_t) g3;
-  int64_t f4g4    = f4   * (int64_t) g4;
-  int64_t f4g5    = f4   * (int64_t) g5;
-  int64_t f4g6_19 = f4   * (int64_t) g6_19;
-  int64_t f4g7_19 = f4   * (int64_t) g7_19;
-  int64_t f4g8_19 = f4   * (int64_t) g8_19;
-  int64_t f4g9_19 = f4   * (int64_t) g9_19;
-  int64_t f5g0    = f5   * (int64_t) g0;
-  int64_t f5g1_2  = f5_2 * (int64_t) g1;
-  int64_t f5g2    = f5   * (int64_t) g2;
-  int64_t f5g3_2  = f5_2 * (int64_t) g3;
-  int64_t f5g4    = f5   * (int64_t) g4;
-  int64_t f5g5_38 = f5_2 * (int64_t) g5_19;
-  int64_t f5g6_19 = f5   * (int64_t) g6_19;
-  int64_t f5g7_38 = f5_2 * (int64_t) g7_19;
-  int64_t f5g8_19 = f5   * (int64_t) g8_19;
-  int64_t f5g9_38 = f5_2 * (int64_t) g9_19;
-  int64_t f6g0    = f6   * (int64_t) g0;
-  int64_t f6g1    = f6   * (int64_t) g1;
-  int64_t f6g2    = f6   * (int64_t) g2;
-  int64_t f6g3    = f6   * (int64_t) g3;
-  int64_t f6g4_19 = f6   * (int64_t) g4_19;
-  int64_t f6g5_19 = f6   * (int64_t) g5_19;
-  int64_t f6g6_19 = f6   * (int64_t) g6_19;
-  int64_t f6g7_19 = f6   * (int64_t) g7_19;
-  int64_t f6g8_19 = f6   * (int64_t) g8_19;
-  int64_t f6g9_19 = f6   * (int64_t) g9_19;
-  int64_t f7g0    = f7   * (int64_t) g0;
-  int64_t f7g1_2  = f7_2 * (int64_t) g1;
-  int64_t f7g2    = f7   * (int64_t) g2;
-  int64_t f7g3_38 = f7_2 * (int64_t) g3_19;
-  int64_t f7g4_19 = f7   * (int64_t) g4_19;
-  int64_t f7g5_38 = f7_2 * (int64_t) g5_19;
-  int64_t f7g6_19 = f7   * (int64_t) g6_19;
-  int64_t f7g7_38 = f7_2 * (int64_t) g7_19;
-  int64_t f7g8_19 = f7   * (int64_t) g8_19;
-  int64_t f7g9_38 = f7_2 * (int64_t) g9_19;
-  int64_t f8g0    = f8   * (int64_t) g0;
-  int64_t f8g1    = f8   * (int64_t) g1;
-  int64_t f8g2_19 = f8   * (int64_t) g2_19;
-  int64_t f8g3_19 = f8   * (int64_t) g3_19;
-  int64_t f8g4_19 = f8   * (int64_t) g4_19;
-  int64_t f8g5_19 = f8   * (int64_t) g5_19;
-  int64_t f8g6_19 = f8   * (int64_t) g6_19;
-  int64_t f8g7_19 = f8   * (int64_t) g7_19;
-  int64_t f8g8_19 = f8   * (int64_t) g8_19;
-  int64_t f8g9_19 = f8   * (int64_t) g9_19;
-  int64_t f9g0    = f9   * (int64_t) g0;
-  int64_t f9g1_38 = f9_2 * (int64_t) g1_19;
-  int64_t f9g2_19 = f9   * (int64_t) g2_19;
-  int64_t f9g3_38 = f9_2 * (int64_t) g3_19;
-  int64_t f9g4_19 = f9   * (int64_t) g4_19;
-  int64_t f9g5_38 = f9_2 * (int64_t) g5_19;
-  int64_t f9g6_19 = f9   * (int64_t) g6_19;
-  int64_t f9g7_38 = f9_2 * (int64_t) g7_19;
-  int64_t f9g8_19 = f9   * (int64_t) g8_19;
-  int64_t f9g9_38 = f9_2 * (int64_t) g9_19;
-  int64_t h0 = f0g0+f1g9_38+f2g8_19+f3g7_38+f4g6_19+f5g5_38+f6g4_19+f7g3_38+f8g2_19+f9g1_38;
-  int64_t h1 = f0g1+f1g0   +f2g9_19+f3g8_19+f4g7_19+f5g6_19+f6g5_19+f7g4_19+f8g3_19+f9g2_19;
-  int64_t h2 = f0g2+f1g1_2 +f2g0   +f3g9_38+f4g8_19+f5g7_38+f6g6_19+f7g5_38+f8g4_19+f9g3_38;
-  int64_t h3 = f0g3+f1g2   +f2g1   +f3g0   +f4g9_19+f5g8_19+f6g7_19+f7g6_19+f8g5_19+f9g4_19;
-  int64_t h4 = f0g4+f1g3_2 +f2g2   +f3g1_2 +f4g0   +f5g9_38+f6g8_19+f7g7_38+f8g6_19+f9g5_38;
-  int64_t h5 = f0g5+f1g4   +f2g3   +f3g2   +f4g1   +f5g0   +f6g9_19+f7g8_19+f8g7_19+f9g6_19;
-  int64_t h6 = f0g6+f1g5_2 +f2g4   +f3g3_2 +f4g2   +f5g1_2 +f6g0   +f7g9_38+f8g8_19+f9g7_38;
-  int64_t h7 = f0g7+f1g6   +f2g5   +f3g4   +f4g3   +f5g2   +f6g1   +f7g0   +f8g9_19+f9g8_19;
-  int64_t h8 = f0g8+f1g7_2 +f2g6   +f3g5_2 +f4g4   +f5g3_2 +f6g2   +f7g1_2 +f8g0   +f9g9_38;
-  int64_t h9 = f0g9+f1g8   +f2g7   +f3g6   +f4g5   +f5g4   +f6g3   +f7g2   +f8g1   +f9g0   ;
-  int64_t carry0;
-  int64_t carry1;
-  int64_t carry2;
-  int64_t carry3;
-  int64_t carry4;
-  int64_t carry5;
-  int64_t carry6;
-  int64_t carry7;
-  int64_t carry8;
-  int64_t carry9;
-
-  // |h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38))
-  //   i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8
-  // |h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19))
-  //   i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-  // |h0| <= 2^25
-  // |h4| <= 2^25
-  // |h1| <= 1.71*2^59
-  // |h5| <= 1.71*2^59
-
-  carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
-  carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
-  // |h1| <= 2^24; from now on fits into int32
-  // |h5| <= 2^24; from now on fits into int32
-  // |h2| <= 1.41*2^60
-  // |h6| <= 1.41*2^60
-
-  carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
-  carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
-  // |h2| <= 2^25; from now on fits into int32 unchanged
-  // |h6| <= 2^25; from now on fits into int32 unchanged
-  // |h3| <= 1.71*2^59
-  // |h7| <= 1.71*2^59
-
-  carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
-  carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
-  // |h3| <= 2^24; from now on fits into int32 unchanged
-  // |h7| <= 2^24; from now on fits into int32 unchanged
-  // |h4| <= 1.72*2^34
-  // |h8| <= 1.41*2^60
-
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-  carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
-  // |h4| <= 2^25; from now on fits into int32 unchanged
-  // |h8| <= 2^25; from now on fits into int32 unchanged
-  // |h5| <= 1.01*2^24
-  // |h9| <= 1.71*2^59
-
-  carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
-  // |h9| <= 2^24; from now on fits into int32 unchanged
-  // |h0| <= 1.1*2^39
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-  // |h0| <= 2^25; from now on fits into int32 unchanged
-  // |h1| <= 1.01*2^24
-
-  h[0] = h0;
-  h[1] = h1;
-  h[2] = h2;
-  h[3] = h3;
-  h[4] = h4;
-  h[5] = h5;
-  h[6] = h6;
-  h[7] = h7;
-  h[8] = h8;
-  h[9] = h9;
-}
-
-// h = f * f
-// Can overlap h with f.
-//
-// Preconditions:
-//    |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
-//
-// Postconditions:
-//    |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
-//
-// See fe_mul.c for discussion of implementation strategy.
-static void fe_sq(fe h, const fe f) {
-  int32_t f0 = f[0];
-  int32_t f1 = f[1];
-  int32_t f2 = f[2];
-  int32_t f3 = f[3];
-  int32_t f4 = f[4];
-  int32_t f5 = f[5];
-  int32_t f6 = f[6];
-  int32_t f7 = f[7];
-  int32_t f8 = f[8];
-  int32_t f9 = f[9];
-  int32_t f0_2 = 2 * f0;
-  int32_t f1_2 = 2 * f1;
-  int32_t f2_2 = 2 * f2;
-  int32_t f3_2 = 2 * f3;
-  int32_t f4_2 = 2 * f4;
-  int32_t f5_2 = 2 * f5;
-  int32_t f6_2 = 2 * f6;
-  int32_t f7_2 = 2 * f7;
-  int32_t f5_38 = 38 * f5;  // 1.959375*2^30
-  int32_t f6_19 = 19 * f6;  // 1.959375*2^30
-  int32_t f7_38 = 38 * f7;  // 1.959375*2^30
-  int32_t f8_19 = 19 * f8;  // 1.959375*2^30
-  int32_t f9_38 = 38 * f9;  // 1.959375*2^30
-  int64_t f0f0    = f0   * (int64_t) f0;
-  int64_t f0f1_2  = f0_2 * (int64_t) f1;
-  int64_t f0f2_2  = f0_2 * (int64_t) f2;
-  int64_t f0f3_2  = f0_2 * (int64_t) f3;
-  int64_t f0f4_2  = f0_2 * (int64_t) f4;
-  int64_t f0f5_2  = f0_2 * (int64_t) f5;
-  int64_t f0f6_2  = f0_2 * (int64_t) f6;
-  int64_t f0f7_2  = f0_2 * (int64_t) f7;
-  int64_t f0f8_2  = f0_2 * (int64_t) f8;
-  int64_t f0f9_2  = f0_2 * (int64_t) f9;
-  int64_t f1f1_2  = f1_2 * (int64_t) f1;
-  int64_t f1f2_2  = f1_2 * (int64_t) f2;
-  int64_t f1f3_4  = f1_2 * (int64_t) f3_2;
-  int64_t f1f4_2  = f1_2 * (int64_t) f4;
-  int64_t f1f5_4  = f1_2 * (int64_t) f5_2;
-  int64_t f1f6_2  = f1_2 * (int64_t) f6;
-  int64_t f1f7_4  = f1_2 * (int64_t) f7_2;
-  int64_t f1f8_2  = f1_2 * (int64_t) f8;
-  int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
-  int64_t f2f2    = f2   * (int64_t) f2;
-  int64_t f2f3_2  = f2_2 * (int64_t) f3;
-  int64_t f2f4_2  = f2_2 * (int64_t) f4;
-  int64_t f2f5_2  = f2_2 * (int64_t) f5;
-  int64_t f2f6_2  = f2_2 * (int64_t) f6;
-  int64_t f2f7_2  = f2_2 * (int64_t) f7;
-  int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
-  int64_t f2f9_38 = f2   * (int64_t) f9_38;
-  int64_t f3f3_2  = f3_2 * (int64_t) f3;
-  int64_t f3f4_2  = f3_2 * (int64_t) f4;
-  int64_t f3f5_4  = f3_2 * (int64_t) f5_2;
-  int64_t f3f6_2  = f3_2 * (int64_t) f6;
-  int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
-  int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
-  int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
-  int64_t f4f4    = f4   * (int64_t) f4;
-  int64_t f4f5_2  = f4_2 * (int64_t) f5;
-  int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
-  int64_t f4f7_38 = f4   * (int64_t) f7_38;
-  int64_t f4f8_38 = f4_2 * (int64_t) f8_19;
-  int64_t f4f9_38 = f4   * (int64_t) f9_38;
-  int64_t f5f5_38 = f5   * (int64_t) f5_38;
-  int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
-  int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
-  int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
-  int64_t f5f9_76 = f5_2 * (int64_t) f9_38;
-  int64_t f6f6_19 = f6   * (int64_t) f6_19;
-  int64_t f6f7_38 = f6   * (int64_t) f7_38;
-  int64_t f6f8_38 = f6_2 * (int64_t) f8_19;
-  int64_t f6f9_38 = f6   * (int64_t) f9_38;
-  int64_t f7f7_38 = f7   * (int64_t) f7_38;
-  int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
-  int64_t f7f9_76 = f7_2 * (int64_t) f9_38;
-  int64_t f8f8_19 = f8   * (int64_t) f8_19;
-  int64_t f8f9_38 = f8   * (int64_t) f9_38;
-  int64_t f9f9_38 = f9   * (int64_t) f9_38;
-  int64_t h0 = f0f0  +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
-  int64_t h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
-  int64_t h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
-  int64_t h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
-  int64_t h4 = f0f4_2+f1f3_4 +f2f2   +f5f9_76+f6f8_38+f7f7_38;
-  int64_t h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
-  int64_t h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
-  int64_t h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
-  int64_t h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4   +f9f9_38;
-  int64_t h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
-  int64_t carry0;
-  int64_t carry1;
-  int64_t carry2;
-  int64_t carry3;
-  int64_t carry4;
-  int64_t carry5;
-  int64_t carry6;
-  int64_t carry7;
-  int64_t carry8;
-  int64_t carry9;
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-
-  carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
-  carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
-
-  carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
-  carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
-
-  carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
-  carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
-
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-  carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
-
-  carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-
-  h[0] = h0;
-  h[1] = h1;
-  h[2] = h2;
-  h[3] = h3;
-  h[4] = h4;
-  h[5] = h5;
-  h[6] = h6;
-  h[7] = h7;
-  h[8] = h8;
-  h[9] = h9;
-}
-
-static void fe_invert(fe out, const fe z) {
-  fe t0;
-  fe t1;
-  fe t2;
-  fe t3;
-  int i;
-
-  fe_sq(t0, z);
-  fe_sq(t1, t0);
-  for (i = 1; i < 2; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(t1, z, t1);
-  fe_mul(t0, t0, t1);
-  fe_sq(t2, t0);
-  fe_mul(t1, t1, t2);
-  fe_sq(t2, t1);
-  for (i = 1; i < 5; ++i) {
-    fe_sq(t2, t2);
-  }
-  fe_mul(t1, t2, t1);
-  fe_sq(t2, t1);
-  for (i = 1; i < 10; ++i) {
-    fe_sq(t2, t2);
-  }
-  fe_mul(t2, t2, t1);
-  fe_sq(t3, t2);
-  for (i = 1; i < 20; ++i) {
-    fe_sq(t3, t3);
-  }
-  fe_mul(t2, t3, t2);
-  fe_sq(t2, t2);
-  for (i = 1; i < 10; ++i) {
-    fe_sq(t2, t2);
-  }
-  fe_mul(t1, t2, t1);
-  fe_sq(t2, t1);
-  for (i = 1; i < 50; ++i) {
-    fe_sq(t2, t2);
-  }
-  fe_mul(t2, t2, t1);
-  fe_sq(t3, t2);
-  for (i = 1; i < 100; ++i) {
-    fe_sq(t3, t3);
-  }
-  fe_mul(t2, t3, t2);
-  fe_sq(t2, t2);
-  for (i = 1; i < 50; ++i) {
-    fe_sq(t2, t2);
-  }
-  fe_mul(t1, t2, t1);
-  fe_sq(t1, t1);
-  for (i = 1; i < 5; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(out, t1, t0);
-}
-
-// h = -f
-//
-// Preconditions:
-//    |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
-//
-// Postconditions:
-//    |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
-static void fe_neg(fe h, const fe f) {
-  unsigned i;
-  for (i = 0; i < 10; i++) {
-    h[i] = -f[i];
-  }
-}
-
-// Replace (f,g) with (g,g) if b == 1;
-// replace (f,g) with (f,g) if b == 0.
-//
-// Preconditions: b in {0,1}.
-static void fe_cmov(fe f, const fe g, unsigned b) {
-  b = 0-b;
-  unsigned i;
-  for (i = 0; i < 10; i++) {
-    int32_t x = f[i] ^ g[i];
-    x &= b;
-    f[i] ^= x;
-  }
-}
-
-// return 0 if f == 0
-// return 1 if f != 0
-//
-// Preconditions:
-//    |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
-static int fe_isnonzero(const fe f) {
-  uint8_t s[32];
-  fe_tobytes(s, f);
-
-  static const uint8_t zero[32] = {0};
-  return CRYPTO_memcmp(s, zero, sizeof(zero)) != 0;
-}
-
-// return 1 if f is in {1,3,5,...,q-2}
-// return 0 if f is in {0,2,4,...,q-1}
-//
-// Preconditions:
-//    |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
-static int fe_isnegative(const fe f) {
-  uint8_t s[32];
-  fe_tobytes(s, f);
-  return s[0] & 1;
-}
-
-// h = 2 * f * f
-// Can overlap h with f.
-//
-// Preconditions:
-//    |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
-//
-// Postconditions:
-//    |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
-//
-// See fe_mul.c for discussion of implementation strategy.
-static void fe_sq2(fe h, const fe f) {
-  int32_t f0 = f[0];
-  int32_t f1 = f[1];
-  int32_t f2 = f[2];
-  int32_t f3 = f[3];
-  int32_t f4 = f[4];
-  int32_t f5 = f[5];
-  int32_t f6 = f[6];
-  int32_t f7 = f[7];
-  int32_t f8 = f[8];
-  int32_t f9 = f[9];
-  int32_t f0_2 = 2 * f0;
-  int32_t f1_2 = 2 * f1;
-  int32_t f2_2 = 2 * f2;
-  int32_t f3_2 = 2 * f3;
-  int32_t f4_2 = 2 * f4;
-  int32_t f5_2 = 2 * f5;
-  int32_t f6_2 = 2 * f6;
-  int32_t f7_2 = 2 * f7;
-  int32_t f5_38 = 38 * f5;  // 1.959375*2^30
-  int32_t f6_19 = 19 * f6;  // 1.959375*2^30
-  int32_t f7_38 = 38 * f7;  // 1.959375*2^30
-  int32_t f8_19 = 19 * f8;  // 1.959375*2^30
-  int32_t f9_38 = 38 * f9;  // 1.959375*2^30
-  int64_t f0f0    = f0   * (int64_t) f0;
-  int64_t f0f1_2  = f0_2 * (int64_t) f1;
-  int64_t f0f2_2  = f0_2 * (int64_t) f2;
-  int64_t f0f3_2  = f0_2 * (int64_t) f3;
-  int64_t f0f4_2  = f0_2 * (int64_t) f4;
-  int64_t f0f5_2  = f0_2 * (int64_t) f5;
-  int64_t f0f6_2  = f0_2 * (int64_t) f6;
-  int64_t f0f7_2  = f0_2 * (int64_t) f7;
-  int64_t f0f8_2  = f0_2 * (int64_t) f8;
-  int64_t f0f9_2  = f0_2 * (int64_t) f9;
-  int64_t f1f1_2  = f1_2 * (int64_t) f1;
-  int64_t f1f2_2  = f1_2 * (int64_t) f2;
-  int64_t f1f3_4  = f1_2 * (int64_t) f3_2;
-  int64_t f1f4_2  = f1_2 * (int64_t) f4;
-  int64_t f1f5_4  = f1_2 * (int64_t) f5_2;
-  int64_t f1f6_2  = f1_2 * (int64_t) f6;
-  int64_t f1f7_4  = f1_2 * (int64_t) f7_2;
-  int64_t f1f8_2  = f1_2 * (int64_t) f8;
-  int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
-  int64_t f2f2    = f2   * (int64_t) f2;
-  int64_t f2f3_2  = f2_2 * (int64_t) f3;
-  int64_t f2f4_2  = f2_2 * (int64_t) f4;
-  int64_t f2f5_2  = f2_2 * (int64_t) f5;
-  int64_t f2f6_2  = f2_2 * (int64_t) f6;
-  int64_t f2f7_2  = f2_2 * (int64_t) f7;
-  int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
-  int64_t f2f9_38 = f2   * (int64_t) f9_38;
-  int64_t f3f3_2  = f3_2 * (int64_t) f3;
-  int64_t f3f4_2  = f3_2 * (int64_t) f4;
-  int64_t f3f5_4  = f3_2 * (int64_t) f5_2;
-  int64_t f3f6_2  = f3_2 * (int64_t) f6;
-  int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
-  int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
-  int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
-  int64_t f4f4    = f4   * (int64_t) f4;
-  int64_t f4f5_2  = f4_2 * (int64_t) f5;
-  int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
-  int64_t f4f7_38 = f4   * (int64_t) f7_38;
-  int64_t f4f8_38 = f4_2 * (int64_t) f8_19;
-  int64_t f4f9_38 = f4   * (int64_t) f9_38;
-  int64_t f5f5_38 = f5   * (int64_t) f5_38;
-  int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
-  int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
-  int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
-  int64_t f5f9_76 = f5_2 * (int64_t) f9_38;
-  int64_t f6f6_19 = f6   * (int64_t) f6_19;
-  int64_t f6f7_38 = f6   * (int64_t) f7_38;
-  int64_t f6f8_38 = f6_2 * (int64_t) f8_19;
-  int64_t f6f9_38 = f6   * (int64_t) f9_38;
-  int64_t f7f7_38 = f7   * (int64_t) f7_38;
-  int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
-  int64_t f7f9_76 = f7_2 * (int64_t) f9_38;
-  int64_t f8f8_19 = f8   * (int64_t) f8_19;
-  int64_t f8f9_38 = f8   * (int64_t) f9_38;
-  int64_t f9f9_38 = f9   * (int64_t) f9_38;
-  int64_t h0 = f0f0  +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
-  int64_t h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
-  int64_t h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
-  int64_t h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
-  int64_t h4 = f0f4_2+f1f3_4 +f2f2   +f5f9_76+f6f8_38+f7f7_38;
-  int64_t h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
-  int64_t h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
-  int64_t h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
-  int64_t h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4   +f9f9_38;
-  int64_t h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
-  int64_t carry0;
-  int64_t carry1;
-  int64_t carry2;
-  int64_t carry3;
-  int64_t carry4;
-  int64_t carry5;
-  int64_t carry6;
-  int64_t carry7;
-  int64_t carry8;
-  int64_t carry9;
-
-  h0 += h0;
-  h1 += h1;
-  h2 += h2;
-  h3 += h3;
-  h4 += h4;
-  h5 += h5;
-  h6 += h6;
-  h7 += h7;
-  h8 += h8;
-  h9 += h9;
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-
-  carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
-  carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
-
-  carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
-  carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
-
-  carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
-  carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
-
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-  carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
-
-  carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-
-  h[0] = h0;
-  h[1] = h1;
-  h[2] = h2;
-  h[3] = h3;
-  h[4] = h4;
-  h[5] = h5;
-  h[6] = h6;
-  h[7] = h7;
-  h[8] = h8;
-  h[9] = h9;
-}
-
-static void fe_pow22523(fe out, const fe z) {
-  fe t0;
-  fe t1;
-  fe t2;
-  int i;
-
-  fe_sq(t0, z);
-  fe_sq(t1, t0);
-  for (i = 1; i < 2; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(t1, z, t1);
-  fe_mul(t0, t0, t1);
-  fe_sq(t0, t0);
-  fe_mul(t0, t1, t0);
-  fe_sq(t1, t0);
-  for (i = 1; i < 5; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(t0, t1, t0);
-  fe_sq(t1, t0);
-  for (i = 1; i < 10; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(t1, t1, t0);
-  fe_sq(t2, t1);
-  for (i = 1; i < 20; ++i) {
-    fe_sq(t2, t2);
-  }
-  fe_mul(t1, t2, t1);
-  fe_sq(t1, t1);
-  for (i = 1; i < 10; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(t0, t1, t0);
-  fe_sq(t1, t0);
-  for (i = 1; i < 50; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(t1, t1, t0);
-  fe_sq(t2, t1);
-  for (i = 1; i < 100; ++i) {
-    fe_sq(t2, t2);
-  }
-  fe_mul(t1, t2, t1);
-  fe_sq(t1, t1);
-  for (i = 1; i < 50; ++i) {
-    fe_sq(t1, t1);
-  }
-  fe_mul(t0, t1, t0);
-  fe_sq(t0, t0);
-  for (i = 1; i < 2; ++i) {
-    fe_sq(t0, t0);
-  }
-  fe_mul(out, t0, z);
-}
-
-void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h) {
-  fe recip;
-  fe x;
-  fe y;
-
-  fe_invert(recip, h->Z);
-  fe_mul(x, h->X, recip);
-  fe_mul(y, h->Y, recip);
-  fe_tobytes(s, y);
-  s[31] ^= fe_isnegative(x) << 7;
-}
-
-static void ge_p3_tobytes(uint8_t *s, const ge_p3 *h) {
-  fe recip;
-  fe x;
-  fe y;
-
-  fe_invert(recip, h->Z);
-  fe_mul(x, h->X, recip);
-  fe_mul(y, h->Y, recip);
-  fe_tobytes(s, y);
-  s[31] ^= fe_isnegative(x) << 7;
-}
-
-static const fe d = {-10913610, 13857413, -15372611, 6949391,   114729,
-                     -8787816,  -6275908, -3247719,  -18696448, -12055116};
-
-static const fe sqrtm1 = {-32595792, -7943725,  9377950,  3500415, 12389472,
-                          -272473,   -25146209, -2005654, 326686,  11406482};
-
-int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s) {
-  fe u;
-  fe v;
-  fe v3;
-  fe vxx;
-  fe check;
-
-  fe_frombytes(h->Y, s);
-  fe_1(h->Z);
-  fe_sq(u, h->Y);
-  fe_mul(v, u, d);
-  fe_sub(u, u, h->Z);  // u = y^2-1
-  fe_add(v, v, h->Z);  // v = dy^2+1
-
-  fe_sq(v3, v);
-  fe_mul(v3, v3, v);  // v3 = v^3
-  fe_sq(h->X, v3);
-  fe_mul(h->X, h->X, v);
-  fe_mul(h->X, h->X, u);  // x = uv^7
-
-  fe_pow22523(h->X, h->X);  // x = (uv^7)^((q-5)/8)
-  fe_mul(h->X, h->X, v3);
-  fe_mul(h->X, h->X, u);  // x = uv^3(uv^7)^((q-5)/8)
-
-  fe_sq(vxx, h->X);
-  fe_mul(vxx, vxx, v);
-  fe_sub(check, vxx, u);  // vx^2-u
-  if (fe_isnonzero(check)) {
-    fe_add(check, vxx, u);  // vx^2+u
-    if (fe_isnonzero(check)) {
-      return -1;
-    }
-    fe_mul(h->X, h->X, sqrtm1);
-  }
-
-  if (fe_isnegative(h->X) != (s[31] >> 7)) {
-    fe_neg(h->X, h->X);
-  }
-
-  fe_mul(h->T, h->X, h->Y);
-  return 0;
-}
-
-static void ge_p2_0(ge_p2 *h) {
-  fe_0(h->X);
-  fe_1(h->Y);
-  fe_1(h->Z);
-}
-
-static void ge_p3_0(ge_p3 *h) {
-  fe_0(h->X);
-  fe_1(h->Y);
-  fe_1(h->Z);
-  fe_0(h->T);
-}
-
-static void ge_cached_0(ge_cached *h) {
-  fe_1(h->YplusX);
-  fe_1(h->YminusX);
-  fe_1(h->Z);
-  fe_0(h->T2d);
-}
-
-static void ge_precomp_0(ge_precomp *h) {
-  fe_1(h->yplusx);
-  fe_1(h->yminusx);
-  fe_0(h->xy2d);
-}
-
-// r = p
-static void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) {
-  fe_copy(r->X, p->X);
-  fe_copy(r->Y, p->Y);
-  fe_copy(r->Z, p->Z);
-}
-
-static const fe d2 = {-21827239, -5839606,  -30745221, 13898782, 229458,
-                      15978800,  -12551817, -6495438,  29715968, 9444199};
-
-// r = p
-void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p) {
-  fe_add(r->YplusX, p->Y, p->X);
-  fe_sub(r->YminusX, p->Y, p->X);
-  fe_copy(r->Z, p->Z);
-  fe_mul(r->T2d, p->T, d2);
-}
-
-// r = p
-void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) {
-  fe_mul(r->X, p->X, p->T);
-  fe_mul(r->Y, p->Y, p->Z);
-  fe_mul(r->Z, p->Z, p->T);
-}
-
-// r = p
-void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) {
-  fe_mul(r->X, p->X, p->T);
-  fe_mul(r->Y, p->Y, p->Z);
-  fe_mul(r->Z, p->Z, p->T);
-  fe_mul(r->T, p->X, p->Y);
-}
-
-// r = p
-static void ge_p1p1_to_cached(ge_cached *r, const ge_p1p1 *p) {
-  ge_p3 t;
-  x25519_ge_p1p1_to_p3(&t, p);
-  x25519_ge_p3_to_cached(r, &t);
-}
-
-// r = 2 * p
-static void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) {
-  fe t0;
-
-  fe_sq(r->X, p->X);
-  fe_sq(r->Z, p->Y);
-  fe_sq2(r->T, p->Z);
-  fe_add(r->Y, p->X, p->Y);
-  fe_sq(t0, r->Y);
-  fe_add(r->Y, r->Z, r->X);
-  fe_sub(r->Z, r->Z, r->X);
-  fe_sub(r->X, t0, r->Y);
-  fe_sub(r->T, r->T, r->Z);
-}
-
-// r = 2 * p
-static void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
-  ge_p2 q;
-  ge_p3_to_p2(&q, p);
-  ge_p2_dbl(r, &q);
-}
-
-// r = p + q
-static void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
-  fe t0;
-
-  fe_add(r->X, p->Y, p->X);
-  fe_sub(r->Y, p->Y, p->X);
-  fe_mul(r->Z, r->X, q->yplusx);
-  fe_mul(r->Y, r->Y, q->yminusx);
-  fe_mul(r->T, q->xy2d, p->T);
-  fe_add(t0, p->Z, p->Z);
-  fe_sub(r->X, r->Z, r->Y);
-  fe_add(r->Y, r->Z, r->Y);
-  fe_add(r->Z, t0, r->T);
-  fe_sub(r->T, t0, r->T);
-}
-
-// r = p - q
-static void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
-  fe t0;
-
-  fe_add(r->X, p->Y, p->X);
-  fe_sub(r->Y, p->Y, p->X);
-  fe_mul(r->Z, r->X, q->yminusx);
-  fe_mul(r->Y, r->Y, q->yplusx);
-  fe_mul(r->T, q->xy2d, p->T);
-  fe_add(t0, p->Z, p->Z);
-  fe_sub(r->X, r->Z, r->Y);
-  fe_add(r->Y, r->Z, r->Y);
-  fe_sub(r->Z, t0, r->T);
-  fe_add(r->T, t0, r->T);
-}
-
-// r = p + q
-void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
-  fe t0;
-
-  fe_add(r->X, p->Y, p->X);
-  fe_sub(r->Y, p->Y, p->X);
-  fe_mul(r->Z, r->X, q->YplusX);
-  fe_mul(r->Y, r->Y, q->YminusX);
-  fe_mul(r->T, q->T2d, p->T);
-  fe_mul(r->X, p->Z, q->Z);
-  fe_add(t0, r->X, r->X);
-  fe_sub(r->X, r->Z, r->Y);
-  fe_add(r->Y, r->Z, r->Y);
-  fe_add(r->Z, t0, r->T);
-  fe_sub(r->T, t0, r->T);
-}
-
-// r = p - q
-void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
-  fe t0;
-
-  fe_add(r->X, p->Y, p->X);
-  fe_sub(r->Y, p->Y, p->X);
-  fe_mul(r->Z, r->X, q->YminusX);
-  fe_mul(r->Y, r->Y, q->YplusX);
-  fe_mul(r->T, q->T2d, p->T);
-  fe_mul(r->X, p->Z, q->Z);
-  fe_add(t0, r->X, r->X);
-  fe_sub(r->X, r->Z, r->Y);
-  fe_add(r->Y, r->Z, r->Y);
-  fe_sub(r->Z, t0, r->T);
-  fe_add(r->T, t0, r->T);
-}
-
-static uint8_t equal(signed char b, signed char c) {
-  uint8_t ub = b;
-  uint8_t uc = c;
-  uint8_t x = ub ^ uc;  // 0: yes; 1..255: no
-  uint32_t y = x;       // 0: yes; 1..255: no
-  y -= 1;               // 4294967295: yes; 0..254: no
-  y >>= 31;             // 1: yes; 0: no
-  return y;
-}
-
-static void cmov(ge_precomp *t, const ge_precomp *u, uint8_t b) {
-  fe_cmov(t->yplusx, u->yplusx, b);
-  fe_cmov(t->yminusx, u->yminusx, b);
-  fe_cmov(t->xy2d, u->xy2d, b);
-}
-
-void x25519_ge_scalarmult_small_precomp(
-    ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]) {
-  // precomp_table is first expanded into matching |ge_precomp|
-  // elements.
-  ge_precomp multiples[15];
-
-  unsigned i;
-  for (i = 0; i < 15; i++) {
-    const uint8_t *bytes = &precomp_table[i*(2 * 32)];
-    fe x, y;
-    fe_frombytes(x, bytes);
-    fe_frombytes(y, bytes + 32);
-
-    ge_precomp *out = &multiples[i];
-    fe_add(out->yplusx, y, x);
-    fe_sub(out->yminusx, y, x);
-    fe_mul(out->xy2d, x, y);
-    fe_mul(out->xy2d, out->xy2d, d2);
-  }
-
-  // See the comment above |k25519SmallPrecomp| about the structure of the
-  // precomputed elements. This loop does 64 additions and 64 doublings to
-  // calculate the result.
-  ge_p3_0(h);
-
-  for (i = 63; i < 64; i--) {
-    unsigned j;
-    signed char index = 0;
-
-    for (j = 0; j < 4; j++) {
-      const uint8_t bit = 1 & (a[(8 * j) + (i / 8)] >> (i & 7));
-      index |= (bit << j);
-    }
-
-    ge_precomp e;
-    ge_precomp_0(&e);
-
-    for (j = 1; j < 16; j++) {
-      cmov(&e, &multiples[j-1], equal(index, j));
-    }
-
-    ge_cached cached;
-    ge_p1p1 r;
-    x25519_ge_p3_to_cached(&cached, h);
-    x25519_ge_add(&r, h, &cached);
-    x25519_ge_p1p1_to_p3(h, &r);
-
-    ge_madd(&r, h, &e);
-    x25519_ge_p1p1_to_p3(h, &r);
-  }
-}
-
-#if defined(OPENSSL_SMALL)
-
-// This block of code replaces the standard base-point table with a much smaller
-// one. The standard table is 30,720 bytes while this one is just 960.
-//
-// This table contains 15 pairs of group elements, (x, y), where each field
-// element is serialised with |fe_tobytes|. If |i| is the index of the group
-// element then consider i+1 as a four-bit number: (i₀, i₁, i₂, i₃) (where i₀
-// is the most significant bit). The value of the group element is then:
-// (i₀×2^192 + i₁×2^128 + i₂×2^64 + i₃)G, where G is the generator.
-static const uint8_t k25519SmallPrecomp[15 * 2 * 32] = {
-    0x1a, 0xd5, 0x25, 0x8f, 0x60, 0x2d, 0x56, 0xc9, 0xb2, 0xa7, 0x25, 0x95,
-    0x60, 0xc7, 0x2c, 0x69, 0x5c, 0xdc, 0xd6, 0xfd, 0x31, 0xe2, 0xa4, 0xc0,
-    0xfe, 0x53, 0x6e, 0xcd, 0xd3, 0x36, 0x69, 0x21, 0x58, 0x66, 0x66, 0x66,
-    0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
-    0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
-    0x66, 0x66, 0x66, 0x66, 0x02, 0xa2, 0xed, 0xf4, 0x8f, 0x6b, 0x0b, 0x3e,
-    0xeb, 0x35, 0x1a, 0xd5, 0x7e, 0xdb, 0x78, 0x00, 0x96, 0x8a, 0xa0, 0xb4,
-    0xcf, 0x60, 0x4b, 0xd4, 0xd5, 0xf9, 0x2d, 0xbf, 0x88, 0xbd, 0x22, 0x62,
-    0x13, 0x53, 0xe4, 0x82, 0x57, 0xfa, 0x1e, 0x8f, 0x06, 0x2b, 0x90, 0xba,
-    0x08, 0xb6, 0x10, 0x54, 0x4f, 0x7c, 0x1b, 0x26, 0xed, 0xda, 0x6b, 0xdd,
-    0x25, 0xd0, 0x4e, 0xea, 0x42, 0xbb, 0x25, 0x03, 0xa2, 0xfb, 0xcc, 0x61,
-    0x67, 0x06, 0x70, 0x1a, 0xc4, 0x78, 0x3a, 0xff, 0x32, 0x62, 0xdd, 0x2c,
-    0xab, 0x50, 0x19, 0x3b, 0xf2, 0x9b, 0x7d, 0xb8, 0xfd, 0x4f, 0x29, 0x9c,
-    0xa7, 0x91, 0xba, 0x0e, 0x46, 0x5e, 0x51, 0xfe, 0x1d, 0xbf, 0xe5, 0xe5,
-    0x9b, 0x95, 0x0d, 0x67, 0xf8, 0xd1, 0xb5, 0x5a, 0xa1, 0x93, 0x2c, 0xc3,
-    0xde, 0x0e, 0x97, 0x85, 0x2d, 0x7f, 0xea, 0xab, 0x3e, 0x47, 0x30, 0x18,
-    0x24, 0xe8, 0xb7, 0x60, 0xae, 0x47, 0x80, 0xfc, 0xe5, 0x23, 0xe7, 0xc2,
-    0xc9, 0x85, 0xe6, 0x98, 0xa0, 0x29, 0x4e, 0xe1, 0x84, 0x39, 0x2d, 0x95,
-    0x2c, 0xf3, 0x45, 0x3c, 0xff, 0xaf, 0x27, 0x4c, 0x6b, 0xa6, 0xf5, 0x4b,
-    0x11, 0xbd, 0xba, 0x5b, 0x9e, 0xc4, 0xa4, 0x51, 0x1e, 0xbe, 0xd0, 0x90,
-    0x3a, 0x9c, 0xc2, 0x26, 0xb6, 0x1e, 0xf1, 0x95, 0x7d, 0xc8, 0x6d, 0x52,
-    0xe6, 0x99, 0x2c, 0x5f, 0x9a, 0x96, 0x0c, 0x68, 0x29, 0xfd, 0xe2, 0xfb,
-    0xe6, 0xbc, 0xec, 0x31, 0x08, 0xec, 0xe6, 0xb0, 0x53, 0x60, 0xc3, 0x8c,
-    0xbe, 0xc1, 0xb3, 0x8a, 0x8f, 0xe4, 0x88, 0x2b, 0x55, 0xe5, 0x64, 0x6e,
-    0x9b, 0xd0, 0xaf, 0x7b, 0x64, 0x2a, 0x35, 0x25, 0x10, 0x52, 0xc5, 0x9e,
-    0x58, 0x11, 0x39, 0x36, 0x45, 0x51, 0xb8, 0x39, 0x93, 0xfc, 0x9d, 0x6a,
-    0xbe, 0x58, 0xcb, 0xa4, 0x0f, 0x51, 0x3c, 0x38, 0x05, 0xca, 0xab, 0x43,
-    0x63, 0x0e, 0xf3, 0x8b, 0x41, 0xa6, 0xf8, 0x9b, 0x53, 0x70, 0x80, 0x53,
-    0x86, 0x5e, 0x8f, 0xe3, 0xc3, 0x0d, 0x18, 0xc8, 0x4b, 0x34, 0x1f, 0xd8,
-    0x1d, 0xbc, 0xf2, 0x6d, 0x34, 0x3a, 0xbe, 0xdf, 0xd9, 0xf6, 0xf3, 0x89,
-    0xa1, 0xe1, 0x94, 0x9f, 0x5d, 0x4c, 0x5d, 0xe9, 0xa1, 0x49, 0x92, 0xef,
-    0x0e, 0x53, 0x81, 0x89, 0x58, 0x87, 0xa6, 0x37, 0xf1, 0xdd, 0x62, 0x60,
-    0x63, 0x5a, 0x9d, 0x1b, 0x8c, 0xc6, 0x7d, 0x52, 0xea, 0x70, 0x09, 0x6a,
-    0xe1, 0x32, 0xf3, 0x73, 0x21, 0x1f, 0x07, 0x7b, 0x7c, 0x9b, 0x49, 0xd8,
-    0xc0, 0xf3, 0x25, 0x72, 0x6f, 0x9d, 0xed, 0x31, 0x67, 0x36, 0x36, 0x54,
-    0x40, 0x92, 0x71, 0xe6, 0x11, 0x28, 0x11, 0xad, 0x93, 0x32, 0x85, 0x7b,
-    0x3e, 0xb7, 0x3b, 0x49, 0x13, 0x1c, 0x07, 0xb0, 0x2e, 0x93, 0xaa, 0xfd,
-    0xfd, 0x28, 0x47, 0x3d, 0x8d, 0xd2, 0xda, 0xc7, 0x44, 0xd6, 0x7a, 0xdb,
-    0x26, 0x7d, 0x1d, 0xb8, 0xe1, 0xde, 0x9d, 0x7a, 0x7d, 0x17, 0x7e, 0x1c,
-    0x37, 0x04, 0x8d, 0x2d, 0x7c, 0x5e, 0x18, 0x38, 0x1e, 0xaf, 0xc7, 0x1b,
-    0x33, 0x48, 0x31, 0x00, 0x59, 0xf6, 0xf2, 0xca, 0x0f, 0x27, 0x1b, 0x63,
-    0x12, 0x7e, 0x02, 0x1d, 0x49, 0xc0, 0x5d, 0x79, 0x87, 0xef, 0x5e, 0x7a,
-    0x2f, 0x1f, 0x66, 0x55, 0xd8, 0x09, 0xd9, 0x61, 0x38, 0x68, 0xb0, 0x07,
-    0xa3, 0xfc, 0xcc, 0x85, 0x10, 0x7f, 0x4c, 0x65, 0x65, 0xb3, 0xfa, 0xfa,
-    0xa5, 0x53, 0x6f, 0xdb, 0x74, 0x4c, 0x56, 0x46, 0x03, 0xe2, 0xd5, 0x7a,
-    0x29, 0x1c, 0xc6, 0x02, 0xbc, 0x59, 0xf2, 0x04, 0x75, 0x63, 0xc0, 0x84,
-    0x2f, 0x60, 0x1c, 0x67, 0x76, 0xfd, 0x63, 0x86, 0xf3, 0xfa, 0xbf, 0xdc,
-    0xd2, 0x2d, 0x90, 0x91, 0xbd, 0x33, 0xa9, 0xe5, 0x66, 0x0c, 0xda, 0x42,
-    0x27, 0xca, 0xf4, 0x66, 0xc2, 0xec, 0x92, 0x14, 0x57, 0x06, 0x63, 0xd0,
-    0x4d, 0x15, 0x06, 0xeb, 0x69, 0x58, 0x4f, 0x77, 0xc5, 0x8b, 0xc7, 0xf0,
-    0x8e, 0xed, 0x64, 0xa0, 0xb3, 0x3c, 0x66, 0x71, 0xc6, 0x2d, 0xda, 0x0a,
-    0x0d, 0xfe, 0x70, 0x27, 0x64, 0xf8, 0x27, 0xfa, 0xf6, 0x5f, 0x30, 0xa5,
-    0x0d, 0x6c, 0xda, 0xf2, 0x62, 0x5e, 0x78, 0x47, 0xd3, 0x66, 0x00, 0x1c,
-    0xfd, 0x56, 0x1f, 0x5d, 0x3f, 0x6f, 0xf4, 0x4c, 0xd8, 0xfd, 0x0e, 0x27,
-    0xc9, 0x5c, 0x2b, 0xbc, 0xc0, 0xa4, 0xe7, 0x23, 0x29, 0x02, 0x9f, 0x31,
-    0xd6, 0xe9, 0xd7, 0x96, 0xf4, 0xe0, 0x5e, 0x0b, 0x0e, 0x13, 0xee, 0x3c,
-    0x09, 0xed, 0xf2, 0x3d, 0x76, 0x91, 0xc3, 0xa4, 0x97, 0xae, 0xd4, 0x87,
-    0xd0, 0x5d, 0xf6, 0x18, 0x47, 0x1f, 0x1d, 0x67, 0xf2, 0xcf, 0x63, 0xa0,
-    0x91, 0x27, 0xf8, 0x93, 0x45, 0x75, 0x23, 0x3f, 0xd1, 0xf1, 0xad, 0x23,
-    0xdd, 0x64, 0x93, 0x96, 0x41, 0x70, 0x7f, 0xf7, 0xf5, 0xa9, 0x89, 0xa2,
-    0x34, 0xb0, 0x8d, 0x1b, 0xae, 0x19, 0x15, 0x49, 0x58, 0x23, 0x6d, 0x87,
-    0x15, 0x4f, 0x81, 0x76, 0xfb, 0x23, 0xb5, 0xea, 0xcf, 0xac, 0x54, 0x8d,
-    0x4e, 0x42, 0x2f, 0xeb, 0x0f, 0x63, 0xdb, 0x68, 0x37, 0xa8, 0xcf, 0x8b,
-    0xab, 0xf5, 0xa4, 0x6e, 0x96, 0x2a, 0xb2, 0xd6, 0xbe, 0x9e, 0xbd, 0x0d,
-    0xb4, 0x42, 0xa9, 0xcf, 0x01, 0x83, 0x8a, 0x17, 0x47, 0x76, 0xc4, 0xc6,
-    0x83, 0x04, 0x95, 0x0b, 0xfc, 0x11, 0xc9, 0x62, 0xb8, 0x0c, 0x76, 0x84,
-    0xd9, 0xb9, 0x37, 0xfa, 0xfc, 0x7c, 0xc2, 0x6d, 0x58, 0x3e, 0xb3, 0x04,
-    0xbb, 0x8c, 0x8f, 0x48, 0xbc, 0x91, 0x27, 0xcc, 0xf9, 0xb7, 0x22, 0x19,
-    0x83, 0x2e, 0x09, 0xb5, 0x72, 0xd9, 0x54, 0x1c, 0x4d, 0xa1, 0xea, 0x0b,
-    0xf1, 0xc6, 0x08, 0x72, 0x46, 0x87, 0x7a, 0x6e, 0x80, 0x56, 0x0a, 0x8a,
-    0xc0, 0xdd, 0x11, 0x6b, 0xd6, 0xdd, 0x47, 0xdf, 0x10, 0xd9, 0xd8, 0xea,
-    0x7c, 0xb0, 0x8f, 0x03, 0x00, 0x2e, 0xc1, 0x8f, 0x44, 0xa8, 0xd3, 0x30,
-    0x06, 0x89, 0xa2, 0xf9, 0x34, 0xad, 0xdc, 0x03, 0x85, 0xed, 0x51, 0xa7,
-    0x82, 0x9c, 0xe7, 0x5d, 0x52, 0x93, 0x0c, 0x32, 0x9a, 0x5b, 0xe1, 0xaa,
-    0xca, 0xb8, 0x02, 0x6d, 0x3a, 0xd4, 0xb1, 0x3a, 0xf0, 0x5f, 0xbe, 0xb5,
-    0x0d, 0x10, 0x6b, 0x38, 0x32, 0xac, 0x76, 0x80, 0xbd, 0xca, 0x94, 0x71,
-    0x7a, 0xf2, 0xc9, 0x35, 0x2a, 0xde, 0x9f, 0x42, 0x49, 0x18, 0x01, 0xab,
-    0xbc, 0xef, 0x7c, 0x64, 0x3f, 0x58, 0x3d, 0x92, 0x59, 0xdb, 0x13, 0xdb,
-    0x58, 0x6e, 0x0a, 0xe0, 0xb7, 0x91, 0x4a, 0x08, 0x20, 0xd6, 0x2e, 0x3c,
-    0x45, 0xc9, 0x8b, 0x17, 0x79, 0xe7, 0xc7, 0x90, 0x99, 0x3a, 0x18, 0x25,
-};
-
-void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
-  x25519_ge_scalarmult_small_precomp(h, a, k25519SmallPrecomp);
-}
-
-#else
-
-// k25519Precomp[i][j] = (j+1)*256^i*B
-static const ge_precomp k25519Precomp[32][8] = {
-    {
-        {
-            {25967493, -14356035, 29566456, 3660896, -12694345, 4014787,
-             27544626, -11754271, -6079156, 2047605},
-            {-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692,
-             5043384, 19500929, -15469378},
-            {-8738181, 4489570, 9688441, -14785194, 10184609, -12363380,
-             29287919, 11864899, -24514362, -4438546},
-        },
-        {
-            {-12815894, -12976347, -21581243, 11784320, -25355658, -2750717,
-             -11717903, -3814571, -358445, -10211303},
-            {-21703237, 6903825, 27185491, 6451973, -29577724, -9554005,
-             -15616551, 11189268, -26829678, -5319081},
-            {26966642, 11152617, 32442495, 15396054, 14353839, -12752335,
-             -3128826, -9541118, -15472047, -4166697},
-        },
-        {
-            {15636291, -9688557, 24204773, -7912398, 616977, -16685262,
-             27787600, -14772189, 28944400, -1550024},
-            {16568933, 4717097, -11556148, -1102322, 15682896, -11807043,
-             16354577, -11775962, 7689662, 11199574},
-            {30464156, -5976125, -11779434, -15670865, 23220365, 15915852,
-             7512774, 10017326, -17749093, -9920357},
-        },
-        {
-            {-17036878, 13921892, 10945806, -6033431, 27105052, -16084379,
-             -28926210, 15006023, 3284568, -6276540},
-            {23599295, -8306047, -11193664, -7687416, 13236774, 10506355,
-             7464579, 9656445, 13059162, 10374397},
-            {7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664,
-             -3839045, -641708, -101325},
-        },
-        {
-            {10861363, 11473154, 27284546, 1981175, -30064349, 12577861,
-             32867885, 14515107, -15438304, 10819380},
-            {4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668,
-             12483688, -12668491, 5581306},
-            {19563160, 16186464, -29386857, 4097519, 10237984, -4348115,
-             28542350, 13850243, -23678021, -15815942},
-        },
-        {
-            {-15371964, -12862754, 32573250, 4720197, -26436522, 5875511,
-             -19188627, -15224819, -9818940, -12085777},
-            {-8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240,
-             -15689887, 1762328, 14866737},
-            {-18199695, -15951423, -10473290, 1707278, -17185920, 3916101,
-             -28236412, 3959421, 27914454, 4383652},
-        },
-        {
-            {5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852,
-             5230134, -23952439, -15175766},
-            {-30269007, -3463509, 7665486, 10083793, 28475525, 1649722,
-             20654025, 16520125, 30598449, 7715701},
-            {28881845, 14381568, 9657904, 3680757, -20181635, 7843316,
-             -31400660, 1370708, 29794553, -1409300},
-        },
-        {
-            {14499471, -2729599, -33191113, -4254652, 28494862, 14271267,
-             30290735, 10876454, -33154098, 2381726},
-            {-7195431, -2655363, -14730155, 462251, -27724326, 3941372,
-             -6236617, 3696005, -32300832, 15351955},
-            {27431194, 8222322, 16448760, -3907995, -18707002, 11938355,
-             -32961401, -2970515, 29551813, 10109425},
-        },
-    },
-    {
-        {
-            {-13657040, -13155431, -31283750, 11777098, 21447386, 6519384,
-             -2378284, -1627556, 10092783, -4764171},
-            {27939166, 14210322, 4677035, 16277044, -22964462, -12398139,
-             -32508754, 12005538, -17810127, 12803510},
-            {17228999, -15661624, -1233527, 300140, -1224870, -11714777,
-             30364213, -9038194, 18016357, 4397660},
-        },
-        {
-            {-10958843, -7690207, 4776341, -14954238, 27850028, -15602212,
-             -26619106, 14544525, -17477504, 982639},
-            {29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899,
-             -4120128, -21047696, 9934963},
-            {5793303, 16271923, -24131614, -10116404, 29188560, 1206517,
-             -14747930, 4559895, -30123922, -10897950},
-        },
-        {
-            {-27643952, -11493006, 16282657, -11036493, 28414021, -15012264,
-             24191034, 4541697, -13338309, 5500568},
-            {12650548, -1497113, 9052871, 11355358, -17680037, -8400164,
-             -17430592, 12264343, 10874051, 13524335},
-            {25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038,
-             5080568, -22528059, 5376628},
-        },
-        {
-            {-26088264, -4011052, -17013699, -3537628, -6726793, 1920897,
-             -22321305, -9447443, 4535768, 1569007},
-            {-2255422, 14606630, -21692440, -8039818, 28430649, 8775819,
-             -30494562, 3044290, 31848280, 12543772},
-            {-22028579, 2943893, -31857513, 6777306, 13784462, -4292203,
-             -27377195, -2062731, 7718482, 14474653},
-        },
-        {
-            {2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965,
-             -7236665, 24316168, -5253567},
-            {13741529, 10911568, -33233417, -8603737, -20177830, -1033297,
-             33040651, -13424532, -20729456, 8321686},
-            {21060490, -2212744, 15712757, -4336099, 1639040, 10656336,
-             23845965, -11874838, -9984458, 608372},
-        },
-        {
-            {-13672732, -15087586, -10889693, -7557059, -6036909, 11305547,
-             1123968, -6780577, 27229399, 23887},
-            {-23244140, -294205, -11744728, 14712571, -29465699, -2029617,
-             12797024, -6440308, -1633405, 16678954},
-            {-29500620, 4770662, -16054387, 14001338, 7830047, 9564805,
-             -1508144, -4795045, -17169265, 4904953},
-        },
-        {
-            {24059557, 14617003, 19037157, -15039908, 19766093, -14906429,
-             5169211, 16191880, 2128236, -4326833},
-            {-16981152, 4124966, -8540610, -10653797, 30336522, -14105247,
-             -29806336, 916033, -6882542, -2986532},
-            {-22630907, 12419372, -7134229, -7473371, -16478904, 16739175,
-             285431, 2763829, 15736322, 4143876},
-        },
-        {
-            {2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801,
-             -14594663, 23527084, -16458268},
-            {33431127, -11130478, -17838966, -15626900, 8909499, 8376530,
-             -32625340, 4087881, -15188911, -14416214},
-            {1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055,
-             4357868, -4774191, -16323038},
-        },
-    },
-    {
-        {
-            {6721966, 13833823, -23523388, -1551314, 26354293, -11863321,
-             23365147, -3949732, 7390890, 2759800},
-            {4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353,
-             -4264057, 1244380, -12919645},
-            {-4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413,
-             9208236, 15886429, 16489664},
-        },
-        {
-            {1996075, 10375649, 14346367, 13311202, -6874135, -16438411,
-             -13693198, 398369, -30606455, -712933},
-            {-25307465, 9795880, -2777414, 14878809, -33531835, 14780363,
-             13348553, 12076947, -30836462, 5113182},
-            {-17770784, 11797796, 31950843, 13929123, -25888302, 12288344,
-             -30341101, -7336386, 13847711, 5387222},
-        },
-        {
-            {-18582163, -3416217, 17824843, -2340966, 22744343, -10442611,
-             8763061, 3617786, -19600662, 10370991},
-            {20246567, -14369378, 22358229, -543712, 18507283, -10413996,
-             14554437, -8746092, 32232924, 16763880},
-            {9648505, 10094563, 26416693, 14745928, -30374318, -6472621,
-             11094161, 15689506, 3140038, -16510092},
-        },
-        {
-            {-16160072, 5472695, 31895588, 4744994, 8823515, 10365685,
-             -27224800, 9448613, -28774454, 366295},
-            {19153450, 11523972, -11096490, -6503142, -24647631, 5420647,
-             28344573, 8041113, 719605, 11671788},
-            {8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916,
-             -15266516, 27000813, -10195553},
-        },
-        {
-            {-15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065,
-             5336097, 6750977, -14521026},
-            {11836410, -3979488, 26297894, 16080799, 23455045, 15735944,
-             1695823, -8819122, 8169720, 16220347},
-            {-18115838, 8653647, 17578566, -6092619, -8025777, -16012763,
-             -11144307, -2627664, -5990708, -14166033},
-        },
-        {
-            {-23308498, -10968312, 15213228, -10081214, -30853605, -11050004,
-             27884329, 2847284, 2655861, 1738395},
-            {-27537433, -14253021, -25336301, -8002780, -9370762, 8129821,
-             21651608, -3239336, -19087449, -11005278},
-            {1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092,
-             5821408, 10478196, 8544890},
-        },
-        {
-            {32173121, -16129311, 24896207, 3921497, 22579056, -3410854,
-             19270449, 12217473, 17789017, -3395995},
-            {-30552961, -2228401, -15578829, -10147201, 13243889, 517024,
-             15479401, -3853233, 30460520, 1052596},
-            {-11614875, 13323618, 32618793, 8175907, -15230173, 12596687,
-             27491595, -4612359, 3179268, -9478891},
-        },
-        {
-            {31947069, -14366651, -4640583, -15339921, -15125977, -6039709,
-             -14756777, -16411740, 19072640, -9511060},
-            {11685058, 11822410, 3158003, -13952594, 33402194, -4165066,
-             5977896, -5215017, 473099, 5040608},
-            {-20290863, 8198642, -27410132, 11602123, 1290375, -2799760,
-             28326862, 1721092, -19558642, -3131606},
-        },
-    },
-    {
-        {
-            {7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786,
-             8076149, -27868496, 11538389},
-            {-19935666, 3899861, 18283497, -6801568, -15728660, -11249211,
-             8754525, 7446702, -5676054, 5797016},
-            {-11295600, -3793569, -15782110, -7964573, 12708869, -8456199,
-             2014099, -9050574, -2369172, -5877341},
-        },
-        {
-            {-22472376, -11568741, -27682020, 1146375, 18956691, 16640559,
-             1192730, -3714199, 15123619, 10811505},
-            {14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363,
-             15776356, -28886779, -11974553},
-            {-28241164, -8072475, -4978962, -5315317, 29416931, 1847569,
-             -20654173, -16484855, 4714547, -9600655},
-        },
-        {
-            {15200332, 8368572, 19679101, 15970074, -31872674, 1959451,
-             24611599, -4543832, -11745876, 12340220},
-            {12876937, -10480056, 33134381, 6590940, -6307776, 14872440,
-             9613953, 8241152, 15370987, 9608631},
-            {-4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868,
-             15866074, -28210621, -8814099},
-        },
-        {
-            {26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233,
-             858697, 20571223, 8420556},
-            {14620715, 13067227, -15447274, 8264467, 14106269, 15080814,
-             33531827, 12516406, -21574435, -12476749},
-            {236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519,
-             7256740, 8791136, 15069930},
-        },
-        {
-            {1276410, -9371918, 22949635, -16322807, -23493039, -5702186,
-             14711875, 4874229, -30663140, -2331391},
-            {5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175,
-             -7912378, -33069337, 9234253},
-            {20590503, -9018988, 31529744, -7352666, -2706834, 10650548,
-             31559055, -11609587, 18979186, 13396066},
-        },
-        {
-            {24474287, 4968103, 22267082, 4407354, 24063882, -8325180,
-             -18816887, 13594782, 33514650, 7021958},
-            {-11566906, -6565505, -21365085, 15928892, -26158305, 4315421,
-             -25948728, -3916677, -21480480, 12868082},
-            {-28635013, 13504661, 19988037, -2132761, 21078225, 6443208,
-             -21446107, 2244500, -12455797, -8089383},
-        },
-        {
-            {-30595528, 13793479, -5852820, 319136, -25723172, -6263899,
-             33086546, 8957937, -15233648, 5540521},
-            {-11630176, -11503902, -8119500, -7643073, 2620056, 1022908,
-             -23710744, -1568984, -16128528, -14962807},
-            {23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819,
-             892185, -11513277, -15205948},
-        },
-        {
-            {9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819,
-             4763127, -19179614, 5867134},
-            {-32765025, 1927590, 31726409, -4753295, 23962434, -16019500,
-             27846559, 5931263, -29749703, -16108455},
-            {27461885, -2977536, 22380810, 1815854, -23033753, -3031938,
-             7283490, -15148073, -19526700, 7734629},
-        },
-    },
-    {
-        {
-            {-8010264, -9590817, -11120403, 6196038, 29344158, -13430885,
-             7585295, -3176626, 18549497, 15302069},
-            {-32658337, -6171222, -7672793, -11051681, 6258878, 13504381,
-             10458790, -6418461, -8872242, 8424746},
-            {24687205, 8613276, -30667046, -3233545, 1863892, -1830544,
-             19206234, 7134917, -11284482, -828919},
-        },
-        {
-            {11334899, -9218022, 8025293, 12707519, 17523892, -10476071,
-             10243738, -14685461, -5066034, 16498837},
-            {8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925,
-             -14124238, 6536641, 10543906},
-            {-28946384, 15479763, -17466835, 568876, -1497683, 11223454,
-             -2669190, -16625574, -27235709, 8876771},
-        },
-        {
-            {-25742899, -12566864, -15649966, -846607, -33026686, -796288,
-             -33481822, 15824474, -604426, -9039817},
-            {10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697,
-             -4890037, 1657394, 3084098},
-            {10477963, -7470260, 12119566, -13250805, 29016247, -5365589,
-             31280319, 14396151, -30233575, 15272409},
-        },
-        {
-            {-12288309, 3169463, 28813183, 16658753, 25116432, -5630466,
-             -25173957, -12636138, -25014757, 1950504},
-            {-26180358, 9489187, 11053416, -14746161, -31053720, 5825630,
-             -8384306, -8767532, 15341279, 8373727},
-            {28685821, 7759505, -14378516, -12002860, -31971820, 4079242,
-             298136, -10232602, -2878207, 15190420},
-        },
-        {
-            {-32932876, 13806336, -14337485, -15794431, -24004620, 10940928,
-             8669718, 2742393, -26033313, -6875003},
-            {-1580388, -11729417, -25979658, -11445023, -17411874, -10912854,
-             9291594, -16247779, -12154742, 6048605},
-            {-30305315, 14843444, 1539301, 11864366, 20201677, 1900163,
-             13934231, 5128323, 11213262, 9168384},
-        },
-        {
-            {-26280513, 11007847, 19408960, -940758, -18592965, -4328580,
-             -5088060, -11105150, 20470157, -16398701},
-            {-23136053, 9282192, 14855179, -15390078, -7362815, -14408560,
-             -22783952, 14461608, 14042978, 5230683},
-            {29969567, -2741594, -16711867, -8552442, 9175486, -2468974,
-             21556951, 3506042, -5933891, -12449708},
-        },
-        {
-            {-3144746, 8744661, 19704003, 4581278, -20430686, 6830683,
-             -21284170, 8971513, -28539189, 15326563},
-            {-19464629, 10110288, -17262528, -3503892, -23500387, 1355669,
-             -15523050, 15300988, -20514118, 9168260},
-            {-5353335, 4488613, -23803248, 16314347, 7780487, -15638939,
-             -28948358, 9601605, 33087103, -9011387},
-        },
-        {
-            {-19443170, -15512900, -20797467, -12445323, -29824447, 10229461,
-             -27444329, -15000531, -5996870, 15664672},
-            {23294591, -16632613, -22650781, -8470978, 27844204, 11461195,
-             13099750, -2460356, 18151676, 13417686},
-            {-24722913, -4176517, -31150679, 5988919, -26858785, 6685065,
-             1661597, -12551441, 15271676, -15452665},
-        },
-    },
-    {
-        {
-            {11433042, -13228665, 8239631, -5279517, -1985436, -725718,
-             -18698764, 2167544, -6921301, -13440182},
-            {-31436171, 15575146, 30436815, 12192228, -22463353, 9395379,
-             -9917708, -8638997, 12215110, 12028277},
-            {14098400, 6555944, 23007258, 5757252, -15427832, -12950502,
-             30123440, 4617780, -16900089, -655628},
-        },
-        {
-            {-4026201, -15240835, 11893168, 13718664, -14809462, 1847385,
-             -15819999, 10154009, 23973261, -12684474},
-            {-26531820, -3695990, -1908898, 2534301, -31870557, -16550355,
-             18341390, -11419951, 32013174, -10103539},
-            {-25479301, 10876443, -11771086, -14625140, -12369567, 1838104,
-             21911214, 6354752, 4425632, -837822},
-        },
-        {
-            {-10433389, -14612966, 22229858, -3091047, -13191166, 776729,
-             -17415375, -12020462, 4725005, 14044970},
-            {19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390,
-             -1411784, -19522291, -16109756},
-            {-24864089, 12986008, -10898878, -5558584, -11312371, -148526,
-             19541418, 8180106, 9282262, 10282508},
-        },
-        {
-            {-26205082, 4428547, -8661196, -13194263, 4098402, -14165257,
-             15522535, 8372215, 5542595, -10702683},
-            {-10562541, 14895633, 26814552, -16673850, -17480754, -2489360,
-             -2781891, 6993761, -18093885, 10114655},
-            {-20107055, -929418, 31422704, 10427861, -7110749, 6150669,
-             -29091755, -11529146, 25953725, -106158},
-        },
-        {
-            {-4234397, -8039292, -9119125, 3046000, 2101609, -12607294,
-             19390020, 6094296, -3315279, 12831125},
-            {-15998678, 7578152, 5310217, 14408357, -33548620, -224739,
-             31575954, 6326196, 7381791, -2421839},
-            {-20902779, 3296811, 24736065, -16328389, 18374254, 7318640,
-             6295303, 8082724, -15362489, 12339664},
-        },
-        {
-            {27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414,
-             15768922, 25091167, 14856294},
-            {-18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300,
-             -12695493, -22182473, -9012899},
-            {-11423429, -5421590, 11632845, 3405020, 30536730, -11674039,
-             -27260765, 13866390, 30146206, 9142070},
-        },
-        {
-            {3924129, -15307516, -13817122, -10054960, 12291820, -668366,
-             -27702774, 9326384, -8237858, 4171294},
-            {-15921940, 16037937, 6713787, 16606682, -21612135, 2790944,
-             26396185, 3731949, 345228, -5462949},
-            {-21327538, 13448259, 25284571, 1143661, 20614966, -8849387,
-             2031539, -12391231, -16253183, -13582083},
-        },
-        {
-            {31016211, -16722429, 26371392, -14451233, -5027349, 14854137,
-             17477601, 3842657, 28012650, -16405420},
-            {-5075835, 9368966, -8562079, -4600902, -15249953, 6970560,
-             -9189873, 16292057, -8867157, 3507940},
-            {29439664, 3537914, 23333589, 6997794, -17555561, -11018068,
-             -15209202, -15051267, -9164929, 6580396},
-        },
-    },
-    {
-        {
-            {-12185861, -7679788, 16438269, 10826160, -8696817, -6235611,
-             17860444, -9273846, -2095802, 9304567},
-            {20714564, -4336911, 29088195, 7406487, 11426967, -5095705,
-             14792667, -14608617, 5289421, -477127},
-            {-16665533, -10650790, -6160345, -13305760, 9192020, -1802462,
-             17271490, 12349094, 26939669, -3752294},
-        },
-        {
-            {-12889898, 9373458, 31595848, 16374215, 21471720, 13221525,
-             -27283495, -12348559, -3698806, 117887},
-            {22263325, -6560050, 3984570, -11174646, -15114008, -566785,
-             28311253, 5358056, -23319780, 541964},
-            {16259219, 3261970, 2309254, -15534474, -16885711, -4581916,
-             24134070, -16705829, -13337066, -13552195},
-        },
-        {
-            {9378160, -13140186, -22845982, -12745264, 28198281, -7244098,
-             -2399684, -717351, 690426, 14876244},
-            {24977353, -314384, -8223969, -13465086, 28432343, -1176353,
-             -13068804, -12297348, -22380984, 6618999},
-            {-1538174, 11685646, 12944378, 13682314, -24389511, -14413193,
-             8044829, -13817328, 32239829, -5652762},
-        },
-        {
-            {-18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647,
-             -10350059, 32779359, 5095274},
-            {-33008130, -5214506, -32264887, -3685216, 9460461, -9327423,
-             -24601656, 14506724, 21639561, -2630236},
-            {-16400943, -13112215, 25239338, 15531969, 3987758, -4499318,
-             -1289502, -6863535, 17874574, 558605},
-        },
-        {
-            {-13600129, 10240081, 9171883, 16131053, -20869254, 9599700,
-             33499487, 5080151, 2085892, 5119761},
-            {-22205145, -2519528, -16381601, 414691, -25019550, 2170430,
-             30634760, -8363614, -31999993, -5759884},
-            {-6845704, 15791202, 8550074, -1312654, 29928809, -12092256,
-             27534430, -7192145, -22351378, 12961482},
-        },
-        {
-            {-24492060, -9570771, 10368194, 11582341, -23397293, -2245287,
-             16533930, 8206996, -30194652, -5159638},
-            {-11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630,
-             7031275, 7589640, 8945490},
-            {-32152748, 8917967, 6661220, -11677616, -1192060, -15793393,
-             7251489, -11182180, 24099109, -14456170},
-        },
-        {
-            {5019558, -7907470, 4244127, -14714356, -26933272, 6453165,
-             -19118182, -13289025, -6231896, -10280736},
-            {10853594, 10721687, 26480089, 5861829, -22995819, 1972175,
-             -1866647, -10557898, -3363451, -6441124},
-            {-17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661,
-             -2008168, -13866408, 7421392},
-        },
-        {
-            {8139927, -6546497, 32257646, -5890546, 30375719, 1886181,
-             -21175108, 15441252, 28826358, -4123029},
-            {6267086, 9695052, 7709135, -16603597, -32869068, -1886135,
-             14795160, -7840124, 13746021, -1742048},
-            {28584902, 7787108, -6732942, -15050729, 22846041, -7571236,
-             -3181936, -363524, 4771362, -8419958},
-        },
-    },
-    {
-        {
-            {24949256, 6376279, -27466481, -8174608, -18646154, -9930606,
-             33543569, -12141695, 3569627, 11342593},
-            {26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886,
-             4608608, 7325975, -14801071},
-            {-11618399, -14554430, -24321212, 7655128, -1369274, 5214312,
-             -27400540, 10258390, -17646694, -8186692},
-        },
-        {
-            {11431204, 15823007, 26570245, 14329124, 18029990, 4796082,
-             -31446179, 15580664, 9280358, -3973687},
-            {-160783, -10326257, -22855316, -4304997, -20861367, -13621002,
-             -32810901, -11181622, -15545091, 4387441},
-            {-20799378, 12194512, 3937617, -5805892, -27154820, 9340370,
-             -24513992, 8548137, 20617071, -7482001},
-        },
-        {
-            {-938825, -3930586, -8714311, 16124718, 24603125, -6225393,
-             -13775352, -11875822, 24345683, 10325460},
-            {-19855277, -1568885, -22202708, 8714034, 14007766, 6928528,
-             16318175, -1010689, 4766743, 3552007},
-            {-21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514,
-             14481909, 10988822, -3994762},
-        },
-        {
-            {15564307, -14311570, 3101243, 5684148, 30446780, -8051356,
-             12677127, -6505343, -8295852, 13296005},
-            {-9442290, 6624296, -30298964, -11913677, -4670981, -2057379,
-             31521204, 9614054, -30000824, 12074674},
-            {4771191, -135239, 14290749, -13089852, 27992298, 14998318,
-             -1413936, -1556716, 29832613, -16391035},
-        },
-        {
-            {7064884, -7541174, -19161962, -5067537, -18891269, -2912736,
-             25825242, 5293297, -27122660, 13101590},
-            {-2298563, 2439670, -7466610, 1719965, -27267541, -16328445,
-             32512469, -5317593, -30356070, -4190957},
-            {-30006540, 10162316, -33180176, 3981723, -16482138, -13070044,
-             14413974, 9515896, 19568978, 9628812},
-        },
-        {
-            {33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894,
-             -6106839, -6291786, 3437740},
-            {-18978877, 3884493, 19469877, 12726490, 15913552, 13614290,
-             -22961733, 70104, 7463304, 4176122},
-            {-27124001, 10659917, 11482427, -16070381, 12771467, -6635117,
-             -32719404, -5322751, 24216882, 5944158},
-        },
-        {
-            {8894125, 7450974, -2664149, -9765752, -28080517, -12389115,
-             19345746, 14680796, 11632993, 5847885},
-            {26942781, -2315317, 9129564, -4906607, 26024105, 11769399,
-             -11518837, 6367194, -9727230, 4782140},
-            {19916461, -4828410, -22910704, -11414391, 25606324, -5972441,
-             33253853, 8220911, 6358847, -1873857},
-        },
-        {
-            {801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388,
-             -4480480, -13538503, 1387155},
-            {19646058, 5720633, -11416706, 12814209, 11607948, 12749789,
-             14147075, 15156355, -21866831, 11835260},
-            {19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523,
-             15467869, -26560550, 5052483},
-        },
-    },
-    {
-        {
-            {-3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123,
-             -12618185, 12228557, -7003677},
-            {32944382, 14922211, -22844894, 5188528, 21913450, -8719943,
-             4001465, 13238564, -6114803, 8653815},
-            {22865569, -4652735, 27603668, -12545395, 14348958, 8234005,
-             24808405, 5719875, 28483275, 2841751},
-        },
-        {
-            {-16420968, -1113305, -327719, -12107856, 21886282, -15552774,
-             -1887966, -315658, 19932058, -12739203},
-            {-11656086, 10087521, -8864888, -5536143, -19278573, -3055912,
-             3999228, 13239134, -4777469, -13910208},
-            {1382174, -11694719, 17266790, 9194690, -13324356, 9720081,
-             20403944, 11284705, -14013818, 3093230},
-        },
-        {
-            {16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424,
-             16271225, -24049421, -6691850},
-            {-21911077, -5927941, -4611316, -5560156, -31744103, -10785293,
-             24123614, 15193618, -21652117, -16739389},
-            {-9935934, -4289447, -25279823, 4372842, 2087473, 10399484,
-             31870908, 14690798, 17361620, 11864968},
-        },
-        {
-            {-11307610, 6210372, 13206574, 5806320, -29017692, -13967200,
-             -12331205, -7486601, -25578460, -16240689},
-            {14668462, -12270235, 26039039, 15305210, 25515617, 4542480,
-             10453892, 6577524, 9145645, -6443880},
-            {5974874, 3053895, -9433049, -10385191, -31865124, 3225009,
-             -7972642, 3936128, -5652273, -3050304},
-        },
-        {
-            {30625386, -4729400, -25555961, -12792866, -20484575, 7695099,
-             17097188, -16303496, -27999779, 1803632},
-            {-3553091, 9865099, -5228566, 4272701, -5673832, -16689700,
-             14911344, 12196514, -21405489, 7047412},
-            {20093277, 9920966, -11138194, -5343857, 13161587, 12044805,
-             -32856851, 4124601, -32343828, -10257566},
-        },
-        {
-            {-20788824, 14084654, -13531713, 7842147, 19119038, -13822605,
-             4752377, -8714640, -21679658, 2288038},
-            {-26819236, -3283715, 29965059, 3039786, -14473765, 2540457,
-             29457502, 14625692, -24819617, 12570232},
-            {-1063558, -11551823, 16920318, 12494842, 1278292, -5869109,
-             -21159943, -3498680, -11974704, 4724943},
-        },
-        {
-            {17960970, -11775534, -4140968, -9702530, -8876562, -1410617,
-             -12907383, -8659932, -29576300, 1903856},
-            {23134274, -14279132, -10681997, -1611936, 20684485, 15770816,
-             -12989750, 3190296, 26955097, 14109738},
-            {15308788, 5320727, -30113809, -14318877, 22902008, 7767164,
-             29425325, -11277562, 31960942, 11934971},
-        },
-        {
-            {-27395711, 8435796, 4109644, 12222639, -24627868, 14818669,
-             20638173, 4875028, 10491392, 1379718},
-            {-13159415, 9197841, 3875503, -8936108, -1383712, -5879801,
-             33518459, 16176658, 21432314, 12180697},
-            {-11787308, 11500838, 13787581, -13832590, -22430679, 10140205,
-             1465425, 12689540, -10301319, -13872883},
-        },
-    },
-    {
-        {
-            {5414091, -15386041, -21007664, 9643570, 12834970, 1186149,
-             -2622916, -1342231, 26128231, 6032912},
-            {-26337395, -13766162, 32496025, -13653919, 17847801, -12669156,
-             3604025, 8316894, -25875034, -10437358},
-            {3296484, 6223048, 24680646, -12246460, -23052020, 5903205,
-             -8862297, -4639164, 12376617, 3188849},
-        },
-        {
-            {29190488, -14659046, 27549113, -1183516, 3520066, -10697301,
-             32049515, -7309113, -16109234, -9852307},
-            {-14744486, -9309156, 735818, -598978, -20407687, -5057904,
-             25246078, -15795669, 18640741, -960977},
-            {-6928835, -16430795, 10361374, 5642961, 4910474, 12345252,
-             -31638386, -494430, 10530747, 1053335},
-        },
-        {
-            {-29265967, -14186805, -13538216, -12117373, -19457059, -10655384,
-             -31462369, -2948985, 24018831, 15026644},
-            {-22592535, -3145277, -2289276, 5953843, -13440189, 9425631,
-             25310643, 13003497, -2314791, -15145616},
-            {-27419985, -603321, -8043984, -1669117, -26092265, 13987819,
-             -27297622, 187899, -23166419, -2531735},
-        },
-        {
-            {-21744398, -13810475, 1844840, 5021428, -10434399, -15911473,
-             9716667, 16266922, -5070217, 726099},
-            {29370922, -6053998, 7334071, -15342259, 9385287, 2247707,
-             -13661962, -4839461, 30007388, -15823341},
-            {-936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109,
-             730663, 9835848, 4555336},
-        },
-        {
-            {-23376435, 1410446, -22253753, -12899614, 30867635, 15826977,
-             17693930, 544696, -11985298, 12422646},
-            {31117226, -12215734, -13502838, 6561947, -9876867, -12757670,
-             -5118685, -4096706, 29120153, 13924425},
-            {-17400879, -14233209, 19675799, -2734756, -11006962, -5858820,
-             -9383939, -11317700, 7240931, -237388},
-        },
-        {
-            {-31361739, -11346780, -15007447, -5856218, -22453340, -12152771,
-             1222336, 4389483, 3293637, -15551743},
-            {-16684801, -14444245, 11038544, 11054958, -13801175, -3338533,
-             -24319580, 7733547, 12796905, -6335822},
-            {-8759414, -10817836, -25418864, 10783769, -30615557, -9746811,
-             -28253339, 3647836, 3222231, -11160462},
-        },
-        {
-            {18606113, 1693100, -25448386, -15170272, 4112353, 10045021,
-             23603893, -2048234, -7550776, 2484985},
-            {9255317, -3131197, -12156162, -1004256, 13098013, -9214866,
-             16377220, -2102812, -19802075, -3034702},
-            {-22729289, 7496160, -5742199, 11329249, 19991973, -3347502,
-             -31718148, 9936966, -30097688, -10618797},
-        },
-        {
-            {21878590, -5001297, 4338336, 13643897, -3036865, 13160960,
-             19708896, 5415497, -7360503, -4109293},
-            {27736861, 10103576, 12500508, 8502413, -3413016, -9633558,
-             10436918, -1550276, -23659143, -8132100},
-            {19492550, -12104365, -29681976, -852630, -3208171, 12403437,
-             30066266, 8367329, 13243957, 8709688},
-        },
-    },
-    {
-        {
-            {12015105, 2801261, 28198131, 10151021, 24818120, -4743133,
-             -11194191, -5645734, 5150968, 7274186},
-            {2831366, -12492146, 1478975, 6122054, 23825128, -12733586,
-             31097299, 6083058, 31021603, -9793610},
-            {-2529932, -2229646, 445613, 10720828, -13849527, -11505937,
-             -23507731, 16354465, 15067285, -14147707},
-        },
-        {
-            {7840942, 14037873, -33364863, 15934016, -728213, -3642706,
-             21403988, 1057586, -19379462, -12403220},
-            {915865, -16469274, 15608285, -8789130, -24357026, 6060030,
-             -17371319, 8410997, -7220461, 16527025},
-            {32922597, -556987, 20336074, -16184568, 10903705, -5384487,
-             16957574, 52992, 23834301, 6588044},
-        },
-        {
-            {32752030, 11232950, 3381995, -8714866, 22652988, -10744103,
-             17159699, 16689107, -20314580, -1305992},
-            {-4689649, 9166776, -25710296, -10847306, 11576752, 12733943,
-             7924251, -2752281, 1976123, -7249027},
-            {21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041,
-             -3371252, 12331345, -8237197},
-        },
-        {
-            {8651614, -4477032, -16085636, -4996994, 13002507, 2950805,
-             29054427, -5106970, 10008136, -4667901},
-            {31486080, 15114593, -14261250, 12951354, 14369431, -7387845,
-             16347321, -13662089, 8684155, -10532952},
-            {19443825, 11385320, 24468943, -9659068, -23919258, 2187569,
-             -26263207, -6086921, 31316348, 14219878},
-        },
-        {
-            {-28594490, 1193785, 32245219, 11392485, 31092169, 15722801,
-             27146014, 6992409, 29126555, 9207390},
-            {32382935, 1110093, 18477781, 11028262, -27411763, -7548111,
-             -4980517, 10843782, -7957600, -14435730},
-            {2814918, 7836403, 27519878, -7868156, -20894015, -11553689,
-             -21494559, 8550130, 28346258, 1994730},
-        },
-        {
-            {-19578299, 8085545, -14000519, -3948622, 2785838, -16231307,
-             -19516951, 7174894, 22628102, 8115180},
-            {-30405132, 955511, -11133838, -15078069, -32447087, -13278079,
-             -25651578, 3317160, -9943017, 930272},
-            {-15303681, -6833769, 28856490, 1357446, 23421993, 1057177,
-             24091212, -1388970, -22765376, -10650715},
-        },
-        {
-            {-22751231, -5303997, -12907607, -12768866, -15811511, -7797053,
-             -14839018, -16554220, -1867018, 8398970},
-            {-31969310, 2106403, -4736360, 1362501, 12813763, 16200670,
-             22981545, -6291273, 18009408, -15772772},
-            {-17220923, -9545221, -27784654, 14166835, 29815394, 7444469,
-             29551787, -3727419, 19288549, 1325865},
-        },
-        {
-            {15100157, -15835752, -23923978, -1005098, -26450192, 15509408,
-             12376730, -3479146, 33166107, -8042750},
-            {20909231, 13023121, -9209752, 16251778, -5778415, -8094914,
-             12412151, 10018715, 2213263, -13878373},
-            {32529814, -11074689, 30361439, -16689753, -9135940, 1513226,
-             22922121, 6382134, -5766928, 8371348},
-        },
-    },
-    {
-        {
-            {9923462, 11271500, 12616794, 3544722, -29998368, -1721626,
-             12891687, -8193132, -26442943, 10486144},
-            {-22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726,
-             2610596, -23921530, -11455195},
-            {5408411, -1136691, -4969122, 10561668, 24145918, 14240566,
-             31319731, -4235541, 19985175, -3436086},
-        },
-        {
-            {-13994457, 16616821, 14549246, 3341099, 32155958, 13648976,
-             -17577068, 8849297, 65030, 8370684},
-            {-8320926, -12049626, 31204563, 5839400, -20627288, -1057277,
-             -19442942, 6922164, 12743482, -9800518},
-            {-2361371, 12678785, 28815050, 4759974, -23893047, 4884717,
-             23783145, 11038569, 18800704, 255233},
-        },
-        {
-            {-5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847,
-             9066957, 19258688, -14753793},
-            {-2936654, -10827535, -10432089, 14516793, -3640786, 4372541,
-             -31934921, 2209390, -1524053, 2055794},
-            {580882, 16705327, 5468415, -2683018, -30926419, -14696000,
-             -7203346, -8994389, -30021019, 7394435},
-        },
-        {
-            {23838809, 1822728, -15738443, 15242727, 8318092, -3733104,
-             -21672180, -3492205, -4821741, 14799921},
-            {13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804,
-             13496856, -9056018, 7402518},
-            {2286874, -4435931, -20042458, -2008336, -13696227, 5038122,
-             11006906, -15760352, 8205061, 1607563},
-        },
-        {
-            {14414086, -8002132, 3331830, -3208217, 22249151, -5594188,
-             18364661, -2906958, 30019587, -9029278},
-            {-27688051, 1585953, -10775053, 931069, -29120221, -11002319,
-             -14410829, 12029093, 9944378, 8024},
-            {4368715, -3709630, 29874200, -15022983, -20230386, -11410704,
-             -16114594, -999085, -8142388, 5640030},
-        },
-        {
-            {10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887,
-             -16694564, 15219798, -14327783},
-            {27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605,
-             -1173195, -18342183, 9742717},
-            {6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614,
-             7406442, 12420155, 1994844},
-        },
-        {
-            {14012521, -5024720, -18384453, -9578469, -26485342, -3936439,
-             -13033478, -10909803, 24319929, -6446333},
-            {16412690, -4507367, 10772641, 15929391, -17068788, -4658621,
-             10555945, -10484049, -30102368, -4739048},
-            {22397382, -7767684, -9293161, -12792868, 17166287, -9755136,
-             -27333065, 6199366, 21880021, -12250760},
-        },
-        {
-            {-4283307, 5368523, -31117018, 8163389, -30323063, 3209128,
-             16557151, 8890729, 8840445, 4957760},
-            {-15447727, 709327, -6919446, -10870178, -29777922, 6522332,
-             -21720181, 12130072, -14796503, 5005757},
-            {-2114751, -14308128, 23019042, 15765735, -25269683, 6002752,
-             10183197, -13239326, -16395286, -2176112},
-        },
-    },
-    {
-        {
-            {-19025756, 1632005, 13466291, -7995100, -23640451, 16573537,
-             -32013908, -3057104, 22208662, 2000468},
-            {3065073, -1412761, -25598674, -361432, -17683065, -5703415,
-             -8164212, 11248527, -3691214, -7414184},
-            {10379208, -6045554, 8877319, 1473647, -29291284, -12507580,
-             16690915, 2553332, -3132688, 16400289},
-        },
-        {
-            {15716668, 1254266, -18472690, 7446274, -8448918, 6344164,
-             -22097271, -7285580, 26894937, 9132066},
-            {24158887, 12938817, 11085297, -8177598, -28063478, -4457083,
-             -30576463, 64452, -6817084, -2692882},
-            {13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710,
-             -3418511, -4688006, 2364226},
-        },
-        {
-            {16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024,
-             -11697457, 15445875, -7798101},
-            {29004207, -7867081, 28661402, -640412, -12794003, -7943086,
-             31863255, -4135540, -278050, -15759279},
-            {-6122061, -14866665, -28614905, 14569919, -10857999, -3591829,
-             10343412, -6976290, -29828287, -10815811},
-        },
-        {
-            {27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636,
-             15372179, 17293797, 960709},
-            {20263915, 11434237, -5765435, 11236810, 13505955, -10857102,
-             -16111345, 6493122, -19384511, 7639714},
-            {-2830798, -14839232, 25403038, -8215196, -8317012, -16173699,
-             18006287, -16043750, 29994677, -15808121},
-        },
-        {
-            {9769828, 5202651, -24157398, -13631392, -28051003, -11561624,
-             -24613141, -13860782, -31184575, 709464},
-            {12286395, 13076066, -21775189, -1176622, -25003198, 4057652,
-             -32018128, -8890874, 16102007, 13205847},
-            {13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170,
-             8525972, 10151379, 10394400},
-        },
-        {
-            {4024660, -16137551, 22436262, 12276534, -9099015, -2686099,
-             19698229, 11743039, -33302334, 8934414},
-            {-15879800, -4525240, -8580747, -2934061, 14634845, -698278,
-             -9449077, 3137094, -11536886, 11721158},
-            {17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229,
-             8835153, -9205489, -1280045},
-        },
-        {
-            {-461409, -7830014, 20614118, 16688288, -7514766, -4807119,
-             22300304, 505429, 6108462, -6183415},
-            {-5070281, 12367917, -30663534, 3234473, 32617080, -8422642,
-             29880583, -13483331, -26898490, -7867459},
-            {-31975283, 5726539, 26934134, 10237677, -3173717, -605053,
-             24199304, 3795095, 7592688, -14992079},
-        },
-        {
-            {21594432, -14964228, 17466408, -4077222, 32537084, 2739898,
-             6407723, 12018833, -28256052, 4298412},
-            {-20650503, -11961496, -27236275, 570498, 3767144, -1717540,
-             13891942, -1569194, 13717174, 10805743},
-            {-14676630, -15644296, 15287174, 11927123, 24177847, -8175568,
-             -796431, 14860609, -26938930, -5863836},
-        },
-    },
-    {
-        {
-            {12962541, 5311799, -10060768, 11658280, 18855286, -7954201,
-             13286263, -12808704, -4381056, 9882022},
-            {18512079, 11319350, -20123124, 15090309, 18818594, 5271736,
-             -22727904, 3666879, -23967430, -3299429},
-            {-6789020, -3146043, 16192429, 13241070, 15898607, -14206114,
-             -10084880, -6661110, -2403099, 5276065},
-        },
-        {
-            {30169808, -5317648, 26306206, -11750859, 27814964, 7069267,
-             7152851, 3684982, 1449224, 13082861},
-            {10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382,
-             15056736, -21016438, -8202000},
-            {-33150110, 3261608, 22745853, 7948688, 19370557, -15177665,
-             -26171976, 6482814, -10300080, -11060101},
-        },
-        {
-            {32869458, -5408545, 25609743, 15678670, -10687769, -15471071,
-             26112421, 2521008, -22664288, 6904815},
-            {29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737,
-             3841096, -29003639, -6657642},
-            {10340844, -6630377, -18656632, -2278430, 12621151, -13339055,
-             30878497, -11824370, -25584551, 5181966},
-        },
-        {
-            {25940115, -12658025, 17324188, -10307374, -8671468, 15029094,
-             24396252, -16450922, -2322852, -12388574},
-            {-21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390,
-             12641087, 20603771, -6561742},
-            {-18882287, -11673380, 24849422, 11501709, 13161720, -4768874,
-             1925523, 11914390, 4662781, 7820689},
-        },
-        {
-            {12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456,
-             12172924, 16136752, 15264020},
-            {-10349955, -14680563, -8211979, 2330220, -17662549, -14545780,
-             10658213, 6671822, 19012087, 3772772},
-            {3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732,
-             -15762884, 20527771, 12988982},
-        },
-        {
-            {-14822485, -5797269, -3707987, 12689773, -898983, -10914866,
-             -24183046, -10564943, 3299665, -12424953},
-            {-16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197,
-             6461331, -25583147, 8991218},
-            {-17226263, 1816362, -1673288, -6086439, 31783888, -8175991,
-             -32948145, 7417950, -30242287, 1507265},
-        },
-        {
-            {29692663, 6829891, -10498800, 4334896, 20945975, -11906496,
-             -28887608, 8209391, 14606362, -10647073},
-            {-3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695,
-             9761487, 4170404, -2085325},
-            {-11587470, 14855945, -4127778, -1531857, -26649089, 15084046,
-             22186522, 16002000, -14276837, -8400798},
-        },
-        {
-            {-4811456, 13761029, -31703877, -2483919, -3312471, 7869047,
-             -7113572, -9620092, 13240845, 10965870},
-            {-7742563, -8256762, -14768334, -13656260, -23232383, 12387166,
-             4498947, 14147411, 29514390, 4302863},
-            {-13413405, -12407859, 20757302, -13801832, 14785143, 8976368,
-             -5061276, -2144373, 17846988, -13971927},
-        },
-    },
-    {
-        {
-            {-2244452, -754728, -4597030, -1066309, -6247172, 1455299,
-             -21647728, -9214789, -5222701, 12650267},
-            {-9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813,
-             13770293, -19134326, 10958663},
-            {22470984, 12369526, 23446014, -5441109, -21520802, -9698723,
-             -11772496, -11574455, -25083830, 4271862},
-        },
-        {
-            {-25169565, -10053642, -19909332, 15361595, -5984358, 2159192,
-             75375, -4278529, -32526221, 8469673},
-            {15854970, 4148314, -8893890, 7259002, 11666551, 13824734,
-             -30531198, 2697372, 24154791, -9460943},
-            {15446137, -15806644, 29759747, 14019369, 30811221, -9610191,
-             -31582008, 12840104, 24913809, 9815020},
-        },
-        {
-            {-4709286, -5614269, -31841498, -12288893, -14443537, 10799414,
-             -9103676, 13438769, 18735128, 9466238},
-            {11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821,
-             -10896103, -22728655, 16199064},
-            {14576810, 379472, -26786533, -8317236, -29426508, -10812974,
-             -102766, 1876699, 30801119, 2164795},
-        },
-        {
-            {15995086, 3199873, 13672555, 13712240, -19378835, -4647646,
-             -13081610, -15496269, -13492807, 1268052},
-            {-10290614, -3659039, -3286592, 10948818, 23037027, 3794475,
-             -3470338, -12600221, -17055369, 3565904},
-            {29210088, -9419337, -5919792, -4952785, 10834811, -13327726,
-             -16512102, -10820713, -27162222, -14030531},
-        },
-        {
-            {-13161890, 15508588, 16663704, -8156150, -28349942, 9019123,
-             -29183421, -3769423, 2244111, -14001979},
-            {-5152875, -3800936, -9306475, -6071583, 16243069, 14684434,
-             -25673088, -16180800, 13491506, 4641841},
-            {10813417, 643330, -19188515, -728916, 30292062, -16600078,
-             27548447, -7721242, 14476989, -12767431},
-        },
-        {
-            {10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937,
-             -1644259, -27912810, 12651324},
-            {-31185513, -813383, 22271204, 11835308, 10201545, 15351028,
-             17099662, 3988035, 21721536, -3148940},
-            {10202177, -6545839, -31373232, -9574638, -32150642, -8119683,
-             -12906320, 3852694, 13216206, 14842320},
-        },
-        {
-            {-15815640, -10601066, -6538952, -7258995, -6984659, -6581778,
-             -31500847, 13765824, -27434397, 9900184},
-            {14465505, -13833331, -32133984, -14738873, -27443187, 12990492,
-             33046193, 15796406, -7051866, -8040114},
-            {30924417, -8279620, 6359016, -12816335, 16508377, 9071735,
-             -25488601, 15413635, 9524356, -7018878},
-        },
-        {
-            {12274201, -13175547, 32627641, -1785326, 6736625, 13267305,
-             5237659, -5109483, 15663516, 4035784},
-            {-2951309, 8903985, 17349946, 601635, -16432815, -4612556,
-             -13732739, -15889334, -22258478, 4659091},
-            {-16916263, -4952973, -30393711, -15158821, 20774812, 15897498,
-             5736189, 15026997, -2178256, -13455585},
-        },
-    },
-    {
-        {
-            {-8858980, -2219056, 28571666, -10155518, -474467, -10105698,
-             -3801496, 278095, 23440562, -290208},
-            {10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275,
-             11551483, -16571960, -7442864},
-            {17932739, -12437276, -24039557, 10749060, 11316803, 7535897,
-             22503767, 5561594, -3646624, 3898661},
-        },
-        {
-            {7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531,
-             7152530, 21831162, 1245233},
-            {26958459, -14658026, 4314586, 8346991, -5677764, 11960072,
-             -32589295, -620035, -30402091, -16716212},
-            {-12165896, 9166947, 33491384, 13673479, 29787085, 13096535,
-             6280834, 14587357, -22338025, 13987525},
-        },
-        {
-            {-24349909, 7778775, 21116000, 15572597, -4833266, -5357778,
-             -4300898, -5124639, -7469781, -2858068},
-            {9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781,
-             6439245, -14581012, 4091397},
-            {-8426427, 1470727, -28109679, -1596990, 3978627, -5123623,
-             -19622683, 12092163, 29077877, -14741988},
-        },
-        {
-            {5269168, -6859726, -13230211, -8020715, 25932563, 1763552,
-             -5606110, -5505881, -20017847, 2357889},
-            {32264008, -15407652, -5387735, -1160093, -2091322, -3946900,
-             23104804, -12869908, 5727338, 189038},
-            {14609123, -8954470, -6000566, -16622781, -14577387, -7743898,
-             -26745169, 10942115, -25888931, -14884697},
-        },
-        {
-            {20513500, 5557931, -15604613, 7829531, 26413943, -2019404,
-             -21378968, 7471781, 13913677, -5137875},
-            {-25574376, 11967826, 29233242, 12948236, -6754465, 4713227,
-             -8940970, 14059180, 12878652, 8511905},
-            {-25656801, 3393631, -2955415, -7075526, -2250709, 9366908,
-             -30223418, 6812974, 5568676, -3127656},
-        },
-        {
-            {11630004, 12144454, 2116339, 13606037, 27378885, 15676917,
-             -17408753, -13504373, -14395196, 8070818},
-            {27117696, -10007378, -31282771, -5570088, 1127282, 12772488,
-             -29845906, 10483306, -11552749, -1028714},
-            {10637467, -5688064, 5674781, 1072708, -26343588, -6982302,
-             -1683975, 9177853, -27493162, 15431203},
-        },
-        {
-            {20525145, 10892566, -12742472, 12779443, -29493034, 16150075,
-             -28240519, 14943142, -15056790, -7935931},
-            {-30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767,
-             -3239766, -3356550, 9594024},
-            {-23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683,
-             -6492290, 13352335, -10977084},
-        },
-        {
-            {-1931799, -5407458, 3304649, -12884869, 17015806, -4877091,
-             -29783850, -7752482, -13215537, -319204},
-            {20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742,
-             15077870, -22750759, 14523817},
-            {27406042, -6041657, 27423596, -4497394, 4996214, 10002360,
-             -28842031, -4545494, -30172742, -4805667},
-        },
-    },
-    {
-        {
-            {11374242, 12660715, 17861383, -12540833, 10935568, 1099227,
-             -13886076, -9091740, -27727044, 11358504},
-            {-12730809, 10311867, 1510375, 10778093, -2119455, -9145702,
-             32676003, 11149336, -26123651, 4985768},
-            {-19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043,
-             13794114, -19414307, -15621255},
-        },
-        {
-            {6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603,
-             6970005, -1691065, -9004790},
-            {1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622,
-             -5475723, -16796596, -5031438},
-            {-22273315, -13524424, -64685, -4334223, -18605636, -10921968,
-             -20571065, -7007978, -99853, -10237333},
-        },
-        {
-            {17747465, 10039260, 19368299, -4050591, -20630635, -16041286,
-             31992683, -15857976, -29260363, -5511971},
-            {31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999,
-             -3744247, 4882242, -10626905},
-            {29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198,
-             3272828, -5190932, -4162409},
-        },
-        {
-            {12501286, 4044383, -8612957, -13392385, -32430052, 5136599,
-             -19230378, -3529697, 330070, -3659409},
-            {6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522,
-             -8573892, -271295, 12071499},
-            {-8365515, -4042521, 25133448, -4517355, -6211027, 2265927,
-             -32769618, 1936675, -5159697, 3829363},
-        },
-        {
-            {28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550,
-             -6567787, 26333140, 14267664},
-            {-11067219, 11871231, 27385719, -10559544, -4585914, -11189312,
-             10004786, -8709488, -21761224, 8930324},
-            {-21197785, -16396035, 25654216, -1725397, 12282012, 11008919,
-             1541940, 4757911, -26491501, -16408940},
-        },
-        {
-            {13537262, -7759490, -20604840, 10961927, -5922820, -13218065,
-             -13156584, 6217254, -15943699, 13814990},
-            {-17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681,
-             9257833, -1956526, -1776914},
-            {-25045300, -10191966, 15366585, 15166509, -13105086, 8423556,
-             -29171540, 12361135, -18685978, 4578290},
-        },
-        {
-            {24579768, 3711570, 1342322, -11180126, -27005135, 14124956,
-             -22544529, 14074919, 21964432, 8235257},
-            {-6528613, -2411497, 9442966, -5925588, 12025640, -1487420,
-             -2981514, -1669206, 13006806, 2355433},
-            {-16304899, -13605259, -6632427, -5142349, 16974359, -10911083,
-             27202044, 1719366, 1141648, -12796236},
-        },
-        {
-            {-12863944, -13219986, -8318266, -11018091, -6810145, -4843894,
-             13475066, -3133972, 32674895, 13715045},
-            {11423335, -5468059, 32344216, 8962751, 24989809, 9241752,
-             -13265253, 16086212, -28740881, -15642093},
-            {-1409668, 12530728, -6368726, 10847387, 19531186, -14132160,
-             -11709148, 7791794, -27245943, 4383347},
-        },
-    },
-    {
-        {
-            {-28970898, 5271447, -1266009, -9736989, -12455236, 16732599,
-             -4862407, -4906449, 27193557, 6245191},
-            {-15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898,
-             3260492, 22510453, 8577507},
-            {-12632451, 11257346, -32692994, 13548177, -721004, 10879011,
-             31168030, 13952092, -29571492, -3635906},
-        },
-        {
-            {3877321, -9572739, 32416692, 5405324, -11004407, -13656635,
-             3759769, 11935320, 5611860, 8164018},
-            {-16275802, 14667797, 15906460, 12155291, -22111149, -9039718,
-             32003002, -8832289, 5773085, -8422109},
-            {-23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725,
-             12376320, 31632953, 190926},
-        },
-        {
-            {-24593607, -16138885, -8423991, 13378746, 14162407, 6901328,
-             -8288749, 4508564, -25341555, -3627528},
-            {8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941,
-             -14786005, -1672488, 827625},
-            {-32720583, -16289296, -32503547, 7101210, 13354605, 2659080,
-             -1800575, -14108036, -24878478, 1541286},
-        },
-        {
-            {2901347, -1117687, 3880376, -10059388, -17620940, -3612781,
-             -21802117, -3567481, 20456845, -1885033},
-            {27019610, 12299467, -13658288, -1603234, -12861660, -4861471,
-             -19540150, -5016058, 29439641, 15138866},
-            {21536104, -6626420, -32447818, -10690208, -22408077, 5175814,
-             -5420040, -16361163, 7779328, 109896},
-        },
-        {
-            {30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390,
-             12180118, 23177719, -554075},
-            {26572847, 3405927, -31701700, 12890905, -19265668, 5335866,
-             -6493768, 2378492, 4439158, -13279347},
-            {-22716706, 3489070, -9225266, -332753, 18875722, -1140095,
-             14819434, -12731527, -17717757, -5461437},
-        },
-        {
-            {-5056483, 16566551, 15953661, 3767752, -10436499, 15627060,
-             -820954, 2177225, 8550082, -15114165},
-            {-18473302, 16596775, -381660, 15663611, 22860960, 15585581,
-             -27844109, -3582739, -23260460, -8428588},
-            {-32480551, 15707275, -8205912, -5652081, 29464558, 2713815,
-             -22725137, 15860482, -21902570, 1494193},
-        },
-        {
-            {-19562091, -14087393, -25583872, -9299552, 13127842, 759709,
-             21923482, 16529112, 8742704, 12967017},
-            {-28464899, 1553205, 32536856, -10473729, -24691605, -406174,
-             -8914625, -2933896, -29903758, 15553883},
-            {21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572,
-             14513274, 19375923, -12647961},
-        },
-        {
-            {8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818,
-             -6222716, 2862653, 9455043},
-            {29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124,
-             -2990080, 15511449, 4789663},
-            {-20679756, 7004547, 8824831, -9434977, -4045704, -3750736,
-             -5754762, 108893, 23513200, 16652362},
-        },
-    },
-    {
-        {
-            {-33256173, 4144782, -4476029, -6579123, 10770039, -7155542,
-             -6650416, -12936300, -18319198, 10212860},
-            {2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801,
-             2600940, -9988298, -12506466},
-            {-24645692, 13317462, -30449259, -15653928, 21365574, -10869657,
-             11344424, 864440, -2499677, -16710063},
-        },
-        {
-            {-26432803, 6148329, -17184412, -14474154, 18782929, -275997,
-             -22561534, 211300, 2719757, 4940997},
-            {-1323882, 3911313, -6948744, 14759765, -30027150, 7851207,
-             21690126, 8518463, 26699843, 5276295},
-            {-13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586,
-             149635, -15452774, 7159369},
-        },
-        {
-            {9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009,
-             8312176, 22477218, -8403385},
-            {18155857, -16504990, 19744716, 9006923, 15154154, -10538976,
-             24256460, -4864995, -22548173, 9334109},
-            {2986088, -4911893, 10776628, -3473844, 10620590, -7083203,
-             -21413845, 14253545, -22587149, 536906},
-        },
-        {
-            {4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551,
-             10589625, 10838060, -15420424},
-            {-19342404, 867880, 9277171, -3218459, -14431572, -1986443,
-             19295826, -15796950, 6378260, 699185},
-            {7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039,
-             15693155, -5045064, -13373962},
-        },
-        {
-            {-7737563, -5869402, -14566319, -7406919, 11385654, 13201616,
-             31730678, -10962840, -3918636, -9669325},
-            {10188286, -15770834, -7336361, 13427543, 22223443, 14896287,
-             30743455, 7116568, -21786507, 5427593},
-            {696102, 13206899, 27047647, -10632082, 15285305, -9853179,
-             10798490, -4578720, 19236243, 12477404},
-        },
-        {
-            {-11229439, 11243796, -17054270, -8040865, -788228, -8167967,
-             -3897669, 11180504, -23169516, 7733644},
-            {17800790, -14036179, -27000429, -11766671, 23887827, 3149671,
-             23466177, -10538171, 10322027, 15313801},
-            {26246234, 11968874, 32263343, -5468728, 6830755, -13323031,
-             -15794704, -101982, -24449242, 10890804},
-        },
-        {
-            {-31365647, 10271363, -12660625, -6267268, 16690207, -13062544,
-             -14982212, 16484931, 25180797, -5334884},
-            {-586574, 10376444, -32586414, -11286356, 19801893, 10997610,
-             2276632, 9482883, 316878, 13820577},
-            {-9882808, -4510367, -2115506, 16457136, -11100081, 11674996,
-             30756178, -7515054, 30696930, -3712849},
-        },
-        {
-            {32988917, -9603412, 12499366, 7910787, -10617257, -11931514,
-             -7342816, -9985397, -32349517, 7392473},
-            {-8855661, 15927861, 9866406, -3649411, -2396914, -16655781,
-             -30409476, -9134995, 25112947, -2926644},
-            {-2504044, -436966, 25621774, -5678772, 15085042, -5479877,
-             -24884878, -13526194, 5537438, -13914319},
-        },
-    },
-    {
-        {
-            {-11225584, 2320285, -9584280, 10149187, -33444663, 5808648,
-             -14876251, -1729667, 31234590, 6090599},
-            {-9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721,
-             15878753, -6970405, -9034768},
-            {-27757857, 247744, -15194774, -9002551, 23288161, -10011936,
-             -23869595, 6503646, 20650474, 1804084},
-        },
-        {
-            {-27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995,
-             -10329713, 27842616, -202328},
-            {-15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656,
-             5031932, -11375082, 12714369},
-            {20807691, -7270825, 29286141, 11421711, -27876523, -13868230,
-             -21227475, 1035546, -19733229, 12796920},
-        },
-        {
-            {12076899, -14301286, -8785001, -11848922, -25012791, 16400684,
-             -17591495, -12899438, 3480665, -15182815},
-            {-32361549, 5457597, 28548107, 7833186, 7303070, -11953545,
-             -24363064, -15921875, -33374054, 2771025},
-            {-21389266, 421932, 26597266, 6860826, 22486084, -6737172,
-             -17137485, -4210226, -24552282, 15673397},
-        },
-        {
-            {-20184622, 2338216, 19788685, -9620956, -4001265, -8740893,
-             -20271184, 4733254, 3727144, -12934448},
-            {6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594,
-             7975683, 31123697, -10958981},
-            {30069250, -11435332, 30434654, 2958439, 18399564, -976289,
-             12296869, 9204260, -16432438, 9648165},
-        },
-        {
-            {32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266,
-             5248604, -26008332, -11377501},
-            {17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711,
-             15298639, 2662509, -16297073},
-            {-1172927, -7558695, -4366770, -4287744, -21346413, -8434326,
-             32087529, -1222777, 32247248, -14389861},
-        },
-        {
-            {14312628, 1221556, 17395390, -8700143, -4945741, -8684635,
-             -28197744, -9637817, -16027623, -13378845},
-            {-1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502,
-             9803137, 17597934, 2346211},
-            {18510800, 15337574, 26171504, 981392, -22241552, 7827556,
-             -23491134, -11323352, 3059833, -11782870},
-        },
-        {
-            {10141598, 6082907, 17829293, -1947643, 9830092, 13613136,
-             -25556636, -5544586, -33502212, 3592096},
-            {33114168, -15889352, -26525686, -13343397, 33076705, 8716171,
-             1151462, 1521897, -982665, -6837803},
-            {-32939165, -4255815, 23947181, -324178, -33072974, -12305637,
-             -16637686, 3891704, 26353178, 693168},
-        },
-        {
-            {30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294,
-             -400668, 31375464, 14369965},
-            {-14370654, -7772529, 1510301, 6434173, -18784789, -6262728,
-             32732230, -13108839, 17901441, 16011505},
-            {18171223, -11934626, -12500402, 15197122, -11038147, -15230035,
-             -19172240, -16046376, 8764035, 12309598},
-        },
-    },
-    {
-        {
-            {5975908, -5243188, -19459362, -9681747, -11541277, 14015782,
-             -23665757, 1228319, 17544096, -10593782},
-            {5811932, -1715293, 3442887, -2269310, -18367348, -8359541,
-             -18044043, -15410127, -5565381, 12348900},
-            {-31399660, 11407555, 25755363, 6891399, -3256938, 14872274,
-             -24849353, 8141295, -10632534, -585479},
-        },
-        {
-            {-12675304, 694026, -5076145, 13300344, 14015258, -14451394,
-             -9698672, -11329050, 30944593, 1130208},
-            {8247766, -6710942, -26562381, -7709309, -14401939, -14648910,
-             4652152, 2488540, 23550156, -271232},
-            {17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737,
-             -5908146, -408818, -137719},
-        },
-        {
-            {16091085, -16253926, 18599252, 7340678, 2137637, -1221657,
-             -3364161, 14550936, 3260525, -7166271},
-            {-4910104, -13332887, 18550887, 10864893, -16459325, -7291596,
-             -23028869, -13204905, -12748722, 2701326},
-            {-8574695, 16099415, 4629974, -16340524, -20786213, -6005432,
-             -10018363, 9276971, 11329923, 1862132},
-        },
-        {
-            {14763076, -15903608, -30918270, 3689867, 3511892, 10313526,
-             -21951088, 12219231, -9037963, -940300},
-            {8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216,
-             -2909717, -15438168, 11595570},
-            {15214962, 3537601, -26238722, -14058872, 4418657, -15230761,
-             13947276, 10730794, -13489462, -4363670},
-        },
-        {
-            {-2538306, 7682793, 32759013, 263109, -29984731, -7955452,
-             -22332124, -10188635, 977108, 699994},
-            {-12466472, 4195084, -9211532, 550904, -15565337, 12917920,
-             19118110, -439841, -30534533, -14337913},
-            {31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237,
-             -10051775, 12493932, -5409317},
-        },
-        {
-            {-25680606, 5260744, -19235809, -6284470, -3695942, 16566087,
-             27218280, 2607121, 29375955, 6024730},
-            {842132, -2794693, -4763381, -8722815, 26332018, -12405641,
-             11831880, 6985184, -9940361, 2854096},
-            {-4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645,
-             960770, 12121869, 16648078},
-        },
-        {
-            {-15218652, 14667096, -13336229, 2013717, 30598287, -464137,
-             -31504922, -7882064, 20237806, 2838411},
-            {-19288047, 4453152, 15298546, -16178388, 22115043, -15972604,
-             12544294, -13470457, 1068881, -12499905},
-            {-9558883, -16518835, 33238498, 13506958, 30505848, -1114596,
-             -8486907, -2630053, 12521378, 4845654},
-        },
-        {
-            {-28198521, 10744108, -2958380, 10199664, 7759311, -13088600,
-             3409348, -873400, -6482306, -12885870},
-            {-23561822, 6230156, -20382013, 10655314, -24040585, -11621172,
-             10477734, -1240216, -3113227, 13974498},
-            {12966261, 15550616, -32038948, -1615346, 21025980, -629444,
-             5642325, 7188737, 18895762, 12629579},
-        },
-    },
-    {
-        {
-            {14741879, -14946887, 22177208, -11721237, 1279741, 8058600,
-             11758140, 789443, 32195181, 3895677},
-            {10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575,
-             -3566119, -8982069, 4429647},
-            {-2453894, 15725973, -20436342, -10410672, -5803908, -11040220,
-             -7135870, -11642895, 18047436, -15281743},
-        },
-        {
-            {-25173001, -11307165, 29759956, 11776784, -22262383, -15820455,
-             10993114, -12850837, -17620701, -9408468},
-            {21987233, 700364, -24505048, 14972008, -7774265, -5718395,
-             32155026, 2581431, -29958985, 8773375},
-            {-25568350, 454463, -13211935, 16126715, 25240068, 8594567,
-             20656846, 12017935, -7874389, -13920155},
-        },
-        {
-            {6028182, 6263078, -31011806, -11301710, -818919, 2461772,
-             -31841174, -5468042, -1721788, -2776725},
-            {-12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845,
-             -4166698, 28408820, 6816612},
-            {-10358094, -8237829, 19549651, -12169222, 22082623, 16147817,
-             20613181, 13982702, -10339570, 5067943},
-        },
-        {
-            {-30505967, -3821767, 12074681, 13582412, -19877972, 2443951,
-             -19719286, 12746132, 5331210, -10105944},
-            {30528811, 3601899, -1957090, 4619785, -27361822, -15436388,
-             24180793, -12570394, 27679908, -1648928},
-            {9402404, -13957065, 32834043, 10838634, -26580150, -13237195,
-             26653274, -8685565, 22611444, -12715406},
-        },
-        {
-            {22190590, 1118029, 22736441, 15130463, -30460692, -5991321,
-             19189625, -4648942, 4854859, 6622139},
-            {-8310738, -2953450, -8262579, -3388049, -10401731, -271929,
-             13424426, -3567227, 26404409, 13001963},
-            {-31241838, -15415700, -2994250, 8939346, 11562230, -12840670,
-             -26064365, -11621720, -15405155, 11020693},
-        },
-        {
-            {1866042, -7949489, -7898649, -10301010, 12483315, 13477547,
-             3175636, -12424163, 28761762, 1406734},
-            {-448555, -1777666, 13018551, 3194501, -9580420, -11161737,
-             24760585, -4347088, 25577411, -13378680},
-            {-24290378, 4759345, -690653, -1852816, 2066747, 10693769,
-             -29595790, 9884936, -9368926, 4745410},
-        },
-        {
-            {-9141284, 6049714, -19531061, -4341411, -31260798, 9944276,
-             -15462008, -11311852, 10931924, -11931931},
-            {-16561513, 14112680, -8012645, 4817318, -8040464, -11414606,
-             -22853429, 10856641, -20470770, 13434654},
-            {22759489, -10073434, -16766264, -1871422, 13637442, -10168091,
-             1765144, -12654326, 28445307, -5364710},
-        },
-        {
-            {29875063, 12493613, 2795536, -3786330, 1710620, 15181182,
-             -10195717, -8788675, 9074234, 1167180},
-            {-26205683, 11014233, -9842651, -2635485, -26908120, 7532294,
-             -18716888, -9535498, 3843903, 9367684},
-            {-10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123,
-             8601684, -139197, 4242895},
-        },
-    },
-    {
-        {
-            {22092954, -13191123, -2042793, -11968512, 32186753, -11517388,
-             -6574341, 2470660, -27417366, 16625501},
-            {-11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857,
-             2602725, -27351616, 14247413},
-            {6314175, -10264892, -32772502, 15957557, -10157730, 168750,
-             -8618807, 14290061, 27108877, -1180880},
-        },
-        {
-            {-8586597, -7170966, 13241782, 10960156, -32991015, -13794596,
-             33547976, -11058889, -27148451, 981874},
-            {22833440, 9293594, -32649448, -13618667, -9136966, 14756819,
-             -22928859, -13970780, -10479804, -16197962},
-            {-7768587, 3326786, -28111797, 10783824, 19178761, 14905060,
-             22680049, 13906969, -15933690, 3797899},
-        },
-        {
-            {21721356, -4212746, -12206123, 9310182, -3882239, -13653110,
-             23740224, -2709232, 20491983, -8042152},
-            {9209270, -15135055, -13256557, -6167798, -731016, 15289673,
-             25947805, 15286587, 30997318, -6703063},
-            {7392032, 16618386, 23946583, -8039892, -13265164, -1533858,
-             -14197445, -2321576, 17649998, -250080},
-        },
-        {
-            {-9301088, -14193827, 30609526, -3049543, -25175069, -1283752,
-             -15241566, -9525724, -2233253, 7662146},
-            {-17558673, 1763594, -33114336, 15908610, -30040870, -12174295,
-             7335080, -8472199, -3174674, 3440183},
-            {-19889700, -5977008, -24111293, -9688870, 10799743, -16571957,
-             40450, -4431835, 4862400, 1133},
-        },
-        {
-            {-32856209, -7873957, -5422389, 14860950, -16319031, 7956142,
-             7258061, 311861, -30594991, -7379421},
-            {-3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763,
-             16527196, 18278453, 15405622},
-            {-4381906, 8508652, -19898366, -3674424, -5984453, 15149970,
-             -13313598, 843523, -21875062, 13626197},
-        },
-        {
-            {2281448, -13487055, -10915418, -2609910, 1879358, 16164207,
-             -10783882, 3953792, 13340839, 15928663},
-            {31727126, -7179855, -18437503, -8283652, 2875793, -16390330,
-             -25269894, -7014826, -23452306, 5964753},
-            {4100420, -5959452, -17179337, 6017714, -18705837, 12227141,
-             -26684835, 11344144, 2538215, -7570755},
-        },
-        {
-            {-9433605, 6123113, 11159803, -2156608, 30016280, 14966241,
-             -20474983, 1485421, -629256, -15958862},
-            {-26804558, 4260919, 11851389, 9658551, -32017107, 16367492,
-             -20205425, -13191288, 11659922, -11115118},
-            {26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568,
-             -10170080, 33100372, -1306171},
-        },
-        {
-            {15121113, -5201871, -10389905, 15427821, -27509937, -15992507,
-             21670947, 4486675, -5931810, -14466380},
-            {16166486, -9483733, -11104130, 6023908, -31926798, -1364923,
-             2340060, -16254968, -10735770, -10039824},
-            {28042865, -3557089, -12126526, 12259706, -3717498, -6945899,
-             6766453, -8689599, 18036436, 5803270},
-        },
-    },
-    {
-        {
-            {-817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391,
-             4598332, -6159431, -14117438},
-            {-31031306, -14256194, 17332029, -2383520, 31312682, -5967183,
-             696309, 50292, -20095739, 11763584},
-            {-594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117,
-             -12613632, -19773211, -10713562},
-        },
-        {
-            {30464590, -11262872, -4127476, -12734478, 19835327, -7105613,
-             -24396175, 2075773, -17020157, 992471},
-            {18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841,
-             8080033, -11574335, -10601610},
-            {19598397, 10334610, 12555054, 2555664, 18821899, -10339780,
-             21873263, 16014234, 26224780, 16452269},
-        },
-        {
-            {-30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804,
-             -7618186, -20533829, 3698650},
-            {14187449, 3448569, -10636236, -10810935, -22663880, -3433596,
-             7268410, -10890444, 27394301, 12015369},
-            {19695761, 16087646, 28032085, 12999827, 6817792, 11427614,
-             20244189, -1312777, -13259127, -3402461},
-        },
-        {
-            {30860103, 12735208, -1888245, -4699734, -16974906, 2256940,
-             -8166013, 12298312, -8550524, -10393462},
-            {-5719826, -11245325, -1910649, 15569035, 26642876, -7587760,
-             -5789354, -15118654, -4976164, 12651793},
-            {-2848395, 9953421, 11531313, -5282879, 26895123, -12697089,
-             -13118820, -16517902, 9768698, -2533218},
-        },
-        {
-            {-24719459, 1894651, -287698, -4704085, 15348719, -8156530,
-             32767513, 12765450, 4940095, 10678226},
-            {18860224, 15980149, -18987240, -1562570, -26233012, -11071856,
-             -7843882, 13944024, -24372348, 16582019},
-            {-15504260, 4970268, -29893044, 4175593, -20993212, -2199756,
-             -11704054, 15444560, -11003761, 7989037},
-        },
-        {
-            {31490452, 5568061, -2412803, 2182383, -32336847, 4531686,
-             -32078269, 6200206, -19686113, -14800171},
-            {-17308668, -15879940, -31522777, -2831, -32887382, 16375549,
-             8680158, -16371713, 28550068, -6857132},
-            {-28126887, -5688091, 16837845, -1820458, -6850681, 12700016,
-             -30039981, 4364038, 1155602, 5988841},
-        },
-        {
-            {21890435, -13272907, -12624011, 12154349, -7831873, 15300496,
-             23148983, -4470481, 24618407, 8283181},
-            {-33136107, -10512751, 9975416, 6841041, -31559793, 16356536,
-             3070187, -7025928, 1466169, 10740210},
-            {-1509399, -15488185, -13503385, -10655916, 32799044, 909394,
-             -13938903, -5779719, -32164649, -15327040},
-        },
-        {
-            {3960823, -14267803, -28026090, -15918051, -19404858, 13146868,
-             15567327, 951507, -3260321, -573935},
-            {24740841, 5052253, -30094131, 8961361, 25877428, 6165135,
-             -24368180, 14397372, -7380369, -6144105},
-            {-28888365, 3510803, -28103278, -1158478, -11238128, -10631454,
-             -15441463, -14453128, -1625486, -6494814},
-        },
-    },
-    {
-        {
-            {793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843,
-             -4885251, -9906200, -621852},
-            {5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374,
-             1468826, -6171428, -15186581},
-            {-4859255, -3779343, -2917758, -6748019, 7778750, 11688288,
-             -30404353, -9871238, -1558923, -9863646},
-        },
-        {
-            {10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958,
-             14783338, -30581476, -15757844},
-            {10566929, 12612572, -31944212, 11118703, -12633376, 12362879,
-             21752402, 8822496, 24003793, 14264025},
-            {27713862, -7355973, -11008240, 9227530, 27050101, 2504721,
-             23886875, -13117525, 13958495, -5732453},
-        },
-        {
-            {-23481610, 4867226, -27247128, 3900521, 29838369, -8212291,
-             -31889399, -10041781, 7340521, -15410068},
-            {4646514, -8011124, -22766023, -11532654, 23184553, 8566613,
-             31366726, -1381061, -15066784, -10375192},
-            {-17270517, 12723032, -16993061, 14878794, 21619651, -6197576,
-             27584817, 3093888, -8843694, 3849921},
-        },
-        {
-            {-9064912, 2103172, 25561640, -15125738, -5239824, 9582958,
-             32477045, -9017955, 5002294, -15550259},
-            {-12057553, -11177906, 21115585, -13365155, 8808712, -12030708,
-             16489530, 13378448, -25845716, 12741426},
-            {-5946367, 10645103, -30911586, 15390284, -3286982, -7118677,
-             24306472, 15852464, 28834118, -7646072},
-        },
-        {
-            {-17335748, -9107057, -24531279, 9434953, -8472084, -583362,
-             -13090771, 455841, 20461858, 5491305},
-            {13669248, -16095482, -12481974, -10203039, -14569770, -11893198,
-             -24995986, 11293807, -28588204, -9421832},
-            {28497928, 6272777, -33022994, 14470570, 8906179, -1225630,
-             18504674, -14165166, 29867745, -8795943},
-        },
-        {
-            {-16207023, 13517196, -27799630, -13697798, 24009064, -6373891,
-             -6367600, -13175392, 22853429, -4012011},
-            {24191378, 16712145, -13931797, 15217831, 14542237, 1646131,
-             18603514, -11037887, 12876623, -2112447},
-            {17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753,
-             608397, 16031844, 3723494},
-        },
-        {
-            {-28632773, 12763728, -20446446, 7577504, 33001348, -13017745,
-             17558842, -7872890, 23896954, -4314245},
-            {-20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064,
-             7229064, -9919646, -8826859},
-            {28816045, 298879, -28165016, -15920938, 19000928, -1665890,
-             -12680833, -2949325, -18051778, -2082915},
-        },
-        {
-            {16000882, -344896, 3493092, -11447198, -29504595, -13159789,
-             12577740, 16041268, -19715240, 7847707},
-            {10151868, 10572098, 27312476, 7922682, 14825339, 4723128,
-             -32855931, -6519018, -10020567, 3852848},
-            {-11430470, 15697596, -21121557, -4420647, 5386314, 15063598,
-             16514493, -15932110, 29330899, -15076224},
-        },
-    },
-    {
-        {
-            {-25499735, -4378794, -15222908, -6901211, 16615731, 2051784,
-             3303702, 15490, -27548796, 12314391},
-            {15683520, -6003043, 18109120, -9980648, 15337968, -5997823,
-             -16717435, 15921866, 16103996, -3731215},
-            {-23169824, -10781249, 13588192, -1628807, -3798557, -1074929,
-             -19273607, 5402699, -29815713, -9841101},
-        },
-        {
-            {23190676, 2384583, -32714340, 3462154, -29903655, -1529132,
-             -11266856, 8911517, -25205859, 2739713},
-            {21374101, -3554250, -33524649, 9874411, 15377179, 11831242,
-             -33529904, 6134907, 4931255, 11987849},
-            {-7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539,
-             13861388, -30076310, 10117930},
-        },
-        {
-            {-29501170, -10744872, -26163768, 13051539, -25625564, 5089643,
-             -6325503, 6704079, 12890019, 15728940},
-            {-21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376,
-             -10428139, 12885167, 8311031},
-            {-17516482, 5352194, 10384213, -13811658, 7506451, 13453191,
-             26423267, 4384730, 1888765, -5435404},
-        },
-        {
-            {-25817338, -3107312, -13494599, -3182506, 30896459, -13921729,
-             -32251644, -12707869, -19464434, -3340243},
-            {-23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245,
-             14845197, 17151279, -9854116},
-            {-24830458, -12733720, -15165978, 10367250, -29530908, -265356,
-             22825805, -7087279, -16866484, 16176525},
-        },
-        {
-            {-23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182,
-             -10363426, -28746253, -10197509},
-            {-10626600, -4486402, -13320562, -5125317, 3432136, -6393229,
-             23632037, -1940610, 32808310, 1099883},
-            {15030977, 5768825, -27451236, -2887299, -6427378, -15361371,
-             -15277896, -6809350, 2051441, -15225865},
-        },
-        {
-            {-3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398,
-             -14154188, -22686354, 16633660},
-            {4577086, -16752288, 13249841, -15304328, 19958763, -14537274,
-             18559670, -10759549, 8402478, -9864273},
-            {-28406330, -1051581, -26790155, -907698, -17212414, -11030789,
-             9453451, -14980072, 17983010, 9967138},
-        },
-        {
-            {-25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990,
-             7806337, 17507396, 3651560},
-            {-10420457, -4118111, 14584639, 15971087, -15768321, 8861010,
-             26556809, -5574557, -18553322, -11357135},
-            {2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121,
-             8459447, -5605463, -7621941},
-        },
-        {
-            {-4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813,
-             -849066, 17258084, -7977739},
-            {18164541, -10595176, -17154882, -1542417, 19237078, -9745295,
-             23357533, -15217008, 26908270, 12150756},
-            {-30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168,
-             -5537701, -32302074, 16215819},
-        },
-    },
-    {
-        {
-            {-6898905, 9824394, -12304779, -4401089, -31397141, -6276835,
-             32574489, 12532905, -7503072, -8675347},
-            {-27343522, -16515468, -27151524, -10722951, 946346, 16291093,
-             254968, 7168080, 21676107, -1943028},
-            {21260961, -8424752, -16831886, -11920822, -23677961, 3968121,
-             -3651949, -6215466, -3556191, -7913075},
-        },
-        {
-            {16544754, 13250366, -16804428, 15546242, -4583003, 12757258,
-             -2462308, -8680336, -18907032, -9662799},
-            {-2415239, -15577728, 18312303, 4964443, -15272530, -12653564,
-             26820651, 16690659, 25459437, -4564609},
-            {-25144690, 11425020, 28423002, -11020557, -6144921, -15826224,
-             9142795, -2391602, -6432418, -1644817},
-        },
-        {
-            {-23104652, 6253476, 16964147, -3768872, -25113972, -12296437,
-             -27457225, -16344658, 6335692, 7249989},
-            {-30333227, 13979675, 7503222, -12368314, -11956721, -4621693,
-             -30272269, 2682242, 25993170, -12478523},
-            {4364628, 5930691, 32304656, -10044554, -8054781, 15091131,
-             22857016, -10598955, 31820368, 15075278},
-        },
-        {
-            {31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788,
-             -9650886, -17970238, 12833045},
-            {19073683, 14851414, -24403169, -11860168, 7625278, 11091125,
-             -19619190, 2074449, -9413939, 14905377},
-            {24483667, -11935567, -2518866, -11547418, -1553130, 15355506,
-             -25282080, 9253129, 27628530, -7555480},
-        },
-        {
-            {17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324,
-             -9157582, -14110875, 15297016},
-            {510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417,
-             -11864220, 8683221, 2921426},
-            {18606791, 11874196, 27155355, -5281482, -24031742, 6265446,
-             -25178240, -1278924, 4674690, 13890525},
-        },
-        {
-            {13609624, 13069022, -27372361, -13055908, 24360586, 9592974,
-             14977157, 9835105, 4389687, 288396},
-            {9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062,
-             8317628, 23388070, 16052080},
-            {12720016, 11937594, -31970060, -5028689, 26900120, 8561328,
-             -20155687, -11632979, -14754271, -10812892},
-        },
-        {
-            {15961858, 14150409, 26716931, -665832, -22794328, 13603569,
-             11829573, 7467844, -28822128, 929275},
-            {11038231, -11582396, -27310482, -7316562, -10498527, -16307831,
-             -23479533, -9371869, -21393143, 2465074},
-            {20017163, -4323226, 27915242, 1529148, 12396362, 15675764,
-             13817261, -9658066, 2463391, -4622140},
-        },
-        {
-            {-16358878, -12663911, -12065183, 4996454, -1256422, 1073572,
-             9583558, 12851107, 4003896, 12673717},
-            {-1731589, -15155870, -3262930, 16143082, 19294135, 13385325,
-             14741514, -9103726, 7903886, 2348101},
-            {24536016, -16515207, 12715592, -3862155, 1511293, 10047386,
-             -3842346, -7129159, -28377538, 10048127},
-        },
-    },
-    {
-        {
-            {-12622226, -6204820, 30718825, 2591312, -10617028, 12192840,
-             18873298, -7297090, -32297756, 15221632},
-            {-26478122, -11103864, 11546244, -1852483, 9180880, 7656409,
-             -21343950, 2095755, 29769758, 6593415},
-            {-31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345,
-             -6118678, 30958054, 8292160},
-        },
-        {
-            {31429822, -13959116, 29173532, 15632448, 12174511, -2760094,
-             32808831, 3977186, 26143136, -3148876},
-            {22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633,
-             -1674433, -3758243, -2304625},
-            {-15491917, 8012313, -2514730, -12702462, -23965846, -10254029,
-             -1612713, -1535569, -16664475, 8194478},
-        },
-        {
-            {27338066, -7507420, -7414224, 10140405, -19026427, -6589889,
-             27277191, 8855376, 28572286, 3005164},
-            {26287124, 4821776, 25476601, -4145903, -3764513, -15788984,
-             -18008582, 1182479, -26094821, -13079595},
-            {-7171154, 3178080, 23970071, 6201893, -17195577, -4489192,
-             -21876275, -13982627, 32208683, -1198248},
-        },
-        {
-            {-16657702, 2817643, -10286362, 14811298, 6024667, 13349505,
-             -27315504, -10497842, -27672585, -11539858},
-            {15941029, -9405932, -21367050, 8062055, 31876073, -238629,
-             -15278393, -1444429, 15397331, -4130193},
-            {8934485, -13485467, -23286397, -13423241, -32446090, 14047986,
-             31170398, -1441021, -27505566, 15087184},
-        },
-        {
-            {-18357243, -2156491, 24524913, -16677868, 15520427, -6360776,
-             -15502406, 11461896, 16788528, -5868942},
-            {-1947386, 16013773, 21750665, 3714552, -17401782, -16055433,
-             -3770287, -10323320, 31322514, -11615635},
-            {21426655, -5650218, -13648287, -5347537, -28812189, -4920970,
-             -18275391, -14621414, 13040862, -12112948},
-        },
-        {
-            {11293895, 12478086, -27136401, 15083750, -29307421, 14748872,
-             14555558, -13417103, 1613711, 4896935},
-            {-25894883, 15323294, -8489791, -8057900, 25967126, -13425460,
-             2825960, -4897045, -23971776, -11267415},
-            {-15924766, -5229880, -17443532, 6410664, 3622847, 10243618,
-             20615400, 12405433, -23753030, -8436416},
-        },
-        {
-            {-7091295, 12556208, -20191352, 9025187, -17072479, 4333801,
-             4378436, 2432030, 23097949, -566018},
-            {4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264,
-             10103221, -18512313, 2424778},
-            {366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678,
-             1344109, -3642553, 12412659},
-        },
-        {
-            {-24001791, 7690286, 14929416, -168257, -32210835, -13412986,
-             24162697, -15326504, -3141501, 11179385},
-            {18289522, -14724954, 8056945, 16430056, -21729724, 7842514,
-             -6001441, -1486897, -18684645, -11443503},
-            {476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959,
-             13403813, 11052904, 5219329},
-        },
-    },
-    {
-        {
-            {20678546, -8375738, -32671898, 8849123, -5009758, 14574752,
-             31186971, -3973730, 9014762, -8579056},
-            {-13644050, -10350239, -15962508, 5075808, -1514661, -11534600,
-             -33102500, 9160280, 8473550, -3256838},
-            {24900749, 14435722, 17209120, -15292541, -22592275, 9878983,
-             -7689309, -16335821, -24568481, 11788948},
-        },
-        {
-            {-3118155, -11395194, -13802089, 14797441, 9652448, -6845904,
-             -20037437, 10410733, -24568470, -1458691},
-            {-15659161, 16736706, -22467150, 10215878, -9097177, 7563911,
-             11871841, -12505194, -18513325, 8464118},
-            {-23400612, 8348507, -14585951, -861714, -3950205, -6373419,
-             14325289, 8628612, 33313881, -8370517},
-        },
-        {
-            {-20186973, -4967935, 22367356, 5271547, -1097117, -4788838,
-             -24805667, -10236854, -8940735, -5818269},
-            {-6948785, -1795212, -32625683, -16021179, 32635414, -7374245,
-             15989197, -12838188, 28358192, -4253904},
-            {-23561781, -2799059, -32351682, -1661963, -9147719, 10429267,
-             -16637684, 4072016, -5351664, 5596589},
-        },
-        {
-            {-28236598, -3390048, 12312896, 6213178, 3117142, 16078565,
-             29266239, 2557221, 1768301, 15373193},
-            {-7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902,
-             -4504991, -24660491, 3442910},
-            {-30210571, 5124043, 14181784, 8197961, 18964734, -11939093,
-             22597931, 7176455, -18585478, 13365930},
-        },
-        {
-            {-7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107,
-             -8570186, -9689599, -3031667},
-            {25008904, -10771599, -4305031, -9638010, 16265036, 15721635,
-             683793, -11823784, 15723479, -15163481},
-            {-9660625, 12374379, -27006999, -7026148, -7724114, -12314514,
-             11879682, 5400171, 519526, -1235876},
-        },
-        {
-            {22258397, -16332233, -7869817, 14613016, -22520255, -2950923,
-             -20353881, 7315967, 16648397, 7605640},
-            {-8081308, -8464597, -8223311, 9719710, 19259459, -15348212,
-             23994942, -5281555, -9468848, 4763278},
-            {-21699244, 9220969, -15730624, 1084137, -25476107, -2852390,
-             31088447, -7764523, -11356529, 728112},
-        },
-        {
-            {26047220, -11751471, -6900323, -16521798, 24092068, 9158119,
-             -4273545, -12555558, -29365436, -5498272},
-            {17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007,
-             12327945, 10750447, 10014012},
-            {-10312768, 3936952, 9156313, -8897683, 16498692, -994647,
-             -27481051, -666732, 3424691, 7540221},
-        },
-        {
-            {30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422,
-             -16317219, -9244265, 15258046},
-            {13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406,
-             2711395, 1062915, -5136345},
-            {-19240248, -11254599, -29509029, -7499965, -5835763, 13005411,
-             -6066489, 12194497, 32960380, 1459310},
-        },
-    },
-    {
-        {
-            {19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197,
-             -6101885, 18638003, -11174937},
-            {31395534, 15098109, 26581030, 8030562, -16527914, -5007134,
-             9012486, -7584354, -6643087, -5442636},
-            {-9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222,
-             9677543, -32294889, -6456008},
-        },
-        {
-            {-2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579,
-             -7839692, -7852844, -8138429},
-            {-15236356, -15433509, 7766470, 746860, 26346930, -10221762,
-             -27333451, 10754588, -9431476, 5203576},
-            {31834314, 14135496, -770007, 5159118, 20917671, -16768096,
-             -7467973, -7337524, 31809243, 7347066},
-        },
-        {
-            {-9606723, -11874240, 20414459, 13033986, 13716524, -11691881,
-             19797970, -12211255, 15192876, -2087490},
-            {-12663563, -2181719, 1168162, -3804809, 26747877, -14138091,
-             10609330, 12694420, 33473243, -13382104},
-            {33184999, 11180355, 15832085, -11385430, -1633671, 225884,
-             15089336, -11023903, -6135662, 14480053},
-        },
-        {
-            {31308717, -5619998, 31030840, -1897099, 15674547, -6582883,
-             5496208, 13685227, 27595050, 8737275},
-            {-20318852, -15150239, 10933843, -16178022, 8335352, -7546022,
-             -31008351, -12610604, 26498114, 66511},
-            {22644454, -8761729, -16671776, 4884562, -3105614, -13559366,
-             30540766, -4286747, -13327787, -7515095},
-        },
-        {
-            {-28017847, 9834845, 18617207, -2681312, -3401956, -13307506,
-             8205540, 13585437, -17127465, 15115439},
-            {23711543, -672915, 31206561, -8362711, 6164647, -9709987,
-             -33535882, -1426096, 8236921, 16492939},
-            {-23910559, -13515526, -26299483, -4503841, 25005590, -7687270,
-             19574902, 10071562, 6708380, -6222424},
-        },
-        {
-            {2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017,
-             9328700, 29955601, -11678310},
-            {3096359, 9271816, -21620864, -15521844, -14847996, -7592937,
-             -25892142, -12635595, -9917575, 6216608},
-            {-32615849, 338663, -25195611, 2510422, -29213566, -13820213,
-             24822830, -6146567, -26767480, 7525079},
-        },
-        {
-            {-23066649, -13985623, 16133487, -7896178, -3389565, 778788,
-             -910336, -2782495, -19386633, 11994101},
-            {21691500, -13624626, -641331, -14367021, 3285881, -3483596,
-             -25064666, 9718258, -7477437, 13381418},
-            {18445390, -4202236, 14979846, 11622458, -1727110, -3582980,
-             23111648, -6375247, 28535282, 15779576},
-        },
-        {
-            {30098053, 3089662, -9234387, 16662135, -21306940, 11308411,
-             -14068454, 12021730, 9955285, -16303356},
-            {9734894, -14576830, -7473633, -9138735, 2060392, 11313496,
-             -18426029, 9924399, 20194861, 13380996},
-            {-26378102, -7965207, -22167821, 15789297, -18055342, -6168792,
-             -1984914, 15707771, 26342023, 10146099},
-        },
-    },
-    {
-        {
-            {-26016874, -219943, 21339191, -41388, 19745256, -2878700,
-             -29637280, 2227040, 21612326, -545728},
-            {-13077387, 1184228, 23562814, -5970442, -20351244, -6348714,
-             25764461, 12243797, -20856566, 11649658},
-            {-10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944,
-             6114064, 33514190, 2333242},
-        },
-        {
-            {-21433588, -12421821, 8119782, 7219913, -21830522, -9016134,
-             -6679750, -12670638, 24350578, -13450001},
-            {-4116307, -11271533, -23886186, 4843615, -30088339, 690623,
-             -31536088, -10406836, 8317860, 12352766},
-            {18200138, -14475911, -33087759, -2696619, -23702521, -9102511,
-             -23552096, -2287550, 20712163, 6719373},
-        },
-        {
-            {26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530,
-             -3763210, 26224235, -3297458},
-            {-17168938, -14854097, -3395676, -16369877, -19954045, 14050420,
-             21728352, 9493610, 18620611, -16428628},
-            {-13323321, 13325349, 11432106, 5964811, 18609221, 6062965,
-             -5269471, -9725556, -30701573, -16479657},
-        },
-        {
-            {-23860538, -11233159, 26961357, 1640861, -32413112, -16737940,
-             12248509, -5240639, 13735342, 1934062},
-            {25089769, 6742589, 17081145, -13406266, 21909293, -16067981,
-             -15136294, -3765346, -21277997, 5473616},
-            {31883677, -7961101, 1083432, -11572403, 22828471, 13290673,
-             -7125085, 12469656, 29111212, -5451014},
-        },
-        {
-            {24244947, -15050407, -26262976, 2791540, -14997599, 16666678,
-             24367466, 6388839, -10295587, 452383},
-            {-25640782, -3417841, 5217916, 16224624, 19987036, -4082269,
-             -24236251, -5915248, 15766062, 8407814},
-            {-20406999, 13990231, 15495425, 16395525, 5377168, 15166495,
-             -8917023, -4388953, -8067909, 2276718},
-        },
-        {
-            {30157918, 12924066, -17712050, 9245753, 19895028, 3368142,
-             -23827587, 5096219, 22740376, -7303417},
-            {2041139, -14256350, 7783687, 13876377, -25946985, -13352459,
-             24051124, 13742383, -15637599, 13295222},
-            {33338237, -8505733, 12532113, 7977527, 9106186, -1715251,
-             -17720195, -4612972, -4451357, -14669444},
-        },
-        {
-            {-20045281, 5454097, -14346548, 6447146, 28862071, 1883651,
-             -2469266, -4141880, 7770569, 9620597},
-            {23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528,
-             -1694323, -33502340, -14767970},
-            {1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801,
-             1220118, 30494170, -11440799},
-        },
-        {
-            {-5037580, -13028295, -2970559, -3061767, 15640974, -6701666,
-             -26739026, 926050, -1684339, -13333647},
-            {13908495, -3549272, 30919928, -6273825, -21521863, 7989039,
-             9021034, 9078865, 3353509, 4033511},
-            {-29663431, -15113610, 32259991, -344482, 24295849, -12912123,
-             23161163, 8839127, 27485041, 7356032},
-        },
-    },
-    {
-        {
-            {9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142,
-             2625015, 28431036, -16771834},
-            {-23839233, -8311415, -25945511, 7480958, -17681669, -8354183,
-             -22545972, 14150565, 15970762, 4099461},
-            {29262576, 16756590, 26350592, -8793563, 8529671, -11208050,
-             13617293, -9937143, 11465739, 8317062},
-        },
-        {
-            {-25493081, -6962928, 32500200, -9419051, -23038724, -2302222,
-             14898637, 3848455, 20969334, -5157516},
-            {-20384450, -14347713, -18336405, 13884722, -33039454, 2842114,
-             -21610826, -3649888, 11177095, 14989547},
-            {-24496721, -11716016, 16959896, 2278463, 12066309, 10137771,
-             13515641, 2581286, -28487508, 9930240},
-        },
-        {
-            {-17751622, -2097826, 16544300, -13009300, -15914807, -14949081,
-             18345767, -13403753, 16291481, -5314038},
-            {-33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774,
-             6957617, 4368891, 9788741},
-            {16660756, 7281060, -10830758, 12911820, 20108584, -8101676,
-             -21722536, -8613148, 16250552, -11111103},
-        },
-        {
-            {-19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584,
-             10604807, -30190403, 4782747},
-            {-1354539, 14736941, -7367442, -13292886, 7710542, -14155590,
-             -9981571, 4383045, 22546403, 437323},
-            {31665577, -12180464, -16186830, 1491339, -18368625, 3294682,
-             27343084, 2786261, -30633590, -14097016},
-        },
-        {
-            {-14467279, -683715, -33374107, 7448552, 19294360, 14334329,
-             -19690631, 2355319, -19284671, -6114373},
-            {15121312, -15796162, 6377020, -6031361, -10798111, -12957845,
-             18952177, 15496498, -29380133, 11754228},
-            {-2637277, -13483075, 8488727, -14303896, 12728761, -1622493,
-             7141596, 11724556, 22761615, -10134141},
-        },
-        {
-            {16918416, 11729663, -18083579, 3022987, -31015732, -13339659,
-             -28741185, -12227393, 32851222, 11717399},
-            {11166634, 7338049, -6722523, 4531520, -29468672, -7302055,
-             31474879, 3483633, -1193175, -4030831},
-            {-185635, 9921305, 31456609, -13536438, -12013818, 13348923,
-             33142652, 6546660, -19985279, -3948376},
-        },
-        {
-            {-32460596, 11266712, -11197107, -7899103, 31703694, 3855903,
-             -8537131, -12833048, -30772034, -15486313},
-            {-18006477, 12709068, 3991746, -6479188, -21491523, -10550425,
-             -31135347, -16049879, 10928917, 3011958},
-            {-6957757, -15594337, 31696059, 334240, 29576716, 14796075,
-             -30831056, -12805180, 18008031, 10258577},
-        },
-        {
-            {-22448644, 15655569, 7018479, -4410003, -30314266, -1201591,
-             -1853465, 1367120, 25127874, 6671743},
-            {29701166, -14373934, -10878120, 9279288, -17568, 13127210,
-             21382910, 11042292, 25838796, 4642684},
-            {-20430234, 14955537, -24126347, 8124619, -5369288, -5990470,
-             30468147, -13900640, 18423289, 4177476},
-        },
-    },
-};
-
-static uint8_t negative(signed char b) {
-  uint32_t x = b;
-  x >>= 31;  // 1: yes; 0: no
-  return x;
-}
-
-static void table_select(ge_precomp *t, int pos, signed char b) {
-  ge_precomp minust;
-  uint8_t bnegative = negative(b);
-  uint8_t babs = b - ((uint8_t)((-bnegative) & b) << 1);
-
-  ge_precomp_0(t);
-  cmov(t, &k25519Precomp[pos][0], equal(babs, 1));
-  cmov(t, &k25519Precomp[pos][1], equal(babs, 2));
-  cmov(t, &k25519Precomp[pos][2], equal(babs, 3));
-  cmov(t, &k25519Precomp[pos][3], equal(babs, 4));
-  cmov(t, &k25519Precomp[pos][4], equal(babs, 5));
-  cmov(t, &k25519Precomp[pos][5], equal(babs, 6));
-  cmov(t, &k25519Precomp[pos][6], equal(babs, 7));
-  cmov(t, &k25519Precomp[pos][7], equal(babs, 8));
-  fe_copy(minust.yplusx, t->yminusx);
-  fe_copy(minust.yminusx, t->yplusx);
-  fe_neg(minust.xy2d, t->xy2d);
-  cmov(t, &minust, bnegative);
-}
-
-// h = a * B
-// where a = a[0]+256*a[1]+...+256^31 a[31]
-// B is the Ed25519 base point (x,4/5) with x positive.
-//
-// Preconditions:
-//   a[31] <= 127
-void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t *a) {
-  signed char e[64];
-  signed char carry;
-  ge_p1p1 r;
-  ge_p2 s;
-  ge_precomp t;
-  int i;
-
-  for (i = 0; i < 32; ++i) {
-    e[2 * i + 0] = (a[i] >> 0) & 15;
-    e[2 * i + 1] = (a[i] >> 4) & 15;
-  }
-  // each e[i] is between 0 and 15
-  // e[63] is between 0 and 7
-
-  carry = 0;
-  for (i = 0; i < 63; ++i) {
-    e[i] += carry;
-    carry = e[i] + 8;
-    carry >>= 4;
-    e[i] -= carry << 4;
-  }
-  e[63] += carry;
-  // each e[i] is between -8 and 8
-
-  ge_p3_0(h);
-  for (i = 1; i < 64; i += 2) {
-    table_select(&t, i / 2, e[i]);
-    ge_madd(&r, h, &t);
-    x25519_ge_p1p1_to_p3(h, &r);
-  }
-
-  ge_p3_dbl(&r, h);
-  x25519_ge_p1p1_to_p2(&s, &r);
-  ge_p2_dbl(&r, &s);
-  x25519_ge_p1p1_to_p2(&s, &r);
-  ge_p2_dbl(&r, &s);
-  x25519_ge_p1p1_to_p2(&s, &r);
-  ge_p2_dbl(&r, &s);
-  x25519_ge_p1p1_to_p3(h, &r);
-
-  for (i = 0; i < 64; i += 2) {
-    table_select(&t, i / 2, e[i]);
-    ge_madd(&r, h, &t);
-    x25519_ge_p1p1_to_p3(h, &r);
-  }
-}
-
-#endif
-
-static void cmov_cached(ge_cached *t, ge_cached *u, uint8_t b) {
-  fe_cmov(t->YplusX, u->YplusX, b);
-  fe_cmov(t->YminusX, u->YminusX, b);
-  fe_cmov(t->Z, u->Z, b);
-  fe_cmov(t->T2d, u->T2d, b);
-}
-
-// r = scalar * A.
-// where a = a[0]+256*a[1]+...+256^31 a[31].
-void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A) {
-  ge_p2 Ai_p2[8];
-  ge_cached Ai[16];
-  ge_p1p1 t;
-
-  ge_cached_0(&Ai[0]);
-  x25519_ge_p3_to_cached(&Ai[1], A);
-  ge_p3_to_p2(&Ai_p2[1], A);
-
-  unsigned i;
-  for (i = 2; i < 16; i += 2) {
-    ge_p2_dbl(&t, &Ai_p2[i / 2]);
-    ge_p1p1_to_cached(&Ai[i], &t);
-    if (i < 8) {
-      x25519_ge_p1p1_to_p2(&Ai_p2[i], &t);
-    }
-    x25519_ge_add(&t, A, &Ai[i]);
-    ge_p1p1_to_cached(&Ai[i + 1], &t);
-    if (i < 7) {
-      x25519_ge_p1p1_to_p2(&Ai_p2[i + 1], &t);
-    }
-  }
-
-  ge_p2_0(r);
-  ge_p3 u;
-
-  for (i = 0; i < 256; i += 4) {
-    ge_p2_dbl(&t, r);
-    x25519_ge_p1p1_to_p2(r, &t);
-    ge_p2_dbl(&t, r);
-    x25519_ge_p1p1_to_p2(r, &t);
-    ge_p2_dbl(&t, r);
-    x25519_ge_p1p1_to_p2(r, &t);
-    ge_p2_dbl(&t, r);
-    x25519_ge_p1p1_to_p3(&u, &t);
-
-    uint8_t index = scalar[31 - i/8];
-    index >>= 4 - (i & 4);
-    index &= 0xf;
-
-    unsigned j;
-    ge_cached selected;
-    ge_cached_0(&selected);
-    for (j = 0; j < 16; j++) {
-      cmov_cached(&selected, &Ai[j], equal(j, index));
-    }
-
-    x25519_ge_add(&t, &u, &selected);
-    x25519_ge_p1p1_to_p2(r, &t);
-  }
-}
-
-static void slide(signed char *r, const uint8_t *a) {
-  int i;
-  int b;
-  int k;
-
-  for (i = 0; i < 256; ++i) {
-    r[i] = 1 & (a[i >> 3] >> (i & 7));
-  }
-
-  for (i = 0; i < 256; ++i) {
-    if (r[i]) {
-      for (b = 1; b <= 6 && i + b < 256; ++b) {
-        if (r[i + b]) {
-          if (r[i] + (r[i + b] << b) <= 15) {
-            r[i] += r[i + b] << b;
-            r[i + b] = 0;
-          } else if (r[i] - (r[i + b] << b) >= -15) {
-            r[i] -= r[i + b] << b;
-            for (k = i + b; k < 256; ++k) {
-              if (!r[k]) {
-                r[k] = 1;
-                break;
-              }
-              r[k] = 0;
-            }
-          } else {
-            break;
-          }
-        }
-      }
-    }
-  }
-}
-
-static const ge_precomp Bi[8] = {
-    {
-        {25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626,
-         -11754271, -6079156, 2047605},
-        {-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692,
-         5043384, 19500929, -15469378},
-        {-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919,
-         11864899, -24514362, -4438546},
-    },
-    {
-        {15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600,
-         -14772189, 28944400, -1550024},
-        {16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577,
-         -11775962, 7689662, 11199574},
-        {30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774,
-         10017326, -17749093, -9920357},
-    },
-    {
-        {10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885,
-         14515107, -15438304, 10819380},
-        {4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668,
-         12483688, -12668491, 5581306},
-        {19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350,
-         13850243, -23678021, -15815942},
-    },
-    {
-        {5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852,
-         5230134, -23952439, -15175766},
-        {-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025,
-         16520125, 30598449, 7715701},
-        {28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660,
-         1370708, 29794553, -1409300},
-    },
-    {
-        {-22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211,
-         -1361450, -13062696, 13821877},
-        {-6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028,
-         -7212327, 18853322, -14220951},
-        {4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358,
-         -10431137, 2207753, -3209784},
-    },
-    {
-        {-25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364,
-         -663000, -31111463, -16132436},
-        {25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789,
-         15725684, 171356, 6466918},
-        {23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339,
-         -14088058, -30714912, 16193877},
-    },
-    {
-        {-33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398,
-         4729455, -18074513, 9256800},
-        {-25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405,
-         9761698, -19827198, 630305},
-        {-13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551,
-         -15960994, -2449256, -14291300},
-    },
-    {
-        {-3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575,
-         15033784, 25105118, -7894876},
-        {-24326370, 15950226, -31801215, -14592823, -11662737, -5090925,
-         1573892, -2625887, 2198790, -15804619},
-        {-3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022,
-         -16236442, -32461234, -12290683},
-    },
-};
-
-// r = a * A + b * B
-// where a = a[0]+256*a[1]+...+256^31 a[31].
-// and b = b[0]+256*b[1]+...+256^31 b[31].
-// B is the Ed25519 base point (x,4/5) with x positive.
-static void ge_double_scalarmult_vartime(ge_p2 *r, const uint8_t *a,
-                                         const ge_p3 *A, const uint8_t *b) {
-  signed char aslide[256];
-  signed char bslide[256];
-  ge_cached Ai[8];  // A,3A,5A,7A,9A,11A,13A,15A
-  ge_p1p1 t;
-  ge_p3 u;
-  ge_p3 A2;
-  int i;
-
-  slide(aslide, a);
-  slide(bslide, b);
-
-  x25519_ge_p3_to_cached(&Ai[0], A);
-  ge_p3_dbl(&t, A);
-  x25519_ge_p1p1_to_p3(&A2, &t);
-  x25519_ge_add(&t, &A2, &Ai[0]);
-  x25519_ge_p1p1_to_p3(&u, &t);
-  x25519_ge_p3_to_cached(&Ai[1], &u);
-  x25519_ge_add(&t, &A2, &Ai[1]);
-  x25519_ge_p1p1_to_p3(&u, &t);
-  x25519_ge_p3_to_cached(&Ai[2], &u);
-  x25519_ge_add(&t, &A2, &Ai[2]);
-  x25519_ge_p1p1_to_p3(&u, &t);
-  x25519_ge_p3_to_cached(&Ai[3], &u);
-  x25519_ge_add(&t, &A2, &Ai[3]);
-  x25519_ge_p1p1_to_p3(&u, &t);
-  x25519_ge_p3_to_cached(&Ai[4], &u);
-  x25519_ge_add(&t, &A2, &Ai[4]);
-  x25519_ge_p1p1_to_p3(&u, &t);
-  x25519_ge_p3_to_cached(&Ai[5], &u);
-  x25519_ge_add(&t, &A2, &Ai[5]);
-  x25519_ge_p1p1_to_p3(&u, &t);
-  x25519_ge_p3_to_cached(&Ai[6], &u);
-  x25519_ge_add(&t, &A2, &Ai[6]);
-  x25519_ge_p1p1_to_p3(&u, &t);
-  x25519_ge_p3_to_cached(&Ai[7], &u);
-
-  ge_p2_0(r);
-
-  for (i = 255; i >= 0; --i) {
-    if (aslide[i] || bslide[i]) {
-      break;
-    }
-  }
-
-  for (; i >= 0; --i) {
-    ge_p2_dbl(&t, r);
-
-    if (aslide[i] > 0) {
-      x25519_ge_p1p1_to_p3(&u, &t);
-      x25519_ge_add(&t, &u, &Ai[aslide[i] / 2]);
-    } else if (aslide[i] < 0) {
-      x25519_ge_p1p1_to_p3(&u, &t);
-      x25519_ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
-    }
-
-    if (bslide[i] > 0) {
-      x25519_ge_p1p1_to_p3(&u, &t);
-      ge_madd(&t, &u, &Bi[bslide[i] / 2]);
-    } else if (bslide[i] < 0) {
-      x25519_ge_p1p1_to_p3(&u, &t);
-      ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
-    }
-
-    x25519_ge_p1p1_to_p2(r, &t);
-  }
-}
-
-// The set of scalars is \Z/l
-// where l = 2^252 + 27742317777372353535851937790883648493.
-
-// Input:
-//   s[0]+256*s[1]+...+256^63*s[63] = s
-//
-// Output:
-//   s[0]+256*s[1]+...+256^31*s[31] = s mod l
-//   where l = 2^252 + 27742317777372353535851937790883648493.
-//   Overwrites s in place.
-void x25519_sc_reduce(uint8_t *s) {
-  int64_t s0 = 2097151 & load_3(s);
-  int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
-  int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
-  int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
-  int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
-  int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
-  int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
-  int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
-  int64_t s8 = 2097151 & load_3(s + 21);
-  int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
-  int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
-  int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
-  int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
-  int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
-  int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
-  int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
-  int64_t s16 = 2097151 & load_3(s + 42);
-  int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
-  int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
-  int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
-  int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
-  int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
-  int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
-  int64_t s23 = (load_4(s + 60) >> 3);
-  int64_t carry0;
-  int64_t carry1;
-  int64_t carry2;
-  int64_t carry3;
-  int64_t carry4;
-  int64_t carry5;
-  int64_t carry6;
-  int64_t carry7;
-  int64_t carry8;
-  int64_t carry9;
-  int64_t carry10;
-  int64_t carry11;
-  int64_t carry12;
-  int64_t carry13;
-  int64_t carry14;
-  int64_t carry15;
-  int64_t carry16;
-
-  s11 += s23 * 666643;
-  s12 += s23 * 470296;
-  s13 += s23 * 654183;
-  s14 -= s23 * 997805;
-  s15 += s23 * 136657;
-  s16 -= s23 * 683901;
-  s23 = 0;
-
-  s10 += s22 * 666643;
-  s11 += s22 * 470296;
-  s12 += s22 * 654183;
-  s13 -= s22 * 997805;
-  s14 += s22 * 136657;
-  s15 -= s22 * 683901;
-  s22 = 0;
-
-  s9 += s21 * 666643;
-  s10 += s21 * 470296;
-  s11 += s21 * 654183;
-  s12 -= s21 * 997805;
-  s13 += s21 * 136657;
-  s14 -= s21 * 683901;
-  s21 = 0;
-
-  s8 += s20 * 666643;
-  s9 += s20 * 470296;
-  s10 += s20 * 654183;
-  s11 -= s20 * 997805;
-  s12 += s20 * 136657;
-  s13 -= s20 * 683901;
-  s20 = 0;
-
-  s7 += s19 * 666643;
-  s8 += s19 * 470296;
-  s9 += s19 * 654183;
-  s10 -= s19 * 997805;
-  s11 += s19 * 136657;
-  s12 -= s19 * 683901;
-  s19 = 0;
-
-  s6 += s18 * 666643;
-  s7 += s18 * 470296;
-  s8 += s18 * 654183;
-  s9 -= s18 * 997805;
-  s10 += s18 * 136657;
-  s11 -= s18 * 683901;
-  s18 = 0;
-
-  carry6 = (s6 + (1 << 20)) >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry8 = (s8 + (1 << 20)) >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry10 = (s10 + (1 << 20)) >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-  carry12 = (s12 + (1 << 20)) >> 21;
-  s13 += carry12;
-  s12 -= carry12 << 21;
-  carry14 = (s14 + (1 << 20)) >> 21;
-  s15 += carry14;
-  s14 -= carry14 << 21;
-  carry16 = (s16 + (1 << 20)) >> 21;
-  s17 += carry16;
-  s16 -= carry16 << 21;
-
-  carry7 = (s7 + (1 << 20)) >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry9 = (s9 + (1 << 20)) >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry11 = (s11 + (1 << 20)) >> 21;
-  s12 += carry11;
-  s11 -= carry11 << 21;
-  carry13 = (s13 + (1 << 20)) >> 21;
-  s14 += carry13;
-  s13 -= carry13 << 21;
-  carry15 = (s15 + (1 << 20)) >> 21;
-  s16 += carry15;
-  s15 -= carry15 << 21;
-
-  s5 += s17 * 666643;
-  s6 += s17 * 470296;
-  s7 += s17 * 654183;
-  s8 -= s17 * 997805;
-  s9 += s17 * 136657;
-  s10 -= s17 * 683901;
-  s17 = 0;
-
-  s4 += s16 * 666643;
-  s5 += s16 * 470296;
-  s6 += s16 * 654183;
-  s7 -= s16 * 997805;
-  s8 += s16 * 136657;
-  s9 -= s16 * 683901;
-  s16 = 0;
-
-  s3 += s15 * 666643;
-  s4 += s15 * 470296;
-  s5 += s15 * 654183;
-  s6 -= s15 * 997805;
-  s7 += s15 * 136657;
-  s8 -= s15 * 683901;
-  s15 = 0;
-
-  s2 += s14 * 666643;
-  s3 += s14 * 470296;
-  s4 += s14 * 654183;
-  s5 -= s14 * 997805;
-  s6 += s14 * 136657;
-  s7 -= s14 * 683901;
-  s14 = 0;
-
-  s1 += s13 * 666643;
-  s2 += s13 * 470296;
-  s3 += s13 * 654183;
-  s4 -= s13 * 997805;
-  s5 += s13 * 136657;
-  s6 -= s13 * 683901;
-  s13 = 0;
-
-  s0 += s12 * 666643;
-  s1 += s12 * 470296;
-  s2 += s12 * 654183;
-  s3 -= s12 * 997805;
-  s4 += s12 * 136657;
-  s5 -= s12 * 683901;
-  s12 = 0;
-
-  carry0 = (s0 + (1 << 20)) >> 21;
-  s1 += carry0;
-  s0 -= carry0 << 21;
-  carry2 = (s2 + (1 << 20)) >> 21;
-  s3 += carry2;
-  s2 -= carry2 << 21;
-  carry4 = (s4 + (1 << 20)) >> 21;
-  s5 += carry4;
-  s4 -= carry4 << 21;
-  carry6 = (s6 + (1 << 20)) >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry8 = (s8 + (1 << 20)) >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry10 = (s10 + (1 << 20)) >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-
-  carry1 = (s1 + (1 << 20)) >> 21;
-  s2 += carry1;
-  s1 -= carry1 << 21;
-  carry3 = (s3 + (1 << 20)) >> 21;
-  s4 += carry3;
-  s3 -= carry3 << 21;
-  carry5 = (s5 + (1 << 20)) >> 21;
-  s6 += carry5;
-  s5 -= carry5 << 21;
-  carry7 = (s7 + (1 << 20)) >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry9 = (s9 + (1 << 20)) >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry11 = (s11 + (1 << 20)) >> 21;
-  s12 += carry11;
-  s11 -= carry11 << 21;
-
-  s0 += s12 * 666643;
-  s1 += s12 * 470296;
-  s2 += s12 * 654183;
-  s3 -= s12 * 997805;
-  s4 += s12 * 136657;
-  s5 -= s12 * 683901;
-  s12 = 0;
-
-  carry0 = s0 >> 21;
-  s1 += carry0;
-  s0 -= carry0 << 21;
-  carry1 = s1 >> 21;
-  s2 += carry1;
-  s1 -= carry1 << 21;
-  carry2 = s2 >> 21;
-  s3 += carry2;
-  s2 -= carry2 << 21;
-  carry3 = s3 >> 21;
-  s4 += carry3;
-  s3 -= carry3 << 21;
-  carry4 = s4 >> 21;
-  s5 += carry4;
-  s4 -= carry4 << 21;
-  carry5 = s5 >> 21;
-  s6 += carry5;
-  s5 -= carry5 << 21;
-  carry6 = s6 >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry7 = s7 >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry8 = s8 >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry9 = s9 >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry10 = s10 >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-  carry11 = s11 >> 21;
-  s12 += carry11;
-  s11 -= carry11 << 21;
-
-  s0 += s12 * 666643;
-  s1 += s12 * 470296;
-  s2 += s12 * 654183;
-  s3 -= s12 * 997805;
-  s4 += s12 * 136657;
-  s5 -= s12 * 683901;
-  s12 = 0;
-
-  carry0 = s0 >> 21;
-  s1 += carry0;
-  s0 -= carry0 << 21;
-  carry1 = s1 >> 21;
-  s2 += carry1;
-  s1 -= carry1 << 21;
-  carry2 = s2 >> 21;
-  s3 += carry2;
-  s2 -= carry2 << 21;
-  carry3 = s3 >> 21;
-  s4 += carry3;
-  s3 -= carry3 << 21;
-  carry4 = s4 >> 21;
-  s5 += carry4;
-  s4 -= carry4 << 21;
-  carry5 = s5 >> 21;
-  s6 += carry5;
-  s5 -= carry5 << 21;
-  carry6 = s6 >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry7 = s7 >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry8 = s8 >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry9 = s9 >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry10 = s10 >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-
-  s[0] = s0 >> 0;
-  s[1] = s0 >> 8;
-  s[2] = (s0 >> 16) | (s1 << 5);
-  s[3] = s1 >> 3;
-  s[4] = s1 >> 11;
-  s[5] = (s1 >> 19) | (s2 << 2);
-  s[6] = s2 >> 6;
-  s[7] = (s2 >> 14) | (s3 << 7);
-  s[8] = s3 >> 1;
-  s[9] = s3 >> 9;
-  s[10] = (s3 >> 17) | (s4 << 4);
-  s[11] = s4 >> 4;
-  s[12] = s4 >> 12;
-  s[13] = (s4 >> 20) | (s5 << 1);
-  s[14] = s5 >> 7;
-  s[15] = (s5 >> 15) | (s6 << 6);
-  s[16] = s6 >> 2;
-  s[17] = s6 >> 10;
-  s[18] = (s6 >> 18) | (s7 << 3);
-  s[19] = s7 >> 5;
-  s[20] = s7 >> 13;
-  s[21] = s8 >> 0;
-  s[22] = s8 >> 8;
-  s[23] = (s8 >> 16) | (s9 << 5);
-  s[24] = s9 >> 3;
-  s[25] = s9 >> 11;
-  s[26] = (s9 >> 19) | (s10 << 2);
-  s[27] = s10 >> 6;
-  s[28] = (s10 >> 14) | (s11 << 7);
-  s[29] = s11 >> 1;
-  s[30] = s11 >> 9;
-  s[31] = s11 >> 17;
-}
-
-// Input:
-//   a[0]+256*a[1]+...+256^31*a[31] = a
-//   b[0]+256*b[1]+...+256^31*b[31] = b
-//   c[0]+256*c[1]+...+256^31*c[31] = c
-//
-// Output:
-//   s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
-//   where l = 2^252 + 27742317777372353535851937790883648493.
-static void sc_muladd(uint8_t *s, const uint8_t *a, const uint8_t *b,
-                      const uint8_t *c) {
-  int64_t a0 = 2097151 & load_3(a);
-  int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
-  int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
-  int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
-  int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
-  int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
-  int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
-  int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
-  int64_t a8 = 2097151 & load_3(a + 21);
-  int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
-  int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
-  int64_t a11 = (load_4(a + 28) >> 7);
-  int64_t b0 = 2097151 & load_3(b);
-  int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
-  int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
-  int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
-  int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
-  int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
-  int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
-  int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
-  int64_t b8 = 2097151 & load_3(b + 21);
-  int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
-  int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
-  int64_t b11 = (load_4(b + 28) >> 7);
-  int64_t c0 = 2097151 & load_3(c);
-  int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
-  int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
-  int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
-  int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
-  int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
-  int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
-  int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
-  int64_t c8 = 2097151 & load_3(c + 21);
-  int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
-  int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
-  int64_t c11 = (load_4(c + 28) >> 7);
-  int64_t s0;
-  int64_t s1;
-  int64_t s2;
-  int64_t s3;
-  int64_t s4;
-  int64_t s5;
-  int64_t s6;
-  int64_t s7;
-  int64_t s8;
-  int64_t s9;
-  int64_t s10;
-  int64_t s11;
-  int64_t s12;
-  int64_t s13;
-  int64_t s14;
-  int64_t s15;
-  int64_t s16;
-  int64_t s17;
-  int64_t s18;
-  int64_t s19;
-  int64_t s20;
-  int64_t s21;
-  int64_t s22;
-  int64_t s23;
-  int64_t carry0;
-  int64_t carry1;
-  int64_t carry2;
-  int64_t carry3;
-  int64_t carry4;
-  int64_t carry5;
-  int64_t carry6;
-  int64_t carry7;
-  int64_t carry8;
-  int64_t carry9;
-  int64_t carry10;
-  int64_t carry11;
-  int64_t carry12;
-  int64_t carry13;
-  int64_t carry14;
-  int64_t carry15;
-  int64_t carry16;
-  int64_t carry17;
-  int64_t carry18;
-  int64_t carry19;
-  int64_t carry20;
-  int64_t carry21;
-  int64_t carry22;
-
-  s0 = c0 + a0 * b0;
-  s1 = c1 + a0 * b1 + a1 * b0;
-  s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;
-  s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
-  s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
-  s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
-  s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0;
-  s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
-       a6 * b1 + a7 * b0;
-  s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
-       a6 * b2 + a7 * b1 + a8 * b0;
-  s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
-       a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
-  s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
-        a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
-  s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
-        a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
-  s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 +
-        a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
-  s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 +
-        a9 * b4 + a10 * b3 + a11 * b2;
-  s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 +
-        a10 * b4 + a11 * b3;
-  s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 +
-        a11 * b4;
-  s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
-  s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
-  s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
-  s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
-  s20 = a9 * b11 + a10 * b10 + a11 * b9;
-  s21 = a10 * b11 + a11 * b10;
-  s22 = a11 * b11;
-  s23 = 0;
-
-  carry0 = (s0 + (1 << 20)) >> 21;
-  s1 += carry0;
-  s0 -= carry0 << 21;
-  carry2 = (s2 + (1 << 20)) >> 21;
-  s3 += carry2;
-  s2 -= carry2 << 21;
-  carry4 = (s4 + (1 << 20)) >> 21;
-  s5 += carry4;
-  s4 -= carry4 << 21;
-  carry6 = (s6 + (1 << 20)) >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry8 = (s8 + (1 << 20)) >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry10 = (s10 + (1 << 20)) >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-  carry12 = (s12 + (1 << 20)) >> 21;
-  s13 += carry12;
-  s12 -= carry12 << 21;
-  carry14 = (s14 + (1 << 20)) >> 21;
-  s15 += carry14;
-  s14 -= carry14 << 21;
-  carry16 = (s16 + (1 << 20)) >> 21;
-  s17 += carry16;
-  s16 -= carry16 << 21;
-  carry18 = (s18 + (1 << 20)) >> 21;
-  s19 += carry18;
-  s18 -= carry18 << 21;
-  carry20 = (s20 + (1 << 20)) >> 21;
-  s21 += carry20;
-  s20 -= carry20 << 21;
-  carry22 = (s22 + (1 << 20)) >> 21;
-  s23 += carry22;
-  s22 -= carry22 << 21;
-
-  carry1 = (s1 + (1 << 20)) >> 21;
-  s2 += carry1;
-  s1 -= carry1 << 21;
-  carry3 = (s3 + (1 << 20)) >> 21;
-  s4 += carry3;
-  s3 -= carry3 << 21;
-  carry5 = (s5 + (1 << 20)) >> 21;
-  s6 += carry5;
-  s5 -= carry5 << 21;
-  carry7 = (s7 + (1 << 20)) >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry9 = (s9 + (1 << 20)) >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry11 = (s11 + (1 << 20)) >> 21;
-  s12 += carry11;
-  s11 -= carry11 << 21;
-  carry13 = (s13 + (1 << 20)) >> 21;
-  s14 += carry13;
-  s13 -= carry13 << 21;
-  carry15 = (s15 + (1 << 20)) >> 21;
-  s16 += carry15;
-  s15 -= carry15 << 21;
-  carry17 = (s17 + (1 << 20)) >> 21;
-  s18 += carry17;
-  s17 -= carry17 << 21;
-  carry19 = (s19 + (1 << 20)) >> 21;
-  s20 += carry19;
-  s19 -= carry19 << 21;
-  carry21 = (s21 + (1 << 20)) >> 21;
-  s22 += carry21;
-  s21 -= carry21 << 21;
-
-  s11 += s23 * 666643;
-  s12 += s23 * 470296;
-  s13 += s23 * 654183;
-  s14 -= s23 * 997805;
-  s15 += s23 * 136657;
-  s16 -= s23 * 683901;
-  s23 = 0;
-
-  s10 += s22 * 666643;
-  s11 += s22 * 470296;
-  s12 += s22 * 654183;
-  s13 -= s22 * 997805;
-  s14 += s22 * 136657;
-  s15 -= s22 * 683901;
-  s22 = 0;
-
-  s9 += s21 * 666643;
-  s10 += s21 * 470296;
-  s11 += s21 * 654183;
-  s12 -= s21 * 997805;
-  s13 += s21 * 136657;
-  s14 -= s21 * 683901;
-  s21 = 0;
-
-  s8 += s20 * 666643;
-  s9 += s20 * 470296;
-  s10 += s20 * 654183;
-  s11 -= s20 * 997805;
-  s12 += s20 * 136657;
-  s13 -= s20 * 683901;
-  s20 = 0;
-
-  s7 += s19 * 666643;
-  s8 += s19 * 470296;
-  s9 += s19 * 654183;
-  s10 -= s19 * 997805;
-  s11 += s19 * 136657;
-  s12 -= s19 * 683901;
-  s19 = 0;
-
-  s6 += s18 * 666643;
-  s7 += s18 * 470296;
-  s8 += s18 * 654183;
-  s9 -= s18 * 997805;
-  s10 += s18 * 136657;
-  s11 -= s18 * 683901;
-  s18 = 0;
-
-  carry6 = (s6 + (1 << 20)) >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry8 = (s8 + (1 << 20)) >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry10 = (s10 + (1 << 20)) >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-  carry12 = (s12 + (1 << 20)) >> 21;
-  s13 += carry12;
-  s12 -= carry12 << 21;
-  carry14 = (s14 + (1 << 20)) >> 21;
-  s15 += carry14;
-  s14 -= carry14 << 21;
-  carry16 = (s16 + (1 << 20)) >> 21;
-  s17 += carry16;
-  s16 -= carry16 << 21;
-
-  carry7 = (s7 + (1 << 20)) >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry9 = (s9 + (1 << 20)) >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry11 = (s11 + (1 << 20)) >> 21;
-  s12 += carry11;
-  s11 -= carry11 << 21;
-  carry13 = (s13 + (1 << 20)) >> 21;
-  s14 += carry13;
-  s13 -= carry13 << 21;
-  carry15 = (s15 + (1 << 20)) >> 21;
-  s16 += carry15;
-  s15 -= carry15 << 21;
-
-  s5 += s17 * 666643;
-  s6 += s17 * 470296;
-  s7 += s17 * 654183;
-  s8 -= s17 * 997805;
-  s9 += s17 * 136657;
-  s10 -= s17 * 683901;
-  s17 = 0;
-
-  s4 += s16 * 666643;
-  s5 += s16 * 470296;
-  s6 += s16 * 654183;
-  s7 -= s16 * 997805;
-  s8 += s16 * 136657;
-  s9 -= s16 * 683901;
-  s16 = 0;
-
-  s3 += s15 * 666643;
-  s4 += s15 * 470296;
-  s5 += s15 * 654183;
-  s6 -= s15 * 997805;
-  s7 += s15 * 136657;
-  s8 -= s15 * 683901;
-  s15 = 0;
-
-  s2 += s14 * 666643;
-  s3 += s14 * 470296;
-  s4 += s14 * 654183;
-  s5 -= s14 * 997805;
-  s6 += s14 * 136657;
-  s7 -= s14 * 683901;
-  s14 = 0;
-
-  s1 += s13 * 666643;
-  s2 += s13 * 470296;
-  s3 += s13 * 654183;
-  s4 -= s13 * 997805;
-  s5 += s13 * 136657;
-  s6 -= s13 * 683901;
-  s13 = 0;
-
-  s0 += s12 * 666643;
-  s1 += s12 * 470296;
-  s2 += s12 * 654183;
-  s3 -= s12 * 997805;
-  s4 += s12 * 136657;
-  s5 -= s12 * 683901;
-  s12 = 0;
-
-  carry0 = (s0 + (1 << 20)) >> 21;
-  s1 += carry0;
-  s0 -= carry0 << 21;
-  carry2 = (s2 + (1 << 20)) >> 21;
-  s3 += carry2;
-  s2 -= carry2 << 21;
-  carry4 = (s4 + (1 << 20)) >> 21;
-  s5 += carry4;
-  s4 -= carry4 << 21;
-  carry6 = (s6 + (1 << 20)) >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry8 = (s8 + (1 << 20)) >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry10 = (s10 + (1 << 20)) >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-
-  carry1 = (s1 + (1 << 20)) >> 21;
-  s2 += carry1;
-  s1 -= carry1 << 21;
-  carry3 = (s3 + (1 << 20)) >> 21;
-  s4 += carry3;
-  s3 -= carry3 << 21;
-  carry5 = (s5 + (1 << 20)) >> 21;
-  s6 += carry5;
-  s5 -= carry5 << 21;
-  carry7 = (s7 + (1 << 20)) >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry9 = (s9 + (1 << 20)) >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry11 = (s11 + (1 << 20)) >> 21;
-  s12 += carry11;
-  s11 -= carry11 << 21;
-
-  s0 += s12 * 666643;
-  s1 += s12 * 470296;
-  s2 += s12 * 654183;
-  s3 -= s12 * 997805;
-  s4 += s12 * 136657;
-  s5 -= s12 * 683901;
-  s12 = 0;
-
-  carry0 = s0 >> 21;
-  s1 += carry0;
-  s0 -= carry0 << 21;
-  carry1 = s1 >> 21;
-  s2 += carry1;
-  s1 -= carry1 << 21;
-  carry2 = s2 >> 21;
-  s3 += carry2;
-  s2 -= carry2 << 21;
-  carry3 = s3 >> 21;
-  s4 += carry3;
-  s3 -= carry3 << 21;
-  carry4 = s4 >> 21;
-  s5 += carry4;
-  s4 -= carry4 << 21;
-  carry5 = s5 >> 21;
-  s6 += carry5;
-  s5 -= carry5 << 21;
-  carry6 = s6 >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry7 = s7 >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry8 = s8 >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry9 = s9 >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry10 = s10 >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-  carry11 = s11 >> 21;
-  s12 += carry11;
-  s11 -= carry11 << 21;
-
-  s0 += s12 * 666643;
-  s1 += s12 * 470296;
-  s2 += s12 * 654183;
-  s3 -= s12 * 997805;
-  s4 += s12 * 136657;
-  s5 -= s12 * 683901;
-  s12 = 0;
-
-  carry0 = s0 >> 21;
-  s1 += carry0;
-  s0 -= carry0 << 21;
-  carry1 = s1 >> 21;
-  s2 += carry1;
-  s1 -= carry1 << 21;
-  carry2 = s2 >> 21;
-  s3 += carry2;
-  s2 -= carry2 << 21;
-  carry3 = s3 >> 21;
-  s4 += carry3;
-  s3 -= carry3 << 21;
-  carry4 = s4 >> 21;
-  s5 += carry4;
-  s4 -= carry4 << 21;
-  carry5 = s5 >> 21;
-  s6 += carry5;
-  s5 -= carry5 << 21;
-  carry6 = s6 >> 21;
-  s7 += carry6;
-  s6 -= carry6 << 21;
-  carry7 = s7 >> 21;
-  s8 += carry7;
-  s7 -= carry7 << 21;
-  carry8 = s8 >> 21;
-  s9 += carry8;
-  s8 -= carry8 << 21;
-  carry9 = s9 >> 21;
-  s10 += carry9;
-  s9 -= carry9 << 21;
-  carry10 = s10 >> 21;
-  s11 += carry10;
-  s10 -= carry10 << 21;
-
-  s[0] = s0 >> 0;
-  s[1] = s0 >> 8;
-  s[2] = (s0 >> 16) | (s1 << 5);
-  s[3] = s1 >> 3;
-  s[4] = s1 >> 11;
-  s[5] = (s1 >> 19) | (s2 << 2);
-  s[6] = s2 >> 6;
-  s[7] = (s2 >> 14) | (s3 << 7);
-  s[8] = s3 >> 1;
-  s[9] = s3 >> 9;
-  s[10] = (s3 >> 17) | (s4 << 4);
-  s[11] = s4 >> 4;
-  s[12] = s4 >> 12;
-  s[13] = (s4 >> 20) | (s5 << 1);
-  s[14] = s5 >> 7;
-  s[15] = (s5 >> 15) | (s6 << 6);
-  s[16] = s6 >> 2;
-  s[17] = s6 >> 10;
-  s[18] = (s6 >> 18) | (s7 << 3);
-  s[19] = s7 >> 5;
-  s[20] = s7 >> 13;
-  s[21] = s8 >> 0;
-  s[22] = s8 >> 8;
-  s[23] = (s8 >> 16) | (s9 << 5);
-  s[24] = s9 >> 3;
-  s[25] = s9 >> 11;
-  s[26] = (s9 >> 19) | (s10 << 2);
-  s[27] = s10 >> 6;
-  s[28] = (s10 >> 14) | (s11 << 7);
-  s[29] = s11 >> 1;
-  s[30] = s11 >> 9;
-  s[31] = s11 >> 17;
-}
-
-void ED25519_keypair(uint8_t out_public_key[32], uint8_t out_private_key[64]) {
-  uint8_t seed[32];
-  RAND_bytes(seed, 32);
-  ED25519_keypair_from_seed(out_public_key, out_private_key, seed);
-}
-
-int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,
-                 const uint8_t private_key[64]) {
-  uint8_t az[SHA512_DIGEST_LENGTH];
-  SHA512(private_key, 32, az);
-
-  az[0] &= 248;
-  az[31] &= 63;
-  az[31] |= 64;
-
-  SHA512_CTX hash_ctx;
-  SHA512_Init(&hash_ctx);
-  SHA512_Update(&hash_ctx, az + 32, 32);
-  SHA512_Update(&hash_ctx, message, message_len);
-  uint8_t nonce[SHA512_DIGEST_LENGTH];
-  SHA512_Final(nonce, &hash_ctx);
-
-  x25519_sc_reduce(nonce);
-  ge_p3 R;
-  x25519_ge_scalarmult_base(&R, nonce);
-  ge_p3_tobytes(out_sig, &R);
-
-  SHA512_Init(&hash_ctx);
-  SHA512_Update(&hash_ctx, out_sig, 32);
-  SHA512_Update(&hash_ctx, private_key + 32, 32);
-  SHA512_Update(&hash_ctx, message, message_len);
-  uint8_t hram[SHA512_DIGEST_LENGTH];
-  SHA512_Final(hram, &hash_ctx);
-
-  x25519_sc_reduce(hram);
-  sc_muladd(out_sig + 32, hram, az, nonce);
-
-  return 1;
-}
-
-int ED25519_verify(const uint8_t *message, size_t message_len,
-                   const uint8_t signature[64], const uint8_t public_key[32]) {
-  ge_p3 A;
-  if ((signature[63] & 224) != 0 ||
-      x25519_ge_frombytes_vartime(&A, public_key) != 0) {
-    return 0;
-  }
-
-  fe_neg(A.X, A.X);
-  fe_neg(A.T, A.T);
-
-  uint8_t pkcopy[32];
-  OPENSSL_memcpy(pkcopy, public_key, 32);
-  uint8_t rcopy[32];
-  OPENSSL_memcpy(rcopy, signature, 32);
-  uint8_t scopy[32];
-  OPENSSL_memcpy(scopy, signature + 32, 32);
-
-  SHA512_CTX hash_ctx;
-  SHA512_Init(&hash_ctx);
-  SHA512_Update(&hash_ctx, signature, 32);
-  SHA512_Update(&hash_ctx, public_key, 32);
-  SHA512_Update(&hash_ctx, message, message_len);
-  uint8_t h[SHA512_DIGEST_LENGTH];
-  SHA512_Final(h, &hash_ctx);
-
-  x25519_sc_reduce(h);
-
-  ge_p2 R;
-  ge_double_scalarmult_vartime(&R, h, &A, scopy);
-
-  uint8_t rcheck[32];
-  x25519_ge_tobytes(rcheck, &R);
-
-  return CRYPTO_memcmp(rcheck, rcopy, sizeof(rcheck)) == 0;
-}
-
-void ED25519_keypair_from_seed(uint8_t out_public_key[32],
-                               uint8_t out_private_key[64],
-                               const uint8_t seed[32]) {
-  uint8_t az[SHA512_DIGEST_LENGTH];
-  SHA512(seed, 32, az);
-
-  az[0] &= 248;
-  az[31] &= 63;
-  az[31] |= 64;
-
-  ge_p3 A;
-  x25519_ge_scalarmult_base(&A, az);
-  ge_p3_tobytes(out_public_key, &A);
-
-  OPENSSL_memcpy(out_private_key, seed, 32);
-  OPENSSL_memcpy(out_private_key + 32, out_public_key, 32);
-}
-
-
-#if defined(BORINGSSL_X25519_X86_64)
-
-static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
-                               const uint8_t point[32]) {
-  x25519_x86_64(out, scalar, point);
-}
-
-#else
-
-// Replace (f,g) with (g,f) if b == 1;
-// replace (f,g) with (f,g) if b == 0.
-//
-// Preconditions: b in {0,1}.
-static void fe_cswap(fe f, fe g, unsigned int b) {
-  b = 0-b;
-  unsigned i;
-  for (i = 0; i < 10; i++) {
-    int32_t x = f[i] ^ g[i];
-    x &= b;
-    f[i] ^= x;
-    g[i] ^= x;
-  }
-}
-
-// h = f * 121666
-// Can overlap h with f.
-//
-// Preconditions:
-//    |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
-//
-// Postconditions:
-//    |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
-static void fe_mul121666(fe h, fe f) {
-  int32_t f0 = f[0];
-  int32_t f1 = f[1];
-  int32_t f2 = f[2];
-  int32_t f3 = f[3];
-  int32_t f4 = f[4];
-  int32_t f5 = f[5];
-  int32_t f6 = f[6];
-  int32_t f7 = f[7];
-  int32_t f8 = f[8];
-  int32_t f9 = f[9];
-  int64_t h0 = f0 * (int64_t) 121666;
-  int64_t h1 = f1 * (int64_t) 121666;
-  int64_t h2 = f2 * (int64_t) 121666;
-  int64_t h3 = f3 * (int64_t) 121666;
-  int64_t h4 = f4 * (int64_t) 121666;
-  int64_t h5 = f5 * (int64_t) 121666;
-  int64_t h6 = f6 * (int64_t) 121666;
-  int64_t h7 = f7 * (int64_t) 121666;
-  int64_t h8 = f8 * (int64_t) 121666;
-  int64_t h9 = f9 * (int64_t) 121666;
-  int64_t carry0;
-  int64_t carry1;
-  int64_t carry2;
-  int64_t carry3;
-  int64_t carry4;
-  int64_t carry5;
-  int64_t carry6;
-  int64_t carry7;
-  int64_t carry8;
-  int64_t carry9;
-
-  carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
-  carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
-  carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
-  carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
-  carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
-
-  carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
-  carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
-  carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
-  carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
-  carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
-
-  h[0] = h0;
-  h[1] = h1;
-  h[2] = h2;
-  h[3] = h3;
-  h[4] = h4;
-  h[5] = h5;
-  h[6] = h6;
-  h[7] = h7;
-  h[8] = h8;
-  h[9] = h9;
-}
-
-static void x25519_scalar_mult_generic(uint8_t out[32],
-                                       const uint8_t scalar[32],
-                                       const uint8_t point[32]) {
-  fe x1, x2, z2, x3, z3, tmp0, tmp1;
-
-  uint8_t e[32];
-  OPENSSL_memcpy(e, scalar, 32);
-  e[0] &= 248;
-  e[31] &= 127;
-  e[31] |= 64;
-  fe_frombytes(x1, point);
-  fe_1(x2);
-  fe_0(z2);
-  fe_copy(x3, x1);
-  fe_1(z3);
-
-  unsigned swap = 0;
-  int pos;
-  for (pos = 254; pos >= 0; --pos) {
-    unsigned b = 1 & (e[pos / 8] >> (pos & 7));
-    swap ^= b;
-    fe_cswap(x2, x3, swap);
-    fe_cswap(z2, z3, swap);
-    swap = b;
-    fe_sub(tmp0, x3, z3);
-    fe_sub(tmp1, x2, z2);
-    fe_add(x2, x2, z2);
-    fe_add(z2, x3, z3);
-    fe_mul(z3, tmp0, x2);
-    fe_mul(z2, z2, tmp1);
-    fe_sq(tmp0, tmp1);
-    fe_sq(tmp1, x2);
-    fe_add(x3, z3, z2);
-    fe_sub(z2, z3, z2);
-    fe_mul(x2, tmp1, tmp0);
-    fe_sub(tmp1, tmp1, tmp0);
-    fe_sq(z2, z2);
-    fe_mul121666(z3, tmp1);
-    fe_sq(x3, x3);
-    fe_add(tmp0, tmp0, z3);
-    fe_mul(z3, x1, z2);
-    fe_mul(z2, tmp1, tmp0);
-  }
-  fe_cswap(x2, x3, swap);
-  fe_cswap(z2, z3, swap);
-
-  fe_invert(z2, z2);
-  fe_mul(x2, x2, z2);
-  fe_tobytes(out, x2);
-}
-
-static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
-                               const uint8_t point[32]) {
-#if defined(BORINGSSL_X25519_NEON)
-  if (CRYPTO_is_NEON_capable()) {
-    x25519_NEON(out, scalar, point);
-    return;
-  }
-#endif
-
-  x25519_scalar_mult_generic(out, scalar, point);
-}
-
-#endif  // BORINGSSL_X25519_X86_64
-
-
-void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]) {
-  RAND_bytes(out_private_key, 32);
-
-  // All X25519 implementations should decode scalars correctly (see
-  // https://tools.ietf.org/html/rfc7748#section-5). However, if an
-  // implementation doesn't then it might interoperate with random keys a
-  // fraction of the time because they'll, randomly, happen to be correctly
-  // formed.
-  //
-  // Thus we do the opposite of the masking here to make sure that our private
-  // keys are never correctly masked and so, hopefully, any incorrect
-  // implementations are deterministically broken.
-  //
-  // This does not affect security because, although we're throwing away
-  // entropy, a valid implementation of scalarmult should throw away the exact
-  // same bits anyway.
-  out_private_key[0] |= 7;
-  out_private_key[31] &= 63;
-  out_private_key[31] |= 128;
-
-  X25519_public_from_private(out_public_value, out_private_key);
-}
-
-int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
-           const uint8_t peer_public_value[32]) {
-  static const uint8_t kZeros[32] = {0};
-  x25519_scalar_mult(out_shared_key, private_key, peer_public_value);
-  // The all-zero output results when the input is a point of small order.
-  return CRYPTO_memcmp(kZeros, out_shared_key, 32) != 0;
-}
-
-#if defined(BORINGSSL_X25519_X86_64)
-
-// When |BORINGSSL_X25519_X86_64| is set, base point multiplication is done with
-// the Montgomery ladder because it's faster. Otherwise it's done using the
-// Ed25519 tables.
-
-void X25519_public_from_private(uint8_t out_public_value[32],
-                                const uint8_t private_key[32]) {
-  static const uint8_t kMongomeryBasePoint[32] = {9};
-  x25519_scalar_mult(out_public_value, private_key, kMongomeryBasePoint);
-}
-
-#else
-
-void X25519_public_from_private(uint8_t out_public_value[32],
-                                const uint8_t private_key[32]) {
-#if defined(BORINGSSL_X25519_NEON)
-  if (CRYPTO_is_NEON_capable()) {
-    static const uint8_t kMongomeryBasePoint[32] = {9};
-    x25519_NEON(out_public_value, private_key, kMongomeryBasePoint);
-    return;
-  }
-#endif
-
-  uint8_t e[32];
-  OPENSSL_memcpy(e, private_key, 32);
-  e[0] &= 248;
-  e[31] &= 127;
-  e[31] |= 64;
-
-  ge_p3 A;
-  x25519_ge_scalarmult_base(&A, e);
-
-  // We only need the u-coordinate of the curve25519 point. The map is
-  // u=(y+1)/(1-y). Since y=Y/Z, this gives u=(Z+Y)/(Z-Y).
-  fe zplusy, zminusy, zminusy_inv;
-  fe_add(zplusy, A.Z, A.Y);
-  fe_sub(zminusy, A.Z, A.Y);
-  fe_invert(zminusy_inv, zminusy);
-  fe_mul(zplusy, zplusy, zminusy_inv);
-  fe_tobytes(out_public_value, zplusy);
-}
-
-#endif  // BORINGSSL_X25519_X86_64
diff --git a/src/crypto/curve25519/internal.h b/src/crypto/curve25519/internal.h
deleted file mode 100644
index 9487a6c..0000000
--- a/src/crypto/curve25519/internal.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Copyright (c) 2015, Google Inc.
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
-
-#ifndef OPENSSL_HEADER_CURVE25519_INTERNAL_H
-#define OPENSSL_HEADER_CURVE25519_INTERNAL_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-
-#if defined(OPENSSL_X86_64) && !defined(OPENSSL_SMALL) && \
-    !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_ASM)
-#define BORINGSSL_X25519_X86_64
-
-void x25519_x86_64(uint8_t out[32], const uint8_t scalar[32],
-                   const uint8_t point[32]);
-#endif
-
-
-#if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
-#define BORINGSSL_X25519_NEON
-
-// x25519_NEON is defined in asm/x25519-arm.S.
-void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
-                 const uint8_t point[32]);
-#endif
-
-// fe means field element. Here the field is \Z/(2^255-19). An element t,
-// entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
-// t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on
-// context.
-typedef int32_t fe[10];
-
-/* ge means group element.
-
- * Here the group is the set of pairs (x,y) of field elements (see fe.h)
- * satisfying -x^2 + y^2 = 1 + d x^2y^2
- * where d = -121665/121666.
- *
- * Representations:
- *   ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
- *   ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
- *   ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
- *   ge_precomp (Duif): (y+x,y-x,2dxy) */
-
-typedef struct {
-  fe X;
-  fe Y;
-  fe Z;
-} ge_p2;
-
-typedef struct {
-  fe X;
-  fe Y;
-  fe Z;
-  fe T;
-} ge_p3;
-
-typedef struct {
-  fe X;
-  fe Y;
-  fe Z;
-  fe T;
-} ge_p1p1;
-
-typedef struct {
-  fe yplusx;
-  fe yminusx;
-  fe xy2d;
-} ge_precomp;
-
-typedef struct {
-  fe YplusX;
-  fe YminusX;
-  fe Z;
-  fe T2d;
-} ge_cached;
-
-void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h);
-int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
-void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
-void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
-void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
-void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
-void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
-void x25519_ge_scalarmult_small_precomp(
-    ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]);
-void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
-void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
-void x25519_sc_reduce(uint8_t *s);
-
-
-#if defined(__cplusplus)
-}  // extern C
-#endif
-
-#endif  // OPENSSL_HEADER_CURVE25519_INTERNAL_H
diff --git a/src/crypto/curve25519/spake25519.c b/src/crypto/curve25519/spake25519.c
index 8ebedf9..e0ff9ba 100644
--- a/src/crypto/curve25519/spake25519.c
+++ b/src/crypto/curve25519/spake25519.c
@@ -14,6 +14,7 @@
 
 #include <openssl/curve25519.h>
 
+#include <assert.h>
 #include <string.h>
 
 #include <openssl/bytestring.h>
@@ -21,8 +22,8 @@
 #include <openssl/rand.h>
 #include <openssl/sha.h>
 
-#include "internal.h"
 #include "../internal.h"
+#include "../../third_party/fiat/internal.h"
 
 
 // The following precomputation tables are for the following
@@ -43,14 +44,14 @@
 // see curve25519.c in this directory.
 //
 // Exact copies of the source code are kept in bug 27296743.
-//
-// import hashlib
-// import ed25519 as E  # http://ed25519.cr.yp.to/python/ed25519.py
-//
-// SEED_N = 'edwards25519 point generation seed (N)'
-// SEED_M = 'edwards25519 point generation seed (M)'
 
 /*
+import hashlib
+import ed25519 as E  # http://ed25519.cr.yp.to/python/ed25519.py
+
+SEED_N = 'edwards25519 point generation seed (N)'
+SEED_M = 'edwards25519 point generation seed (M)'
+
 def genpoint(seed):
     v = hashlib.sha256(seed).digest()
     it = 1
@@ -72,10 +73,10 @@
 def gentable(P):
     t = []
     for i in range(1,16):
-        k = (i >> 3 & 1) * (1 << 192) + \
-            (i >> 2 & 1) * (1 << 128) + \
-            (i >> 1 & 1) * (1 <<  64) + \
-            (i      & 1)
+        k = ((i >> 3 & 1) * (1 << 192) +
+             (i >> 2 & 1) * (1 << 128) +
+             (i >> 1 & 1) * (1 <<  64) +
+             (i      & 1))
         t.append(E.scalarmult(P, k))
     return ''.join(E.encodeint(x) + E.encodeint(y) for (x,y) in t)
 
@@ -267,25 +268,6 @@
     0xa6, 0x76, 0x81, 0x28, 0xb2, 0x65, 0xe8, 0x47, 0x14, 0xc6, 0x39, 0x06,
 };
 
-enum spake2_state_t {
-  spake2_state_init = 0,
-  spake2_state_msg_generated,
-  spake2_state_key_generated,
-};
-
-struct spake2_ctx_st {
-  uint8_t private_key[32];
-  uint8_t my_msg[32];
-  uint8_t password_scalar[32];
-  uint8_t password_hash[SHA512_DIGEST_LENGTH];
-  uint8_t *my_name;
-  size_t my_name_len;
-  uint8_t *their_name;
-  size_t their_name_len;
-  enum spake2_role_t my_role;
-  enum spake2_state_t state;
-};
-
 SPAKE2_CTX *SPAKE2_CTX_new(enum spake2_role_t my_role,
                            const uint8_t *my_name, size_t my_name_len,
                            const uint8_t *their_name, size_t their_name_len) {
@@ -332,6 +314,48 @@
   }
 }
 
+typedef union {
+  uint8_t bytes[32];
+  uint32_t words[8];
+} scalar;
+
+// kOrder is the order of the prime-order subgroup of curve25519 in
+// little-endian order.
+static const scalar kOrder = {{0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
+                               0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
+                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}};
+
+// scalar_cmov copies |src| to |dest| if |mask| is all ones.
+static void scalar_cmov(scalar *dest, const scalar *src, crypto_word_t mask) {
+  for (size_t i = 0; i < 8; i++) {
+    dest->words[i] =
+        constant_time_select_w(mask, src->words[i], dest->words[i]);
+  }
+}
+
+// scalar_double sets |s| to |2×s|.
+static void scalar_double(scalar *s) {
+  uint32_t carry = 0;
+
+  for (size_t i = 0; i < 8; i++) {
+    const uint32_t carry_out = s->words[i] >> 31;
+    s->words[i] = (s->words[i] << 1) | carry;
+    carry = carry_out;
+  }
+}
+
+// scalar_add sets |dest| to |dest| plus |src|.
+static void scalar_add(scalar *dest, const scalar *src) {
+  uint32_t carry = 0;
+
+  for (size_t i = 0; i < 8; i++) {
+    uint64_t tmp = ((uint64_t)dest->words[i] + src->words[i]) + carry;
+    dest->words[i] = (uint32_t)tmp;
+    carry = (uint32_t)(tmp >> 32);
+  }
+}
+
 int SPAKE2_generate_msg(SPAKE2_CTX *ctx, uint8_t *out, size_t *out_len,
                          size_t max_out_len, const uint8_t *password,
                          size_t password_len) {
@@ -359,13 +383,61 @@
   SHA512(password, password_len, password_tmp);
   OPENSSL_memcpy(ctx->password_hash, password_tmp, sizeof(ctx->password_hash));
   x25519_sc_reduce(password_tmp);
-  OPENSSL_memcpy(ctx->password_scalar, password_tmp, sizeof(ctx->password_scalar));
+
+  // Due to a copy-paste error, the call to |left_shift_3| was omitted after
+  // the |x25519_sc_reduce|, just above. This meant that |ctx->password_scalar|
+  // was not a multiple of eight to clear the cofactor and thus three bits of
+  // the password hash would leak. In order to fix this in a unilateral way,
+  // points of small order are added to the mask point such that it is in the
+  // prime-order subgroup. Since the ephemeral scalar is a multiple of eight,
+  // these points will cancel out when calculating the shared secret.
+  //
+  // Adding points of small order is the same as adding multiples of the prime
+  // order to the password scalar. Since that's faster, that is what is done
+  // below. The prime order (kOrder) is a large prime, thus odd, thus the LSB
+  // is one. So adding it will flip the LSB. Adding twice it will flip the next
+  // bit and so one for all the bottom three bits.
+
+  scalar password_scalar;
+  OPENSSL_memcpy(&password_scalar, password_tmp, sizeof(password_scalar));
+
+  // |password_scalar| is the result of |x25519_sc_reduce| and thus is, at
+  // most, $l-1$ (where $l$ is |kOrder|, the order of the prime-order subgroup
+  // of Ed25519). In the following, we may add $l + 2×l + 4×l$ for a max value
+  // of $8×l-1$. That is < 2**256, as required.
+
+  if (!ctx->disable_password_scalar_hack) {
+    scalar order = kOrder;
+    scalar tmp;
+
+    OPENSSL_memset(&tmp, 0, sizeof(tmp));
+    scalar_cmov(&tmp, &order,
+                constant_time_eq_w(password_scalar.bytes[0] & 1, 1));
+    scalar_add(&password_scalar, &tmp);
+
+    scalar_double(&order);
+    OPENSSL_memset(&tmp, 0, sizeof(tmp));
+    scalar_cmov(&tmp, &order,
+                constant_time_eq_w(password_scalar.bytes[0] & 2, 2));
+    scalar_add(&password_scalar, &tmp);
+
+    scalar_double(&order);
+    OPENSSL_memset(&tmp, 0, sizeof(tmp));
+    scalar_cmov(&tmp, &order,
+                constant_time_eq_w(password_scalar.bytes[0] & 4, 4));
+    scalar_add(&password_scalar, &tmp);
+
+    assert((password_scalar.bytes[0] & 7) == 0);
+  }
+
+  OPENSSL_memcpy(ctx->password_scalar, password_scalar.bytes,
+                 sizeof(ctx->password_scalar));
 
   ge_p3 mask;
   x25519_ge_scalarmult_small_precomp(&mask, ctx->password_scalar,
-                              ctx->my_role == spake2_role_alice
-                                  ? kSpakeMSmallPrecomp
-                                  : kSpakeNSmallPrecomp);
+                                     ctx->my_role == spake2_role_alice
+                                         ? kSpakeMSmallPrecomp
+                                         : kSpakeNSmallPrecomp);
 
   // P* = P + mask.
   ge_cached mask_cached;
diff --git a/src/crypto/curve25519/spake25519_test.cc b/src/crypto/curve25519/spake25519_test.cc
index cdf4ff5..71c9771 100644
--- a/src/crypto/curve25519/spake25519_test.cc
+++ b/src/crypto/curve25519/spake25519_test.cc
@@ -23,6 +23,7 @@
 #include <gtest/gtest.h>
 
 #include "../internal.h"
+#include "../../third_party/fiat/internal.h"
 
 
 // TODO(agl): add tests with fixed vectors once SPAKE2 is nailed down.
@@ -46,6 +47,13 @@
       return false;
     }
 
+    if (alice_disable_password_scalar_hack) {
+      alice->disable_password_scalar_hack = 1;
+    }
+    if (bob_disable_password_scalar_hack) {
+      bob->disable_password_scalar_hack = 1;
+    }
+
     uint8_t alice_msg[SPAKE2_MAX_MSG_SIZE];
     uint8_t bob_msg[SPAKE2_MAX_MSG_SIZE];
     size_t alice_msg_len, bob_msg_len;
@@ -90,6 +98,8 @@
   std::string bob_password = "password";
   std::pair<std::string, std::string> alice_names = {"alice", "bob"};
   std::pair<std::string, std::string> bob_names = {"bob", "alice"};
+  bool alice_disable_password_scalar_hack = false;
+  bool bob_disable_password_scalar_hack = false;
   int alice_corrupt_msg_bit = -1;
 
  private:
@@ -104,6 +114,24 @@
   }
 }
 
+TEST(SPAKE25519Test, OldAlice) {
+  for (unsigned i = 0; i < 20; i++) {
+    SPAKE2Run spake2;
+    spake2.alice_disable_password_scalar_hack = true;
+    ASSERT_TRUE(spake2.Run());
+    EXPECT_TRUE(spake2.key_matches());
+  }
+}
+
+TEST(SPAKE25519Test, OldBob) {
+  for (unsigned i = 0; i < 20; i++) {
+    SPAKE2Run spake2;
+    spake2.bob_disable_password_scalar_hack = true;
+    ASSERT_TRUE(spake2.Run());
+    EXPECT_TRUE(spake2.key_matches());
+  }
+}
+
 TEST(SPAKE25519Test, WrongPassword) {
   SPAKE2Run spake2;
   spake2.bob_password = "wrong password";
diff --git a/src/crypto/curve25519/x25519-x86_64.c b/src/crypto/curve25519/x25519-x86_64.c
index d677b52..41db0bd 100644
--- a/src/crypto/curve25519/x25519-x86_64.c
+++ b/src/crypto/curve25519/x25519-x86_64.c
@@ -24,7 +24,7 @@
 #include <string.h>
 
 #include "../internal.h"
-#include "internal.h"
+#include "../../third_party/fiat/internal.h"
 
 
 #if defined(BORINGSSL_X25519_X86_64)
diff --git a/src/crypto/curve25519/x25519_test.cc b/src/crypto/curve25519/x25519_test.cc
index 903892f..3e0a27e 100644
--- a/src/crypto/curve25519/x25519_test.cc
+++ b/src/crypto/curve25519/x25519_test.cc
@@ -105,3 +105,22 @@
 
   EXPECT_EQ(Bytes(kExpected), Bytes(scalar));
 }
+
+TEST(X25519Test, DISABLED_IteratedLarge) {
+  // Taken from https://tools.ietf.org/html/rfc7748#section-5.2.
+  uint8_t scalar[32] = {9}, point[32] = {9}, out[32];
+
+  for (unsigned i = 0; i < 1000000; i++) {
+    EXPECT_TRUE(X25519(out, scalar, point));
+    OPENSSL_memcpy(point, scalar, sizeof(point));
+    OPENSSL_memcpy(scalar, out, sizeof(scalar));
+  }
+
+  static const uint8_t kExpected[32] = {
+      0x7c, 0x39, 0x11, 0xe0, 0xab, 0x25, 0x86, 0xfd, 0x86, 0x44, 0x97,
+      0x29, 0x7e, 0x57, 0x5e, 0x6f, 0x3b, 0xc6, 0x01, 0xc0, 0x88, 0x3c,
+      0x30, 0xdf, 0x5f, 0x4d, 0xd2, 0xd2, 0x4f, 0x66, 0x54, 0x24,
+  };
+
+  EXPECT_EQ(Bytes(kExpected), Bytes(scalar));
+}
diff --git a/src/crypto/fipsmodule/bn/asm/x86_64-mont5.pl b/src/crypto/fipsmodule/bn/asm/x86_64-mont5.pl
index dfb8b37..69b8e01 100755
--- a/src/crypto/fipsmodule/bn/asm/x86_64-mont5.pl
+++ b/src/crypto/fipsmodule/bn/asm/x86_64-mont5.pl
@@ -3190,11 +3190,19 @@
 
 .align	32
 .Lsqrx8x_break:
-	sub	16+8(%rsp),%r8		# consume last carry
+	xor	$zero,$zero
+	sub	16+8(%rsp),%rbx		# mov 16(%rsp),%cf
+	adcx	$zero,%r8
 	mov	24+8(%rsp),$carry	# initial $tptr, borrow $carry
+	adcx	$zero,%r9
 	mov	0*8($aptr),%rdx		# a[8], modulo-scheduled
-	xor	%ebp,%ebp		# xor	$zero,$zero
+	adc	\$0,%r10
 	mov	%r8,0*8($tptr)
+	adc	\$0,%r11
+	adc	\$0,%r12
+	adc	\$0,%r13
+	adc	\$0,%r14
+	adc	\$0,%r15
 	cmp	$carry,$tptr		# cf=0, of=0
 	je	.Lsqrx8x_outer_loop
 
diff --git a/src/crypto/fipsmodule/bn/bn_tests.txt b/src/crypto/fipsmodule/bn/bn_tests.txt
index c53eb23..f809e7e 100644
--- a/src/crypto/fipsmodule/bn/bn_tests.txt
+++ b/src/crypto/fipsmodule/bn/bn_tests.txt
@@ -9897,6 +9897,12 @@
 A = ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffff00000000
 M = ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffff
 
+# Regression test for CVE-2017-3736.
+ModSquare = fe06fe0b06160c09
+A = fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8f8f8f800000000000010000000006c000000000000000000000000000000000000000000000000000000000000000000000000000000000000fffffffffffff8f8f8f800000000000010000000006c000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffff00000000ffffffffffffffffffffffffffff00fcfdfc
+# A in Montgomery form is fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8ffeadbcfc4dae7fff908e92820306b9544d954000000006c000000000000000000000000000000000000000000000000000000000000000000ff030202fffff8ffebdbcfc4dae7fff908e92820306b9544d954000000006c000000ff0302030000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01fc00ff02ffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00fcfdfcffffffffff000000000000000000ff0302030000000000ffffffffffffffffff00fcfdfdff030202ff00000000ffffffffffffffffff00fcfdfcffffffffff
+M = fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8f8f8f800000000000010000000006c000000000000000000000000000000000000000000000000000000000000000000000000000000000000fffffffffffff8f8f8f800000000000010000000006c000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffffffff
+
 
 # ModExp tests.
 #
diff --git a/src/crypto/fipsmodule/bn/exponentiation.c b/src/crypto/fipsmodule/bn/exponentiation.c
index b6b7fa9..e2dfb34 100644
--- a/src/crypto/fipsmodule/bn/exponentiation.c
+++ b/src/crypto/fipsmodule/bn/exponentiation.c
@@ -733,12 +733,14 @@
   return ret;
 }
 
-// BN_mod_exp_mont_consttime() stores the precomputed powers in a specific
+
+// |BN_mod_exp_mont_consttime| stores the precomputed powers in a specific
 // layout so that accessing any of these table values shows the same access
 // pattern as far as cache lines are concerned. The following functions are
 // used to transfer a BIGNUM from/to that table.
-static int copy_to_prebuf(const BIGNUM *b, int top, unsigned char *buf, int idx,
-                          int window) {
+
+static void copy_to_prebuf(const BIGNUM *b, int top, unsigned char *buf,
+                           int idx, int window) {
   int i, j;
   const int width = 1 << window;
   BN_ULONG *table = (BN_ULONG *) buf;
@@ -750,8 +752,6 @@
   for (i = 0, j = idx; i < top; i++, j += width)  {
     table[j] = b->d[i];
   }
-
-  return 1;
 }
 
 static int copy_from_prebuf(BIGNUM *b, int top, unsigned char *buf, int idx,
@@ -1103,26 +1103,27 @@
   } else
 #endif
   {
-    if (!copy_to_prebuf(&tmp, top, powerbuf, 0, window) ||
-        !copy_to_prebuf(&am, top, powerbuf, 1, window)) {
-      goto err;
-    }
+    copy_to_prebuf(&tmp, top, powerbuf, 0, window);
+    copy_to_prebuf(&am, top, powerbuf, 1, window);
 
     // If the window size is greater than 1, then calculate
     // val[i=2..2^winsize-1]. Powers are computed as a*a^(i-1)
     // (even powers could instead be computed as (a^(i/2))^2
     // to use the slight performance advantage of sqr over mul).
     if (window > 1) {
-      if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx) ||
-          !copy_to_prebuf(&tmp, top, powerbuf, 2, window)) {
+      if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx)) {
         goto err;
       }
+
+      copy_to_prebuf(&tmp, top, powerbuf, 2, window);
+
       for (i = 3; i < numPowers; i++) {
         // Calculate a^i = a^(i-1) * a
-        if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx) ||
-            !copy_to_prebuf(&tmp, top, powerbuf, i, window)) {
+        if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx)) {
           goto err;
         }
+
+        copy_to_prebuf(&tmp, top, powerbuf, i, window);
       }
     }
 
diff --git a/src/crypto/fipsmodule/cipher/cipher.c b/src/crypto/fipsmodule/cipher/cipher.c
index 7b00c3f..f3d4057 100644
--- a/src/crypto/fipsmodule/cipher/cipher.c
+++ b/src/crypto/fipsmodule/cipher/cipher.c
@@ -611,3 +611,5 @@
 int EVP_add_cipher_alias(const char *a, const char *b) {
   return 1;
 }
+
+void EVP_CIPHER_CTX_set_flags(const EVP_CIPHER_CTX *ctx, uint32_t flags) {}
diff --git a/src/crypto/fipsmodule/rsa/rsa_impl.c b/src/crypto/fipsmodule/rsa/rsa_impl.c
index b89eccb..adbb69f 100644
--- a/src/crypto/fipsmodule/rsa/rsa_impl.c
+++ b/src/crypto/fipsmodule/rsa/rsa_impl.c
@@ -807,11 +807,16 @@
     return 0;
   }
 
-  // Ensure the bound on |tries| does not overflow.
-  if (bits >= INT_MAX/5) {
+  // See FIPS 186-4 appendix B.3.3, steps 4 and 5. Note |bits| here is nlen/2.
+
+  // Use the limit from steps 4.7 and 5.8 for most values of |e|. When |e| is 3,
+  // the 186-4 limit is too low, so we use a higher one. Note this case is not
+  // reachable from |RSA_generate_key_fips|.
+  if (bits >= INT_MAX/32) {
     OPENSSL_PUT_ERROR(RSA, RSA_R_MODULUS_TOO_LARGE);
     return 0;
   }
+  int limit = BN_is_word(e, 3) ? bits * 32 : bits * 5;
 
   int ret = 0, tries = 0, rand_tries = 0;
   BN_CTX_start(ctx);
@@ -820,8 +825,6 @@
     goto err;
   }
 
-  // See FIPS 186-4 appendix B.3.3, steps 4 and 5. Note |bits| here is
-  // nlen/2.
   for (;;) {
     // Generate a random number of length |bits| where the bottom bit is set
     // (steps 4.2, 4.3, 5.2 and 5.3) and the top bit is set (implied by the
@@ -890,7 +893,7 @@
     // If we've tried too many times to find a prime, abort (steps 4.7 and
     // 5.8).
     tries++;
-    if (tries >= bits * 5) {
+    if (tries >= limit) {
       OPENSSL_PUT_ERROR(RSA, RSA_R_TOO_MANY_ITERATIONS);
       goto err;
     }
diff --git a/src/include/openssl/bio.h b/src/include/openssl/bio.h
index b397696..f87167e 100644
--- a/src/include/openssl/bio.h
+++ b/src/include/openssl/bio.h
@@ -622,7 +622,9 @@
 // Use the |BIO_meth_set_*| functions below to initialize the |BIO_METHOD|. The
 // function implementations may use |BIO_set_data| and |BIO_get_data| to add
 // method-specific state to associated |BIO|s. Additionally, |BIO_set_init| must
-// be called after an associated |BIO| is fully initialized.
+// be called after an associated |BIO| is fully initialized. State set via
+// |BIO_set_data| may be released by configuring a destructor with
+// |BIO_meth_set_destroy|.
 OPENSSL_EXPORT BIO_METHOD *BIO_meth_new(int type, const char *name);
 
 // BIO_meth_free releases memory associated with |method|.
@@ -640,7 +642,8 @@
                                         int (*destroy)(BIO *));
 
 // BIO_meth_set_write sets the implementation of |BIO_write| for |method| and
-// returns one.
+// returns one. |BIO_METHOD|s which implement |BIO_write| should also implement
+// |BIO_CTRL_FLUSH|. (See |BIO_meth_set_ctrl|.)
 OPENSSL_EXPORT int BIO_meth_set_write(BIO_METHOD *method,
                                       int (*write)(BIO *, const char *, int));
 
diff --git a/src/include/openssl/cipher.h b/src/include/openssl/cipher.h
index 5c380a1..643bf04 100644
--- a/src/include/openssl/cipher.h
+++ b/src/include/openssl/cipher.h
@@ -417,6 +417,16 @@
 // EVP_aes_128_cfb128 is only available in decrepit.
 OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_128_cfb128(void);
 
+// The following flags do nothing and are included only to make it easier to
+// compile code with BoringSSL.
+#define EVP_CIPH_CCM_MODE 0
+#define EVP_CIPH_WRAP_MODE 0
+#define EVP_CIPHER_CTX_FLAG_WRAP_ALLOW 0
+
+// EVP_CIPHER_CTX_set_flags does nothing.
+OPENSSL_EXPORT void EVP_CIPHER_CTX_set_flags(const EVP_CIPHER_CTX *ctx,
+                                             uint32_t flags);
+
 
 // Private functions.
 
diff --git a/src/include/openssl/conf.h b/src/include/openssl/conf.h
index ebf6dc4..4ffce37 100644
--- a/src/include/openssl/conf.h
+++ b/src/include/openssl/conf.h
@@ -141,13 +141,9 @@
 #define CONF_MFLAGS_DEFAULT_SECTION 0
 #define CONF_MFLAGS_IGNORE_MISSING_FILE 0
 
-typedef struct conf_must_be_null_st CONF_MUST_BE_NULL;
-
-// CONF_modules_load_file returns one. |filename| was originally a string, with
-// NULL indicating the default. BoringSSL does not support configuration files,
-// so this stub emulates the "default" no-op file but intentionally breaks
-// compilation of consumers actively attempting to use this subsystem.
-OPENSSL_EXPORT int CONF_modules_load_file(CONF_MUST_BE_NULL *filename,
+// CONF_modules_load_file returns one. BoringSSL is defined to have no config
+// file options, thus loading from |filename| always succeeds by doing nothing.
+OPENSSL_EXPORT int CONF_modules_load_file(const char *filename,
                                           const char *appname,
                                           unsigned long flags);
 
@@ -155,7 +151,7 @@
 OPENSSL_EXPORT void CONF_modules_free(void);
 
 // OPENSSL_config does nothing.
-OPENSSL_EXPORT void OPENSSL_config(CONF_MUST_BE_NULL *config_name);
+OPENSSL_EXPORT void OPENSSL_config(const char *config_name);
 
 // OPENSSL_no_config does nothing.
 OPENSSL_EXPORT void OPENSSL_no_config(void);
diff --git a/src/include/openssl/ssl.h b/src/include/openssl/ssl.h
index a2d3ce7..3540a25 100644
--- a/src/include/openssl/ssl.h
+++ b/src/include/openssl/ssl.h
@@ -592,6 +592,7 @@
 #define DTLS1_2_VERSION 0xfefd
 
 #define TLS1_3_DRAFT_VERSION 0x7f12
+#define TLS1_3_DRAFT21_VERSION 0x7f15
 #define TLS1_3_EXPERIMENT_VERSION 0x7e01
 #define TLS1_3_EXPERIMENT2_VERSION 0x7e02
 #define TLS1_3_EXPERIMENT3_VERSION 0x7e03
@@ -977,6 +978,25 @@
 // before TLS 1.2.
 #define SSL_SIGN_RSA_PKCS1_MD5_SHA1 0xff01
 
+// SSL_get_signature_algorithm_name returns a human-readable name for |sigalg|,
+// or NULL if unknown. If |include_curve| is one, the curve for ECDSA algorithms
+// is included as in TLS 1.3. Otherwise, it is excluded as in TLS 1.2.
+OPENSSL_EXPORT const char *SSL_get_signature_algorithm_name(uint16_t sigalg,
+                                                            int include_curve);
+
+// SSL_get_signature_algorithm_key_type returns the key type associated with
+// |sigalg| as an |EVP_PKEY_*| constant or |EVP_PKEY_NONE| if unknown.
+OPENSSL_EXPORT int SSL_get_signature_algorithm_key_type(uint16_t sigalg);
+
+// SSL_get_signature_algorithm_digest returns the digest function associated
+// with |sigalg| or |NULL| if |sigalg| has no prehash (Ed25519) or is unknown.
+OPENSSL_EXPORT const EVP_MD *SSL_get_signature_algorithm_digest(
+    uint16_t sigalg);
+
+// SSL_is_signature_algorithm_rsa_pss returns one if |sigalg| is an RSA-PSS
+// signature algorithm and zero otherwise.
+OPENSSL_EXPORT int SSL_is_signature_algorithm_rsa_pss(uint16_t sigalg);
+
 // SSL_CTX_set_signing_algorithm_prefs configures |ctx| to use |prefs| as the
 // preference list when signing with |ctx|'s private key. It returns one on
 // success and zero on error. |prefs| should not include the internal-only value
@@ -3234,6 +3254,7 @@
   tls13_experiment = 1,
   tls13_experiment2 = 2,
   tls13_experiment3 = 3,
+  tls13_draft21 = 4,
 };
 
 // SSL_CTX_set_tls13_variant sets which variant of TLS 1.3 we negotiate. On the
diff --git a/src/include/openssl/ssl3.h b/src/include/openssl/ssl3.h
index 6754cec..ae0be88 100644
--- a/src/include/openssl/ssl3.h
+++ b/src/include/openssl/ssl3.h
@@ -299,6 +299,7 @@
 #define SSL3_MT_CLIENT_HELLO 1
 #define SSL3_MT_SERVER_HELLO 2
 #define SSL3_MT_NEW_SESSION_TICKET 4
+#define SSL3_MT_END_OF_EARLY_DATA 5
 #define SSL3_MT_HELLO_RETRY_REQUEST 6
 #define SSL3_MT_ENCRYPTED_EXTENSIONS 8
 #define SSL3_MT_CERTIFICATE 11
@@ -313,6 +314,7 @@
 #define SSL3_MT_KEY_UPDATE 24
 #define SSL3_MT_NEXT_PROTO 67
 #define SSL3_MT_CHANNEL_ID 203
+#define SSL3_MT_MESSAGE_HASH 254
 #define DTLS1_MT_HELLO_VERIFY_REQUEST 3
 
 // The following are legacy aliases for consumers which use
diff --git a/src/include/openssl/tls1.h b/src/include/openssl/tls1.h
index 8eafe4c..f62ee1f 100644
--- a/src/include/openssl/tls1.h
+++ b/src/include/openssl/tls1.h
@@ -214,6 +214,7 @@
 #define TLSEXT_TYPE_cookie 44
 #define TLSEXT_TYPE_psk_key_exchange_modes 45
 #define TLSEXT_TYPE_ticket_early_data_info 46
+#define TLSEXT_TYPE_certificate_authorities 47
 
 // ExtensionType value from RFC5746
 #define TLSEXT_TYPE_renegotiate 0xff01
@@ -600,22 +601,6 @@
 #define TLS_CT_ECDSA_FIXED_ECDH 66
 
 #define TLS_MD_MAX_CONST_SIZE 20
-#define TLS_MD_CLIENT_FINISH_CONST "client finished"
-#define TLS_MD_CLIENT_FINISH_CONST_SIZE 15
-#define TLS_MD_SERVER_FINISH_CONST "server finished"
-#define TLS_MD_SERVER_FINISH_CONST_SIZE 15
-#define TLS_MD_KEY_EXPANSION_CONST "key expansion"
-#define TLS_MD_KEY_EXPANSION_CONST_SIZE 13
-#define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key"
-#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16
-#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
-#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
-#define TLS_MD_IV_BLOCK_CONST "IV block"
-#define TLS_MD_IV_BLOCK_CONST_SIZE 8
-#define TLS_MD_MASTER_SECRET_CONST "master secret"
-#define TLS_MD_MASTER_SECRET_CONST_SIZE 13
-#define TLS_MD_EXTENDED_MASTER_SECRET_CONST "extended master secret"
-#define TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE 22
 
 
 #ifdef  __cplusplus
diff --git a/src/ssl/dtls_method.cc b/src/ssl/dtls_method.cc
index 91a955f..d0416ad 100644
--- a/src/ssl/dtls_method.cc
+++ b/src/ssl/dtls_method.cc
@@ -68,10 +68,6 @@
 
 using namespace bssl;
 
-static bool dtls1_supports_cipher(const SSL_CIPHER *cipher) {
-  return cipher->algorithm_enc != SSL_eNULL;
-}
-
 static void dtls1_on_handshake_complete(SSL *ssl) {
   // Stop the reply timer left by the last flight we sent.
   dtls1_stop_timer(ssl);
@@ -121,7 +117,6 @@
     dtls1_open_app_data,
     dtls1_write_app_data,
     dtls1_dispatch_alert,
-    dtls1_supports_cipher,
     dtls1_init_message,
     dtls1_finish_message,
     dtls1_add_message,
diff --git a/src/ssl/handshake_client.cc b/src/ssl/handshake_client.cc
index ff8ebd8..f907939 100644
--- a/src/ssl/handshake_client.cc
+++ b/src/ssl/handshake_client.cc
@@ -500,9 +500,8 @@
     return ssl_hs_ok;
   }
 
-  if (!tls13_init_early_key_schedule(hs) ||
-      !tls13_advance_key_schedule(hs, ssl->session->master_key,
-                                  ssl->session->master_key_length) ||
+  if (!tls13_init_early_key_schedule(hs, ssl->session->master_key,
+                                     ssl->session->master_key_length) ||
       !tls13_derive_early_secrets(hs) ||
       !tls13_set_traffic_key(ssl, evp_aead_seal, hs->early_traffic_secret,
                              hs->hash_len)) {
@@ -1360,8 +1359,8 @@
     return ssl_hs_error;
   }
 
-  hs->new_session->master_key_length = tls1_generate_master_secret(
-      hs, hs->new_session->master_key, pms.data(), pms.size());
+  hs->new_session->master_key_length =
+      tls1_generate_master_secret(hs, hs->new_session->master_key, pms);
   if (hs->new_session->master_key_length == 0) {
     return ssl_hs_error;
   }
diff --git a/src/ssl/handshake_server.cc b/src/ssl/handshake_server.cc
index d346875..bb565e9 100644
--- a/src/ssl/handshake_server.cc
+++ b/src/ssl/handshake_server.cc
@@ -1243,8 +1243,7 @@
 
   // Compute the master secret.
   hs->new_session->master_key_length = tls1_generate_master_secret(
-      hs, hs->new_session->master_key, premaster_secret.data(),
-      premaster_secret.size());
+      hs, hs->new_session->master_key, premaster_secret);
   if (hs->new_session->master_key_length == 0) {
     return ssl_hs_error;
   }
diff --git a/src/ssl/internal.h b/src/ssl/internal.h
index 7e1801a..55bece9 100644
--- a/src/ssl/internal.h
+++ b/src/ssl/internal.h
@@ -392,6 +392,10 @@
 // call this function before the version is determined.
 uint16_t ssl_protocol_version(const SSL *ssl);
 
+// ssl_is_draft21 returns whether the version corresponds to a draft21 TLS 1.3
+// variant.
+bool ssl_is_draft21(uint16_t version);
+
 // ssl_is_resumption_experiment returns whether the version corresponds to a
 // TLS 1.3 resumption experiment.
 bool ssl_is_resumption_experiment(uint16_t version);
@@ -490,14 +494,12 @@
 const EVP_MD *ssl_get_handshake_digest(uint16_t version,
                                        const SSL_CIPHER *cipher);
 
-// ssl_create_cipher_list evaluates |rule_str| according to the ciphers in
-// |ssl_method|. It sets |*out_cipher_list| to a newly-allocated
-// |ssl_cipher_preference_list_st| containing the result. It returns true on
-// success and false on failure. If |strict| is true, nonsense will be
-// rejected. If false, nonsense will be silently ignored. An empty result is
-// considered an error regardless of |strict|.
+// ssl_create_cipher_list evaluates |rule_str|. It sets |*out_cipher_list| to a
+// newly-allocated |ssl_cipher_preference_list_st| containing the result. It
+// returns true on success and false on failure. If |strict| is true, nonsense
+// will be rejected. If false, nonsense will be silently ignored. An empty
+// result is considered an error regardless of |strict|.
 bool ssl_create_cipher_list(
-    const SSL_PROTOCOL_METHOD *ssl_method,
     struct ssl_cipher_preference_list_st **out_cipher_list,
     const char *rule_str, bool strict);
 
@@ -545,6 +547,16 @@
   // to call this function after the handshake buffer is released.
   bool InitHash(uint16_t version, const SSL_CIPHER *cipher);
 
+  // UpdateForHelloRetryRequest resets the rolling hash with the
+  // HelloRetryRequest construction. It returns true on success and false on
+  // failure. It is an error to call this function before the handshake buffer
+  // is released.
+  bool UpdateForHelloRetryRequest();
+
+  // CopyHashContext copies the hash context into |ctx| and returns true on
+  // success.
+  bool CopyHashContext(EVP_MD_CTX *ctx);
+
   Span<const uint8_t> buffer() {
     return MakeConstSpan(reinterpret_cast<const uint8_t *>(buffer_->data),
                          buffer_->length);
@@ -596,14 +608,12 @@
   ScopedEVP_MD_CTX md5_;
 };
 
-// tls1_prf computes the PRF function for |ssl|. It writes |out_len| bytes to
-// |out|, using |secret| as the secret and |label| as the label. |seed1| and
-// |seed2| are concatenated to form the seed parameter. It returns one on
-// success and zero on failure.
-int tls1_prf(const EVP_MD *digest, uint8_t *out, size_t out_len,
-             const uint8_t *secret, size_t secret_len, const char *label,
-             size_t label_len, const uint8_t *seed1, size_t seed1_len,
-             const uint8_t *seed2, size_t seed2_len);
+// tls1_prf computes the PRF function for |ssl|. It fills |out|, using |secret|
+// as the secret and |label| as the label. |seed1| and |seed2| are concatenated
+// to form the seed parameter. It returns true on success and false on failure.
+bool tls1_prf(const EVP_MD *digest, Span<uint8_t> out,
+              Span<const uint8_t> secret, Span<const char> label,
+              Span<const uint8_t> seed1, Span<const uint8_t> seed2);
 
 
 // Encryption layer.
@@ -1161,6 +1171,9 @@
                                                             uint8_t *out_alert,
                                                             CBS *cbs);
 
+// ssl_has_client_CAs returns there are configured CAs.
+bool ssl_has_client_CAs(SSL *ssl);
+
 // ssl_add_client_CA_list adds the configured CA list to |cbb| in the format
 // used by a TLS CertificateRequest message. It returns one on success and zero
 // on error.
@@ -1181,14 +1194,16 @@
 // TLS 1.3 key derivation.
 
 // tls13_init_key_schedule initializes the handshake hash and key derivation
-// state. The cipher suite and PRF hash must have been selected at this point.
-// It returns one on success and zero on error.
-int tls13_init_key_schedule(SSL_HANDSHAKE *hs);
+// state, and incorporates the PSK. The cipher suite and PRF hash must have been
+// selected at this point. It returns one on success and zero on error.
+int tls13_init_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
+                            size_t psk_len);
 
 // tls13_init_early_key_schedule initializes the handshake hash and key
-// derivation state from the resumption secret to derive the early secrets. It
-// returns one on success and zero on error.
-int tls13_init_early_key_schedule(SSL_HANDSHAKE *hs);
+// derivation state from the resumption secret and incorporates the PSK to
+// derive the early secrets. It returns one on success and zero on error.
+int tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
+                                  size_t psk_len);
 
 // tls13_advance_key_schedule incorporates |in| into the key schedule with
 // HKDF-Extract. It returns one on success and zero on error.
@@ -1235,6 +1250,11 @@
 int tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out,
                        size_t *out_len, int is_server);
 
+// tls13_derive_session_psk calculates the PSK for this session based on the
+// resumption master secret and |nonce|. It returns true on success, and false
+// on failure.
+bool tls13_derive_session_psk(SSL_SESSION *session, Span<const uint8_t> nonce);
+
 // tls13_write_psk_binder calculates the PSK binder value and replaces the last
 // bytes of |msg| with the resulting value. It returns 1 on success, and 0 on
 // failure.
@@ -1773,8 +1793,6 @@
   int (*write_app_data)(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
                         int len);
   int (*dispatch_alert)(SSL *ssl);
-  // supports_cipher returns whether |cipher| is supported by this protocol.
-  bool (*supports_cipher)(const SSL_CIPHER *cipher);
   // init_message begins a new handshake message of type |type|. |cbb| is the
   // root CBB to be passed into |finish_message|. |*body| is set to a child CBB
   // the caller should write to. It returns true on success and false on error.
@@ -2803,7 +2821,7 @@
 
 int tls1_change_cipher_state(SSL_HANDSHAKE *hs, evp_aead_direction_t direction);
 int tls1_generate_master_secret(SSL_HANDSHAKE *hs, uint8_t *out,
-                                const uint8_t *premaster, size_t premaster_len);
+                                Span<const uint8_t> premaster);
 
 // tls1_get_grouplist returns the locally-configured group preference list.
 Span<const uint16_t> tls1_get_grouplist(const SSL *ssl);
@@ -2865,8 +2883,8 @@
 
 // tls1_write_channel_id generates a Channel ID message and puts the output in
 // |cbb|. |ssl->tlsext_channel_id_private| must already be set before calling.
-// This function returns one on success and zero on error.
-int tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb);
+// This function returns true on success and false on error.
+bool tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb);
 
 // tls1_channel_id_hash computes the hash to be signed by Channel ID and writes
 // it to |out|, which must contain at least |EVP_MAX_MD_SIZE| bytes. It returns
diff --git a/src/ssl/s3_pkt.cc b/src/ssl/s3_pkt.cc
index 285abb3..e6518ba 100644
--- a/src/ssl/s3_pkt.cc
+++ b/src/ssl/s3_pkt.cc
@@ -306,7 +306,7 @@
   if (type == SSL3_RT_HANDSHAKE) {
     // If reading 0-RTT data, reject handshake data. 0-RTT data is terminated
     // by an alert.
-    if (is_early_data_read) {
+    if (!ssl_is_draft21(ssl->version) && is_early_data_read) {
       OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_RECORD);
       *out_alert = SSL_AD_UNEXPECTED_MESSAGE;
       return ssl_open_record_error;
@@ -335,7 +335,8 @@
   // Handle the end_of_early_data alert.
   static const uint8_t kEndOfEarlyData[2] = {SSL3_AL_WARNING,
                                              TLS1_AD_END_OF_EARLY_DATA};
-  if (is_early_data_read && type == SSL3_RT_ALERT && body == kEndOfEarlyData) {
+  if (!ssl_is_draft21(ssl->version) && is_early_data_read &&
+      type == SSL3_RT_ALERT && body == kEndOfEarlyData) {
     // Stop accepting early data.
     ssl->s3->hs->can_early_read = false;
     return ssl_open_record_discard;
diff --git a/src/ssl/ssl_cert.cc b/src/ssl/ssl_cert.cc
index cd586a0..9a3eef3 100644
--- a/src/ssl/ssl_cert.cc
+++ b/src/ssl/ssl_cert.cc
@@ -704,6 +704,17 @@
   return ret;
 }
 
+bool ssl_has_client_CAs(SSL *ssl) {
+  STACK_OF(CRYPTO_BUFFER) *names = ssl->client_CA;
+  if (names == NULL) {
+    names = ssl->ctx->client_CA;
+  }
+  if (names == NULL) {
+    return false;
+  }
+  return sk_CRYPTO_BUFFER_num(names) > 0;
+}
+
 int ssl_add_client_CA_list(SSL *ssl, CBB *cbb) {
   CBB child, name_cbb;
   if (!CBB_add_u16_length_prefixed(cbb, &child)) {
diff --git a/src/ssl/ssl_cipher.cc b/src/ssl/ssl_cipher.cc
index 0c02389..87dc7cd 100644
--- a/src/ssl/ssl_cipher.cc
+++ b/src/ssl/ssl_cipher.cc
@@ -578,7 +578,7 @@
 
 static const CIPHER_ALIAS kCipherAliases[] = {
     // "ALL" doesn't include eNULL. It must be explicitly enabled.
-    {"ALL", ~0u, ~0u, ~SSL_eNULL, ~0u, 0},
+    {"ALL", ~0u, ~0u, ~0u, ~0u, 0},
 
     // The "COMPLEMENTOFDEFAULT" rule is omitted. It matches nothing.
 
@@ -594,7 +594,7 @@
     {"kPSK", SSL_kPSK, ~0u, ~0u, ~0u, 0},
 
     // server authentication aliases
-    {"aRSA", ~0u, SSL_aRSA, ~SSL_eNULL, ~0u, 0},
+    {"aRSA", ~0u, SSL_aRSA, ~0u, ~0u, 0},
     {"aECDSA", ~0u, SSL_aECDSA, ~0u, ~0u, 0},
     {"ECDSA", ~0u, SSL_aECDSA, ~0u, ~0u, 0},
     {"aPSK", ~0u, SSL_aPSK, ~0u, ~0u, 0},
@@ -602,7 +602,7 @@
     // aliases combining key exchange and server authentication
     {"ECDHE", SSL_kECDHE, ~0u, ~0u, ~0u, 0},
     {"EECDH", SSL_kECDHE, ~0u, ~0u, ~0u, 0},
-    {"RSA", SSL_kRSA, SSL_aRSA, ~SSL_eNULL, ~0u, 0},
+    {"RSA", SSL_kRSA, SSL_aRSA, ~0u, ~0u, 0},
     {"PSK", SSL_kPSK, SSL_aPSK, ~0u, ~0u, 0},
 
     // symmetric encryption aliases
@@ -614,20 +614,20 @@
     {"CHACHA20", ~0u, ~0u, SSL_CHACHA20POLY1305, ~0u, 0},
 
     // MAC aliases
-    {"SHA1", ~0u, ~0u, ~SSL_eNULL, SSL_SHA1, 0},
-    {"SHA", ~0u, ~0u, ~SSL_eNULL, SSL_SHA1, 0},
+    {"SHA1", ~0u, ~0u, ~0u, SSL_SHA1, 0},
+    {"SHA", ~0u, ~0u, ~0u, SSL_SHA1, 0},
     {"SHA256", ~0u, ~0u, ~0u, SSL_SHA256, 0},
     {"SHA384", ~0u, ~0u, ~0u, SSL_SHA384, 0},
 
     // Legacy protocol minimum version aliases. "TLSv1" is intentionally the
     // same as "SSLv3".
-    {"SSLv3", ~0u, ~0u, ~SSL_eNULL, ~0u, SSL3_VERSION},
-    {"TLSv1", ~0u, ~0u, ~SSL_eNULL, ~0u, SSL3_VERSION},
-    {"TLSv1.2", ~0u, ~0u, ~SSL_eNULL, ~0u, TLS1_2_VERSION},
+    {"SSLv3", ~0u, ~0u, ~0u, ~0u, SSL3_VERSION},
+    {"TLSv1", ~0u, ~0u, ~0u, ~0u, SSL3_VERSION},
+    {"TLSv1.2", ~0u, ~0u, ~0u, ~0u, TLS1_2_VERSION},
 
     // Legacy strength classes.
-    {"HIGH", ~0u, ~0u, ~SSL_eNULL, ~0u, 0},
-    {"FIPS", ~0u, ~0u, ~SSL_eNULL, ~0u, 0},
+    {"HIGH", ~0u, ~0u, ~0u, ~0u, 0},
+    {"FIPS", ~0u, ~0u, ~0u, ~0u, 0},
 };
 
 static const size_t kCipherAliasesLen = OPENSSL_ARRAY_SIZE(kCipherAliases);
@@ -811,19 +811,14 @@
   *head = curr;
 }
 
-static void ssl_cipher_collect_ciphers(const SSL_PROTOCOL_METHOD *ssl_method,
-                                       CIPHER_ORDER *co_list,
+static void ssl_cipher_collect_ciphers(CIPHER_ORDER *co_list,
                                        CIPHER_ORDER **head_p,
                                        CIPHER_ORDER **tail_p) {
-  // The set of ciphers is static, but some subset may be unsupported by
-  // |ssl_method|, so the list may be smaller.
   size_t co_list_num = 0;
-  for (size_t i = 0; i < kCiphersLen; i++) {
-    const SSL_CIPHER *cipher = &kCiphers[i];
-    if (ssl_method->supports_cipher(cipher) &&
-        // TLS 1.3 ciphers do not participate in this mechanism.
-        cipher->algorithm_mkey != SSL_kGENERIC) {
-      co_list[co_list_num].cipher = cipher;
+  for (const SSL_CIPHER &cipher : kCiphers) {
+    // TLS 1.3 ciphers do not participate in this mechanism.
+    if (cipher.algorithm_mkey != SSL_kGENERIC) {
+      co_list[co_list_num].cipher = &cipher;
       co_list[co_list_num].next = NULL;
       co_list[co_list_num].prev = NULL;
       co_list[co_list_num].active = false;
@@ -923,7 +918,9 @@
           !(alg_auth & cp->algorithm_auth) ||
           !(alg_enc & cp->algorithm_enc) ||
           !(alg_mac & cp->algorithm_mac) ||
-          (min_version != 0 && SSL_CIPHER_get_min_version(cp) != min_version)) {
+          (min_version != 0 && SSL_CIPHER_get_min_version(cp) != min_version) ||
+          // The NULL cipher must be selected explicitly.
+          cp->algorithm_enc == SSL_eNULL) {
         continue;
       }
     }
@@ -1023,8 +1020,7 @@
   return true;
 }
 
-static bool ssl_cipher_process_rulestr(const SSL_PROTOCOL_METHOD *ssl_method,
-                                       const char *rule_str,
+static bool ssl_cipher_process_rulestr(const char *rule_str,
                                        CIPHER_ORDER **head_p,
                                        CIPHER_ORDER **tail_p, bool strict) {
   uint32_t alg_mkey, alg_auth, alg_enc, alg_mac;
@@ -1206,7 +1202,6 @@
 }
 
 bool ssl_create_cipher_list(
-    const SSL_PROTOCOL_METHOD *ssl_method,
     struct ssl_cipher_preference_list_st **out_cipher_list,
     const char *rule_str, bool strict) {
   STACK_OF(SSL_CIPHER) *cipherstack = NULL;
@@ -1229,7 +1224,7 @@
     return false;
   }
 
-  ssl_cipher_collect_ciphers(ssl_method, co_list, &head, &tail);
+  ssl_cipher_collect_ciphers(co_list, &head, &tail);
 
   // Now arrange all ciphers by preference:
   // TODO(davidben): Compute this order once and copy it.
@@ -1288,8 +1283,8 @@
   // using the (possibly available) additional rules.
   const char *rule_p = rule_str;
   if (strncmp(rule_str, "DEFAULT", 7) == 0) {
-    if (!ssl_cipher_process_rulestr(ssl_method, SSL_DEFAULT_CIPHER_LIST, &head,
-                                    &tail, strict)) {
+    if (!ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST, &head, &tail,
+                                    strict)) {
       goto err;
     }
     rule_p += 7;
@@ -1299,7 +1294,7 @@
   }
 
   if (*rule_p != '\0' &&
-      !ssl_cipher_process_rulestr(ssl_method, rule_p, &head, &tail, strict)) {
+      !ssl_cipher_process_rulestr(rule_p, &head, &tail, strict)) {
     goto err;
   }
 
diff --git a/src/ssl/ssl_key_share.cc b/src/ssl/ssl_key_share.cc
index 52ff85d..a5ae578 100644
--- a/src/ssl/ssl_key_share.cc
+++ b/src/ssl/ssl_key_share.cc
@@ -171,13 +171,13 @@
 CONSTEXPR_ARRAY struct {
   int nid;
   uint16_t group_id;
-  const char name[8];
+  const char name[8], alias[11];
 } kNamedGroups[] = {
-    {NID_secp224r1, SSL_CURVE_SECP224R1, "P-224"},
-    {NID_X9_62_prime256v1, SSL_CURVE_SECP256R1, "P-256"},
-    {NID_secp384r1, SSL_CURVE_SECP384R1, "P-384"},
-    {NID_secp521r1, SSL_CURVE_SECP521R1, "P-521"},
-    {NID_X25519, SSL_CURVE_X25519, "X25519"},
+    {NID_secp224r1, SSL_CURVE_SECP224R1, "P-224", "secp224r1"},
+    {NID_X9_62_prime256v1, SSL_CURVE_SECP256R1, "P-256", "prime256v1"},
+    {NID_secp384r1, SSL_CURVE_SECP384R1, "P-384", "secp384r1"},
+    {NID_secp521r1, SSL_CURVE_SECP521R1, "P-521", "secp521r1"},
+    {NID_X25519, SSL_CURVE_X25519, "X25519", "x25519"},
 };
 
 }  // namespace
@@ -227,6 +227,11 @@
       *out_group_id = group.group_id;
       return 1;
     }
+    if (len == strlen(group.alias) &&
+        !strncmp(group.alias, name, len)) {
+      *out_group_id = group.group_id;
+      return 1;
+    }
   }
   return 0;
 }
diff --git a/src/ssl/ssl_lib.cc b/src/ssl/ssl_lib.cc
index 2fc6ffd..122313f 100644
--- a/src/ssl/ssl_lib.cc
+++ b/src/ssl/ssl_lib.cc
@@ -986,6 +986,13 @@
     // Process any buffered post-handshake messages.
     SSLMessage msg;
     if (ssl->method->get_message(ssl, &msg)) {
+      // If we received an interrupt in early read (EndOfEarlyData), loop again
+      // for the handshake to process it.
+      if (SSL_in_init(ssl)) {
+        ssl->s3->hs->can_early_read = false;
+        continue;
+      }
+
       // Handle the post-handshake message and try again.
       if (!ssl_do_post_handshake(ssl, msg)) {
         ssl_set_read_error(ssl);
@@ -1827,23 +1834,19 @@
 }
 
 int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) {
-  return ssl_create_cipher_list(ctx->method, &ctx->cipher_list, str,
-                                false /* not strict */);
+  return ssl_create_cipher_list(&ctx->cipher_list, str, false /* not strict */);
 }
 
 int SSL_CTX_set_strict_cipher_list(SSL_CTX *ctx, const char *str) {
-  return ssl_create_cipher_list(ctx->method, &ctx->cipher_list, str,
-                                true /* strict */);
+  return ssl_create_cipher_list(&ctx->cipher_list, str, true /* strict */);
 }
 
 int SSL_set_cipher_list(SSL *ssl, const char *str) {
-  return ssl_create_cipher_list(ssl->ctx->method, &ssl->cipher_list, str,
-                                false /* not strict */);
+  return ssl_create_cipher_list(&ssl->cipher_list, str, false /* not strict */);
 }
 
 int SSL_set_strict_cipher_list(SSL *ssl, const char *str) {
-  return ssl_create_cipher_list(ssl->ctx->method, &ssl->cipher_list, str,
-                                true /* strict */);
+  return ssl_create_cipher_list(&ssl->cipher_list, str, true /* strict */);
 }
 
 const char *SSL_get_servername(const SSL *ssl, const int type) {
diff --git a/src/ssl/ssl_privkey.cc b/src/ssl/ssl_privkey.cc
index b00613d..e9990af 100644
--- a/src/ssl/ssl_privkey.cc
+++ b/src/ssl/ssl_privkey.cc
@@ -438,6 +438,58 @@
   ctx->cert->key_method = key_method;
 }
 
+const char *SSL_get_signature_algorithm_name(uint16_t sigalg,
+                                             int include_curve) {
+  switch (sigalg) {
+    case SSL_SIGN_RSA_PKCS1_MD5_SHA1:
+      return "rsa_pkcs1_md5_sha1";
+    case SSL_SIGN_RSA_PKCS1_SHA1:
+      return "rsa_pkcs1_sha1";
+    case SSL_SIGN_RSA_PKCS1_SHA256:
+      return "rsa_pkcs1_sha256";
+    case SSL_SIGN_RSA_PKCS1_SHA384:
+      return "rsa_pkcs1_sha384";
+    case SSL_SIGN_RSA_PKCS1_SHA512:
+      return "rsa_pkcs1_sha512";
+    case SSL_SIGN_ECDSA_SHA1:
+      return "ecdsa_sha1";
+    case SSL_SIGN_ECDSA_SECP256R1_SHA256:
+      return include_curve ? "ecdsa_secp256r1_sha256" : "ecdsa_sha256";
+    case SSL_SIGN_ECDSA_SECP384R1_SHA384:
+      return include_curve ? "ecdsa_secp384r1_sha384" : "ecdsa_sha384";
+    case SSL_SIGN_ECDSA_SECP521R1_SHA512:
+      return include_curve ? "ecdsa_secp521r1_sha512" : "ecdsa_sha512";
+    case SSL_SIGN_RSA_PSS_SHA256:
+      return "rsa_pss_sha256";
+    case SSL_SIGN_RSA_PSS_SHA384:
+      return "rsa_pss_sha384";
+    case SSL_SIGN_RSA_PSS_SHA512:
+      return "rsa_pss_sha512";
+    case SSL_SIGN_ED25519:
+      return "ed25519";
+    default:
+      return NULL;
+  }
+}
+
+int SSL_get_signature_algorithm_key_type(uint16_t sigalg) {
+  const SSL_SIGNATURE_ALGORITHM *alg = get_signature_algorithm(sigalg);
+  return alg != nullptr ? alg->pkey_type : EVP_PKEY_NONE;
+}
+
+const EVP_MD *SSL_get_signature_algorithm_digest(uint16_t sigalg) {
+  const SSL_SIGNATURE_ALGORITHM *alg = get_signature_algorithm(sigalg);
+  if (alg == nullptr || alg->digest_func == nullptr) {
+    return nullptr;
+  }
+  return alg->digest_func();
+}
+
+int SSL_is_signature_algorithm_rsa_pss(uint16_t sigalg) {
+  const SSL_SIGNATURE_ALGORITHM *alg = get_signature_algorithm(sigalg);
+  return alg != nullptr && alg->is_rsa_pss;
+}
+
 static int set_algorithm_prefs(uint16_t **out_prefs, size_t *out_num_prefs,
                                const uint16_t *prefs, size_t num_prefs) {
   OPENSSL_free(*out_prefs);
diff --git a/src/ssl/ssl_test.cc b/src/ssl/ssl_test.cc
index ab50a57..8288878 100644
--- a/src/ssl/ssl_test.cc
+++ b/src/ssl/ssl_test.cc
@@ -379,6 +379,15 @@
       SSL_CURVE_X25519,
     },
   },
+  {
+    "prime256v1:secp384r1:secp521r1:x25519",
+    {
+      SSL_CURVE_SECP256R1,
+      SSL_CURVE_SECP384R1,
+      SSL_CURVE_SECP521R1,
+      SSL_CURVE_X25519,
+    },
+  },
 };
 
 static const char *kBadCurvesLists[] = {
@@ -3813,6 +3822,31 @@
   EXPECT_EQ(1, SSL_shutdown(client.get()));
 }
 
+TEST(SSLTest, SignatureAlgorithmProperties) {
+  EXPECT_EQ(EVP_PKEY_NONE, SSL_get_signature_algorithm_key_type(0x1234));
+  EXPECT_EQ(nullptr, SSL_get_signature_algorithm_digest(0x1234));
+  EXPECT_FALSE(SSL_is_signature_algorithm_rsa_pss(0x1234));
+
+  EXPECT_EQ(EVP_PKEY_RSA,
+            SSL_get_signature_algorithm_key_type(SSL_SIGN_RSA_PKCS1_MD5_SHA1));
+  EXPECT_EQ(EVP_md5_sha1(),
+            SSL_get_signature_algorithm_digest(SSL_SIGN_RSA_PKCS1_MD5_SHA1));
+  EXPECT_FALSE(SSL_is_signature_algorithm_rsa_pss(SSL_SIGN_RSA_PKCS1_MD5_SHA1));
+
+  EXPECT_EQ(EVP_PKEY_EC, SSL_get_signature_algorithm_key_type(
+                             SSL_SIGN_ECDSA_SECP256R1_SHA256));
+  EXPECT_EQ(EVP_sha256(), SSL_get_signature_algorithm_digest(
+                              SSL_SIGN_ECDSA_SECP256R1_SHA256));
+  EXPECT_FALSE(
+      SSL_is_signature_algorithm_rsa_pss(SSL_SIGN_ECDSA_SECP256R1_SHA256));
+
+  EXPECT_EQ(EVP_PKEY_RSA,
+            SSL_get_signature_algorithm_key_type(SSL_SIGN_RSA_PSS_SHA384));
+  EXPECT_EQ(EVP_sha384(),
+            SSL_get_signature_algorithm_digest(SSL_SIGN_RSA_PSS_SHA384));
+  EXPECT_TRUE(SSL_is_signature_algorithm_rsa_pss(SSL_SIGN_RSA_PSS_SHA384));
+}
+
 // TODO(davidben): Convert this file to GTest properly.
 TEST(SSLTest, AllTests) {
   if (!TestSSL_SESSIONEncoding(kOpenSSLSession) ||
diff --git a/src/ssl/ssl_transcript.cc b/src/ssl/ssl_transcript.cc
index ab9822f..2033dfd 100644
--- a/src/ssl/ssl_transcript.cc
+++ b/src/ssl/ssl_transcript.cc
@@ -209,6 +209,30 @@
   return EVP_MD_CTX_md(hash_.get());
 }
 
+bool SSLTranscript::UpdateForHelloRetryRequest() {
+  if (buffer_) {
+    buffer_->length = 0;
+  }
+
+  uint8_t old_hash[EVP_MAX_MD_SIZE];
+  size_t hash_len;
+  if (!GetHash(old_hash, &hash_len)) {
+    return false;
+  }
+  const uint8_t header[4] = {SSL3_MT_MESSAGE_HASH, 0, 0,
+                             static_cast<uint8_t>(hash_len)};
+  if (!EVP_DigestInit_ex(hash_.get(), Digest(), nullptr) ||
+      !Update(header) ||
+      !Update(MakeConstSpan(old_hash, hash_len))) {
+    return false;
+  }
+  return true;
+}
+
+bool SSLTranscript::CopyHashContext(EVP_MD_CTX *ctx) {
+  return EVP_MD_CTX_copy_ex(ctx, hash_.get());
+}
+
 bool SSLTranscript::Update(Span<const uint8_t> in) {
   // Depending on the state of the handshake, either the handshake buffer may be
   // active, the rolling hash, or both.
@@ -348,12 +372,11 @@
   // its own.
   assert(!buffer_);
 
-  const char *label = TLS_MD_CLIENT_FINISH_CONST;
-  size_t label_len = TLS_MD_SERVER_FINISH_CONST_SIZE;
-  if (from_server) {
-    label = TLS_MD_SERVER_FINISH_CONST;
-    label_len = TLS_MD_SERVER_FINISH_CONST_SIZE;
-  }
+  static const char kClientLabel[] = "client finished";
+  static const char kServerLabel[] = "server finished";
+  auto label = from_server
+                   ? MakeConstSpan(kServerLabel, sizeof(kServerLabel) - 1)
+                   : MakeConstSpan(kClientLabel, sizeof(kClientLabel) - 1);
 
   uint8_t digests[EVP_MAX_MD_SIZE];
   size_t digests_len;
@@ -362,9 +385,9 @@
   }
 
   static const size_t kFinishedLen = 12;
-  if (!tls1_prf(Digest(), out, kFinishedLen, session->master_key,
-                session->master_key_length, label, label_len, digests,
-                digests_len, NULL, 0)) {
+  if (!tls1_prf(Digest(), MakeSpan(out, kFinishedLen),
+                MakeConstSpan(session->master_key, session->master_key_length),
+                label, MakeConstSpan(digests, digests_len), {})) {
     return false;
   }
 
diff --git a/src/ssl/ssl_versions.cc b/src/ssl/ssl_versions.cc
index ccae6ef..1f30b41 100644
--- a/src/ssl/ssl_versions.cc
+++ b/src/ssl/ssl_versions.cc
@@ -35,6 +35,7 @@
       return true;
 
     case TLS1_3_DRAFT_VERSION:
+    case TLS1_3_DRAFT21_VERSION:
     case TLS1_3_EXPERIMENT_VERSION:
     case TLS1_3_EXPERIMENT2_VERSION:
     case TLS1_3_EXPERIMENT3_VERSION:
@@ -63,6 +64,7 @@
     TLS1_3_EXPERIMENT2_VERSION,
     TLS1_3_EXPERIMENT_VERSION,
     TLS1_3_DRAFT_VERSION,
+    TLS1_3_DRAFT21_VERSION,
     TLS1_2_VERSION,
     TLS1_1_VERSION,
     TLS1_VERSION,
@@ -106,6 +108,7 @@
 static const char *ssl_version_to_string(uint16_t version) {
   switch (version) {
     case TLS1_3_DRAFT_VERSION:
+    case TLS1_3_DRAFT21_VERSION:
     case TLS1_3_EXPERIMENT_VERSION:
     case TLS1_3_EXPERIMENT2_VERSION:
     case TLS1_3_EXPERIMENT3_VERSION:
@@ -138,6 +141,7 @@
   switch (version) {
     // Report TLS 1.3 draft versions as TLS 1.3 in the public API.
     case TLS1_3_DRAFT_VERSION:
+    case TLS1_3_DRAFT21_VERSION:
     case TLS1_3_EXPERIMENT_VERSION:
     case TLS1_3_EXPERIMENT2_VERSION:
     case TLS1_3_EXPERIMENT3_VERSION:
@@ -152,6 +156,7 @@
 // used in context where that does not matter.
 static bool api_version_to_wire(uint16_t *out, uint16_t version) {
   if (version == TLS1_3_DRAFT_VERSION ||
+      version == TLS1_3_DRAFT21_VERSION ||
       version == TLS1_3_EXPERIMENT_VERSION ||
       version == TLS1_3_EXPERIMENT2_VERSION ||
       version == TLS1_3_EXPERIMENT3_VERSION) {
@@ -301,34 +306,42 @@
 
 bool ssl_supports_version(SSL_HANDSHAKE *hs, uint16_t version) {
   SSL *const ssl = hs->ssl;
-  // As a client, only allow the configured TLS 1.3 variant. As a server,
-  // support all TLS 1.3 variants as long as tls13_variant is set to a
-  // non-default value.
-  if (ssl->server) {
-    if (ssl->tls13_variant == tls13_default &&
-        (version == TLS1_3_EXPERIMENT_VERSION ||
-         version == TLS1_3_EXPERIMENT2_VERSION ||
-         version == TLS1_3_EXPERIMENT3_VERSION)) {
-      return false;
-    }
-  } else {
-    if ((ssl->tls13_variant != tls13_experiment &&
-         version == TLS1_3_EXPERIMENT_VERSION) ||
-        (ssl->tls13_variant != tls13_experiment2 &&
-         version == TLS1_3_EXPERIMENT2_VERSION) ||
-        (ssl->tls13_variant != tls13_experiment3 &&
-         version == TLS1_3_EXPERIMENT3_VERSION) ||
-        (ssl->tls13_variant != tls13_default &&
-         version == TLS1_3_DRAFT_VERSION)) {
-      return false;
-    }
+  uint16_t protocol_version;
+  if (!method_supports_version(ssl->method, version) ||
+      !ssl_protocol_version_from_wire(&protocol_version, version) ||
+      hs->min_version > protocol_version ||
+      protocol_version > hs->max_version) {
+    return false;
   }
 
-  uint16_t protocol_version;
-  return method_supports_version(ssl->method, version) &&
-         ssl_protocol_version_from_wire(&protocol_version, version) &&
-         hs->min_version <= protocol_version &&
-         protocol_version <= hs->max_version;
+  // TLS 1.3 variants must additionally match |tls13_variant|.
+  if (protocol_version != TLS1_3_VERSION ||
+      (ssl->tls13_variant == tls13_experiment &&
+       version == TLS1_3_EXPERIMENT_VERSION) ||
+      (ssl->tls13_variant == tls13_experiment2 &&
+       version == TLS1_3_EXPERIMENT2_VERSION) ||
+      (ssl->tls13_variant == tls13_experiment3 &&
+       version == TLS1_3_EXPERIMENT3_VERSION) ||
+      (ssl->tls13_variant == tls13_draft21 &&
+       version == TLS1_3_DRAFT21_VERSION) ||
+      (ssl->tls13_variant == tls13_default &&
+       version == TLS1_3_DRAFT_VERSION)) {
+    return true;
+  }
+
+  // The server, when not configured at |tls13_default|, should additionally
+  // enable all variants, except draft-21 which is implemented solely for QUIC
+  // interop testing and will not be deployed. Currently, this is to implement
+  // the draft-18 vs. experiments field trials. In the future, this will be to
+  // transition cleanly to a future draft-22 which hopefully includes the
+  // deployability fixes.
+  if (ssl->server &&
+      ssl->tls13_variant != tls13_default &&
+      version != TLS1_3_DRAFT21_VERSION) {
+    return true;
+  }
+
+  return false;
 }
 
 bool ssl_add_supported_versions(SSL_HANDSHAKE *hs, CBB *cbb) {
@@ -375,6 +388,10 @@
   return false;
 }
 
+bool ssl_is_draft21(uint16_t version) {
+  return version == TLS1_3_DRAFT21_VERSION;
+}
+
 bool ssl_is_resumption_experiment(uint16_t version) {
   return version == TLS1_3_EXPERIMENT_VERSION ||
          version == TLS1_3_EXPERIMENT2_VERSION ||
diff --git a/src/ssl/t1_enc.cc b/src/ssl/t1_enc.cc
index 1298a10..2a09987 100644
--- a/src/ssl/t1_enc.cc
+++ b/src/ssl/t1_enc.cc
@@ -155,26 +155,26 @@
 namespace bssl {
 
 // tls1_P_hash computes the TLS P_<hash> function as described in RFC 5246,
-// section 5. It XORs |out_len| bytes to |out|, using |md| as the hash and
-// |secret| as the secret. |seed1| through |seed3| are concatenated to form the
-// seed parameter. It returns one on success and zero on failure.
-static int tls1_P_hash(uint8_t *out, size_t out_len, const EVP_MD *md,
-                       const uint8_t *secret, size_t secret_len,
-                       const uint8_t *seed1, size_t seed1_len,
-                       const uint8_t *seed2, size_t seed2_len,
-                       const uint8_t *seed3, size_t seed3_len) {
+// section 5. It XORs |out.size()| bytes to |out|, using |md| as the hash and
+// |secret| as the secret. |label|, |seed1|, and |seed2| are concatenated to
+// form the seed parameter. It returns true on success and false on failure.
+static bool tls1_P_hash(Span<uint8_t> out, const EVP_MD *md,
+                        Span<const uint8_t> secret, Span<const char> label,
+                        Span<const uint8_t> seed1, Span<const uint8_t> seed2) {
   ScopedHMAC_CTX ctx, ctx_tmp, ctx_init;
   uint8_t A1[EVP_MAX_MD_SIZE];
   unsigned A1_len;
-  int ret = 0;
+  bool ret = false;
 
   size_t chunk = EVP_MD_size(md);
 
-  if (!HMAC_Init_ex(ctx_init.get(), secret, secret_len, md, NULL) ||
+  if (!HMAC_Init_ex(ctx_init.get(), secret.data(), secret.size(), md,
+                    nullptr) ||
       !HMAC_CTX_copy_ex(ctx.get(), ctx_init.get()) ||
-      !HMAC_Update(ctx.get(), seed1, seed1_len) ||
-      !HMAC_Update(ctx.get(), seed2, seed2_len) ||
-      !HMAC_Update(ctx.get(), seed3, seed3_len) ||
+      !HMAC_Update(ctx.get(), reinterpret_cast<const uint8_t *>(label.data()),
+                   label.size()) ||
+      !HMAC_Update(ctx.get(), seed1.data(), seed1.size()) ||
+      !HMAC_Update(ctx.get(), seed2.data(), seed2.size()) ||
       !HMAC_Final(ctx.get(), A1, &A1_len)) {
     goto err;
   }
@@ -185,27 +185,26 @@
     if (!HMAC_CTX_copy_ex(ctx.get(), ctx_init.get()) ||
         !HMAC_Update(ctx.get(), A1, A1_len) ||
         // Save a copy of |ctx| to compute the next A1 value below.
-        (out_len > chunk && !HMAC_CTX_copy_ex(ctx_tmp.get(), ctx.get())) ||
-        !HMAC_Update(ctx.get(), seed1, seed1_len) ||
-        !HMAC_Update(ctx.get(), seed2, seed2_len) ||
-        !HMAC_Update(ctx.get(), seed3, seed3_len) ||
+        (out.size() > chunk && !HMAC_CTX_copy_ex(ctx_tmp.get(), ctx.get())) ||
+        !HMAC_Update(ctx.get(), reinterpret_cast<const uint8_t *>(label.data()),
+                     label.size()) ||
+        !HMAC_Update(ctx.get(), seed1.data(), seed1.size()) ||
+        !HMAC_Update(ctx.get(), seed2.data(), seed2.size()) ||
         !HMAC_Final(ctx.get(), hmac, &len)) {
       goto err;
     }
     assert(len == chunk);
 
     // XOR the result into |out|.
-    if (len > out_len) {
-      len = out_len;
+    if (len > out.size()) {
+      len = out.size();
     }
-    unsigned i;
-    for (i = 0; i < len; i++) {
+    for (unsigned i = 0; i < len; i++) {
       out[i] ^= hmac[i];
     }
-    out += len;
-    out_len -= len;
+    out = out.subspan(len);
 
-    if (out_len == 0) {
+    if (out.empty()) {
       break;
     }
 
@@ -215,105 +214,86 @@
     }
   }
 
-  ret = 1;
+  ret = true;
 
 err:
   OPENSSL_cleanse(A1, sizeof(A1));
   return ret;
 }
 
-int tls1_prf(const EVP_MD *digest, uint8_t *out, size_t out_len,
-             const uint8_t *secret, size_t secret_len, const char *label,
-             size_t label_len, const uint8_t *seed1, size_t seed1_len,
-             const uint8_t *seed2, size_t seed2_len) {
-  if (out_len == 0) {
-    return 1;
+bool tls1_prf(const EVP_MD *digest, Span<uint8_t> out,
+              Span<const uint8_t> secret, Span<const char> label,
+              Span<const uint8_t> seed1, Span<const uint8_t> seed2) {
+  if (out.empty()) {
+    return true;
   }
 
-  OPENSSL_memset(out, 0, out_len);
+  OPENSSL_memset(out.data(), 0, out.size());
 
   if (digest == EVP_md5_sha1()) {
-    // If using the MD5/SHA1 PRF, |secret| is partitioned between SHA-1 and
-    // MD5, MD5 first.
-    size_t secret_half = secret_len - (secret_len / 2);
-    if (!tls1_P_hash(out, out_len, EVP_md5(), secret, secret_half,
-                     (const uint8_t *)label, label_len, seed1, seed1_len, seed2,
-                     seed2_len)) {
-      return 0;
+    // If using the MD5/SHA1 PRF, |secret| is partitioned between MD5 and SHA-1.
+    size_t secret_half = secret.size() - (secret.size() / 2);
+    if (!tls1_P_hash(out, EVP_md5(), secret.subspan(0, secret_half), label,
+                     seed1, seed2)) {
+      return false;
     }
 
-    // Note that, if |secret_len| is odd, the two halves share a byte.
-    secret = secret + (secret_len - secret_half);
-    secret_len = secret_half;
-
+    // Note that, if |secret.size()| is odd, the two halves share a byte.
+    secret = secret.subspan(secret.size() - secret_half);
     digest = EVP_sha1();
   }
 
-  if (!tls1_P_hash(out, out_len, digest, secret, secret_len,
-                   (const uint8_t *)label, label_len, seed1, seed1_len, seed2,
-                   seed2_len)) {
-    return 0;
-  }
-
-  return 1;
+  return tls1_P_hash(out, digest, secret, label, seed1, seed2);
 }
 
-static int ssl3_prf(uint8_t *out, size_t out_len, const uint8_t *secret,
-                    size_t secret_len, const char *label, size_t label_len,
-                    const uint8_t *seed1, size_t seed1_len,
-                    const uint8_t *seed2, size_t seed2_len) {
+static bool ssl3_prf(Span<uint8_t> out, Span<const uint8_t> secret,
+                     Span<const char> label, Span<const uint8_t> seed1,
+                     Span<const uint8_t> seed2) {
   ScopedEVP_MD_CTX md5;
   ScopedEVP_MD_CTX sha1;
   uint8_t buf[16], smd[SHA_DIGEST_LENGTH];
   uint8_t c = 'A';
-  size_t i, j, k;
-
-  k = 0;
-  for (i = 0; i < out_len; i += MD5_DIGEST_LENGTH) {
+  size_t k = 0;
+  while (!out.empty()) {
     k++;
     if (k > sizeof(buf)) {
       // bug: 'buf' is too small for this ciphersuite
       OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
-      return 0;
+      return false;
     }
 
-    for (j = 0; j < k; j++) {
+    for (size_t j = 0; j < k; j++) {
       buf[j] = c;
     }
     c++;
     if (!EVP_DigestInit_ex(sha1.get(), EVP_sha1(), NULL)) {
       OPENSSL_PUT_ERROR(SSL, ERR_LIB_EVP);
-      return 0;
+      return false;
     }
     EVP_DigestUpdate(sha1.get(), buf, k);
-    EVP_DigestUpdate(sha1.get(), secret, secret_len);
+    EVP_DigestUpdate(sha1.get(), secret.data(), secret.size());
     // |label| is ignored for SSLv3.
-    if (seed1_len) {
-      EVP_DigestUpdate(sha1.get(), seed1, seed1_len);
-    }
-    if (seed2_len) {
-      EVP_DigestUpdate(sha1.get(), seed2, seed2_len);
-    }
+    EVP_DigestUpdate(sha1.get(), seed1.data(), seed1.size());
+    EVP_DigestUpdate(sha1.get(), seed2.data(), seed2.size());
     EVP_DigestFinal_ex(sha1.get(), smd, NULL);
 
     if (!EVP_DigestInit_ex(md5.get(), EVP_md5(), NULL)) {
       OPENSSL_PUT_ERROR(SSL, ERR_LIB_EVP);
-      return 0;
+      return false;
     }
-    EVP_DigestUpdate(md5.get(), secret, secret_len);
+    EVP_DigestUpdate(md5.get(), secret.data(), secret.size());
     EVP_DigestUpdate(md5.get(), smd, SHA_DIGEST_LENGTH);
-    if (i + MD5_DIGEST_LENGTH > out_len) {
+    if (out.size() < MD5_DIGEST_LENGTH) {
       EVP_DigestFinal_ex(md5.get(), smd, NULL);
-      OPENSSL_memcpy(out, smd, out_len - i);
-    } else {
-      EVP_DigestFinal_ex(md5.get(), out, NULL);
+      OPENSSL_memcpy(out.data(), smd, out.size());
+      break;
     }
-
-    out += MD5_DIGEST_LENGTH;
+    EVP_DigestFinal_ex(md5.get(), out.data(), NULL);
+    out = out.subspan(MD5_DIGEST_LENGTH);
   }
 
   OPENSSL_cleanse(smd, SHA_DIGEST_LENGTH);
-  return 1;
+  return true;
 }
 
 static bool get_key_block_lengths(const SSL *ssl, size_t *out_mac_secret_len,
@@ -405,33 +385,33 @@
 }
 
 int tls1_generate_master_secret(SSL_HANDSHAKE *hs, uint8_t *out,
-                                const uint8_t *premaster,
-                                size_t premaster_len) {
+                                Span<const uint8_t> premaster) {
+  static const char kMasterSecretLabel[] = "master secret";
+  static const char kExtendedMasterSecretLabel[] = "extended master secret";
+
   const SSL *ssl = hs->ssl;
+  auto out_span = MakeSpan(out, SSL3_MASTER_SECRET_SIZE);
   if (hs->extended_master_secret) {
+    auto label = MakeConstSpan(kExtendedMasterSecretLabel,
+                               sizeof(kExtendedMasterSecretLabel) - 1);
     uint8_t digests[EVP_MAX_MD_SIZE];
     size_t digests_len;
     if (!hs->transcript.GetHash(digests, &digests_len) ||
-        !tls1_prf(hs->transcript.Digest(), out, SSL3_MASTER_SECRET_SIZE,
-                  premaster, premaster_len, TLS_MD_EXTENDED_MASTER_SECRET_CONST,
-                  TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE, digests,
-                  digests_len, NULL, 0)) {
+        !tls1_prf(hs->transcript.Digest(), out_span, premaster, label,
+                  MakeConstSpan(digests, digests_len), {})) {
       return 0;
     }
   } else {
+    auto label =
+        MakeConstSpan(kMasterSecretLabel, sizeof(kMasterSecretLabel) - 1);
     if (ssl_protocol_version(ssl) == SSL3_VERSION) {
-      if (!ssl3_prf(out, SSL3_MASTER_SECRET_SIZE, premaster, premaster_len,
-                    TLS_MD_MASTER_SECRET_CONST, TLS_MD_MASTER_SECRET_CONST_SIZE,
-                    ssl->s3->client_random, SSL3_RANDOM_SIZE,
-                    ssl->s3->server_random, SSL3_RANDOM_SIZE)) {
+      if (!ssl3_prf(out_span, premaster, label, ssl->s3->client_random,
+                    ssl->s3->server_random)) {
         return 0;
       }
     } else {
-      if (!tls1_prf(hs->transcript.Digest(), out, SSL3_MASTER_SECRET_SIZE,
-                    premaster, premaster_len, TLS_MD_MASTER_SECRET_CONST,
-                    TLS_MD_MASTER_SECRET_CONST_SIZE, ssl->s3->client_random,
-                    SSL3_RANDOM_SIZE, ssl->s3->server_random,
-                    SSL3_RANDOM_SIZE)) {
+      if (!tls1_prf(hs->transcript.Digest(), out_span, premaster, label,
+                    ssl->s3->client_random, ssl->s3->server_random)) {
         return 0;
       }
     }
@@ -457,18 +437,20 @@
 
 int SSL_generate_key_block(const SSL *ssl, uint8_t *out, size_t out_len) {
   const SSL_SESSION *session = SSL_get_session(ssl);
+  auto out_span = MakeSpan(out, out_len);
+  auto master_key =
+      MakeConstSpan(session->master_key, session->master_key_length);
+  static const char kLabel[] = "key expansion";
+  auto label = MakeConstSpan(kLabel, sizeof(kLabel) - 1);
+
   if (ssl_protocol_version(ssl) == SSL3_VERSION) {
-    return ssl3_prf(out, out_len, session->master_key,
-                    session->master_key_length, TLS_MD_KEY_EXPANSION_CONST,
-                    TLS_MD_KEY_EXPANSION_CONST_SIZE, ssl->s3->server_random,
-                    SSL3_RANDOM_SIZE, ssl->s3->client_random, SSL3_RANDOM_SIZE);
+    return ssl3_prf(out_span, master_key, label, ssl->s3->server_random,
+                    ssl->s3->client_random);
   }
 
   const EVP_MD *digest = ssl_session_get_digest(session);
-  return tls1_prf(digest, out, out_len, session->master_key,
-                  session->master_key_length, TLS_MD_KEY_EXPANSION_CONST,
-                  TLS_MD_KEY_EXPANSION_CONST_SIZE, ssl->s3->server_random,
-                  SSL3_RANDOM_SIZE, ssl->s3->client_random, SSL3_RANDOM_SIZE);
+  return tls1_prf(digest, out_span, master_key, label, ssl->s3->server_random,
+                  ssl->s3->client_random);
 }
 
 int SSL_export_keying_material(SSL *ssl, uint8_t *out, size_t out_len,
@@ -497,26 +479,25 @@
     }
     seed_len += 2 + context_len;
   }
-  uint8_t *seed = (uint8_t *)OPENSSL_malloc(seed_len);
-  if (seed == NULL) {
+  Array<uint8_t> seed;
+  if (!seed.Init(seed_len)) {
     OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
-  OPENSSL_memcpy(seed, ssl->s3->client_random, SSL3_RANDOM_SIZE);
-  OPENSSL_memcpy(seed + SSL3_RANDOM_SIZE, ssl->s3->server_random,
+  OPENSSL_memcpy(seed.data(), ssl->s3->client_random, SSL3_RANDOM_SIZE);
+  OPENSSL_memcpy(seed.data() + SSL3_RANDOM_SIZE, ssl->s3->server_random,
                  SSL3_RANDOM_SIZE);
   if (use_context) {
-    seed[2 * SSL3_RANDOM_SIZE] = (uint8_t)(context_len >> 8);
-    seed[2 * SSL3_RANDOM_SIZE + 1] = (uint8_t)context_len;
-    OPENSSL_memcpy(seed + 2 * SSL3_RANDOM_SIZE + 2, context, context_len);
+    seed[2 * SSL3_RANDOM_SIZE] = static_cast<uint8_t>(context_len >> 8);
+    seed[2 * SSL3_RANDOM_SIZE + 1] = static_cast<uint8_t>(context_len);
+    OPENSSL_memcpy(seed.data() + 2 * SSL3_RANDOM_SIZE + 2, context, context_len);
   }
 
   const SSL_SESSION *session = SSL_get_session(ssl);
   const EVP_MD *digest = ssl_session_get_digest(session);
-  int ret = tls1_prf(digest, out, out_len, session->master_key,
-                     session->master_key_length, label, label_len, seed,
-                     seed_len, NULL, 0);
-  OPENSSL_free(seed);
-  return ret;
+  return tls1_prf(
+      digest, MakeSpan(out, out_len),
+      MakeConstSpan(session->master_key, session->master_key_length),
+      MakeConstSpan(label, label_len), seed, {});
 }
diff --git a/src/ssl/t1_lib.cc b/src/ssl/t1_lib.cc
index 31b51c9..a7bfec4 100644
--- a/src/ssl/t1_lib.cc
+++ b/src/ssl/t1_lib.cc
@@ -1800,11 +1800,21 @@
 
 static bool ext_pre_shared_key_add_clienthello(SSL_HANDSHAKE *hs, CBB *out) {
   SSL *const ssl = hs->ssl;
+  hs->needs_psk_binder = false;
   if (hs->max_version < TLS1_3_VERSION || ssl->session == NULL ||
       ssl_session_protocol_version(ssl->session) < TLS1_3_VERSION) {
     return true;
   }
 
+  // Per draft-ietf-tls-tls13-21 section 4.1.4, skip offering the session if the
+  // selected cipher in HelloRetryRequest does not match. This avoids performing
+  // the transcript hash transformation for multiple hashes.
+  if (hs->received_hello_retry_request &&
+      ssl_is_draft21(ssl->version) &&
+      ssl->session->cipher->algorithm_prf != hs->new_cipher->algorithm_prf) {
+    return true;
+  }
+
   struct OPENSSL_timeval now;
   ssl_get_current_time(ssl, &now);
   uint32_t ticket_age = 1000 * (now.tv_sec - ssl->session->time);
@@ -3265,54 +3275,45 @@
   return 1;
 }
 
-int tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb) {
+bool tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb) {
   SSL *const ssl = hs->ssl;
   uint8_t digest[EVP_MAX_MD_SIZE];
   size_t digest_len;
   if (!tls1_channel_id_hash(hs, digest, &digest_len)) {
-    return 0;
+    return false;
   }
 
   EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(ssl->tlsext_channel_id_private);
-  if (ec_key == NULL) {
+  if (ec_key == nullptr) {
     OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
-    return 0;
+    return false;
   }
 
-  int ret = 0;
-  BIGNUM *x = BN_new();
-  BIGNUM *y = BN_new();
-  ECDSA_SIG *sig = NULL;
-  if (x == NULL || y == NULL ||
+  UniquePtr<BIGNUM> x(BN_new()), y(BN_new());
+  if (!x || !y ||
       !EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec_key),
                                            EC_KEY_get0_public_key(ec_key),
-                                           x, y, NULL)) {
-    goto err;
+                                           x.get(), y.get(), nullptr)) {
+    return false;
   }
 
-  sig = ECDSA_do_sign(digest, digest_len, ec_key);
-  if (sig == NULL) {
-    goto err;
+  UniquePtr<ECDSA_SIG> sig(ECDSA_do_sign(digest, digest_len, ec_key));
+  if (!sig) {
+    return false;
   }
 
   CBB child;
   if (!CBB_add_u16(cbb, TLSEXT_TYPE_channel_id) ||
       !CBB_add_u16_length_prefixed(cbb, &child) ||
-      !BN_bn2cbb_padded(&child, 32, x) ||
-      !BN_bn2cbb_padded(&child, 32, y) ||
+      !BN_bn2cbb_padded(&child, 32, x.get()) ||
+      !BN_bn2cbb_padded(&child, 32, y.get()) ||
       !BN_bn2cbb_padded(&child, 32, sig->r) ||
       !BN_bn2cbb_padded(&child, 32, sig->s) ||
       !CBB_flush(cbb)) {
-    goto err;
+    return false;
   }
 
-  ret = 1;
-
-err:
-  BN_free(x);
-  BN_free(y);
-  ECDSA_SIG_free(sig);
-  return ret;
+  return true;
 }
 
 int tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len) {
diff --git a/src/ssl/test/bssl_shim.cc b/src/ssl/test/bssl_shim.cc
index d439cb5..7eca21d 100644
--- a/src/ssl/test/bssl_shim.cc
+++ b/src/ssl/test/bssl_shim.cc
@@ -1278,6 +1278,9 @@
   if (!config->use_client_ca_list.empty()) {
     if (config->use_client_ca_list == "<NULL>") {
       SSL_CTX_set_client_CA_list(ssl_ctx.get(), nullptr);
+    } else if (config->use_client_ca_list == "<EMPTY>") {
+      bssl::UniquePtr<STACK_OF(X509_NAME)> names;
+      SSL_CTX_set_client_CA_list(ssl_ctx.get(), names.release());
     } else {
       bssl::UniquePtr<STACK_OF(X509_NAME)> names =
           DecodeHexX509Names(config->use_client_ca_list);
@@ -2396,14 +2399,13 @@
     }
 
     if (expect_new_session) {
-      bool got_early_data_info =
+      bool got_early_data =
           GetTestState(ssl)->new_session->ticket_max_early_data != 0;
-      if (config->expect_early_data_info != got_early_data_info) {
-        fprintf(
-            stderr,
-            "new session did%s include ticket_early_data_info, but we expected "
-            "the opposite\n",
-            got_early_data_info ? "" : " not");
+      if (config->expect_ticket_supports_early_data != got_early_data) {
+        fprintf(stderr,
+                "new session did%s support early data, but we expected the "
+                "opposite\n",
+                got_early_data ? "" : " not");
         return false;
       }
     }
diff --git a/src/ssl/test/runner/cipher_suites.go b/src/ssl/test/runner/cipher_suites.go
index 2681e71..f4c5900 100644
--- a/src/ssl/test/runner/cipher_suites.go
+++ b/src/ssl/test/runner/cipher_suites.go
@@ -11,7 +11,6 @@
 	"crypto/des"
 	"crypto/hmac"
 	"crypto/md5"
-	"crypto/rc4"
 	"crypto/sha1"
 	"crypto/sha256"
 	"crypto/sha512"
@@ -62,9 +61,6 @@
 	// suiteSHA384 indicates that the cipher suite uses SHA384 as the
 	// handshake hash.
 	suiteSHA384
-	// suiteNoDTLS indicates that the cipher suite cannot be used
-	// in DTLS.
-	suiteNoDTLS
 	// suitePSK indicates that the cipher suite authenticates with
 	// a pre-shared key rather than a server private key.
 	suitePSK
@@ -99,8 +95,6 @@
 }
 
 var cipherSuites = []*cipherSuite{
-	// Ciphersuite order is chosen so that ECDHE comes before plain RSA
-	// and RC4 comes before AES (because of the Lucky13 attack).
 	{TLS_CHACHA20_POLY1305_SHA256, 32, 0, ivLenChaCha20Poly1305, nil, suiteTLS13, nil, nil, aeadCHACHA20POLY1305},
 	{TLS_AES_128_GCM_SHA256, 16, 0, ivLenAESGCM, nil, suiteTLS13, nil, nil, aeadAESGCM},
 	{TLS_AES_256_GCM_SHA384, 32, 0, ivLenAESGCM, nil, suiteTLS13 | suiteSHA384, nil, nil, aeadAESGCM},
@@ -110,8 +104,6 @@
 	{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 16, 0, ivLenAESGCM, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteTLS12, nil, nil, aeadAESGCM},
 	{TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 32, 0, ivLenAESGCM, ecdheRSAKA, suiteECDHE | suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
 	{TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, 32, 0, ivLenAESGCM, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
-	{TLS_ECDHE_RSA_WITH_RC4_128_SHA, 16, 20, noIV, ecdheRSAKA, suiteECDHE | suiteNoDTLS, cipherRC4, macSHA1, nil},
-	{TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 16, 20, noIV, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteNoDTLS, cipherRC4, macSHA1, nil},
 	{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, 16, 32, ivLenAES, ecdheRSAKA, suiteECDHE | suiteTLS12, cipherAES, macSHA256, nil},
 	{TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, 16, 32, ivLenAES, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteTLS12, cipherAES, macSHA256, nil},
 	{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 16, 20, ivLenAES, ecdheRSAKA, suiteECDHE, cipherAES, macSHA1, nil},
@@ -122,8 +114,6 @@
 	{TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 32, 20, ivLenAES, ecdheECDSAKA, suiteECDHE | suiteECDSA, cipherAES, macSHA1, nil},
 	{TLS_RSA_WITH_AES_128_GCM_SHA256, 16, 0, ivLenAESGCM, rsaKA, suiteTLS12, nil, nil, aeadAESGCM},
 	{TLS_RSA_WITH_AES_256_GCM_SHA384, 32, 0, ivLenAESGCM, rsaKA, suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
-	{TLS_RSA_WITH_RC4_128_SHA, 16, 20, noIV, rsaKA, suiteNoDTLS, cipherRC4, macSHA1, nil},
-	{TLS_RSA_WITH_RC4_128_MD5, 16, 16, noIV, rsaKA, suiteNoDTLS, cipherRC4, macMD5, nil},
 	{TLS_RSA_WITH_AES_128_CBC_SHA256, 16, 32, ivLenAES, rsaKA, suiteTLS12, cipherAES, macSHA256, nil},
 	{TLS_RSA_WITH_AES_256_CBC_SHA256, 32, 32, ivLenAES, rsaKA, suiteTLS12, cipherAES, macSHA256, nil},
 	{TLS_RSA_WITH_AES_128_CBC_SHA, 16, 20, ivLenAES, rsaKA, 0, cipherAES, macSHA1, nil},
@@ -133,10 +123,9 @@
 	{TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, 32, 0, ivLenChaCha20Poly1305, ecdhePSKKA, suiteECDHE | suitePSK | suiteTLS12, nil, nil, aeadCHACHA20POLY1305},
 	{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, 16, 20, ivLenAES, ecdhePSKKA, suiteECDHE | suitePSK, cipherAES, macSHA1, nil},
 	{TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, 32, 20, ivLenAES, ecdhePSKKA, suiteECDHE | suitePSK, cipherAES, macSHA1, nil},
-	{TLS_PSK_WITH_RC4_128_SHA, 16, 20, noIV, pskKA, suiteNoDTLS | suitePSK, cipherRC4, macSHA1, nil},
 	{TLS_PSK_WITH_AES_128_CBC_SHA, 16, 20, ivLenAES, pskKA, suitePSK, cipherAES, macSHA1, nil},
 	{TLS_PSK_WITH_AES_256_CBC_SHA, 32, 20, ivLenAES, pskKA, suitePSK, cipherAES, macSHA1, nil},
-	{TLS_RSA_WITH_NULL_SHA, 0, 20, noIV, rsaKA, suiteNoDTLS, cipherNull, macSHA1, nil},
+	{TLS_RSA_WITH_NULL_SHA, 0, 20, noIV, rsaKA, 0, cipherNull, macSHA1, nil},
 }
 
 func noIV(vers uint16) int {
@@ -168,11 +157,6 @@
 	return nullCipher{}
 }
 
-func cipherRC4(key, iv []byte, isRead bool) interface{} {
-	cipher, _ := rc4.NewCipher(key)
-	return cipher
-}
-
 func cipher3DES(key, iv []byte, isRead bool) interface{} {
 	block, _ := des.NewTripleDESCipher(key)
 	if isRead {
@@ -448,22 +432,17 @@
 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
 const (
 	TLS_RSA_WITH_NULL_SHA                         uint16 = 0x0002
-	TLS_RSA_WITH_RC4_128_MD5                      uint16 = 0x0004
-	TLS_RSA_WITH_RC4_128_SHA                      uint16 = 0x0005
 	TLS_RSA_WITH_3DES_EDE_CBC_SHA                 uint16 = 0x000a
 	TLS_RSA_WITH_AES_128_CBC_SHA                  uint16 = 0x002f
 	TLS_RSA_WITH_AES_256_CBC_SHA                  uint16 = 0x0035
 	TLS_RSA_WITH_AES_128_CBC_SHA256               uint16 = 0x003c
 	TLS_RSA_WITH_AES_256_CBC_SHA256               uint16 = 0x003d
-	TLS_PSK_WITH_RC4_128_SHA                      uint16 = 0x008a
 	TLS_PSK_WITH_AES_128_CBC_SHA                  uint16 = 0x008c
 	TLS_PSK_WITH_AES_256_CBC_SHA                  uint16 = 0x008d
 	TLS_RSA_WITH_AES_128_GCM_SHA256               uint16 = 0x009c
 	TLS_RSA_WITH_AES_256_GCM_SHA384               uint16 = 0x009d
-	TLS_ECDHE_ECDSA_WITH_RC4_128_SHA              uint16 = 0xc007
 	TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA          uint16 = 0xc009
 	TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA          uint16 = 0xc00a
-	TLS_ECDHE_RSA_WITH_RC4_128_SHA                uint16 = 0xc011
 	TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA           uint16 = 0xc012
 	TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA            uint16 = 0xc013
 	TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA            uint16 = 0xc014
diff --git a/src/ssl/test/runner/common.go b/src/ssl/test/runner/common.go
index eee1337..9e0deef 100644
--- a/src/ssl/test/runner/common.go
+++ b/src/ssl/test/runner/common.go
@@ -34,6 +34,7 @@
 // A draft version of TLS 1.3 that is sent over the wire for the current draft.
 const (
 	tls13DraftVersion       = 0x7f12
+	tls13Draft21Version     = 0x7f15
 	tls13ExperimentVersion  = 0x7e01
 	tls13Experiment2Version = 0x7e02
 	tls13Experiment3Version = 0x7e03
@@ -44,10 +45,12 @@
 	TLS13Experiment  = 1
 	TLS13Experiment2 = 2
 	TLS13Experiment3 = 3
+	TLS13Draft21     = 4
 )
 
 var allTLSWireVersions = []uint16{
 	tls13DraftVersion,
+	tls13Draft21Version,
 	tls13Experiment3Version,
 	tls13Experiment2Version,
 	tls13ExperimentVersion,
@@ -91,6 +94,7 @@
 	typeServerHello         uint8 = 2
 	typeHelloVerifyRequest  uint8 = 3
 	typeNewSessionTicket    uint8 = 4
+	typeEndOfEarlyData      uint8 = 5 // draft-ietf-tls-tls13-21
 	typeHelloRetryRequest   uint8 = 6 // draft-ietf-tls-tls13-16
 	typeEncryptedExtensions uint8 = 8 // draft-ietf-tls-tls13-16
 	typeCertificate         uint8 = 11
@@ -104,6 +108,7 @@
 	typeKeyUpdate           uint8 = 24  // draft-ietf-tls-tls13-16
 	typeNextProtocol        uint8 = 67  // Not IANA assigned
 	typeChannelID           uint8 = 203 // Not IANA assigned
+	typeMessageHash         uint8 = 254 // draft-ietf-tls-tls13-21
 )
 
 // TLS compression types.
@@ -131,6 +136,7 @@
 	extensionCookie                     uint16 = 44    // draft-ietf-tls-tls13-16
 	extensionPSKKeyExchangeModes        uint16 = 45    // draft-ietf-tls-tls13-18
 	extensionTicketEarlyDataInfo        uint16 = 46    // draft-ietf-tls-tls13-18
+	extensionCertificateAuthorities     uint16 = 47    // draft-ietf-tls-tls13-21
 	extensionCustom                     uint16 = 1234  // not IANA assigned
 	extensionNextProtoNeg               uint16 = 13172 // not IANA assigned
 	extensionRenegotiationInfo          uint16 = 0xff01
@@ -456,8 +462,7 @@
 	// MaxEarlyDataSize controls the maximum number of bytes that the
 	// server will accept in early data and advertise in a
 	// NewSessionTicketMsg. If 0, no early data will be accepted and
-	// the TicketEarlyDataInfo extension in the NewSessionTicketMsg
-	// will be omitted.
+	// the early_data extension in the NewSessionTicketMsg will be omitted.
 	MaxEarlyDataSize uint32
 
 	// SRTPProtectionProfiles, if not nil, is the list of SRTP
@@ -581,10 +586,14 @@
 	// message.
 	SkipFinished bool
 
-	// SkipEndOfEarlyData causes the implementation to skip the
-	// end_of_early_data alert.
+	// SkipEndOfEarlyData causes the implementation to skip
+	// end_of_early_data.
 	SkipEndOfEarlyData bool
 
+	// NonEmptyEndOfEarlyData causes the implementation to end an extra byte in the
+	// EndOfEarlyData.
+	NonEmptyEndOfEarlyData bool
+
 	// SkipCertificateVerify, if true causes peer to skip sending a
 	// CertificateVerify message after the Certificate message.
 	SkipCertificateVerify bool
@@ -755,6 +764,10 @@
 	// if a TLS 1.3 PSK is offered.
 	ExpectNoTLS13PSK bool
 
+	// ExpectNoTLS13PSKAfterHRR, if true, causes the server to fail the connection
+	// if a TLS 1.3 PSK is offered after HRR.
+	ExpectNoTLS13PSKAfterHRR bool
+
 	// RequireExtendedMasterSecret, if true, requires that the peer support
 	// the extended master secret option.
 	RequireExtendedMasterSecret bool
@@ -1054,13 +1067,13 @@
 	// receipt of a NewSessionTicket message.
 	ExpectNoNewSessionTicket bool
 
-	// DuplicateTicketEarlyDataInfo causes an extra empty extension of
-	// ticket_early_data_info to be sent in NewSessionTicket.
-	DuplicateTicketEarlyDataInfo bool
+	// DuplicateTicketEarlyData causes an extra empty extension of early_data to
+	// be sent in NewSessionTicket.
+	DuplicateTicketEarlyData bool
 
-	// ExpectTicketEarlyDataInfo, if true, means that the client will fail upon
-	// absence of the ticket_early_data_info extension.
-	ExpectTicketEarlyDataInfo bool
+	// ExpectTicketEarlyData, if true, means that the client will fail upon
+	// absence of the early_data extension.
+	ExpectTicketEarlyData bool
 
 	// ExpectTicketAge, if non-zero, is the expected age of the ticket that the
 	// server receives from the client.
@@ -1308,6 +1321,10 @@
 	// the specified curve in a HelloRetryRequest.
 	SendHelloRetryRequestCurve CurveID
 
+	// SendHelloRetryRequestCipherSuite, if non-zero, causes the server to send
+	// the specified cipher suite in a HelloRetryRequest.
+	SendHelloRetryRequestCipherSuite uint16
+
 	// SendHelloRetryRequestCookie, if not nil, contains a cookie to be
 	// sent by the server in HelloRetryRequest.
 	SendHelloRetryRequestCookie []byte
@@ -1345,6 +1362,14 @@
 	// a TLS 1.3 CertificateRequest.
 	SendRequestContext []byte
 
+	// OmitCertificateRequestAlgorithms, if true, omits the signature_algorithm
+	// extension in a TLS 1.3 CertificateRequest.
+	OmitCertificateRequestAlgorithms bool
+
+	// SendCustomCertificateRequest, if non-zero, send an additional custom
+	// extension in a TLS 1.3 CertificateRequest.
+	SendCustomCertificateRequest uint16
+
 	// SendSNIWarningAlert, if true, causes the server to send an
 	// unrecognized_name alert before the ServerHello.
 	SendSNIWarningAlert bool
@@ -1432,6 +1457,10 @@
 	// renegotiation handshakes.
 	RenegotiationCertificate *Certificate
 
+	// ExpectNoCertificateAuthoritiesExtension, if true, causes the client to
+	// reject CertificateRequest with the CertificateAuthorities extension.
+	ExpectNoCertificateAuthoritiesExtension bool
+
 	// UseLegacySigningAlgorithm, if non-zero, is the signature algorithm
 	// to use when signing in TLS 1.1 and earlier where algorithms are not
 	// negotiated.
@@ -1576,7 +1605,7 @@
 		switch vers {
 		case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
 			return vers, true
-		case tls13DraftVersion, tls13ExperimentVersion, tls13Experiment2Version, tls13Experiment3Version:
+		case tls13DraftVersion, tls13Draft21Version, tls13ExperimentVersion, tls13Experiment2Version, tls13Experiment3Version:
 			return VersionTLS13, true
 		}
 	}
@@ -1584,6 +1613,10 @@
 	return 0, false
 }
 
+func isDraft21(vers uint16) bool {
+	return vers == tls13Draft21Version
+}
+
 func isResumptionExperiment(vers uint16) bool {
 	return vers == tls13ExperimentVersion || vers == tls13Experiment2Version || vers == tls13Experiment3Version
 }
@@ -1603,6 +1636,7 @@
 	if (c.TLS13Variant != TLS13Experiment && wireVers == tls13ExperimentVersion) ||
 		(c.TLS13Variant != TLS13Experiment2 && wireVers == tls13Experiment2Version) ||
 		(c.TLS13Variant != TLS13Experiment3 && wireVers == tls13Experiment3Version) ||
+		(c.TLS13Variant != TLS13Draft21 && wireVers == tls13Draft21Version) ||
 		(c.TLS13Variant != TLS13Default && wireVers == tls13DraftVersion) {
 		return 0, false
 	}
diff --git a/src/ssl/test/runner/conn.go b/src/ssl/test/runner/conn.go
index 71b52f2..6a2c59c 100644
--- a/src/ssl/test/runner/conn.go
+++ b/src/ssl/test/runner/conn.go
@@ -1274,7 +1274,8 @@
 		m = new(helloRetryRequestMsg)
 	case typeNewSessionTicket:
 		m = &newSessionTicketMsg{
-			version: c.vers,
+			vers:   c.wireVersion,
+			isDTLS: c.isDTLS,
 		}
 	case typeEncryptedExtensions:
 		m = new(encryptedExtensionsMsg)
@@ -1284,6 +1285,7 @@
 		}
 	case typeCertificateRequest:
 		m = &certificateRequestMsg{
+			vers: c.wireVersion,
 			hasSignatureAlgorithm: c.vers >= VersionTLS12,
 			hasRequestContext:     c.vers >= VersionTLS13,
 		}
@@ -1309,6 +1311,8 @@
 		m = new(channelIDMsg)
 	case typeKeyUpdate:
 		m = new(keyUpdateMsg)
+	case typeEndOfEarlyData:
+		m = new(endOfEarlyDataMsg)
 	default:
 		return nil, c.in.setErrorLocked(c.sendAlert(alertUnexpectedMessage))
 	}
@@ -1469,8 +1473,8 @@
 		return errors.New("tls: no GREASE ticket extension found")
 	}
 
-	if c.config.Bugs.ExpectTicketEarlyDataInfo && newSessionTicket.maxEarlyDataSize == 0 {
-		return errors.New("tls: no ticket_early_data_info extension found")
+	if c.config.Bugs.ExpectTicketEarlyData && newSessionTicket.maxEarlyDataSize == 0 {
+		return errors.New("tls: no early_data ticket extension found")
 	}
 
 	if c.config.Bugs.ExpectNoNewSessionTicket {
@@ -1497,6 +1501,10 @@
 		earlyALPN:          c.clientProtocol,
 	}
 
+	if isDraft21(c.wireVersion) {
+		session.masterSecret = deriveSessionPSK(cipherSuite, c.wireVersion, c.resumptionSecret, newSessionTicket.ticketNonce)
+	}
+
 	cacheKey := clientSessionCacheKey(c.conn.RemoteAddr(), c.config)
 	_, ok := c.config.ClientSessionCache.Get(cacheKey)
 	if !ok || !c.config.Bugs.UseFirstSessionTicket {
@@ -1537,7 +1545,7 @@
 		if c.config.Bugs.RejectUnsolicitedKeyUpdate {
 			return errors.New("tls: unexpected KeyUpdate message")
 		}
-		if err := c.useInTrafficSecret(c.in.wireVersion, c.cipherSuite, updateTrafficSecret(c.cipherSuite.hash(), c.in.trafficSecret)); err != nil {
+		if err := c.useInTrafficSecret(c.in.wireVersion, c.cipherSuite, updateTrafficSecret(c.cipherSuite.hash(), c.wireVersion, c.in.trafficSecret)); err != nil {
 			return err
 		}
 		if keyUpdate.keyUpdateRequest == keyUpdateRequested {
@@ -1571,7 +1579,7 @@
 		return errors.New("tls: received invalid KeyUpdate message")
 	}
 
-	return c.useInTrafficSecret(c.in.wireVersion, c.cipherSuite, updateTrafficSecret(c.cipherSuite.hash(), c.in.trafficSecret))
+	return c.useInTrafficSecret(c.in.wireVersion, c.cipherSuite, updateTrafficSecret(c.cipherSuite.hash(), c.wireVersion, c.in.trafficSecret))
 }
 
 func (c *Conn) Renegotiate() error {
@@ -1789,9 +1797,16 @@
 	}
 
 	if c.vers >= VersionTLS13 {
-		// TODO(davidben): What should we do with useContext? See
-		// https://github.com/tlswg/tls13-spec/issues/546
-		return hkdfExpandLabel(c.cipherSuite.hash(), c.exporterSecret, label, context, length), nil
+		if isDraft21(c.wireVersion) {
+			hash := c.cipherSuite.hash()
+			exporterKeyingLabel := []byte("exporter")
+			contextHash := hash.New()
+			contextHash.Write(context)
+			exporterContext := hash.New().Sum(nil)
+			derivedSecret := hkdfExpandLabel(c.cipherSuite.hash(), c.wireVersion, c.exporterSecret, label, exporterContext, hash.Size())
+			return hkdfExpandLabel(c.cipherSuite.hash(), c.wireVersion, derivedSecret, exporterKeyingLabel, contextHash.Sum(nil), length), nil
+		}
+		return hkdfExpandLabel(c.cipherSuite.hash(), c.wireVersion, c.exporterSecret, label, context, length), nil
 	}
 
 	seedLen := len(c.clientRandom) + len(c.serverRandom)
@@ -1825,7 +1840,7 @@
 	return false
 }
 
-func (c *Conn) SendNewSessionTicket() error {
+func (c *Conn) SendNewSessionTicket(nonce []byte) error {
 	if c.isClient || c.vers < VersionTLS13 {
 		return errors.New("tls: cannot send post-handshake NewSessionTicket")
 	}
@@ -1845,12 +1860,17 @@
 
 	// TODO(davidben): Allow configuring these values.
 	m := &newSessionTicketMsg{
-		version:                c.vers,
-		ticketLifetime:         uint32(24 * time.Hour / time.Second),
-		duplicateEarlyDataInfo: c.config.Bugs.DuplicateTicketEarlyDataInfo,
-		customExtension:        c.config.Bugs.CustomTicketExtension,
-		ticketAgeAdd:           ticketAgeAdd,
-		maxEarlyDataSize:       c.config.MaxEarlyDataSize,
+		vers:                        c.wireVersion,
+		isDTLS:                      c.isDTLS,
+		ticketLifetime:              uint32(24 * time.Hour / time.Second),
+		duplicateEarlyDataExtension: c.config.Bugs.DuplicateTicketEarlyData,
+		customExtension:             c.config.Bugs.CustomTicketExtension,
+		ticketAgeAdd:                ticketAgeAdd,
+		maxEarlyDataSize:            c.config.MaxEarlyDataSize,
+	}
+
+	if isDraft21(c.wireVersion) {
+		m.ticketNonce = nonce
 	}
 
 	if c.config.Bugs.SendTicketLifetime != 0 {
@@ -1868,6 +1888,10 @@
 		earlyALPN:          []byte(c.clientProtocol),
 	}
 
+	if isDraft21(c.wireVersion) {
+		state.masterSecret = deriveSessionPSK(c.cipherSuite, c.wireVersion, c.resumptionSecret, nonce)
+	}
+
 	if !c.config.Bugs.SendEmptySessionTicket {
 		var err error
 		m.ticket, err = c.encryptTicket(&state)
@@ -1901,7 +1925,7 @@
 	if err := c.flushHandshake(); err != nil {
 		return err
 	}
-	c.useOutTrafficSecret(c.out.wireVersion, c.cipherSuite, updateTrafficSecret(c.cipherSuite.hash(), c.out.trafficSecret))
+	c.useOutTrafficSecret(c.out.wireVersion, c.cipherSuite, updateTrafficSecret(c.cipherSuite.hash(), c.wireVersion, c.out.trafficSecret))
 	return nil
 }
 
diff --git a/src/ssl/test/runner/handshake_client.go b/src/ssl/test/runner/handshake_client.go
index 30105a5..ba34647 100644
--- a/src/ssl/test/runner/handshake_client.go
+++ b/src/ssl/test/runner/handshake_client.go
@@ -211,10 +211,6 @@
 			if maxVersion < VersionTLS12 && suite.flags&suiteTLS12 != 0 {
 				continue
 			}
-			// Don't advertise non-DTLS cipher suites in DTLS.
-			if c.isDTLS && suite.flags&suiteNoDTLS != 0 {
-				continue
-			}
 			hello.cipherSuites = append(hello.cipherSuites, suiteId)
 			continue NextCipherSuite
 		}
@@ -376,7 +372,14 @@
 		c.writeV2Record(helloBytes)
 	} else {
 		if len(hello.pskIdentities) > 0 {
-			generatePSKBinders(hello, pskCipherSuite, session.masterSecret, []byte{}, c.config)
+			version := session.wireVersion
+			// We may have a pre-1.3 session if SendBothTickets is
+			// set. Fill in an arbitrary TLS 1.3 version to compute
+			// the binder.
+			if session.vers < VersionTLS13 {
+				version = tls13DraftVersion
+			}
+			generatePSKBinders(version, hello, pskCipherSuite, session.masterSecret, []byte{}, []byte{}, c.config)
 		}
 		helloBytes = hello.marshal()
 
@@ -407,10 +410,16 @@
 
 	// Derive early write keys and set Conn state to allow early writes.
 	if sendEarlyData {
-		finishedHash := newFinishedHash(session.vers, pskCipherSuite)
+		finishedHash := newFinishedHash(session.wireVersion, c.isDTLS, pskCipherSuite)
 		finishedHash.addEntropy(session.masterSecret)
 		finishedHash.Write(helloBytes)
-		earlyTrafficSecret := finishedHash.deriveSecret(earlyTrafficLabel)
+
+		earlyLabel := earlyTrafficLabel
+		if isDraft21(session.wireVersion) {
+			earlyLabel = earlyTrafficLabelDraft21
+		}
+
+		earlyTrafficSecret := finishedHash.deriveSecret(earlyLabel)
 		c.useOutTrafficSecret(session.wireVersion, pskCipherSuite, earlyTrafficSecret)
 		for _, earlyData := range c.config.Bugs.SendEarlyData {
 			if _, err := c.writeRecord(recordTypeApplicationData, earlyData); err != nil {
@@ -518,7 +527,7 @@
 		hello.raw = nil
 
 		if len(hello.pskIdentities) > 0 {
-			generatePSKBinders(hello, pskCipherSuite, session.masterSecret, append(helloBytes, helloRetryRequest.marshal()...), c.config)
+			generatePSKBinders(c.wireVersion, hello, pskCipherSuite, session.masterSecret, helloBytes, helloRetryRequest.marshal(), c.config)
 		}
 		secondHelloBytes = hello.marshal()
 
@@ -588,13 +597,19 @@
 		serverHello:  serverHello,
 		hello:        hello,
 		suite:        suite,
-		finishedHash: newFinishedHash(c.vers, suite),
+		finishedHash: newFinishedHash(c.wireVersion, c.isDTLS, suite),
 		keyShares:    keyShares,
 		session:      session,
 	}
 
 	hs.writeHash(helloBytes, hs.c.sendHandshakeSeq-1)
 	if haveHelloRetryRequest {
+		if isDraft21(c.wireVersion) {
+			err = hs.finishedHash.UpdateForHelloRetryRequest()
+			if err != nil {
+				return err
+			}
+		}
 		hs.writeServerHash(helloRetryRequest.marshal())
 		hs.writeClientHash(secondHelloBytes)
 	}
@@ -739,8 +754,10 @@
 		if err != nil {
 			return err
 		}
+		hs.finishedHash.nextSecret()
 		hs.finishedHash.addEntropy(ecdheSecret)
 	} else {
+		hs.finishedHash.nextSecret()
 		hs.finishedHash.addEntropy(zeroSecret)
 	}
 
@@ -750,10 +767,17 @@
 		}
 	}
 
+	clientLabel := clientHandshakeTrafficLabel
+	serverLabel := serverHandshakeTrafficLabel
+	if isDraft21(c.wireVersion) {
+		clientLabel = clientHandshakeTrafficLabelDraft21
+		serverLabel = serverHandshakeTrafficLabelDraft21
+	}
+
 	// Derive handshake traffic keys and switch read key to handshake
 	// traffic key.
-	clientHandshakeTrafficSecret := hs.finishedHash.deriveSecret(clientHandshakeTrafficLabel)
-	serverHandshakeTrafficSecret := hs.finishedHash.deriveSecret(serverHandshakeTrafficLabel)
+	clientHandshakeTrafficSecret := hs.finishedHash.deriveSecret(clientLabel)
+	serverHandshakeTrafficSecret := hs.finishedHash.deriveSecret(serverLabel)
 	if err := c.useInTrafficSecret(c.wireVersion, hs.suite, serverHandshakeTrafficSecret); err != nil {
 		return err
 	}
@@ -795,6 +819,10 @@
 				return errors.New("tls: non-empty certificate request context sent in handshake")
 			}
 
+			if c.config.Bugs.ExpectNoCertificateAuthoritiesExtension && certReq.hasCAExtension {
+				return errors.New("tls: expected no certificate_authorities extension")
+			}
+
 			if c.config.Bugs.IgnorePeerSignatureAlgorithmPreferences {
 				certReq.signatureAlgorithms = c.config.signSignatureAlgorithms()
 			}
@@ -883,10 +911,21 @@
 
 	// The various secrets do not incorporate the client's final leg, so
 	// derive them now before updating the handshake context.
+	hs.finishedHash.nextSecret()
 	hs.finishedHash.addEntropy(zeroSecret)
-	clientTrafficSecret := hs.finishedHash.deriveSecret(clientApplicationTrafficLabel)
-	serverTrafficSecret := hs.finishedHash.deriveSecret(serverApplicationTrafficLabel)
-	c.exporterSecret = hs.finishedHash.deriveSecret(exporterLabel)
+
+	clientLabel = clientApplicationTrafficLabel
+	serverLabel = serverApplicationTrafficLabel
+	exportLabel := exporterLabel
+	if isDraft21(c.wireVersion) {
+		clientLabel = clientApplicationTrafficLabelDraft21
+		serverLabel = serverApplicationTrafficLabelDraft21
+		exportLabel = exporterLabelDraft21
+	}
+
+	clientTrafficSecret := hs.finishedHash.deriveSecret(clientLabel)
+	serverTrafficSecret := hs.finishedHash.deriveSecret(serverLabel)
+	c.exporterSecret = hs.finishedHash.deriveSecret(exportLabel)
 
 	// Switch to application data keys on read. In particular, any alerts
 	// from the client certificate are read over these keys.
@@ -894,8 +933,8 @@
 		return err
 	}
 
-	// If we're expecting 0.5-RTT messages from the server, read them
-	// now.
+	// If we're expecting 0.5-RTT messages from the server, read them now.
+	var deferredTickets []*newSessionTicketMsg
 	if encryptedExtensions.extensions.hasEarlyData {
 		// BoringSSL will always send two tickets half-RTT when
 		// negotiating 0-RTT.
@@ -908,9 +947,8 @@
 			if !ok {
 				return errors.New("tls: expected half-RTT ticket")
 			}
-			if err := c.processTLS13NewSessionTicket(newSessionTicket, hs.suite); err != nil {
-				return err
-			}
+			// Defer processing until the resumption secret is computed.
+			deferredTickets = append(deferredTickets, newSessionTicket)
 		}
 		for _, expectedMsg := range c.config.Bugs.ExpectHalfRTTData {
 			if err := c.readRecord(recordTypeApplicationData); err != nil {
@@ -926,12 +964,19 @@
 
 	// Send EndOfEarlyData and then switch write key to handshake
 	// traffic key.
-	if c.out.cipher != nil && !c.config.Bugs.SkipEndOfEarlyData {
+	if encryptedExtensions.extensions.hasEarlyData && c.out.cipher != nil && !c.config.Bugs.SkipEndOfEarlyData {
 		if c.config.Bugs.SendStrayEarlyHandshake {
 			helloRequest := new(helloRequestMsg)
 			c.writeRecord(recordTypeHandshake, helloRequest.marshal())
 		}
-		c.sendAlert(alertEndOfEarlyData)
+		if isDraft21(c.wireVersion) {
+			endOfEarlyData := new(endOfEarlyDataMsg)
+			endOfEarlyData.nonEmpty = c.config.Bugs.NonEmptyEndOfEarlyData
+			c.writeRecord(recordTypeHandshake, endOfEarlyData.marshal())
+			hs.writeClientHash(endOfEarlyData.marshal())
+		} else {
+			c.sendAlert(alertEndOfEarlyData)
+		}
 	}
 
 	if isResumptionClientCCSExperiment(c.wireVersion) {
@@ -1026,7 +1071,18 @@
 	// Switch to application data keys.
 	c.useOutTrafficSecret(c.wireVersion, hs.suite, clientTrafficSecret)
 
-	c.resumptionSecret = hs.finishedHash.deriveSecret(resumptionLabel)
+	resumeLabel := resumptionLabel
+	if isDraft21(c.wireVersion) {
+		resumeLabel = resumptionLabelDraft21
+	}
+
+	c.resumptionSecret = hs.finishedHash.deriveSecret(resumeLabel)
+	for _, ticket := range deferredTickets {
+		if err := c.processTLS13NewSessionTicket(ticket, hs.suite); err != nil {
+			return err
+		}
+	}
+
 	return nil
 }
 
@@ -1502,6 +1558,7 @@
 	// session ID or session ticket will be attached.
 	session := &ClientSessionState{
 		vers:               c.vers,
+		wireVersion:        c.wireVersion,
 		cipherSuite:        hs.suite.id,
 		masterSecret:       hs.masterSecret,
 		handshakeHash:      hs.finishedHash.Sum(),
@@ -1735,7 +1792,7 @@
 	copy(b[len(b)-len(xb):], xb)
 }
 
-func generatePSKBinders(hello *clientHelloMsg, pskCipherSuite *cipherSuite, psk, transcript []byte, config *Config) {
+func generatePSKBinders(version uint16, hello *clientHelloMsg, pskCipherSuite *cipherSuite, psk, firstClientHello, helloRetryRequest []byte, config *Config) {
 	if config.Bugs.SendNoPSKBinder {
 		return
 	}
@@ -1761,7 +1818,11 @@
 	helloBytes := hello.marshal()
 	binderSize := len(hello.pskBinders)*(binderLen+1) + 2
 	truncatedHello := helloBytes[:len(helloBytes)-binderSize]
-	binder := computePSKBinder(psk, resumptionPSKBinderLabel, pskCipherSuite, transcript, truncatedHello)
+	binderLabel := resumptionPSKBinderLabel
+	if isDraft21(version) {
+		binderLabel = resumptionPSKBinderLabelDraft21
+	}
+	binder := computePSKBinder(psk, version, binderLabel, pskCipherSuite, firstClientHello, helloRetryRequest, truncatedHello)
 	if config.Bugs.SendShortPSKBinder {
 		binder = binder[:binderLen]
 	}
diff --git a/src/ssl/test/runner/handshake_messages.go b/src/ssl/test/runner/handshake_messages.go
index bf9cb7f..aa6b463 100644
--- a/src/ssl/test/runner/handshake_messages.go
+++ b/src/ssl/test/runner/handshake_messages.go
@@ -1406,6 +1406,7 @@
 type helloRetryRequestMsg struct {
 	raw                 []byte
 	vers                uint16
+	cipherSuite         uint16
 	hasSelectedGroup    bool
 	selectedGroup       CurveID
 	cookie              []byte
@@ -1422,6 +1423,9 @@
 	retryRequestMsg.addU8(typeHelloRetryRequest)
 	retryRequest := retryRequestMsg.addU24LengthPrefixed()
 	retryRequest.addU16(m.vers)
+	if isDraft21(m.vers) {
+		retryRequest.addU16(m.cipherSuite)
+	}
 	extensions := retryRequest.addU16LengthPrefixed()
 
 	count := 1
@@ -1456,8 +1460,13 @@
 		return false
 	}
 	m.vers = uint16(data[4])<<8 | uint16(data[5])
-	extLen := int(data[6])<<8 | int(data[7])
-	data = data[8:]
+	data = data[6:]
+	if isDraft21(m.vers) {
+		m.cipherSuite = uint16(data[0])<<8 | uint16(data[1])
+		data = data[2:]
+	}
+	extLen := int(data[0])<<8 | int(data[1])
+	data = data[2:]
 	if len(data) != extLen || len(data) == 0 {
 		return false
 	}
@@ -1870,7 +1879,8 @@
 }
 
 type certificateRequestMsg struct {
-	raw []byte
+	raw  []byte
+	vers uint16
 	// hasSignatureAlgorithm indicates whether this message includes a list
 	// of signature and hash functions. This change was introduced with TLS
 	// 1.2.
@@ -1884,6 +1894,8 @@
 	requestContext         []byte
 	signatureAlgorithms    []signatureAlgorithm
 	certificateAuthorities [][]byte
+	hasCAExtension         bool
+	customExtension        uint16
 }
 
 func (m *certificateRequestMsg) marshal() []byte {
@@ -1899,33 +1911,119 @@
 	if m.hasRequestContext {
 		requestContext := body.addU8LengthPrefixed()
 		requestContext.addBytes(m.requestContext)
+		extensions := newByteBuilder()
+		if isDraft21(m.vers) {
+			extensions = body.addU16LengthPrefixed()
+			if m.hasSignatureAlgorithm {
+				extensions.addU16(extensionSignatureAlgorithms)
+				signatureAlgorithms := extensions.addU16LengthPrefixed().addU16LengthPrefixed()
+				for _, sigAlg := range m.signatureAlgorithms {
+					signatureAlgorithms.addU16(uint16(sigAlg))
+				}
+			}
+			if len(m.certificateAuthorities) > 0 {
+				extensions.addU16(extensionCertificateAuthorities)
+				certificateAuthorities := extensions.addU16LengthPrefixed().addU16LengthPrefixed()
+				for _, ca := range m.certificateAuthorities {
+					caEntry := certificateAuthorities.addU16LengthPrefixed()
+					caEntry.addBytes(ca)
+				}
+			}
+		} else {
+			if m.hasSignatureAlgorithm {
+				signatureAlgorithms := body.addU16LengthPrefixed()
+				for _, sigAlg := range m.signatureAlgorithms {
+					signatureAlgorithms.addU16(uint16(sigAlg))
+				}
+			}
+
+			certificateAuthorities := body.addU16LengthPrefixed()
+			for _, ca := range m.certificateAuthorities {
+				caEntry := certificateAuthorities.addU16LengthPrefixed()
+				caEntry.addBytes(ca)
+			}
+			extensions = body.addU16LengthPrefixed()
+		}
+
+		if m.customExtension > 0 {
+			extensions.addU16(m.customExtension)
+			extensions.addU16LengthPrefixed()
+		}
 	} else {
 		certificateTypes := body.addU8LengthPrefixed()
 		certificateTypes.addBytes(m.certificateTypes)
-	}
 
-	if m.hasSignatureAlgorithm {
-		signatureAlgorithms := body.addU16LengthPrefixed()
-		for _, sigAlg := range m.signatureAlgorithms {
-			signatureAlgorithms.addU16(uint16(sigAlg))
+		if m.hasSignatureAlgorithm {
+			signatureAlgorithms := body.addU16LengthPrefixed()
+			for _, sigAlg := range m.signatureAlgorithms {
+				signatureAlgorithms.addU16(uint16(sigAlg))
+			}
 		}
-	}
 
-	certificateAuthorities := body.addU16LengthPrefixed()
-	for _, ca := range m.certificateAuthorities {
-		caEntry := certificateAuthorities.addU16LengthPrefixed()
-		caEntry.addBytes(ca)
-	}
-
-	if m.hasRequestContext {
-		// Emit no certificate extensions.
-		body.addU16(0)
+		certificateAuthorities := body.addU16LengthPrefixed()
+		for _, ca := range m.certificateAuthorities {
+			caEntry := certificateAuthorities.addU16LengthPrefixed()
+			caEntry.addBytes(ca)
+		}
 	}
 
 	m.raw = builder.finish()
 	return m.raw
 }
 
+func parseSignatureAlgorithms(data []byte) ([]signatureAlgorithm, []byte, bool) {
+	if len(data) < 2 {
+		return nil, nil, false
+	}
+	sigAlgsLen := int(data[0])<<8 | int(data[1])
+	data = data[2:]
+	if sigAlgsLen&1 != 0 {
+		return nil, nil, false
+	}
+	if len(data) < int(sigAlgsLen) {
+		return nil, nil, false
+	}
+	numSigAlgs := sigAlgsLen / 2
+	signatureAlgorithms := make([]signatureAlgorithm, numSigAlgs)
+	for i := range signatureAlgorithms {
+		signatureAlgorithms[i] = signatureAlgorithm(data[0])<<8 | signatureAlgorithm(data[1])
+		data = data[2:]
+	}
+
+	return signatureAlgorithms, data, true
+}
+
+func parseCAs(data []byte) ([][]byte, []byte, bool) {
+	if len(data) < 2 {
+		return nil, nil, false
+	}
+	casLength := uint16(data[0])<<8 | uint16(data[1])
+	data = data[2:]
+	if len(data) < int(casLength) {
+		return nil, nil, false
+	}
+
+	cas := data[:casLength]
+	data = data[casLength:]
+
+	var certificateAuthorities [][]byte
+	for len(cas) > 0 {
+		if len(cas) < 2 {
+			return nil, nil, false
+		}
+		caLen := uint16(cas[0])<<8 | uint16(cas[1])
+		cas = cas[2:]
+
+		if len(cas) < int(caLen) {
+			return nil, nil, false
+		}
+
+		certificateAuthorities = append(certificateAuthorities, cas[:caLen])
+		cas = cas[caLen:]
+	}
+	return certificateAuthorities, data, true
+}
+
 func (m *certificateRequestMsg) unmarshal(data []byte) bool {
 	m.raw = data
 
@@ -1942,6 +2040,70 @@
 		m.requestContext = make([]byte, contextLen)
 		copy(m.requestContext, data[1:])
 		data = data[1+contextLen:]
+		if isDraft21(m.vers) {
+			if len(data) < 2 {
+				return false
+			}
+			extensionsLen := int(data[0])<<8 | int(data[1])
+			if len(data) < 2+extensionsLen {
+				return false
+			}
+			extensions := data[2 : 2+extensionsLen]
+			data = data[2+extensionsLen:]
+			for len(extensions) != 0 {
+				if len(extensions) < 4 {
+					return false
+				}
+				extension := uint16(extensions[0])<<8 | uint16(extensions[1])
+				length := int(extensions[2])<<8 | int(extensions[3])
+				if len(extensions) < 4+length {
+					return false
+				}
+				contents := extensions[4 : 4+length]
+				extensions = extensions[4+length:]
+				switch extension {
+				case extensionSignatureAlgorithms:
+					sigAlgs, rest, ok := parseSignatureAlgorithms(contents)
+					if !ok || len(rest) != 0 {
+						return false
+					}
+					m.signatureAlgorithms = sigAlgs
+				case extensionCertificateAuthorities:
+					cas, rest, ok := parseCAs(contents)
+					if !ok || len(rest) != 0 {
+						return false
+					}
+					m.hasCAExtension = true
+					m.certificateAuthorities = cas
+				}
+			}
+		} else {
+			if m.hasSignatureAlgorithm {
+				sigAlgs, rest, ok := parseSignatureAlgorithms(data)
+				if !ok {
+					return false
+				}
+				m.signatureAlgorithms = sigAlgs
+				data = rest
+			}
+
+			cas, rest, ok := parseCAs(data)
+			if !ok {
+				return false
+			}
+			m.certificateAuthorities = cas
+			data = rest
+
+			// Ignore certificate extensions.
+			if len(data) < 2 {
+				return false
+			}
+			extsLength := int(data[0])<<8 | int(data[1])
+			if len(data) < 2+extsLength {
+				return false
+			}
+			data = data[2+extsLength:]
+		}
 	} else {
 		numCertTypes := int(data[0])
 		if len(data) < 1+numCertTypes {
@@ -1950,66 +2112,22 @@
 		m.certificateTypes = make([]byte, numCertTypes)
 		copy(m.certificateTypes, data[1:])
 		data = data[1+numCertTypes:]
-	}
 
-	if m.hasSignatureAlgorithm {
-		if len(data) < 2 {
-			return false
-		}
-		sigAlgsLen := uint16(data[0])<<8 | uint16(data[1])
-		data = data[2:]
-		if sigAlgsLen&1 != 0 {
-			return false
-		}
-		if len(data) < int(sigAlgsLen) {
-			return false
-		}
-		numSigAlgs := sigAlgsLen / 2
-		m.signatureAlgorithms = make([]signatureAlgorithm, numSigAlgs)
-		for i := range m.signatureAlgorithms {
-			m.signatureAlgorithms[i] = signatureAlgorithm(data[0])<<8 | signatureAlgorithm(data[1])
-			data = data[2:]
-		}
-	}
-
-	if len(data) < 2 {
-		return false
-	}
-	casLength := uint16(data[0])<<8 | uint16(data[1])
-	data = data[2:]
-	if len(data) < int(casLength) {
-		return false
-	}
-	cas := make([]byte, casLength)
-	copy(cas, data)
-	data = data[casLength:]
-
-	m.certificateAuthorities = nil
-	for len(cas) > 0 {
-		if len(cas) < 2 {
-			return false
-		}
-		caLen := uint16(cas[0])<<8 | uint16(cas[1])
-		cas = cas[2:]
-
-		if len(cas) < int(caLen) {
-			return false
+		if m.hasSignatureAlgorithm {
+			sigAlgs, rest, ok := parseSignatureAlgorithms(data)
+			if !ok {
+				return false
+			}
+			m.signatureAlgorithms = sigAlgs
+			data = rest
 		}
 
-		m.certificateAuthorities = append(m.certificateAuthorities, cas[:caLen])
-		cas = cas[caLen:]
-	}
-
-	if m.hasRequestContext {
-		// Ignore certificate extensions.
-		if len(data) < 2 {
+		cas, rest, ok := parseCAs(data)
+		if !ok {
 			return false
 		}
-		extsLength := int(data[0])<<8 | int(data[1])
-		if len(data) < 2+extsLength {
-			return false
-		}
-		data = data[2+extsLength:]
+		m.certificateAuthorities = cas
+		data = rest
 	}
 
 	if len(data) > 0 {
@@ -2090,15 +2208,17 @@
 }
 
 type newSessionTicketMsg struct {
-	raw                    []byte
-	version                uint16
-	ticketLifetime         uint32
-	ticketAgeAdd           uint32
-	ticket                 []byte
-	maxEarlyDataSize       uint32
-	customExtension        string
-	duplicateEarlyDataInfo bool
-	hasGREASEExtension     bool
+	raw                         []byte
+	vers                        uint16
+	isDTLS                      bool
+	ticketLifetime              uint32
+	ticketAgeAdd                uint32
+	ticketNonce                 []byte
+	ticket                      []byte
+	maxEarlyDataSize            uint32
+	customExtension             string
+	duplicateEarlyDataExtension bool
+	hasGREASEExtension          bool
 }
 
 func (m *newSessionTicketMsg) marshal() []byte {
@@ -2106,25 +2226,37 @@
 		return m.raw
 	}
 
+	version, ok := wireToVersion(m.vers, m.isDTLS)
+	if !ok {
+		panic("unknown version")
+	}
+
 	// See http://tools.ietf.org/html/rfc5077#section-3.3
 	ticketMsg := newByteBuilder()
 	ticketMsg.addU8(typeNewSessionTicket)
 	body := ticketMsg.addU24LengthPrefixed()
 	body.addU32(m.ticketLifetime)
-	if m.version >= VersionTLS13 {
+	if version >= VersionTLS13 {
 		body.addU32(m.ticketAgeAdd)
+		if isDraft21(m.vers) {
+			body.addU8LengthPrefixed().addBytes(m.ticketNonce)
+		}
 	}
 
 	ticket := body.addU16LengthPrefixed()
 	ticket.addBytes(m.ticket)
 
-	if m.version >= VersionTLS13 {
+	if version >= VersionTLS13 {
 		extensions := body.addU16LengthPrefixed()
 		if m.maxEarlyDataSize > 0 {
-			extensions.addU16(extensionTicketEarlyDataInfo)
+			extID := extensionTicketEarlyDataInfo
+			if isDraft21(m.vers) {
+				extID = extensionEarlyData
+			}
+			extensions.addU16(extID)
 			extensions.addU16LengthPrefixed().addU32(m.maxEarlyDataSize)
-			if m.duplicateEarlyDataInfo {
-				extensions.addU16(extensionTicketEarlyDataInfo)
+			if m.duplicateEarlyDataExtension {
+				extensions.addU16(extID)
 				extensions.addU16LengthPrefixed().addU32(m.maxEarlyDataSize)
 			}
 		}
@@ -2141,18 +2273,32 @@
 func (m *newSessionTicketMsg) unmarshal(data []byte) bool {
 	m.raw = data
 
+	version, ok := wireToVersion(m.vers, m.isDTLS)
+	if !ok {
+		panic("unknown version")
+	}
+
 	if len(data) < 8 {
 		return false
 	}
 	m.ticketLifetime = uint32(data[4])<<24 | uint32(data[5])<<16 | uint32(data[6])<<8 | uint32(data[7])
 	data = data[8:]
 
-	if m.version >= VersionTLS13 {
+	if version >= VersionTLS13 {
 		if len(data) < 4 {
 			return false
 		}
 		m.ticketAgeAdd = uint32(data[0])<<24 | uint32(data[1])<<16 | uint32(data[2])<<8 | uint32(data[3])
 		data = data[4:]
+		if isDraft21(m.vers) {
+			nonceLen := int(data[0])
+			data = data[1:]
+			if len(data) < nonceLen {
+				return false
+			}
+			m.ticketNonce = data[:nonceLen]
+			data = data[nonceLen:]
+		}
 	}
 
 	if len(data) < 2 {
@@ -2164,14 +2310,14 @@
 		return false
 	}
 
-	if m.version >= VersionTLS13 && ticketLen == 0 {
+	if version >= VersionTLS13 && ticketLen == 0 {
 		return false
 	}
 
 	m.ticket = data[:ticketLen]
 	data = data[ticketLen:]
 
-	if m.version >= VersionTLS13 {
+	if version >= VersionTLS13 {
 		if len(data) < 2 {
 			return false
 		}
@@ -2182,6 +2328,11 @@
 			return false
 		}
 
+		extID := extensionTicketEarlyDataInfo
+		if isDraft21(m.vers) {
+			extID = extensionEarlyData
+		}
+
 		for len(data) != 0 {
 			if len(data) < 4 {
 				return false
@@ -2194,7 +2345,7 @@
 			}
 
 			switch extension {
-			case extensionTicketEarlyDataInfo:
+			case extID:
 				if length != 4 {
 					return false
 				}
@@ -2381,6 +2532,21 @@
 	return m.keyUpdateRequest == keyUpdateNotRequested || m.keyUpdateRequest == keyUpdateRequested
 }
 
+type endOfEarlyDataMsg struct {
+	nonEmpty bool
+}
+
+func (m *endOfEarlyDataMsg) marshal() []byte {
+	if m.nonEmpty {
+		return []byte{typeEndOfEarlyData, 0, 0, 1, 42}
+	}
+	return []byte{typeEndOfEarlyData, 0, 0, 0}
+}
+
+func (*endOfEarlyDataMsg) unmarshal(data []byte) bool {
+	return len(data) == 4
+}
+
 // ssl3NoCertificateMsg is a dummy message to handle SSL 3.0 using a warning
 // alert in the handshake.
 type ssl3NoCertificateMsg struct{}
diff --git a/src/ssl/test/runner/handshake_server.go b/src/ssl/test/runner/handshake_server.go
index f50772e..dd6f48f 100644
--- a/src/ssl/test/runner/handshake_server.go
+++ b/src/ssl/test/runner/handshake_server.go
@@ -412,7 +412,7 @@
 		hs.hello.cipherSuite = c.config.Bugs.SendCipherSuite
 	}
 
-	hs.finishedHash = newFinishedHash(c.vers, hs.suite)
+	hs.finishedHash = newFinishedHash(c.wireVersion, c.isDTLS, hs.suite)
 	hs.finishedHash.discardHandshakeBuffer()
 	hs.writeClientHash(hs.clientHello.marshal())
 
@@ -496,7 +496,7 @@
 	// AcceptAnyBinder is set. See https://crbug.com/boringssl/115.
 	if hs.sessionState != nil && !config.Bugs.AcceptAnySession {
 		binderToVerify := hs.clientHello.pskBinders[pskIndex]
-		if err := verifyPSKBinder(hs.clientHello, hs.sessionState, binderToVerify, []byte{}); err != nil {
+		if err := verifyPSKBinder(c.wireVersion, hs.clientHello, hs.sessionState, binderToVerify, []byte{}, []byte{}); err != nil {
 			return err
 		}
 	}
@@ -520,8 +520,13 @@
 
 ResendHelloRetryRequest:
 	var sendHelloRetryRequest bool
+	cipherSuite := hs.suite.id
+	if config.Bugs.SendHelloRetryRequestCipherSuite != 0 {
+		cipherSuite = config.Bugs.SendHelloRetryRequestCipherSuite
+	}
 	helloRetryRequest := &helloRetryRequestMsg{
 		vers:                c.wireVersion,
+		cipherSuite:         cipherSuite,
 		duplicateExtensions: config.Bugs.DuplicateHelloRetryRequestExtensions,
 	}
 
@@ -571,6 +576,12 @@
 	}
 
 	if sendHelloRetryRequest {
+		if isDraft21(c.wireVersion) {
+			if err := hs.finishedHash.UpdateForHelloRetryRequest(); err != nil {
+				return err
+			}
+		}
+
 		oldClientHelloBytes := hs.clientHello.marshal()
 		hs.writeServerHash(helloRetryRequest.marshal())
 		c.writeRecord(recordTypeHandshake, helloRetryRequest.marshal())
@@ -592,6 +603,10 @@
 		}
 		hs.writeClientHash(newClientHello.marshal())
 
+		if config.Bugs.ExpectNoTLS13PSKAfterHRR && len(newClientHello.pskIdentities) > 0 {
+			return fmt.Errorf("tls: client offered unexpected PSK identities after HelloRetryRequest")
+		}
+
 		if newClientHello.hasEarlyData {
 			return errors.New("tls: EarlyData sent in new ClientHello")
 		}
@@ -626,11 +641,15 @@
 
 		// PSK binders and obfuscated ticket age are both updated in the
 		// second ClientHello.
-		if len(oldClientHelloCopy.pskIdentities) != len(newClientHelloCopy.pskIdentities) {
-			return errors.New("tls: PSK identity count from old and new ClientHello do not match")
-		}
-		for i, identity := range oldClientHelloCopy.pskIdentities {
-			newClientHelloCopy.pskIdentities[i].obfuscatedTicketAge = identity.obfuscatedTicketAge
+		if isDraft21(c.wireVersion) && len(oldClientHelloCopy.pskIdentities) != len(newClientHelloCopy.pskIdentities) {
+			newClientHelloCopy.pskIdentities = oldClientHelloCopy.pskIdentities
+		} else {
+			if len(oldClientHelloCopy.pskIdentities) != len(newClientHelloCopy.pskIdentities) {
+				return errors.New("tls: PSK identity count from old and new ClientHello do not match")
+			}
+			for i, identity := range oldClientHelloCopy.pskIdentities {
+				newClientHelloCopy.pskIdentities[i].obfuscatedTicketAge = identity.obfuscatedTicketAge
+			}
 		}
 		newClientHelloCopy.pskBinders = oldClientHelloCopy.pskBinders
 		newClientHelloCopy.hasEarlyData = oldClientHelloCopy.hasEarlyData
@@ -648,7 +667,7 @@
 		// AcceptAnyBinder is set. See https://crbug.com/115.
 		if hs.sessionState != nil && !config.Bugs.AcceptAnySession {
 			binderToVerify := newClientHello.pskBinders[pskIndex]
-			if err := verifyPSKBinder(newClientHello, hs.sessionState, binderToVerify, append(oldClientHelloBytes, helloRetryRequest.marshal()...)); err != nil {
+			if err := verifyPSKBinder(c.wireVersion, newClientHello, hs.sessionState, binderToVerify, oldClientHelloBytes, helloRetryRequest.marshal()); err != nil {
 				return err
 			}
 		}
@@ -662,7 +681,12 @@
 			}
 		}
 		if encryptedExtensions.extensions.hasEarlyData {
-			earlyTrafficSecret := hs.finishedHash.deriveSecret(earlyTrafficLabel)
+			earlyLabel := earlyTrafficLabel
+			if isDraft21(c.wireVersion) {
+				earlyLabel = earlyTrafficLabelDraft21
+			}
+
+			earlyTrafficSecret := hs.finishedHash.deriveSecret(earlyLabel)
 			if err := c.useInTrafficSecret(c.wireVersion, hs.suite, earlyTrafficSecret); err != nil {
 				return err
 			}
@@ -716,6 +740,7 @@
 			c.sendAlert(alertHandshakeFailure)
 			return err
 		}
+		hs.finishedHash.nextSecret()
 		hs.finishedHash.addEntropy(ecdheSecret)
 		hs.hello.hasKeyShare = true
 
@@ -740,6 +765,7 @@
 			}
 		}
 	} else {
+		hs.finishedHash.nextSecret()
 		hs.finishedHash.addEntropy(hs.finishedHash.zeroSecret())
 	}
 
@@ -760,11 +786,18 @@
 		c.writeRecord(recordTypeChangeCipherSpec, []byte{1})
 	}
 
+	clientLabel := clientHandshakeTrafficLabel
+	serverLabel := serverHandshakeTrafficLabel
+	if isDraft21(c.wireVersion) {
+		clientLabel = clientHandshakeTrafficLabelDraft21
+		serverLabel = serverHandshakeTrafficLabelDraft21
+	}
+
 	// Switch to handshake traffic keys.
-	serverHandshakeTrafficSecret := hs.finishedHash.deriveSecret(serverHandshakeTrafficLabel)
+	serverHandshakeTrafficSecret := hs.finishedHash.deriveSecret(serverLabel)
 	c.useOutTrafficSecret(c.wireVersion, hs.suite, serverHandshakeTrafficSecret)
 	// Derive handshake traffic read key, but don't switch yet.
-	clientHandshakeTrafficSecret := hs.finishedHash.deriveSecret(clientHandshakeTrafficLabel)
+	clientHandshakeTrafficSecret := hs.finishedHash.deriveSecret(clientLabel)
 
 	// Send EncryptedExtensions.
 	hs.writeServerHash(encryptedExtensions.marshal())
@@ -779,9 +812,11 @@
 		if config.ClientAuth >= RequestClientCert {
 			// Request a client certificate
 			certReq := &certificateRequestMsg{
-				hasSignatureAlgorithm: true,
+				vers: c.wireVersion,
+				hasSignatureAlgorithm: !config.Bugs.OmitCertificateRequestAlgorithms,
 				hasRequestContext:     true,
 				requestContext:        config.Bugs.SendRequestContext,
+				customExtension:       config.Bugs.SendCustomCertificateRequest,
 			}
 			if !config.Bugs.NoSignatureAlgorithms {
 				certReq.signatureAlgorithms = config.verifySignatureAlgorithms()
@@ -896,10 +931,21 @@
 
 	// The various secrets do not incorporate the client's final leg, so
 	// derive them now before updating the handshake context.
+	hs.finishedHash.nextSecret()
 	hs.finishedHash.addEntropy(hs.finishedHash.zeroSecret())
-	clientTrafficSecret := hs.finishedHash.deriveSecret(clientApplicationTrafficLabel)
-	serverTrafficSecret := hs.finishedHash.deriveSecret(serverApplicationTrafficLabel)
-	c.exporterSecret = hs.finishedHash.deriveSecret(exporterLabel)
+
+	clientLabel = clientApplicationTrafficLabel
+	serverLabel = serverApplicationTrafficLabel
+	exportLabel := exporterLabel
+	if isDraft21(c.wireVersion) {
+		clientLabel = clientApplicationTrafficLabelDraft21
+		serverLabel = serverApplicationTrafficLabelDraft21
+		exportLabel = exporterLabelDraft21
+	}
+
+	clientTrafficSecret := hs.finishedHash.deriveSecret(clientLabel)
+	serverTrafficSecret := hs.finishedHash.deriveSecret(serverLabel)
+	c.exporterSecret = hs.finishedHash.deriveSecret(exportLabel)
 
 	// Switch to application data keys on write. In particular, any alerts
 	// from the client certificate are sent over these keys.
@@ -912,13 +958,27 @@
 		}
 	}
 
-	// Read end_of_early_data alert.
+	// Read end_of_early_data.
 	if encryptedExtensions.extensions.hasEarlyData {
-		if err := c.readRecord(recordTypeAlert); err != errEndOfEarlyDataAlert {
-			if err == nil {
-				panic("readRecord(recordTypeAlert) returned nil")
+		if isDraft21(c.wireVersion) {
+			msg, err := c.readHandshake()
+			if err != nil {
+				return err
 			}
-			return err
+
+			endOfEarlyData, ok := msg.(*endOfEarlyDataMsg)
+			if !ok {
+				c.sendAlert(alertUnexpectedMessage)
+				return unexpectedMessageError(endOfEarlyData, msg)
+			}
+			hs.writeClientHash(endOfEarlyData.marshal())
+		} else {
+			if err := c.readRecord(recordTypeAlert); err != errEndOfEarlyDataAlert {
+				if err == nil {
+					panic("readRecord(recordTypeAlert) returned nil")
+				}
+				return err
+			}
 		}
 	}
 
@@ -1040,14 +1100,20 @@
 	}
 
 	c.cipherSuite = hs.suite
-	c.resumptionSecret = hs.finishedHash.deriveSecret(resumptionLabel)
+
+	resumeLabel := resumptionLabel
+	if isDraft21(c.wireVersion) {
+		resumeLabel = resumptionLabelDraft21
+	}
+
+	c.resumptionSecret = hs.finishedHash.deriveSecret(resumeLabel)
 
 	// TODO(davidben): Allow configuring the number of tickets sent for
 	// testing.
 	if !c.config.SessionTicketsDisabled && foundKEMode {
 		ticketCount := 2
 		for i := 0; i < ticketCount; i++ {
-			c.SendNewSessionTicket()
+			c.SendNewSessionTicket([]byte{byte(i)})
 		}
 	}
 	return nil
@@ -1408,7 +1474,7 @@
 		hs.hello.extensions.ocspStapling = true
 	}
 
-	hs.finishedHash = newFinishedHash(c.vers, hs.suite)
+	hs.finishedHash = newFinishedHash(c.wireVersion, c.isDTLS, hs.suite)
 	hs.finishedHash.discardHandshakeBuffer()
 	hs.writeClientHash(hs.clientHello.marshal())
 	hs.writeServerHash(hs.hello.marshal())
@@ -1460,7 +1526,7 @@
 		}
 	}
 
-	hs.finishedHash = newFinishedHash(c.vers, hs.suite)
+	hs.finishedHash = newFinishedHash(c.wireVersion, c.isDTLS, hs.suite)
 	hs.writeClientHash(hs.clientHello.marshal())
 	hs.writeServerHash(hs.hello.marshal())
 
@@ -1514,6 +1580,7 @@
 	if config.ClientAuth >= RequestClientCert {
 		// Request a client certificate
 		certReq := &certificateRequestMsg{
+			vers:             c.wireVersion,
 			certificateTypes: config.ClientCertificateTypes,
 		}
 		if certReq.certificateTypes == nil {
@@ -1787,6 +1854,8 @@
 	}
 
 	m := new(newSessionTicketMsg)
+	m.vers = c.wireVersion
+	m.isDTLS = c.isDTLS
 	if c.config.Bugs.SendTicketLifetime != 0 {
 		m.ticketLifetime = uint32(c.config.Bugs.SendTicketLifetime / time.Second)
 	}
@@ -2000,9 +2069,6 @@
 			if version < VersionTLS12 && candidate.flags&suiteTLS12 != 0 {
 				continue
 			}
-			if c.isDTLS && candidate.flags&suiteNoDTLS != 0 {
-				continue
-			}
 			return candidate
 		}
 	}
@@ -2025,7 +2091,7 @@
 	return val&0x0f0f == 0x0a0a && val&0xff == val>>8
 }
 
-func verifyPSKBinder(clientHello *clientHelloMsg, sessionState *sessionState, binderToVerify, transcript []byte) error {
+func verifyPSKBinder(version uint16, clientHello *clientHelloMsg, sessionState *sessionState, binderToVerify, firstClientHello, helloRetryRequest []byte) error {
 	binderLen := 2
 	for _, binder := range clientHello.pskBinders {
 		binderLen += 1 + len(binder)
@@ -2038,7 +2104,11 @@
 		return errors.New("tls: Unknown cipher suite for PSK in session")
 	}
 
-	binder := computePSKBinder(sessionState.masterSecret, resumptionPSKBinderLabel, pskCipherSuite, transcript, truncatedHello)
+	binderLabel := resumptionPSKBinderLabel
+	if isDraft21(version) {
+		binderLabel = resumptionPSKBinderLabelDraft21
+	}
+	binder := computePSKBinder(sessionState.masterSecret, version, binderLabel, pskCipherSuite, firstClientHello, helloRetryRequest, truncatedHello)
 	if !bytes.Equal(binder, binderToVerify) {
 		return errors.New("tls: PSK binder does not verify")
 	}
diff --git a/src/ssl/test/runner/prf.go b/src/ssl/test/runner/prf.go
index cfc383d..6fa3c4c 100644
--- a/src/ssl/test/runner/prf.go
+++ b/src/ssl/test/runner/prf.go
@@ -180,9 +180,14 @@
 	return
 }
 
-func newFinishedHash(version uint16, cipherSuite *cipherSuite) finishedHash {
+func newFinishedHash(wireVersion uint16, isDTLS bool, cipherSuite *cipherSuite) finishedHash {
 	var ret finishedHash
 
+	version, ok := wireToVersion(wireVersion, isDTLS)
+	if !ok {
+		panic("unknown version")
+	}
+
 	if version >= VersionTLS12 {
 		ret.hash = cipherSuite.hash()
 
@@ -207,6 +212,7 @@
 
 	ret.buffer = []byte{}
 	ret.version = version
+	ret.wireVersion = wireVersion
 	return ret
 }
 
@@ -226,13 +232,28 @@
 	// full buffer is required.
 	buffer []byte
 
-	version uint16
-	prf     func(result, secret, label, seed []byte)
+	version     uint16
+	wireVersion uint16
+	prf         func(result, secret, label, seed []byte)
 
 	// secret, in TLS 1.3, is the running input secret.
 	secret []byte
 }
 
+func (h *finishedHash) UpdateForHelloRetryRequest() (err error) {
+	data := newByteBuilder()
+	data.addU8(typeMessageHash)
+	data.addU24(h.hash.Size())
+	data.addBytes(h.Sum())
+	h.client = h.hash.New()
+	h.server = h.hash.New()
+	if h.buffer != nil {
+		h.buffer = []byte{}
+	}
+	h.Write(data.finish())
+	return nil
+}
+
 func (h *finishedHash) Write(msg []byte) (n int, err error) {
 	h.client.Write(msg)
 	h.server.Write(msg)
@@ -307,7 +328,7 @@
 		return out
 	}
 
-	clientFinishedKey := hkdfExpandLabel(h.hash, baseKey, finishedLabel, nil, h.hash.Size())
+	clientFinishedKey := hkdfExpandLabel(h.hash, h.wireVersion, baseKey, finishedLabel, nil, h.hash.Size())
 	finishedHMAC := hmac.New(h.hash.New, clientFinishedKey)
 	finishedHMAC.Write(h.appendContextHashes(nil))
 	return finishedHMAC.Sum(nil)
@@ -326,7 +347,7 @@
 		return out
 	}
 
-	serverFinishedKey := hkdfExpandLabel(h.hash, baseKey, finishedLabel, nil, h.hash.Size())
+	serverFinishedKey := hkdfExpandLabel(h.hash, h.wireVersion, baseKey, finishedLabel, nil, h.hash.Size())
 	finishedHMAC := hmac.New(h.hash.New, serverFinishedKey)
 	finishedHMAC.Write(h.appendContextHashes(nil))
 	return finishedHMAC.Sum(nil)
@@ -374,20 +395,33 @@
 	h.secret = hkdfExtract(h.hash.New, h.secret, ikm)
 }
 
+func (h *finishedHash) nextSecret() {
+	if isDraft21(h.wireVersion) {
+		derivedLabel := []byte("derived")
+		h.secret = hkdfExpandLabel(h.hash, h.wireVersion, h.secret, derivedLabel, h.hash.New().Sum(nil), h.hash.Size())
+	}
+}
+
 // hkdfExpandLabel implements TLS 1.3's HKDF-Expand-Label function, as defined
 // in section 7.1 of draft-ietf-tls-tls13-16.
-func hkdfExpandLabel(hash crypto.Hash, secret, label, hashValue []byte, length int) []byte {
+func hkdfExpandLabel(hash crypto.Hash, version uint16, secret, label, hashValue []byte, length int) []byte {
 	if len(label) > 255 || len(hashValue) > 255 {
 		panic("hkdfExpandLabel: label or hashValue too long")
 	}
-	hkdfLabel := make([]byte, 3+9+len(label)+1+len(hashValue))
+
+	versionLabel := []byte("TLS 1.3, ")
+	if isDraft21(version) {
+		versionLabel = []byte("tls13 ")
+	}
+
+	hkdfLabel := make([]byte, 3+len(versionLabel)+len(label)+1+len(hashValue))
 	x := hkdfLabel
 	x[0] = byte(length >> 8)
 	x[1] = byte(length)
-	x[2] = byte(9 + len(label))
+	x[2] = byte(len(versionLabel) + len(label))
 	x = x[3:]
-	copy(x, []byte("TLS 1.3, "))
-	x = x[9:]
+	copy(x, versionLabel)
+	x = x[len(versionLabel):]
 	copy(x, label)
 	x = x[len(label):]
 	x[0] = byte(len(hashValue))
@@ -414,12 +448,25 @@
 	applicationTrafficLabel       = []byte("application traffic secret")
 	exporterLabel                 = []byte("exporter master secret")
 	resumptionLabel               = []byte("resumption master secret")
+
+	externalPSKBinderLabelDraft21        = []byte("ext binder")
+	resumptionPSKBinderLabelDraft21      = []byte("res binder")
+	earlyTrafficLabelDraft21             = []byte("c e traffic")
+	clientHandshakeTrafficLabelDraft21   = []byte("c hs traffic")
+	serverHandshakeTrafficLabelDraft21   = []byte("s hs traffic")
+	clientApplicationTrafficLabelDraft21 = []byte("c ap traffic")
+	serverApplicationTrafficLabelDraft21 = []byte("s ap traffic")
+	applicationTrafficLabelDraft21       = []byte("traffic upd")
+	exporterLabelDraft21                 = []byte("exp master")
+	resumptionLabelDraft21               = []byte("res master")
+
+	resumptionPSKLabel = []byte("resumption")
 )
 
 // deriveSecret implements TLS 1.3's Derive-Secret function, as defined in
 // section 7.1 of draft ietf-tls-tls13-16.
 func (h *finishedHash) deriveSecret(label []byte) []byte {
-	return hkdfExpandLabel(h.hash, h.secret, label, h.appendContextHashes(nil), h.hash.Size())
+	return hkdfExpandLabel(h.hash, h.wireVersion, h.secret, label, h.appendContextHashes(nil), h.hash.Size())
 }
 
 // The following are context strings for CertificateVerify in TLS 1.3.
@@ -458,21 +505,34 @@
 // deriveTrafficAEAD derives traffic keys and constructs an AEAD given a traffic
 // secret.
 func deriveTrafficAEAD(version uint16, suite *cipherSuite, secret []byte, side trafficDirection) interface{} {
-	key := hkdfExpandLabel(suite.hash(), secret, keyTLS13, nil, suite.keyLen)
-	iv := hkdfExpandLabel(suite.hash(), secret, ivTLS13, nil, suite.ivLen(version))
+	key := hkdfExpandLabel(suite.hash(), version, secret, keyTLS13, nil, suite.keyLen)
+	iv := hkdfExpandLabel(suite.hash(), version, secret, ivTLS13, nil, suite.ivLen(version))
 
 	return suite.aead(version, key, iv)
 }
 
-func updateTrafficSecret(hash crypto.Hash, secret []byte) []byte {
-	return hkdfExpandLabel(hash, secret, applicationTrafficLabel, nil, hash.Size())
+func updateTrafficSecret(hash crypto.Hash, version uint16, secret []byte) []byte {
+	trafficLabel := applicationTrafficLabel
+	if isDraft21(version) {
+		trafficLabel = applicationTrafficLabelDraft21
+	}
+	return hkdfExpandLabel(hash, version, secret, trafficLabel, nil, hash.Size())
 }
 
-func computePSKBinder(psk, label []byte, cipherSuite *cipherSuite, transcript, truncatedHello []byte) []byte {
-	finishedHash := newFinishedHash(VersionTLS13, cipherSuite)
+func computePSKBinder(psk []byte, version uint16, label []byte, cipherSuite *cipherSuite, clientHello, helloRetryRequest, truncatedHello []byte) []byte {
+	finishedHash := newFinishedHash(version, false, cipherSuite)
 	finishedHash.addEntropy(psk)
 	binderKey := finishedHash.deriveSecret(label)
-	finishedHash.Write(transcript)
+	finishedHash.Write(clientHello)
+	if isDraft21(version) && len(helloRetryRequest) != 0 {
+		finishedHash.UpdateForHelloRetryRequest()
+	}
+	finishedHash.Write(helloRetryRequest)
 	finishedHash.Write(truncatedHello)
 	return finishedHash.clientSum(binderKey)
 }
+
+func deriveSessionPSK(suite *cipherSuite, version uint16, masterSecret []byte, nonce []byte) []byte {
+	hash := suite.hash()
+	return hkdfExpandLabel(hash, version, masterSecret, resumptionPSKLabel, nonce, hash.Size())
+}
diff --git a/src/ssl/test/runner/runner.go b/src/ssl/test/runner/runner.go
index d34eaa6..ce50fa8 100644
--- a/src/ssl/test/runner/runner.go
+++ b/src/ssl/test/runner/runner.go
@@ -1305,6 +1305,13 @@
 		tls13Variant: TLS13Default,
 	},
 	{
+		name:         "TLS13Draft21",
+		version:      VersionTLS13,
+		excludeFlag:  "-no-tls13",
+		versionWire:  tls13Draft21Version,
+		tls13Variant: TLS13Draft21,
+	},
+	{
 		name:         "TLS13Experiment",
 		version:      VersionTLS13,
 		excludeFlag:  "-no-tls13",
@@ -1394,10 +1401,6 @@
 	return strings.HasPrefix(suiteName, "AEAD-")
 }
 
-func isDTLSCipher(suiteName string) bool {
-	return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
-}
-
 func bigFromHex(hex string) *big.Int {
 	ret, ok := new(big.Int).SetString(hex, 16)
 	if !ok {
@@ -2948,10 +2951,6 @@
 		shouldClientFail = true
 		shouldServerFail = true
 	}
-	if !isDTLSCipher(suite.name) && protocol == dtls {
-		shouldClientFail = true
-		shouldServerFail = true
-	}
 
 	var sendCipherSuite uint16
 	var expectedServerError, expectedClientError string
@@ -3138,7 +3137,7 @@
 			},
 		},
 		shouldFail:    true,
-		expectedError: ":UNKNOWN_CIPHER_RETURNED:",
+		expectedError: ":WRONG_CIPHER_RETURNED:",
 	})
 
 	// The server must be tolerant to bogus ciphers.
@@ -3791,6 +3790,25 @@
 			"-use-client-ca-list", "<NULL>",
 		},
 	})
+
+	// Test that an empty client CA list doesn't send a CA extension.
+	testCases = append(testCases, testCase{
+		testType: serverTest,
+		name:     "TLS13Draft21-Empty-Client-CA-List",
+		config: Config{
+			MaxVersion:   VersionTLS13,
+			Certificates: []Certificate{rsaCertificate},
+			Bugs: ProtocolBugs{
+				ExpectNoCertificateAuthoritiesExtension: true,
+			},
+		},
+		tls13Variant: TLS13Draft21,
+		flags: []string{
+			"-require-any-client-certificate",
+			"-use-client-ca-list", "<EMPTY>",
+		},
+	})
+
 }
 
 func addExtendedMasterSecretTests() {
@@ -4161,7 +4179,7 @@
 			resumeSession:    true,
 			flags: []string{
 				"-enable-early-data",
-				"-expect-early-data-info",
+				"-expect-ticket-supports-early-data",
 				"-expect-accept-early-data",
 				"-on-resume-shim-writes-first",
 			},
@@ -4190,7 +4208,7 @@
 				resumeSession: true,
 				flags: []string{
 					"-enable-early-data",
-					"-expect-early-data-info",
+					"-expect-ticket-supports-early-data",
 					"-expect-accept-early-data",
 					"-on-resume-read-with-unfinished-write",
 					"-on-resume-shim-writes-first",
@@ -4219,7 +4237,7 @@
 				resumeSession: true,
 				flags: []string{
 					"-enable-early-data",
-					"-expect-early-data-info",
+					"-expect-ticket-supports-early-data",
 					"-expect-reject-early-data",
 					"-on-resume-read-with-unfinished-write",
 					"-on-resume-shim-writes-first",
@@ -5153,14 +5171,13 @@
 				}
 				// When running and shim have different TLS 1.3 variants enabled,
 				// shim clients are expected to fall back to TLS 1.2, while shim
-				// servers support both variants when enabled when the experiment is
-				// enabled.
+				// servers support multiple variants.
 				expectedServerVersion := expectedVersion
 				expectedClientVersion := expectedVersion
 				if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
 					expectedClientVersion = VersionTLS12
 					expectedServerVersion = VersionTLS12
-					if shimVers.tls13Variant != TLS13Default {
+					if shimVers.tls13Variant != TLS13Default && runnerVers.tls13Variant != TLS13Draft21 {
 						expectedServerVersion = VersionTLS13
 					}
 				}
@@ -9189,7 +9206,7 @@
 		flags: []string{
 			"-enable-client-custom-extension",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 		},
 	})
@@ -9208,7 +9225,7 @@
 		flags: []string{
 			"-enable-client-custom-extension",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-accept-early-data",
 		},
 	})
@@ -9229,7 +9246,7 @@
 		flags: []string{
 			"-enable-client-custom-extension",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 		},
 	})
@@ -9260,7 +9277,7 @@
 		flags: []string{
 			"-enable-client-custom-extension",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 		},
 	})
 
@@ -9282,7 +9299,7 @@
 		flags: []string{
 			"-enable-server-custom-extension",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 		},
 	})
 
@@ -10044,7 +10061,7 @@
 		},
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 		},
 	})
 
@@ -10065,7 +10082,7 @@
 			MaxVersion:       VersionTLS13,
 			MaxEarlyDataSize: 16384,
 			Bugs: ProtocolBugs{
-				DuplicateTicketEarlyDataInfo: true,
+				DuplicateTicketEarlyData: true,
 			},
 		},
 		shouldFail:         true,
@@ -10079,7 +10096,7 @@
 		config: Config{
 			MaxVersion: VersionTLS13,
 			Bugs: ProtocolBugs{
-				ExpectTicketEarlyDataInfo: true,
+				ExpectTicketEarlyData: true,
 			},
 		},
 		flags: []string{
@@ -10964,7 +10981,7 @@
 			resumeSession: true,
 			flags: []string{
 				"-enable-early-data",
-				"-expect-early-data-info",
+				"-expect-ticket-supports-early-data",
 				"-expect-accept-early-data",
 				"-on-resume-shim-writes-first",
 			},
@@ -10988,7 +11005,7 @@
 			resumeSession: true,
 			flags: []string{
 				"-enable-early-data",
-				"-expect-early-data-info",
+				"-expect-ticket-supports-early-data",
 				"-expect-reject-early-data",
 				"-on-resume-shim-writes-first",
 			},
@@ -11229,6 +11246,49 @@
 	})
 
 	testCases = append(testCases, testCase{
+		name: "TLS13Draft21-HelloRetryRequest-CipherChange",
+		config: Config{
+			MaxVersion: VersionTLS13,
+			// P-384 requires HelloRetryRequest in BoringSSL.
+			CurvePreferences: []CurveID{CurveP384},
+			Bugs: ProtocolBugs{
+				SendCipherSuite:                  TLS_AES_128_GCM_SHA256,
+				SendHelloRetryRequestCipherSuite: TLS_CHACHA20_POLY1305_SHA256,
+			},
+		},
+		tls13Variant:  TLS13Draft21,
+		shouldFail:    true,
+		expectedError: ":WRONG_CIPHER_RETURNED:",
+	})
+
+	// Test that the client does not offer a PSK in the second ClientHello if the
+	// HelloRetryRequest is incompatible with it.
+	testCases = append(testCases, testCase{
+		testType: clientTest,
+		name:     "TLS13Draft21-HelloRetryRequest-NonResumableCipher",
+		config: Config{
+			MaxVersion: VersionTLS13,
+			CipherSuites: []uint16{
+				TLS_AES_128_GCM_SHA256,
+			},
+		},
+		resumeConfig: &Config{
+			MaxVersion: VersionTLS13,
+			// P-384 requires HelloRetryRequest in BoringSSL.
+			CurvePreferences: []CurveID{CurveP384},
+			Bugs: ProtocolBugs{
+				ExpectNoTLS13PSKAfterHRR: true,
+			},
+			CipherSuites: []uint16{
+				TLS_AES_256_GCM_SHA384,
+			},
+		},
+		tls13Variant:         TLS13Draft21,
+		resumeSession:        true,
+		expectResumeRejected: true,
+	})
+
+	testCases = append(testCases, testCase{
 		name: "DisabledCurve-HelloRetryRequest",
 		config: Config{
 			MaxVersion:       VersionTLS13,
@@ -11454,6 +11514,42 @@
 	})
 
 	testCases = append(testCases, testCase{
+		name: "TLS13-UnknownInCertificateRequest",
+		config: Config{
+			MaxVersion: VersionTLS13,
+			MinVersion: VersionTLS13,
+			ClientAuth: RequireAnyClientCert,
+			Bugs: ProtocolBugs{
+				SendCustomCertificateRequest: 0x1212,
+			},
+		},
+		tls13Variant: TLS13Draft21,
+		flags: []string{
+			"-cert-file", path.Join(*resourceDir, rsaCertificateFile),
+			"-key-file", path.Join(*resourceDir, rsaKeyFile),
+		},
+	})
+
+	testCases = append(testCases, testCase{
+		name: "TLS13-MissingSignatureAlgorithmsInCertificateRequest",
+		config: Config{
+			MaxVersion: VersionTLS13,
+			MinVersion: VersionTLS13,
+			ClientAuth: RequireAnyClientCert,
+			Bugs: ProtocolBugs{
+				OmitCertificateRequestAlgorithms: true,
+			},
+		},
+		tls13Variant: TLS13Draft21,
+		flags: []string{
+			"-cert-file", path.Join(*resourceDir, rsaCertificateFile),
+			"-key-file", path.Join(*resourceDir, rsaKeyFile),
+		},
+		shouldFail:    true,
+		expectedError: ":DECODE_ERROR:",
+	})
+
+	testCases = append(testCases, testCase{
 		testType: serverTest,
 		name:     "TLS13-TrailingKeyShareData",
 		config: Config{
@@ -11532,7 +11628,7 @@
 		expectResumeRejected: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 			"-on-resume-shim-writes-first",
 			"-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
@@ -11560,7 +11656,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 		},
 	})
@@ -11584,7 +11680,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 		},
 		shouldFail:    true,
 		expectedError: ":UNEXPECTED_EXTENSION:",
@@ -11605,7 +11701,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 		},
 		shouldFail:    true,
 		expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
@@ -11631,7 +11727,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 		},
 		shouldFail:    true,
@@ -11664,7 +11760,7 @@
 		flags: []string{
 			"-advertise-alpn", "\x03foo\x03bar",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 			"-on-initial-expect-alpn", "foo",
 			"-on-resume-expect-alpn", "foo",
@@ -11690,7 +11786,7 @@
 		flags: []string{
 			"-advertise-alpn", "\x03foo\x03bar",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 			"-on-initial-expect-alpn", "",
 			"-on-resume-expect-alpn", "",
@@ -11717,7 +11813,7 @@
 		flags: []string{
 			"-advertise-alpn", "\x03foo\x03bar",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-reject-early-data",
 			"-on-initial-expect-alpn", "foo",
 			"-on-resume-expect-alpn", "foo",
@@ -11749,7 +11845,7 @@
 		flags: []string{
 			"-advertise-alpn", "\x03foo\x03bar",
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-on-initial-expect-alpn", "foo",
 			"-on-resume-expect-alpn", "foo",
 			"-on-retry-expect-alpn", "bar",
@@ -11771,7 +11867,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-no-offer-early-data",
 			"-on-initial-advertise-alpn", "\x03foo",
 			"-on-resume-advertise-alpn", "\x03bar",
@@ -11892,7 +11988,7 @@
 		expectedError:   ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
 		},
 	})
@@ -11914,7 +12010,7 @@
 		expectChannelID: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
 			"-expect-reject-early-data",
 		},
@@ -11932,7 +12028,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
 			"-expect-accept-early-data",
 		},
@@ -12038,7 +12134,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-accept-early-data",
 			"-expect-version", strconv.Itoa(VersionTLS13),
 		},
@@ -12063,7 +12159,7 @@
 		resumeSession: true,
 		flags: []string{
 			"-enable-early-data",
-			"-expect-early-data-info",
+			"-expect-ticket-supports-early-data",
 			"-expect-accept-early-data",
 		},
 		shouldFail:         true,
@@ -12096,6 +12192,34 @@
 		expectedError:      ":DIGEST_CHECK_FAILED:",
 		expectedLocalError: "remote error: error decrypting message",
 	})
+
+	testCases = append(testCases, testCase{
+		testType: serverTest,
+		name:     "TLS13Draft21-Server-NonEmptyEndOfEarlyData",
+		config: Config{
+			MaxVersion:       VersionTLS13,
+			MaxEarlyDataSize: 16384,
+		},
+		resumeConfig: &Config{
+			MaxVersion:       VersionTLS13,
+			MaxEarlyDataSize: 16384,
+			Bugs: ProtocolBugs{
+				SendEarlyData:           [][]byte{{1, 2, 3, 4}},
+				ExpectEarlyDataAccepted: true,
+				NonEmptyEndOfEarlyData:  true,
+			},
+		},
+		resumeSession: true,
+		flags: []string{
+			"-enable-early-data",
+			"-expect-ticket-supports-early-data",
+			"-expect-accept-early-data",
+		},
+		tls13Variant:  TLS13Draft21,
+		shouldFail:    true,
+		expectedError: ":DECODE_ERROR:",
+	})
+
 	testCases = append(testCases, testCase{
 		testType: serverTest,
 		name:     "TLS13-ServerSkipCertificateVerify",
diff --git a/src/ssl/test/test_config.cc b/src/ssl/test/test_config.cc
index 3354851..2d9f725 100644
--- a/src/ssl/test/test_config.cc
+++ b/src/ssl/test/test_config.cc
@@ -81,7 +81,8 @@
   { "-tls-unique", &TestConfig::tls_unique },
   { "-expect-ticket-renewal", &TestConfig::expect_ticket_renewal },
   { "-expect-no-session", &TestConfig::expect_no_session },
-  { "-expect-early-data-info", &TestConfig::expect_early_data_info },
+  { "-expect-ticket-supports-early-data",
+    &TestConfig::expect_ticket_supports_early_data },
   { "-use-ticket-callback", &TestConfig::use_ticket_callback },
   { "-renew-ticket", &TestConfig::renew_ticket },
   { "-enable-early-data", &TestConfig::enable_early_data },
diff --git a/src/ssl/test/test_config.h b/src/ssl/test/test_config.h
index b96d9e5..b742f94 100644
--- a/src/ssl/test/test_config.h
+++ b/src/ssl/test/test_config.h
@@ -87,7 +87,7 @@
   bool tls_unique = false;
   bool expect_ticket_renewal = false;
   bool expect_no_session = false;
-  bool expect_early_data_info = false;
+  bool expect_ticket_supports_early_data = false;
   bool expect_accept_early_data = false;
   bool expect_reject_early_data = false;
   bool expect_no_offer_early_data = false;
diff --git a/src/ssl/tls13_client.cc b/src/ssl/tls13_client.cc
index b6307ee..9c09309 100644
--- a/src/ssl/tls13_client.cc
+++ b/src/ssl/tls13_client.cc
@@ -63,8 +63,10 @@
   }
 
   CBS body = msg.body, extensions;
-  uint16_t server_version;
+  uint16_t server_version, cipher_suite = 0;
   if (!CBS_get_u16(&body, &server_version) ||
+      (ssl_is_draft21(ssl->version) &&
+       !CBS_get_u16(&body, &cipher_suite)) ||
       !CBS_get_u16_length_prefixed(&body, &extensions) ||
       // HelloRetryRequest may not be empty.
       CBS_len(&extensions) == 0 ||
@@ -74,6 +76,26 @@
     return ssl_hs_error;
   }
 
+  if (ssl_is_draft21(ssl->version)) {
+    const SSL_CIPHER *cipher = SSL_get_cipher_by_value(cipher_suite);
+    // Check if the cipher is a TLS 1.3 cipher.
+    if (cipher == NULL ||
+        SSL_CIPHER_get_min_version(cipher) > ssl_protocol_version(ssl) ||
+        SSL_CIPHER_get_max_version(cipher) < ssl_protocol_version(ssl)) {
+      OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
+      ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
+      return ssl_hs_error;
+    }
+
+    hs->new_cipher = cipher;
+
+    if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher) ||
+        !hs->transcript.UpdateForHelloRetryRequest()) {
+      return ssl_hs_error;
+    }
+  }
+
+
   bool have_cookie, have_key_share;
   CBS cookie, key_share;
   const SSL_EXTENSION_TYPE ext_types[] = {
@@ -206,16 +228,20 @@
   OPENSSL_memcpy(ssl->s3->server_random, CBS_data(&server_random),
                  SSL3_RANDOM_SIZE);
 
+  // Check if the cipher is a TLS 1.3 cipher.
   const SSL_CIPHER *cipher = SSL_get_cipher_by_value(cipher_suite);
-  if (cipher == NULL) {
-    OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CIPHER_RETURNED);
+  if (cipher == nullptr ||
+      SSL_CIPHER_get_min_version(cipher) > ssl_protocol_version(ssl) ||
+      SSL_CIPHER_get_max_version(cipher) < ssl_protocol_version(ssl)) {
+    OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
     ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
     return ssl_hs_error;
   }
 
-  // Check if the cipher is a TLS 1.3 cipher.
-  if (SSL_CIPHER_get_min_version(cipher) > ssl_protocol_version(ssl) ||
-      SSL_CIPHER_get_max_version(cipher) < ssl_protocol_version(ssl)) {
+  // Check that the cipher matches the one in the HelloRetryRequest.
+  if (ssl_is_draft21(ssl->version) &&
+      hs->received_hello_retry_request &&
+      hs->new_cipher != cipher) {
     OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
     ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
     return ssl_hs_error;
@@ -302,18 +328,16 @@
   hs->new_session->cipher = cipher;
   hs->new_cipher = cipher;
 
-  // The PRF hash is now known. Set up the key schedule.
-  if (!tls13_init_key_schedule(hs)) {
-    return ssl_hs_error;
-  }
+  size_t hash_len =
+      EVP_MD_size(ssl_get_handshake_digest(ssl_protocol_version(ssl), cipher));
 
-  // Incorporate the PSK into the running secret.
+  // Set up the key schedule and incorporate the PSK into the running secret.
   if (ssl->s3->session_reused) {
-    if (!tls13_advance_key_schedule(hs, hs->new_session->master_key,
-                                    hs->new_session->master_key_length)) {
+    if (!tls13_init_key_schedule(hs, hs->new_session->master_key,
+                                 hs->new_session->master_key_length)) {
       return ssl_hs_error;
     }
-  } else if (!tls13_advance_key_schedule(hs, kZeroes, hs->hash_len)) {
+  } else if (!tls13_init_key_schedule(hs, kZeroes, hash_len)) {
     return ssl_hs_error;
   }
 
@@ -445,37 +469,81 @@
     return ssl_hs_ok;
   }
 
-  CBS body = msg.body, context, supported_signature_algorithms;
-  if (!CBS_get_u8_length_prefixed(&body, &context) ||
-      // The request context is always empty during the handshake.
-      CBS_len(&context) != 0 ||
-      !CBS_get_u16_length_prefixed(&body, &supported_signature_algorithms) ||
-      CBS_len(&supported_signature_algorithms) == 0 ||
-      !tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) {
-    ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
-    OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
-    return ssl_hs_error;
-  }
 
-  uint8_t alert = SSL_AD_DECODE_ERROR;
-  UniquePtr<STACK_OF(CRYPTO_BUFFER)> ca_names =
-      ssl_parse_client_CA_list(ssl, &alert, &body);
-  if (!ca_names) {
-    ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
-    return ssl_hs_error;
-  }
+  if (ssl_is_draft21(ssl->version)) {
+    bool have_sigalgs = false, have_ca = false;
+    CBS sigalgs, ca;
+    const SSL_EXTENSION_TYPE ext_types[] = {
+      {TLSEXT_TYPE_signature_algorithms, &have_sigalgs, &sigalgs},
+      {TLSEXT_TYPE_certificate_authorities, &have_ca, &ca},
+    };
 
-  // Ignore extensions.
-  CBS extensions;
-  if (!CBS_get_u16_length_prefixed(&body, &extensions) ||
-      CBS_len(&body) != 0) {
-    ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
-    OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
-    return ssl_hs_error;
+    CBS body = msg.body, context, extensions, supported_signature_algorithms;
+    uint8_t alert = SSL_AD_DECODE_ERROR;
+    if (!CBS_get_u8_length_prefixed(&body, &context) ||
+        // The request context is always empty during the handshake.
+        CBS_len(&context) != 0 ||
+        !CBS_get_u16_length_prefixed(&body, &extensions) ||
+        CBS_len(&body) != 0 ||
+        !ssl_parse_extensions(&extensions, &alert, ext_types,
+                              OPENSSL_ARRAY_SIZE(ext_types),
+                              1 /* accept unknown */) ||
+        (have_ca && CBS_len(&ca) == 0) ||
+        !have_sigalgs ||
+        !CBS_get_u16_length_prefixed(&sigalgs,
+                                     &supported_signature_algorithms) ||
+        CBS_len(&supported_signature_algorithms) == 0 ||
+        !tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) {
+      ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
+      OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
+      return ssl_hs_error;
+    }
+
+    if (have_ca) {
+      hs->ca_names = ssl_parse_client_CA_list(ssl, &alert, &ca);
+      if (!hs->ca_names) {
+        ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
+        return ssl_hs_error;
+      }
+    } else {
+      hs->ca_names.reset(sk_CRYPTO_BUFFER_new_null());
+      if (!hs->ca_names) {
+        OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
+        ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
+        return ssl_hs_error;
+      }
+    }
+  } else {
+    CBS body = msg.body, context, supported_signature_algorithms;
+    if (!CBS_get_u8_length_prefixed(&body, &context) ||
+        // The request context is always empty during the handshake.
+        CBS_len(&context) != 0 ||
+        !CBS_get_u16_length_prefixed(&body, &supported_signature_algorithms) ||
+        CBS_len(&supported_signature_algorithms) == 0 ||
+        !tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) {
+      ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
+      OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
+      return ssl_hs_error;
+    }
+
+    uint8_t alert = SSL_AD_DECODE_ERROR;
+    hs->ca_names = ssl_parse_client_CA_list(ssl, &alert, &body);
+    if (!hs->ca_names) {
+      ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
+      return ssl_hs_error;
+    }
+
+    // Ignore extensions.
+    CBS extensions;
+    if (!CBS_get_u16_length_prefixed(&body, &extensions) ||
+        CBS_len(&body) != 0) {
+      ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
+      OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
+      return ssl_hs_error;
+    }
   }
 
   hs->cert_request = true;
-  hs->ca_names = std::move(ca_names);
   ssl->ctx->x509_method->hs_flush_cached_ca_names(hs);
 
   if (!ssl_hash_message(hs, msg)) {
@@ -557,9 +625,19 @@
 
   if (ssl->early_data_accepted) {
     hs->can_early_write = false;
-    if (!ssl->method->add_alert(ssl, SSL3_AL_WARNING,
-                                TLS1_AD_END_OF_EARLY_DATA)) {
-      return ssl_hs_error;
+    if (ssl_is_draft21(ssl->version)) {
+      ScopedCBB cbb;
+      CBB body;
+      if (!ssl->method->init_message(ssl, cbb.get(), &body,
+                                     SSL3_MT_END_OF_EARLY_DATA) ||
+          !ssl_add_message_cbb(ssl, cbb.get())) {
+        return ssl_hs_error;
+      }
+    } else {
+      if (!ssl->method->add_alert(ssl, SSL3_AL_WARNING,
+                                  TLS1_AD_END_OF_EARLY_DATA)) {
+        return ssl_hs_error;
+      }
     }
   }
 
@@ -790,9 +868,11 @@
   ssl_session_rebase_time(ssl, session.get());
 
   uint32_t server_timeout;
-  CBS body = msg.body, ticket, extensions;
+  CBS body = msg.body, ticket_nonce, ticket, extensions;
   if (!CBS_get_u32(&body, &server_timeout) ||
       !CBS_get_u32(&body, &session->ticket_age_add) ||
+      (ssl_is_draft21(ssl->version) &&
+       !CBS_get_u8_length_prefixed(&body, &ticket_nonce)) ||
       !CBS_get_u16_length_prefixed(&body, &ticket) ||
       !CBS_stow(&ticket, &session->tlsext_tick, &session->tlsext_ticklen) ||
       !CBS_get_u16_length_prefixed(&body, &extensions) ||
@@ -808,12 +888,18 @@
     session->timeout = server_timeout;
   }
 
+  if (!tls13_derive_session_psk(session.get(), ticket_nonce)) {
+    return 0;
+  }
+
   // Parse out the extensions.
   bool have_early_data_info = false;
   CBS early_data_info;
+  uint16_t ext_id = ssl_is_draft21(ssl->version)
+                        ? TLSEXT_TYPE_early_data
+                        : TLSEXT_TYPE_ticket_early_data_info;
   const SSL_EXTENSION_TYPE ext_types[] = {
-      {TLSEXT_TYPE_ticket_early_data_info, &have_early_data_info,
-       &early_data_info},
+      {ext_id, &have_early_data_info, &early_data_info},
   };
 
   uint8_t alert = SSL_AD_DECODE_ERROR;
diff --git a/src/ssl/tls13_enc.cc b/src/ssl/tls13_enc.cc
index 6c7e1da..14f4a78 100644
--- a/src/ssl/tls13_enc.cc
+++ b/src/ssl/tls13_enc.cc
@@ -46,32 +46,33 @@
   return 1;
 }
 
-int tls13_init_key_schedule(SSL_HANDSHAKE *hs) {
+int tls13_init_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
+                            size_t psk_len) {
   if (!init_key_schedule(hs, ssl_protocol_version(hs->ssl), hs->new_cipher)) {
     return 0;
   }
 
   hs->transcript.FreeBuffer();
-  return 1;
+  return HKDF_extract(hs->secret, &hs->hash_len, hs->transcript.Digest(), psk,
+                      psk_len, hs->secret, hs->hash_len);
 }
 
-int tls13_init_early_key_schedule(SSL_HANDSHAKE *hs) {
+int tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
+                                  size_t psk_len) {
   SSL *const ssl = hs->ssl;
   return init_key_schedule(hs, ssl_session_protocol_version(ssl->session),
-                           ssl->session->cipher);
+                           ssl->session->cipher) &&
+         HKDF_extract(hs->secret, &hs->hash_len, hs->transcript.Digest(), psk,
+                      psk_len, hs->secret, hs->hash_len);
 }
 
-int tls13_advance_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *in,
-                               size_t len) {
-  return HKDF_extract(hs->secret, &hs->hash_len, hs->transcript.Digest(), in,
-                      len, hs->secret, hs->hash_len);
-}
-
-static int hkdf_expand_label(uint8_t *out, const EVP_MD *digest,
-                             const uint8_t *secret, size_t secret_len,
-                             const uint8_t *label, size_t label_len,
-                             const uint8_t *hash, size_t hash_len, size_t len) {
-  static const char kTLS13LabelVersion[] = "TLS 1.3, ";
+static int hkdf_expand_label(uint8_t *out, uint16_t version,
+                             const EVP_MD *digest, const uint8_t *secret,
+                             size_t secret_len, const uint8_t *label,
+                             size_t label_len, const uint8_t *hash,
+                             size_t hash_len, size_t len) {
+  const char *kTLS13LabelVersion =
+      ssl_is_draft21(version) ? "tls13 " : "TLS 1.3, ";
 
   ScopedCBB cbb;
   CBB child;
@@ -96,6 +97,34 @@
   return ret;
 }
 
+static const char kTLS13LabelDerived[] = "derived";
+
+int tls13_advance_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *in,
+                               size_t len) {
+  SSL *const ssl = hs->ssl;
+
+  // Draft 18 does not include the extra Derive-Secret step.
+  if (ssl_is_draft21(ssl->version)) {
+    uint8_t derive_context[EVP_MAX_MD_SIZE];
+    unsigned derive_context_len;
+    if (!EVP_Digest(nullptr, 0, derive_context, &derive_context_len,
+                    hs->transcript.Digest(), nullptr)) {
+      return 0;
+    }
+
+    if (!hkdf_expand_label(hs->secret, ssl->version, hs->transcript.Digest(),
+                           hs->secret, hs->hash_len,
+                           (const uint8_t *)kTLS13LabelDerived,
+                           strlen(kTLS13LabelDerived), derive_context,
+                           derive_context_len, hs->hash_len)) {
+      return 0;
+    }
+  }
+
+  return HKDF_extract(hs->secret, &hs->hash_len, hs->transcript.Digest(), in,
+                      len, hs->secret, hs->hash_len);
+}
+
 // derive_secret derives a secret of length |len| and writes the result in |out|
 // with the given label and the current base secret and most recently-saved
 // handshake context. It returns one on success and zero on error.
@@ -107,9 +136,10 @@
     return 0;
   }
 
-  return hkdf_expand_label(out, hs->transcript.Digest(), hs->secret,
-                           hs->hash_len, label, label_len, context_hash,
-                           context_hash_len, len);
+  return hkdf_expand_label(out, SSL_get_session(hs->ssl)->ssl_version,
+                           hs->transcript.Digest(), hs->secret, hs->hash_len,
+                           label, label_len, context_hash, context_hash_len,
+                           len);
 }
 
 int tls13_set_traffic_key(SSL *ssl, enum evp_aead_direction_t direction,
@@ -136,16 +166,18 @@
   // Derive the key.
   size_t key_len = EVP_AEAD_key_length(aead);
   uint8_t key[EVP_AEAD_MAX_KEY_LENGTH];
-  if (!hkdf_expand_label(key, digest, traffic_secret, traffic_secret_len,
-                         (const uint8_t *)"key", 3, NULL, 0, key_len)) {
+  if (!hkdf_expand_label(key, session->ssl_version, digest, traffic_secret,
+                         traffic_secret_len, (const uint8_t *)"key", 3, NULL, 0,
+                         key_len)) {
     return 0;
   }
 
   // Derive the IV.
   size_t iv_len = EVP_AEAD_nonce_length(aead);
   uint8_t iv[EVP_AEAD_MAX_NONCE_LENGTH];
-  if (!hkdf_expand_label(iv, digest, traffic_secret, traffic_secret_len,
-                         (const uint8_t *)"iv", 2, NULL, 0, iv_len)) {
+  if (!hkdf_expand_label(iv, session->ssl_version, digest, traffic_secret,
+                         traffic_secret_len, (const uint8_t *)"iv", 2, NULL, 0,
+                         iv_len)) {
     return 0;
   }
 
@@ -195,28 +227,49 @@
 static const char kTLS13LabelServerApplicationTraffic[] =
     "server application traffic secret";
 
+static const char kTLS13Draft21LabelExporter[] = "exp master";
+static const char kTLS13Draft21LabelEarlyExporter[] = "e exp master";
+
+static const char kTLS13Draft21LabelClientEarlyTraffic[] = "c e traffic";
+static const char kTLS13Draft21LabelClientHandshakeTraffic[] = "c hs traffic";
+static const char kTLS13Draft21LabelServerHandshakeTraffic[] = "s hs traffic";
+static const char kTLS13Draft21LabelClientApplicationTraffic[] = "c ap traffic";
+static const char kTLS13Draft21LabelServerApplicationTraffic[] = "s ap traffic";
+
 int tls13_derive_early_secrets(SSL_HANDSHAKE *hs) {
   SSL *const ssl = hs->ssl;
+  uint16_t version = SSL_get_session(ssl)->ssl_version;
+
+  const char *early_traffic_label = ssl_is_draft21(version)
+                                        ? kTLS13Draft21LabelClientEarlyTraffic
+                                        : kTLS13LabelClientEarlyTraffic;
+  const char *early_exporter_label = ssl_is_draft21(version)
+                                         ? kTLS13Draft21LabelEarlyExporter
+                                         : kTLS13LabelEarlyExporter;
   return derive_secret(hs, hs->early_traffic_secret, hs->hash_len,
-                       (const uint8_t *)kTLS13LabelClientEarlyTraffic,
-                       strlen(kTLS13LabelClientEarlyTraffic)) &&
+                       (const uint8_t *)early_traffic_label,
+                       strlen(early_traffic_label)) &&
          ssl_log_secret(ssl, "CLIENT_EARLY_TRAFFIC_SECRET",
                         hs->early_traffic_secret, hs->hash_len) &&
          derive_secret(hs, ssl->s3->early_exporter_secret, hs->hash_len,
-                       (const uint8_t *)kTLS13LabelEarlyExporter,
-                       strlen(kTLS13LabelEarlyExporter));
+                       (const uint8_t *)early_exporter_label,
+                       strlen(early_exporter_label));
 }
 
 int tls13_derive_handshake_secrets(SSL_HANDSHAKE *hs) {
   SSL *const ssl = hs->ssl;
+  const char *client_label = ssl_is_draft21(ssl->version)
+                                 ? kTLS13Draft21LabelClientHandshakeTraffic
+                                 : kTLS13LabelClientHandshakeTraffic;
+  const char *server_label = ssl_is_draft21(ssl->version)
+                                 ? kTLS13Draft21LabelServerHandshakeTraffic
+                                 : kTLS13LabelServerHandshakeTraffic;
   return derive_secret(hs, hs->client_handshake_secret, hs->hash_len,
-                       (const uint8_t *)kTLS13LabelClientHandshakeTraffic,
-                       strlen(kTLS13LabelClientHandshakeTraffic)) &&
+                       (const uint8_t *)client_label, strlen(client_label)) &&
          ssl_log_secret(ssl, "CLIENT_HANDSHAKE_TRAFFIC_SECRET",
                         hs->client_handshake_secret, hs->hash_len) &&
          derive_secret(hs, hs->server_handshake_secret, hs->hash_len,
-                       (const uint8_t *)kTLS13LabelServerHandshakeTraffic,
-                       strlen(kTLS13LabelServerHandshakeTraffic)) &&
+                       (const uint8_t *)server_label, strlen(server_label)) &&
          ssl_log_secret(ssl, "SERVER_HANDSHAKE_TRAFFIC_SECRET",
                         hs->server_handshake_secret, hs->hash_len);
 }
@@ -224,25 +277,33 @@
 int tls13_derive_application_secrets(SSL_HANDSHAKE *hs) {
   SSL *const ssl = hs->ssl;
   ssl->s3->exporter_secret_len = hs->hash_len;
+  const char *client_label = ssl_is_draft21(ssl->version)
+                                 ? kTLS13Draft21LabelClientApplicationTraffic
+                                 : kTLS13LabelClientApplicationTraffic;
+  const char *server_label = ssl_is_draft21(ssl->version)
+                                 ? kTLS13Draft21LabelServerApplicationTraffic
+                                 : kTLS13LabelServerApplicationTraffic;
+  const char *exporter_label = ssl_is_draft21(ssl->version)
+                                   ? kTLS13Draft21LabelExporter
+                                   : kTLS13LabelExporter;
   return derive_secret(hs, hs->client_traffic_secret_0, hs->hash_len,
-                       (const uint8_t *)kTLS13LabelClientApplicationTraffic,
-                       strlen(kTLS13LabelClientApplicationTraffic)) &&
+                       (const uint8_t *)client_label, strlen(client_label)) &&
          ssl_log_secret(ssl, "CLIENT_TRAFFIC_SECRET_0",
                         hs->client_traffic_secret_0, hs->hash_len) &&
          derive_secret(hs, hs->server_traffic_secret_0, hs->hash_len,
-                       (const uint8_t *)kTLS13LabelServerApplicationTraffic,
-                       strlen(kTLS13LabelServerApplicationTraffic)) &&
+                       (const uint8_t *)server_label, strlen(server_label)) &&
          ssl_log_secret(ssl, "SERVER_TRAFFIC_SECRET_0",
                         hs->server_traffic_secret_0, hs->hash_len) &&
          derive_secret(hs, ssl->s3->exporter_secret, hs->hash_len,
-                       (const uint8_t *)kTLS13LabelExporter,
-                       strlen(kTLS13LabelExporter)) &&
+                       (const uint8_t *)exporter_label,
+                       strlen(exporter_label)) &&
          ssl_log_secret(ssl, "EXPORTER_SECRET", ssl->s3->exporter_secret,
                         hs->hash_len);
 }
 
 static const char kTLS13LabelApplicationTraffic[] =
     "application traffic secret";
+static const char kTLS13Draft21LabelApplicationTraffic[] = "traffic upd";
 
 int tls13_rotate_traffic_key(SSL *ssl, enum evp_aead_direction_t direction) {
   uint8_t *secret;
@@ -255,11 +316,14 @@
     secret_len = ssl->s3->write_traffic_secret_len;
   }
 
+  const char *traffic_label = ssl_is_draft21(ssl->version)
+                                  ? kTLS13Draft21LabelApplicationTraffic
+                                  : kTLS13LabelApplicationTraffic;
+
   const EVP_MD *digest = ssl_session_get_digest(SSL_get_session(ssl));
-  if (!hkdf_expand_label(secret, digest, secret, secret_len,
-                         (const uint8_t *)kTLS13LabelApplicationTraffic,
-                         strlen(kTLS13LabelApplicationTraffic), NULL, 0,
-                         secret_len)) {
+  if (!hkdf_expand_label(secret, ssl->version, digest, secret, secret_len,
+                         (const uint8_t *)traffic_label, strlen(traffic_label),
+                         NULL, 0, secret_len)) {
     return 0;
   }
 
@@ -267,30 +331,33 @@
 }
 
 static const char kTLS13LabelResumption[] = "resumption master secret";
+static const char kTLS13Draft21LabelResumption[] = "res master";
 
 int tls13_derive_resumption_secret(SSL_HANDSHAKE *hs) {
   if (hs->hash_len > SSL_MAX_MASTER_KEY_LENGTH) {
     OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
     return 0;
   }
-
+  const char *resumption_label = ssl_is_draft21(hs->ssl->version)
+                                     ? kTLS13Draft21LabelResumption
+                                     : kTLS13LabelResumption;
   hs->new_session->master_key_length = hs->hash_len;
   return derive_secret(
       hs, hs->new_session->master_key, hs->new_session->master_key_length,
-      (const uint8_t *)kTLS13LabelResumption, strlen(kTLS13LabelResumption));
+      (const uint8_t *)resumption_label, strlen(resumption_label));
 }
 
 static const char kTLS13LabelFinished[] = "finished";
 
 // tls13_verify_data sets |out| to be the HMAC of |context| using a derived
 // Finished key for both Finished messages and the PSK binder.
-static int tls13_verify_data(const EVP_MD *digest, uint8_t *out,
-                             size_t *out_len, const uint8_t *secret,
-                             size_t hash_len, uint8_t *context,
-                             size_t context_len) {
+static int tls13_verify_data(const EVP_MD *digest, uint16_t version,
+                             uint8_t *out, size_t *out_len,
+                             const uint8_t *secret, size_t hash_len,
+                             uint8_t *context, size_t context_len) {
   uint8_t key[EVP_MAX_MD_SIZE];
   unsigned len;
-  if (!hkdf_expand_label(key, digest, secret, hash_len,
+  if (!hkdf_expand_label(key, version, digest, secret, hash_len,
                          (const uint8_t *)kTLS13LabelFinished,
                          strlen(kTLS13LabelFinished), NULL, 0, hash_len) ||
       HMAC(digest, key, hash_len, context, context_len, out, &len) == NULL) {
@@ -312,35 +379,79 @@
   uint8_t context_hash[EVP_MAX_MD_SIZE];
   size_t context_hash_len;
   if (!hs->transcript.GetHash(context_hash, &context_hash_len) ||
-      !tls13_verify_data(hs->transcript.Digest(), out, out_len, traffic_secret,
-                         hs->hash_len, context_hash, context_hash_len)) {
+      !tls13_verify_data(hs->transcript.Digest(), hs->ssl->version, out,
+                         out_len, traffic_secret, hs->hash_len, context_hash,
+                         context_hash_len)) {
     return 0;
   }
   return 1;
 }
 
+static const char kTLS13LabelResumptionPSK[] = "resumption";
+
+bool tls13_derive_session_psk(SSL_SESSION *session, Span<const uint8_t> nonce) {
+  if (!ssl_is_draft21(session->ssl_version)) {
+    return true;
+  }
+
+  const EVP_MD *digest = ssl_session_get_digest(session);
+  return hkdf_expand_label(session->master_key, session->ssl_version, digest,
+                           session->master_key, session->master_key_length,
+                           (const uint8_t *)kTLS13LabelResumptionPSK,
+                           strlen(kTLS13LabelResumptionPSK), nonce.data(),
+                           nonce.size(), session->master_key_length);
+}
+
+static const char kTLS13LabelExportKeying[] = "exporter";
+
 int tls13_export_keying_material(SSL *ssl, uint8_t *out, size_t out_len,
                                  const char *label, size_t label_len,
-                                 const uint8_t *context, size_t context_len,
-                                 int use_context) {
-  const uint8_t *hash = NULL;
-  size_t hash_len = 0;
+                                 const uint8_t *context_in,
+                                 size_t context_in_len, int use_context) {
+  const uint8_t *context = NULL;
+  size_t context_len = 0;
   if (use_context) {
-    hash = context;
-    hash_len = context_len;
+    context = context_in;
+    context_len = context_in_len;
+  }
+
+  if (!ssl_is_draft21(ssl->version)) {
+    const EVP_MD *digest = ssl_session_get_digest(SSL_get_session(ssl));
+    return hkdf_expand_label(
+        out, ssl->version, digest, ssl->s3->exporter_secret,
+        ssl->s3->exporter_secret_len, (const uint8_t *)label, label_len,
+        context, context_len, out_len);
   }
 
   const EVP_MD *digest = ssl_session_get_digest(SSL_get_session(ssl));
-  return hkdf_expand_label(out, digest, ssl->s3->exporter_secret,
-                           ssl->s3->exporter_secret_len, (const uint8_t *)label,
-                           label_len, hash, hash_len, out_len);
+
+  uint8_t hash[EVP_MAX_MD_SIZE];
+  uint8_t export_context[EVP_MAX_MD_SIZE];
+  uint8_t derived_secret[EVP_MAX_MD_SIZE];
+  unsigned hash_len;
+  unsigned export_context_len;
+  unsigned derived_secret_len = EVP_MD_size(digest);
+  if (!EVP_Digest(context, context_len, hash, &hash_len, digest, NULL) ||
+      !EVP_Digest(NULL, 0, export_context, &export_context_len, digest, NULL)) {
+    return 0;
+  }
+  return hkdf_expand_label(
+             derived_secret, ssl->version, digest, ssl->s3->exporter_secret,
+             ssl->s3->exporter_secret_len, (const uint8_t *)label, label_len,
+             export_context, export_context_len, derived_secret_len) &&
+         hkdf_expand_label(
+             out, ssl->version, digest, derived_secret, derived_secret_len,
+             (const uint8_t *)kTLS13LabelExportKeying,
+             strlen(kTLS13LabelExportKeying), hash, hash_len, out_len);
 }
 
 static const char kTLS13LabelPSKBinder[] = "resumption psk binder key";
+static const char kTLS13Draft21LabelPSKBinder[] = "res binder";
 
-static int tls13_psk_binder(uint8_t *out, const EVP_MD *digest, uint8_t *psk,
-                            size_t psk_len, uint8_t *context,
-                            size_t context_len, size_t hash_len) {
+static int tls13_psk_binder(uint8_t *out, uint16_t version,
+                            const EVP_MD *digest, uint8_t *psk, size_t psk_len,
+                            uint8_t *context, size_t context_len,
+                            size_t hash_len) {
   uint8_t binder_context[EVP_MAX_MD_SIZE];
   unsigned binder_context_len;
   if (!EVP_Digest(NULL, 0, binder_context, &binder_context_len, digest, NULL)) {
@@ -353,15 +464,17 @@
                     NULL, 0)) {
     return 0;
   }
+  const char *binder_label = ssl_is_draft21(version)
+                                 ? kTLS13Draft21LabelPSKBinder
+                                 : kTLS13LabelPSKBinder;
 
   uint8_t binder_key[EVP_MAX_MD_SIZE] = {0};
   size_t len;
-  if (!hkdf_expand_label(binder_key, digest, early_secret, hash_len,
-                         (const uint8_t *)kTLS13LabelPSKBinder,
-                         strlen(kTLS13LabelPSKBinder), binder_context,
-                         binder_context_len, hash_len) ||
-      !tls13_verify_data(digest, out, &len, binder_key, hash_len, context,
-                         context_len)) {
+  if (!hkdf_expand_label(binder_key, version, digest, early_secret, hash_len,
+                         (const uint8_t *)binder_label, strlen(binder_label),
+                         binder_context, binder_context_len, hash_len) ||
+      !tls13_verify_data(digest, version, out, &len, binder_key, hash_len,
+                         context, context_len)) {
     return 0;
   }
 
@@ -381,6 +494,7 @@
   ScopedEVP_MD_CTX ctx;
   uint8_t context[EVP_MAX_MD_SIZE];
   unsigned context_len;
+
   if (!EVP_DigestInit_ex(ctx.get(), digest, NULL) ||
       !EVP_DigestUpdate(ctx.get(), hs->transcript.buffer().data(),
                         hs->transcript.buffer().size()) ||
@@ -390,7 +504,8 @@
   }
 
   uint8_t verify_data[EVP_MAX_MD_SIZE] = {0};
-  if (!tls13_psk_binder(verify_data, digest, ssl->session->master_key,
+  if (!tls13_psk_binder(verify_data, ssl->session->ssl_version, digest,
+                        ssl->session->master_key,
                         ssl->session->master_key_length, context, context_len,
                         hash_len)) {
     return 0;
@@ -422,7 +537,7 @@
 
   uint8_t verify_data[EVP_MAX_MD_SIZE] = {0};
   CBS binder;
-  if (!tls13_psk_binder(verify_data, hs->transcript.Digest(),
+  if (!tls13_psk_binder(verify_data, hs->ssl->version, hs->transcript.Digest(),
                         session->master_key, session->master_key_length,
                         context, context_len, hash_len) ||
       // We only consider the first PSK, so compare against the first binder.
diff --git a/src/ssl/tls13_server.cc b/src/ssl/tls13_server.cc
index 89c9d46..9afd0d4 100644
--- a/src/ssl/tls13_server.cc
+++ b/src/ssl/tls13_server.cc
@@ -160,33 +160,46 @@
   ssl_session_rebase_time(ssl, hs->new_session.get());
 
   for (int i = 0; i < kNumTickets; i++) {
-    if (!RAND_bytes((uint8_t *)&hs->new_session->ticket_age_add, 4)) {
+    UniquePtr<SSL_SESSION> session(
+        SSL_SESSION_dup(hs->new_session.get(), SSL_SESSION_INCLUDE_NONAUTH));
+    if (!session) {
       return 0;
     }
-    hs->new_session->ticket_age_add_valid = 1;
 
+    if (!RAND_bytes((uint8_t *)&session->ticket_age_add, 4)) {
+      return 0;
+    }
+    session->ticket_age_add_valid = 1;
     if (ssl->cert->enable_early_data) {
-      hs->new_session->ticket_max_early_data = kMaxEarlyDataAccepted;
+      session->ticket_max_early_data = kMaxEarlyDataAccepted;
     }
 
+    static_assert(kNumTickets < 256, "Too many tickets");
+    uint8_t nonce[] = {static_cast<uint8_t>(i)};
+
     ScopedCBB cbb;
-    CBB body, ticket, extensions;
+    CBB body, nonce_cbb, ticket, extensions;
     if (!ssl->method->init_message(ssl, cbb.get(), &body,
                                    SSL3_MT_NEW_SESSION_TICKET) ||
-        !CBB_add_u32(&body, hs->new_session->timeout) ||
-        !CBB_add_u32(&body, hs->new_session->ticket_age_add) ||
+        !CBB_add_u32(&body, session->timeout) ||
+        !CBB_add_u32(&body, session->ticket_age_add) ||
+        (ssl_is_draft21(ssl->version) &&
+         (!CBB_add_u8_length_prefixed(&body, &nonce_cbb) ||
+          !CBB_add_bytes(&nonce_cbb, nonce, sizeof(nonce)))) ||
         !CBB_add_u16_length_prefixed(&body, &ticket) ||
-        !ssl_encrypt_ticket(ssl, &ticket, hs->new_session.get()) ||
+        !tls13_derive_session_psk(session.get(), nonce) ||
+        !ssl_encrypt_ticket(ssl, &ticket, session.get()) ||
         !CBB_add_u16_length_prefixed(&body, &extensions)) {
       return 0;
     }
 
     if (ssl->cert->enable_early_data) {
       CBB early_data_info;
-      if (!CBB_add_u16(&extensions, TLSEXT_TYPE_ticket_early_data_info) ||
+      if (!CBB_add_u16(&extensions, ssl_is_draft21(ssl->version)
+                                        ? TLSEXT_TYPE_early_data
+                                        : TLSEXT_TYPE_ticket_early_data_info) ||
           !CBB_add_u16_length_prefixed(&extensions, &early_data_info) ||
-          !CBB_add_u32(&early_data_info,
-                       hs->new_session->ticket_max_early_data) ||
+          !CBB_add_u32(&early_data_info, session->ticket_max_early_data) ||
           !CBB_flush(&extensions)) {
         return 0;
       }
@@ -244,8 +257,11 @@
 
   // The PRF hash is now known. Set up the key schedule and hash the
   // ClientHello.
-  if (!tls13_init_key_schedule(hs) ||
-      !ssl_hash_message(hs, msg)) {
+  if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher)) {
+    return ssl_hs_error;
+  }
+
+  if (!ssl_hash_message(hs, msg)) {
     return ssl_hs_error;
   }
 
@@ -429,13 +445,16 @@
     return ssl_hs_error;
   }
 
-  // Incorporate the PSK into the running secret.
+  size_t hash_len = EVP_MD_size(
+      ssl_get_handshake_digest(ssl_protocol_version(ssl), hs->new_cipher));
+
+  // Set up the key schedule and incorporate the PSK into the running secret.
   if (ssl->s3->session_reused) {
-    if (!tls13_advance_key_schedule(hs, hs->new_session->master_key,
+    if (!tls13_init_key_schedule(hs, hs->new_session->master_key,
                                     hs->new_session->master_key_length)) {
       return ssl_hs_error;
     }
-  } else if (!tls13_advance_key_schedule(hs, kZeroes, hs->hash_len)) {
+  } else if (!tls13_init_key_schedule(hs, kZeroes, hash_len)) {
     return ssl_hs_error;
   }
 
@@ -454,6 +473,10 @@
       ssl->early_data_accepted = false;
       ssl->s3->skip_early_data = true;
       ssl->method->next_message(ssl);
+      if (ssl_is_draft21(ssl->version) &&
+          !hs->transcript.UpdateForHelloRetryRequest()) {
+        return ssl_hs_error;
+      }
       hs->tls13_state = state_send_hello_retry_request;
       return ssl_hs_ok;
     }
@@ -473,6 +496,8 @@
   if (!ssl->method->init_message(ssl, cbb.get(), &body,
                                  SSL3_MT_HELLO_RETRY_REQUEST) ||
       !CBB_add_u16(&body, ssl->version) ||
+      (ssl_is_draft21(ssl->version) &&
+       !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher))) ||
       !tls1_get_shared_group(hs, &group_id) ||
       !CBB_add_u16_length_prefixed(&body, &extensions) ||
       !CBB_add_u16(&extensions, TLSEXT_TYPE_key_share) ||
@@ -582,16 +607,48 @@
 
   // Send a CertificateRequest, if necessary.
   if (hs->cert_request) {
-    CBB sigalgs_cbb;
-    if (!ssl->method->init_message(ssl, cbb.get(), &body,
-                                   SSL3_MT_CERTIFICATE_REQUEST) ||
-        !CBB_add_u8(&body, 0 /* no certificate_request_context. */) ||
-        !CBB_add_u16_length_prefixed(&body, &sigalgs_cbb) ||
-        !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb) ||
-        !ssl_add_client_CA_list(ssl, &body) ||
-        !CBB_add_u16(&body, 0 /* empty certificate_extensions. */) ||
-        !ssl_add_message_cbb(ssl, cbb.get())) {
-      return ssl_hs_error;
+    if (ssl_is_draft21(ssl->version)) {
+      CBB cert_request_extensions, sigalg_contents, sigalgs_cbb;
+      if (!ssl->method->init_message(ssl, cbb.get(), &body,
+                                     SSL3_MT_CERTIFICATE_REQUEST) ||
+          !CBB_add_u8(&body, 0 /* no certificate_request_context. */) ||
+          !CBB_add_u16_length_prefixed(&body, &cert_request_extensions) ||
+          !CBB_add_u16(&cert_request_extensions,
+                       TLSEXT_TYPE_signature_algorithms) ||
+          !CBB_add_u16_length_prefixed(&cert_request_extensions,
+                                       &sigalg_contents) ||
+          !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) ||
+          !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb)) {
+        return ssl_hs_error;
+      }
+
+      if (ssl_has_client_CAs(ssl)) {
+        CBB ca_contents;
+        if (!CBB_add_u16(&cert_request_extensions,
+                         TLSEXT_TYPE_certificate_authorities) ||
+            !CBB_add_u16_length_prefixed(&cert_request_extensions,
+                                         &ca_contents) ||
+            !ssl_add_client_CA_list(ssl, &ca_contents) ||
+            !CBB_flush(&cert_request_extensions)) {
+          return ssl_hs_error;
+        }
+      }
+
+      if (!ssl_add_message_cbb(ssl, cbb.get())) {
+        return ssl_hs_error;
+      }
+    } else {
+      CBB sigalgs_cbb;
+      if (!ssl->method->init_message(ssl, cbb.get(), &body,
+                                     SSL3_MT_CERTIFICATE_REQUEST) ||
+          !CBB_add_u8(&body, 0 /* no certificate_request_context. */) ||
+          !CBB_add_u16_length_prefixed(&body, &sigalgs_cbb) ||
+          !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb) ||
+          !ssl_add_client_CA_list(ssl, &body) ||
+          !CBB_add_u16(&body, 0 /* empty certificate_extensions. */) ||
+          !ssl_add_message_cbb(ssl, cbb.get())) {
+        return ssl_hs_error;
+      }
     }
   }
 
@@ -648,6 +705,15 @@
     // the wire sooner and also avoids triggering a write on |SSL_read| when
     // processing the client Finished. This requires computing the client
     // Finished early. See draft-ietf-tls-tls13-18, section 4.5.1.
+    if (ssl_is_draft21(ssl->version)) {
+      static const uint8_t kEndOfEarlyData[4] = {SSL3_MT_END_OF_EARLY_DATA, 0,
+                                                 0, 0};
+      if (!hs->transcript.Update(kEndOfEarlyData)) {
+        OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
+        return ssl_hs_error;
+      }
+    }
+
     size_t finished_len;
     if (!tls13_finished_mac(hs, hs->expected_client_finished, &finished_len,
                             0 /* client */)) {
@@ -698,11 +764,30 @@
 }
 
 static enum ssl_hs_wait_t do_process_end_of_early_data(SSL_HANDSHAKE *hs) {
+  SSL *const ssl = hs->ssl;
   hs->tls13_state = state_process_change_cipher_spec;
-  // If early data was accepted, the ChangeCipherSpec message will be in the
-  // discarded early data.
-  if (hs->early_data_offered && !hs->ssl->early_data_accepted) {
-    return ssl_hs_ok;
+  if (hs->early_data_offered) {
+    // If early data was not accepted, the EndOfEarlyData and ChangeCipherSpec
+    // message will be in the discarded early data.
+    if (!hs->ssl->early_data_accepted) {
+      return ssl_hs_ok;
+    }
+    if (ssl_is_draft21(ssl->version)) {
+      SSLMessage msg;
+      if (!ssl->method->get_message(ssl, &msg)) {
+        return ssl_hs_read_message;
+      }
+
+      if (!ssl_check_message_type(ssl, msg, SSL3_MT_END_OF_EARLY_DATA)) {
+        return ssl_hs_error;
+      }
+      if (CBS_len(&msg.body) != 0) {
+        ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
+        OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
+        return ssl_hs_error;
+      }
+      ssl->method->next_message(ssl);
+    }
   }
   return ssl_is_resumption_client_ccs_experiment(hs->ssl->version)
              ? ssl_hs_read_change_cipher_spec
diff --git a/src/ssl/tls_method.cc b/src/ssl/tls_method.cc
index c5b0178..4eacf64 100644
--- a/src/ssl/tls_method.cc
+++ b/src/ssl/tls_method.cc
@@ -67,8 +67,6 @@
 
 namespace bssl {
 
-static bool ssl3_supports_cipher(const SSL_CIPHER *cipher) { return true; }
-
 static void ssl3_on_handshake_complete(SSL *ssl) {
   // The handshake should have released its final message.
   assert(!ssl->s3->has_message);
@@ -113,7 +111,6 @@
     ssl3_open_app_data,
     ssl3_write_app_data,
     ssl3_dispatch_alert,
-    ssl3_supports_cipher,
     ssl3_init_message,
     ssl3_finish_message,
     ssl3_add_message,
diff --git a/src/ssl/tls_record.cc b/src/ssl/tls_record.cc
index bc641fa..a062012 100644
--- a/src/ssl/tls_record.cc
+++ b/src/ssl/tls_record.cc
@@ -320,7 +320,8 @@
 
   if (type == SSL3_RT_ALERT) {
     // Return end_of_early_data alerts as-is for the caller to process.
-    if (out->size() == 2 &&
+    if (!ssl_is_draft21(ssl->version) &&
+        out->size() == 2 &&
         (*out)[0] == SSL3_AL_WARNING &&
         (*out)[1] == TLS1_AD_END_OF_EARLY_DATA) {
       *out_type = type;
diff --git a/src/third_party/fiat/CMakeLists.txt b/src/third_party/fiat/CMakeLists.txt
new file mode 100644
index 0000000..fcc77d5
--- /dev/null
+++ b/src/third_party/fiat/CMakeLists.txt
@@ -0,0 +1,9 @@
+include_directories(../../include)
+
+add_library(
+  fiat
+
+  OBJECT
+
+  curve25519.c
+)
diff --git a/src/third_party/fiat/LICENSE b/src/third_party/fiat/LICENSE
new file mode 100644
index 0000000..bd46c61
--- /dev/null
+++ b/src/third_party/fiat/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015-2016 the fiat-crypto authors (see
+https://github.com/mit-plv/fiat-crypto/blob/master/AUTHORS).
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/src/third_party/fiat/METADATA b/src/third_party/fiat/METADATA
new file mode 100644
index 0000000..bae0285
--- /dev/null
+++ b/src/third_party/fiat/METADATA
@@ -0,0 +1,14 @@
+name: "fiat"
+description:
+    "Fiat-Crypto: Synthesizing Correct-by-Construction Code for Cryptographic Primitives".
+
+third_party {
+  url {
+    type: HOMEPAGE
+    value: "https://github.com/mit-plv/fiat-crypto"
+  }
+  version: "6c4d4afb26de639718fcac39094353ca7feec365"
+  last_upgrade_date { year: 2017 month: 11 day: 3 }
+
+  local_modifications: "Fiat-generated code has been integrated into existing BoringSSL code"
+}
diff --git a/src/third_party/fiat/README.md b/src/third_party/fiat/README.md
new file mode 100644
index 0000000..5512715
--- /dev/null
+++ b/src/third_party/fiat/README.md
@@ -0,0 +1,5 @@
+# Fiat
+
+Some of the code in this directory is generated by
+[Fiat](https://github.com/mit-plv/fiat-crypto) and thus these files are
+licensed under the MIT license. (See LICENSE file.)
diff --git a/src/third_party/fiat/curve25519.c b/src/third_party/fiat/curve25519.c
new file mode 100644
index 0000000..d54aa83
--- /dev/null
+++ b/src/third_party/fiat/curve25519.c
@@ -0,0 +1,5062 @@
+// The MIT License (MIT)
+//
+// Copyright (c) 2015-2016 the fiat-crypto authors (see the AUTHORS file).
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+// Some of this code is taken from the ref10 version of Ed25519 in SUPERCOP
+// 20141124 (http://bench.cr.yp.to/supercop.html). That code is released as
+// public domain but parts have been replaced with code generated by Fiat
+// (https://github.com/mit-plv/fiat-crypto), which is MIT licensed.
+//
+// The field functions are shared by Ed25519 and X25519 where possible.
+
+#include <openssl/curve25519.h>
+
+#include <assert.h>
+#include <string.h>
+
+#include <openssl/cpu.h>
+#include <openssl/mem.h>
+#include <openssl/rand.h>
+#include <openssl/sha.h>
+
+#include "internal.h"
+#include "../../crypto/internal.h"
+
+
+static const int64_t kBottom25Bits = INT64_C(0x1ffffff);
+static const int64_t kBottom26Bits = INT64_C(0x3ffffff);
+
+static uint64_t load_3(const uint8_t *in) {
+  uint64_t result;
+  result = (uint64_t)in[0];
+  result |= ((uint64_t)in[1]) << 8;
+  result |= ((uint64_t)in[2]) << 16;
+  return result;
+}
+
+static uint64_t load_4(const uint8_t *in) {
+  uint64_t result;
+  result = (uint64_t)in[0];
+  result |= ((uint64_t)in[1]) << 8;
+  result |= ((uint64_t)in[2]) << 16;
+  result |= ((uint64_t)in[3]) << 24;
+  return result;
+}
+
+#define assert_fe(f) do { \
+  for (unsigned _assert_fe_i = 0; _assert_fe_i< 10; _assert_fe_i++) { \
+    assert(f[_assert_fe_i] < 1.125*(1<<(26-(_assert_fe_i&1)))); \
+  } \
+} while (0)
+
+#define assert_fe_loose(f) do { \
+  for (unsigned _assert_fe_i = 0; _assert_fe_i< 10; _assert_fe_i++) { \
+    assert(f[_assert_fe_i] < 3.375*(1<<(26-(_assert_fe_i&1)))); \
+  } \
+} while (0)
+
+static void fe_frombytes_impl(uint32_t h[10], const uint8_t *s) {
+  // Ignores top bit of s.
+  uint32_t a0 = load_4(s);
+  uint32_t a1 = load_4(s+4);
+  uint32_t a2 = load_4(s+8);
+  uint32_t a3 = load_4(s+12);
+  uint32_t a4 = load_4(s+16);
+  uint32_t a5 = load_4(s+20);
+  uint32_t a6 = load_4(s+24);
+  uint32_t a7 = load_4(s+28);
+  h[0] = a0&((1<<26)-1);                    // 26 used, 32-26 left.   26
+  h[1] = (a0>>26) | ((a1&((1<<19)-1))<< 6); // (32-26) + 19 =  6+19 = 25
+  h[2] = (a1>>19) | ((a2&((1<<13)-1))<<13); // (32-19) + 13 = 13+13 = 26
+  h[3] = (a2>>13) | ((a3&((1<< 6)-1))<<19); // (32-13) +  6 = 19+ 6 = 25
+  h[4] = (a3>> 6);                          // (32- 6)              = 26
+  h[5] = a4&((1<<25)-1);                    //                        25
+  h[6] = (a4>>25) | ((a5&((1<<19)-1))<< 7); // (32-25) + 19 =  7+19 = 26
+  h[7] = (a5>>19) | ((a6&((1<<12)-1))<<13); // (32-19) + 12 = 13+12 = 25
+  h[8] = (a6>>12) | ((a7&((1<< 6)-1))<<20); // (32-12) +  6 = 20+ 6 = 26
+  h[9] = (a7>> 6)&((1<<25)-1); //                                     25
+  assert_fe(h);
+}
+
+static void fe_frombytes(fe *h, const uint8_t *s) {
+  fe_frombytes_impl(h->v, s);
+}
+
+// Preconditions:
+//  |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
+//
+// Write p=2^255-19; q=floor(h/p).
+// Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
+//
+// Proof:
+//   Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
+//   Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.
+//
+//   Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
+//   Then 0<y<1.
+//
+//   Write r=h-pq.
+//   Have 0<=r<=p-1=2^255-20.
+//   Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
+//
+//   Write x=r+19(2^-255)r+y.
+//   Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
+//
+//   Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
+//   so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
+static void fe_tobytes_impl(uint8_t *s, const uint32_t h[10]) {
+  assert_fe_loose(h);
+  int32_t h0 = h[0];
+  int32_t h1 = h[1];
+  int32_t h2 = h[2];
+  int32_t h3 = h[3];
+  int32_t h4 = h[4];
+  int32_t h5 = h[5];
+  int32_t h6 = h[6];
+  int32_t h7 = h[7];
+  int32_t h8 = h[8];
+  int32_t h9 = h[9];
+  int32_t q;
+
+  q = (19 * h9 + (((int32_t) 1) << 24)) >> 25;
+  q = (h0 + q) >> 26;
+  q = (h1 + q) >> 25;
+  q = (h2 + q) >> 26;
+  q = (h3 + q) >> 25;
+  q = (h4 + q) >> 26;
+  q = (h5 + q) >> 25;
+  q = (h6 + q) >> 26;
+  q = (h7 + q) >> 25;
+  q = (h8 + q) >> 26;
+  q = (h9 + q) >> 25;
+
+  // Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20.
+  h0 += 19 * q;
+  // Goal: Output h-2^255 q, which is between 0 and 2^255-20.
+
+  h1 += h0 >> 26; h0 &= kBottom26Bits;
+  h2 += h1 >> 25; h1 &= kBottom25Bits;
+  h3 += h2 >> 26; h2 &= kBottom26Bits;
+  h4 += h3 >> 25; h3 &= kBottom25Bits;
+  h5 += h4 >> 26; h4 &= kBottom26Bits;
+  h6 += h5 >> 25; h5 &= kBottom25Bits;
+  h7 += h6 >> 26; h6 &= kBottom26Bits;
+  h8 += h7 >> 25; h7 &= kBottom25Bits;
+  h9 += h8 >> 26; h8 &= kBottom26Bits;
+                  h9 &= kBottom25Bits;
+                  // h10 = carry9
+
+  // Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.
+  // Have h0+...+2^230 h9 between 0 and 2^255-1;
+  // evidently 2^255 h10-2^255 q = 0.
+  // Goal: Output h0+...+2^230 h9.
+
+  s[0] = h0 >> 0;
+  s[1] = h0 >> 8;
+  s[2] = h0 >> 16;
+  s[3] = (h0 >> 24) | ((uint32_t)(h1) << 2);
+  s[4] = h1 >> 6;
+  s[5] = h1 >> 14;
+  s[6] = (h1 >> 22) | ((uint32_t)(h2) << 3);
+  s[7] = h2 >> 5;
+  s[8] = h2 >> 13;
+  s[9] = (h2 >> 21) | ((uint32_t)(h3) << 5);
+  s[10] = h3 >> 3;
+  s[11] = h3 >> 11;
+  s[12] = (h3 >> 19) | ((uint32_t)(h4) << 6);
+  s[13] = h4 >> 2;
+  s[14] = h4 >> 10;
+  s[15] = h4 >> 18;
+  s[16] = h5 >> 0;
+  s[17] = h5 >> 8;
+  s[18] = h5 >> 16;
+  s[19] = (h5 >> 24) | ((uint32_t)(h6) << 1);
+  s[20] = h6 >> 7;
+  s[21] = h6 >> 15;
+  s[22] = (h6 >> 23) | ((uint32_t)(h7) << 3);
+  s[23] = h7 >> 5;
+  s[24] = h7 >> 13;
+  s[25] = (h7 >> 21) | ((uint32_t)(h8) << 4);
+  s[26] = h8 >> 4;
+  s[27] = h8 >> 12;
+  s[28] = (h8 >> 20) | ((uint32_t)(h9) << 6);
+  s[29] = h9 >> 2;
+  s[30] = h9 >> 10;
+  s[31] = h9 >> 18;
+}
+
+static void fe_tobytes(uint8_t *s, const fe *h) {
+  fe_tobytes_impl(s, h->v);
+}
+
+static void fe_loose_tobytes(uint8_t *s, const fe_loose *h) {
+  fe_tobytes_impl(s, h->v);
+}
+
+// h = f
+static void fe_copy(fe *h, const fe *f) {
+  OPENSSL_memmove(h, f, sizeof(uint32_t) * 10);
+}
+
+static void fe_copy_lt(fe_loose *h, const fe *f) {
+  OPENSSL_memmove(h, f, sizeof(uint32_t) * 10);
+}
+#if !defined(OPENSSL_SMALL)
+static void fe_copy_ll(fe_loose *h, const fe_loose *f) {
+  OPENSSL_memmove(h, f, sizeof(uint32_t) * 10);
+}
+#endif // !defined(OPENSSL_SMALL)
+
+// h = 0
+static void fe_0(fe *h) {
+  OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
+}
+
+static void fe_loose_0(fe_loose *h) {
+  OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
+}
+
+// h = 1
+static void fe_1(fe *h) {
+  OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
+  h->v[0] = 1;
+}
+
+static void fe_loose_1(fe_loose *h) {
+  OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
+  h->v[0] = 1;
+}
+
+static void fe_add_impl(uint32_t out[10], const uint32_t in1[10], const uint32_t in2[10]) {
+  { const uint32_t x20 = in1[9];
+  { const uint32_t x21 = in1[8];
+  { const uint32_t x19 = in1[7];
+  { const uint32_t x17 = in1[6];
+  { const uint32_t x15 = in1[5];
+  { const uint32_t x13 = in1[4];
+  { const uint32_t x11 = in1[3];
+  { const uint32_t x9 = in1[2];
+  { const uint32_t x7 = in1[1];
+  { const uint32_t x5 = in1[0];
+  { const uint32_t x38 = in2[9];
+  { const uint32_t x39 = in2[8];
+  { const uint32_t x37 = in2[7];
+  { const uint32_t x35 = in2[6];
+  { const uint32_t x33 = in2[5];
+  { const uint32_t x31 = in2[4];
+  { const uint32_t x29 = in2[3];
+  { const uint32_t x27 = in2[2];
+  { const uint32_t x25 = in2[1];
+  { const uint32_t x23 = in2[0];
+  out[0] = (x5 + x23);
+  out[1] = (x7 + x25);
+  out[2] = (x9 + x27);
+  out[3] = (x11 + x29);
+  out[4] = (x13 + x31);
+  out[5] = (x15 + x33);
+  out[6] = (x17 + x35);
+  out[7] = (x19 + x37);
+  out[8] = (x21 + x39);
+  out[9] = (x20 + x38);
+  }}}}}}}}}}}}}}}}}}}}
+}
+
+// h = f + g
+// Can overlap h with f or g.
+//
+// Preconditions:
+//    |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
+//    |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
+//
+// Postconditions:
+//    |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
+static void fe_add(fe_loose *h, const fe *f, const fe *g) {
+  assert_fe(f->v);
+  assert_fe(g->v);
+  fe_add_impl(h->v, f->v, g->v);
+  assert_fe_loose(h->v);
+}
+
+static void fe_sub_impl(uint32_t out[10], const uint32_t in1[10], const uint32_t in2[10]) {
+  { const uint32_t x20 = in1[9];
+  { const uint32_t x21 = in1[8];
+  { const uint32_t x19 = in1[7];
+  { const uint32_t x17 = in1[6];
+  { const uint32_t x15 = in1[5];
+  { const uint32_t x13 = in1[4];
+  { const uint32_t x11 = in1[3];
+  { const uint32_t x9 = in1[2];
+  { const uint32_t x7 = in1[1];
+  { const uint32_t x5 = in1[0];
+  { const uint32_t x38 = in2[9];
+  { const uint32_t x39 = in2[8];
+  { const uint32_t x37 = in2[7];
+  { const uint32_t x35 = in2[6];
+  { const uint32_t x33 = in2[5];
+  { const uint32_t x31 = in2[4];
+  { const uint32_t x29 = in2[3];
+  { const uint32_t x27 = in2[2];
+  { const uint32_t x25 = in2[1];
+  { const uint32_t x23 = in2[0];
+  out[0] = ((0x7ffffda + x5) - x23);
+  out[1] = ((0x3fffffe + x7) - x25);
+  out[2] = ((0x7fffffe + x9) - x27);
+  out[3] = ((0x3fffffe + x11) - x29);
+  out[4] = ((0x7fffffe + x13) - x31);
+  out[5] = ((0x3fffffe + x15) - x33);
+  out[6] = ((0x7fffffe + x17) - x35);
+  out[7] = ((0x3fffffe + x19) - x37);
+  out[8] = ((0x7fffffe + x21) - x39);
+  out[9] = ((0x3fffffe + x20) - x38);
+  }}}}}}}}}}}}}}}}}}}}
+}
+
+// h = f - g
+// Can overlap h with f or g.
+//
+// Preconditions:
+//    |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
+//    |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
+//
+// Postconditions:
+//    |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
+static void fe_sub(fe_loose *h, const fe *f, const fe *g) {
+  assert_fe(f->v);
+  assert_fe(g->v);
+  fe_sub_impl(h->v, f->v, g->v);
+  assert_fe_loose(h->v);
+}
+
+static void fe_carry_impl(uint32_t out[10], const uint32_t in1[10]) {
+  { const uint32_t x17 = in1[9];
+  { const uint32_t x18 = in1[8];
+  { const uint32_t x16 = in1[7];
+  { const uint32_t x14 = in1[6];
+  { const uint32_t x12 = in1[5];
+  { const uint32_t x10 = in1[4];
+  { const uint32_t x8 = in1[3];
+  { const uint32_t x6 = in1[2];
+  { const uint32_t x4 = in1[1];
+  { const uint32_t x2 = in1[0];
+  { uint32_t x19 = (x2 >> 0x1a);
+  { uint32_t x20 = (x2 & 0x3ffffff);
+  { uint32_t x21 = (x19 + x4);
+  { uint32_t x22 = (x21 >> 0x19);
+  { uint32_t x23 = (x21 & 0x1ffffff);
+  { uint32_t x24 = (x22 + x6);
+  { uint32_t x25 = (x24 >> 0x1a);
+  { uint32_t x26 = (x24 & 0x3ffffff);
+  { uint32_t x27 = (x25 + x8);
+  { uint32_t x28 = (x27 >> 0x19);
+  { uint32_t x29 = (x27 & 0x1ffffff);
+  { uint32_t x30 = (x28 + x10);
+  { uint32_t x31 = (x30 >> 0x1a);
+  { uint32_t x32 = (x30 & 0x3ffffff);
+  { uint32_t x33 = (x31 + x12);
+  { uint32_t x34 = (x33 >> 0x19);
+  { uint32_t x35 = (x33 & 0x1ffffff);
+  { uint32_t x36 = (x34 + x14);
+  { uint32_t x37 = (x36 >> 0x1a);
+  { uint32_t x38 = (x36 & 0x3ffffff);
+  { uint32_t x39 = (x37 + x16);
+  { uint32_t x40 = (x39 >> 0x19);
+  { uint32_t x41 = (x39 & 0x1ffffff);
+  { uint32_t x42 = (x40 + x18);
+  { uint32_t x43 = (x42 >> 0x1a);
+  { uint32_t x44 = (x42 & 0x3ffffff);
+  { uint32_t x45 = (x43 + x17);
+  { uint32_t x46 = (x45 >> 0x19);
+  { uint32_t x47 = (x45 & 0x1ffffff);
+  { uint32_t x48 = (x20 + (0x13 * x46));
+  { uint32_t x49 = (x48 >> 0x1a);
+  { uint32_t x50 = (x48 & 0x3ffffff);
+  { uint32_t x51 = (x49 + x23);
+  { uint32_t x52 = (x51 >> 0x19);
+  { uint32_t x53 = (x51 & 0x1ffffff);
+  out[0] = x50;
+  out[1] = x53;
+  out[2] = (x52 + x26);
+  out[3] = x29;
+  out[4] = x32;
+  out[5] = x35;
+  out[6] = x38;
+  out[7] = x41;
+  out[8] = x44;
+  out[9] = x47;
+  }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+}
+
+static void fe_carry(fe *h, const fe_loose* f) {
+  assert_fe_loose(f->v);
+  fe_carry_impl(h->v, f->v);
+  assert_fe(h->v);
+}
+
+static void fe_mul_impl(uint32_t out[10], const uint32_t in1[10], const uint32_t in2[10]) {
+  assert_fe_loose(in1);
+  assert_fe_loose(in2);
+  { const uint32_t x20 = in1[9];
+  { const uint32_t x21 = in1[8];
+  { const uint32_t x19 = in1[7];
+  { const uint32_t x17 = in1[6];
+  { const uint32_t x15 = in1[5];
+  { const uint32_t x13 = in1[4];
+  { const uint32_t x11 = in1[3];
+  { const uint32_t x9 = in1[2];
+  { const uint32_t x7 = in1[1];
+  { const uint32_t x5 = in1[0];
+  { const uint32_t x38 = in2[9];
+  { const uint32_t x39 = in2[8];
+  { const uint32_t x37 = in2[7];
+  { const uint32_t x35 = in2[6];
+  { const uint32_t x33 = in2[5];
+  { const uint32_t x31 = in2[4];
+  { const uint32_t x29 = in2[3];
+  { const uint32_t x27 = in2[2];
+  { const uint32_t x25 = in2[1];
+  { const uint32_t x23 = in2[0];
+  { uint64_t x40 = ((uint64_t)x23 * x5);
+  { uint64_t x41 = (((uint64_t)x23 * x7) + ((uint64_t)x25 * x5));
+  { uint64_t x42 = ((((uint64_t)(0x2 * x25) * x7) + ((uint64_t)x23 * x9)) + ((uint64_t)x27 * x5));
+  { uint64_t x43 = (((((uint64_t)x25 * x9) + ((uint64_t)x27 * x7)) + ((uint64_t)x23 * x11)) + ((uint64_t)x29 * x5));
+  { uint64_t x44 = (((((uint64_t)x27 * x9) + (0x2 * (((uint64_t)x25 * x11) + ((uint64_t)x29 * x7)))) + ((uint64_t)x23 * x13)) + ((uint64_t)x31 * x5));
+  { uint64_t x45 = (((((((uint64_t)x27 * x11) + ((uint64_t)x29 * x9)) + ((uint64_t)x25 * x13)) + ((uint64_t)x31 * x7)) + ((uint64_t)x23 * x15)) + ((uint64_t)x33 * x5));
+  { uint64_t x46 = (((((0x2 * ((((uint64_t)x29 * x11) + ((uint64_t)x25 * x15)) + ((uint64_t)x33 * x7))) + ((uint64_t)x27 * x13)) + ((uint64_t)x31 * x9)) + ((uint64_t)x23 * x17)) + ((uint64_t)x35 * x5));
+  { uint64_t x47 = (((((((((uint64_t)x29 * x13) + ((uint64_t)x31 * x11)) + ((uint64_t)x27 * x15)) + ((uint64_t)x33 * x9)) + ((uint64_t)x25 * x17)) + ((uint64_t)x35 * x7)) + ((uint64_t)x23 * x19)) + ((uint64_t)x37 * x5));
+  { uint64_t x48 = (((((((uint64_t)x31 * x13) + (0x2 * (((((uint64_t)x29 * x15) + ((uint64_t)x33 * x11)) + ((uint64_t)x25 * x19)) + ((uint64_t)x37 * x7)))) + ((uint64_t)x27 * x17)) + ((uint64_t)x35 * x9)) + ((uint64_t)x23 * x21)) + ((uint64_t)x39 * x5));
+  { uint64_t x49 = (((((((((((uint64_t)x31 * x15) + ((uint64_t)x33 * x13)) + ((uint64_t)x29 * x17)) + ((uint64_t)x35 * x11)) + ((uint64_t)x27 * x19)) + ((uint64_t)x37 * x9)) + ((uint64_t)x25 * x21)) + ((uint64_t)x39 * x7)) + ((uint64_t)x23 * x20)) + ((uint64_t)x38 * x5));
+  { uint64_t x50 = (((((0x2 * ((((((uint64_t)x33 * x15) + ((uint64_t)x29 * x19)) + ((uint64_t)x37 * x11)) + ((uint64_t)x25 * x20)) + ((uint64_t)x38 * x7))) + ((uint64_t)x31 * x17)) + ((uint64_t)x35 * x13)) + ((uint64_t)x27 * x21)) + ((uint64_t)x39 * x9));
+  { uint64_t x51 = (((((((((uint64_t)x33 * x17) + ((uint64_t)x35 * x15)) + ((uint64_t)x31 * x19)) + ((uint64_t)x37 * x13)) + ((uint64_t)x29 * x21)) + ((uint64_t)x39 * x11)) + ((uint64_t)x27 * x20)) + ((uint64_t)x38 * x9));
+  { uint64_t x52 = (((((uint64_t)x35 * x17) + (0x2 * (((((uint64_t)x33 * x19) + ((uint64_t)x37 * x15)) + ((uint64_t)x29 * x20)) + ((uint64_t)x38 * x11)))) + ((uint64_t)x31 * x21)) + ((uint64_t)x39 * x13));
+  { uint64_t x53 = (((((((uint64_t)x35 * x19) + ((uint64_t)x37 * x17)) + ((uint64_t)x33 * x21)) + ((uint64_t)x39 * x15)) + ((uint64_t)x31 * x20)) + ((uint64_t)x38 * x13));
+  { uint64_t x54 = (((0x2 * ((((uint64_t)x37 * x19) + ((uint64_t)x33 * x20)) + ((uint64_t)x38 * x15))) + ((uint64_t)x35 * x21)) + ((uint64_t)x39 * x17));
+  { uint64_t x55 = (((((uint64_t)x37 * x21) + ((uint64_t)x39 * x19)) + ((uint64_t)x35 * x20)) + ((uint64_t)x38 * x17));
+  { uint64_t x56 = (((uint64_t)x39 * x21) + (0x2 * (((uint64_t)x37 * x20) + ((uint64_t)x38 * x19))));
+  { uint64_t x57 = (((uint64_t)x39 * x20) + ((uint64_t)x38 * x21));
+  { uint64_t x58 = ((uint64_t)(0x2 * x38) * x20);
+  { uint64_t x59 = (x48 + (x58 << 0x4));
+  { uint64_t x60 = (x59 + (x58 << 0x1));
+  { uint64_t x61 = (x60 + x58);
+  { uint64_t x62 = (x47 + (x57 << 0x4));
+  { uint64_t x63 = (x62 + (x57 << 0x1));
+  { uint64_t x64 = (x63 + x57);
+  { uint64_t x65 = (x46 + (x56 << 0x4));
+  { uint64_t x66 = (x65 + (x56 << 0x1));
+  { uint64_t x67 = (x66 + x56);
+  { uint64_t x68 = (x45 + (x55 << 0x4));
+  { uint64_t x69 = (x68 + (x55 << 0x1));
+  { uint64_t x70 = (x69 + x55);
+  { uint64_t x71 = (x44 + (x54 << 0x4));
+  { uint64_t x72 = (x71 + (x54 << 0x1));
+  { uint64_t x73 = (x72 + x54);
+  { uint64_t x74 = (x43 + (x53 << 0x4));
+  { uint64_t x75 = (x74 + (x53 << 0x1));
+  { uint64_t x76 = (x75 + x53);
+  { uint64_t x77 = (x42 + (x52 << 0x4));
+  { uint64_t x78 = (x77 + (x52 << 0x1));
+  { uint64_t x79 = (x78 + x52);
+  { uint64_t x80 = (x41 + (x51 << 0x4));
+  { uint64_t x81 = (x80 + (x51 << 0x1));
+  { uint64_t x82 = (x81 + x51);
+  { uint64_t x83 = (x40 + (x50 << 0x4));
+  { uint64_t x84 = (x83 + (x50 << 0x1));
+  { uint64_t x85 = (x84 + x50);
+  { uint64_t x86 = (x85 >> 0x1a);
+  { uint32_t x87 = ((uint32_t)x85 & 0x3ffffff);
+  { uint64_t x88 = (x86 + x82);
+  { uint64_t x89 = (x88 >> 0x19);
+  { uint32_t x90 = ((uint32_t)x88 & 0x1ffffff);
+  { uint64_t x91 = (x89 + x79);
+  { uint64_t x92 = (x91 >> 0x1a);
+  { uint32_t x93 = ((uint32_t)x91 & 0x3ffffff);
+  { uint64_t x94 = (x92 + x76);
+  { uint64_t x95 = (x94 >> 0x19);
+  { uint32_t x96 = ((uint32_t)x94 & 0x1ffffff);
+  { uint64_t x97 = (x95 + x73);
+  { uint64_t x98 = (x97 >> 0x1a);
+  { uint32_t x99 = ((uint32_t)x97 & 0x3ffffff);
+  { uint64_t x100 = (x98 + x70);
+  { uint64_t x101 = (x100 >> 0x19);
+  { uint32_t x102 = ((uint32_t)x100 & 0x1ffffff);
+  { uint64_t x103 = (x101 + x67);
+  { uint64_t x104 = (x103 >> 0x1a);
+  { uint32_t x105 = ((uint32_t)x103 & 0x3ffffff);
+  { uint64_t x106 = (x104 + x64);
+  { uint64_t x107 = (x106 >> 0x19);
+  { uint32_t x108 = ((uint32_t)x106 & 0x1ffffff);
+  { uint64_t x109 = (x107 + x61);
+  { uint64_t x110 = (x109 >> 0x1a);
+  { uint32_t x111 = ((uint32_t)x109 & 0x3ffffff);
+  { uint64_t x112 = (x110 + x49);
+  { uint64_t x113 = (x112 >> 0x19);
+  { uint32_t x114 = ((uint32_t)x112 & 0x1ffffff);
+  { uint64_t x115 = (x87 + (0x13 * x113));
+  { uint32_t x116 = (uint32_t) (x115 >> 0x1a);
+  { uint32_t x117 = ((uint32_t)x115 & 0x3ffffff);
+  { uint32_t x118 = (x116 + x90);
+  { uint32_t x119 = (x118 >> 0x19);
+  { uint32_t x120 = (x118 & 0x1ffffff);
+  out[0] = x117;
+  out[1] = x120;
+  out[2] = (x119 + x93);
+  out[3] = x96;
+  out[4] = x99;
+  out[5] = x102;
+  out[6] = x105;
+  out[7] = x108;
+  out[8] = x111;
+  out[9] = x114;
+  }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+  assert_fe(out);
+}
+
+static void fe_mul_ltt(fe_loose *h, const fe *f, const fe *g) {
+  fe_mul_impl(h->v, f->v, g->v);
+}
+
+static void fe_mul_llt(fe_loose *h, const fe_loose *f, const fe *g) {
+  fe_mul_impl(h->v, f->v, g->v);
+}
+
+static void fe_mul_ttt(fe *h, const fe *f, const fe *g) {
+  fe_mul_impl(h->v, f->v, g->v);
+}
+
+static void fe_mul_tlt(fe *h, const fe_loose *f, const fe *g) {
+  fe_mul_impl(h->v, f->v, g->v);
+}
+
+static void fe_mul_ttl(fe *h, const fe *f, const fe_loose *g) {
+  fe_mul_impl(h->v, f->v, g->v);
+}
+
+static void fe_mul_tll(fe *h, const fe_loose *f, const fe_loose *g) {
+  fe_mul_impl(h->v, f->v, g->v);
+}
+
+static void fe_sqr_impl(uint32_t out[10], const uint32_t in1[10]) {
+  assert_fe_loose(in1);
+  { const uint32_t x17 = in1[9];
+  { const uint32_t x18 = in1[8];
+  { const uint32_t x16 = in1[7];
+  { const uint32_t x14 = in1[6];
+  { const uint32_t x12 = in1[5];
+  { const uint32_t x10 = in1[4];
+  { const uint32_t x8 = in1[3];
+  { const uint32_t x6 = in1[2];
+  { const uint32_t x4 = in1[1];
+  { const uint32_t x2 = in1[0];
+  { uint64_t x19 = ((uint64_t)x2 * x2);
+  { uint64_t x20 = ((uint64_t)(0x2 * x2) * x4);
+  { uint64_t x21 = (0x2 * (((uint64_t)x4 * x4) + ((uint64_t)x2 * x6)));
+  { uint64_t x22 = (0x2 * (((uint64_t)x4 * x6) + ((uint64_t)x2 * x8)));
+  { uint64_t x23 = ((((uint64_t)x6 * x6) + ((uint64_t)(0x4 * x4) * x8)) + ((uint64_t)(0x2 * x2) * x10));
+  { uint64_t x24 = (0x2 * ((((uint64_t)x6 * x8) + ((uint64_t)x4 * x10)) + ((uint64_t)x2 * x12)));
+  { uint64_t x25 = (0x2 * (((((uint64_t)x8 * x8) + ((uint64_t)x6 * x10)) + ((uint64_t)x2 * x14)) + ((uint64_t)(0x2 * x4) * x12)));
+  { uint64_t x26 = (0x2 * (((((uint64_t)x8 * x10) + ((uint64_t)x6 * x12)) + ((uint64_t)x4 * x14)) + ((uint64_t)x2 * x16)));
+  { uint64_t x27 = (((uint64_t)x10 * x10) + (0x2 * ((((uint64_t)x6 * x14) + ((uint64_t)x2 * x18)) + (0x2 * (((uint64_t)x4 * x16) + ((uint64_t)x8 * x12))))));
+  { uint64_t x28 = (0x2 * ((((((uint64_t)x10 * x12) + ((uint64_t)x8 * x14)) + ((uint64_t)x6 * x16)) + ((uint64_t)x4 * x18)) + ((uint64_t)x2 * x17)));
+  { uint64_t x29 = (0x2 * (((((uint64_t)x12 * x12) + ((uint64_t)x10 * x14)) + ((uint64_t)x6 * x18)) + (0x2 * (((uint64_t)x8 * x16) + ((uint64_t)x4 * x17)))));
+  { uint64_t x30 = (0x2 * (((((uint64_t)x12 * x14) + ((uint64_t)x10 * x16)) + ((uint64_t)x8 * x18)) + ((uint64_t)x6 * x17)));
+  { uint64_t x31 = (((uint64_t)x14 * x14) + (0x2 * (((uint64_t)x10 * x18) + (0x2 * (((uint64_t)x12 * x16) + ((uint64_t)x8 * x17))))));
+  { uint64_t x32 = (0x2 * ((((uint64_t)x14 * x16) + ((uint64_t)x12 * x18)) + ((uint64_t)x10 * x17)));
+  { uint64_t x33 = (0x2 * ((((uint64_t)x16 * x16) + ((uint64_t)x14 * x18)) + ((uint64_t)(0x2 * x12) * x17)));
+  { uint64_t x34 = (0x2 * (((uint64_t)x16 * x18) + ((uint64_t)x14 * x17)));
+  { uint64_t x35 = (((uint64_t)x18 * x18) + ((uint64_t)(0x4 * x16) * x17));
+  { uint64_t x36 = ((uint64_t)(0x2 * x18) * x17);
+  { uint64_t x37 = ((uint64_t)(0x2 * x17) * x17);
+  { uint64_t x38 = (x27 + (x37 << 0x4));
+  { uint64_t x39 = (x38 + (x37 << 0x1));
+  { uint64_t x40 = (x39 + x37);
+  { uint64_t x41 = (x26 + (x36 << 0x4));
+  { uint64_t x42 = (x41 + (x36 << 0x1));
+  { uint64_t x43 = (x42 + x36);
+  { uint64_t x44 = (x25 + (x35 << 0x4));
+  { uint64_t x45 = (x44 + (x35 << 0x1));
+  { uint64_t x46 = (x45 + x35);
+  { uint64_t x47 = (x24 + (x34 << 0x4));
+  { uint64_t x48 = (x47 + (x34 << 0x1));
+  { uint64_t x49 = (x48 + x34);
+  { uint64_t x50 = (x23 + (x33 << 0x4));
+  { uint64_t x51 = (x50 + (x33 << 0x1));
+  { uint64_t x52 = (x51 + x33);
+  { uint64_t x53 = (x22 + (x32 << 0x4));
+  { uint64_t x54 = (x53 + (x32 << 0x1));
+  { uint64_t x55 = (x54 + x32);
+  { uint64_t x56 = (x21 + (x31 << 0x4));
+  { uint64_t x57 = (x56 + (x31 << 0x1));
+  { uint64_t x58 = (x57 + x31);
+  { uint64_t x59 = (x20 + (x30 << 0x4));
+  { uint64_t x60 = (x59 + (x30 << 0x1));
+  { uint64_t x61 = (x60 + x30);
+  { uint64_t x62 = (x19 + (x29 << 0x4));
+  { uint64_t x63 = (x62 + (x29 << 0x1));
+  { uint64_t x64 = (x63 + x29);
+  { uint64_t x65 = (x64 >> 0x1a);
+  { uint32_t x66 = ((uint32_t)x64 & 0x3ffffff);
+  { uint64_t x67 = (x65 + x61);
+  { uint64_t x68 = (x67 >> 0x19);
+  { uint32_t x69 = ((uint32_t)x67 & 0x1ffffff);
+  { uint64_t x70 = (x68 + x58);
+  { uint64_t x71 = (x70 >> 0x1a);
+  { uint32_t x72 = ((uint32_t)x70 & 0x3ffffff);
+  { uint64_t x73 = (x71 + x55);
+  { uint64_t x74 = (x73 >> 0x19);
+  { uint32_t x75 = ((uint32_t)x73 & 0x1ffffff);
+  { uint64_t x76 = (x74 + x52);
+  { uint64_t x77 = (x76 >> 0x1a);
+  { uint32_t x78 = ((uint32_t)x76 & 0x3ffffff);
+  { uint64_t x79 = (x77 + x49);
+  { uint64_t x80 = (x79 >> 0x19);
+  { uint32_t x81 = ((uint32_t)x79 & 0x1ffffff);
+  { uint64_t x82 = (x80 + x46);
+  { uint64_t x83 = (x82 >> 0x1a);
+  { uint32_t x84 = ((uint32_t)x82 & 0x3ffffff);
+  { uint64_t x85 = (x83 + x43);
+  { uint64_t x86 = (x85 >> 0x19);
+  { uint32_t x87 = ((uint32_t)x85 & 0x1ffffff);
+  { uint64_t x88 = (x86 + x40);
+  { uint64_t x89 = (x88 >> 0x1a);
+  { uint32_t x90 = ((uint32_t)x88 & 0x3ffffff);
+  { uint64_t x91 = (x89 + x28);
+  { uint64_t x92 = (x91 >> 0x19);
+  { uint32_t x93 = ((uint32_t)x91 & 0x1ffffff);
+  { uint64_t x94 = (x66 + (0x13 * x92));
+  { uint32_t x95 = (uint32_t) (x94 >> 0x1a);
+  { uint32_t x96 = ((uint32_t)x94 & 0x3ffffff);
+  { uint32_t x97 = (x95 + x69);
+  { uint32_t x98 = (x97 >> 0x19);
+  { uint32_t x99 = (x97 & 0x1ffffff);
+  out[0] = x96;
+  out[1] = x99;
+  out[2] = (x98 + x72);
+  out[3] = x75;
+  out[4] = x78;
+  out[5] = x81;
+  out[6] = x84;
+  out[7] = x87;
+  out[8] = x90;
+  out[9] = x93;
+  }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+  assert_fe(out);
+}
+
+static void fe_sq_tl(fe *h, const fe_loose *f) {
+  fe_sqr_impl(h->v, f->v);
+}
+
+static void fe_sq_tt(fe *h, const fe *f) {
+  fe_sqr_impl(h->v, f->v);
+}
+
+static void fe_loose_invert(fe *out, const fe_loose *z) {
+  fe t0;
+  fe t1;
+  fe t2;
+  fe t3;
+  int i;
+
+  fe_sq_tl(&t0, z);
+  fe_sq_tt(&t1, &t0);
+  for (i = 1; i < 2; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_tlt(&t1, z, &t1);
+  fe_mul_ttt(&t0, &t0, &t1);
+  fe_sq_tt(&t2, &t0);
+  fe_mul_ttt(&t1, &t1, &t2);
+  fe_sq_tt(&t2, &t1);
+  for (i = 1; i < 5; ++i) {
+    fe_sq_tt(&t2, &t2);
+  }
+  fe_mul_ttt(&t1, &t2, &t1);
+  fe_sq_tt(&t2, &t1);
+  for (i = 1; i < 10; ++i) {
+    fe_sq_tt(&t2, &t2);
+  }
+  fe_mul_ttt(&t2, &t2, &t1);
+  fe_sq_tt(&t3, &t2);
+  for (i = 1; i < 20; ++i) {
+    fe_sq_tt(&t3, &t3);
+  }
+  fe_mul_ttt(&t2, &t3, &t2);
+  fe_sq_tt(&t2, &t2);
+  for (i = 1; i < 10; ++i) {
+    fe_sq_tt(&t2, &t2);
+  }
+  fe_mul_ttt(&t1, &t2, &t1);
+  fe_sq_tt(&t2, &t1);
+  for (i = 1; i < 50; ++i) {
+    fe_sq_tt(&t2, &t2);
+  }
+  fe_mul_ttt(&t2, &t2, &t1);
+  fe_sq_tt(&t3, &t2);
+  for (i = 1; i < 100; ++i) {
+    fe_sq_tt(&t3, &t3);
+  }
+  fe_mul_ttt(&t2, &t3, &t2);
+  fe_sq_tt(&t2, &t2);
+  for (i = 1; i < 50; ++i) {
+    fe_sq_tt(&t2, &t2);
+  }
+  fe_mul_ttt(&t1, &t2, &t1);
+  fe_sq_tt(&t1, &t1);
+  for (i = 1; i < 5; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_ttt(out, &t1, &t0);
+}
+
+static void fe_invert(fe *out, const fe *z) {
+  fe_loose l;
+  fe_copy_lt(&l, z);
+  fe_loose_invert(out, &l);
+}
+
+static void fe_neg_impl(uint32_t out[10], const uint32_t in2[10]) {
+  { const uint32_t x20 = 0;
+  { const uint32_t x21 = 0;
+  { const uint32_t x19 = 0;
+  { const uint32_t x17 = 0;
+  { const uint32_t x15 = 0;
+  { const uint32_t x13 = 0;
+  { const uint32_t x11 = 0;
+  { const uint32_t x9 = 0;
+  { const uint32_t x7 = 0;
+  { const uint32_t x5 = 0;
+  { const uint32_t x38 = in2[9];
+  { const uint32_t x39 = in2[8];
+  { const uint32_t x37 = in2[7];
+  { const uint32_t x35 = in2[6];
+  { const uint32_t x33 = in2[5];
+  { const uint32_t x31 = in2[4];
+  { const uint32_t x29 = in2[3];
+  { const uint32_t x27 = in2[2];
+  { const uint32_t x25 = in2[1];
+  { const uint32_t x23 = in2[0];
+  out[0] = ((0x7ffffda + x5) - x23);
+  out[1] = ((0x3fffffe + x7) - x25);
+  out[2] = ((0x7fffffe + x9) - x27);
+  out[3] = ((0x3fffffe + x11) - x29);
+  out[4] = ((0x7fffffe + x13) - x31);
+  out[5] = ((0x3fffffe + x15) - x33);
+  out[6] = ((0x7fffffe + x17) - x35);
+  out[7] = ((0x3fffffe + x19) - x37);
+  out[8] = ((0x7fffffe + x21) - x39);
+  out[9] = ((0x3fffffe + x20) - x38);
+  }}}}}}}}}}}}}}}}}}}}
+}
+
+// h = -f
+//
+// Preconditions:
+//    |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
+//
+// Postconditions:
+//    |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
+static void fe_neg(fe_loose *h, const fe *f) {
+  assert_fe(f->v);
+  fe_neg_impl(h->v, f->v);
+  assert_fe_loose(h->v);
+}
+
+// Replace (f,g) with (g,g) if b == 1;
+// replace (f,g) with (f,g) if b == 0.
+//
+// Preconditions: b in {0,1}.
+static void fe_cmov(fe_loose *f, const fe_loose *g, unsigned b) {
+  b = 0-b;
+  unsigned i;
+  for (i = 0; i < 10; i++) {
+    uint32_t x = f->v[i] ^ g->v[i];
+    x &= b;
+    f->v[i] ^= x;
+  }
+}
+
+// return 0 if f == 0
+// return 1 if f != 0
+//
+// Preconditions:
+//    |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
+static int fe_isnonzero(const fe_loose *f) {
+  uint8_t s[32];
+  fe_loose_tobytes(s, f);
+
+  static const uint8_t zero[32] = {0};
+  return CRYPTO_memcmp(s, zero, sizeof(zero)) != 0;
+}
+
+// return 1 if f is in {1,3,5,...,q-2}
+// return 0 if f is in {0,2,4,...,q-1}
+//
+// Preconditions:
+//    |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
+static int fe_isnegative(const fe *f) {
+  uint8_t s[32];
+  fe_tobytes(s, f);
+  return s[0] & 1;
+}
+
+// NOTE: based on fiat-crypto fe_mul, edited for in2=2*in1
+static void fe_sq2_impl(uint32_t out[10], const uint32_t in1[10]) {
+  assert_fe_loose(in1);
+  { const uint32_t x20 = in1[9];
+  { const uint32_t x21 = in1[8];
+  { const uint32_t x19 = in1[7];
+  { const uint32_t x17 = in1[6];
+  { const uint32_t x15 = in1[5];
+  { const uint32_t x13 = in1[4];
+  { const uint32_t x11 = in1[3];
+  { const uint32_t x9 = in1[2];
+  { const uint32_t x7 = in1[1];
+  { const uint32_t x5 = in1[0];
+  { const uint32_t x38 = 2*in1[9];
+  { const uint32_t x39 = 2*in1[8];
+  { const uint32_t x37 = 2*in1[7];
+  { const uint32_t x35 = 2*in1[6];
+  { const uint32_t x33 = 2*in1[5];
+  { const uint32_t x31 = 2*in1[4];
+  { const uint32_t x29 = 2*in1[3];
+  { const uint32_t x27 = 2*in1[2];
+  { const uint32_t x25 = 2*in1[1];
+  { const uint32_t x23 = 2*in1[0];
+  { uint64_t x40 = ((uint64_t)x23 * x5);
+  { uint64_t x41 = (((uint64_t)x23 * x7) + ((uint64_t)x25 * x5));
+  { uint64_t x42 = ((((uint64_t)(0x2 * x25) * x7) + ((uint64_t)x23 * x9)) + ((uint64_t)x27 * x5));
+  { uint64_t x43 = (((((uint64_t)x25 * x9) + ((uint64_t)x27 * x7)) + ((uint64_t)x23 * x11)) + ((uint64_t)x29 * x5));
+  { uint64_t x44 = (((((uint64_t)x27 * x9) + (0x2 * (((uint64_t)x25 * x11) + ((uint64_t)x29 * x7)))) + ((uint64_t)x23 * x13)) + ((uint64_t)x31 * x5));
+  { uint64_t x45 = (((((((uint64_t)x27 * x11) + ((uint64_t)x29 * x9)) + ((uint64_t)x25 * x13)) + ((uint64_t)x31 * x7)) + ((uint64_t)x23 * x15)) + ((uint64_t)x33 * x5));
+  { uint64_t x46 = (((((0x2 * ((((uint64_t)x29 * x11) + ((uint64_t)x25 * x15)) + ((uint64_t)x33 * x7))) + ((uint64_t)x27 * x13)) + ((uint64_t)x31 * x9)) + ((uint64_t)x23 * x17)) + ((uint64_t)x35 * x5));
+  { uint64_t x47 = (((((((((uint64_t)x29 * x13) + ((uint64_t)x31 * x11)) + ((uint64_t)x27 * x15)) + ((uint64_t)x33 * x9)) + ((uint64_t)x25 * x17)) + ((uint64_t)x35 * x7)) + ((uint64_t)x23 * x19)) + ((uint64_t)x37 * x5));
+  { uint64_t x48 = (((((((uint64_t)x31 * x13) + (0x2 * (((((uint64_t)x29 * x15) + ((uint64_t)x33 * x11)) + ((uint64_t)x25 * x19)) + ((uint64_t)x37 * x7)))) + ((uint64_t)x27 * x17)) + ((uint64_t)x35 * x9)) + ((uint64_t)x23 * x21)) + ((uint64_t)x39 * x5));
+  { uint64_t x49 = (((((((((((uint64_t)x31 * x15) + ((uint64_t)x33 * x13)) + ((uint64_t)x29 * x17)) + ((uint64_t)x35 * x11)) + ((uint64_t)x27 * x19)) + ((uint64_t)x37 * x9)) + ((uint64_t)x25 * x21)) + ((uint64_t)x39 * x7)) + ((uint64_t)x23 * x20)) + ((uint64_t)x38 * x5));
+  { uint64_t x50 = (((((0x2 * ((((((uint64_t)x33 * x15) + ((uint64_t)x29 * x19)) + ((uint64_t)x37 * x11)) + ((uint64_t)x25 * x20)) + ((uint64_t)x38 * x7))) + ((uint64_t)x31 * x17)) + ((uint64_t)x35 * x13)) + ((uint64_t)x27 * x21)) + ((uint64_t)x39 * x9));
+  { uint64_t x51 = (((((((((uint64_t)x33 * x17) + ((uint64_t)x35 * x15)) + ((uint64_t)x31 * x19)) + ((uint64_t)x37 * x13)) + ((uint64_t)x29 * x21)) + ((uint64_t)x39 * x11)) + ((uint64_t)x27 * x20)) + ((uint64_t)x38 * x9));
+  { uint64_t x52 = (((((uint64_t)x35 * x17) + (0x2 * (((((uint64_t)x33 * x19) + ((uint64_t)x37 * x15)) + ((uint64_t)x29 * x20)) + ((uint64_t)x38 * x11)))) + ((uint64_t)x31 * x21)) + ((uint64_t)x39 * x13));
+  { uint64_t x53 = (((((((uint64_t)x35 * x19) + ((uint64_t)x37 * x17)) + ((uint64_t)x33 * x21)) + ((uint64_t)x39 * x15)) + ((uint64_t)x31 * x20)) + ((uint64_t)x38 * x13));
+  { uint64_t x54 = (((0x2 * ((((uint64_t)x37 * x19) + ((uint64_t)x33 * x20)) + ((uint64_t)x38 * x15))) + ((uint64_t)x35 * x21)) + ((uint64_t)x39 * x17));
+  { uint64_t x55 = (((((uint64_t)x37 * x21) + ((uint64_t)x39 * x19)) + ((uint64_t)x35 * x20)) + ((uint64_t)x38 * x17));
+  { uint64_t x56 = (((uint64_t)x39 * x21) + (0x2 * (((uint64_t)x37 * x20) + ((uint64_t)x38 * x19))));
+  { uint64_t x57 = (((uint64_t)x39 * x20) + ((uint64_t)x38 * x21));
+  { uint64_t x58 = ((uint64_t)(0x2 * x38) * x20);
+  { uint64_t x59 = (x48 + (x58 << 0x4));
+  { uint64_t x60 = (x59 + (x58 << 0x1));
+  { uint64_t x61 = (x60 + x58);
+  { uint64_t x62 = (x47 + (x57 << 0x4));
+  { uint64_t x63 = (x62 + (x57 << 0x1));
+  { uint64_t x64 = (x63 + x57);
+  { uint64_t x65 = (x46 + (x56 << 0x4));
+  { uint64_t x66 = (x65 + (x56 << 0x1));
+  { uint64_t x67 = (x66 + x56);
+  { uint64_t x68 = (x45 + (x55 << 0x4));
+  { uint64_t x69 = (x68 + (x55 << 0x1));
+  { uint64_t x70 = (x69 + x55);
+  { uint64_t x71 = (x44 + (x54 << 0x4));
+  { uint64_t x72 = (x71 + (x54 << 0x1));
+  { uint64_t x73 = (x72 + x54);
+  { uint64_t x74 = (x43 + (x53 << 0x4));
+  { uint64_t x75 = (x74 + (x53 << 0x1));
+  { uint64_t x76 = (x75 + x53);
+  { uint64_t x77 = (x42 + (x52 << 0x4));
+  { uint64_t x78 = (x77 + (x52 << 0x1));
+  { uint64_t x79 = (x78 + x52);
+  { uint64_t x80 = (x41 + (x51 << 0x4));
+  { uint64_t x81 = (x80 + (x51 << 0x1));
+  { uint64_t x82 = (x81 + x51);
+  { uint64_t x83 = (x40 + (x50 << 0x4));
+  { uint64_t x84 = (x83 + (x50 << 0x1));
+  { uint64_t x85 = (x84 + x50);
+  { uint64_t x86 = (x85 >> 0x1a);
+  { uint32_t x87 = ((uint32_t)x85 & 0x3ffffff);
+  { uint64_t x88 = (x86 + x82);
+  { uint64_t x89 = (x88 >> 0x19);
+  { uint32_t x90 = ((uint32_t)x88 & 0x1ffffff);
+  { uint64_t x91 = (x89 + x79);
+  { uint64_t x92 = (x91 >> 0x1a);
+  { uint32_t x93 = ((uint32_t)x91 & 0x3ffffff);
+  { uint64_t x94 = (x92 + x76);
+  { uint64_t x95 = (x94 >> 0x19);
+  { uint32_t x96 = ((uint32_t)x94 & 0x1ffffff);
+  { uint64_t x97 = (x95 + x73);
+  { uint64_t x98 = (x97 >> 0x1a);
+  { uint32_t x99 = ((uint32_t)x97 & 0x3ffffff);
+  { uint64_t x100 = (x98 + x70);
+  { uint64_t x101 = (x100 >> 0x19);
+  { uint32_t x102 = ((uint32_t)x100 & 0x1ffffff);
+  { uint64_t x103 = (x101 + x67);
+  { uint64_t x104 = (x103 >> 0x1a);
+  { uint32_t x105 = ((uint32_t)x103 & 0x3ffffff);
+  { uint64_t x106 = (x104 + x64);
+  { uint64_t x107 = (x106 >> 0x19);
+  { uint32_t x108 = ((uint32_t)x106 & 0x1ffffff);
+  { uint64_t x109 = (x107 + x61);
+  { uint64_t x110 = (x109 >> 0x1a);
+  { uint32_t x111 = ((uint32_t)x109 & 0x3ffffff);
+  { uint64_t x112 = (x110 + x49);
+  { uint64_t x113 = (x112 >> 0x19);
+  { uint32_t x114 = ((uint32_t)x112 & 0x1ffffff);
+  { uint64_t x115 = (x87 + (0x13 * x113));
+  { uint32_t x116 = (uint32_t) (x115 >> 0x1a);
+  { uint32_t x117 = ((uint32_t)x115 & 0x3ffffff);
+  { uint32_t x118 = (x116 + x90);
+  { uint32_t x119 = (x118 >> 0x19);
+  { uint32_t x120 = (x118 & 0x1ffffff);
+  out[0] = x117;
+  out[1] = x120;
+  out[2] = (x119 + x93);
+  out[3] = x96;
+  out[4] = x99;
+  out[5] = x102;
+  out[6] = x105;
+  out[7] = x108;
+  out[8] = x111;
+  out[9] = x114;
+  }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+  assert_fe(out);
+}
+
+static void fe_sq2_tt(fe *h, const fe *f) {
+  fe_sq2_impl(h->v, f->v);
+}
+
+static void fe_pow22523(fe *out, const fe *z) {
+  fe t0;
+  fe t1;
+  fe t2;
+  int i;
+
+  fe_sq_tt(&t0, z);
+  fe_sq_tt(&t1, &t0);
+  for (i = 1; i < 2; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_ttt(&t1, z, &t1);
+  fe_mul_ttt(&t0, &t0, &t1);
+  fe_sq_tt(&t0, &t0);
+  fe_mul_ttt(&t0, &t1, &t0);
+  fe_sq_tt(&t1, &t0);
+  for (i = 1; i < 5; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_ttt(&t0, &t1, &t0);
+  fe_sq_tt(&t1, &t0);
+  for (i = 1; i < 10; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_ttt(&t1, &t1, &t0);
+  fe_sq_tt(&t2, &t1);
+  for (i = 1; i < 20; ++i) {
+    fe_sq_tt(&t2, &t2);
+  }
+  fe_mul_ttt(&t1, &t2, &t1);
+  fe_sq_tt(&t1, &t1);
+  for (i = 1; i < 10; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_ttt(&t0, &t1, &t0);
+  fe_sq_tt(&t1, &t0);
+  for (i = 1; i < 50; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_ttt(&t1, &t1, &t0);
+  fe_sq_tt(&t2, &t1);
+  for (i = 1; i < 100; ++i) {
+    fe_sq_tt(&t2, &t2);
+  }
+  fe_mul_ttt(&t1, &t2, &t1);
+  fe_sq_tt(&t1, &t1);
+  for (i = 1; i < 50; ++i) {
+    fe_sq_tt(&t1, &t1);
+  }
+  fe_mul_ttt(&t0, &t1, &t0);
+  fe_sq_tt(&t0, &t0);
+  for (i = 1; i < 2; ++i) {
+    fe_sq_tt(&t0, &t0);
+  }
+  fe_mul_ttt(out, &t0, z);
+}
+
+void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h) {
+  fe recip;
+  fe x;
+  fe y;
+
+  fe_invert(&recip, &h->Z);
+  fe_mul_ttt(&x, &h->X, &recip);
+  fe_mul_ttt(&y, &h->Y, &recip);
+  fe_tobytes(s, &y);
+  s[31] ^= fe_isnegative(&x) << 7;
+}
+
+static void ge_p3_tobytes(uint8_t *s, const ge_p3 *h) {
+  fe recip;
+  fe x;
+  fe y;
+
+  fe_invert(&recip, &h->Z);
+  fe_mul_ttt(&x, &h->X, &recip);
+  fe_mul_ttt(&y, &h->Y, &recip);
+  fe_tobytes(s, &y);
+  s[31] ^= fe_isnegative(&x) << 7;
+}
+
+static const fe d = {{56195235, 13857412, 51736253, 6949390,   114729,
+                     24766616,  60832955, 30306712,  48412415, 21499315}};
+
+static const fe sqrtm1 = {{34513072, 25610706,  9377949,  3500415, 12389472,
+                          33281959,   41962654, 31548777, 326685,  11406482}};
+
+int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s) {
+  fe u;
+  fe_loose v;
+  fe v3;
+  fe vxx;
+  fe_loose check;
+
+  fe_frombytes(&h->Y, s);
+  fe_1(&h->Z);
+  fe_sq_tt(&v3, &h->Y);
+  fe_mul_ttt(&vxx, &v3, &d);
+  fe_sub(&v, &v3, &h->Z);  // u = y^2-1
+  fe_carry(&u, &v);
+  fe_add(&v, &vxx, &h->Z);  // v = dy^2+1
+
+  fe_sq_tl(&v3, &v);
+  fe_mul_ttl(&v3, &v3, &v);  // v3 = v^3
+  fe_sq_tt(&h->X, &v3);
+  fe_mul_ttl(&h->X, &h->X, &v);
+  fe_mul_ttt(&h->X, &h->X, &u);  // x = uv^7
+
+  fe_pow22523(&h->X, &h->X);  // x = (uv^7)^((q-5)/8)
+  fe_mul_ttt(&h->X, &h->X, &v3);
+  fe_mul_ttt(&h->X, &h->X, &u);  // x = uv^3(uv^7)^((q-5)/8)
+
+  fe_sq_tt(&vxx, &h->X);
+  fe_mul_ttl(&vxx, &vxx, &v);
+  fe_sub(&check, &vxx, &u);
+  if (fe_isnonzero(&check)) {
+    fe_add(&check, &vxx, &u);
+    if (fe_isnonzero(&check)) {
+      return -1;
+    }
+    fe_mul_ttt(&h->X, &h->X, &sqrtm1);
+  }
+
+  if (fe_isnegative(&h->X) != (s[31] >> 7)) {
+    fe_loose t;
+    fe_neg(&t, &h->X);
+    fe_carry(&h->X, &t);
+  }
+
+  fe_mul_ttt(&h->T, &h->X, &h->Y);
+  return 0;
+}
+
+static void ge_p2_0(ge_p2 *h) {
+  fe_0(&h->X);
+  fe_1(&h->Y);
+  fe_1(&h->Z);
+}
+
+static void ge_p3_0(ge_p3 *h) {
+  fe_0(&h->X);
+  fe_1(&h->Y);
+  fe_1(&h->Z);
+  fe_0(&h->T);
+}
+
+static void ge_cached_0(ge_cached *h) {
+  fe_loose_1(&h->YplusX);
+  fe_loose_1(&h->YminusX);
+  fe_loose_1(&h->Z);
+  fe_loose_0(&h->T2d);
+}
+
+static void ge_precomp_0(ge_precomp *h) {
+  fe_loose_1(&h->yplusx);
+  fe_loose_1(&h->yminusx);
+  fe_loose_0(&h->xy2d);
+}
+
+// r = p
+static void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) {
+  fe_copy(&r->X, &p->X);
+  fe_copy(&r->Y, &p->Y);
+  fe_copy(&r->Z, &p->Z);
+}
+
+static const fe d2 = {{45281625, 27714825,  36363642, 13898781, 229458,
+                      15978800,  54557047, 27058993,  29715967, 9444199}};
+
+// r = p
+void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p) {
+  fe_add(&r->YplusX, &p->Y, &p->X);
+  fe_sub(&r->YminusX, &p->Y, &p->X);
+  fe_copy_lt(&r->Z, &p->Z);
+  fe_mul_ltt(&r->T2d, &p->T, &d2);
+}
+
+// r = p
+void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) {
+  fe_mul_tll(&r->X, &p->X, &p->T);
+  fe_mul_tll(&r->Y, &p->Y, &p->Z);
+  fe_mul_tll(&r->Z, &p->Z, &p->T);
+}
+
+// r = p
+void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) {
+  fe_mul_tll(&r->X, &p->X, &p->T);
+  fe_mul_tll(&r->Y, &p->Y, &p->Z);
+  fe_mul_tll(&r->Z, &p->Z, &p->T);
+  fe_mul_tll(&r->T, &p->X, &p->Y);
+}
+
+// r = p
+static void ge_p1p1_to_cached(ge_cached *r, const ge_p1p1 *p) {
+  ge_p3 t;
+  x25519_ge_p1p1_to_p3(&t, p);
+  x25519_ge_p3_to_cached(r, &t);
+}
+
+// r = 2 * p
+static void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) {
+  fe trX, trZ, trT;
+  fe t0;
+
+  fe_sq_tt(&trX, &p->X);
+  fe_sq_tt(&trZ, &p->Y);
+  fe_sq2_tt(&trT, &p->Z);
+  fe_add(&r->Y, &p->X, &p->Y);
+  fe_sq_tl(&t0, &r->Y);
+
+  fe_add(&r->Y, &trZ, &trX);
+  fe_sub(&r->Z, &trZ, &trX);
+  fe_carry(&trZ, &r->Y);
+  fe_sub(&r->X, &t0, &trZ);
+  fe_carry(&trZ, &r->Z);
+  fe_sub(&r->T, &trT, &trZ);
+}
+
+// r = 2 * p
+static void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
+  ge_p2 q;
+  ge_p3_to_p2(&q, p);
+  ge_p2_dbl(r, &q);
+}
+
+// r = p + q
+static void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
+  fe trY, trZ, trT;
+
+  fe_add(&r->X, &p->Y, &p->X);
+  fe_sub(&r->Y, &p->Y, &p->X);
+  fe_mul_tll(&trZ, &r->X, &q->yplusx);
+  fe_mul_tll(&trY, &r->Y, &q->yminusx);
+  fe_mul_tlt(&trT, &q->xy2d, &p->T);
+  fe_add(&r->T, &p->Z, &p->Z);
+  fe_sub(&r->X, &trZ, &trY);
+  fe_add(&r->Y, &trZ, &trY);
+  fe_carry(&trZ, &r->T);
+  fe_add(&r->Z, &trZ, &trT);
+  fe_sub(&r->T, &trZ, &trT);
+}
+
+// r = p - q
+static void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
+  fe trY, trZ, trT;
+
+  fe_add(&r->X, &p->Y, &p->X);
+  fe_sub(&r->Y, &p->Y, &p->X);
+  fe_mul_tll(&trZ, &r->X, &q->yminusx);
+  fe_mul_tll(&trY, &r->Y, &q->yplusx);
+  fe_mul_tlt(&trT, &q->xy2d, &p->T);
+  fe_add(&r->T, &p->Z, &p->Z);
+  fe_sub(&r->X, &trZ, &trY);
+  fe_add(&r->Y, &trZ, &trY);
+  fe_carry(&trZ, &r->T);
+  fe_sub(&r->Z, &trZ, &trT);
+  fe_add(&r->T, &trZ, &trT);
+}
+
+// r = p + q
+void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
+  fe trX, trY, trZ, trT;
+
+  fe_add(&r->X, &p->Y, &p->X);
+  fe_sub(&r->Y, &p->Y, &p->X);
+  fe_mul_tll(&trZ, &r->X, &q->YplusX);
+  fe_mul_tll(&trY, &r->Y, &q->YminusX);
+  fe_mul_tlt(&trT, &q->T2d, &p->T);
+  fe_mul_ttl(&trX, &p->Z, &q->Z);
+  fe_add(&r->T, &trX, &trX);
+  fe_sub(&r->X, &trZ, &trY);
+  fe_add(&r->Y, &trZ, &trY);
+  fe_carry(&trZ, &r->T);
+  fe_add(&r->Z, &trZ, &trT);
+  fe_sub(&r->T, &trZ, &trT);
+}
+
+// r = p - q
+void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
+  fe trX, trY, trZ, trT;
+
+  fe_add(&r->X, &p->Y, &p->X);
+  fe_sub(&r->Y, &p->Y, &p->X);
+  fe_mul_tll(&trZ, &r->X, &q->YminusX);
+  fe_mul_tll(&trY, &r->Y, &q->YplusX);
+  fe_mul_tlt(&trT, &q->T2d, &p->T);
+  fe_mul_ttl(&trX, &p->Z, &q->Z);
+  fe_add(&r->T, &trX, &trX);
+  fe_sub(&r->X, &trZ, &trY);
+  fe_add(&r->Y, &trZ, &trY);
+  fe_carry(&trZ, &r->T);
+  fe_sub(&r->Z, &trZ, &trT);
+  fe_add(&r->T, &trZ, &trT);
+}
+
+static uint8_t equal(signed char b, signed char c) {
+  uint8_t ub = b;
+  uint8_t uc = c;
+  uint8_t x = ub ^ uc;  // 0: yes; 1..255: no
+  uint32_t y = x;       // 0: yes; 1..255: no
+  y -= 1;               // 4294967295: yes; 0..254: no
+  y >>= 31;             // 1: yes; 0: no
+  return y;
+}
+
+static void cmov(ge_precomp *t, const ge_precomp *u, uint8_t b) {
+  fe_cmov(&t->yplusx, &u->yplusx, b);
+  fe_cmov(&t->yminusx, &u->yminusx, b);
+  fe_cmov(&t->xy2d, &u->xy2d, b);
+}
+
+void x25519_ge_scalarmult_small_precomp(
+    ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]) {
+  // precomp_table is first expanded into matching |ge_precomp|
+  // elements.
+  ge_precomp multiples[15];
+
+  unsigned i;
+  for (i = 0; i < 15; i++) {
+    const uint8_t *bytes = &precomp_table[i*(2 * 32)];
+    fe x, y;
+    fe_frombytes(&x, bytes);
+    fe_frombytes(&y, bytes + 32);
+
+    ge_precomp *out = &multiples[i];
+    fe_add(&out->yplusx, &y, &x);
+    fe_sub(&out->yminusx, &y, &x);
+    fe_mul_ltt(&out->xy2d, &x, &y);
+    fe_mul_llt(&out->xy2d, &out->xy2d, &d2);
+  }
+
+  // See the comment above |k25519SmallPrecomp| about the structure of the
+  // precomputed elements. This loop does 64 additions and 64 doublings to
+  // calculate the result.
+  ge_p3_0(h);
+
+  for (i = 63; i < 64; i--) {
+    unsigned j;
+    signed char index = 0;
+
+    for (j = 0; j < 4; j++) {
+      const uint8_t bit = 1 & (a[(8 * j) + (i / 8)] >> (i & 7));
+      index |= (bit << j);
+    }
+
+    ge_precomp e;
+    ge_precomp_0(&e);
+
+    for (j = 1; j < 16; j++) {
+      cmov(&e, &multiples[j-1], equal(index, j));
+    }
+
+    ge_cached cached;
+    ge_p1p1 r;
+    x25519_ge_p3_to_cached(&cached, h);
+    x25519_ge_add(&r, h, &cached);
+    x25519_ge_p1p1_to_p3(h, &r);
+
+    ge_madd(&r, h, &e);
+    x25519_ge_p1p1_to_p3(h, &r);
+  }
+}
+
+#if defined(OPENSSL_SMALL)
+
+// This block of code replaces the standard base-point table with a much smaller
+// one. The standard table is 30,720 bytes while this one is just 960.
+//
+// This table contains 15 pairs of group elements, (x, y), where each field
+// element is serialised with |fe_tobytes|. If |i| is the index of the group
+// element then consider i+1 as a four-bit number: (i₀, i₁, i₂, i₃) (where i₀
+// is the most significant bit). The value of the group element is then:
+// (i₀×2^192 + i₁×2^128 + i₂×2^64 + i₃)G, where G is the generator.
+static const uint8_t k25519SmallPrecomp[15 * 2 * 32] = {
+    0x1a, 0xd5, 0x25, 0x8f, 0x60, 0x2d, 0x56, 0xc9, 0xb2, 0xa7, 0x25, 0x95,
+    0x60, 0xc7, 0x2c, 0x69, 0x5c, 0xdc, 0xd6, 0xfd, 0x31, 0xe2, 0xa4, 0xc0,
+    0xfe, 0x53, 0x6e, 0xcd, 0xd3, 0x36, 0x69, 0x21, 0x58, 0x66, 0x66, 0x66,
+    0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
+    0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
+    0x66, 0x66, 0x66, 0x66, 0x02, 0xa2, 0xed, 0xf4, 0x8f, 0x6b, 0x0b, 0x3e,
+    0xeb, 0x35, 0x1a, 0xd5, 0x7e, 0xdb, 0x78, 0x00, 0x96, 0x8a, 0xa0, 0xb4,
+    0xcf, 0x60, 0x4b, 0xd4, 0xd5, 0xf9, 0x2d, 0xbf, 0x88, 0xbd, 0x22, 0x62,
+    0x13, 0x53, 0xe4, 0x82, 0x57, 0xfa, 0x1e, 0x8f, 0x06, 0x2b, 0x90, 0xba,
+    0x08, 0xb6, 0x10, 0x54, 0x4f, 0x7c, 0x1b, 0x26, 0xed, 0xda, 0x6b, 0xdd,
+    0x25, 0xd0, 0x4e, 0xea, 0x42, 0xbb, 0x25, 0x03, 0xa2, 0xfb, 0xcc, 0x61,
+    0x67, 0x06, 0x70, 0x1a, 0xc4, 0x78, 0x3a, 0xff, 0x32, 0x62, 0xdd, 0x2c,
+    0xab, 0x50, 0x19, 0x3b, 0xf2, 0x9b, 0x7d, 0xb8, 0xfd, 0x4f, 0x29, 0x9c,
+    0xa7, 0x91, 0xba, 0x0e, 0x46, 0x5e, 0x51, 0xfe, 0x1d, 0xbf, 0xe5, 0xe5,
+    0x9b, 0x95, 0x0d, 0x67, 0xf8, 0xd1, 0xb5, 0x5a, 0xa1, 0x93, 0x2c, 0xc3,
+    0xde, 0x0e, 0x97, 0x85, 0x2d, 0x7f, 0xea, 0xab, 0x3e, 0x47, 0x30, 0x18,
+    0x24, 0xe8, 0xb7, 0x60, 0xae, 0x47, 0x80, 0xfc, 0xe5, 0x23, 0xe7, 0xc2,
+    0xc9, 0x85, 0xe6, 0x98, 0xa0, 0x29, 0x4e, 0xe1, 0x84, 0x39, 0x2d, 0x95,
+    0x2c, 0xf3, 0x45, 0x3c, 0xff, 0xaf, 0x27, 0x4c, 0x6b, 0xa6, 0xf5, 0x4b,
+    0x11, 0xbd, 0xba, 0x5b, 0x9e, 0xc4, 0xa4, 0x51, 0x1e, 0xbe, 0xd0, 0x90,
+    0x3a, 0x9c, 0xc2, 0x26, 0xb6, 0x1e, 0xf1, 0x95, 0x7d, 0xc8, 0x6d, 0x52,
+    0xe6, 0x99, 0x2c, 0x5f, 0x9a, 0x96, 0x0c, 0x68, 0x29, 0xfd, 0xe2, 0xfb,
+    0xe6, 0xbc, 0xec, 0x31, 0x08, 0xec, 0xe6, 0xb0, 0x53, 0x60, 0xc3, 0x8c,
+    0xbe, 0xc1, 0xb3, 0x8a, 0x8f, 0xe4, 0x88, 0x2b, 0x55, 0xe5, 0x64, 0x6e,
+    0x9b, 0xd0, 0xaf, 0x7b, 0x64, 0x2a, 0x35, 0x25, 0x10, 0x52, 0xc5, 0x9e,
+    0x58, 0x11, 0x39, 0x36, 0x45, 0x51, 0xb8, 0x39, 0x93, 0xfc, 0x9d, 0x6a,
+    0xbe, 0x58, 0xcb, 0xa4, 0x0f, 0x51, 0x3c, 0x38, 0x05, 0xca, 0xab, 0x43,
+    0x63, 0x0e, 0xf3, 0x8b, 0x41, 0xa6, 0xf8, 0x9b, 0x53, 0x70, 0x80, 0x53,
+    0x86, 0x5e, 0x8f, 0xe3, 0xc3, 0x0d, 0x18, 0xc8, 0x4b, 0x34, 0x1f, 0xd8,
+    0x1d, 0xbc, 0xf2, 0x6d, 0x34, 0x3a, 0xbe, 0xdf, 0xd9, 0xf6, 0xf3, 0x89,
+    0xa1, 0xe1, 0x94, 0x9f, 0x5d, 0x4c, 0x5d, 0xe9, 0xa1, 0x49, 0x92, 0xef,
+    0x0e, 0x53, 0x81, 0x89, 0x58, 0x87, 0xa6, 0x37, 0xf1, 0xdd, 0x62, 0x60,
+    0x63, 0x5a, 0x9d, 0x1b, 0x8c, 0xc6, 0x7d, 0x52, 0xea, 0x70, 0x09, 0x6a,
+    0xe1, 0x32, 0xf3, 0x73, 0x21, 0x1f, 0x07, 0x7b, 0x7c, 0x9b, 0x49, 0xd8,
+    0xc0, 0xf3, 0x25, 0x72, 0x6f, 0x9d, 0xed, 0x31, 0x67, 0x36, 0x36, 0x54,
+    0x40, 0x92, 0x71, 0xe6, 0x11, 0x28, 0x11, 0xad, 0x93, 0x32, 0x85, 0x7b,
+    0x3e, 0xb7, 0x3b, 0x49, 0x13, 0x1c, 0x07, 0xb0, 0x2e, 0x93, 0xaa, 0xfd,
+    0xfd, 0x28, 0x47, 0x3d, 0x8d, 0xd2, 0xda, 0xc7, 0x44, 0xd6, 0x7a, 0xdb,
+    0x26, 0x7d, 0x1d, 0xb8, 0xe1, 0xde, 0x9d, 0x7a, 0x7d, 0x17, 0x7e, 0x1c,
+    0x37, 0x04, 0x8d, 0x2d, 0x7c, 0x5e, 0x18, 0x38, 0x1e, 0xaf, 0xc7, 0x1b,
+    0x33, 0x48, 0x31, 0x00, 0x59, 0xf6, 0xf2, 0xca, 0x0f, 0x27, 0x1b, 0x63,
+    0x12, 0x7e, 0x02, 0x1d, 0x49, 0xc0, 0x5d, 0x79, 0x87, 0xef, 0x5e, 0x7a,
+    0x2f, 0x1f, 0x66, 0x55, 0xd8, 0x09, 0xd9, 0x61, 0x38, 0x68, 0xb0, 0x07,
+    0xa3, 0xfc, 0xcc, 0x85, 0x10, 0x7f, 0x4c, 0x65, 0x65, 0xb3, 0xfa, 0xfa,
+    0xa5, 0x53, 0x6f, 0xdb, 0x74, 0x4c, 0x56, 0x46, 0x03, 0xe2, 0xd5, 0x7a,
+    0x29, 0x1c, 0xc6, 0x02, 0xbc, 0x59, 0xf2, 0x04, 0x75, 0x63, 0xc0, 0x84,
+    0x2f, 0x60, 0x1c, 0x67, 0x76, 0xfd, 0x63, 0x86, 0xf3, 0xfa, 0xbf, 0xdc,
+    0xd2, 0x2d, 0x90, 0x91, 0xbd, 0x33, 0xa9, 0xe5, 0x66, 0x0c, 0xda, 0x42,
+    0x27, 0xca, 0xf4, 0x66, 0xc2, 0xec, 0x92, 0x14, 0x57, 0x06, 0x63, 0xd0,
+    0x4d, 0x15, 0x06, 0xeb, 0x69, 0x58, 0x4f, 0x77, 0xc5, 0x8b, 0xc7, 0xf0,
+    0x8e, 0xed, 0x64, 0xa0, 0xb3, 0x3c, 0x66, 0x71, 0xc6, 0x2d, 0xda, 0x0a,
+    0x0d, 0xfe, 0x70, 0x27, 0x64, 0xf8, 0x27, 0xfa, 0xf6, 0x5f, 0x30, 0xa5,
+    0x0d, 0x6c, 0xda, 0xf2, 0x62, 0x5e, 0x78, 0x47, 0xd3, 0x66, 0x00, 0x1c,
+    0xfd, 0x56, 0x1f, 0x5d, 0x3f, 0x6f, 0xf4, 0x4c, 0xd8, 0xfd, 0x0e, 0x27,
+    0xc9, 0x5c, 0x2b, 0xbc, 0xc0, 0xa4, 0xe7, 0x23, 0x29, 0x02, 0x9f, 0x31,
+    0xd6, 0xe9, 0xd7, 0x96, 0xf4, 0xe0, 0x5e, 0x0b, 0x0e, 0x13, 0xee, 0x3c,
+    0x09, 0xed, 0xf2, 0x3d, 0x76, 0x91, 0xc3, 0xa4, 0x97, 0xae, 0xd4, 0x87,
+    0xd0, 0x5d, 0xf6, 0x18, 0x47, 0x1f, 0x1d, 0x67, 0xf2, 0xcf, 0x63, 0xa0,
+    0x91, 0x27, 0xf8, 0x93, 0x45, 0x75, 0x23, 0x3f, 0xd1, 0xf1, 0xad, 0x23,
+    0xdd, 0x64, 0x93, 0x96, 0x41, 0x70, 0x7f, 0xf7, 0xf5, 0xa9, 0x89, 0xa2,
+    0x34, 0xb0, 0x8d, 0x1b, 0xae, 0x19, 0x15, 0x49, 0x58, 0x23, 0x6d, 0x87,
+    0x15, 0x4f, 0x81, 0x76, 0xfb, 0x23, 0xb5, 0xea, 0xcf, 0xac, 0x54, 0x8d,
+    0x4e, 0x42, 0x2f, 0xeb, 0x0f, 0x63, 0xdb, 0x68, 0x37, 0xa8, 0xcf, 0x8b,
+    0xab, 0xf5, 0xa4, 0x6e, 0x96, 0x2a, 0xb2, 0xd6, 0xbe, 0x9e, 0xbd, 0x0d,
+    0xb4, 0x42, 0xa9, 0xcf, 0x01, 0x83, 0x8a, 0x17, 0x47, 0x76, 0xc4, 0xc6,
+    0x83, 0x04, 0x95, 0x0b, 0xfc, 0x11, 0xc9, 0x62, 0xb8, 0x0c, 0x76, 0x84,
+    0xd9, 0xb9, 0x37, 0xfa, 0xfc, 0x7c, 0xc2, 0x6d, 0x58, 0x3e, 0xb3, 0x04,
+    0xbb, 0x8c, 0x8f, 0x48, 0xbc, 0x91, 0x27, 0xcc, 0xf9, 0xb7, 0x22, 0x19,
+    0x83, 0x2e, 0x09, 0xb5, 0x72, 0xd9, 0x54, 0x1c, 0x4d, 0xa1, 0xea, 0x0b,
+    0xf1, 0xc6, 0x08, 0x72, 0x46, 0x87, 0x7a, 0x6e, 0x80, 0x56, 0x0a, 0x8a,
+    0xc0, 0xdd, 0x11, 0x6b, 0xd6, 0xdd, 0x47, 0xdf, 0x10, 0xd9, 0xd8, 0xea,
+    0x7c, 0xb0, 0x8f, 0x03, 0x00, 0x2e, 0xc1, 0x8f, 0x44, 0xa8, 0xd3, 0x30,
+    0x06, 0x89, 0xa2, 0xf9, 0x34, 0xad, 0xdc, 0x03, 0x85, 0xed, 0x51, 0xa7,
+    0x82, 0x9c, 0xe7, 0x5d, 0x52, 0x93, 0x0c, 0x32, 0x9a, 0x5b, 0xe1, 0xaa,
+    0xca, 0xb8, 0x02, 0x6d, 0x3a, 0xd4, 0xb1, 0x3a, 0xf0, 0x5f, 0xbe, 0xb5,
+    0x0d, 0x10, 0x6b, 0x38, 0x32, 0xac, 0x76, 0x80, 0xbd, 0xca, 0x94, 0x71,
+    0x7a, 0xf2, 0xc9, 0x35, 0x2a, 0xde, 0x9f, 0x42, 0x49, 0x18, 0x01, 0xab,
+    0xbc, 0xef, 0x7c, 0x64, 0x3f, 0x58, 0x3d, 0x92, 0x59, 0xdb, 0x13, 0xdb,
+    0x58, 0x6e, 0x0a, 0xe0, 0xb7, 0x91, 0x4a, 0x08, 0x20, 0xd6, 0x2e, 0x3c,
+    0x45, 0xc9, 0x8b, 0x17, 0x79, 0xe7, 0xc7, 0x90, 0x99, 0x3a, 0x18, 0x25,
+};
+
+void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
+  x25519_ge_scalarmult_small_precomp(h, a, k25519SmallPrecomp);
+}
+
+#else
+
+// k25519Precomp[i][j] = (j+1)*256^i*B
+static const ge_precomp k25519Precomp[32][8] = {
+    {
+        {
+            {{25967493, 19198397, 29566455, 3660896, 54414519, 4014786,
+             27544626, 21800161, 61029707, 2047604}},
+            {{54563134, 934261, 64385954, 3049989, 66381436, 9406985, 12720692,
+             5043384, 19500929, 18085054}},
+            {{58370664, 4489569, 9688441, 18769238, 10184608, 21191052,
+             29287918, 11864899, 42594502, 29115885}},
+        },
+        {
+            {{54292951, 20578084, 45527620, 11784319, 41753206, 30803714,
+             55390960, 29739860, 66750418, 23343128}},
+            {{45405608, 6903824, 27185491, 6451973, 37531140, 24000426,
+             51492312, 11189267, 40279186, 28235350}},
+            {{26966623, 11152617, 32442495, 15396054, 14353839, 20802097,
+             63980037, 24013313, 51636816, 29387734}},
+        },
+        {
+            {{15636272, 23865875, 24204772, 25642034, 616976, 16869170,
+             27787599, 18782243, 28944399, 32004408}},
+            {{16568933, 4717097, 55552716, 32452109, 15682895, 21747389,
+             16354576, 21778470, 7689661, 11199574}},
+            {{30464137, 27578307, 55329429, 17883566, 23220364, 15915852,
+             7512774, 10017326, 49359771, 23634074}},
+        },
+        {
+            {{50071967, 13921891, 10945806, 27521001, 27105051, 17470053,
+             38182653, 15006022, 3284568, 27277892}},
+            {{23599295, 25248385, 55915199, 25867015, 13236773, 10506355,
+             7464579, 9656445, 13059162, 10374397}},
+            {{7798537, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664,
+             29715387, 66467155, 33453106}},
+        },
+        {
+            {{10861363, 11473154, 27284546, 1981175, 37044515, 12577860,
+             32867885, 14515107, 51670560, 10819379}},
+            {{4708026, 6336745, 20377586, 9066809, 55836755, 6594695, 41455196,
+             12483687, 54440373, 5581305}},
+            {{19563141, 16186464, 37722007, 4097518, 10237984, 29206317,
+             28542349, 13850243, 43430843, 17738489}},
+        },
+        {
+            {{51736881, 20691677, 32573249, 4720197, 40672342, 5875510,
+             47920237, 18329612, 57289923, 21468654}},
+            {{58559652, 109982, 15149363, 2178705, 22900618, 4543417, 3044240,
+             17864545, 1762327, 14866737}},
+            {{48909169, 17603008, 56635573, 1707277, 49922944, 3916100,
+             38872452, 3959420, 27914454, 4383652}},
+        },
+        {
+            {{5153727, 9909285, 1723747, 30776558, 30523604, 5516873, 19480852,
+             5230134, 43156425, 18378665}},
+            {{36839857, 30090922, 7665485, 10083793, 28475525, 1649722,
+             20654025, 16520125, 30598449, 7715701}},
+            {{28881826, 14381568, 9657904, 3680757, 46927229, 7843315,
+             35708204, 1370707, 29794553, 32145132}},
+        },
+        {
+            {{14499471, 30824833, 33917750, 29299779, 28494861, 14271267,
+             30290735, 10876454, 33954766, 2381725}},
+            {{59913433, 30899068, 52378708, 462250, 39384538, 3941371,
+             60872247, 3696004, 34808032, 15351954}},
+            {{27431194, 8222322, 16448760, 29646437, 48401861, 11938354,
+             34147463, 30583916, 29551812, 10109425}},
+        },
+    },
+    {
+        {
+            {{53451805, 20399000, 35825113, 11777097, 21447386, 6519384,
+             64730580, 31926875, 10092782, 28790261}},
+            {{27939166, 14210322, 4677035, 16277044, 44144402, 21156292,
+             34600109, 12005537, 49298737, 12803509}},
+            {{17228999, 17892808, 65875336, 300139, 65883994, 21839654,
+             30364212, 24516238, 18016356, 4397660}},
+        },
+        {
+            {{56150021, 25864224, 4776340, 18600194, 27850027, 17952220,
+             40489757, 14544524, 49631360, 982638}},
+            {{29253598, 15796703, 64244882, 23645547, 10057022, 3163536, 7332899,
+             29434304, 46061167, 9934962}},
+            {{5793284, 16271923, 42977250, 23438027, 29188559, 1206517,
+             52360934, 4559894, 36984942, 22656481}},
+        },
+        {
+            {{39464912, 22061425, 16282656, 22517939, 28414020, 18542168,
+             24191033, 4541697, 53770555, 5500567}},
+            {{12650548, 32057319, 9052870, 11355358, 49428827, 25154267,
+             49678271, 12264342, 10874051, 13524335}},
+            {{25556948, 30508442, 714650, 2510400, 23394682, 23139102, 33119037,
+             5080568, 44580805, 5376627}},
+        },
+        {
+            {{41020600, 29543379, 50095164, 30016803, 60382070, 1920896,
+             44787559, 24106988, 4535767, 1569007}},
+            {{64853442, 14606629, 45416424, 25514613, 28430648, 8775819,
+             36614302, 3044289, 31848280, 12543772}},
+            {{45080285, 2943892, 35251351, 6777305, 13784462, 29262229,
+             39731668, 31491700, 7718481, 14474653}},
+        },
+        {
+            {{2385296, 2454213, 44477544, 46602, 62670929, 17874016, 656964,
+             26317767, 24316167, 28300865}},
+            {{13741529, 10911568, 33875447, 24950694, 46931033, 32521134,
+             33040650, 20129900, 46379407, 8321685}},
+            {{21060490, 31341688, 15712756, 29218333, 1639039, 10656336,
+             23845965, 21679594, 57124405, 608371}},
+        },
+        {
+            {{53436132, 18466845, 56219170, 25997372, 61071954, 11305546,
+             1123968, 26773855, 27229398, 23887}},
+            {{43864724, 33260226, 55364135, 14712570, 37643165, 31524814,
+             12797023, 27114124, 65475458, 16678953}},
+            {{37608244, 4770661, 51054477, 14001337, 7830047, 9564805,
+             65600720, 28759386, 49939598, 4904952}},
+        },
+        {
+            {{24059538, 14617003, 19037157, 18514524, 19766092, 18648003,
+             5169210, 16191880, 2128236, 29227599}},
+            {{50127693, 4124965, 58568254, 22900634, 30336521, 19449185,
+             37302527, 916032, 60226322, 30567899}},
+            {{44477957, 12419371, 59974635, 26081060, 50629959, 16739174,
+             285431, 2763829, 15736322, 4143876}},
+        },
+        {
+            {{2379333, 11839345, 62998462, 27565766, 11274297, 794957, 212801,
+             18959769, 23527083, 17096164}},
+            {{33431108, 22423954, 49269897, 17927531, 8909498, 8376530,
+             34483524, 4087880, 51919953, 19138217}},
+            {{1767664, 7197987, 53903638, 31531796, 54017513, 448825, 5799055,
+             4357868, 62334673, 17231393}},
+        },
+    },
+    {
+        {
+            {{6721966, 13833823, 43585476, 32003117, 26354292, 21691111,
+             23365146, 29604700, 7390889, 2759800}},
+            {{4409022, 2052381, 23373853, 10530217, 7676779, 20668478, 21302352,
+             29290375, 1244379, 20634787}},
+            {{62687625, 7169618, 4982368, 30596842, 30256824, 30776892, 14086412,
+             9208236, 15886429, 16489664}},
+        },
+        {
+            {{1996056, 10375649, 14346367, 13311202, 60234729, 17116020,
+             53415665, 398368, 36502409, 32841498}},
+            {{41801399, 9795879, 64331450, 14878808, 33577029, 14780362,
+             13348553, 12076947, 36272402, 5113181}},
+            {{49338080, 11797795, 31950843, 13929123, 41220562, 12288343,
+             36767763, 26218045, 13847710, 5387222}},
+        },
+        {
+            {{48526701, 30138214, 17824842, 31213466, 22744342, 23111821,
+             8763060, 3617786, 47508202, 10370990}},
+            {{20246567, 19185054, 22358228, 33010720, 18507282, 23140436,
+             14554436, 24808340, 32232923, 16763880}},
+            {{9648486, 10094563, 26416693, 14745928, 36734546, 27081810,
+             11094160, 15689506, 3140038, 17044340}},
+        },
+        {
+            {{50948792, 5472694, 31895588, 4744994, 8823515, 10365685,
+             39884064, 9448612, 38334410, 366294}},
+            {{19153450, 11523972, 56012374, 27051289, 42461232, 5420646,
+             28344573, 8041113, 719605, 11671788}},
+            {{8678006, 2694440, 60300850, 2517371, 4964326, 11152271, 51675948,
+             18287915, 27000812, 23358879}},
+        },
+        {
+            {{51950941, 7134311, 8639287, 30739555, 59873175, 10421741, 564065,
+             5336097, 6750977, 19033406}},
+            {{11836410, 29574944, 26297893, 16080799, 23455045, 15735944,
+             1695823, 24735310, 8169719, 16220347}},
+            {{48993007, 8653646, 17578566, 27461813, 59083086, 17541668,
+             55964556, 30926767, 61118155, 19388398}},
+        },
+        {
+            {{43800366, 22586119, 15213227, 23473218, 36255258, 22504427,
+             27884328, 2847284, 2655861, 1738395}},
+            {{39571412, 19301410, 41772562, 25551651, 57738101, 8129820,
+             21651608, 30315096, 48021414, 22549153}},
+            {{1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092,
+             5821408, 10478196, 8544890}},
+        },
+        {
+            {{32173102, 17425121, 24896206, 3921497, 22579056, 30143578,
+             19270448, 12217473, 17789017, 30158437}},
+            {{36555903, 31326030, 51530034, 23407230, 13243888, 517024,
+             15479401, 29701199, 30460519, 1052596}},
+            {{55493970, 13323617, 32618793, 8175907, 51878691, 12596686,
+             27491595, 28942073, 3179267, 24075541}},
+        },
+        {
+            {{31947050, 19187781, 62468280, 18214510, 51982886, 27514722,
+             52352086, 17142691, 19072639, 24043372}},
+            {{11685058, 11822410, 3158003, 19601838, 33402193, 29389366,
+             5977895, 28339415, 473098, 5040608}},
+            {{46817982, 8198641, 39698732, 11602122, 1290375, 30754672,
+             28326861, 1721092, 47550222, 30422825}},
+        },
+    },
+    {
+        {
+            {{7881532, 10687937, 7578723, 7738378, 48157852, 31000479, 21820785,
+             8076149, 39240368, 11538388}},
+            {{47173198, 3899860, 18283497, 26752864, 51380203, 22305220,
+             8754524, 7446702, 61432810, 5797015}},
+            {{55813245, 29760862, 51326753, 25589858, 12708868, 25098233,
+             2014098, 24503858, 64739691, 27677090}},
+        },
+        {
+            {{44636488, 21985690, 39426843, 1146374, 18956691, 16640559,
+             1192730, 29840233, 15123618, 10811505}},
+            {{14352079, 30134717, 48166819, 10822654, 32750596, 4699007, 67038501,
+             15776355, 38222085, 21579878}},
+            {{38867681, 25481956, 62129901, 28239114, 29416930, 1847569,
+             46454691, 17069576, 4714546, 23953777}},
+        },
+        {
+            {{15200332, 8368572, 19679101, 15970074, 35236190, 1959450,
+             24611599, 29010600, 55362987, 12340219}},
+            {{12876937, 23074376, 33134380, 6590940, 60801088, 14872439,
+             9613953, 8241152, 15370987, 9608631}},
+            {{62965568, 21540023, 8446280, 33162829, 4407737, 13629032, 59383996,
+             15866073, 38898243, 24740332}},
+        },
+        {
+            {{26660628, 17876777, 8393733, 358047, 59707573, 992987, 43204631,
+             858696, 20571223, 8420556}},
+            {{14620696, 13067227, 51661590, 8264466, 14106269, 15080814,
+             33531827, 12516406, 45534429, 21077682}},
+            {{236881, 10476226, 57258, 18877408, 6472997, 2466984, 17258519,
+             7256740, 8791136, 15069930}},
+        },
+        {
+            {{1276391, 24182514, 22949634, 17231625, 43615824, 27852245,
+             14711874, 4874229, 36445724, 31223040}},
+            {{5855666, 4990204, 53397016, 7294283, 59304582, 1924646, 65685689,
+             25642053, 34039526, 9234252}},
+            {{20590503, 24535444, 31529743, 26201766, 64402029, 10650547,
+             31559055, 21944845, 18979185, 13396066}},
+        },
+        {
+            {{24474287, 4968103, 22267082, 4407354, 24063882, 25229252,
+             48291976, 13594781, 33514650, 7021958}},
+            {{55541958, 26988926, 45743778, 15928891, 40950559, 4315420,
+             41160136, 29637754, 45628383, 12868081}},
+            {{38473832, 13504660, 19988037, 31421671, 21078224, 6443208,
+             45662757, 2244499, 54653067, 25465048}},
+        },
+        {
+            {{36513336, 13793478, 61256044, 319135, 41385692, 27290532,
+             33086545, 8957937, 51875216, 5540520}},
+            {{55478669, 22050529, 58989363, 25911358, 2620055, 1022908,
+             43398120, 31985447, 50980335, 18591624}},
+            {{23152952, 775386, 27395463, 14006635, 57407746, 4649511, 1689819,
+             892185, 55595587, 18348483}},
+        },
+        {
+            {{9770129, 9586738, 26496094, 4324120, 1556511, 30004408, 27453818,
+             4763127, 47929250, 5867133}},
+            {{34343820, 1927589, 31726409, 28801137, 23962433, 17534932,
+             27846558, 5931263, 37359161, 17445976}},
+            {{27461885, 30576896, 22380809, 1815854, 44075111, 30522493,
+             7283489, 18406359, 47582163, 7734628}},
+        },
+    },
+    {
+        {
+            {{59098600, 23963614, 55988460, 6196037, 29344158, 20123547,
+             7585294, 30377806, 18549496, 15302069}},
+            {{34450527, 27383209, 59436070, 22502750, 6258877, 13504381,
+             10458790, 27135971, 58236621, 8424745}},
+            {{24687186, 8613276, 36441818, 30320886, 1863891, 31723888,
+             19206233, 7134917, 55824382, 32725512}},
+        },
+        {
+            {{11334899, 24336410, 8025292, 12707519, 17523892, 23078361,
+             10243737, 18868971, 62042829, 16498836}},
+            {{8911542, 6887158, 57524604, 26595841, 11145640, 24010752, 17303924,
+             19430194, 6536640, 10543906}},
+            {{38162480, 15479762, 49642029, 568875, 65611181, 11223453,
+             64439674, 16928857, 39873154, 8876770}},
+        },
+        {
+            {{41365946, 20987567, 51458897, 32707824, 34082177, 32758143,
+             33627041, 15824473, 66504438, 24514614}},
+            {{10330056, 70051, 7957388, 24551765, 9764901, 15609756, 27698697,
+             28664395, 1657393, 3084098}},
+            {{10477963, 26084172, 12119565, 20303627, 29016246, 28188843,
+             31280318, 14396151, 36875289, 15272408}},
+        },
+        {
+            {{54820555, 3169462, 28813183, 16658753, 25116432, 27923966,
+             41934906, 20918293, 42094106, 1950503}},
+            {{40928506, 9489186, 11053416, 18808271, 36055143, 5825629,
+             58724558, 24786899, 15341278, 8373727}},
+            {{28685821, 7759505, 52730348, 21551571, 35137043, 4079241,
+             298136, 23321830, 64230656, 15190419}},
+        },
+        {
+            {{34175969, 13806335, 52771379, 17760000, 43104243, 10940927,
+             8669718, 2742393, 41075551, 26679428}},
+            {{65528476, 21825014, 41129205, 22109408, 49696989, 22641577,
+             9291593, 17306653, 54954121, 6048604}},
+            {{36803549, 14843443, 1539301, 11864366, 20201677, 1900163,
+             13934231, 5128323, 11213262, 9168384}},
+        },
+        {
+            {{40828332, 11007846, 19408960, 32613674, 48515898, 29225851,
+             62020803, 22449281, 20470156, 17155731}},
+            {{43972811, 9282191, 14855179, 18164354, 59746048, 19145871,
+             44324911, 14461607, 14042978, 5230683}},
+            {{29969548, 30812838, 50396996, 25001989, 9175485, 31085458,
+             21556950, 3506042, 61174973, 21104723}},
+        },
+        {
+            {{63964118, 8744660, 19704003, 4581278, 46678178, 6830682,
+             45824694, 8971512, 38569675, 15326562}},
+            {{47644235, 10110287, 49846336, 30050539, 43608476, 1355668,
+             51585814, 15300987, 46594746, 9168259}},
+            {{61755510, 4488612, 43305616, 16314346, 7780487, 17915493,
+             38160505, 9601604, 33087103, 24543045}},
+        },
+        {
+            {{47665694, 18041531, 46311396, 21109108, 37284416, 10229460,
+             39664535, 18553900, 61111993, 15664671}},
+            {{23294591, 16921819, 44458082, 25083453, 27844203, 11461195,
+             13099750, 31094076, 18151675, 13417686}},
+            {{42385932, 29377914, 35958184, 5988918, 40250079, 6685064,
+             1661597, 21002991, 15271675, 18101767}},
+        },
+    },
+    {
+        {
+            {{11433023, 20325767, 8239630, 28274915, 65123427, 32828713,
+             48410099, 2167543, 60187563, 20114249}},
+            {{35672693, 15575145, 30436815, 12192228, 44645511, 9395378,
+             57191156, 24915434, 12215109, 12028277}},
+            {{14098381, 6555944, 23007258, 5757252, 51681032, 20603929,
+             30123439, 4617780, 50208775, 32898803}},
+        },
+        {
+            {{63082644, 18313596, 11893167, 13718664, 52299402, 1847384,
+             51288865, 10154008, 23973261, 20869958}},
+            {{40577025, 29858441, 65199965, 2534300, 35238307, 17004076,
+             18341389, 22134481, 32013173, 23450893}},
+            {{41629544, 10876442, 55337778, 18929291, 54739296, 1838103,
+             21911214, 6354752, 4425632, 32716610}},
+        },
+        {
+            {{56675475, 18941465, 22229857, 30463385, 53917697, 776728,
+             49693489, 21533969, 4725004, 14044970}},
+            {{19268631, 26250011, 1555348, 8692754, 45634805, 23643767, 6347389,
+             32142648, 47586572, 17444675}},
+            {{42244775, 12986007, 56209986, 27995847, 55796492, 33405905,
+             19541417, 8180106, 9282262, 10282508}},
+        },
+        {
+            {{40903763, 4428546, 58447668, 20360168, 4098401, 19389175,
+             15522534, 8372215, 5542595, 22851749}},
+            {{56546323, 14895632, 26814552, 16880582, 49628109, 31065071,
+             64326972, 6993760, 49014979, 10114654}},
+            {{47001790, 32625013, 31422703, 10427861, 59998115, 6150668,
+             38017109, 22025285, 25953724, 33448274}},
+        },
+        {
+            {{62874467, 25515139, 57989738, 3045999, 2101609, 20947138,
+             19390019, 6094296, 63793585, 12831124}},
+            {{51110167, 7578151, 5310217, 14408357, 33560244, 33329692,
+             31575953, 6326196, 7381791, 31132593}},
+            {{46206085, 3296810, 24736065, 17226043, 18374253, 7318640,
+             6295303, 8082724, 51746375, 12339663}},
+        },
+        {
+            {{27724736, 2291157, 6088201, 19369634, 1792726, 5857634, 13848414,
+             15768922, 25091167, 14856294}},
+            {{48242193, 8331042, 24373479, 8541013, 66406866, 24284974, 12927299,
+             20858939, 44926390, 24541532}},
+            {{55685435, 28132841, 11632844, 3405020, 30536730, 21880393,
+             39848098, 13866389, 30146206, 9142070}},
+        },
+        {
+            {{3924129, 18246916, 53291741, 23499471, 12291819, 32886066,
+             39406089, 9326383, 58871006, 4171293}},
+            {{51186905, 16037936, 6713787, 16606682, 45496729, 2790943,
+             26396185, 3731949, 345228, 28091483}},
+            {{45781307, 13448258, 25284571, 1143661, 20614966, 24705045,
+             2031538, 21163201, 50855680, 19972348}},
+        },
+        {
+            {{31016192, 16832003, 26371391, 19103199, 62081514, 14854136,
+             17477601, 3842657, 28012650, 17149012}},
+            {{62033029, 9368965, 58546785, 28953529, 51858910, 6970559,
+             57918991, 16292056, 58241707, 3507939}},
+            {{29439664, 3537914, 23333589, 6997794, 49553303, 22536363,
+             51899661, 18503164, 57943934, 6580395}},
+        },
+    },
+    {
+        {
+            {{54923003, 25874643, 16438268, 10826160, 58412047, 27318820,
+             17860443, 24280586, 65013061, 9304566}},
+            {{20714545, 29217521, 29088194, 7406487, 11426967, 28458727,
+             14792666, 18945815, 5289420, 33077305}},
+            {{50443312, 22903641, 60948518, 20248671, 9192019, 31751970,
+             17271489, 12349094, 26939669, 29802138}},
+        },
+        {
+            {{54218966, 9373457, 31595848, 16374215, 21471720, 13221525,
+             39825369, 21205872, 63410057, 117886}},
+            {{22263325, 26994382, 3984569, 22379786, 51994855, 32987646,
+             28311252, 5358056, 43789084, 541963}},
+            {{16259200, 3261970, 2309254, 18019958, 50223152, 28972515,
+             24134069, 16848603, 53771797, 20002236}},
+        },
+        {
+            {{9378160, 20414246, 44262881, 20809167, 28198280, 26310334,
+             64709179, 32837080, 690425, 14876244}},
+            {{24977353, 33240048, 58884894, 20089345, 28432342, 32378079,
+             54040059, 21257083, 44727879, 6618998}},
+            {{65570671, 11685645, 12944378, 13682314, 42719353, 19141238,
+             8044828, 19737104, 32239828, 27901670}},
+        },
+        {
+            {{48505798, 4762989, 66182614, 8885303, 38696384, 30367116, 9781646,
+             23204373, 32779358, 5095274}},
+            {{34100715, 28339925, 34843976, 29869215, 9460460, 24227009,
+             42507207, 14506723, 21639561, 30924196}},
+            {{50707921, 20442216, 25239337, 15531969, 3987758, 29055114,
+             65819361, 26690896, 17874573, 558605}},
+        },
+        {
+            {{53508735, 10240080, 9171883, 16131053, 46239610, 9599699,
+             33499487, 5080151, 2085892, 5119761}},
+            {{44903700, 31034903, 50727262, 414690, 42089314, 2170429,
+             30634760, 25190818, 35108870, 27794547}},
+            {{60263160, 15791201, 8550074, 32241778, 29928808, 21462176,
+             27534429, 26362287, 44757485, 12961481}},
+        },
+        {
+            {{42616785, 23983660, 10368193, 11582341, 43711571, 31309144,
+             16533929, 8206996, 36914212, 28394793}},
+            {{55987368, 30172197, 2307365, 6362031, 66973409, 8868176, 50273234,
+             7031274, 7589640, 8945490}},
+            {{34956097, 8917966, 6661220, 21876816, 65916803, 17761038,
+             7251488, 22372252, 24099108, 19098262}},
+        },
+        {
+            {{5019539, 25646962, 4244126, 18840076, 40175591, 6453164,
+             47990682, 20265406, 60876967, 23273695}},
+            {{10853575, 10721687, 26480089, 5861829, 44113045, 1972174,
+             65242217, 22996533, 63745412, 27113307}},
+            {{50106456, 5906789, 221599, 26991285, 7828207, 20305514, 24362660,
+             31546264, 53242455, 7421391}},
+        },
+        {
+            {{8139908, 27007935, 32257645, 27663886, 30375718, 1886181,
+             45933756, 15441251, 28826358, 29431403}},
+            {{6267067, 9695052, 7709135, 16950835, 34239795, 31668296,
+             14795159, 25714308, 13746020, 31812384}},
+            {{28584883, 7787108, 60375922, 18503702, 22846040, 25983196,
+             63926927, 33190907, 4771361, 25134474}},
+        },
+    },
+    {
+        {
+            {{24949256, 6376279, 39642383, 25379823, 48462709, 23623825,
+             33543568, 21412737, 3569626, 11342593}},
+            {{26514970, 4740088, 27912651, 3697550, 19331575, 22082093, 6809885,
+             4608608, 7325975, 18753361}},
+            {{55490446, 19000001, 42787651, 7655127, 65739590, 5214311,
+             39708324, 10258389, 49462170, 25367739}},
+        },
+        {
+            {{11431185, 15823007, 26570245, 14329124, 18029990, 4796082,
+             35662685, 15580663, 9280358, 29580745}},
+            {{66948081, 23228174, 44253547, 29249434, 46247496, 19933429,
+             34297962, 22372809, 51563772, 4387440}},
+            {{46309467, 12194511, 3937617, 27748540, 39954043, 9340369,
+             42594872, 8548136, 20617071, 26072431}},
+        },
+        {
+            {{66170039, 29623845, 58394552, 16124717, 24603125, 27329039,
+             53333511, 21678609, 24345682, 10325460}},
+            {{47253587, 31985546, 44906155, 8714033, 14007766, 6928528,
+             16318175, 32543743, 4766742, 3552007}},
+            {{45357481, 16823515, 1351762, 32751011, 63099193, 3950934, 3217514,
+             14481909, 10988822, 29559670}},
+        },
+        {
+            {{15564307, 19242862, 3101242, 5684148, 30446780, 25503076,
+             12677126, 27049089, 58813011, 13296004}},
+            {{57666574, 6624295, 36809900, 21640754, 62437882, 31497052,
+             31521203, 9614054, 37108040, 12074673}},
+            {{4771172, 33419193, 14290748, 20464580, 27992297, 14998318,
+             65694928, 31997715, 29832612, 17163397}},
+        },
+        {
+            {{7064884, 26013258, 47946901, 28486894, 48217594, 30641695,
+             25825241, 5293297, 39986204, 13101589}},
+            {{64810282, 2439669, 59642254, 1719964, 39841323, 17225986,
+             32512468, 28236839, 36752793, 29363474}},
+            {{37102324, 10162315, 33928688, 3981722, 50626726, 20484387,
+             14413973, 9515896, 19568978, 9628812}},
+        },
+        {
+            {{33053803, 199357, 15894591, 1583059, 27380243, 28973997, 49269969,
+             27447592, 60817077, 3437739}},
+            {{48129987, 3884492, 19469877, 12726490, 15913552, 13614290,
+             44147131, 70103, 7463304, 4176122}},
+            {{39984863, 10659916, 11482427, 17484051, 12771466, 26919315,
+             34389459, 28231680, 24216881, 5944158}},
+        },
+        {
+            {{8894125, 7450974, 64444715, 23788679, 39028346, 21165316,
+             19345745, 14680796, 11632993, 5847885}},
+            {{26942781, 31239115, 9129563, 28647825, 26024104, 11769399,
+             55590027, 6367193, 57381634, 4782139}},
+            {{19916442, 28726022, 44198159, 22140040, 25606323, 27581991,
+             33253852, 8220911, 6358847, 31680575}},
+        },
+        {
+            {{801428, 31472730, 16569427, 11065167, 29875704, 96627, 7908388,
+             29073952, 53570360, 1387154}},
+            {{19646058, 5720633, 55692158, 12814208, 11607948, 12749789,
+             14147075, 15156355, 45242033, 11835259}},
+            {{19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523,
+             15467869, 40548314, 5052482}},
+        },
+    },
+    {
+        {
+            {{64091413, 10058205, 1980837, 3964243, 22160966, 12322533, 60677741,
+             20936246, 12228556, 26550755}},
+            {{32944382, 14922211, 44263970, 5188527, 21913450, 24834489,
+             4001464, 13238564, 60994061, 8653814}},
+            {{22865569, 28901697, 27603667, 21009037, 14348957, 8234005,
+             24808405, 5719875, 28483275, 2841751}},
+        },
+        {
+            {{50687877, 32441126, 66781144, 21446575, 21886281, 18001658,
+             65220897, 33238773, 19932057, 20815229}},
+            {{55452759, 10087520, 58243976, 28018288, 47830290, 30498519,
+             3999227, 13239134, 62331395, 19644223}},
+            {{1382174, 21859713, 17266789, 9194690, 53784508, 9720080,
+             20403944, 11284705, 53095046, 3093229}},
+        },
+        {
+            {{16650902, 22516500, 66044685, 1570628, 58779118, 7352752, 66806440,
+             16271224, 43059443, 26862581}},
+            {{45197768, 27626490, 62497547, 27994275, 35364760, 22769138,
+             24123613, 15193618, 45456747, 16815042}},
+            {{57172930, 29264984, 41829040, 4372841, 2087473, 10399484,
+             31870908, 14690798, 17361620, 11864968}},
+        },
+        {
+            {{55801235, 6210371, 13206574, 5806320, 38091172, 19587231,
+             54777658, 26067830, 41530403, 17313742}},
+            {{14668443, 21284197, 26039038, 15305210, 25515617, 4542480,
+             10453892, 6577524, 9145645, 27110552}},
+            {{5974855, 3053895, 57675815, 23169240, 35243739, 3225008,
+             59136222, 3936127, 61456591, 30504127}},
+        },
+        {
+            {{30625386, 28825032, 41552902, 20761565, 46624288, 7695098,
+             17097188, 17250936, 39109084, 1803631}},
+            {{63555773, 9865098, 61880298, 4272700, 61435032, 16864731,
+             14911343, 12196514, 45703375, 7047411}},
+            {{20093258, 9920966, 55970670, 28210574, 13161586, 12044805,
+             34252013, 4124600, 34765036, 23296865}},
+        },
+        {
+            {{46320040, 14084653, 53577151, 7842146, 19119038, 19731827,
+             4752376, 24839792, 45429205, 2288037}},
+            {{40289628, 30270716, 29965058, 3039786, 52635099, 2540456,
+             29457502, 14625692, 42289247, 12570231}},
+            {{66045306, 22002608, 16920317, 12494842, 1278292, 27685323,
+             45948920, 30055751, 55134159, 4724942}},
+        },
+        {
+            {{17960970, 21778898, 62967895, 23851901, 58232301, 32143814,
+             54201480, 24894499, 37532563, 1903855}},
+            {{23134274, 19275300, 56426866, 31942495, 20684484, 15770816,
+             54119114, 3190295, 26955097, 14109738}},
+            {{15308788, 5320727, 36995055, 19235554, 22902007, 7767164,
+             29425325, 22276870, 31960941, 11934971}},
+        },
+        {
+            {{39713153, 8435795, 4109644, 12222639, 42480996, 14818668,
+             20638173, 4875028, 10491392, 1379718}},
+            {{53949449, 9197840, 3875503, 24618324, 65725151, 27674630,
+             33518458, 16176658, 21432314, 12180697}},
+            {{55321537, 11500837, 13787581, 19721842, 44678184, 10140204,
+             1465425, 12689540, 56807545, 19681548}},
+        },
+    },
+    {
+        {
+            {{5414091, 18168391, 46101199, 9643569, 12834970, 1186149,
+             64485948, 32212200, 26128230, 6032912}},
+            {{40771450, 19788269, 32496024, 19900513, 17847800, 20885276,
+             3604024, 8316894, 41233830, 23117073}},
+            {{3296484, 6223048, 24680646, 21307972, 44056843, 5903204,
+             58246567, 28915267, 12376616, 3188849}},
+        },
+        {
+            {{29190469, 18895386, 27549112, 32370916, 3520065, 22857131,
+             32049514, 26245319, 50999629, 23702124}},
+            {{52364359, 24245275, 735817, 32955454, 46701176, 28496527,
+             25246077, 17758763, 18640740, 32593455}},
+            {{60180029, 17123636, 10361373, 5642961, 4910474, 12345252,
+             35470478, 33060001, 10530746, 1053335}},
+        },
+        {
+            {{37842897, 19367626, 53570647, 21437058, 47651804, 22899047,
+             35646494, 30605446, 24018830, 15026644}},
+            {{44516310, 30409154, 64819587, 5953842, 53668675, 9425630,
+             25310643, 13003497, 64794073, 18408815}},
+            {{39688860, 32951110, 59064879, 31885314, 41016598, 13987818,
+             39811242, 187898, 43942445, 31022696}},
+        },
+        {
+            {{45364466, 19743956, 1844839, 5021428, 56674465, 17642958,
+             9716666, 16266922, 62038647, 726098}},
+            {{29370903, 27500434, 7334070, 18212173, 9385286, 2247707,
+             53446902, 28714970, 30007387, 17731091}},
+            {{66172485, 16086690, 23751945, 33011114, 65941325, 28365395, 9137108,
+             730663, 9835848, 4555336}},
+        },
+        {
+            {{43732429, 1410445, 44855111, 20654817, 30867634, 15826977,
+             17693930, 544696, 55123566, 12422645}},
+            {{31117226, 21338698, 53606025, 6561946, 57231997, 20796761,
+             61990178, 29457725, 29120152, 13924425}},
+            {{49707966, 19321222, 19675798, 30819676, 56101901, 27695611,
+             57724924, 22236731, 7240930, 33317044}},
+        },
+        {
+            {{35747106, 22207651, 52101416, 27698213, 44655523, 21401660,
+             1222335, 4389483, 3293637, 18002689}},
+            {{50424044, 19110186, 11038543, 11054958, 53307689, 30215898,
+             42789283, 7733546, 12796905, 27218610}},
+            {{58349431, 22736595, 41689999, 10783768, 36493307, 23807620,
+             38855524, 3647835, 3222231, 22393970}},
+        },
+        {
+            {{18606113, 1693100, 41660478, 18384159, 4112352, 10045021,
+             23603893, 31506198, 59558087, 2484984}},
+            {{9255298, 30423235, 54952701, 32550175, 13098012, 24339566,
+             16377219, 31451620, 47306788, 30519729}},
+            {{44379556, 7496159, 61366665, 11329248, 19991973, 30206930,
+             35390715, 9936965, 37011176, 22935634}},
+        },
+        {
+            {{21878571, 28553135, 4338335, 13643897, 64071999, 13160959,
+             19708896, 5415497, 59748361, 29445138}},
+            {{27736842, 10103576, 12500508, 8502413, 63695848, 23920873,
+             10436917, 32004156, 43449720, 25422331}},
+            {{19492550, 21450067, 37426887, 32701801, 63900692, 12403436,
+             30066266, 8367329, 13243957, 8709688}},
+        },
+    },
+    {
+        {
+            {{12015105, 2801261, 28198131, 10151021, 24818120, 28811299,
+             55914672, 27908697, 5150967, 7274186}},
+            {{2831347, 21062286, 1478974, 6122054, 23825128, 20820846,
+             31097298, 6083058, 31021603, 23760822}},
+            {{64578913, 31324785, 445612, 10720828, 53259337, 22048494,
+             43601132, 16354464, 15067285, 19406725}},
+        },
+        {
+            {{7840923, 14037873, 33744001, 15934015, 66380651, 29911725,
+             21403987, 1057586, 47729402, 21151211}},
+            {{915865, 17085158, 15608284, 24765302, 42751837, 6060029,
+             49737545, 8410996, 59888403, 16527024}},
+            {{32922597, 32997445, 20336073, 17369864, 10903704, 28169945,
+             16957573, 52992, 23834301, 6588044}},
+        },
+        {
+            {{32752011, 11232950, 3381995, 24839566, 22652987, 22810329,
+             17159698, 16689107, 46794284, 32248439}},
+            {{62419196, 9166775, 41398568, 22707125, 11576751, 12733943,
+             7924251, 30802151, 1976122, 26305405}},
+            {{21251203, 16309901, 64125849, 26771309, 30810596, 12967303, 156041,
+             30183180, 12331344, 25317235}},
+        },
+        {
+            {{8651595, 29077400, 51023227, 28557437, 13002506, 2950805,
+             29054427, 28447462, 10008135, 28886531}},
+            {{31486061, 15114593, 52847614, 12951353, 14369431, 26166587,
+             16347320, 19892343, 8684154, 23021480}},
+            {{19443825, 11385320, 24468943, 23895364, 43189605, 2187568,
+             40845657, 27467510, 31316347, 14219878}},
+        },
+        {
+            {{38514374, 1193784, 32245219, 11392485, 31092169, 15722801,
+             27146014, 6992409, 29126555, 9207390}},
+            {{32382916, 1110093, 18477781, 11028262, 39697101, 26006320,
+             62128346, 10843781, 59151264, 19118701}},
+            {{2814918, 7836403, 27519878, 25686276, 46214848, 22000742,
+             45614304, 8550129, 28346258, 1994730}},
+        },
+        {
+            {{47530565, 8085544, 53108345, 29605809, 2785837, 17323125,
+             47591912, 7174893, 22628102, 8115180}},
+            {{36703732, 955510, 55975026, 18476362, 34661776, 20276352,
+             41457285, 3317159, 57165847, 930271}},
+            {{51805164, 26720662, 28856489, 1357446, 23421993, 1057177,
+             24091212, 32165462, 44343487, 22903716}},
+        },
+        {
+            {{44357633, 28250434, 54201256, 20785565, 51297352, 25757378,
+             52269845, 17000211, 65241845, 8398969}},
+            {{35139535, 2106402, 62372504, 1362500, 12813763, 16200670,
+             22981545, 27263159, 18009407, 17781660}},
+            {{49887941, 24009210, 39324209, 14166834, 29815394, 7444469,
+             29551787, 29827013, 19288548, 1325865}},
+        },
+        {
+            {{15100138, 17718680, 43184885, 32549333, 40658671, 15509407,
+             12376730, 30075286, 33166106, 25511682}},
+            {{20909212, 13023121, 57899112, 16251777, 61330449, 25459517,
+             12412150, 10018715, 2213263, 19676059}},
+            {{32529814, 22479743, 30361438, 16864679, 57972923, 1513225,
+             22922121, 6382134, 61341936, 8371347}},
+        },
+    },
+    {
+        {
+            {{9923462, 11271500, 12616794, 3544722, 37110496, 31832805,
+             12891686, 25361300, 40665920, 10486143}},
+            {{44511638, 26541766, 8587002, 25296571, 4084308, 20584370, 361725,
+             2610596, 43187334, 22099236}},
+            {{5408392, 32417741, 62139741, 10561667, 24145918, 14240566,
+             31319731, 29318891, 19985174, 30118346}},
+        },
+        {
+            {{53114407, 16616820, 14549246, 3341099, 32155958, 13648976,
+             49531796, 8849296, 65030, 8370684}},
+            {{58787919, 21504805, 31204562, 5839400, 46481576, 32497154,
+             47665921, 6922163, 12743482, 23753914}},
+            {{64747493, 12678784, 28815050, 4759974, 43215817, 4884716,
+             23783145, 11038569, 18800704, 255233}},
+        },
+        {
+            {{61839187, 31780545, 13957885, 7990715, 23132995, 728773, 13393847,
+             9066957, 19258688, 18800639}},
+            {{64172210, 22726896, 56676774, 14516792, 63468078, 4372540,
+             35173943, 2209389, 65584811, 2055793}},
+            {{580882, 16705327, 5468415, 30871414, 36182444, 18858431,
+             59905517, 24560042, 37087844, 7394434}},
+        },
+        {
+            {{23838809, 1822728, 51370421, 15242726, 8318092, 29821328,
+             45436683, 30062226, 62287122, 14799920}},
+            {{13345610, 9759151, 3371034, 17416641, 16353038, 8577942, 31129804,
+             13496856, 58052846, 7402517}},
+            {{2286874, 29118501, 47066405, 31546095, 53412636, 5038121,
+             11006906, 17794080, 8205060, 1607563}},
+        },
+        {
+            {{14414067, 25552300, 3331829, 30346215, 22249150, 27960244,
+             18364660, 30647474, 30019586, 24525154}},
+            {{39420813, 1585952, 56333811, 931068, 37988643, 22552112,
+             52698034, 12029092, 9944378, 8024}},
+            {{4368715, 29844802, 29874199, 18531449, 46878477, 22143727,
+             50994269, 32555346, 58966475, 5640029}},
+        },
+        {
+            {{10299591, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887,
+             16859868, 15219797, 19226649}},
+            {{27425505, 27835351, 3055005, 10660664, 23458024, 595578, 51710259,
+             32381236, 48766680, 9742716}},
+            {{6744077, 2427284, 26042789, 2720740, 66260958, 1118973, 32324614,
+             7406442, 12420155, 1994844}},
+        },
+        {
+            {{14012502, 28529712, 48724410, 23975962, 40623521, 29617992,
+             54075385, 22644628, 24319928, 27108099}},
+            {{16412671, 29047065, 10772640, 15929391, 50040076, 28895810,
+             10555944, 23070383, 37006495, 28815383}},
+            {{22397363, 25786748, 57815702, 20761563, 17166286, 23799296,
+             39775798, 6199365, 21880021, 21303672}},
+        },
+        {
+            {{62825557, 5368522, 35991846, 8163388, 36785801, 3209127,
+             16557151, 8890729, 8840445, 4957760}},
+            {{51661137, 709326, 60189418, 22684253, 37330941, 6522331,
+             45388683, 12130071, 52312361, 5005756}},
+            {{64994094, 19246303, 23019041, 15765735, 41839181, 6002751,
+             10183197, 20315106, 50713577, 31378319}},
+        },
+    },
+    {
+        {
+            {{48083108, 1632004, 13466291, 25559332, 43468412, 16573536,
+             35094956, 30497327, 22208661, 2000468}},
+            {{3065054, 32141671, 41510189, 33192999, 49425798, 27851016,
+             58944651, 11248526, 63417650, 26140247}},
+            {{10379208, 27508878, 8877318, 1473647, 37817580, 21046851,
+             16690914, 2553332, 63976176, 16400288}},
+        },
+        {
+            {{15716668, 1254266, 48636174, 7446273, 58659946, 6344163,
+             45011593, 26268851, 26894936, 9132066}},
+            {{24158868, 12938817, 11085297, 25376834, 39045385, 29097348,
+             36532400, 64451, 60291780, 30861549}},
+            {{13488534, 7794716, 22236231, 5989356, 25426474, 20976224, 2350709,
+             30135921, 62420857, 2364225}},
+        },
+        {
+            {{16335033, 9132434, 25640582, 6678888, 1725628, 8517937, 55301840,
+             21856974, 15445874, 25756331}},
+            {{29004188, 25687351, 28661401, 32914020, 54314860, 25611345,
+             31863254, 29418892, 66830813, 17795152}},
+            {{60986784, 18687766, 38493958, 14569918, 56250865, 29962602,
+             10343411, 26578142, 37280576, 22738620}},
+        },
+        {
+            {{27081650, 3463984, 14099042, 29036828, 1616302, 27348828, 29542635,
+             15372179, 17293797, 960709}},
+            {{20263915, 11434237, 61343429, 11236809, 13505955, 22697330,
+             50997518, 6493121, 47724353, 7639713}},
+            {{64278047, 18715199, 25403037, 25339236, 58791851, 17380732,
+             18006286, 17510682, 29994676, 17746311}},
+        },
+        {
+            {{9769828, 5202651, 42951466, 19923039, 39057860, 21992807,
+             42495722, 19693649, 35924288, 709463}},
+            {{12286395, 13076066, 45333675, 32377809, 42105665, 4057651,
+             35090736, 24663557, 16102006, 13205847}},
+            {{13733362, 5599946, 10557076, 3195751, 61550873, 8536969, 41568694,
+             8525971, 10151379, 10394400}},
+        },
+        {
+            {{4024660, 17416881, 22436261, 12276534, 58009849, 30868332,
+             19698228, 11743039, 33806530, 8934413}},
+            {{51229064, 29029191, 58528116, 30620370, 14634844, 32856154,
+             57659786, 3137093, 55571978, 11721157}},
+            {{17555920, 28540494, 8268605, 2331751, 44370049, 9761012, 9319229,
+             8835153, 57903375, 32274386}},
+        },
+        {
+            {{66647436, 25724417, 20614117, 16688288, 59594098, 28747312,
+             22300303, 505429, 6108462, 27371017}},
+            {{62038564, 12367916, 36445330, 3234472, 32617080, 25131790,
+             29880582, 20071101, 40210373, 25686972}},
+            {{35133562, 5726538, 26934134, 10237677, 63935147, 32949378,
+             24199303, 3795095, 7592688, 18562353}},
+        },
+        {
+            {{21594432, 18590204, 17466407, 29477210, 32537083, 2739898,
+             6407723, 12018833, 38852812, 4298411}},
+            {{46458361, 21592935, 39872588, 570497, 3767144, 31836892,
+             13891941, 31985238, 13717173, 10805743}},
+            {{52432215, 17910135, 15287173, 11927123, 24177847, 25378864,
+             66312432, 14860608, 40169934, 27690595}},
+        },
+    },
+    {
+        {
+            {{12962541, 5311799, 57048096, 11658279, 18855286, 25600231,
+             13286262, 20745728, 62727807, 9882021}},
+            {{18512060, 11319350, 46985740, 15090308, 18818594, 5271736,
+             44380960, 3666878, 43141434, 30255002}},
+            {{60319844, 30408388, 16192428, 13241070, 15898607, 19348318,
+             57023983, 26893321, 64705764, 5276064}},
+        },
+        {
+            {{30169808, 28236784, 26306205, 21803573, 27814963, 7069267,
+             7152851, 3684982, 1449224, 13082861}},
+            {{10342807, 3098505, 2119311, 193222, 25702612, 12233820, 23697382,
+             15056736, 46092426, 25352431}},
+            {{33958735, 3261607, 22745853, 7948688, 19370557, 18376767,
+             40936887, 6482813, 56808784, 22494330}},
+        },
+        {
+            {{32869458, 28145887, 25609742, 15678670, 56421095, 18083360,
+             26112420, 2521008, 44444576, 6904814}},
+            {{29506904, 4457497, 3377935, 23757988, 36598817, 12935079, 1561737,
+             3841096, 38105225, 26896789}},
+            {{10340844, 26924055, 48452231, 31276001, 12621150, 20215377,
+             30878496, 21730062, 41524312, 5181965}},
+        },
+        {
+            {{25940096, 20896407, 17324187, 23247058, 58437395, 15029093,
+             24396252, 17103510, 64786011, 21165857}},
+            {{45343161, 9916822, 65808455, 4079497, 66080518, 11909558, 1782390,
+             12641087, 20603771, 26992690}},
+            {{48226577, 21881051, 24849421, 11501709, 13161720, 28785558,
+             1925522, 11914390, 4662781, 7820689}},
+        },
+        {
+            {{12241050, 33128450, 8132690, 9393934, 32846760, 31954812, 29749455,
+             12172924, 16136752, 15264020}},
+            {{56758909, 18873868, 58896884, 2330219, 49446315, 19008651,
+             10658212, 6671822, 19012087, 3772772}},
+            {{3753511, 30133366, 10617073, 2028709, 14841030, 26832768, 28718731,
+             17791548, 20527770, 12988982}},
+        },
+        {
+            {{52286360, 27757162, 63400876, 12689772, 66209881, 22639565,
+             42925817, 22989488, 3299664, 21129479}},
+            {{50331161, 18301130, 57466446, 4978982, 3308785, 8755439, 6943197,
+             6461331, 41525717, 8991217}},
+            {{49882601, 1816361, 65435576, 27467992, 31783887, 25378441,
+             34160718, 7417949, 36866577, 1507264}},
+        },
+        {
+            {{29692644, 6829891, 56610064, 4334895, 20945975, 21647936,
+             38221255, 8209390, 14606362, 22907359}},
+            {{63627275, 8707080, 32188102, 5672294, 22096700, 1711240, 34088169,
+             9761486, 4170404, 31469107}},
+            {{55521375, 14855944, 62981086, 32022574, 40459774, 15084045,
+             22186522, 16002000, 52832027, 25153633}},
+        },
+        {
+            {{62297408, 13761028, 35404987, 31070512, 63796392, 7869046,
+             59995292, 23934339, 13240844, 10965870}},
+            {{59366301, 25297669, 52340529, 19898171, 43876480, 12387165,
+             4498947, 14147411, 29514390, 4302863}},
+            {{53695440, 21146572, 20757301, 19752600, 14785142, 8976368,
+             62047588, 31410058, 17846987, 19582505}},
+        },
+    },
+    {
+        {
+            {{64864412, 32799703, 62511833, 32488122, 60861691, 1455298,
+             45461136, 24339642, 61886162, 12650266}},
+            {{57202067, 17484121, 21134159, 12198166, 40044289, 708125, 387813,
+             13770293, 47974538, 10958662}},
+            {{22470984, 12369526, 23446014, 28113323, 45588061, 23855708,
+             55336367, 21979976, 42025033, 4271861}},
+        },
+        {
+            {{41939299, 23500789, 47199531, 15361594, 61124506, 2159191,
+             75375, 29275903, 34582642, 8469672}},
+            {{15854951, 4148314, 58214974, 7259001, 11666551, 13824734,
+             36577666, 2697371, 24154791, 24093489}},
+            {{15446137, 17747788, 29759746, 14019369, 30811221, 23944241,
+             35526855, 12840103, 24913809, 9815020}},
+        },
+        {
+            {{62399578, 27940162, 35267365, 21265538, 52665326, 10799413,
+             58005188, 13438768, 18735128, 9466238}},
+            {{11933045, 9281483, 5081055, 28370608, 64480701, 28648802, 59381042,
+             22658328, 44380208, 16199063}},
+            {{14576810, 379472, 40322331, 25237195, 37682355, 22741457,
+             67006097, 1876698, 30801119, 2164795}},
+        },
+        {
+            {{15995086, 3199873, 13672555, 13712240, 47730029, 28906785,
+             54027253, 18058162, 53616056, 1268051}},
+            {{56818250, 29895392, 63822271, 10948817, 23037027, 3794475,
+             63638526, 20954210, 50053494, 3565903}},
+            {{29210069, 24135095, 61189071, 28601646, 10834810, 20226706,
+             50596761, 22733718, 39946641, 19523900}},
+        },
+        {
+            {{53946955, 15508587, 16663704, 25398282, 38758921, 9019122,
+             37925443, 29785008, 2244110, 19552453}},
+            {{61955989, 29753495, 57802388, 27482848, 16243068, 14684434,
+             41435776, 17373631, 13491505, 4641841}},
+            {{10813398, 643330, 47920349, 32825515, 30292061, 16954354,
+             27548446, 25833190, 14476988, 20787001}},
+        },
+        {
+            {{10292079, 9984945, 6481436, 8279905, 59857350, 7032742, 27282937,
+             31910173, 39196053, 12651323}},
+            {{35923332, 32741048, 22271203, 11835308, 10201545, 15351028,
+             17099662, 3988035, 21721536, 30405492}},
+            {{10202177, 27008593, 35735631, 23979793, 34958221, 25434748,
+             54202543, 3852693, 13216206, 14842320}},
+        },
+        {
+            {{51293224, 22953365, 60569911, 26295436, 60124204, 26972653,
+             35608016, 13765823, 39674467, 9900183}},
+            {{14465486, 19721101, 34974879, 18815558, 39665676, 12990491,
+             33046193, 15796406, 60056998, 25514317}},
+            {{30924398, 25274812, 6359015, 20738097, 16508376, 9071735,
+             41620263, 15413634, 9524356, 26535554}},
+        },
+        {
+            {{12274201, 20378885, 32627640, 31769106, 6736624, 13267305,
+             5237659, 28444949, 15663515, 4035784}},
+            {{64157555, 8903984, 17349946, 601635, 50676049, 28941875,
+             53376124, 17665097, 44850385, 4659090}},
+            {{50192582, 28601458, 36715152, 18395610, 20774811, 15897498,
+             5736189, 15026997, 64930608, 20098846}},
+        },
+    },
+    {
+        {
+            {{58249865, 31335375, 28571665, 23398914, 66634396, 23448733,
+             63307367, 278094, 23440562, 33264224}},
+            {{10226222, 27625730, 15139955, 120818, 52241171, 5218602, 32937275,
+             11551483, 50536904, 26111567}},
+            {{17932739, 21117156, 43069306, 10749059, 11316803, 7535897,
+             22503767, 5561594, 63462240, 3898660}},
+        },
+        {
+            {{7749907, 32584865, 50769132, 33537967, 42090752, 15122142, 65535333,
+             7152529, 21831162, 1245233}},
+            {{26958440, 18896406, 4314585, 8346991, 61431100, 11960071,
+             34519569, 32934396, 36706772, 16838219}},
+            {{54942968, 9166946, 33491384, 13673479, 29787085, 13096535,
+             6280834, 14587357, 44770839, 13987524}},
+        },
+        {
+            {{42758936, 7778774, 21116000, 15572597, 62275598, 28196653,
+             62807965, 28429792, 59639082, 30696363}},
+            {{9681908, 26817309, 35157219, 13591837, 60225043, 386949, 31622781,
+             6439245, 52527852, 4091396}},
+            {{58682418, 1470726, 38999185, 31957441, 3978626, 28430809,
+             47486180, 12092162, 29077877, 18812444}},
+        },
+        {
+            {{5269168, 26694706, 53878652, 25533716, 25932562, 1763552,
+             61502754, 28048550, 47091016, 2357888}},
+            {{32264008, 18146780, 61721128, 32394338, 65017541, 29607531,
+             23104803, 20684524, 5727337, 189038}},
+            {{14609104, 24599962, 61108297, 16931650, 52531476, 25810533,
+             40363694, 10942114, 41219933, 18669734}},
+        },
+        {
+            {{20513481, 5557931, 51504251, 7829530, 26413943, 31535028,
+             45729895, 7471780, 13913677, 28416557}},
+            {{41534488, 11967825, 29233242, 12948236, 60354399, 4713226,
+             58167894, 14059179, 12878652, 8511905}},
+            {{41452044, 3393630, 64153449, 26478905, 64858154, 9366907,
+             36885446, 6812973, 5568676, 30426776}},
+        },
+        {
+            {{11630004, 12144454, 2116339, 13606037, 27378885, 15676917,
+             49700111, 20050058, 52713667, 8070817}},
+            {{27117677, 23547054, 35826092, 27984343, 1127281, 12772488,
+             37262958, 10483305, 55556115, 32525717}},
+            {{10637467, 27866368, 5674780, 1072708, 40765276, 26572129,
+             65424888, 9177852, 39615702, 15431202}},
+        },
+        {
+            {{20525126, 10892566, 54366392, 12779442, 37615830, 16150074,
+             38868345, 14943141, 52052074, 25618500}},
+            {{37084402, 5626925, 66557297, 23573344, 753597, 11981191, 25244767,
+             30314666, 63752313, 9594023}},
+            {{43356201, 2636869, 61944954, 23450613, 585133, 7877383, 11345683,
+             27062142, 13352334, 22577348}},
+        },
+        {
+            {{65177046, 28146973, 3304648, 20669563, 17015805, 28677341,
+             37325013, 25801949, 53893326, 33235227}},
+            {{20239939, 6607058, 6203985, 3483793, 48721888, 32775202, 46385121,
+             15077869, 44358105, 14523816}},
+            {{27406023, 27512775, 27423595, 29057038, 4996213, 10002360,
+             38266833, 29008937, 36936121, 28748764}},
+        },
+    },
+    {
+        {
+            {{11374242, 12660715, 17861383, 21013599, 10935567, 1099227,
+             53222788, 24462691, 39381819, 11358503}},
+            {{54378055, 10311866, 1510375, 10778093, 64989409, 24408729,
+             32676002, 11149336, 40985213, 4985767}},
+            {{48012542, 341146, 60911379, 33315398, 15756972, 24757770, 66125820,
+             13794113, 47694557, 17933176}},
+        },
+        {
+            {{6490062, 11940286, 25495923, 25828072, 8668372, 24803116, 3367602,
+             6970005, 65417799, 24549641}},
+            {{1656478, 13457317, 15370807, 6364910, 13605745, 8362338, 47934242,
+             28078708, 50312267, 28522993}},
+            {{44835530, 20030007, 67044178, 29220208, 48503227, 22632463,
+             46537798, 26546453, 67009010, 23317098}},
+        },
+        {
+            {{17747446, 10039260, 19368299, 29503841, 46478228, 17513145,
+             31992682, 17696456, 37848500, 28042460}},
+            {{31932008, 28568291, 47496481, 16366579, 22023614, 88450, 11371999,
+             29810185, 4882241, 22927527}},
+            {{29796488, 37186, 19818052, 10115756, 55279832, 3352735, 18551198,
+             3272828, 61917932, 29392022}},
+        },
+        {
+            {{12501267, 4044383, 58495907, 20162046, 34678811, 5136598,
+             47878486, 30024734, 330069, 29895023}},
+            {{6384877, 2899513, 17807477, 7663917, 64749976, 12363164, 25366522,
+             24980540, 66837568, 12071498}},
+            {{58743349, 29511910, 25133447, 29037077, 60897836, 2265926,
+             34339246, 1936674, 61949167, 3829362}},
+        },
+        {
+            {{28425966, 27718999, 66531773, 28857233, 52891308, 6870929, 7921550,
+             26986645, 26333139, 14267664}},
+            {{56041645, 11871230, 27385719, 22994888, 62522949, 22365119,
+             10004785, 24844944, 45347639, 8930323}},
+            {{45911060, 17158396, 25654215, 31829035, 12282011, 11008919,
+             1541940, 4757911, 40617363, 17145491}},
+        },
+        {
+            {{13537262, 25794942, 46504023, 10961926, 61186044, 20336366,
+             53952279, 6217253, 51165165, 13814989}},
+            {{49686272, 15157789, 18705543, 29619, 24409717, 33293956, 27361680,
+             9257833, 65152338, 31777517}},
+            {{42063564, 23362465, 15366584, 15166509, 54003778, 8423555,
+             37937324, 12361134, 48422886, 4578289}},
+        },
+        {
+            {{24579768, 3711570, 1342322, 22374306, 40103728, 14124955,
+             44564335, 14074918, 21964432, 8235257}},
+            {{60580251, 31142934, 9442965, 27628844, 12025639, 32067012,
+             64127349, 31885225, 13006805, 2355433}},
+            {{50803946, 19949172, 60476436, 28412082, 16974358, 22643349,
+             27202043, 1719366, 1141648, 20758196}},
+        },
+        {
+            {{54244920, 20334445, 58790597, 22536340, 60298718, 28710537,
+             13475065, 30420460, 32674894, 13715045}},
+            {{11423316, 28086373, 32344215, 8962751, 24989809, 9241752,
+             53843611, 16086211, 38367983, 17912338}},
+            {{65699196, 12530727, 60740138, 10847386, 19531186, 19422272,
+             55399715, 7791793, 39862921, 4383346}},
+        },
+    },
+    {
+        {
+            {{38137966, 5271446, 65842855, 23817442, 54653627, 16732598,
+             62246457, 28647982, 27193556, 6245191}},
+            {{51914908, 5362277, 65324971, 2695833, 4960227, 12840725, 23061898,
+             3260492, 22510453, 8577507}},
+            {{54476394, 11257345, 34415870, 13548176, 66387860, 10879010,
+             31168030, 13952092, 37537372, 29918525}},
+        },
+        {
+            {{3877321, 23981693, 32416691, 5405324, 56104457, 19897796,
+             3759768, 11935320, 5611860, 8164018}},
+            {{50833043, 14667796, 15906460, 12155291, 44997715, 24514713,
+             32003001, 24722143, 5773084, 25132323}},
+            {{43320746, 25300131, 1950874, 8937633, 18686727, 16459170, 66203139,
+             12376319, 31632953, 190926}},
+        },
+        {
+            {{42515238, 17415546, 58684872, 13378745, 14162407, 6901328,
+             58820115, 4508563, 41767309, 29926903}},
+            {{8884438, 27670423, 6023973, 10104341, 60227295, 28612898, 18722940,
+             18768427, 65436375, 827624}},
+            {{34388281, 17265135, 34605316, 7101209, 13354605, 2659080,
+             65308289, 19446395, 42230385, 1541285}},
+        },
+        {
+            {{2901328, 32436745, 3880375, 23495044, 49487923, 29941650,
+             45306746, 29986950, 20456844, 31669399}},
+            {{27019610, 12299467, 53450576, 31951197, 54247203, 28692960,
+             47568713, 28538373, 29439640, 15138866}},
+            {{21536104, 26928012, 34661045, 22864223, 44700786, 5175813,
+             61688824, 17193268, 7779327, 109896}},
+        },
+        {
+            {{30279725, 14648750, 59063993, 6425557, 13639621, 32810923, 28698389,
+             12180118, 23177719, 33000357}},
+            {{26572828, 3405927, 35407164, 12890904, 47843196, 5335865,
+             60615096, 2378491, 4439158, 20275085}},
+            {{44392139, 3489069, 57883598, 33221678, 18875721, 32414337,
+             14819433, 20822905, 49391106, 28092994}},
+        },
+        {
+            {{62052362, 16566550, 15953661, 3767752, 56672365, 15627059,
+             66287910, 2177224, 8550082, 18440267}},
+            {{48635543, 16596774, 66727204, 15663610, 22860960, 15585581,
+             39264755, 29971692, 43848403, 25125843}},
+            {{34628313, 15707274, 58902952, 27902350, 29464557, 2713815,
+             44383727, 15860481, 45206294, 1494192}},
+        },
+        {
+            {{47546773, 19467038, 41524991, 24254879, 13127841, 759709,
+             21923482, 16529112, 8742704, 12967017}},
+            {{38643965, 1553204, 32536856, 23080703, 42417258, 33148257,
+             58194238, 30620535, 37205105, 15553882}},
+            {{21877890, 3230008, 9881174, 10539357, 62311749, 2841331, 11543572,
+             14513274, 19375923, 20906471}},
+        },
+        {
+            {{8832269, 19058947, 13253510, 5137575, 5037871, 4078777, 24880818,
+             27331716, 2862652, 9455043}},
+            {{29306751, 5123106, 20245049, 19404543, 9592565, 8447059, 65031740,
+             30564351, 15511448, 4789663}},
+            {{46429108, 7004546, 8824831, 24119455, 63063159, 29803695,
+             61354101, 108892, 23513200, 16652362}},
+        },
+    },
+    {
+        {
+            {{33852691, 4144781, 62632835, 26975308, 10770038, 26398890,
+             60458447, 20618131, 48789665, 10212859}},
+            {{2756062, 8598110, 7383731, 26694540, 22312758, 32449420, 21179800,
+             2600940, 57120566, 21047965}},
+            {{42463153, 13317461, 36659605, 17900503, 21365573, 22684775,
+             11344423, 864440, 64609187, 16844368}},
+        },
+        {
+            {{40676061, 6148328, 49924452, 19080277, 18782928, 33278435,
+             44547329, 211299, 2719757, 4940997}},
+            {{65784982, 3911312, 60160120, 14759764, 37081714, 7851206,
+             21690126, 8518463, 26699843, 5276295}},
+            {{53958991, 27125364, 9396248, 365013, 24703301, 23065493, 1321585,
+             149635, 51656090, 7159368}},
+        },
+        {
+            {{9987761, 30149673, 17507961, 9505530, 9731535, 31388918, 22356008,
+             8312176, 22477218, 25151047}},
+            {{18155857, 17049442, 19744715, 9006923, 15154154, 23015456,
+             24256459, 28689437, 44560690, 9334108}},
+            {{2986088, 28642539, 10776627, 30080588, 10620589, 26471229,
+             45695018, 14253544, 44521715, 536905}},
+        },
+        {
+            {{4377737, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551,
+             10589625, 10838060, 18134008}},
+            {{47766460, 867879, 9277171, 30335973, 52677291, 31567988,
+             19295825, 17757482, 6378259, 699185}},
+            {{7895007, 4057113, 60027092, 20476675, 49222032, 33231305, 66392824,
+             15693154, 62063800, 20180469}},
+        },
+        {
+            {{59371282, 27685029, 52542544, 26147512, 11385653, 13201616,
+             31730678, 22591592, 63190227, 23885106}},
+            {{10188286, 17783598, 59772502, 13427542, 22223443, 14896287,
+             30743455, 7116568, 45322357, 5427592}},
+            {{696102, 13206899, 27047647, 22922350, 15285304, 23701253,
+             10798489, 28975712, 19236242, 12477404}},
+        },
+        {
+            {{55879425, 11243795, 50054594, 25513566, 66320635, 25386464,
+             63211194, 11180503, 43939348, 7733643}},
+            {{17800790, 19518253, 40108434, 21787760, 23887826, 3149671,
+             23466177, 23016261, 10322026, 15313801}},
+            {{26246234, 11968874, 32263343, 28085704, 6830754, 20231401,
+             51314159, 33452449, 42659621, 10890803}},
+        },
+        {
+            {{35743198, 10271362, 54448239, 27287163, 16690206, 20491888,
+             52126651, 16484930, 25180797, 28219548}},
+            {{66522290, 10376443, 34522450, 22268075, 19801892, 10997610,
+             2276632, 9482883, 316878, 13820577}},
+            {{57226037, 29044064, 64993357, 16457135, 56008783, 11674995,
+             30756178, 26039378, 30696929, 29841583}},
+        },
+        {
+            {{32988917, 23951020, 12499365, 7910787, 56491607, 21622917,
+             59766047, 23569034, 34759346, 7392472}},
+            {{58253184, 15927860, 9866406, 29905021, 64711949, 16898650,
+             36699387, 24419436, 25112946, 30627788}},
+            {{64604801, 33117465, 25621773, 27875660, 15085041, 28074555,
+             42223985, 20028237, 5537437, 19640113}},
+        },
+    },
+    {
+        {
+            {{55883280, 2320284, 57524584, 10149186, 33664201, 5808647,
+             52232613, 31824764, 31234589, 6090599}},
+            {{57475529, 116425, 26083934, 2897444, 60744427, 30866345, 609720,
+             15878753, 60138459, 24519663}},
+            {{39351007, 247743, 51914090, 24551880, 23288160, 23542496,
+             43239268, 6503645, 20650474, 1804084}},
+        },
+        {
+            {{39519059, 15456423, 8972517, 8469608, 15640622, 4439847, 3121995,
+             23224719, 27842615, 33352104}},
+            {{51801891, 2839643, 22530074, 10026331, 4602058, 5048462, 28248656,
+             5031932, 55733782, 12714368}},
+            {{20807691, 26283607, 29286140, 11421711, 39232341, 19686201,
+             45881388, 1035545, 47375635, 12796919}},
+        },
+        {
+            {{12076880, 19253146, 58323862, 21705509, 42096072, 16400683,
+             49517369, 20654993, 3480664, 18371617}},
+            {{34747315, 5457596, 28548107, 7833186, 7303070, 21600887,
+             42745799, 17632556, 33734809, 2771024}},
+            {{45719598, 421931, 26597266, 6860826, 22486084, 26817260,
+             49971378, 29344205, 42556581, 15673396}},
+        },
+        {
+            {{46924223, 2338215, 19788685, 23933476, 63107598, 24813538,
+             46837679, 4733253, 3727144, 20619984}},
+            {{6120100, 814863, 55314462, 32931715, 6812204, 17806661, 2019593,
+             7975683, 31123697, 22595451}},
+            {{30069250, 22119100, 30434653, 2958439, 18399564, 32578143,
+             12296868, 9204260, 50676426, 9648164}},
+        },
+        {
+            {{32705413, 32003455, 30705657, 7451065, 55303258, 9631812, 3305266,
+             5248604, 41100532, 22176930}},
+            {{17219846, 2375039, 35537917, 27978816, 47649184, 9219902, 294711,
+             15298639, 2662509, 17257359}},
+            {{65935918, 25995736, 62742093, 29266687, 45762450, 25120105,
+             32087528, 32331655, 32247247, 19164571}},
+        },
+        {
+            {{14312609, 1221556, 17395390, 24854289, 62163122, 24869796,
+             38911119, 23916614, 51081240, 20175586}},
+            {{65680039, 23875441, 57873182, 6549686, 59725795, 33085767, 23046501,
+             9803137, 17597934, 2346211}},
+            {{18510781, 15337574, 26171504, 981392, 44867312, 7827555,
+             43617730, 22231079, 3059832, 21771562}},
+        },
+        {
+            {{10141598, 6082907, 17829293, 31606789, 9830091, 13613136,
+             41552228, 28009845, 33606651, 3592095}},
+            {{33114149, 17665080, 40583177, 20211034, 33076704, 8716171,
+             1151462, 1521897, 66126199, 26716628}},
+            {{34169699, 29298616, 23947180, 33230254, 34035889, 21248794,
+             50471177, 3891703, 26353178, 693168}},
+        },
+        {
+            {{30374239, 1595580, 50224825, 13186930, 4600344, 406904, 9585294,
+             33153764, 31375463, 14369965}},
+            {{52738210, 25781902, 1510300, 6434173, 48324075, 27291703,
+             32732229, 20445593, 17901440, 16011505}},
+            {{18171223, 21619806, 54608461, 15197121, 56070717, 18324396,
+             47936623, 17508055, 8764034, 12309598}},
+        },
+    },
+    {
+        {
+            {{5975889, 28311244, 47649501, 23872684, 55567586, 14015781,
+             43443107, 1228318, 17544096, 22960650}},
+            {{5811932, 31839139, 3442886, 31285122, 48741515, 25194890,
+             49064820, 18144304, 61543482, 12348899}},
+            {{35709185, 11407554, 25755363, 6891399, 63851926, 14872273,
+             42259511, 8141294, 56476330, 32968952}},
+        },
+        {
+            {{54433560, 694025, 62032719, 13300343, 14015258, 19103038,
+             57410191, 22225381, 30944592, 1130208}},
+            {{8247747, 26843490, 40546482, 25845122, 52706924, 18905521,
+             4652151, 2488540, 23550156, 33283200}},
+            {{17294297, 29765994, 7026747, 15626851, 22990044, 113481, 2267737,
+             27646286, 66700045, 33416712}},
+        },
+        {
+            {{16091066, 17300506, 18599251, 7340678, 2137637, 32332775,
+             63744702, 14550935, 3260525, 26388161}},
+            {{62198760, 20221544, 18550886, 10864893, 50649539, 26262835,
+             44079994, 20349526, 54360141, 2701325}},
+            {{58534169, 16099414, 4629974, 17213908, 46322650, 27548999,
+             57090500, 9276970, 11329923, 1862132}},
+        },
+        {
+            {{14763057, 17650824, 36190593, 3689866, 3511892, 10313526,
+             45157776, 12219230, 58070901, 32614131}},
+            {{8894987, 30108338, 6150752, 3013931, 301220, 15693451, 35127648,
+             30644714, 51670695, 11595569}},
+            {{15214943, 3537601, 40870142, 19495559, 4418656, 18323671,
+             13947275, 10730794, 53619402, 29190761}},
+        },
+        {
+            {{64570558, 7682792, 32759013, 263109, 37124133, 25598979,
+             44776739, 23365796, 977107, 699994}},
+            {{54642373, 4195083, 57897332, 550903, 51543527, 12917919,
+             19118110, 33114591, 36574330, 19216518}},
+            {{31788442, 19046775, 4799988, 7372237, 8808585, 18806489, 9408236,
+             23502657, 12493931, 28145115}},
+        },
+        {
+            {{41428258, 5260743, 47873055, 27269961, 63412921, 16566086,
+             27218280, 2607121, 29375955, 6024730}},
+            {{842132, 30759739, 62345482, 24831616, 26332017, 21148791,
+             11831879, 6985184, 57168503, 2854095}},
+            {{62261602, 25585100, 2516241, 27706719, 9695690, 26333246, 16512644,
+             960770, 12121869, 16648078}},
+        },
+        {
+            {{51890212, 14667095, 53772635, 2013716, 30598287, 33090295,
+             35603941, 25672367, 20237805, 2838411}},
+            {{47820798, 4453151, 15298546, 17376044, 22115042, 17581828,
+             12544293, 20083975, 1068880, 21054527}},
+            {{57549981, 17035596, 33238497, 13506958, 30505848, 32439836,
+             58621956, 30924378, 12521377, 4845654}},
+        },
+        {
+            {{38910324, 10744107, 64150484, 10199663, 7759311, 20465832,
+             3409347, 32681032, 60626557, 20668561}},
+            {{43547042, 6230155, 46726851, 10655313, 43068279, 21933259,
+             10477733, 32314216, 63995636, 13974497}},
+            {{12966261, 15550616, 35069916, 31939085, 21025979, 32924988,
+             5642324, 7188737, 18895762, 12629579}},
+        },
+    },
+    {
+        {
+            {{14741879, 18607545, 22177207, 21833195, 1279740, 8058600,
+             11758140, 789443, 32195181, 3895677}},
+            {{10758205, 15755439, 62598914, 9243697, 62229442, 6879878, 64904289,
+             29988312, 58126794, 4429646}},
+            {{64654951, 15725972, 46672522, 23143759, 61304955, 22514211,
+             59972993, 21911536, 18047435, 18272689}},
+        },
+        {
+            {{41935844, 22247266, 29759955, 11776784, 44846481, 17733976,
+             10993113, 20703595, 49488162, 24145963}},
+            {{21987233, 700364, 42603816, 14972007, 59334599, 27836036,
+             32155025, 2581431, 37149879, 8773374}},
+            {{41540495, 454462, 53896929, 16126714, 25240068, 8594567,
+             20656846, 12017935, 59234475, 19634276}},
+        },
+        {
+            {{6028163, 6263078, 36097058, 22252721, 66289944, 2461771,
+             35267690, 28086389, 65387075, 30777706}},
+            {{54829870, 16624276, 987579, 27631834, 32908202, 1248608, 7719845,
+             29387734, 28408819, 6816612}},
+            {{56750770, 25316602, 19549650, 21385210, 22082622, 16147817,
+             20613181, 13982702, 56769294, 5067942}},
+        },
+        {
+            {{36602878, 29732664, 12074680, 13582412, 47230892, 2443950,
+             47389578, 12746131, 5331210, 23448488}},
+            {{30528792, 3601899, 65151774, 4619784, 39747042, 18118043,
+             24180792, 20984038, 27679907, 31905504}},
+            {{9402385, 19597367, 32834042, 10838634, 40528714, 20317236,
+             26653273, 24868867, 22611443, 20839026}},
+        },
+        {
+            {{22190590, 1118029, 22736441, 15130463, 36648172, 27563110,
+             19189624, 28905490, 4854858, 6622139}},
+            {{58798126, 30600981, 58846284, 30166382, 56707132, 33282502,
+             13424425, 29987205, 26404408, 13001963}},
+            {{35867026, 18138731, 64114613, 8939345, 11562230, 20713762,
+             41044498, 21932711, 51703708, 11020692}},
+        },
+        {
+            {{1866042, 25604943, 59210214, 23253421, 12483314, 13477547,
+             3175636, 21130269, 28761761, 1406734}},
+            {{66660290, 31776765, 13018550, 3194501, 57528444, 22392694,
+             24760584, 29207344, 25577410, 20175752}},
+            {{42818486, 4759344, 66418211, 31701615, 2066746, 10693769,
+             37513074, 9884935, 57739938, 4745409}},
+        },
+        {
+            {{57967561, 6049713, 47577803, 29213020, 35848065, 9944275,
+             51646856, 22242579, 10931923, 21622501}},
+            {{50547351, 14112679, 59096219, 4817317, 59068400, 22139825,
+             44255434, 10856640, 46638094, 13434653}},
+            {{22759470, 23480998, 50342599, 31683009, 13637441, 23386341,
+             1765143, 20900106, 28445306, 28189722}},
+        },
+        {
+            {{29875063, 12493613, 2795536, 29768102, 1710619, 15181182,
+             56913147, 24765756, 9074233, 1167180}},
+            {{40903181, 11014232, 57266213, 30918946, 40200743, 7532293,
+             48391976, 24018933, 3843902, 9367684}},
+            {{56139269, 27150720, 9591133, 9582310, 11349256, 108879, 16235123,
+             8601684, 66969667, 4242894}},
+        },
+    },
+    {
+        {
+            {{22092954, 20363309, 65066070, 21585919, 32186752, 22037044,
+             60534522, 2470659, 39691498, 16625500}},
+            {{56051142, 3042015, 13770083, 24296510, 584235, 33009577, 59338006,
+             2602724, 39757248, 14247412}},
+            {{6314156, 23289540, 34336361, 15957556, 56951134, 168749,
+             58490057, 14290060, 27108877, 32373552}},
+        },
+        {
+            {{58522267, 26383465, 13241781, 10960156, 34117849, 19759835,
+             33547975, 22495543, 39960412, 981873}},
+            {{22833421, 9293594, 34459416, 19935764, 57971897, 14756818,
+             44180005, 19583651, 56629059, 17356469}},
+            {{59340277, 3326785, 38997067, 10783823, 19178761, 14905060,
+             22680049, 13906969, 51175174, 3797898}},
+        },
+        {
+            {{21721337, 29341686, 54902740, 9310181, 63226625, 19901321,
+             23740223, 30845200, 20491982, 25512280}},
+            {{9209251, 18419377, 53852306, 27386633, 66377847, 15289672,
+             25947805, 15286587, 30997318, 26851369}},
+            {{7392013, 16618386, 23946583, 25514540, 53843699, 32020573,
+             52911418, 31232855, 17649997, 33304352}},
+        },
+        {
+            {{57807776, 19360604, 30609525, 30504889, 41933794, 32270679,
+             51867297, 24028707, 64875610, 7662145}},
+            {{49550191, 1763593, 33994528, 15908609, 37067994, 21380136,
+             7335079, 25082233, 63934189, 3440182}},
+            {{47219164, 27577423, 42997570, 23865561, 10799742, 16982475,
+             40449, 29122597, 4862399, 1133}},
+        },
+        {
+            {{34252636, 25680474, 61686474, 14860949, 50789833, 7956141,
+             7258061, 311861, 36513873, 26175010}},
+            {{63335436, 31988495, 28985339, 7499440, 24445838, 9325937, 29727763,
+             16527196, 18278453, 15405622}},
+            {{62726958, 8508651, 47210498, 29880007, 61124410, 15149969,
+             53795266, 843522, 45233802, 13626196}},
+        },
+        {
+            {{2281448, 20067377, 56193445, 30944521, 1879357, 16164207,
+             56324982, 3953791, 13340839, 15928663}},
+            {{31727126, 26374577, 48671360, 25270779, 2875792, 17164102,
+             41838969, 26539605, 43656557, 5964752}},
+            {{4100401, 27594980, 49929526, 6017713, 48403027, 12227140,
+             40424029, 11344143, 2538215, 25983677}},
+        },
+        {
+            {{57675240, 6123112, 11159803, 31397824, 30016279, 14966241,
+             46633881, 1485420, 66479608, 17595569}},
+            {{40304287, 4260918, 11851389, 9658551, 35091757, 16367491,
+             46903439, 20363143, 11659921, 22439314}},
+            {{26180377, 10015009, 36264640, 24973138, 5418196, 9480663, 2231568,
+             23384352, 33100371, 32248261}},
+        },
+        {
+            {{15121094, 28352561, 56718958, 15427820, 39598927, 17561924,
+             21670946, 4486675, 61177054, 19088051}},
+            {{16166467, 24070699, 56004733, 6023907, 35182066, 32189508,
+             2340059, 17299464, 56373093, 23514607}},
+            {{28042865, 29997343, 54982337, 12259705, 63391366, 26608532,
+             6766452, 24864833, 18036435, 5803270}},
+        },
+    },
+    {
+        {
+            {{66291264, 6763911, 11803561, 1585585, 10958447, 30883267, 23855390,
+             4598332, 60949433, 19436993}},
+            {{36077558, 19298237, 17332028, 31170912, 31312681, 27587249,
+             696308, 50292, 47013125, 11763583}},
+            {{66514282, 31040148, 34874710, 12643979, 12650761, 14811489, 665117,
+             20940800, 47335652, 22840869}},
+        },
+        {
+            {{30464590, 22291560, 62981387, 20819953, 19835326, 26448819,
+             42712688, 2075772, 50088707, 992470}},
+            {{18357166, 26559999, 7766381, 16342475, 37783946, 411173, 14578841,
+             8080033, 55534529, 22952821}},
+            {{19598397, 10334610, 12555054, 2555664, 18821899, 23214652,
+             21873262, 16014234, 26224780, 16452269}},
+        },
+        {
+            {{36884939, 5145195, 5944548, 16385966, 3976735, 2009897, 55731060,
+             25936245, 46575034, 3698649}},
+            {{14187449, 3448569, 56472628, 22743496, 44444983, 30120835,
+             7268409, 22663988, 27394300, 12015369}},
+            {{19695742, 16087646, 28032085, 12999827, 6817792, 11427614,
+             20244189, 32241655, 53849736, 30151970}},
+        },
+        {
+            {{30860084, 12735208, 65220619, 28854697, 50133957, 2256939,
+             58942851, 12298311, 58558340, 23160969}},
+            {{61389038, 22309106, 65198214, 15569034, 26642876, 25966672,
+             61319509, 18435777, 62132699, 12651792}},
+            {{64260450, 9953420, 11531313, 28271553, 26895122, 20857343,
+             53990043, 17036529, 9768697, 31021214}},
+        },
+        {
+            {{42389405, 1894650, 66821166, 28850346, 15348718, 25397902,
+             32767512, 12765450, 4940095, 10678226}},
+            {{18860224, 15980149, 48121624, 31991861, 40875851, 22482575,
+             59264981, 13944023, 42736516, 16582018}},
+            {{51604604, 4970267, 37215820, 4175592, 46115652, 31354675,
+             55404809, 15444559, 56105103, 7989036}},
+        },
+        {
+            {{31490433, 5568061, 64696061, 2182382, 34772017, 4531685,
+             35030595, 6200205, 47422751, 18754260}},
+            {{49800177, 17674491, 35586086, 33551600, 34221481, 16375548,
+             8680158, 17182719, 28550067, 26697300}},
+            {{38981977, 27866340, 16837844, 31733974, 60258182, 12700015,
+             37068883, 4364037, 1155602, 5988841}},
+        },
+        {
+            {{21890435, 20281525, 54484852, 12154348, 59276991, 15300495,
+             23148983, 29083951, 24618406, 8283181}},
+            {{33972757, 23041680, 9975415, 6841041, 35549071, 16356535,
+             3070187, 26528504, 1466168, 10740210}},
+            {{65599446, 18066246, 53605478, 22898515, 32799043, 909394,
+             53169961, 27774712, 34944214, 18227391}},
+        },
+        {
+            {{3960804, 19286629, 39082773, 17636380, 47704005, 13146867,
+             15567327, 951507, 63848543, 32980496}},
+            {{24740822, 5052253, 37014733, 8961360, 25877428, 6165135,
+             42740684, 14397371, 59728495, 27410326}},
+            {{38220480, 3510802, 39005586, 32395953, 55870735, 22922977,
+             51667400, 19101303, 65483377, 27059617}},
+        },
+    },
+    {
+        {
+            {{793280, 24323954, 8836301, 27318725, 39747955, 31184838, 33152842,
+             28669181, 57202663, 32932579}},
+            {{5666214, 525582, 20782575, 25516013, 42570364, 14657739, 16099374,
+             1468826, 60937436, 18367850}},
+            {{62249590, 29775088, 64191105, 26806412, 7778749, 11688288,
+             36704511, 23683193, 65549940, 23690785}},
+        },
+        {
+            {{10896313, 25834728, 824274, 472601, 47648556, 3009586, 25248958,
+             14783338, 36527388, 17796587}},
+            {{10566929, 12612572, 35164652, 11118702, 54475488, 12362878,
+             21752402, 8822496, 24003793, 14264025}},
+            {{27713843, 26198459, 56100623, 9227529, 27050101, 2504721,
+             23886875, 20436907, 13958494, 27821979}},
+        },
+        {
+            {{43627235, 4867225, 39861736, 3900520, 29838369, 25342141,
+             35219464, 23512650, 7340520, 18144364}},
+            {{4646495, 25543308, 44342840, 22021777, 23184552, 8566613,
+             31366726, 32173371, 52042079, 23179239}},
+            {{49838347, 12723031, 50115803, 14878793, 21619651, 27356856,
+             27584816, 3093888, 58265170, 3849920}},
+        },
+        {
+            {{58043933, 2103171, 25561640, 18428694, 61869039, 9582957,
+             32477045, 24536477, 5002293, 18004173}},
+            {{55051311, 22376525, 21115584, 20189277, 8808711, 21523724,
+             16489529, 13378448, 41263148, 12741425}},
+            {{61162478, 10645102, 36197278, 15390283, 63821882, 26435754,
+             24306471, 15852464, 28834118, 25908360}},
+        },
+        {
+            {{49773116, 24447374, 42577584, 9434952, 58636780, 32971069,
+             54018092, 455840, 20461858, 5491305}},
+            {{13669229, 17458950, 54626889, 23351392, 52539093, 21661233,
+             42112877, 11293806, 38520660, 24132599}},
+            {{28497909, 6272777, 34085870, 14470569, 8906179, 32328802,
+             18504673, 19389266, 29867744, 24758489}},
+        },
+        {
+            {{50901822, 13517195, 39309234, 19856633, 24009063, 27180541,
+             60741263, 20379039, 22853428, 29542421}},
+            {{24191359, 16712145, 53177067, 15217830, 14542237, 1646131,
+             18603514, 22516545, 12876622, 31441985}},
+            {{17902668, 4518229, 66697162, 30725184, 26878216, 5258055, 54248111,
+             608396, 16031844, 3723494}},
+        },
+        {
+            {{38476072, 12763727, 46662418, 7577503, 33001348, 20536687,
+             17558841, 25681542, 23896953, 29240187}},
+            {{47103464, 21542479, 31520463, 605201, 2543521, 5991821, 64163800,
+             7229063, 57189218, 24727572}},
+            {{28816026, 298879, 38943848, 17633493, 19000927, 31888542,
+             54428030, 30605106, 49057085, 31471516}},
+        },
+        {
+            {{16000882, 33209536, 3493091, 22107234, 37604268, 20394642,
+             12577739, 16041268, 47393624, 7847706}},
+            {{10151868, 10572098, 27312476, 7922682, 14825339, 4723128,
+             34252933, 27035413, 57088296, 3852847}},
+            {{55678375, 15697595, 45987307, 29133784, 5386313, 15063598,
+             16514493, 17622322, 29330898, 18478208}},
+        },
+    },
+    {
+        {
+            {{41609129, 29175637, 51885955, 26653220, 16615730, 2051784,
+             3303702, 15490, 39560068, 12314390}},
+            {{15683501, 27551389, 18109119, 23573784, 15337967, 27556609,
+             50391428, 15921865, 16103996, 29823217}},
+            {{43939021, 22773182, 13588191, 31925625, 63310306, 32479502,
+             47835256, 5402698, 37293151, 23713330}},
+        },
+        {
+            {{23190676, 2384583, 34394524, 3462153, 37205209, 32025299,
+             55842007, 8911516, 41903005, 2739712}},
+            {{21374101, 30000182, 33584214, 9874410, 15377179, 11831242,
+             33578960, 6134906, 4931255, 11987849}},
+            {{67101132, 30575573, 50885377, 7277596, 105524, 33232381, 35628324,
+             13861387, 37032554, 10117929}},
+        },
+        {
+            {{37607694, 22809559, 40945095, 13051538, 41483300, 5089642,
+             60783361, 6704078, 12890019, 15728940}},
+            {{45136504, 21783052, 66157804, 29135591, 14704839, 2695116, 903376,
+             23126293, 12885166, 8311031}},
+            {{49592363, 5352193, 10384213, 19742774, 7506450, 13453191,
+             26423267, 4384730, 1888765, 28119028}},
+        },
+        {
+            {{41291507, 30447119, 53614264, 30371925, 30896458, 19632703,
+             34857219, 20846562, 47644429, 30214188}},
+            {{43500868, 30888657, 66582772, 4651135, 5765089, 4618330, 6092245,
+             14845197, 17151279, 23700316}},
+            {{42278406, 20820711, 51942885, 10367249, 37577956, 33289075,
+             22825804, 26467153, 50242379, 16176524}},
+        },
+        {
+            {{43525589, 6564960, 20063689, 3798228, 62368686, 7359224, 2006182,
+             23191006, 38362610, 23356922}},
+            {{56482264, 29068029, 53788301, 28429114, 3432135, 27161203,
+             23632036, 31613822, 32808309, 1099883}},
+            {{15030958, 5768825, 39657628, 30667132, 60681485, 18193060,
+             51830967, 26745081, 2051440, 18328567}},
+        },
+        {
+            {{63746541, 26315059, 7517889, 9824992, 23555850, 295369, 5148398,
+             19400244, 44422509, 16633659}},
+            {{4577067, 16802144, 13249840, 18250104, 19958762, 19017158,
+             18559669, 22794883, 8402477, 23690159}},
+            {{38702534, 32502850, 40318708, 32646733, 49896449, 22523642,
+             9453450, 18574360, 17983009, 9967138}},
+        },
+        {
+            {{41346370, 6524721, 26585488, 9969270, 24709298, 1220360, 65430874,
+             7806336, 17507396, 3651560}},
+            {{56688388, 29436320, 14584638, 15971087, 51340543, 8861009,
+             26556809, 27979875, 48555541, 22197296}},
+            {{2839082, 14284142, 4029895, 3472686, 14402957, 12689363, 40466743,
+             8459446, 61503401, 25932490}},
+        },
+        {
+            {{62269556, 30018987, 9744960, 2871048, 25113978, 3187018, 41998051,
+             32705365, 17258083, 25576693}},
+            {{18164541, 22959256, 49953981, 32012014, 19237077, 23809137,
+             23357532, 18337424, 26908269, 12150756}},
+            {{36843994, 25906566, 5112248, 26517760, 65609056, 26580174, 43167,
+             28016731, 34806789, 16215818}},
+        },
+    },
+    {
+        {
+            {{60209940, 9824393, 54804085, 29153342, 35711722, 27277596,
+             32574488, 12532905, 59605792, 24879084}},
+            {{39765323, 17038963, 39957339, 22831480, 946345, 16291093,
+             254968, 7168080, 21676107, 31611404}},
+            {{21260942, 25129680, 50276977, 21633609, 43430902, 3968120,
+             63456915, 27338965, 63552672, 25641356}},
+        },
+        {
+            {{16544735, 13250366, 50304436, 15546241, 62525861, 12757257,
+             64646556, 24874095, 48201831, 23891632}},
+            {{64693606, 17976703, 18312302, 4964443, 51836334, 20900867,
+             26820650, 16690659, 25459437, 28989823}},
+            {{41964155, 11425019, 28423002, 22533875, 60963942, 17728207,
+             9142794, 31162830, 60676445, 31909614}},
+        },
+        {
+            {{44004212, 6253475, 16964147, 29785560, 41994891, 21257994,
+             39651638, 17209773, 6335691, 7249989}},
+            {{36775618, 13979674, 7503222, 21186118, 55152142, 28932738,
+             36836594, 2682241, 25993170, 21075909}},
+            {{4364628, 5930691, 32304656, 23509878, 59054082, 15091130,
+             22857016, 22955477, 31820367, 15075278}},
+        },
+        {
+            {{31879134, 24635739, 17258760, 90626, 59067028, 28636722, 24162787,
+             23903546, 49138625, 12833044}},
+            {{19073683, 14851414, 42705695, 21694263, 7625277, 11091125,
+             47489674, 2074448, 57694925, 14905376}},
+            {{24483648, 21618865, 64589997, 22007013, 65555733, 15355505,
+             41826784, 9253128, 27628530, 25998952}},
+        },
+        {
+            {{17597607, 8340603, 19355617, 552187, 26198470, 30377849, 4593323,
+             24396850, 52997988, 15297015}},
+            {{510886, 14337390, 35323607, 16638631, 6328095, 2713355, 46891447,
+             21690211, 8683220, 2921426}},
+            {{18606791, 11874196, 27155355, 28272950, 43077121, 6265445,
+             41930624, 32275507, 4674689, 13890525}},
+        },
+        {
+            {{13609624, 13069022, 39736503, 20498523, 24360585, 9592974,
+             14977157, 9835105, 4389687, 288396}},
+            {{9922506, 33035038, 13613106, 5883594, 48350519, 33120168, 54804801,
+             8317627, 23388070, 16052080}},
+            {{12719997, 11937594, 35138804, 28525742, 26900119, 8561328,
+             46953177, 21921452, 52354592, 22741539}},
+        },
+        {
+            {{15961858, 14150409, 26716931, 32888600, 44314535, 13603568,
+             11829573, 7467844, 38286736, 929274}},
+            {{11038231, 21972036, 39798381, 26237869, 56610336, 17246600,
+             43629330, 24182562, 45715720, 2465073}},
+            {{20017144, 29231206, 27915241, 1529148, 12396362, 15675764,
+             13817261, 23896366, 2463390, 28932292}},
+        },
+        {
+            {{50749986, 20890520, 55043680, 4996453, 65852442, 1073571,
+             9583558, 12851107, 4003896, 12673717}},
+            {{65377275, 18398561, 63845933, 16143081, 19294135, 13385325,
+             14741514, 24450706, 7903885, 2348101}},
+            {{24536016, 17039225, 12715591, 29692277, 1511292, 10047386,
+             63266518, 26425272, 38731325, 10048126}},
+        },
+    },
+    {
+        {
+            {{54486638, 27349611, 30718824, 2591312, 56491836, 12192839,
+             18873298, 26257342, 34811107, 15221631}},
+            {{40630742, 22450567, 11546243, 31701949, 9180879, 7656409,
+             45764914, 2095754, 29769758, 6593415}},
+            {{35114656, 30646970, 4176911, 3264766, 12538965, 32686321, 26312344,
+             27435754, 30958053, 8292160}},
+        },
+        {
+            {{31429803, 19595316, 29173531, 15632448, 12174511, 30794338,
+             32808830, 3977186, 26143136, 30405556}},
+            {{22648882, 1402143, 44308880, 13746058, 7936347, 365344, 58440231,
+             31879998, 63350620, 31249806}},
+            {{51616947, 8012312, 64594134, 20851969, 43143017, 23300402,
+             65496150, 32018862, 50444388, 8194477}},
+        },
+        {
+            {{27338066, 26047012, 59694639, 10140404, 48082437, 26964542,
+             27277190, 8855376, 28572286, 3005164}},
+            {{26287105, 4821776, 25476601, 29408529, 63344350, 17765447,
+             49100281, 1182478, 41014043, 20474836}},
+            {{59937691, 3178079, 23970071, 6201893, 49913287, 29065239,
+             45232588, 19571804, 32208682, 32356184}},
+        },
+        {
+            {{50451143, 2817642, 56822502, 14811297, 6024667, 13349505,
+             39793360, 23056589, 39436278, 22014573}},
+            {{15941010, 24148500, 45741813, 8062054, 31876073, 33315803,
+             51830470, 32110002, 15397330, 29424239}},
+            {{8934485, 20068965, 43822466, 20131190, 34662773, 14047985,
+             31170398, 32113411, 39603297, 15087183}},
+        },
+        {
+            {{48751602, 31397940, 24524912, 16876564, 15520426, 27193656,
+             51606457, 11461895, 16788528, 27685490}},
+            {{65161459, 16013772, 21750665, 3714552, 49707082, 17498998,
+             63338576, 23231111, 31322513, 21938797}},
+            {{21426636, 27904214, 53460576, 28206894, 38296674, 28633461,
+             48833472, 18933017, 13040861, 21441484}},
+        },
+        {
+            {{11293895, 12478086, 39972463, 15083749, 37801443, 14748871,
+             14555558, 20137329, 1613710, 4896935}},
+            {{41213962, 15323293, 58619073, 25496531, 25967125, 20128972,
+             2825959, 28657387, 43137087, 22287016}},
+            {{51184079, 28324551, 49665331, 6410663, 3622847, 10243618,
+             20615400, 12405433, 43355834, 25118015}},
+        },
+        {
+            {{60017550, 12556207, 46917512, 9025186, 50036385, 4333800,
+             4378436, 2432030, 23097949, 32988414}},
+            {{4565804, 17528778, 20084411, 25711615, 1724998, 189254, 24767264,
+             10103221, 48596551, 2424777}},
+            {{366633, 21577626, 8173089, 26664313, 30788633, 5745705, 59940186,
+             1344108, 63466311, 12412658}},
+        },
+        {
+            {{43107073, 7690285, 14929416, 33386175, 34898028, 20141445,
+             24162696, 18227928, 63967362, 11179384}},
+            {{18289503, 18829478, 8056944, 16430056, 45379140, 7842513,
+             61107423, 32067534, 48424218, 22110928}},
+            {{476239, 6601091, 60956074, 23831056, 17503544, 28690532, 27672958,
+             13403813, 11052904, 5219329}},
+        },
+    },
+    {
+        {
+            {{20678527, 25178694, 34436965, 8849122, 62099106, 14574751,
+             31186971, 29580702, 9014761, 24975376}},
+            {{53464795, 23204192, 51146355, 5075807, 65594203, 22019831,
+             34006363, 9160279, 8473550, 30297594}},
+            {{24900749, 14435722, 17209120, 18261891, 44516588, 9878982,
+             59419555, 17218610, 42540382, 11788947}},
+        },
+        {
+            {{63990690, 22159237, 53306774, 14797440, 9652448, 26708528,
+             47071426, 10410732, 42540394, 32095740}},
+            {{51449703, 16736705, 44641714, 10215877, 58011687, 7563910,
+             11871841, 21049238, 48595538, 8464117}},
+            {{43708233, 8348506, 52522913, 32692717, 63158658, 27181012,
+             14325288, 8628612, 33313881, 25183915}},
+        },
+        {
+            {{46921872, 28586496, 22367355, 5271547, 66011747, 28765593,
+             42303196, 23317577, 58168128, 27736162}},
+            {{60160060, 31759219, 34483180, 17533252, 32635413, 26180187,
+             15989196, 20716244, 28358191, 29300528}},
+            {{43547083, 30755372, 34757181, 31892468, 57961144, 10429266,
+             50471180, 4072015, 61757200, 5596588}},
+        },
+        {
+            {{38872266, 30164383, 12312895, 6213178, 3117142, 16078565,
+             29266239, 2557221, 1768301, 15373193}},
+            {{59865506, 30307471, 62515396, 26001078, 66980936, 32642186, 66017961,
+             29049440, 42448372, 3442909}},
+            {{36898293, 5124042, 14181784, 8197961, 18964734, 21615339,
+             22597930, 7176455, 48523386, 13365929}},
+        },
+        {
+            {{59231455, 32054473, 8324672, 4690079, 6261860, 890446, 24538107,
+             24984246, 57419264, 30522764}},
+            {{25008885, 22782833, 62803832, 23916421, 16265035, 15721635,
+             683793, 21730648, 15723478, 18390951}},
+            {{57448220, 12374378, 40101865, 26528283, 59384749, 21239917,
+             11879681, 5400171, 519526, 32318556}},
+        },
+        {
+            {{22258397, 17222199, 59239046, 14613015, 44588609, 30603508,
+             46754982, 7315966, 16648397, 7605640}},
+            {{59027556, 25089834, 58885552, 9719709, 19259459, 18206220,
+             23994941, 28272877, 57640015, 4763277}},
+            {{45409620, 9220968, 51378240, 1084136, 41632757, 30702041,
+             31088446, 25789909, 55752334, 728111}},
+        },
+        {
+            {{26047201, 21802961, 60208540, 17032633, 24092067, 9158119,
+             62835319, 20998873, 37743427, 28056159}},
+            {{17510331, 33231575, 5854288, 8403524, 17133918, 30441820, 38997856,
+             12327944, 10750447, 10014012}},
+            {{56796096, 3936951, 9156313, 24656749, 16498691, 32559785,
+             39627812, 32887699, 3424690, 7540221}},
+        },
+        {
+            {{30322361, 26590322, 11361004, 29411115, 7433303, 4989748, 60037442,
+             17237212, 57864598, 15258045}},
+            {{13054543, 30774935, 19155473, 469045, 54626067, 4566041, 5631406,
+             2711395, 1062915, 28418087}},
+            {{47868616, 22299832, 37599834, 26054466, 61273100, 13005410,
+             61042375, 12194496, 32960380, 1459310}},
+        },
+    },
+    {
+        {
+            {{19852015, 7027924, 23669353, 10020366, 8586503, 26896525, 394196,
+             27452547, 18638002, 22379495}},
+            {{31395515, 15098109, 26581030, 8030562, 50580950, 28547297,
+             9012485, 25970078, 60465776, 28111795}},
+            {{57916680, 31207054, 65111764, 4529533, 25766844, 607986, 67095642,
+             9677542, 34813975, 27098423}},
+        },
+        {
+            {{64664349, 33404494, 29348901, 8186665, 1873760, 12489863, 36174285,
+             25714739, 59256019, 25416002}},
+            {{51872508, 18120922, 7766469, 746860, 26346930, 23332670,
+             39775412, 10754587, 57677388, 5203575}},
+            {{31834314, 14135496, 66338857, 5159117, 20917671, 16786336,
+             59640890, 26216907, 31809242, 7347066}},
+        },
+        {
+            {{57502122, 21680191, 20414458, 13033986, 13716524, 21862551,
+             19797969, 21343177, 15192875, 31466942}},
+            {{54445282, 31372712, 1168161, 29749623, 26747876, 19416341,
+             10609329, 12694420, 33473243, 20172328}},
+            {{33184999, 11180355, 15832085, 22169002, 65475192, 225883,
+             15089336, 22530529, 60973201, 14480052}},
+        },
+        {
+            {{31308717, 27934434, 31030839, 31657333, 15674546, 26971549,
+             5496207, 13685227, 27595050, 8737275}},
+            {{46790012, 18404192, 10933842, 17376410, 8335351, 26008410,
+             36100512, 20943827, 26498113, 66511}},
+            {{22644435, 24792703, 50437087, 4884561, 64003250, 19995065,
+             30540765, 29267685, 53781076, 26039336}},
+        },
+        {
+            {{39091017, 9834844, 18617207, 30873120, 63706907, 20246925,
+             8205539, 13585437, 49981399, 15115438}},
+            {{23711543, 32881517, 31206560, 25191721, 6164646, 23844445,
+             33572981, 32128335, 8236920, 16492939}},
+            {{43198286, 20038905, 40809380, 29050590, 25005589, 25867162,
+             19574901, 10071562, 6708380, 27332008}},
+        },
+        {
+            {{2101372, 28624378, 19702730, 2367575, 51681697, 1047674, 5301017,
+             9328700, 29955601, 21876122}},
+            {{3096359, 9271816, 45488000, 18032587, 52260867, 25961494,
+             41216721, 20918836, 57191288, 6216607}},
+            {{34493015, 338662, 41913253, 2510421, 37895298, 19734218,
+             24822829, 27407865, 40341383, 7525078}},
+        },
+        {
+            {{44042215, 19568808, 16133486, 25658254, 63719298, 778787,
+             66198528, 30771936, 47722230, 11994100}},
+            {{21691500, 19929806, 66467532, 19187410, 3285880, 30070836,
+             42044197, 9718257, 59631427, 13381417}},
+            {{18445390, 29352196, 14979845, 11622458, 65381754, 29971451,
+             23111647, 27179185, 28535281, 15779576}},
+        },
+        {
+            {{30098034, 3089662, 57874477, 16662134, 45801924, 11308410,
+             53040410, 12021729, 9955285, 17251076}},
+            {{9734894, 18977602, 59635230, 24415696, 2060391, 11313496,
+             48682835, 9924398, 20194861, 13380996}},
+            {{40730762, 25589224, 44941042, 15789296, 49053522, 27385639,
+             65123949, 15707770, 26342023, 10146099}},
+        },
+    },
+    {
+        {
+            {{41091971, 33334488, 21339190, 33513044, 19745255, 30675732,
+             37471583, 2227039, 21612326, 33008704}},
+            {{54031477, 1184227, 23562814, 27583990, 46757619, 27205717,
+             25764460, 12243797, 46252298, 11649657}},
+            {{57077370, 11262625, 27384172, 2271902, 26947504, 17556661, 39943,
+             6114064, 33514190, 2333242}},
+        },
+        {
+            {{45675257, 21132610, 8119781, 7219913, 45278342, 24538297,
+             60429113, 20883793, 24350577, 20104431}},
+            {{62992557, 22282898, 43222677, 4843614, 37020525, 690622,
+             35572776, 23147595, 8317859, 12352766}},
+            {{18200138, 19078521, 34021104, 30857812, 43406342, 24451920,
+             43556767, 31266881, 20712162, 6719373}},
+        },
+        {
+            {{26656189, 6075253, 59250308, 1886071, 38764821, 4262325, 11117530,
+             29791222, 26224234, 30256974}},
+            {{49939907, 18700334, 63713187, 17184554, 47154818, 14050419,
+             21728352, 9493610, 18620611, 17125804}},
+            {{53785524, 13325348, 11432106, 5964811, 18609221, 6062965,
+             61839393, 23828875, 36407290, 17074774}},
+        },
+        {
+            {{43248326, 22321272, 26961356, 1640861, 34695752, 16816491,
+             12248508, 28313793, 13735341, 1934062}},
+            {{25089769, 6742589, 17081145, 20148166, 21909292, 17486451,
+             51972569, 29789085, 45830866, 5473615}},
+            {{31883658, 25593331, 1083431, 21982029, 22828470, 13290673,
+             59983779, 12469655, 29111212, 28103418}},
+        },
+        {
+            {{24244947, 18504025, 40845887, 2791539, 52111265, 16666677,
+             24367466, 6388839, 56813277, 452382}},
+            {{41468082, 30136590, 5217915, 16224624, 19987036, 29472163,
+             42872612, 27639183, 15766061, 8407814}},
+            {{46701865, 13990230, 15495425, 16395525, 5377168, 15166495,
+             58191841, 29165478, 59040954, 2276717}},
+        },
+        {
+            {{30157899, 12924066, 49396814, 9245752, 19895028, 3368142,
+             43281277, 5096218, 22740376, 26251015}},
+            {{2041139, 19298082, 7783686, 13876377, 41161879, 20201972,
+             24051123, 13742383, 51471265, 13295221}},
+            {{33338218, 25048699, 12532112, 7977527, 9106186, 31839181,
+             49388668, 28941459, 62657506, 18884987}},
+        },
+        {
+            {{47063583, 5454096, 52762316, 6447145, 28862071, 1883651,
+             64639598, 29412551, 7770568, 9620597}},
+            {{23208049, 7979712, 33071466, 8149229, 1758231, 22719437, 30945527,
+             31860109, 33606523, 18786461}},
+            {{1439939, 17283952, 66028874, 32760649, 4625401, 10647766, 62065063,
+             1220117, 30494170, 22113633}},
+        },
+        {
+            {{62071265, 20526136, 64138304, 30492664, 15640973, 26852766,
+             40369837, 926049, 65424525, 20220784}},
+            {{13908495, 30005160, 30919927, 27280607, 45587000, 7989038,
+             9021034, 9078865, 3353509, 4033511}},
+            {{37445433, 18440821, 32259990, 33209950, 24295848, 20642309,
+             23161162, 8839127, 27485041, 7356032}},
+        },
+    },
+    {
+        {
+            {{9661008, 705443, 11980065, 28184278, 65480320, 14661172, 60762722,
+             2625014, 28431036, 16782598}},
+            {{43269631, 25243016, 41163352, 7480957, 49427195, 25200248,
+             44562891, 14150564, 15970762, 4099461}},
+            {{29262576, 16756590, 26350592, 24760869, 8529670, 22346382,
+             13617292, 23617289, 11465738, 8317062}},
+        },
+        {
+            {{41615764, 26591503, 32500199, 24135381, 44070139, 31252209,
+             14898636, 3848455, 20969334, 28396916}},
+            {{46724414, 19206718, 48772458, 13884721, 34069410, 2842113,
+             45498038, 29904543, 11177094, 14989547}},
+            {{42612143, 21838415, 16959895, 2278463, 12066309, 10137771,
+             13515641, 2581286, 38621356, 9930239}},
+        },
+        {
+            {{49357223, 31456605, 16544299, 20545132, 51194056, 18605350,
+             18345766, 20150679, 16291480, 28240394}},
+            {{33879670, 2553287, 32678213, 9875984, 8534129, 6889387, 57432090,
+             6957616, 4368891, 9788741}},
+            {{16660737, 7281060, 56278106, 12911819, 20108584, 25452756,
+             45386327, 24941283, 16250551, 22443329}},
+        },
+        {
+            {{47343357, 2390525, 50557833, 14161979, 1905286, 6414907, 4689584,
+             10604807, 36918461, 4782746}},
+            {{65754325, 14736940, 59741422, 20261545, 7710541, 19398842,
+             57127292, 4383044, 22546403, 437323}},
+            {{31665558, 21373968, 50922033, 1491338, 48740239, 3294681,
+             27343084, 2786261, 36475274, 19457415}},
+        },
+        {
+            {{52641566, 32870716, 33734756, 7448551, 19294360, 14334329,
+             47418233, 2355318, 47824193, 27440058}},
+            {{15121312, 17758270, 6377019, 27523071, 56310752, 20596586,
+             18952176, 15496498, 37728731, 11754227}},
+            {{64471568, 20071356, 8488726, 19250536, 12728760, 31931939,
+             7141595, 11724556, 22761615, 23420291}},
+        },
+        {
+            {{16918416, 11729663, 49025285, 3022986, 36093132, 20214772,
+             38367678, 21327038, 32851221, 11717399}},
+            {{11166615, 7338049, 60386341, 4531519, 37640192, 26252376,
+             31474878, 3483633, 65915689, 29523600}},
+            {{66923210, 9921304, 31456609, 20017994, 55095045, 13348922,
+             33142652, 6546660, 47123585, 29606055}},
+        },
+        {
+            {{34648249, 11266711, 55911757, 25655328, 31703693, 3855903,
+             58571733, 20721383, 36336829, 18068118}},
+            {{49102387, 12709067, 3991746, 27075244, 45617340, 23004006,
+             35973516, 17504552, 10928916, 3011958}},
+            {{60151107, 17960094, 31696058, 334240, 29576716, 14796075,
+             36277808, 20749251, 18008030, 10258577}},
+        },
+        {
+            {{44660220, 15655568, 7018479, 29144429, 36794597, 32352840,
+             65255398, 1367119, 25127874, 6671743}},
+            {{29701166, 19180498, 56230743, 9279287, 67091296, 13127209,
+             21382910, 11042292, 25838796, 4642684}},
+            {{46678630, 14955536, 42982517, 8124618, 61739576, 27563961,
+             30468146, 19653792, 18423288, 4177476}},
+        },
+    },
+};
+
+static uint8_t negative(signed char b) {
+  uint32_t x = b;
+  x >>= 31;  // 1: yes; 0: no
+  return x;
+}
+
+static void table_select(ge_precomp *t, int pos, signed char b) {
+  ge_precomp minust;
+  uint8_t bnegative = negative(b);
+  uint8_t babs = b - ((uint8_t)((-bnegative) & b) << 1);
+
+  ge_precomp_0(t);
+  cmov(t, &k25519Precomp[pos][0], equal(babs, 1));
+  cmov(t, &k25519Precomp[pos][1], equal(babs, 2));
+  cmov(t, &k25519Precomp[pos][2], equal(babs, 3));
+  cmov(t, &k25519Precomp[pos][3], equal(babs, 4));
+  cmov(t, &k25519Precomp[pos][4], equal(babs, 5));
+  cmov(t, &k25519Precomp[pos][5], equal(babs, 6));
+  cmov(t, &k25519Precomp[pos][6], equal(babs, 7));
+  cmov(t, &k25519Precomp[pos][7], equal(babs, 8));
+  fe_copy_ll(&minust.yplusx, &t->yminusx);
+  fe_copy_ll(&minust.yminusx, &t->yplusx);
+
+  // NOTE: the input table is canonical, but types don't encode it
+  fe tmp;
+  fe_carry(&tmp, &t->xy2d);
+  fe_neg(&minust.xy2d, &tmp);
+
+  cmov(t, &minust, bnegative);
+}
+
+// h = a * B
+// where a = a[0]+256*a[1]+...+256^31 a[31]
+// B is the Ed25519 base point (x,4/5) with x positive.
+//
+// Preconditions:
+//   a[31] <= 127
+void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t *a) {
+  signed char e[64];
+  signed char carry;
+  ge_p1p1 r;
+  ge_p2 s;
+  ge_precomp t;
+  int i;
+
+  for (i = 0; i < 32; ++i) {
+    e[2 * i + 0] = (a[i] >> 0) & 15;
+    e[2 * i + 1] = (a[i] >> 4) & 15;
+  }
+  // each e[i] is between 0 and 15
+  // e[63] is between 0 and 7
+
+  carry = 0;
+  for (i = 0; i < 63; ++i) {
+    e[i] += carry;
+    carry = e[i] + 8;
+    carry >>= 4;
+    e[i] -= carry << 4;
+  }
+  e[63] += carry;
+  // each e[i] is between -8 and 8
+
+  ge_p3_0(h);
+  for (i = 1; i < 64; i += 2) {
+    table_select(&t, i / 2, e[i]);
+    ge_madd(&r, h, &t);
+    x25519_ge_p1p1_to_p3(h, &r);
+  }
+
+  ge_p3_dbl(&r, h);
+  x25519_ge_p1p1_to_p2(&s, &r);
+  ge_p2_dbl(&r, &s);
+  x25519_ge_p1p1_to_p2(&s, &r);
+  ge_p2_dbl(&r, &s);
+  x25519_ge_p1p1_to_p2(&s, &r);
+  ge_p2_dbl(&r, &s);
+  x25519_ge_p1p1_to_p3(h, &r);
+
+  for (i = 0; i < 64; i += 2) {
+    table_select(&t, i / 2, e[i]);
+    ge_madd(&r, h, &t);
+    x25519_ge_p1p1_to_p3(h, &r);
+  }
+}
+
+#endif
+
+static void cmov_cached(ge_cached *t, ge_cached *u, uint8_t b) {
+  fe_cmov(&t->YplusX, &u->YplusX, b);
+  fe_cmov(&t->YminusX, &u->YminusX, b);
+  fe_cmov(&t->Z, &u->Z, b);
+  fe_cmov(&t->T2d, &u->T2d, b);
+}
+
+// r = scalar * A.
+// where a = a[0]+256*a[1]+...+256^31 a[31].
+void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A) {
+  ge_p2 Ai_p2[8];
+  ge_cached Ai[16];
+  ge_p1p1 t;
+
+  ge_cached_0(&Ai[0]);
+  x25519_ge_p3_to_cached(&Ai[1], A);
+  ge_p3_to_p2(&Ai_p2[1], A);
+
+  unsigned i;
+  for (i = 2; i < 16; i += 2) {
+    ge_p2_dbl(&t, &Ai_p2[i / 2]);
+    ge_p1p1_to_cached(&Ai[i], &t);
+    if (i < 8) {
+      x25519_ge_p1p1_to_p2(&Ai_p2[i], &t);
+    }
+    x25519_ge_add(&t, A, &Ai[i]);
+    ge_p1p1_to_cached(&Ai[i + 1], &t);
+    if (i < 7) {
+      x25519_ge_p1p1_to_p2(&Ai_p2[i + 1], &t);
+    }
+  }
+
+  ge_p2_0(r);
+  ge_p3 u;
+
+  for (i = 0; i < 256; i += 4) {
+    ge_p2_dbl(&t, r);
+    x25519_ge_p1p1_to_p2(r, &t);
+    ge_p2_dbl(&t, r);
+    x25519_ge_p1p1_to_p2(r, &t);
+    ge_p2_dbl(&t, r);
+    x25519_ge_p1p1_to_p2(r, &t);
+    ge_p2_dbl(&t, r);
+    x25519_ge_p1p1_to_p3(&u, &t);
+
+    uint8_t index = scalar[31 - i/8];
+    index >>= 4 - (i & 4);
+    index &= 0xf;
+
+    unsigned j;
+    ge_cached selected;
+    ge_cached_0(&selected);
+    for (j = 0; j < 16; j++) {
+      cmov_cached(&selected, &Ai[j], equal(j, index));
+    }
+
+    x25519_ge_add(&t, &u, &selected);
+    x25519_ge_p1p1_to_p2(r, &t);
+  }
+}
+
+static void slide(signed char *r, const uint8_t *a) {
+  int i;
+  int b;
+  int k;
+
+  for (i = 0; i < 256; ++i) {
+    r[i] = 1 & (a[i >> 3] >> (i & 7));
+  }
+
+  for (i = 0; i < 256; ++i) {
+    if (r[i]) {
+      for (b = 1; b <= 6 && i + b < 256; ++b) {
+        if (r[i + b]) {
+          if (r[i] + (r[i + b] << b) <= 15) {
+            r[i] += r[i + b] << b;
+            r[i + b] = 0;
+          } else if (r[i] - (r[i + b] << b) >= -15) {
+            r[i] -= r[i + b] << b;
+            for (k = i + b; k < 256; ++k) {
+              if (!r[k]) {
+                r[k] = 1;
+                break;
+              }
+              r[k] = 0;
+            }
+          } else {
+            break;
+          }
+        }
+      }
+    }
+  }
+}
+
+static const ge_precomp Bi[8] = {
+    {
+        {{25967493, 19198397, 29566455, 3660896, 54414519, 4014786, 27544626,
+         21800161, 61029707, 2047604}},
+        {{54563134, 934261, 64385954, 3049989, 66381436, 9406985, 12720692,
+         5043384, 19500929, 18085054}},
+        {{58370664, 4489569, 9688441, 18769238, 10184608, 21191052, 29287918,
+         11864899, 42594502, 29115885}},
+    },
+    {
+        {{15636272, 23865875, 24204772, 25642034, 616976, 16869170, 27787599,
+         18782243, 28944399, 32004408}},
+        {{16568933, 4717097, 55552716, 32452109, 15682895, 21747389, 16354576,
+         21778470, 7689661, 11199574}},
+        {{30464137, 27578307, 55329429, 17883566, 23220364, 15915852, 7512774,
+         10017326, 49359771, 23634074}},
+    },
+    {
+        {{10861363, 11473154, 27284546, 1981175, 37044515, 12577860, 32867885,
+         14515107, 51670560, 10819379}},
+        {{4708026, 6336745, 20377586, 9066809, 55836755, 6594695, 41455196,
+         12483687, 54440373, 5581305}},
+        {{19563141, 16186464, 37722007, 4097518, 10237984, 29206317, 28542349,
+         13850243, 43430843, 17738489}},
+    },
+    {
+        {{5153727, 9909285, 1723747, 30776558, 30523604, 5516873, 19480852,
+         5230134, 43156425, 18378665}},
+        {{36839857, 30090922, 7665485, 10083793, 28475525, 1649722, 20654025,
+         16520125, 30598449, 7715701}},
+        {{28881826, 14381568, 9657904, 3680757, 46927229, 7843315, 35708204,
+         1370707, 29794553, 32145132}},
+    },
+    {
+        {{44589871, 26862249, 14201701, 24808930, 43598457, 8844725, 18474211,
+         32192982, 54046167, 13821876}},
+        {{60653668, 25714560, 3374701, 28813570, 40010246, 22982724, 31655027,
+         26342105, 18853321, 19333481}},
+        {{4566811, 20590564, 38133974, 21313742, 59506191, 30723862, 58594505,
+         23123294, 2207752, 30344648}},
+    },
+    {
+        {{41954014, 29368610, 29681143, 7868801, 60254203, 24130566, 54671499,
+         32891431, 35997400, 17421995}},
+        {{25576264, 30851218, 7349803, 21739588, 16472781, 9300885, 3844789,
+         15725684, 171356, 6466918}},
+        {{23103977, 13316479, 9739013, 17404951, 817874, 18515490, 8965338,
+         19466374, 36393951, 16193876}},
+    },
+    {
+        {{33587053, 3180712, 64714734, 14003686, 50205390, 17283591, 17238397,
+         4729455, 49034351, 9256799}},
+        {{41926547, 29380300, 32336397, 5036987, 45872047, 11360616, 22616405,
+         9761698, 47281666, 630304}},
+        {{53388152, 2639452, 42871404, 26147950, 9494426, 27780403, 60554312,
+         17593437, 64659607, 19263131}},
+    },
+    {
+        {{63957664, 28508356, 9282713, 6866145, 35201802, 32691408, 48168288,
+         15033783, 25105118, 25659556}},
+        {{42782475, 15950225, 35307649, 18961608, 55446126, 28463506,
+         1573891, 30928545, 2198789, 17749813}},
+        {{64009494, 10324966, 64867251, 7453182, 61661885, 30818928, 53296841,
+         17317989, 34647629, 21263748}},
+    },
+};
+
+// r = a * A + b * B
+// where a = a[0]+256*a[1]+...+256^31 a[31].
+// and b = b[0]+256*b[1]+...+256^31 b[31].
+// B is the Ed25519 base point (x,4/5) with x positive.
+static void ge_double_scalarmult_vartime(ge_p2 *r, const uint8_t *a,
+                                         const ge_p3 *A, const uint8_t *b) {
+  signed char aslide[256];
+  signed char bslide[256];
+  ge_cached Ai[8];  // A,3A,5A,7A,9A,11A,13A,15A
+  ge_p1p1 t;
+  ge_p3 u;
+  ge_p3 A2;
+  int i;
+
+  slide(aslide, a);
+  slide(bslide, b);
+
+  x25519_ge_p3_to_cached(&Ai[0], A);
+  ge_p3_dbl(&t, A);
+  x25519_ge_p1p1_to_p3(&A2, &t);
+  x25519_ge_add(&t, &A2, &Ai[0]);
+  x25519_ge_p1p1_to_p3(&u, &t);
+  x25519_ge_p3_to_cached(&Ai[1], &u);
+  x25519_ge_add(&t, &A2, &Ai[1]);
+  x25519_ge_p1p1_to_p3(&u, &t);
+  x25519_ge_p3_to_cached(&Ai[2], &u);
+  x25519_ge_add(&t, &A2, &Ai[2]);
+  x25519_ge_p1p1_to_p3(&u, &t);
+  x25519_ge_p3_to_cached(&Ai[3], &u);
+  x25519_ge_add(&t, &A2, &Ai[3]);
+  x25519_ge_p1p1_to_p3(&u, &t);
+  x25519_ge_p3_to_cached(&Ai[4], &u);
+  x25519_ge_add(&t, &A2, &Ai[4]);
+  x25519_ge_p1p1_to_p3(&u, &t);
+  x25519_ge_p3_to_cached(&Ai[5], &u);
+  x25519_ge_add(&t, &A2, &Ai[5]);
+  x25519_ge_p1p1_to_p3(&u, &t);
+  x25519_ge_p3_to_cached(&Ai[6], &u);
+  x25519_ge_add(&t, &A2, &Ai[6]);
+  x25519_ge_p1p1_to_p3(&u, &t);
+  x25519_ge_p3_to_cached(&Ai[7], &u);
+
+  ge_p2_0(r);
+
+  for (i = 255; i >= 0; --i) {
+    if (aslide[i] || bslide[i]) {
+      break;
+    }
+  }
+
+  for (; i >= 0; --i) {
+    ge_p2_dbl(&t, r);
+
+    if (aslide[i] > 0) {
+      x25519_ge_p1p1_to_p3(&u, &t);
+      x25519_ge_add(&t, &u, &Ai[aslide[i] / 2]);
+    } else if (aslide[i] < 0) {
+      x25519_ge_p1p1_to_p3(&u, &t);
+      x25519_ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
+    }
+
+    if (bslide[i] > 0) {
+      x25519_ge_p1p1_to_p3(&u, &t);
+      ge_madd(&t, &u, &Bi[bslide[i] / 2]);
+    } else if (bslide[i] < 0) {
+      x25519_ge_p1p1_to_p3(&u, &t);
+      ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
+    }
+
+    x25519_ge_p1p1_to_p2(r, &t);
+  }
+}
+
+// The set of scalars is \Z/l
+// where l = 2^252 + 27742317777372353535851937790883648493.
+
+// Input:
+//   s[0]+256*s[1]+...+256^63*s[63] = s
+//
+// Output:
+//   s[0]+256*s[1]+...+256^31*s[31] = s mod l
+//   where l = 2^252 + 27742317777372353535851937790883648493.
+//   Overwrites s in place.
+void x25519_sc_reduce(uint8_t *s) {
+  int64_t s0 = 2097151 & load_3(s);
+  int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
+  int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
+  int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
+  int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
+  int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
+  int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
+  int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
+  int64_t s8 = 2097151 & load_3(s + 21);
+  int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
+  int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
+  int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
+  int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
+  int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
+  int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
+  int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
+  int64_t s16 = 2097151 & load_3(s + 42);
+  int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
+  int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
+  int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
+  int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
+  int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
+  int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
+  int64_t s23 = (load_4(s + 60) >> 3);
+  int64_t carry0;
+  int64_t carry1;
+  int64_t carry2;
+  int64_t carry3;
+  int64_t carry4;
+  int64_t carry5;
+  int64_t carry6;
+  int64_t carry7;
+  int64_t carry8;
+  int64_t carry9;
+  int64_t carry10;
+  int64_t carry11;
+  int64_t carry12;
+  int64_t carry13;
+  int64_t carry14;
+  int64_t carry15;
+  int64_t carry16;
+
+  s11 += s23 * 666643;
+  s12 += s23 * 470296;
+  s13 += s23 * 654183;
+  s14 -= s23 * 997805;
+  s15 += s23 * 136657;
+  s16 -= s23 * 683901;
+  s23 = 0;
+
+  s10 += s22 * 666643;
+  s11 += s22 * 470296;
+  s12 += s22 * 654183;
+  s13 -= s22 * 997805;
+  s14 += s22 * 136657;
+  s15 -= s22 * 683901;
+  s22 = 0;
+
+  s9 += s21 * 666643;
+  s10 += s21 * 470296;
+  s11 += s21 * 654183;
+  s12 -= s21 * 997805;
+  s13 += s21 * 136657;
+  s14 -= s21 * 683901;
+  s21 = 0;
+
+  s8 += s20 * 666643;
+  s9 += s20 * 470296;
+  s10 += s20 * 654183;
+  s11 -= s20 * 997805;
+  s12 += s20 * 136657;
+  s13 -= s20 * 683901;
+  s20 = 0;
+
+  s7 += s19 * 666643;
+  s8 += s19 * 470296;
+  s9 += s19 * 654183;
+  s10 -= s19 * 997805;
+  s11 += s19 * 136657;
+  s12 -= s19 * 683901;
+  s19 = 0;
+
+  s6 += s18 * 666643;
+  s7 += s18 * 470296;
+  s8 += s18 * 654183;
+  s9 -= s18 * 997805;
+  s10 += s18 * 136657;
+  s11 -= s18 * 683901;
+  s18 = 0;
+
+  carry6 = (s6 + (1 << 20)) >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry8 = (s8 + (1 << 20)) >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry10 = (s10 + (1 << 20)) >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+  carry12 = (s12 + (1 << 20)) >> 21;
+  s13 += carry12;
+  s12 -= carry12 << 21;
+  carry14 = (s14 + (1 << 20)) >> 21;
+  s15 += carry14;
+  s14 -= carry14 << 21;
+  carry16 = (s16 + (1 << 20)) >> 21;
+  s17 += carry16;
+  s16 -= carry16 << 21;
+
+  carry7 = (s7 + (1 << 20)) >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry9 = (s9 + (1 << 20)) >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry11 = (s11 + (1 << 20)) >> 21;
+  s12 += carry11;
+  s11 -= carry11 << 21;
+  carry13 = (s13 + (1 << 20)) >> 21;
+  s14 += carry13;
+  s13 -= carry13 << 21;
+  carry15 = (s15 + (1 << 20)) >> 21;
+  s16 += carry15;
+  s15 -= carry15 << 21;
+
+  s5 += s17 * 666643;
+  s6 += s17 * 470296;
+  s7 += s17 * 654183;
+  s8 -= s17 * 997805;
+  s9 += s17 * 136657;
+  s10 -= s17 * 683901;
+  s17 = 0;
+
+  s4 += s16 * 666643;
+  s5 += s16 * 470296;
+  s6 += s16 * 654183;
+  s7 -= s16 * 997805;
+  s8 += s16 * 136657;
+  s9 -= s16 * 683901;
+  s16 = 0;
+
+  s3 += s15 * 666643;
+  s4 += s15 * 470296;
+  s5 += s15 * 654183;
+  s6 -= s15 * 997805;
+  s7 += s15 * 136657;
+  s8 -= s15 * 683901;
+  s15 = 0;
+
+  s2 += s14 * 666643;
+  s3 += s14 * 470296;
+  s4 += s14 * 654183;
+  s5 -= s14 * 997805;
+  s6 += s14 * 136657;
+  s7 -= s14 * 683901;
+  s14 = 0;
+
+  s1 += s13 * 666643;
+  s2 += s13 * 470296;
+  s3 += s13 * 654183;
+  s4 -= s13 * 997805;
+  s5 += s13 * 136657;
+  s6 -= s13 * 683901;
+  s13 = 0;
+
+  s0 += s12 * 666643;
+  s1 += s12 * 470296;
+  s2 += s12 * 654183;
+  s3 -= s12 * 997805;
+  s4 += s12 * 136657;
+  s5 -= s12 * 683901;
+  s12 = 0;
+
+  carry0 = (s0 + (1 << 20)) >> 21;
+  s1 += carry0;
+  s0 -= carry0 << 21;
+  carry2 = (s2 + (1 << 20)) >> 21;
+  s3 += carry2;
+  s2 -= carry2 << 21;
+  carry4 = (s4 + (1 << 20)) >> 21;
+  s5 += carry4;
+  s4 -= carry4 << 21;
+  carry6 = (s6 + (1 << 20)) >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry8 = (s8 + (1 << 20)) >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry10 = (s10 + (1 << 20)) >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+
+  carry1 = (s1 + (1 << 20)) >> 21;
+  s2 += carry1;
+  s1 -= carry1 << 21;
+  carry3 = (s3 + (1 << 20)) >> 21;
+  s4 += carry3;
+  s3 -= carry3 << 21;
+  carry5 = (s5 + (1 << 20)) >> 21;
+  s6 += carry5;
+  s5 -= carry5 << 21;
+  carry7 = (s7 + (1 << 20)) >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry9 = (s9 + (1 << 20)) >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry11 = (s11 + (1 << 20)) >> 21;
+  s12 += carry11;
+  s11 -= carry11 << 21;
+
+  s0 += s12 * 666643;
+  s1 += s12 * 470296;
+  s2 += s12 * 654183;
+  s3 -= s12 * 997805;
+  s4 += s12 * 136657;
+  s5 -= s12 * 683901;
+  s12 = 0;
+
+  carry0 = s0 >> 21;
+  s1 += carry0;
+  s0 -= carry0 << 21;
+  carry1 = s1 >> 21;
+  s2 += carry1;
+  s1 -= carry1 << 21;
+  carry2 = s2 >> 21;
+  s3 += carry2;
+  s2 -= carry2 << 21;
+  carry3 = s3 >> 21;
+  s4 += carry3;
+  s3 -= carry3 << 21;
+  carry4 = s4 >> 21;
+  s5 += carry4;
+  s4 -= carry4 << 21;
+  carry5 = s5 >> 21;
+  s6 += carry5;
+  s5 -= carry5 << 21;
+  carry6 = s6 >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry7 = s7 >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry8 = s8 >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry9 = s9 >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry10 = s10 >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+  carry11 = s11 >> 21;
+  s12 += carry11;
+  s11 -= carry11 << 21;
+
+  s0 += s12 * 666643;
+  s1 += s12 * 470296;
+  s2 += s12 * 654183;
+  s3 -= s12 * 997805;
+  s4 += s12 * 136657;
+  s5 -= s12 * 683901;
+  s12 = 0;
+
+  carry0 = s0 >> 21;
+  s1 += carry0;
+  s0 -= carry0 << 21;
+  carry1 = s1 >> 21;
+  s2 += carry1;
+  s1 -= carry1 << 21;
+  carry2 = s2 >> 21;
+  s3 += carry2;
+  s2 -= carry2 << 21;
+  carry3 = s3 >> 21;
+  s4 += carry3;
+  s3 -= carry3 << 21;
+  carry4 = s4 >> 21;
+  s5 += carry4;
+  s4 -= carry4 << 21;
+  carry5 = s5 >> 21;
+  s6 += carry5;
+  s5 -= carry5 << 21;
+  carry6 = s6 >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry7 = s7 >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry8 = s8 >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry9 = s9 >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry10 = s10 >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+
+  s[0] = s0 >> 0;
+  s[1] = s0 >> 8;
+  s[2] = (s0 >> 16) | (s1 << 5);
+  s[3] = s1 >> 3;
+  s[4] = s1 >> 11;
+  s[5] = (s1 >> 19) | (s2 << 2);
+  s[6] = s2 >> 6;
+  s[7] = (s2 >> 14) | (s3 << 7);
+  s[8] = s3 >> 1;
+  s[9] = s3 >> 9;
+  s[10] = (s3 >> 17) | (s4 << 4);
+  s[11] = s4 >> 4;
+  s[12] = s4 >> 12;
+  s[13] = (s4 >> 20) | (s5 << 1);
+  s[14] = s5 >> 7;
+  s[15] = (s5 >> 15) | (s6 << 6);
+  s[16] = s6 >> 2;
+  s[17] = s6 >> 10;
+  s[18] = (s6 >> 18) | (s7 << 3);
+  s[19] = s7 >> 5;
+  s[20] = s7 >> 13;
+  s[21] = s8 >> 0;
+  s[22] = s8 >> 8;
+  s[23] = (s8 >> 16) | (s9 << 5);
+  s[24] = s9 >> 3;
+  s[25] = s9 >> 11;
+  s[26] = (s9 >> 19) | (s10 << 2);
+  s[27] = s10 >> 6;
+  s[28] = (s10 >> 14) | (s11 << 7);
+  s[29] = s11 >> 1;
+  s[30] = s11 >> 9;
+  s[31] = s11 >> 17;
+}
+
+// Input:
+//   a[0]+256*a[1]+...+256^31*a[31] = a
+//   b[0]+256*b[1]+...+256^31*b[31] = b
+//   c[0]+256*c[1]+...+256^31*c[31] = c
+//
+// Output:
+//   s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
+//   where l = 2^252 + 27742317777372353535851937790883648493.
+static void sc_muladd(uint8_t *s, const uint8_t *a, const uint8_t *b,
+                      const uint8_t *c) {
+  int64_t a0 = 2097151 & load_3(a);
+  int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
+  int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
+  int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
+  int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
+  int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
+  int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
+  int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
+  int64_t a8 = 2097151 & load_3(a + 21);
+  int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
+  int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
+  int64_t a11 = (load_4(a + 28) >> 7);
+  int64_t b0 = 2097151 & load_3(b);
+  int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
+  int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
+  int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
+  int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
+  int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
+  int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
+  int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
+  int64_t b8 = 2097151 & load_3(b + 21);
+  int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
+  int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
+  int64_t b11 = (load_4(b + 28) >> 7);
+  int64_t c0 = 2097151 & load_3(c);
+  int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
+  int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
+  int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
+  int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
+  int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
+  int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
+  int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
+  int64_t c8 = 2097151 & load_3(c + 21);
+  int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
+  int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
+  int64_t c11 = (load_4(c + 28) >> 7);
+  int64_t s0;
+  int64_t s1;
+  int64_t s2;
+  int64_t s3;
+  int64_t s4;
+  int64_t s5;
+  int64_t s6;
+  int64_t s7;
+  int64_t s8;
+  int64_t s9;
+  int64_t s10;
+  int64_t s11;
+  int64_t s12;
+  int64_t s13;
+  int64_t s14;
+  int64_t s15;
+  int64_t s16;
+  int64_t s17;
+  int64_t s18;
+  int64_t s19;
+  int64_t s20;
+  int64_t s21;
+  int64_t s22;
+  int64_t s23;
+  int64_t carry0;
+  int64_t carry1;
+  int64_t carry2;
+  int64_t carry3;
+  int64_t carry4;
+  int64_t carry5;
+  int64_t carry6;
+  int64_t carry7;
+  int64_t carry8;
+  int64_t carry9;
+  int64_t carry10;
+  int64_t carry11;
+  int64_t carry12;
+  int64_t carry13;
+  int64_t carry14;
+  int64_t carry15;
+  int64_t carry16;
+  int64_t carry17;
+  int64_t carry18;
+  int64_t carry19;
+  int64_t carry20;
+  int64_t carry21;
+  int64_t carry22;
+
+  s0 = c0 + a0 * b0;
+  s1 = c1 + a0 * b1 + a1 * b0;
+  s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;
+  s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
+  s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
+  s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
+  s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0;
+  s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
+       a6 * b1 + a7 * b0;
+  s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
+       a6 * b2 + a7 * b1 + a8 * b0;
+  s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
+       a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
+  s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
+        a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
+  s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
+        a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
+  s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 +
+        a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
+  s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 +
+        a9 * b4 + a10 * b3 + a11 * b2;
+  s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 +
+        a10 * b4 + a11 * b3;
+  s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 +
+        a11 * b4;
+  s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
+  s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
+  s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
+  s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
+  s20 = a9 * b11 + a10 * b10 + a11 * b9;
+  s21 = a10 * b11 + a11 * b10;
+  s22 = a11 * b11;
+  s23 = 0;
+
+  carry0 = (s0 + (1 << 20)) >> 21;
+  s1 += carry0;
+  s0 -= carry0 << 21;
+  carry2 = (s2 + (1 << 20)) >> 21;
+  s3 += carry2;
+  s2 -= carry2 << 21;
+  carry4 = (s4 + (1 << 20)) >> 21;
+  s5 += carry4;
+  s4 -= carry4 << 21;
+  carry6 = (s6 + (1 << 20)) >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry8 = (s8 + (1 << 20)) >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry10 = (s10 + (1 << 20)) >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+  carry12 = (s12 + (1 << 20)) >> 21;
+  s13 += carry12;
+  s12 -= carry12 << 21;
+  carry14 = (s14 + (1 << 20)) >> 21;
+  s15 += carry14;
+  s14 -= carry14 << 21;
+  carry16 = (s16 + (1 << 20)) >> 21;
+  s17 += carry16;
+  s16 -= carry16 << 21;
+  carry18 = (s18 + (1 << 20)) >> 21;
+  s19 += carry18;
+  s18 -= carry18 << 21;
+  carry20 = (s20 + (1 << 20)) >> 21;
+  s21 += carry20;
+  s20 -= carry20 << 21;
+  carry22 = (s22 + (1 << 20)) >> 21;
+  s23 += carry22;
+  s22 -= carry22 << 21;
+
+  carry1 = (s1 + (1 << 20)) >> 21;
+  s2 += carry1;
+  s1 -= carry1 << 21;
+  carry3 = (s3 + (1 << 20)) >> 21;
+  s4 += carry3;
+  s3 -= carry3 << 21;
+  carry5 = (s5 + (1 << 20)) >> 21;
+  s6 += carry5;
+  s5 -= carry5 << 21;
+  carry7 = (s7 + (1 << 20)) >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry9 = (s9 + (1 << 20)) >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry11 = (s11 + (1 << 20)) >> 21;
+  s12 += carry11;
+  s11 -= carry11 << 21;
+  carry13 = (s13 + (1 << 20)) >> 21;
+  s14 += carry13;
+  s13 -= carry13 << 21;
+  carry15 = (s15 + (1 << 20)) >> 21;
+  s16 += carry15;
+  s15 -= carry15 << 21;
+  carry17 = (s17 + (1 << 20)) >> 21;
+  s18 += carry17;
+  s17 -= carry17 << 21;
+  carry19 = (s19 + (1 << 20)) >> 21;
+  s20 += carry19;
+  s19 -= carry19 << 21;
+  carry21 = (s21 + (1 << 20)) >> 21;
+  s22 += carry21;
+  s21 -= carry21 << 21;
+
+  s11 += s23 * 666643;
+  s12 += s23 * 470296;
+  s13 += s23 * 654183;
+  s14 -= s23 * 997805;
+  s15 += s23 * 136657;
+  s16 -= s23 * 683901;
+  s23 = 0;
+
+  s10 += s22 * 666643;
+  s11 += s22 * 470296;
+  s12 += s22 * 654183;
+  s13 -= s22 * 997805;
+  s14 += s22 * 136657;
+  s15 -= s22 * 683901;
+  s22 = 0;
+
+  s9 += s21 * 666643;
+  s10 += s21 * 470296;
+  s11 += s21 * 654183;
+  s12 -= s21 * 997805;
+  s13 += s21 * 136657;
+  s14 -= s21 * 683901;
+  s21 = 0;
+
+  s8 += s20 * 666643;
+  s9 += s20 * 470296;
+  s10 += s20 * 654183;
+  s11 -= s20 * 997805;
+  s12 += s20 * 136657;
+  s13 -= s20 * 683901;
+  s20 = 0;
+
+  s7 += s19 * 666643;
+  s8 += s19 * 470296;
+  s9 += s19 * 654183;
+  s10 -= s19 * 997805;
+  s11 += s19 * 136657;
+  s12 -= s19 * 683901;
+  s19 = 0;
+
+  s6 += s18 * 666643;
+  s7 += s18 * 470296;
+  s8 += s18 * 654183;
+  s9 -= s18 * 997805;
+  s10 += s18 * 136657;
+  s11 -= s18 * 683901;
+  s18 = 0;
+
+  carry6 = (s6 + (1 << 20)) >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry8 = (s8 + (1 << 20)) >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry10 = (s10 + (1 << 20)) >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+  carry12 = (s12 + (1 << 20)) >> 21;
+  s13 += carry12;
+  s12 -= carry12 << 21;
+  carry14 = (s14 + (1 << 20)) >> 21;
+  s15 += carry14;
+  s14 -= carry14 << 21;
+  carry16 = (s16 + (1 << 20)) >> 21;
+  s17 += carry16;
+  s16 -= carry16 << 21;
+
+  carry7 = (s7 + (1 << 20)) >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry9 = (s9 + (1 << 20)) >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry11 = (s11 + (1 << 20)) >> 21;
+  s12 += carry11;
+  s11 -= carry11 << 21;
+  carry13 = (s13 + (1 << 20)) >> 21;
+  s14 += carry13;
+  s13 -= carry13 << 21;
+  carry15 = (s15 + (1 << 20)) >> 21;
+  s16 += carry15;
+  s15 -= carry15 << 21;
+
+  s5 += s17 * 666643;
+  s6 += s17 * 470296;
+  s7 += s17 * 654183;
+  s8 -= s17 * 997805;
+  s9 += s17 * 136657;
+  s10 -= s17 * 683901;
+  s17 = 0;
+
+  s4 += s16 * 666643;
+  s5 += s16 * 470296;
+  s6 += s16 * 654183;
+  s7 -= s16 * 997805;
+  s8 += s16 * 136657;
+  s9 -= s16 * 683901;
+  s16 = 0;
+
+  s3 += s15 * 666643;
+  s4 += s15 * 470296;
+  s5 += s15 * 654183;
+  s6 -= s15 * 997805;
+  s7 += s15 * 136657;
+  s8 -= s15 * 683901;
+  s15 = 0;
+
+  s2 += s14 * 666643;
+  s3 += s14 * 470296;
+  s4 += s14 * 654183;
+  s5 -= s14 * 997805;
+  s6 += s14 * 136657;
+  s7 -= s14 * 683901;
+  s14 = 0;
+
+  s1 += s13 * 666643;
+  s2 += s13 * 470296;
+  s3 += s13 * 654183;
+  s4 -= s13 * 997805;
+  s5 += s13 * 136657;
+  s6 -= s13 * 683901;
+  s13 = 0;
+
+  s0 += s12 * 666643;
+  s1 += s12 * 470296;
+  s2 += s12 * 654183;
+  s3 -= s12 * 997805;
+  s4 += s12 * 136657;
+  s5 -= s12 * 683901;
+  s12 = 0;
+
+  carry0 = (s0 + (1 << 20)) >> 21;
+  s1 += carry0;
+  s0 -= carry0 << 21;
+  carry2 = (s2 + (1 << 20)) >> 21;
+  s3 += carry2;
+  s2 -= carry2 << 21;
+  carry4 = (s4 + (1 << 20)) >> 21;
+  s5 += carry4;
+  s4 -= carry4 << 21;
+  carry6 = (s6 + (1 << 20)) >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry8 = (s8 + (1 << 20)) >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry10 = (s10 + (1 << 20)) >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+
+  carry1 = (s1 + (1 << 20)) >> 21;
+  s2 += carry1;
+  s1 -= carry1 << 21;
+  carry3 = (s3 + (1 << 20)) >> 21;
+  s4 += carry3;
+  s3 -= carry3 << 21;
+  carry5 = (s5 + (1 << 20)) >> 21;
+  s6 += carry5;
+  s5 -= carry5 << 21;
+  carry7 = (s7 + (1 << 20)) >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry9 = (s9 + (1 << 20)) >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry11 = (s11 + (1 << 20)) >> 21;
+  s12 += carry11;
+  s11 -= carry11 << 21;
+
+  s0 += s12 * 666643;
+  s1 += s12 * 470296;
+  s2 += s12 * 654183;
+  s3 -= s12 * 997805;
+  s4 += s12 * 136657;
+  s5 -= s12 * 683901;
+  s12 = 0;
+
+  carry0 = s0 >> 21;
+  s1 += carry0;
+  s0 -= carry0 << 21;
+  carry1 = s1 >> 21;
+  s2 += carry1;
+  s1 -= carry1 << 21;
+  carry2 = s2 >> 21;
+  s3 += carry2;
+  s2 -= carry2 << 21;
+  carry3 = s3 >> 21;
+  s4 += carry3;
+  s3 -= carry3 << 21;
+  carry4 = s4 >> 21;
+  s5 += carry4;
+  s4 -= carry4 << 21;
+  carry5 = s5 >> 21;
+  s6 += carry5;
+  s5 -= carry5 << 21;
+  carry6 = s6 >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry7 = s7 >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry8 = s8 >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry9 = s9 >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry10 = s10 >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+  carry11 = s11 >> 21;
+  s12 += carry11;
+  s11 -= carry11 << 21;
+
+  s0 += s12 * 666643;
+  s1 += s12 * 470296;
+  s2 += s12 * 654183;
+  s3 -= s12 * 997805;
+  s4 += s12 * 136657;
+  s5 -= s12 * 683901;
+  s12 = 0;
+
+  carry0 = s0 >> 21;
+  s1 += carry0;
+  s0 -= carry0 << 21;
+  carry1 = s1 >> 21;
+  s2 += carry1;
+  s1 -= carry1 << 21;
+  carry2 = s2 >> 21;
+  s3 += carry2;
+  s2 -= carry2 << 21;
+  carry3 = s3 >> 21;
+  s4 += carry3;
+  s3 -= carry3 << 21;
+  carry4 = s4 >> 21;
+  s5 += carry4;
+  s4 -= carry4 << 21;
+  carry5 = s5 >> 21;
+  s6 += carry5;
+  s5 -= carry5 << 21;
+  carry6 = s6 >> 21;
+  s7 += carry6;
+  s6 -= carry6 << 21;
+  carry7 = s7 >> 21;
+  s8 += carry7;
+  s7 -= carry7 << 21;
+  carry8 = s8 >> 21;
+  s9 += carry8;
+  s8 -= carry8 << 21;
+  carry9 = s9 >> 21;
+  s10 += carry9;
+  s9 -= carry9 << 21;
+  carry10 = s10 >> 21;
+  s11 += carry10;
+  s10 -= carry10 << 21;
+
+  s[0] = s0 >> 0;
+  s[1] = s0 >> 8;
+  s[2] = (s0 >> 16) | (s1 << 5);
+  s[3] = s1 >> 3;
+  s[4] = s1 >> 11;
+  s[5] = (s1 >> 19) | (s2 << 2);
+  s[6] = s2 >> 6;
+  s[7] = (s2 >> 14) | (s3 << 7);
+  s[8] = s3 >> 1;
+  s[9] = s3 >> 9;
+  s[10] = (s3 >> 17) | (s4 << 4);
+  s[11] = s4 >> 4;
+  s[12] = s4 >> 12;
+  s[13] = (s4 >> 20) | (s5 << 1);
+  s[14] = s5 >> 7;
+  s[15] = (s5 >> 15) | (s6 << 6);
+  s[16] = s6 >> 2;
+  s[17] = s6 >> 10;
+  s[18] = (s6 >> 18) | (s7 << 3);
+  s[19] = s7 >> 5;
+  s[20] = s7 >> 13;
+  s[21] = s8 >> 0;
+  s[22] = s8 >> 8;
+  s[23] = (s8 >> 16) | (s9 << 5);
+  s[24] = s9 >> 3;
+  s[25] = s9 >> 11;
+  s[26] = (s9 >> 19) | (s10 << 2);
+  s[27] = s10 >> 6;
+  s[28] = (s10 >> 14) | (s11 << 7);
+  s[29] = s11 >> 1;
+  s[30] = s11 >> 9;
+  s[31] = s11 >> 17;
+}
+
+void ED25519_keypair(uint8_t out_public_key[32], uint8_t out_private_key[64]) {
+  uint8_t seed[32];
+  RAND_bytes(seed, 32);
+  ED25519_keypair_from_seed(out_public_key, out_private_key, seed);
+}
+
+int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,
+                 const uint8_t private_key[64]) {
+  uint8_t az[SHA512_DIGEST_LENGTH];
+  SHA512(private_key, 32, az);
+
+  az[0] &= 248;
+  az[31] &= 63;
+  az[31] |= 64;
+
+  SHA512_CTX hash_ctx;
+  SHA512_Init(&hash_ctx);
+  SHA512_Update(&hash_ctx, az + 32, 32);
+  SHA512_Update(&hash_ctx, message, message_len);
+  uint8_t nonce[SHA512_DIGEST_LENGTH];
+  SHA512_Final(nonce, &hash_ctx);
+
+  x25519_sc_reduce(nonce);
+  ge_p3 R;
+  x25519_ge_scalarmult_base(&R, nonce);
+  ge_p3_tobytes(out_sig, &R);
+
+  SHA512_Init(&hash_ctx);
+  SHA512_Update(&hash_ctx, out_sig, 32);
+  SHA512_Update(&hash_ctx, private_key + 32, 32);
+  SHA512_Update(&hash_ctx, message, message_len);
+  uint8_t hram[SHA512_DIGEST_LENGTH];
+  SHA512_Final(hram, &hash_ctx);
+
+  x25519_sc_reduce(hram);
+  sc_muladd(out_sig + 32, hram, az, nonce);
+
+  return 1;
+}
+
+int ED25519_verify(const uint8_t *message, size_t message_len,
+                   const uint8_t signature[64], const uint8_t public_key[32]) {
+  ge_p3 A;
+  if ((signature[63] & 224) != 0 ||
+      x25519_ge_frombytes_vartime(&A, public_key) != 0) {
+    return 0;
+  }
+
+  fe_loose t;
+  fe_neg(&t, &A.X);
+  fe_carry(&A.X, &t);
+  fe_neg(&t, &A.T);
+  fe_carry(&A.T, &t);
+
+  uint8_t pkcopy[32];
+  OPENSSL_memcpy(pkcopy, public_key, 32);
+  uint8_t rcopy[32];
+  OPENSSL_memcpy(rcopy, signature, 32);
+  uint8_t scopy[32];
+  OPENSSL_memcpy(scopy, signature + 32, 32);
+
+  SHA512_CTX hash_ctx;
+  SHA512_Init(&hash_ctx);
+  SHA512_Update(&hash_ctx, signature, 32);
+  SHA512_Update(&hash_ctx, public_key, 32);
+  SHA512_Update(&hash_ctx, message, message_len);
+  uint8_t h[SHA512_DIGEST_LENGTH];
+  SHA512_Final(h, &hash_ctx);
+
+  x25519_sc_reduce(h);
+
+  ge_p2 R;
+  ge_double_scalarmult_vartime(&R, h, &A, scopy);
+
+  uint8_t rcheck[32];
+  x25519_ge_tobytes(rcheck, &R);
+
+  return CRYPTO_memcmp(rcheck, rcopy, sizeof(rcheck)) == 0;
+}
+
+void ED25519_keypair_from_seed(uint8_t out_public_key[32],
+                               uint8_t out_private_key[64],
+                               const uint8_t seed[32]) {
+  uint8_t az[SHA512_DIGEST_LENGTH];
+  SHA512(seed, 32, az);
+
+  az[0] &= 248;
+  az[31] &= 63;
+  az[31] |= 64;
+
+  ge_p3 A;
+  x25519_ge_scalarmult_base(&A, az);
+  ge_p3_tobytes(out_public_key, &A);
+
+  OPENSSL_memcpy(out_private_key, seed, 32);
+  OPENSSL_memcpy(out_private_key + 32, out_public_key, 32);
+}
+
+
+#if defined(BORINGSSL_X25519_X86_64)
+
+static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
+                               const uint8_t point[32]) {
+  x25519_x86_64(out, scalar, point);
+}
+
+#else
+
+// Replace (f,g) with (g,f) if b == 1;
+// replace (f,g) with (f,g) if b == 0.
+//
+// Preconditions: b in {0,1}.
+static void fe_cswap(fe *f, fe *g, unsigned int b) {
+  b = 0-b;
+  unsigned i;
+  for (i = 0; i < 10; i++) {
+    uint32_t x = f->v[i] ^ g->v[i];
+    x &= b;
+    f->v[i] ^= x;
+    g->v[i] ^= x;
+  }
+}
+
+// NOTE: based on fiat-crypto fe_mul, edited for in2=121666, 0, 0..
+static void fe_mul_121666_impl(uint32_t out[10], const uint32_t in1[10]) {
+  assert_fe_loose(in1);
+  { const uint32_t x20 = in1[9];
+  { const uint32_t x21 = in1[8];
+  { const uint32_t x19 = in1[7];
+  { const uint32_t x17 = in1[6];
+  { const uint32_t x15 = in1[5];
+  { const uint32_t x13 = in1[4];
+  { const uint32_t x11 = in1[3];
+  { const uint32_t x9 = in1[2];
+  { const uint32_t x7 = in1[1];
+  { const uint32_t x5 = in1[0];
+  { const uint32_t x38 = 0;
+  { const uint32_t x39 = 0;
+  { const uint32_t x37 = 0;
+  { const uint32_t x35 = 0;
+  { const uint32_t x33 = 0;
+  { const uint32_t x31 = 0;
+  { const uint32_t x29 = 0;
+  { const uint32_t x27 = 0;
+  { const uint32_t x25 = 0;
+  { const uint32_t x23 = 121666;
+  { uint64_t x40 = ((uint64_t)x23 * x5);
+  { uint64_t x41 = (((uint64_t)x23 * x7) + ((uint64_t)x25 * x5));
+  { uint64_t x42 = ((((uint64_t)(0x2 * x25) * x7) + ((uint64_t)x23 * x9)) + ((uint64_t)x27 * x5));
+  { uint64_t x43 = (((((uint64_t)x25 * x9) + ((uint64_t)x27 * x7)) + ((uint64_t)x23 * x11)) + ((uint64_t)x29 * x5));
+  { uint64_t x44 = (((((uint64_t)x27 * x9) + (0x2 * (((uint64_t)x25 * x11) + ((uint64_t)x29 * x7)))) + ((uint64_t)x23 * x13)) + ((uint64_t)x31 * x5));
+  { uint64_t x45 = (((((((uint64_t)x27 * x11) + ((uint64_t)x29 * x9)) + ((uint64_t)x25 * x13)) + ((uint64_t)x31 * x7)) + ((uint64_t)x23 * x15)) + ((uint64_t)x33 * x5));
+  { uint64_t x46 = (((((0x2 * ((((uint64_t)x29 * x11) + ((uint64_t)x25 * x15)) + ((uint64_t)x33 * x7))) + ((uint64_t)x27 * x13)) + ((uint64_t)x31 * x9)) + ((uint64_t)x23 * x17)) + ((uint64_t)x35 * x5));
+  { uint64_t x47 = (((((((((uint64_t)x29 * x13) + ((uint64_t)x31 * x11)) + ((uint64_t)x27 * x15)) + ((uint64_t)x33 * x9)) + ((uint64_t)x25 * x17)) + ((uint64_t)x35 * x7)) + ((uint64_t)x23 * x19)) + ((uint64_t)x37 * x5));
+  { uint64_t x48 = (((((((uint64_t)x31 * x13) + (0x2 * (((((uint64_t)x29 * x15) + ((uint64_t)x33 * x11)) + ((uint64_t)x25 * x19)) + ((uint64_t)x37 * x7)))) + ((uint64_t)x27 * x17)) + ((uint64_t)x35 * x9)) + ((uint64_t)x23 * x21)) + ((uint64_t)x39 * x5));
+  { uint64_t x49 = (((((((((((uint64_t)x31 * x15) + ((uint64_t)x33 * x13)) + ((uint64_t)x29 * x17)) + ((uint64_t)x35 * x11)) + ((uint64_t)x27 * x19)) + ((uint64_t)x37 * x9)) + ((uint64_t)x25 * x21)) + ((uint64_t)x39 * x7)) + ((uint64_t)x23 * x20)) + ((uint64_t)x38 * x5));
+  { uint64_t x50 = (((((0x2 * ((((((uint64_t)x33 * x15) + ((uint64_t)x29 * x19)) + ((uint64_t)x37 * x11)) + ((uint64_t)x25 * x20)) + ((uint64_t)x38 * x7))) + ((uint64_t)x31 * x17)) + ((uint64_t)x35 * x13)) + ((uint64_t)x27 * x21)) + ((uint64_t)x39 * x9));
+  { uint64_t x51 = (((((((((uint64_t)x33 * x17) + ((uint64_t)x35 * x15)) + ((uint64_t)x31 * x19)) + ((uint64_t)x37 * x13)) + ((uint64_t)x29 * x21)) + ((uint64_t)x39 * x11)) + ((uint64_t)x27 * x20)) + ((uint64_t)x38 * x9));
+  { uint64_t x52 = (((((uint64_t)x35 * x17) + (0x2 * (((((uint64_t)x33 * x19) + ((uint64_t)x37 * x15)) + ((uint64_t)x29 * x20)) + ((uint64_t)x38 * x11)))) + ((uint64_t)x31 * x21)) + ((uint64_t)x39 * x13));
+  { uint64_t x53 = (((((((uint64_t)x35 * x19) + ((uint64_t)x37 * x17)) + ((uint64_t)x33 * x21)) + ((uint64_t)x39 * x15)) + ((uint64_t)x31 * x20)) + ((uint64_t)x38 * x13));
+  { uint64_t x54 = (((0x2 * ((((uint64_t)x37 * x19) + ((uint64_t)x33 * x20)) + ((uint64_t)x38 * x15))) + ((uint64_t)x35 * x21)) + ((uint64_t)x39 * x17));
+  { uint64_t x55 = (((((uint64_t)x37 * x21) + ((uint64_t)x39 * x19)) + ((uint64_t)x35 * x20)) + ((uint64_t)x38 * x17));
+  { uint64_t x56 = (((uint64_t)x39 * x21) + (0x2 * (((uint64_t)x37 * x20) + ((uint64_t)x38 * x19))));
+  { uint64_t x57 = (((uint64_t)x39 * x20) + ((uint64_t)x38 * x21));
+  { uint64_t x58 = ((uint64_t)(0x2 * x38) * x20);
+  { uint64_t x59 = (x48 + (x58 << 0x4));
+  { uint64_t x60 = (x59 + (x58 << 0x1));
+  { uint64_t x61 = (x60 + x58);
+  { uint64_t x62 = (x47 + (x57 << 0x4));
+  { uint64_t x63 = (x62 + (x57 << 0x1));
+  { uint64_t x64 = (x63 + x57);
+  { uint64_t x65 = (x46 + (x56 << 0x4));
+  { uint64_t x66 = (x65 + (x56 << 0x1));
+  { uint64_t x67 = (x66 + x56);
+  { uint64_t x68 = (x45 + (x55 << 0x4));
+  { uint64_t x69 = (x68 + (x55 << 0x1));
+  { uint64_t x70 = (x69 + x55);
+  { uint64_t x71 = (x44 + (x54 << 0x4));
+  { uint64_t x72 = (x71 + (x54 << 0x1));
+  { uint64_t x73 = (x72 + x54);
+  { uint64_t x74 = (x43 + (x53 << 0x4));
+  { uint64_t x75 = (x74 + (x53 << 0x1));
+  { uint64_t x76 = (x75 + x53);
+  { uint64_t x77 = (x42 + (x52 << 0x4));
+  { uint64_t x78 = (x77 + (x52 << 0x1));
+  { uint64_t x79 = (x78 + x52);
+  { uint64_t x80 = (x41 + (x51 << 0x4));
+  { uint64_t x81 = (x80 + (x51 << 0x1));
+  { uint64_t x82 = (x81 + x51);
+  { uint64_t x83 = (x40 + (x50 << 0x4));
+  { uint64_t x84 = (x83 + (x50 << 0x1));
+  { uint64_t x85 = (x84 + x50);
+  { uint64_t x86 = (x85 >> 0x1a);
+  { uint32_t x87 = ((uint32_t)x85 & 0x3ffffff);
+  { uint64_t x88 = (x86 + x82);
+  { uint64_t x89 = (x88 >> 0x19);
+  { uint32_t x90 = ((uint32_t)x88 & 0x1ffffff);
+  { uint64_t x91 = (x89 + x79);
+  { uint64_t x92 = (x91 >> 0x1a);
+  { uint32_t x93 = ((uint32_t)x91 & 0x3ffffff);
+  { uint64_t x94 = (x92 + x76);
+  { uint64_t x95 = (x94 >> 0x19);
+  { uint32_t x96 = ((uint32_t)x94 & 0x1ffffff);
+  { uint64_t x97 = (x95 + x73);
+  { uint64_t x98 = (x97 >> 0x1a);
+  { uint32_t x99 = ((uint32_t)x97 & 0x3ffffff);
+  { uint64_t x100 = (x98 + x70);
+  { uint64_t x101 = (x100 >> 0x19);
+  { uint32_t x102 = ((uint32_t)x100 & 0x1ffffff);
+  { uint64_t x103 = (x101 + x67);
+  { uint64_t x104 = (x103 >> 0x1a);
+  { uint32_t x105 = ((uint32_t)x103 & 0x3ffffff);
+  { uint64_t x106 = (x104 + x64);
+  { uint64_t x107 = (x106 >> 0x19);
+  { uint32_t x108 = ((uint32_t)x106 & 0x1ffffff);
+  { uint64_t x109 = (x107 + x61);
+  { uint64_t x110 = (x109 >> 0x1a);
+  { uint32_t x111 = ((uint32_t)x109 & 0x3ffffff);
+  { uint64_t x112 = (x110 + x49);
+  { uint64_t x113 = (x112 >> 0x19);
+  { uint32_t x114 = ((uint32_t)x112 & 0x1ffffff);
+  { uint64_t x115 = (x87 + (0x13 * x113));
+  { uint32_t x116 = (uint32_t) (x115 >> 0x1a);
+  { uint32_t x117 = ((uint32_t)x115 & 0x3ffffff);
+  { uint32_t x118 = (x116 + x90);
+  { uint32_t x119 = (x118 >> 0x19);
+  { uint32_t x120 = (x118 & 0x1ffffff);
+  out[0] = x117;
+  out[1] = x120;
+  out[2] = (x119 + x93);
+  out[3] = x96;
+  out[4] = x99;
+  out[5] = x102;
+  out[6] = x105;
+  out[7] = x108;
+  out[8] = x111;
+  out[9] = x114;
+  }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+  assert_fe(out);
+}
+
+static void fe_mul121666(fe *h, const fe_loose *f) {
+  assert_fe_loose(f->v);
+  fe_mul_121666_impl(h->v, f->v);
+  assert_fe(h->v);
+}
+
+static void x25519_scalar_mult_generic(uint8_t out[32],
+                                       const uint8_t scalar[32],
+                                       const uint8_t point[32]) {
+  fe x1, x2, z2, x3, z3, tmp0, tmp1;
+  fe_loose x2l, z2l, x3l, tmp0l, tmp1l;
+
+  uint8_t e[32];
+  OPENSSL_memcpy(e, scalar, 32);
+  e[0] &= 248;
+  e[31] &= 127;
+  e[31] |= 64;
+  fe_frombytes(&x1, point);
+  fe_1(&x2);
+  fe_0(&z2);
+  fe_copy(&x3, &x1);
+  fe_1(&z3);
+
+  unsigned swap = 0;
+  int pos;
+  for (pos = 254; pos >= 0; --pos) {
+    unsigned b = 1 & (e[pos / 8] >> (pos & 7));
+    swap ^= b;
+    fe_cswap(&x2, &x3, swap);
+    fe_cswap(&z2, &z3, swap);
+    swap = b;
+    fe_sub(&tmp0l, &x3, &z3);
+    fe_sub(&tmp1l, &x2, &z2);
+    fe_add(&x2l, &x2, &z2);
+    fe_add(&z2l, &x3, &z3);
+    fe_mul_tll(&z3, &tmp0l, &x2l);
+    fe_mul_tll(&z2, &z2l, &tmp1l);
+    fe_sq_tl(&tmp0, &tmp1l);
+    fe_sq_tl(&tmp1, &x2l);
+    fe_add(&x3l, &z3, &z2);
+    fe_sub(&z2l, &z3, &z2);
+    fe_mul_ttt(&x2, &tmp1, &tmp0);
+    fe_sub(&tmp1l, &tmp1, &tmp0);
+    fe_sq_tl(&z2, &z2l);
+    fe_mul121666(&z3, &tmp1l);
+    fe_sq_tl(&x3, &x3l);
+    fe_add(&tmp0l, &tmp0, &z3);
+    fe_mul_ttt(&z3, &x1, &z2);
+    fe_mul_tll(&z2, &tmp1l, &tmp0l);
+  }
+  fe_cswap(&x2, &x3, swap);
+  fe_cswap(&z2, &z3, swap);
+
+  fe_invert(&z2, &z2);
+  fe_mul_ttt(&x2, &x2, &z2);
+  fe_tobytes(out, &x2);
+}
+
+static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
+                               const uint8_t point[32]) {
+#if defined(BORINGSSL_X25519_NEON)
+  if (CRYPTO_is_NEON_capable()) {
+    x25519_NEON(out, scalar, point);
+    return;
+  }
+#endif
+
+  x25519_scalar_mult_generic(out, scalar, point);
+}
+
+#endif  // BORINGSSL_X25519_X86_64
+
+
+void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]) {
+  RAND_bytes(out_private_key, 32);
+
+  // All X25519 implementations should decode scalars correctly (see
+  // https://tools.ietf.org/html/rfc7748#section-5). However, if an
+  // implementation doesn't then it might interoperate with random keys a
+  // fraction of the time because they'll, randomly, happen to be correctly
+  // formed.
+  //
+  // Thus we do the opposite of the masking here to make sure that our private
+  // keys are never correctly masked and so, hopefully, any incorrect
+  // implementations are deterministically broken.
+  //
+  // This does not affect security because, although we're throwing away
+  // entropy, a valid implementation of scalarmult should throw away the exact
+  // same bits anyway.
+  out_private_key[0] |= 7;
+  out_private_key[31] &= 63;
+  out_private_key[31] |= 128;
+
+  X25519_public_from_private(out_public_value, out_private_key);
+}
+
+int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
+           const uint8_t peer_public_value[32]) {
+  static const uint8_t kZeros[32] = {0};
+  x25519_scalar_mult(out_shared_key, private_key, peer_public_value);
+  // The all-zero output results when the input is a point of small order.
+  return CRYPTO_memcmp(kZeros, out_shared_key, 32) != 0;
+}
+
+#if defined(BORINGSSL_X25519_X86_64)
+
+// When |BORINGSSL_X25519_X86_64| is set, base point multiplication is done with
+// the Montgomery ladder because it's faster. Otherwise it's done using the
+// Ed25519 tables.
+
+void X25519_public_from_private(uint8_t out_public_value[32],
+                                const uint8_t private_key[32]) {
+  static const uint8_t kMongomeryBasePoint[32] = {9};
+  x25519_scalar_mult(out_public_value, private_key, kMongomeryBasePoint);
+}
+
+#else
+
+void X25519_public_from_private(uint8_t out_public_value[32],
+                                const uint8_t private_key[32]) {
+#if defined(BORINGSSL_X25519_NEON)
+  if (CRYPTO_is_NEON_capable()) {
+    static const uint8_t kMongomeryBasePoint[32] = {9};
+    x25519_NEON(out_public_value, private_key, kMongomeryBasePoint);
+    return;
+  }
+#endif
+
+  uint8_t e[32];
+  OPENSSL_memcpy(e, private_key, 32);
+  e[0] &= 248;
+  e[31] &= 127;
+  e[31] |= 64;
+
+  ge_p3 A;
+  x25519_ge_scalarmult_base(&A, e);
+
+  // We only need the u-coordinate of the curve25519 point. The map is
+  // u=(y+1)/(1-y). Since y=Y/Z, this gives u=(Z+Y)/(Z-Y).
+  fe_loose zplusy, zminusy;
+  fe zminusy_inv;
+  fe_add(&zplusy, &A.Z, &A.Y);
+  fe_sub(&zminusy, &A.Z, &A.Y);
+  fe_loose_invert(&zminusy_inv, &zminusy);
+  fe_mul_tlt(&zminusy_inv, &zplusy, &zminusy_inv);
+  fe_tobytes(out_public_value, &zminusy_inv);
+}
+
+#endif  // BORINGSSL_X25519_X86_64
diff --git a/src/third_party/fiat/internal.h b/src/third_party/fiat/internal.h
new file mode 100644
index 0000000..10218e0
--- /dev/null
+++ b/src/third_party/fiat/internal.h
@@ -0,0 +1,142 @@
+// The MIT License (MIT)
+//
+// Copyright (c) 2015-2016 the fiat-crypto authors (see the AUTHORS file).
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#ifndef OPENSSL_HEADER_CURVE25519_INTERNAL_H
+#define OPENSSL_HEADER_CURVE25519_INTERNAL_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+#if defined(OPENSSL_X86_64) && !defined(OPENSSL_SMALL) && \
+    !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_ASM)
+#define BORINGSSL_X25519_X86_64
+
+void x25519_x86_64(uint8_t out[32], const uint8_t scalar[32],
+                   const uint8_t point[32]);
+#endif
+
+
+#if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
+#define BORINGSSL_X25519_NEON
+
+// x25519_NEON is defined in asm/x25519-arm.S.
+void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
+                 const uint8_t point[32]);
+#endif
+
+// fe means field element. Here the field is \Z/(2^255-19). An element t,
+// entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
+// t[3]+2^102 t[4]+...+2^230 t[9].
+// fe limbs are bounded by 1.125*2^26,1.125*2^25,1.125*2^26,1.125*2^25,etc.
+// Multiplication and carrying produce fe from fe_loose.
+typedef struct fe { uint32_t v[10]; } fe;
+
+// fe_loose limbs are bounded by 3.375*2^26,3.375*2^25,3.375*2^26,3.375*2^25,etc.
+// Addition and subtraction produce fe_loose from (fe, fe).
+typedef struct fe_loose { uint32_t v[10]; } fe_loose;
+
+/* ge means group element.
+
+ * Here the group is the set of pairs (x,y) of field elements (see fe.h)
+ * satisfying -x^2 + y^2 = 1 + d x^2y^2
+ * where d = -121665/121666.
+ *
+ * Representations:
+ *   ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
+ *   ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
+ *   ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
+ *   ge_precomp (Duif): (y+x,y-x,2dxy) */
+
+typedef struct {
+  fe X;
+  fe Y;
+  fe Z;
+} ge_p2;
+
+typedef struct {
+  fe X;
+  fe Y;
+  fe Z;
+  fe T;
+} ge_p3;
+
+typedef struct {
+  fe_loose X;
+  fe_loose Y;
+  fe_loose Z;
+  fe_loose T;
+} ge_p1p1;
+
+typedef struct {
+  fe_loose yplusx;
+  fe_loose yminusx;
+  fe_loose xy2d;
+} ge_precomp;
+
+typedef struct {
+  fe_loose YplusX;
+  fe_loose YminusX;
+  fe_loose Z;
+  fe_loose T2d;
+} ge_cached;
+
+void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h);
+int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
+void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
+void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
+void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
+void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
+void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
+void x25519_ge_scalarmult_small_precomp(
+    ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]);
+void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
+void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
+void x25519_sc_reduce(uint8_t *s);
+
+enum spake2_state_t {
+  spake2_state_init = 0,
+  spake2_state_msg_generated,
+  spake2_state_key_generated,
+};
+
+struct spake2_ctx_st {
+  uint8_t private_key[32];
+  uint8_t my_msg[32];
+  uint8_t password_scalar[32];
+  uint8_t password_hash[64];
+  uint8_t *my_name;
+  size_t my_name_len;
+  uint8_t *their_name;
+  size_t their_name_len;
+  enum spake2_role_t my_role;
+  enum spake2_state_t state;
+  char disable_password_scalar_hack;
+};
+
+
+#if defined(__cplusplus)
+}  // extern C
+#endif
+
+#endif  // OPENSSL_HEADER_CURVE25519_INTERNAL_H
diff --git a/src/tool/client.cc b/src/tool/client.cc
index 2ec381f..873cea0 100644
--- a/src/tool/client.cc
+++ b/src/tool/client.cc
@@ -323,6 +323,10 @@
     *out = tls13_default;
     return true;
   }
+  if (in == "draft21") {
+    *out = tls13_draft21;
+    return true;
+  }
   if (in == "experiment") {
     *out = tls13_experiment;
     return true;
diff --git a/src/tool/server.cc b/src/tool/server.cc
index b6ed284..0061cb3 100644
--- a/src/tool/server.cc
+++ b/src/tool/server.cc
@@ -80,6 +80,10 @@
         "Print debug information about the handshake",
     },
     {
+        "-require-any-client-cert", kBooleanArgument,
+        "The server will require a client certificate.",
+    },
+    {
         "", kOptionalArgument, "",
     },
 };
@@ -320,6 +324,14 @@
     SSL_CTX_set_info_callback(ctx.get(), InfoCallback);
   }
 
+  if (args_map.count("-require-any-client-cert") != 0) {
+    SSL_CTX_set_verify(
+        ctx.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr);
+    SSL_CTX_set_cert_verify_callback(
+        ctx.get(), [](X509_STORE_CTX *store, void *arg) -> int { return 1; },
+        nullptr);
+  }
+
   Listener listener;
   if (!listener.Init(args_map["-accept"])) {
     return false;
diff --git a/src/tool/transport_common.cc b/src/tool/transport_common.cc
index a7c2b36..1a80678 100644
--- a/src/tool/transport_common.cc
+++ b/src/tool/transport_common.cc
@@ -234,38 +234,6 @@
   return false;
 }
 
-static const char *SignatureAlgorithmToString(uint16_t version, uint16_t sigalg) {
-  const bool is_tls12 = version == TLS1_2_VERSION || version == DTLS1_2_VERSION;
-  switch (sigalg) {
-    case SSL_SIGN_RSA_PKCS1_SHA1:
-      return "rsa_pkcs1_sha1";
-    case SSL_SIGN_RSA_PKCS1_SHA256:
-      return "rsa_pkcs1_sha256";
-    case SSL_SIGN_RSA_PKCS1_SHA384:
-      return "rsa_pkcs1_sha384";
-    case SSL_SIGN_RSA_PKCS1_SHA512:
-      return "rsa_pkcs1_sha512";
-    case SSL_SIGN_ECDSA_SHA1:
-      return "ecdsa_sha1";
-    case SSL_SIGN_ECDSA_SECP256R1_SHA256:
-      return is_tls12 ? "ecdsa_sha256" : "ecdsa_secp256r1_sha256";
-    case SSL_SIGN_ECDSA_SECP384R1_SHA384:
-      return is_tls12 ? "ecdsa_sha384" : "ecdsa_secp384r1_sha384";
-    case SSL_SIGN_ECDSA_SECP521R1_SHA512:
-      return is_tls12 ? "ecdsa_sha512" : "ecdsa_secp521r1_sha512";
-    case SSL_SIGN_RSA_PSS_SHA256:
-      return "rsa_pss_sha256";
-    case SSL_SIGN_RSA_PSS_SHA384:
-      return "rsa_pss_sha384";
-    case SSL_SIGN_RSA_PSS_SHA512:
-      return "rsa_pss_sha512";
-    case SSL_SIGN_ED25519:
-      return "ed25519";
-    default:
-      return "(unknown)";
-  }
-}
-
 void PrintConnectionInfo(BIO *bio, const SSL *ssl) {
   const SSL_CIPHER *cipher = SSL_get_current_cipher(ssl);
 
@@ -280,7 +248,8 @@
   uint16_t sigalg = SSL_get_peer_signature_algorithm(ssl);
   if (sigalg != 0) {
     BIO_printf(bio, "  Signature algorithm: %s\n",
-               SignatureAlgorithmToString(SSL_version(ssl), sigalg));
+               SSL_get_signature_algorithm_name(
+                   sigalg, SSL_version(ssl) != TLS1_2_VERSION));
   }
   BIO_printf(bio, "  Secure renegotiation: %s\n",
              SSL_get_secure_renegotiation_support(ssl) ? "yes" : "no");
diff --git a/src/util/bot/DEPS b/src/util/bot/DEPS
index 0d67e3d..7b9f39e 100644
--- a/src/util/bot/DEPS
+++ b/src/util/bot/DEPS
@@ -22,7 +22,7 @@
 
 deps = {
   'boringssl/util/bot/android_tools': {
-    'url': Var('chromium_git') + '/android_tools.git' + '@' + 'ca9dc7245b888c75307f0619e4a39fb46a82de66',
+    'url': Var('chromium_git') + '/android_tools.git' + '@' + 'ca0bd083872ad925881736fe2bedc3ff855e08f5',
     'condition': 'checkout_android',
   },
 
diff --git a/src/util/bot/go/bootstrap.py b/src/util/bot/go/bootstrap.py
index 86335aa..ec5aa3e 100755
--- a/src/util/bot/go/bootstrap.py
+++ b/src/util/bot/go/bootstrap.py
@@ -45,7 +45,7 @@
 EXE_SFX = '.exe' if sys.platform == 'win32' else ''
 
 # Pinned version of Go toolset to download.
-TOOLSET_VERSION = 'go1.9.1'
+TOOLSET_VERSION = 'go1.9.2'
 
 # Platform dependent portion of a download URL. See http://golang.org/dl/.
 TOOLSET_VARIANTS = {
diff --git a/src/util/bot/update_clang.py b/src/util/bot/update_clang.py
index 3164750..ee66153 100644
--- a/src/util/bot/update_clang.py
+++ b/src/util/bot/update_clang.py
@@ -19,8 +19,8 @@
 # CLANG_REVISION and CLANG_SUB_REVISION determine the build of clang
 # to use. These should be synced with tools/clang/scripts/update.py in
 # Chromium.
-CLANG_REVISION = '313786'
-CLANG_SUB_REVISION=1
+CLANG_REVISION = '315613'
+CLANG_SUB_REVISION=2
 
 PACKAGE_VERSION = "%s-%s" % (CLANG_REVISION, CLANG_SUB_REVISION)
 
diff --git a/src/util/bot/vs_toolchain.py b/src/util/bot/vs_toolchain.py
index 64da79a..153a6ed 100644
--- a/src/util/bot/vs_toolchain.py
+++ b/src/util/bot/vs_toolchain.py
@@ -87,8 +87,8 @@
     # Update 3 final with 10.0.15063.468 SDK and no vctip.exe.
     return ['f53e4598951162bad6330f7a167486c7ae5db1e5']
   if env_version == '2017':
-    # VS 2017 Update 3.2 with 10.0.15063.468 SDK and patched setenv.cmd.
-    return ['a9e1098bba66d2acccc377d5ee81265910f29272']
+    # VS 2017 Update 4 with 10.0.15063.468 SDK.
+    return ['88c3b62e1eb0893b8cd57e3f4859c3af27907f64']
   raise Exception('Unsupported VS version %s' % env_version)
 
 
diff --git a/src/util/generate_build_files.py b/src/util/generate_build_files.py
index 738484d..4b4a899 100644
--- a/src/util/generate_build_files.py
+++ b/src/util/generate_build_files.py
@@ -587,7 +587,8 @@
 
 def main(platforms):
   cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake'))
-  crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments)
+  crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) +
+                    FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments))
   fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
   ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
   tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
@@ -638,8 +639,9 @@
           NotSSLHeaderFiles))
 
   ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
-  crypto_internal_h_files = FindHeaderFiles(
-      os.path.join('src', 'crypto'), NoTests)
+  crypto_internal_h_files = (
+      FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) +
+      FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests))
 
   files = {
       'crypto': crypto_c_files,
diff --git a/src/util/make_errors.go b/src/util/make_errors.go
index 22fbd6a..2525a69 100644
--- a/src/util/make_errors.go
+++ b/src/util/make_errors.go
@@ -110,7 +110,7 @@
 	}
 
 	for _, name := range filenames {
-		if !strings.HasSuffix(name, ".c") {
+		if !strings.HasSuffix(name, ".c") && !strings.HasSuffix(name, ".cc") {
 			continue
 		}
 
@@ -136,7 +136,12 @@
 	if err := writeHeaderFile(newHeaderFile, headerFile, prefix, reasons); err != nil {
 		return err
 	}
-	os.Rename(headerPath+".tmp", headerPath)
+	// Windows forbids renaming an open file.
+	headerFile.Close()
+	newHeaderFile.Close()
+	if err := os.Rename(headerPath+".tmp", headerPath); err != nil {
+		return err
+	}
 
 	dataFile, err := os.OpenFile(dataPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
 	if err != nil {