* Add TLS framing (headers and trailers) to a chain of mbufs. Each * mbuf in the chain must be an unmapped mbuf. The payload of the * mbuf must be populated with the payload of each TLS record. * * The record_type argument specifies the TLS record type used when * populating the TLS header. * * The enq_count argument on return is set to the number of pages of * payload data for this enti
| 1486 | * fragment counts as one page. |
| 1487 | */ |
| 1488 | void |
| 1489 | ktls_frame(struct mbuf *top, struct ktls_session *tls, int *enq_cnt, |
| 1490 | uint8_t record_type) |
| 1491 | { |
| 1492 | struct tls_record_layer *tlshdr; |
| 1493 | struct mbuf *m; |
| 1494 | uint64_t *noncep; |
| 1495 | uint16_t tls_len; |
| 1496 | int maxlen; |
| 1497 | |
| 1498 | maxlen = tls->params.max_frame_len; |
| 1499 | *enq_cnt = 0; |
| 1500 | for (m = top; m != NULL; m = m->m_next) { |
| 1501 | /* |
| 1502 | * All mbufs in the chain should be TLS records whose |
| 1503 | * payload does not exceed the maximum frame length. |
| 1504 | * |
| 1505 | * Empty TLS records are permitted when using CBC. |
| 1506 | */ |
| 1507 | KASSERT(m->m_len <= maxlen && |
| 1508 | (tls->params.cipher_algorithm == CRYPTO_AES_CBC ? |
| 1509 | m->m_len >= 0 : m->m_len > 0), |
| 1510 | ("ktls_frame: m %p len %d\n", m, m->m_len)); |
| 1511 | |
| 1512 | /* |
| 1513 | * TLS frames require unmapped mbufs to store session |
| 1514 | * info. |
| 1515 | */ |
| 1516 | KASSERT((m->m_flags & M_EXTPG) != 0, |
| 1517 | ("ktls_frame: mapped mbuf %p (top = %p)\n", m, top)); |
| 1518 | |
| 1519 | tls_len = m->m_len; |
| 1520 | |
| 1521 | /* Save a reference to the session. */ |
| 1522 | m->m_epg_tls = ktls_hold(tls); |
| 1523 | |
| 1524 | m->m_epg_hdrlen = tls->params.tls_hlen; |
| 1525 | m->m_epg_trllen = tls->params.tls_tlen; |
| 1526 | if (tls->params.cipher_algorithm == CRYPTO_AES_CBC) { |
| 1527 | int bs, delta; |
| 1528 | |
| 1529 | /* |
| 1530 | * AES-CBC pads messages to a multiple of the |
| 1531 | * block size. Note that the padding is |
| 1532 | * applied after the digest and the encryption |
| 1533 | * is done on the "plaintext || mac || padding". |
| 1534 | * At least one byte of padding is always |
| 1535 | * present. |
| 1536 | * |
| 1537 | * Compute the final trailer length assuming |
| 1538 | * at most one block of padding. |
| 1539 | * tls->params.sb_tls_tlen is the maximum |
| 1540 | * possible trailer length (padding + digest). |
| 1541 | * delta holds the number of excess padding |
| 1542 | * bytes if the maximum were used. Those |
| 1543 | * extra bytes are removed. |
| 1544 | */ |
| 1545 | bs = tls->params.tls_bs; |
no test coverage detected