More miscellaneous bools.

Change-Id: I0960fed68ef39e4523ef9f2ba89ffa92f09c4dce
Reviewed-on: https://boringssl-review.googlesource.com/19945
Reviewed-by: Steven Valdez <svaldez@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/d1_pkt.cc b/ssl/d1_pkt.cc
index 7a1c229..a3095e1 100644
--- a/ssl/d1_pkt.cc
+++ b/ssl/d1_pkt.cc
@@ -205,11 +205,11 @@
   return -1;
 }
 
-int dtls1_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
-                        int peek) {
+int dtls1_read_app_data(SSL *ssl, bool *out_got_handshake, uint8_t *buf,
+                        int len, int peek) {
   assert(!SSL_in_init(ssl));
 
-  *out_got_handshake = 0;
+  *out_got_handshake = false;
   SSL3_RECORD *rr = &ssl->s3->rrec;
 
 again:
@@ -298,10 +298,10 @@
   }
 }
 
-int dtls1_write_app_data(SSL *ssl, int *out_needs_handshake, const uint8_t *buf,
-                         int len) {
+int dtls1_write_app_data(SSL *ssl, bool *out_needs_handshake,
+                         const uint8_t *buf, int len) {
   assert(!SSL_in_init(ssl));
-  *out_needs_handshake = 0;
+  *out_needs_handshake = false;
 
   if (len > SSL3_RT_MAX_PLAIN_LENGTH) {
     OPENSSL_PUT_ERROR(SSL, SSL_R_DTLS_MESSAGE_TOO_BIG);
diff --git a/ssl/handshake.cc b/ssl/handshake.cc
index 8d74b7b..5770d6f 100644
--- a/ssl/handshake.cc
+++ b/ssl/handshake.cc
@@ -439,7 +439,7 @@
   return ssl_hs_ok;
 }
 
-int ssl_run_handshake(SSL_HANDSHAKE *hs, int *out_early_return) {
+int ssl_run_handshake(SSL_HANDSHAKE *hs, bool *out_early_return) {
   SSL *const ssl = hs->ssl;
   for (;;) {
     // Resolve the operation the handshake was waiting on.
@@ -489,7 +489,7 @@
       case ssl_hs_read_end_of_early_data: {
         if (ssl->s3->hs->can_early_read) {
           // While we are processing early data, the handshake returns early.
-          *out_early_return = 1;
+          *out_early_return = true;
           return 1;
         }
         hs->wait = ssl_hs_ok;
@@ -538,7 +538,7 @@
         return -1;
 
       case ssl_hs_early_return:
-        *out_early_return = 1;
+        *out_early_return = true;
         hs->wait = ssl_hs_ok;
         return 1;
 
@@ -555,6 +555,7 @@
     }
     if (hs->wait == ssl_hs_ok) {
       // The handshake has completed.
+      *out_early_return = false;
       return 1;
     }
 
diff --git a/ssl/handshake_client.cc b/ssl/handshake_client.cc
index 3469017..a779b8a 100644
--- a/ssl/handshake_client.cc
+++ b/ssl/handshake_client.cc
@@ -401,7 +401,7 @@
     return 0;
   }
 
-  int have_supported_versions;
+  bool have_supported_versions;
   CBS supported_versions;
   const SSL_EXTENSION_TYPE ext_types[] = {
     {TLSEXT_TYPE_supported_versions, &have_supported_versions,
diff --git a/ssl/internal.h b/ssl/internal.h
index b59de99..19968ac 100644
--- a/ssl/internal.h
+++ b/ssl/internal.h
@@ -1324,7 +1324,7 @@
 // ssl_run_handshake runs the TLS handshake. It returns one on success and <= 0
 // on error. It sets |out_early_return| to one if we've completed the handshake
 // early.
-int ssl_run_handshake(SSL_HANDSHAKE *hs, int *out_early_return);
+int ssl_run_handshake(SSL_HANDSHAKE *hs, bool *out_early_return);
 
 // The following are implementations of |do_handshake| for the client and
 // server.
@@ -1367,7 +1367,7 @@
 int ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t **out_secret,
                                         size_t *out_secret_len,
                                         uint8_t *out_alert, CBS *contents);
-int ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, int *out_found,
+int ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, bool *out_found,
                                         uint8_t **out_secret,
                                         size_t *out_secret_len,
                                         uint8_t *out_alert, CBS *contents);
@@ -1413,7 +1413,7 @@
 
 struct SSL_EXTENSION_TYPE {
   uint16_t type;
-  int *out_present;
+  bool *out_present;
   CBS *out_data;
 };
 
@@ -2161,12 +2161,12 @@
 
 int ssl3_send_finished(SSL_HANDSHAKE *hs);
 int ssl3_dispatch_alert(SSL *ssl);
-int ssl3_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
+int ssl3_read_app_data(SSL *ssl, bool *out_got_handshake, uint8_t *buf, int len,
                        int peek);
 int ssl3_read_change_cipher_spec(SSL *ssl);
 void ssl3_read_close_notify(SSL *ssl);
 int ssl3_read_handshake_bytes(SSL *ssl, uint8_t *buf, int len);
-int ssl3_write_app_data(SSL *ssl, int *out_needs_handshake, const uint8_t *buf,
+int ssl3_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
                         int len);
 int ssl3_output_cert_chain(SSL *ssl);
 
@@ -2201,13 +2201,13 @@
 // more data is needed.
 int dtls1_get_record(SSL *ssl);
 
-int dtls1_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
-                        int peek);
+int dtls1_read_app_data(SSL *ssl, bool *out_got_handshake, uint8_t *buf,
+                        int len, int peek);
 int dtls1_read_change_cipher_spec(SSL *ssl);
 void dtls1_read_close_notify(SSL *ssl);
 
-int dtls1_write_app_data(SSL *ssl, int *out_needs_handshake, const uint8_t *buf,
-                         int len);
+int dtls1_write_app_data(SSL *ssl, bool *out_needs_handshake,
+                         const uint8_t *buf, int len);
 
 // dtls1_write_record sends a record. It returns one on success and <= 0 on
 // error.
@@ -2388,11 +2388,11 @@
   // and sets |*out_got_handshake| to whether the failure was due to a
   // post-handshake handshake message. If so, any handshake messages consumed
   // may be read with |get_message|.
-  int (*read_app_data)(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
+  int (*read_app_data)(SSL *ssl, bool *out_got_handshake, uint8_t *buf, int len,
                        int peek);
   int (*read_change_cipher_spec)(SSL *ssl);
   void (*read_close_notify)(SSL *ssl);
-  int (*write_app_data)(SSL *ssl, int *out_needs_handshake, const uint8_t *buf,
+  int (*write_app_data)(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
                         int len);
   int (*dispatch_alert)(SSL *ssl);
   // supports_cipher returns one if |cipher| is supported by this protocol and
diff --git a/ssl/s3_pkt.cc b/ssl/s3_pkt.cc
index 7afe3dd..b9eebf3 100644
--- a/ssl/s3_pkt.cc
+++ b/ssl/s3_pkt.cc
@@ -191,12 +191,12 @@
   return -1;
 }
 
-int ssl3_write_app_data(SSL *ssl, int *out_needs_handshake, const uint8_t *buf,
+int ssl3_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
                         int len) {
   assert(ssl_can_write(ssl));
   assert(!ssl->s3->aead_write_ctx->is_null_cipher());
 
-  *out_needs_handshake = 0;
+  *out_needs_handshake = false;
 
   unsigned tot, n, nw;
 
@@ -229,7 +229,7 @@
       if (max == 0) {
         ssl->s3->wnum = tot;
         ssl->s3->hs->can_early_write = false;
-        *out_needs_handshake = 1;
+        *out_needs_handshake = true;
         return -1;
       }
     }
@@ -370,11 +370,11 @@
   return len;
 }
 
-int ssl3_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
+int ssl3_read_app_data(SSL *ssl, bool *out_got_handshake, uint8_t *buf, int len,
                        int peek) {
   assert(ssl_can_read(ssl));
   assert(!ssl->s3->aead_read_ctx->is_null_cipher());
-  *out_got_handshake = 0;
+  *out_got_handshake = false;
 
   SSL3_RECORD *rr = &ssl->s3->rrec;
 
@@ -414,7 +414,7 @@
       if (ret <= 0) {
         return ret;
       }
-      *out_got_handshake = 1;
+      *out_got_handshake = true;
       return -1;
     }
 
@@ -434,7 +434,7 @@
       ssl_read_buffer_discard(ssl);
       // Stop accepting early data.
       ssl->s3->hs->can_early_read = false;
-      *out_got_handshake = 1;
+      *out_got_handshake = true;
       return -1;
     }
 
diff --git a/ssl/ssl_lib.cc b/ssl/ssl_lib.cc
index ee2cd89..853994b 100644
--- a/ssl/ssl_lib.cc
+++ b/ssl/ssl_lib.cc
@@ -800,7 +800,7 @@
   // Run the handshake.
   SSL_HANDSHAKE *hs = ssl->s3->hs;
 
-  int early_return = 0;
+  bool early_return = false;
   int ret = ssl_run_handshake(hs, &early_return);
   ssl_do_info_callback(
       ssl, ssl->server ? SSL_CB_ACCEPT_EXIT : SSL_CB_CONNECT_EXIT, ret);
@@ -921,7 +921,7 @@
       }
     }
 
-    int got_handshake;
+    bool got_handshake = false;
     int ret = ssl->method->read_app_data(ssl, &got_handshake, (uint8_t *)buf,
                                          num, peek);
     if (ret > 0 || !got_handshake) {
@@ -967,7 +967,8 @@
     return -1;
   }
 
-  int ret = 0, needs_handshake = 0;
+  int ret = 0;
+  bool needs_handshake = false;
   do {
     // If necessary, complete the handshake implicitly.
     if (!ssl_can_write(ssl)) {
diff --git a/ssl/t1_lib.cc b/ssl/t1_lib.cc
index a978fb3..481c9f8 100644
--- a/ssl/t1_lib.cc
+++ b/ssl/t1_lib.cc
@@ -2215,7 +2215,7 @@
   return 1;
 }
 
-int ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, int *out_found,
+int ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, bool *out_found,
                                         uint8_t **out_secret,
                                         size_t *out_secret_len,
                                         uint8_t *out_alert, CBS *contents) {
@@ -2234,7 +2234,7 @@
   }
 
   // Find the corresponding key share.
-  int found = 0;
+  bool found = false;
   CBS peer_key;
   while (CBS_len(&key_shares) > 0) {
     uint16_t id;
@@ -2252,14 +2252,14 @@
         return 0;
       }
 
-      found = 1;
+      found = true;
       peer_key = peer_key_tmp;
       // Continue parsing the structure to keep peers honest.
     }
   }
 
   if (!found) {
-    *out_found = 0;
+    *out_found = false;
     *out_secret = NULL;
     *out_secret_len = 0;
     return 1;
@@ -2283,7 +2283,7 @@
 
   *out_secret = secret;
   *out_secret_len = secret_len;
-  *out_found = 1;
+  *out_found = true;
   return 1;
 }
 
diff --git a/ssl/tls13_both.cc b/ssl/tls13_both.cc
index 10b944f..e0fefe3 100644
--- a/ssl/tls13_both.cc
+++ b/ssl/tls13_both.cc
@@ -154,7 +154,7 @@
     }
 
     // Parse out the extensions.
-    int have_status_request = 0, have_sct = 0;
+    bool have_status_request = false, have_sct = false;
     CBS status_request, sct;
     const SSL_EXTENSION_TYPE ext_types[] = {
         {TLSEXT_TYPE_status_request, &have_status_request, &status_request},
diff --git a/ssl/tls13_client.cc b/ssl/tls13_client.cc
index df79960..f91da26 100644
--- a/ssl/tls13_client.cc
+++ b/ssl/tls13_client.cc
@@ -74,7 +74,7 @@
     return ssl_hs_error;
   }
 
-  int have_cookie, have_key_share;
+  bool have_cookie, have_key_share;
   CBS cookie, key_share;
   const SSL_EXTENSION_TYPE ext_types[] = {
       {TLSEXT_TYPE_key_share, &have_key_share, &key_share},
@@ -226,7 +226,8 @@
   }
 
   // Parse out the extensions.
-  int have_key_share = 0, have_pre_shared_key = 0, have_supported_versions = 0;
+  bool have_key_share = false, have_pre_shared_key = false,
+       have_supported_versions = false;
   CBS key_share, pre_shared_key, supported_versions;
   const SSL_EXTENSION_TYPE ext_types[] = {
       {TLSEXT_TYPE_key_share, &have_key_share, &key_share},
@@ -811,7 +812,7 @@
   }
 
   // Parse out the extensions.
-  int have_early_data_info = 0;
+  bool have_early_data_info = false;
   CBS early_data_info;
   const SSL_EXTENSION_TYPE ext_types[] = {
       {TLSEXT_TYPE_ticket_early_data_info, &have_early_data_info,
diff --git a/ssl/tls13_server.cc b/ssl/tls13_server.cc
index a46d0c8..65c2f11 100644
--- a/ssl/tls13_server.cc
+++ b/ssl/tls13_server.cc
@@ -73,7 +73,7 @@
     return 0;
   }
 
-  int found_key_share;
+  bool found_key_share;
   uint8_t *dhe_secret;
   size_t dhe_secret_len;
   uint8_t alert = SSL_AD_DECODE_ERROR;