2 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "../ssl_local.h"
12 #include <openssl/trace.h>
13 #include <openssl/rand.h>
14 #include <openssl/core_names.h>
15 #include "record_local.h"
16 #include "internal/cryptlib.h"
18 static const unsigned char ssl3_pad_1[48] = {
19 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
20 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
21 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
22 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
23 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
24 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
27 static const unsigned char ssl3_pad_2[48] = {
28 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
29 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
30 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
31 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
32 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
33 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c
37 * Clear the contents of an SSL3_RECORD but retain any memory allocated
39 void SSL3_RECORD_clear(SSL3_RECORD *r, size_t num_recs)
44 for (i = 0; i < num_recs; i++) {
47 memset(&r[i], 0, sizeof(*r));
52 void SSL3_RECORD_release(SSL3_RECORD *r, size_t num_recs)
56 for (i = 0; i < num_recs; i++) {
57 OPENSSL_free(r[i].comp);
62 void SSL3_RECORD_set_seq_num(SSL3_RECORD *r, const unsigned char *seq_num)
64 memcpy(r->seq_num, seq_num, SEQ_NUM_SIZE);
67 uint32_t ossl_get_max_early_data(SSL_CONNECTION *s)
69 uint32_t max_early_data;
70 SSL_SESSION *sess = s->session;
73 * If we are a client then we always use the max_early_data from the
74 * session/psksession. Otherwise we go with the lowest out of the max early
75 * data set in the session and the configured max_early_data.
77 if (!s->server && sess->ext.max_early_data == 0) {
78 if (!ossl_assert(s->psksession != NULL
79 && s->psksession->ext.max_early_data > 0)) {
80 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
87 max_early_data = sess->ext.max_early_data;
88 else if (s->ext.early_data != SSL_EARLY_DATA_ACCEPTED)
89 max_early_data = s->recv_max_early_data;
91 max_early_data = s->recv_max_early_data < sess->ext.max_early_data
92 ? s->recv_max_early_data : sess->ext.max_early_data;
94 return max_early_data;
97 int ossl_early_data_count_ok(SSL_CONNECTION *s, size_t length, size_t overhead,
100 uint32_t max_early_data;
102 max_early_data = ossl_get_max_early_data(s);
104 if (max_early_data == 0) {
105 SSLfatal(s, send ? SSL_AD_INTERNAL_ERROR : SSL_AD_UNEXPECTED_MESSAGE,
106 SSL_R_TOO_MUCH_EARLY_DATA);
110 /* If we are dealing with ciphertext we need to allow for the overhead */
111 max_early_data += overhead;
113 if (s->early_data_count + length > max_early_data) {
114 SSLfatal(s, send ? SSL_AD_INTERNAL_ERROR : SSL_AD_UNEXPECTED_MESSAGE,
115 SSL_R_TOO_MUCH_EARLY_DATA);
118 s->early_data_count += length;
123 int ssl3_do_uncompress(SSL_CONNECTION *ssl, SSL3_RECORD *rr)
125 #ifndef OPENSSL_NO_COMP
128 if (rr->comp == NULL) {
129 rr->comp = (unsigned char *)
130 OPENSSL_malloc(SSL3_RT_MAX_ENCRYPTED_LENGTH);
132 if (rr->comp == NULL)
135 i = COMP_expand_block(ssl->expand, rr->comp,
136 SSL3_RT_MAX_PLAIN_LENGTH, rr->data, (int)rr->length);
146 int ssl3_do_compress(SSL_CONNECTION *sc, SSL3_RECORD *wr)
148 #ifndef OPENSSL_NO_COMP
151 i = COMP_compress_block(sc->compress, wr->data,
152 (int)(wr->length + SSL3_RT_MAX_COMPRESSED_OVERHEAD),
153 wr->input, (int)wr->length);
159 wr->input = wr->data;
165 * ssl3_enc encrypts/decrypts |n_recs| records in |inrecs|. Calls SSLfatal on
166 * internal error, but not otherwise. It is the responsibility of the caller to
167 * report a bad_record_mac
170 * 0: if the record is publicly invalid, or an internal error
171 * 1: Success or Mac-then-encrypt decryption failed (MAC will be randomised)
173 int ssl3_enc(SSL_CONNECTION *s, SSL3_RECORD *inrecs, size_t n_recs, int sending,
174 SSL_MAC_BUF *mac, size_t macsize)
180 const EVP_CIPHER *enc;
184 * We shouldn't ever be called with more than one record in the SSLv3 case
189 ds = s->enc_write_ctx;
190 if (s->enc_write_ctx == NULL)
193 enc = EVP_CIPHER_CTX_get0_cipher(s->enc_write_ctx);
195 ds = s->enc_read_ctx;
196 if (s->enc_read_ctx == NULL)
199 enc = EVP_CIPHER_CTX_get0_cipher(s->enc_read_ctx);
202 if ((s->session == NULL) || (ds == NULL) || (enc == NULL)) {
203 memmove(rec->data, rec->input, rec->length);
204 rec->input = rec->data;
206 int provided = (EVP_CIPHER_get0_provider(enc) != NULL);
209 bs = EVP_CIPHER_CTX_get_block_size(ds);
213 if ((bs != 1) && sending && !provided) {
215 * We only do this for legacy ciphers. Provided ciphers add the
216 * padding on the provider side.
220 /* we need to add 'i-1' padding bytes */
223 * the last of these zero bytes will be overwritten with the
226 memset(&rec->input[rec->length], 0, i);
228 rec->input[l - 1] = (unsigned char)(i - 1);
232 if (l == 0 || l % bs != 0) {
233 /* Publicly invalid */
236 /* otherwise, rec->length >= bs */
239 if (EVP_CIPHER_get0_provider(enc) != NULL) {
242 if (!EVP_CipherUpdate(ds, rec->data, &outlen, rec->input,
245 rec->length = outlen;
247 if (!sending && mac != NULL) {
248 /* Now get a pointer to the MAC */
249 OSSL_PARAM params[2], *p = params;
254 *p++ = OSSL_PARAM_construct_octet_ptr(OSSL_CIPHER_PARAM_TLS_MAC,
257 *p = OSSL_PARAM_construct_end();
259 if (!EVP_CIPHER_CTX_get_params(ds, params)) {
260 /* Shouldn't normally happen */
261 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
266 if (EVP_Cipher(ds, rec->data, rec->input, (unsigned int)l) < 1) {
267 /* Shouldn't happen */
268 SSLfatal(s, SSL_AD_BAD_RECORD_MAC, ERR_R_INTERNAL_ERROR);
273 return ssl3_cbc_remove_padding_and_mac(&rec->length,
276 (mac != NULL) ? &mac->mac : NULL,
277 (mac != NULL) ? &mac->alloced : NULL,
280 SSL_CONNECTION_GET_CTX(s)->libctx);
286 #define MAX_PADDING 256
288 * tls1_enc encrypts/decrypts |n_recs| in |recs|. Calls SSLfatal on internal
289 * error, but not otherwise. It is the responsibility of the caller to report
290 * a bad_record_mac - if appropriate (DTLS just drops the record).
293 * 0: if the record is publicly invalid, or an internal error, or AEAD
294 * decryption failed, or Encrypt-then-mac decryption failed.
295 * 1: Success or Mac-then-encrypt decryption failed (MAC will be randomised)
297 int tls1_enc(SSL_CONNECTION *s, SSL3_RECORD *recs, size_t n_recs, int sending,
298 SSL_MAC_BUF *macs, size_t macsize)
301 size_t reclen[SSL_MAX_PIPELINES];
302 unsigned char buf[SSL_MAX_PIPELINES][EVP_AEAD_TLS1_AAD_LEN];
303 int i, pad = 0, tmpr;
304 size_t bs, ctr, padnum, loop;
305 unsigned char padval;
306 const EVP_CIPHER *enc;
307 int tlstree_enc = sending ? (s->mac_flags & SSL_MAC_FLAG_WRITE_MAC_TLSTREE)
308 : (s->mac_flags & SSL_MAC_FLAG_READ_MAC_TLSTREE);
311 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
316 if (EVP_MD_CTX_get0_md(s->write_hash)) {
317 int n = EVP_MD_CTX_get_size(s->write_hash);
318 if (!ossl_assert(n >= 0)) {
319 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
323 ds = s->enc_write_ctx;
324 if (s->enc_write_ctx == NULL)
329 enc = EVP_CIPHER_CTX_get0_cipher(s->enc_write_ctx);
330 /* For TLSv1.1 and later explicit IV */
331 if (SSL_USE_EXPLICIT_IV(s)
332 && EVP_CIPHER_get_mode(enc) == EVP_CIPH_CBC_MODE)
333 ivlen = EVP_CIPHER_get_iv_length(enc);
337 for (ctr = 0; ctr < n_recs; ctr++) {
338 if (recs[ctr].data != recs[ctr].input) {
340 * we can't write into the input stream: Can this ever
343 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
345 } else if (RAND_bytes_ex(SSL_CONNECTION_GET_CTX(s)->libctx,
348 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
355 if (EVP_MD_CTX_get0_md(s->read_hash)) {
356 int n = EVP_MD_CTX_get_size(s->read_hash);
357 if (!ossl_assert(n >= 0)) {
358 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
362 ds = s->enc_read_ctx;
363 if (s->enc_read_ctx == NULL)
366 enc = EVP_CIPHER_CTX_get0_cipher(s->enc_read_ctx);
369 if ((s->session == NULL) || (ds == NULL) || (enc == NULL)) {
370 for (ctr = 0; ctr < n_recs; ctr++) {
371 memmove(recs[ctr].data, recs[ctr].input, recs[ctr].length);
372 recs[ctr].input = recs[ctr].data;
375 int provided = (EVP_CIPHER_get0_provider(enc) != NULL);
377 bs = EVP_CIPHER_get_block_size(EVP_CIPHER_CTX_get0_cipher(ds));
380 if ((EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(ds))
381 & EVP_CIPH_FLAG_PIPELINE) == 0) {
383 * We shouldn't have been called with pipeline data if the
384 * cipher doesn't support pipelining
386 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_PIPELINE_FAILURE);
390 for (ctr = 0; ctr < n_recs; ctr++) {
391 reclen[ctr] = recs[ctr].length;
393 if ((EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(ds))
394 & EVP_CIPH_FLAG_AEAD_CIPHER) != 0) {
397 seq = sending ? RECORD_LAYER_get_write_sequence(&s->rlayer)
398 : RECORD_LAYER_get_read_sequence(&s->rlayer);
400 if (SSL_CONNECTION_IS_DTLS(s)) {
401 /* DTLS does not support pipelining */
402 unsigned char dtlsseq[8], *p = dtlsseq;
404 s2n(sending ? DTLS_RECORD_LAYER_get_w_epoch(&s->rlayer) :
405 DTLS_RECORD_LAYER_get_r_epoch(&s->rlayer), p);
406 memcpy(p, &seq[2], 6);
407 memcpy(buf[ctr], dtlsseq, 8);
409 memcpy(buf[ctr], seq, 8);
410 for (i = 7; i >= 0; i--) { /* increment */
417 buf[ctr][8] = recs[ctr].type;
418 buf[ctr][9] = (unsigned char)(s->version >> 8);
419 buf[ctr][10] = (unsigned char)(s->version);
420 buf[ctr][11] = (unsigned char)(recs[ctr].length >> 8);
421 buf[ctr][12] = (unsigned char)(recs[ctr].length & 0xff);
422 pad = EVP_CIPHER_CTX_ctrl(ds, EVP_CTRL_AEAD_TLS1_AAD,
423 EVP_AEAD_TLS1_AAD_LEN, buf[ctr]);
425 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
431 recs[ctr].length += pad;
434 } else if ((bs != 1) && sending && !provided) {
436 * We only do this for legacy ciphers. Provided ciphers add the
437 * padding on the provider side.
439 padnum = bs - (reclen[ctr] % bs);
441 /* Add weird padding of up to 256 bytes */
443 if (padnum > MAX_PADDING) {
444 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
447 /* we need to add 'padnum' padding bytes of value padval */
448 padval = (unsigned char)(padnum - 1);
449 for (loop = reclen[ctr]; loop < reclen[ctr] + padnum; loop++)
450 recs[ctr].input[loop] = padval;
451 reclen[ctr] += padnum;
452 recs[ctr].length += padnum;
456 if (reclen[ctr] == 0 || reclen[ctr] % bs != 0) {
457 /* Publicly invalid */
463 unsigned char *data[SSL_MAX_PIPELINES];
465 /* Set the output buffers */
466 for (ctr = 0; ctr < n_recs; ctr++) {
467 data[ctr] = recs[ctr].data;
469 if (EVP_CIPHER_CTX_ctrl(ds, EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS,
470 (int)n_recs, data) <= 0) {
471 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_PIPELINE_FAILURE);
474 /* Set the input buffers */
475 for (ctr = 0; ctr < n_recs; ctr++) {
476 data[ctr] = recs[ctr].input;
478 if (EVP_CIPHER_CTX_ctrl(ds, EVP_CTRL_SET_PIPELINE_INPUT_BUFS,
479 (int)n_recs, data) <= 0
480 || EVP_CIPHER_CTX_ctrl(ds, EVP_CTRL_SET_PIPELINE_INPUT_LENS,
481 (int)n_recs, reclen) <= 0) {
482 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_PIPELINE_FAILURE);
487 if (!SSL_CONNECTION_IS_DTLS(s) && tlstree_enc) {
489 int decrement_seq = 0;
492 * When sending, seq is incremented after MAC calculation.
493 * So if we are in ETM mode, we use seq 'as is' in the ctrl-function.
494 * Otherwise we have to decrease it in the implementation
496 if (sending && !SSL_WRITE_ETM(s))
499 seq = sending ? RECORD_LAYER_get_write_sequence(&s->rlayer)
500 : RECORD_LAYER_get_read_sequence(&s->rlayer);
501 if (EVP_CIPHER_CTX_ctrl(ds, EVP_CTRL_TLSTREE, decrement_seq, seq) <= 0) {
502 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
510 /* Provided cipher - we do not support pipelining on this path */
512 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
516 if (!EVP_CipherUpdate(ds, recs[0].data, &outlen, recs[0].input,
517 (unsigned int)reclen[0]))
519 recs[0].length = outlen;
522 * The length returned from EVP_CipherUpdate above is the actual
523 * payload length. We need to adjust the data/input ptr to skip over
527 if (EVP_CIPHER_get_mode(enc) == EVP_CIPH_GCM_MODE) {
528 recs[0].data += EVP_GCM_TLS_EXPLICIT_IV_LEN;
529 recs[0].input += EVP_GCM_TLS_EXPLICIT_IV_LEN;
530 } else if (EVP_CIPHER_get_mode(enc) == EVP_CIPH_CCM_MODE) {
531 recs[0].data += EVP_CCM_TLS_EXPLICIT_IV_LEN;
532 recs[0].input += EVP_CCM_TLS_EXPLICIT_IV_LEN;
533 } else if (bs != 1 && SSL_USE_EXPLICIT_IV(s)) {
536 recs[0].orig_len -= bs;
539 /* Now get a pointer to the MAC (if applicable) */
541 OSSL_PARAM params[2], *p = params;
546 *p++ = OSSL_PARAM_construct_octet_ptr(OSSL_CIPHER_PARAM_TLS_MAC,
547 (void **)&macs[0].mac,
549 *p = OSSL_PARAM_construct_end();
551 if (!EVP_CIPHER_CTX_get_params(ds, params)) {
552 /* Shouldn't normally happen */
553 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
554 ERR_R_INTERNAL_ERROR);
562 tmpr = EVP_Cipher(ds, recs[0].data, recs[0].input,
563 (unsigned int)reclen[0]);
564 if ((EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(ds))
565 & EVP_CIPH_FLAG_CUSTOM_CIPHER) != 0
568 /* AEAD can fail to verify MAC */
573 for (ctr = 0; ctr < n_recs; ctr++) {
574 /* Adjust the record to remove the explicit IV/MAC/Tag */
575 if (EVP_CIPHER_get_mode(enc) == EVP_CIPH_GCM_MODE) {
576 recs[ctr].data += EVP_GCM_TLS_EXPLICIT_IV_LEN;
577 recs[ctr].input += EVP_GCM_TLS_EXPLICIT_IV_LEN;
578 recs[ctr].length -= EVP_GCM_TLS_EXPLICIT_IV_LEN;
579 } else if (EVP_CIPHER_get_mode(enc) == EVP_CIPH_CCM_MODE) {
580 recs[ctr].data += EVP_CCM_TLS_EXPLICIT_IV_LEN;
581 recs[ctr].input += EVP_CCM_TLS_EXPLICIT_IV_LEN;
582 recs[ctr].length -= EVP_CCM_TLS_EXPLICIT_IV_LEN;
583 } else if (bs != 1 && SSL_USE_EXPLICIT_IV(s)) {
584 if (recs[ctr].length < bs)
586 recs[ctr].data += bs;
587 recs[ctr].input += bs;
588 recs[ctr].length -= bs;
589 recs[ctr].orig_len -= bs;
593 * If using Mac-then-encrypt, then this will succeed but
594 * with a random MAC if padding is invalid
596 if (!tls1_cbc_remove_padding_and_mac(&recs[ctr].length,
599 (macs != NULL) ? &macs[ctr].mac : NULL,
600 (macs != NULL) ? &macs[ctr].alloced
603 pad ? (size_t)pad : macsize,
604 (EVP_CIPHER_get_flags(enc)
605 & EVP_CIPH_FLAG_AEAD_CIPHER) != 0,
606 SSL_CONNECTION_GET_CTX(s)->libctx))
615 int n_ssl3_mac(SSL_CONNECTION *sc, SSL3_RECORD *rec, unsigned char *md,
618 unsigned char *mac_sec, *seq;
619 const EVP_MD_CTX *hash;
620 unsigned char *p, rec_char;
624 unsigned int md_size_u;
628 * All read record layer operations should have been moved to the new
633 mac_sec = &(sc->s3.write_mac_secret[0]);
634 seq = RECORD_LAYER_get_write_sequence(&sc->rlayer);
635 hash = sc->write_hash;
637 t = EVP_MD_CTX_get_size(hash);
641 npad = (48 / md_size) * md_size;
643 /* Chop the digest off the end :-) */
644 md_ctx = EVP_MD_CTX_new();
649 rec_char = rec->type;
652 if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
653 || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
654 || EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0
655 || EVP_DigestUpdate(md_ctx, seq, 8) <= 0
656 || EVP_DigestUpdate(md_ctx, &rec_char, 1) <= 0
657 || EVP_DigestUpdate(md_ctx, md, 2) <= 0
658 || EVP_DigestUpdate(md_ctx, rec->input, rec->length) <= 0
659 || EVP_DigestFinal_ex(md_ctx, md, NULL) <= 0
660 || EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
661 || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
662 || EVP_DigestUpdate(md_ctx, ssl3_pad_2, npad) <= 0
663 || EVP_DigestUpdate(md_ctx, md, md_size) <= 0
664 || EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {
665 EVP_MD_CTX_free(md_ctx);
669 EVP_MD_CTX_free(md_ctx);
671 ssl3_record_sequence_update(seq);
675 int tls1_mac_old(SSL_CONNECTION *sc, SSL3_RECORD *rec, unsigned char *md,
682 EVP_MD_CTX *hmac = NULL, *mac_ctx;
683 unsigned char header[13];
684 int stream_mac = sending ? (sc->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM)
685 : (sc->mac_flags & SSL_MAC_FLAG_READ_MAC_STREAM);
686 int tlstree_mac = sending ? (sc->mac_flags & SSL_MAC_FLAG_WRITE_MAC_TLSTREE)
687 : (sc->mac_flags & SSL_MAC_FLAG_READ_MAC_TLSTREE);
692 * All read record layer calls should have been moved to the new record
697 seq = RECORD_LAYER_get_write_sequence(&sc->rlayer);
698 hash = sc->write_hash;
700 t = EVP_MD_CTX_get_size(hash);
701 if (!ossl_assert(t >= 0))
705 /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */
709 hmac = EVP_MD_CTX_new();
710 if (hmac == NULL || !EVP_MD_CTX_copy(hmac, hash)) {
716 if (!SSL_CONNECTION_IS_DTLS(sc) && tlstree_mac
717 && EVP_MD_CTX_ctrl(mac_ctx, EVP_MD_CTRL_TLSTREE, 0, seq) <= 0) {
721 if (SSL_CONNECTION_IS_DTLS(sc)) {
722 unsigned char dtlsseq[8], *p = dtlsseq;
724 s2n(sending ? DTLS_RECORD_LAYER_get_w_epoch(&sc->rlayer) :
725 DTLS_RECORD_LAYER_get_r_epoch(&sc->rlayer), p);
726 memcpy(p, &seq[2], 6);
728 memcpy(header, dtlsseq, 8);
730 memcpy(header, seq, 8);
732 header[8] = rec->type;
733 header[9] = (unsigned char)(sc->version >> 8);
734 header[10] = (unsigned char)(sc->version);
735 header[11] = (unsigned char)(rec->length >> 8);
736 header[12] = (unsigned char)(rec->length & 0xff);
738 if (EVP_DigestSignUpdate(mac_ctx, header, sizeof(header)) <= 0
739 || EVP_DigestSignUpdate(mac_ctx, rec->input, rec->length) <= 0
740 || EVP_DigestSignFinal(mac_ctx, md, &md_size) <= 0) {
744 OSSL_TRACE_BEGIN(TLS) {
745 BIO_printf(trc_out, "seq:\n");
746 BIO_dump_indent(trc_out, seq, 8, 4);
747 BIO_printf(trc_out, "rec:\n");
748 BIO_dump_indent(trc_out, rec->data, rec->length, 4);
749 } OSSL_TRACE_END(TLS);
751 if (!SSL_CONNECTION_IS_DTLS(sc)) {
752 for (i = 7; i >= 0; i--) {
758 OSSL_TRACE_BEGIN(TLS) {
759 BIO_printf(trc_out, "md:\n");
760 BIO_dump_indent(trc_out, md, md_size, 4);
761 } OSSL_TRACE_END(TLS);
764 EVP_MD_CTX_free(hmac);