Andre Goddard Rosa 3711734a0a Add invalid padding_len check in get_pkcs_padding
When trying to decrypt data with an invalid key, we found that `mbedtls`
returned `0x6200` (`-25088`), which means "_CIPHER - Input data contains
invalid padding and is rejected_" from `mbedtls_cipher_finish`, but it also
set the output len as `18446744073709551516`.

In case we detect an error with padding, we leave the output len zero'ed
and return `MBEDTLS_ERR_CIPHER_INVALID_PADDING`.

Here's a reference for the way `openssl` checks the padding length:
  - 1848c561ec/crypto/evp/evp_enc.c (L1023)
  - b554eef43b

So add a check ensuring output is set to the least-harmful value in the
error cases.

With the robustness fix:
`PASSED (125 suites, 26644 tests run)`

Without the robustness fix:
`FAILED (125 suites, 26644 tests run)`

Signed-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>
Signed-off-by: Andre Goddard Rosa <agoddardrosa@roku.com>
2024-05-13 09:27:57 -05:00
..
2024-01-16 18:38:55 +00:00
2024-01-16 16:27:34 +00:00
2023-07-27 14:17:27 +01:00
2024-02-01 13:54:46 +00:00
2023-07-27 14:17:27 +01:00
2023-07-27 14:17:27 +01:00
2023-07-27 14:17:27 +01:00
2023-07-27 16:02:42 +01:00
2023-03-21 16:28:00 +01:00
2023-07-27 14:17:27 +01:00
2023-03-31 18:04:34 +01:00
2024-03-22 11:46:25 +00:00