Closed suiljex closed 1 year ago
I agree that this is not consistent, but I'm not entirely sure what the correct solution should look like ... I'm tempted to argue in a very different than you expected I guess, and that's: "rsa_encrypt_key()
shouldn't return CRYPT_BUFFER_OVERFLOW
in the first place"
When looking at RFC8017 Section 7.1.2 it clearly states that there shall only be two error cases: "message too long"; "label too long"
CRYPT_PK_INVALID_SIZE
CRYPT_HASH_OVERFLOW
(even though it's not really implemented [0])The correct way to work with the RSA API is: use rsa_get_size()
and pre-allocate the maximum size for the output buffer.
I don't have the necessary cryptography knowledge to decide whether "rsa_encrypt_key()
returning CRYPT_BUFFER_OVERFLOW
" poses a security problem, but I hope someone reading this issue tracker and having that knowledge steps in here :)
My feeling tells me "we should stick to the standard", so if there's nobody commenting on this I'll remove that functionality in a future version.
[0] ltc won't allow you to process more than 2^64-1 octets through the RSA API, since its lparamlen
argument is max. 64bit wide. This would also mean that we could potentially overflow the as of RFC8017 resp. RFC3447 proposed input limitation of SHA-1 (2^61 - 1 octets). I couldn't find a reference where 2^61 - 1
stems from, but I'd simply accept it. I also couldn't find any input limitation numbers for other hashes besides the statement that SHA3 isn't vulnerable anymore to length-extension attacks https://keccak.team/keccak_strengths.html.
Prerequisites
Description
rsa_decrypt_key
doesn't properly handle buffer overflows. Instead of settingoutlen
to the required size to match the output and returningCRYPT_BUFFER_OVERFLOW
, it leavesoutlen
untouched and returnsCRYPT_INVALID_PACKET
.Steps to Reproduce
Code snippet:
Version
v1.18.2-654-g06a81aeb-dirty
Additional Information
I think the problem is with these functions: https://github.com/libtom/libtomcrypt/blob/910d6252770f1e517d9ed02dc0549a1d61dfe159/src/pk/pkcs1/pkcs_1_oaep_decode.c#L148 https://github.com/libtom/libtomcrypt/blob/910d6252770f1e517d9ed02dc0549a1d61dfe159/src/pk/pkcs1/pkcs_1_v1_5_decode.c#L88