@@ -1533,6 +1533,35 @@ int tls_initialise_write_packets_default(OSSL_RECORD_LAYER *rl,
15331533 return 1 ;
15341534}
15351535
1536+ int tls_prepare_record_header_default (OSSL_RECORD_LAYER * rl ,
1537+ WPACKET * thispkt ,
1538+ OSSL_RECORD_TEMPLATE * templ ,
1539+ unsigned int rectype ,
1540+ unsigned char * * recdata )
1541+ {
1542+ size_t maxcomplen ;
1543+
1544+ * recdata = NULL ;
1545+
1546+ maxcomplen = templ -> buflen ;
1547+ if (rl -> compctx != NULL )
1548+ maxcomplen += SSL3_RT_MAX_COMPRESSED_OVERHEAD ;
1549+
1550+ if (!WPACKET_put_bytes_u8 (thispkt , rectype )
1551+ || !WPACKET_put_bytes_u16 (thispkt , templ -> version )
1552+ || !WPACKET_start_sub_packet_u16 (thispkt )
1553+ || (rl -> eivlen > 0
1554+ && !WPACKET_allocate_bytes (thispkt , rl -> eivlen , NULL ))
1555+ || (maxcomplen > 0
1556+ && !WPACKET_reserve_bytes (thispkt , maxcomplen ,
1557+ recdata ))) {
1558+ RLAYERfatal (rl , SSL_AD_INTERNAL_ERROR , ERR_R_INTERNAL_ERROR );
1559+ return 0 ;
1560+ }
1561+
1562+ return 1 ;
1563+ }
1564+
15361565int tls_write_records_default (OSSL_RECORD_LAYER * rl ,
15371566 OSSL_RECORD_TEMPLATE * templates ,
15381567 size_t numtempl )
@@ -1579,7 +1608,6 @@ int tls_write_records_default(OSSL_RECORD_LAYER *rl,
15791608 memset (wr , 0 , sizeof (wr ));
15801609 for (j = 0 ; j < numtempl + prefix ; j ++ ) {
15811610 unsigned char * compressdata = NULL ;
1582- size_t maxcomplen ;
15831611 unsigned int rectype ;
15841612
15851613 thispkt = & pkt [j ];
@@ -1598,23 +1626,8 @@ int tls_write_records_default(OSSL_RECORD_LAYER *rl,
15981626 SSL3_RECORD_set_type (thiswr , rectype );
15991627 SSL3_RECORD_set_rec_version (thiswr , thistempl -> version );
16001628
1601- maxcomplen = thistempl -> buflen ;
1602- if (rl -> compctx != NULL )
1603- maxcomplen += SSL3_RT_MAX_COMPRESSED_OVERHEAD ;
1604-
1605- /*
1606- * When using offload kernel will write the header.
1607- * Otherwise write the header now
1608- */
1609- if (!using_ktls
1610- && (!WPACKET_put_bytes_u8 (thispkt , rectype )
1611- || !WPACKET_put_bytes_u16 (thispkt , thistempl -> version )
1612- || !WPACKET_start_sub_packet_u16 (thispkt )
1613- || (rl -> eivlen > 0
1614- && !WPACKET_allocate_bytes (thispkt , rl -> eivlen , NULL ))
1615- || (maxcomplen > 0
1616- && !WPACKET_reserve_bytes (thispkt , maxcomplen ,
1617- & compressdata )))) {
1629+ if (!rl -> funcs -> prepare_record_header (rl , thispkt , thistempl , rectype ,
1630+ & compressdata )) {
16181631 RLAYERfatal (rl , SSL_AD_INTERNAL_ERROR , ERR_R_INTERNAL_ERROR );
16191632 goto err ;
16201633 }
@@ -1637,16 +1650,12 @@ int tls_write_records_default(OSSL_RECORD_LAYER *rl,
16371650 RLAYERfatal (rl , SSL_AD_INTERNAL_ERROR , SSL_R_COMPRESSION_FAILURE );
16381651 goto err ;
16391652 }
1640- } else {
1641- if (using_ktls ) {
1642- SSL3_RECORD_reset_data (& wr [j ]);
1643- } else {
1644- if (!WPACKET_memcpy (thispkt , thiswr -> input , thiswr -> length )) {
1645- RLAYERfatal (rl , SSL_AD_INTERNAL_ERROR , ERR_R_INTERNAL_ERROR );
1646- goto err ;
1647- }
1648- SSL3_RECORD_reset_input (& wr [j ]);
1653+ } else if (compressdata != NULL ) {
1654+ if (!WPACKET_memcpy (thispkt , thiswr -> input , thiswr -> length )) {
1655+ RLAYERfatal (rl , SSL_AD_INTERNAL_ERROR , ERR_R_INTERNAL_ERROR );
1656+ goto err ;
16491657 }
1658+ SSL3_RECORD_reset_input (& wr [j ]);
16501659 }
16511660
16521661 if (rl -> version == TLS1_3_VERSION
0 commit comments