Re-factor X_import_radix() etc. API's#238
Conversation
| #ifdef LTC_MRSA | ||
|
|
||
| int rsa_import_radix(int radix, char *N, char *e, char *d, char *p, char *q, char *dP, char *dQ, char *qP, rsa_key *key) | ||
| static int _rsa_read_pk_part(void* mpi, ltc_pk_part *p) |
There was a problem hiding this comment.
This might be handy as an internal function e.g. mp_read_pk_part(..) or something like that (maybe "pk_part" is not self-explanatory here, but I do not have a better idea).
| } ltc_pk_part; | ||
|
|
||
| #define PK_PART_HEX(s) &((ltc_pk_part){s, 0, 16}) | ||
| #define PK_PART_DEC(d) &((ltc_pk_part){d, 0, 10}) |
There was a problem hiding this comment.
Instead of PK_PART_DEC(d) I would define PK_PART_RADIX(d,r) so that we have: PK_PART_HEX, PK_PART_RADIX and PK_PART_BIN
|
If it were me I would...
Keep LTC lean. Don't load routines up with a bunch of internal radix conversions and extra arguments.
Instead, support the most likely or most convenient radix for the function. Then, if a user has data in other radices let them convert using a set of [to be?] provided utility functions.
.
… On Jun 22, 2017, at 3:16 AM, Steffen Jaeckel ***@***.***> wrote:
In order to resolve #227 <#227> and /8 of #228 <#228> I propose this as a possible solution.
This evolved from #227 (comment) <#227 (comment)> ff.
Short summary: we want to be able to pass a huge (enough) number and combination of parameters to import functions and we're trying to find a nice way to do that.
First there was rsa_import() et. al which used standardized and/or proprietary formats to {ex,im}port asymmetric keys
Second there were issues (e.g. #136 <#136> ) where this wasn't enough and rsa_import_radix() was introduced as an evolution of a newly introduced rsa_import_hex() (c.f. #97 <#97> )
Third here we are as we realized that one radix is sometimes not enough, where you e.g. have one part of a key as hex string and another part as binary data.
Thanks for your comments.
You can view, comment on, or merge this pull request online at:
#238 <#238>
Commit Summary
use ltc_pk_part in rsa_import_radix()
use compare_testvector() in rsa_test()
also test binary import
File Changes
M src/headers/tomcrypt_pk.h <https://github.com/libtom/libtomcrypt/pull/238/files#diff-0> (12)
M src/pk/rsa/rsa_import_radix.c <https://github.com/libtom/libtomcrypt/pull/238/files#diff-1> (34)
M tests/rsa_test.c <https://github.com/libtom/libtomcrypt/pull/238/files#diff-2> (54)
Patch Links:
https://github.com/libtom/libtomcrypt/pull/238.patch <https://github.com/libtom/libtomcrypt/pull/238.patch>
https://github.com/libtom/libtomcrypt/pull/238.diff <https://github.com/libtom/libtomcrypt/pull/238.diff>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#238>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAzofteXxMpI5oc2jIE_SHgQ0eNtjR2vks5sGj71gaJpZM4OCFn3>.
|
|
The most universal is IMO binary/raw format; however, it will end up like this: int rsa_import_bin(unsigned char *N, unsigned long Nlen,
unsigned char *e, unsigned long elen,
unsigned char *d, unsigned long dlen,
unsigned char *p, unsigned long plen,
unsigned char *q, unsigned long qlen,
unsigned char *dP, unsigned long dPlen,
unsigned char *dQ, unsigned long dQlen,
unsigned char *qP, unsigned long qPlen,
rsa_key *key); |
|
On Jun 22, 2017, at 7:53 AM, karel-m ***@***.***> wrote:
The most universal is IMO binary/raw format; however, it will end up like this:
int rsa_import_bin(unsigned char *N, unsigned long Nlen,
unsigned char *e, unsigned long elen,
unsigned char *d, unsigned long dlen,
unsigned char *p, unsigned long plen,
unsigned char *q, unsigned long qlen,
unsigned char *dP, unsigned long dPlen,
unsigned char *dQ, unsigned long dQlen,
unsigned char *qP, unsigned long qPlen,
rsa_key *key);
Tough call.
The above appears messy but it is arguably the cleanest. ...and in the spirit of lean, keeping it, IMO, makes sense. If we want to provide additional helper/wrapper functions for PEM/DER and/or mixed radices I'm okay with that. ...or perhaps just a set of base conversion utilities?
My concern was driven in part because I have seen some params expressed in decimal, some hex, and yes, base64 all in the same set. Ugh. But who's responsibility is it to clean that mess up? A set of simple base conversion utilities can address this and a host of other issues.
That said, I defer to you as you are doing the heavy lifting. I'm just the sidewalk super. ;-)
|
|
As for the simplicity the "bin" approach might make sense. We can leave converting dec, hex, base64 or whatever to LTC users. |
|
I just had a chat with @sebastianas and he had a good idea! how about orienting on the OpenSSL API?
|
e16d2e7 to
ba23185
Compare
It looks fine. |
alright, I'll add the rest |
|
BTW the following API is also a bit insane (I know, it is my commit 2014-01-27) int dsa_make_key_ex(prng_state *prng, int wprng, int group_size, int modulus_size,
dsa_key *key, char* p_hex, char* q_hex, char* g_hex) |
|
We should perhaps keep DH and DSA API in a similar style
|
that was my intention |
|
1/ The new seems to cover all my use cases relater to DSA/DH/RSA, which is a great. 2/ I am not sure about the names It would be IMO better to name them: - dsa_make_key_ex
+ dsa_generate_key (or shorter dsa_gen_key)
- dh_make_key
+ dh_generate_key (or shorter dh_gen_key)We might want (maybe later) introduce 3/ Ad 4/ I am not sure if I like the idea of
Considering the fact that the "custom" keys have to be created by calling 2 functions in given order - like: dh_set_pg(p, plen, g, glen, key);
dh_set_key(pub, publen, priv, privlen, key);
//OR
dsa_set_pqg(p, plen, q, qlen, g, glen, key);
dsa_set_key(pub, publen, priv, privlen, key);we can IMO simply initialize the keys in If you think that 5/ I would prefer to have at least 6/ question related to Is it intended as a new best practice to call |
|
The 5/ also applies to |
e.g. sprng() lives w/o context
that's perfect!
you're right! done
ah, the user can do that, 1.17 had no
because I prefer
I also wasn't sure if I should like it or not, therefore I removed it. All the PK algos lived without it until now so let's keep it like that.
done
I think it's an easy and safe method to prevent use-after-free -> yes, we should treat is as the new best practice |
|
Regarding |
|
Ad - int radix_to_bin(const void *in, int radix, void *out, size_t* len);
+ int radix_to_bin(const void *in, size_t inlen int radix, void *out, size_t* outlen);BTW what about to add Ad int rand_bn_range(void *N, ltc_mp_digit lower, void *upper, prng_state *prng, int wprng)I think that we should rename the current function to: int rand_bn_limit(void *N, void *limit, prng_state *prng, int wprng)I am not sure whether we should add The rest is OK from my point of view. Although I have not checked whether the test suite of my perl bindings passes after this API facelift, IMO it would better to check it with the whole 1.18-RC. |
|
I'd leave radix_to_bin() as it is. I don't see a case for bin_to_radix() (yet?). How about rand_bn_upto() ? |
Then
Yes. |
Yep, the |
|
OK, I would at least put that information in comment like:
Yes, but libtomcrypt's interface should be independent on underlying implementation. As for |
In order to resolve #227 and /8 of #228 I propose this as a possible solution.
This evolved from #227 (comment) ff.
Short summary: we want to be able to pass a huge (enough) number and combination of parameters to import functions and we're trying to find a nice way to do that.
First there was
rsa_import()et. al which used standardized and/or proprietary formats to {ex,im}port asymmetric keysSecond there were issues (e.g. #136 ) where this wasn't enough and
rsa_import_radix()was introduced as an evolution of a newly introducedrsa_import_hex()(c.f. #97 )Third here we are as we realized that one radix is sometimes not enough, where you e.g. have one part of a key as hex string and another part as binary data.
Thanks for your comments.