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;