Remove dtls_write_records
authorMatt Caswell <matt@openssl.org>
Mon, 17 Oct 2022 14:07:47 +0000 (15:07 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 20 Oct 2022 13:39:33 +0000 (14:39 +0100)
The dtls_write_records function, after the previous series of commits,
was functionally equivalent to tls_write_records_default - so it can be
removed completely.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19424)

ssl/record/methods/dtls_meth.c
ssl/record/methods/recmethod_local.h
ssl/record/methods/tls1_meth.c
ssl/record/methods/tlsany_meth.c

index 9a24d5f8ad5e1497d169873954753d2e540e7fad..e867adc382e32f79e4f43cf7002671952a4c06fb 100644 (file)
@@ -735,106 +735,6 @@ int dtls_post_encryption_processing(OSSL_RECORD_LAYER *rl,
     return tls_increment_sequence_ctr(rl);
 }
 
-int dtls_write_records(OSSL_RECORD_LAYER *rl, OSSL_RECORD_TEMPLATE *templates,
-                       size_t numtempl)
-{
-    int mac_size = 0;
-    SSL3_RECORD wr;
-    SSL3_BUFFER *wb;
-    WPACKET pkt, *thispkt = &pkt;
-    size_t wpinited = 0;
-    int ret = 0;
-    unsigned char *compressdata = NULL;
-
-    if (rl->md_ctx != NULL && EVP_MD_CTX_get0_md(rl->md_ctx) != NULL) {
-        mac_size = EVP_MD_CTX_get_size(rl->md_ctx);
-        if (mac_size < 0) {
-            RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
-            return 0;
-        }
-    }
-
-    if (numtempl != 1) {
-        /* Should not happen */
-        RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
-        return 0;
-    }
-
-    if (!rl->funcs->allocate_write_buffers(rl, templates, numtempl, NULL)) {
-        /* RLAYERfatal() already called */
-        return 0;
-    }
-
-    if (!rl->funcs->initialise_write_packets(rl, templates, numtempl,
-                                             NULL, thispkt, rl->wbuf,
-                                             &wpinited)) {
-        /* RLAYERfatal() already called */
-        return 0;
-    }
-
-    wb = rl->wbuf;
-
-    SSL3_RECORD_set_type(&wr, templates->type);
-    SSL3_RECORD_set_rec_version(&wr, templates->version);
-
-    if (!rl->funcs->prepare_record_header(rl, thispkt, templates,
-                                          templates->type, &compressdata)) {
-        /* RLAYERfatal() already called */
-        goto err;
-    }
-
-    /* lets setup the record stuff. */
-    SSL3_RECORD_set_data(&wr, compressdata);
-    SSL3_RECORD_set_length(&wr, templates->buflen);
-    SSL3_RECORD_set_input(&wr, (unsigned char *)templates->buf);
-
-    /*
-     * we now 'read' from wr.input, wr.length bytes into wr.data
-     */
-
-    /* first we compress */
-    if (rl->compctx != NULL) {
-        if (!tls_do_compress(rl, &wr)
-                || !WPACKET_allocate_bytes(thispkt, wr.length, NULL)) {
-            RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, SSL_R_COMPRESSION_FAILURE);
-            goto err;
-        }
-    } else if (compressdata != NULL) {
-        if (!WPACKET_memcpy(thispkt, wr.input, wr.length)) {
-            RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
-            goto err;
-        }
-        SSL3_RECORD_reset_input(&wr);
-    }
-
-    if (!rl->funcs->prepare_for_encryption(rl, mac_size, thispkt, &wr)) {
-        /* RLAYERfatal() already called */
-        goto err;
-    }
-
-    if (rl->funcs->cipher(rl, &wr, 1, 1, NULL, mac_size) < 1) {
-        if (rl->alert == SSL_AD_NO_ALERT) {
-            RLAYERfatal(rl, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
-        }
-        goto err;
-    }
-
-    if (!rl->funcs->post_encryption_processing(rl, mac_size, templates,
-                                               thispkt, &wr)) {
-        /* RLAYERfatal() already called */
-        goto err;
-    }
-
-    /* now let's set up wb */
-    SSL3_BUFFER_set_left(wb, SSL3_RECORD_get_length(&wr));
-
-    ret = 1;
- err:
-    if (wpinited > 0)
-        WPACKET_cleanup(thispkt);
-    return ret;
-}
-
 static size_t dtls_get_max_record_overhead(OSSL_RECORD_LAYER *rl)
 {
     size_t blocksize, mac_size;
index a25dd9d70fbc535b890b640e310d658f65df687c..2552a8c0acec2862ffec98feda11a0aeeea58904 100644 (file)
@@ -361,8 +361,6 @@ int dtls_post_encryption_processing(OSSL_RECORD_LAYER *rl,
                                     OSSL_RECORD_TEMPLATE *thistempl,
                                     WPACKET *thispkt,
                                     SSL3_RECORD *thiswr);
-int dtls_write_records(OSSL_RECORD_LAYER *rl, OSSL_RECORD_TEMPLATE *templates,
-                       size_t numtempl);
 
 int tls_default_set_protocol_version(OSSL_RECORD_LAYER *rl, int version);
 int tls_default_validate_record_header(OSSL_RECORD_LAYER *rl, SSL3_RECORD *re);
index 232f055c52007877da435ab1fa5368fa04ed4d72..1007efc57a37624aff69cab14858f550d45abdb3 100644 (file)
@@ -669,7 +669,7 @@ struct record_functions_st dtls_1_funcs = {
     NULL,
     NULL,
     NULL,
-    dtls_write_records,
+    tls_write_records_default,
     /*
      * Don't use tls1_allocate_write_buffers since that handles empty fragment
      * records which aren't needed in DTLS. We just use the default allocation
index c2a1e0d09021b15042a528c72a5cbaea4cee9719..e52bebfba0c5414df2ce8b8217a46e138d6f0406 100644 (file)
@@ -183,7 +183,7 @@ struct record_functions_st dtls_any_funcs = {
     NULL,
     NULL,
     NULL,
-    dtls_write_records,
+    tls_write_records_default,
     tls_allocate_write_buffers_default,
     tls_initialise_write_packets_default,
     NULL,