aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-11-13 11:58:53 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-11-13 11:58:53 +0100
commitd5a0405a6fa2d17bf86e059dfc35efcba52f120c (patch)
treebc029818158bc5a549d85bc2557ab6898d818402
parentde7b5bb59a5d89f8b63284c6a9de5a5a95f02db3 (diff)
downloadbusybox-w32-d5a0405a6fa2d17bf86e059dfc35efcba52f120c.tar.gz
busybox-w32-d5a0405a6fa2d17bf86e059dfc35efcba52f120c.tar.bz2
busybox-w32-d5a0405a6fa2d17bf86e059dfc35efcba52f120c.zip
tls: code shrink
function old new delta tls_get_zeroed_outbuf - 28 +28 static.empty_client_cert 7 - -7 tls_handshake 1930 1890 -40 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/1 up/down: 28/-47) Total: -19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/tls.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/networking/tls.c b/networking/tls.c
index 20343bc0a..90a1bcf35 100644
--- a/networking/tls.c
+++ b/networking/tls.c
@@ -602,6 +602,13 @@ static void *tls_get_outbuf(tls_state_t *tls, int len)
602 return tls->outbuf + OUTBUF_PFX; 602 return tls->outbuf + OUTBUF_PFX;
603} 603}
604 604
605static void *tls_get_zeroed_outbuf(tls_state_t *tls, int len)
606{
607 void *record = tls_get_outbuf(tls, len);
608 memset(record, 0, len);
609 return record;
610}
611
605static void xwrite_encrypted(tls_state_t *tls, unsigned size, unsigned type) 612static void xwrite_encrypted(tls_state_t *tls, unsigned size, unsigned type)
606{ 613{
607 uint8_t *buf = tls->outbuf + OUTBUF_PFX; 614 uint8_t *buf = tls->outbuf + OUTBUF_PFX;
@@ -1332,8 +1339,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1332 1339
1333 /* +2 is for "len of all extensions" 2-byte field */ 1340 /* +2 is for "len of all extensions" 2-byte field */
1334 len = sizeof(*record) + 2 + ext_len; 1341 len = sizeof(*record) + 2 + ext_len;
1335 record = tls_get_outbuf(tls, len); 1342 record = tls_get_zeroed_outbuf(tls, len);
1336 memset(record, 0, len);
1337 1343
1338 fill_handshake_record_hdr(record, HANDSHAKE_CLIENT_HELLO, len); 1344 fill_handshake_record_hdr(record, HANDSHAKE_CLIENT_HELLO, len);
1339 record->proto_maj = TLS_MAJ; /* the "requested" version of the protocol, */ 1345 record->proto_maj = TLS_MAJ; /* the "requested" version of the protocol, */
@@ -1565,19 +1571,15 @@ static void send_empty_client_cert(tls_state_t *tls)
1565 uint8_t cert_chain_len24_hi, cert_chain_len24_mid, cert_chain_len24_lo; 1571 uint8_t cert_chain_len24_hi, cert_chain_len24_mid, cert_chain_len24_lo;
1566 }; 1572 };
1567 struct client_empty_cert *record; 1573 struct client_empty_cert *record;
1568 static const uint8_t empty_client_cert[] = {
1569 HANDSHAKE_CERTIFICATE,
1570 0, 0, 3, //len24
1571 0, 0, 0, //cert_chain_len24
1572 };
1573 1574
1574 record = tls_get_outbuf(tls, sizeof(*record)); 1575 record = tls_get_zeroed_outbuf(tls, sizeof(*record));
1575 //fill_handshake_record_hdr(record, HANDSHAKE_CERTIFICATE, sizeof(*record)); 1576 //fill_handshake_record_hdr(record, HANDSHAKE_CERTIFICATE, sizeof(*record));
1576 //record->cert_chain_len24_hi = 0; 1577 //record->cert_chain_len24_hi = 0;
1577 //record->cert_chain_len24_mid = 0; 1578 //record->cert_chain_len24_mid = 0;
1578 //record->cert_chain_len24_lo = 0; 1579 //record->cert_chain_len24_lo = 0;
1579 // same as above: 1580 // same as above:
1580 memcpy(record, empty_client_cert, sizeof(empty_client_cert)); 1581 record->type = HANDSHAKE_CERTIFICATE;
1582 record->len24_lo = 3;
1581 1583
1582 dbg(">> CERTIFICATE\n"); 1584 dbg(">> CERTIFICATE\n");
1583 xwrite_and_update_handshake_hash(tls, sizeof(*record)); 1585 xwrite_and_update_handshake_hash(tls, sizeof(*record));
@@ -1591,7 +1593,7 @@ static void send_client_key_exchange(tls_state_t *tls)
1591 uint8_t key[2 + 4 * 1024]; // size?? 1593 uint8_t key[2 + 4 * 1024]; // size??
1592 }; 1594 };
1593//FIXME: better size estimate 1595//FIXME: better size estimate
1594 struct client_key_exchange *record = tls_get_outbuf(tls, sizeof(*record)); 1596 struct client_key_exchange *record = tls_get_zeroed_outbuf(tls, sizeof(*record));
1595 uint8_t rsa_premaster[RSA_PREMASTER_SIZE]; 1597 uint8_t rsa_premaster[RSA_PREMASTER_SIZE];
1596 uint8_t x25519_premaster[CURVE25519_KEYSIZE]; 1598 uint8_t x25519_premaster[CURVE25519_KEYSIZE];
1597 uint8_t *premaster; 1599 uint8_t *premaster;
@@ -1646,7 +1648,7 @@ static void send_client_key_exchange(tls_state_t *tls)
1646 } 1648 }
1647 1649
1648 record->type = HANDSHAKE_CLIENT_KEY_EXCHANGE; 1650 record->type = HANDSHAKE_CLIENT_KEY_EXCHANGE;
1649 record->len24_hi = 0; 1651 /* record->len24_hi = 0; - already is */
1650 record->len24_mid = len >> 8; 1652 record->len24_mid = len >> 8;
1651 record->len24_lo = len & 0xff; 1653 record->len24_lo = len & 0xff;
1652 len += 4; 1654 len += 4;