mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

mbedtls_cipher functions return 0 in invalid scenarios

Open gilles-peskine-arm opened this issue 3 years ago • 1 comments

If you call mbedtls_cipher_update_ad or mbedtls_cipher_write_tag or mbedtls_cipher_check_tag on a non-AEAD algorithm, they return 0. This looks wrong: surely it's an application error, and it's easily detectable, so we should return MBEDTLS_ERR_CIPHER_INVALID_CONTEXT or MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA?

Our unit tests indiscriminately call these functions on non-AEAD algorithms though. Is this just a test bug or is this deliberate? The documentation doesn't say anything explicit.

Similar pattern with mbedtls_cipher_set_iv on ECB.

Since the unit tests validate the current behavior, if we change it, we should probably not change LTS branches.

Note: moot if we remove cipher.h as a public API.

gilles-peskine-arm avatar Dec 13 '21 11:12 gilles-peskine-arm