Fixes large heap over-allocation in rsa_import #301
No reviewers
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt!301
Loading…
Reference in a new issue
No description provided.
Delete branch "develop"
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?
Bug-fix: MAX_RSA_SIZE is the maximum RSA key size in bits (as commented in tomcrypt_custom.h), so the proper conversion to bytes (as the argument value to XCALLOC) would be to divide by 8 (bits per byte), not multiply by 8. This excessive allocation of heap memory (32 Kbytes instead of 512 bytes) is readily apparent in memory-constrained environments.
Hah, nice find!
especially since
der_decode_subject_public_key_info()will also allocate 32k ;)Edit: ...which is also nonsense IIUC
LTC_DER_MAX_PUBKEY_SIZEisn't enough inder_decode_subject_public_key_info(), but at least we shouldn't needLTC_DER_MAX_PUBKEY_SIZE * 8... there's probably a way to find out what we really need to allocate...I guess the easiest would be to use
inlenCould you please add a test case to tests/rsa_test.c which will make a key
of size MAX_RSA_SIZE/8 and then export-priv, import-priv, export-pub,
import-pub.
+ export-pub&PK_STD, import-pub
As for the actual fix, Steffen's inlen idea is IMO better e.g.
tmpbuf = XMALLOC(inlen);
Btw I tried it out and needs some more tweaking!
MALLOC(inlen)isn't enough, that failsI've pushed the fix to the fix/pr/301 branch, tests still missing.
Closed in favor of #302
Pull request closed