rsa_decrypt_key() CRYPT_BUFFER_OVERFLOW handling #592
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt#592
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Prerequisites
Description
rsa_decrypt_keydoesn't properly handle buffer overflows. Instead of settingoutlento the required size to match the output and returningCRYPT_BUFFER_OVERFLOW, it leavesoutlenuntouched 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
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 returnCRYPT_BUFFER_OVERFLOWin 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_SIZECRYPT_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()returningCRYPT_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
lparamlenargument 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 where2^61 - 1stems 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.