re-work PK crypto im- & export #302
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!302
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pr/301"
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?
well this turned out to become a bigger one with some real bugfixes as well...
This mostly removes
MAX_RSA_SIZEfrom the code, onlyrsa_make_key()still checks for it.After some thinking I'd even propose to remove
MIN_RSA_SIZEandMAX_RSA_SIZEentirely! Somebody against it?Not really, but note that it is currently set to 4096. Given recent interest in post-quantum resistance with longer key lengths, folks may want to play with 8192 and 15360. ...but given space and time, not for long. ;-)
That said, checking inputs for reasonableness is not a bad idea. The question then becomes what should be the limit? Everybody will have a different opinion but I consider 8192 another "reasonable" number. (A higher or lower number can always set it at compile time.)
Also on the subject of key lengths, a few lines further down in tomcrypt_custom.h, LTC_DER_MAX_PUBKEY_SIZE is set to 1024. FIPS.186-4 now defines longer DSA key lengths.
http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
This might cause DSA key import problems in pk/dsa/dsa_import.c
I have doubts about
der_decode_raw_bit_string:1/ Ad
blen/8 > *outlen- what ifblenis not multiple of 8? And thepart
*outlen = blen;perhaps also needs a fix.2/ To me it seems like we are (falsely) assuming that
out[]iszero-initialized, we are setting just 1-bits.
yeah, I would basically just remove the limits, so someone could create arbitrary sized RSA keys
I also think that sanity checking is useful at one point but I'm not sure if this library is the correct point where someone should hit an error because he chose an insane (from the library's view) value.
probably keeping
MIN_RSA_SIZEbut increasing it to 2048 is a good ideaAd (MAX|MIN)_RSA_SIZE I am for removing them completely.
Looking at der_decode_raw_bit_string once again:
outlen [in/out] The number of bits stored
So perhaps the original comparison with just
blenwas correct.wouldn't that prevent usage of 1024 bit keys ? i can imagine there are still some users of such keys, which may not have the option to change them.
well it would prevent the creation of fresh 1024 bit keys but importing would still be feasible.
yeah you're right... now the API is completely inconsistent..
We do not have an ambition to prevent ltc users from weak crypo at many
other places. The recommended minimum should be mentioned with a loud
warning in the doc, not compiled into the library.
Enforcing min/max limits make sense to me only if those are limits of our
RSA make key implementation.
For what it's worth, rsa_import() is now working in a (very) memory-constrained environment. Thanks for all your fixes!
According to my testing this PR introduces the following valgrind warnings:
The remaining 4 are DSA related and are unfortunately already present in
release/1.18.0.Steps to reproduce:
@ -288,0 +313,4 @@static int _rsa_issue_301(int prng_idx){rsa_key key, key_in;unsigned char buf[4096];approx
buf[2500]should be enough here@ -288,0 +316,4 @@unsigned char buf[4096];unsigned long len;DO(rsa_make_key(&yarrow_prng, prng_idx, sizeof(buf)/8, 65537, &key));4096/8instead ofsizeof(buf)/8would be IMO betterwhat about
DO(_rsa_issue_301(prng_idx))?@ -31,10 +31,7 @@ int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key)LTC_ARGCHK(ltc_mp.name != NULL);considering the fact that
sizeisintwe should at least checkLTC_ARGCHK(size > 0)@ -285,6 +285,64 @@ static int rsa_compat_test(void)return 0;what about
return CRYPT_OKinstead ofreturn 0👍