Ensure Stream ciphers know how to remove a TLS MAC
We previously updated the block ciphers to know how to remove a TLS
MAC when using Encrypt-then-MAC. We also need to do the same for stream
ciphers.
Fixes
@@ -429,11 +429,12 @@ int ossl_cipher_generic_stream_update(void *vctx, unsigned char *out,
}
*outl = inl;
+ if (!ctx->enc) {
/*
* Remove any TLS padding. Only used by cipher_aes_cbc_hmac_sha1_hw.c and
* cipher_aes_cbc_hmac_sha256_hw.c
*/
- if (!ctx->enc && ctx->removetlspad > 0) {
+ if (ctx->removetlspad > 0) {
/* The actual padding length */
*outl -= out[inl - 1] + 1;
@@ -441,6 +442,16 @@ int ossl_cipher_generic_stream_update(void *vctx, unsigned char *out,
*outl -= ctx->removetlspad;
}
+ /* Extract the MAC if there is one */
+ if (ctx->tlsmacsize > 0) {
+ if (*outl < ctx->tlsmacsize)
+ return 0;
+
+ ctx->tlsmac = out + *outl - ctx->tlsmacsize;
+ *outl -= ctx->tlsmacsize;
+ }
+ }
+
return 1;
}
int ossl_cipher_generic_stream_final(void *vctx, unsigned char *out,
