Move ssl_handshake_new, etc., into s3_both.c.

s3_both.c does a few too many things right now, but SSL_HANDSHAKE is not
only for TLS 1.3.

Change-Id: Ieac17c592a1271d4d5c9cee005eaf5642772b8f5
Reviewed-on: https://boringssl-review.googlesource.com/10443
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/ssl/s3_both.c b/ssl/s3_both.c
index cb5d0da..30429e5 100644
--- a/ssl/s3_both.c
+++ b/ssl/s3_both.c
@@ -130,6 +130,44 @@
 #include "internal.h"
 
 
+SSL_HANDSHAKE *ssl_handshake_new(enum ssl_hs_wait_t (*do_handshake)(SSL *ssl)) {
+  SSL_HANDSHAKE *hs = OPENSSL_malloc(sizeof(SSL_HANDSHAKE));
+  if (hs == NULL) {
+    OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
+    return NULL;
+  }
+  memset(hs, 0, sizeof(SSL_HANDSHAKE));
+  hs->do_handshake = do_handshake;
+  hs->wait = ssl_hs_ok;
+  return hs;
+}
+
+void ssl_handshake_clear_groups(SSL_HANDSHAKE *hs) {
+  if (hs->groups == NULL) {
+    return;
+  }
+
+  for (size_t i = 0; i < hs->groups_len; i++) {
+    SSL_ECDH_CTX_cleanup(&hs->groups[i]);
+  }
+  OPENSSL_free(hs->groups);
+  hs->groups = NULL;
+  hs->groups_len = 0;
+}
+
+void ssl_handshake_free(SSL_HANDSHAKE *hs) {
+  if (hs == NULL) {
+    return;
+  }
+
+  OPENSSL_cleanse(hs->secret, sizeof(hs->secret));
+  OPENSSL_cleanse(hs->traffic_secret_0, sizeof(hs->traffic_secret_0));
+  ssl_handshake_clear_groups(hs);
+  OPENSSL_free(hs->key_share_bytes);
+  OPENSSL_free(hs->public_key);
+  OPENSSL_free(hs);
+}
+
 /* ssl3_do_write sends |ssl->init_buf| in records of type 'type'
  * (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC). It returns 1 on success
  * and <= 0 on error. */
diff --git a/ssl/tls13_both.c b/ssl/tls13_both.c
index 9dd27ce..2a2fe2f 100644
--- a/ssl/tls13_both.c
+++ b/ssl/tls13_both.c
@@ -28,44 +28,6 @@
 #include "internal.h"
 
 
-SSL_HANDSHAKE *ssl_handshake_new(enum ssl_hs_wait_t (*do_handshake)(SSL *ssl)) {
-  SSL_HANDSHAKE *hs = OPENSSL_malloc(sizeof(SSL_HANDSHAKE));
-  if (hs == NULL) {
-    OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
-    return NULL;
-  }
-  memset(hs, 0, sizeof(SSL_HANDSHAKE));
-  hs->do_handshake = do_handshake;
-  hs->wait = ssl_hs_ok;
-  return hs;
-}
-
-void ssl_handshake_clear_groups(SSL_HANDSHAKE *hs) {
-  if (hs->groups == NULL) {
-    return;
-  }
-
-  for (size_t i = 0; i < hs->groups_len; i++) {
-    SSL_ECDH_CTX_cleanup(&hs->groups[i]);
-  }
-  OPENSSL_free(hs->groups);
-  hs->groups = NULL;
-  hs->groups_len = 0;
-}
-
-void ssl_handshake_free(SSL_HANDSHAKE *hs) {
-  if (hs == NULL) {
-    return;
-  }
-
-  OPENSSL_cleanse(hs->secret, sizeof(hs->secret));
-  OPENSSL_cleanse(hs->traffic_secret_0, sizeof(hs->traffic_secret_0));
-  ssl_handshake_clear_groups(hs);
-  OPENSSL_free(hs->key_share_bytes);
-  OPENSSL_free(hs->public_key);
-  OPENSSL_free(hs);
-}
-
 int tls13_handshake(SSL *ssl) {
   SSL_HANDSHAKE *hs = ssl->s3->hs;