size_t ciphertext_len,
size_t *plaintext_len);
+/*
+ * Given the value plaintext_len represented a plaintext packet payload length
+ * in bytes, determines how many ciphertext bytes it will encrypt to. The value
+ * output does not include packet headers. Returns 0 if the specified EL is not
+ * provisioned. The result is written to *ciphertext_len.
+ */
+int ossl_qtx_calculate_ciphertext_payload_len(OSSL_QTX *qtx, uint32_t enc_level,
+ size_t plaintext_len,
+ size_t *ciphertext_len);
+
uint32_t ossl_qrl_get_suite_cipher_tag_len(uint32_t suite_id);
}
/* Determines the size of the AEAD output given the input size. */
-static size_t qtx_inflate_payload_len(OSSL_QTX *qtx, uint32_t enc_level,
- size_t plaintext_len)
+int ossl_qtx_calculate_ciphertext_payload_len(OSSL_QTX *qtx, uint32_t enc_level,
+ size_t plaintext_len,
+ size_t *ciphertext_len)
{
OSSL_QRL_ENC_LEVEL *el
= ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1);
+ size_t tag_len;
- assert(el != NULL); /* Already checked by caller. */
+ if (el == NULL) {
+ *ciphertext_len = 0;
+ return 0;
+ }
/*
* We currently only support ciphers with a 1:1 mapping between plaintext
* and ciphertext size, save for authentication tag.
*/
- return plaintext_len + ossl_qrl_get_suite_cipher_tag_len(el->suite_id);
+ tag_len = ossl_qrl_get_suite_cipher_tag_len(el->suite_id);
+
+ *ciphertext_len = plaintext_len + tag_len;
+ return 1;
}
/* Determines the size of the AEAD input given the output size. */
}
/* Determine encrypted payload length. */
- payload_len = needs_encrypt ? qtx_inflate_payload_len(qtx, enc_level,
- cur.bytes_remaining)
- : cur.bytes_remaining;
+ if (needs_encrypt)
+ ossl_qtx_calculate_ciphertext_payload_len(qtx, enc_level,
+ cur.bytes_remaining,
+ &payload_len);
+ else
+ payload_len = cur.bytes_remaining;
/* Determine header length. */
hdr->data = NULL;