-
Notifications
You must be signed in to change notification settings - Fork 203
API discussions/overhaul #243
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
|
|
yeah, that would've been a better solution ...
... but I was young, heimdal was complaining ... and in the end never updated ltm to the version that introduced this ... :-\
TBH I don't know why it wouldn't make sense to provide a While looking at the The rest of the to-be-deprecated/-internalized functions LGTM
good question! |
(I took one day off and all hell broke loose here! ;-) )
Is a small table, tiny enough to fit in the L0 cache of the bigger CPUs faster than a full sieve? But the sieve fits in the L1 cache, so the second time it is needed it runs faster. The only "benchmark" I made is the observation, that computing the primesum up to 2^32 needs as much time as PARI/GP but generating the primes is a very small part of computing the primesum, admitted. The same with Ok, ok, ok, I'll do a benchmark this WE.
Well, strictly spoken: it is not. Nothing in LTM is. You need more than the high-level functions run in constant-time, you need the basic arithmetics, too, even down to CPU-level. See e.g.: Bear-SSL line 713ff "Constant-time primitives" (example chosen for legibility, nothing overly special with Bear-SSL, although it can be made quite small). Yes, an extreme example, I know. Uhm… where was I? Oh, yes. It is not constant-time as it is because you only multiply if the bit is set, You should always multiply, no matter what, either with Is normal exponentiation even used in cryptography? |
A first quick test (no full benchmark!) More interesting will be the results for low-mp, especially for MP_8BIT, which cannot hold most of the 1,000 primes in a mp_digit and must do bigint arithmetic instead. But it's gone late now, so that's for later in the evening. |
Cool. Then we can definitely use your sieve instead 😊 |
Um…it is a bit more complicated than that, of course, the error bar is really that big. Current benchmark, nothing fancy, just to get a hint for the direction it goes.
256 primes is the size of the original table, 31 that for MP_8BIT. But is that worth the change of the API (the sieve needs to be initiated in mp_prime_rand and transported from there) without any of the other functions that sieve is supposed to support later? I don't know *sigh* |
@czurnieden Thx for the numbers, I don't think MP_8BIT is the use case we should optimize for. One general thing about the API overhaul: At some places it makes sense to modify the type signatures of functions, for example the return type of mp_set_int to void in #253. What could be done about such cases? Introduce another function mp_set_int_with_some_other_name? The goal should be that we don't end up with ugly names after the overhaul, e.g. mp_set_int_v2... Hmm... |
For init and set I would propose the following to get/set signed values. Deprecate all mp_set, mp_set_, mp_init_set_int, mp_get_. Furthermore add this: Variant I: int mp_init_setl(mp_int*, long);
void mp_setl(mp_int*, long);
void mp_setll(mp_int*, long long);
void mp_setull(mp_int*, unsigned long long);
long mp_getl(const mp_int*);
long long mp_getll(const mp_int*);
unsigned long long mp_getull(const mp_int*);
(int mp_init_seti(mp_int*, int);)
(int mp_geti(const mp_int*);)
(void mp_seti(mp_int*, int);) Variant II (naming bikeshed): int mp_init_set_l(mp_int*, long);
void mp_set_l(mp_int*, long);
void mp_set_ll(mp_int*, long long);
void mp_set_ull(mp_int*, unsigned long long);
long mp_get_l(const mp_int*);
long long mp_get_ll(const mp_int*);
unsigned long long mp_get_ull(const mp_int*); Variant III (sized api): int mp_init_set32(mp_int*, int32_t);
void mp_set32(mp_int*, int32_t);
void mp_set64(mp_int*, int64_t);
void mp_setu64(mp_int*, uint64_t);
int32_t mp_get32(const mp_int*);
int64_t mp_get64(const mp_int*);
uint64_t mp_getu64(const mp_int*); This will be the first easy step. Then the add_d, sub_d, ... apis could follow in a similar fashion. Note that for those we would probably only add the long variant. @sjaeckel @czurnieden Please tell me which variant you prefer. |
I do have some pride left! ;-)
Going from returning a type to returning nothing is not much of a problem, only the other way around.
Mmh…do you have a variant IV? ;-) Var. III is of course the most precise one but one of the users of LTM does not like it if they have to include stdint.h. What about keeping the old names and just add |
Note that we already include stdint.h. I would prefer variant III for a new lib, since this is the most precise one. This gives some kind of bold statement that we encourage using precise type. However this is not what is done in tommath right now. Mostly unprecise types are used everywhere and I don't want to rewrite everything. Therefore variant I/II are probably a better fit here.
Not possible, since the old names already take unsigned types. We could however add signed variants. But then I would rather clean it up nicely for once. Note that currently
I don't like it if we accumulate just more stuff. I think we should decide on one variant. I would rather keep the deprecated APIs around for some longer time (until 2.0 or something) instead of keeping around all APIs forever. |
It was the use of the content of stdint.h, not the inclusion itself. But I haven't heard anything to this regard for some time, maybe they gave up/in?
That's what I wanted to change: to let e.g.: I still like Var. III but Var. I or II is probably the better choice for now. |
I don't know. There are uintx_t uses in tommath.h. But I also must say - even if you want to restrict yourself to a very restricted c subset, or legacy variant like c89, stdint.h is a very trivial header. Even in environments without libc, I always provide stdint.h just because I need the precise types. There is really no reason in avoiding it.
Yes, I excluded that option right from the start due to incompatible changes.
I also like Var III for the precision. If we decide for Var I/II, then Var II is probaby better because of the naming scheme. I will play around a bit and prepare little prototypes then we can still decide. |
You're preaching to the choire here ;-) |
UPDATE: This is mostly done except for the addition of functions of the type
I am however not convinced anymore that it makes sense to deprecate the |
The deprecation is done more or less I think. |
Starting from the discussion in #240 with @czurnieden, I thought a bit about the exposed API.
It might make sense to do a bit of an overhaul and make some functions private. In particular
mp_digit
is exposed to often in the public API and it would be more useful to provide functions taking signed ints or longs. I considermp_digit
to be more of an implementation detail.mp_cmp_d
,mp_add_d
,mp_sub_d
,mp_div_d
,mp_mod_d
->mp_*_int
ormp_*_long
(not yet available)(DEPRECATED in open deprecate mp_expt_d and mp_n_root in favor of mp_expt and mp_root #304)mp_expt_d
->mp_expt_int
(DONE)mp_set
->mp_set_int
,mp_set_long
,mp_set_long_long
(already there)(DONE)mp_init_set
->mp_init_set_int
(already there)Deprecation of the
mp_*_d
functions could be done gracefully since they can be replaced by the more generalmp_*_int
functions.What could also be discussed is going to defined bit sizes since we include(DONE)stdint.h
and provide functions likemp_add_i32
instead ofmp_add_int
/mp_add_long
. This would make the API platform independent. However this might be a bit of a too large deviation from how things are now.Furthermore(KEEP)mp_set
is not needed anymore as soon as#221#253 has been implemented. Right nowmp_set
still makes sense since it is guaranteed to not allocate.Then there are a few functions which seem to be internal and it might make sense to not expose them.
(KEEP since it pretty much harmless)mp_exch
(KEEP?)mp_rshd
,mp_lshd
(shifting by digits)(DEPRECATED in deprecate mp_prime_is_divisible and ltm_prime_tab #288)mp_prime_is_divisble
+ltm_prime_tab
(to special and dependent on MP_PRIME_SIZE, not generally useful?)(DEPRECATED in deprecate mp_n_root_ex and mp_expt_d_ex #294)mp_n_root_ex
(what is this fast parameter for?)(DEPRECATED in deprecate mp_n_root_ex and mp_expt_d_ex #294)mp_n_expt_d_ex
(what is this fast parameter for?)Then there is the rand_digit function which is a remnant of before #236 and could be deprecated.(DEPRECATED)Concerning the bit manipulation functions, there ismp_get_bit
but nomp_set_bit
. Either addmp_set_bit
or internalizemp_get_bit
ass_mp_get_bit
?(DEPRECATED)mp_get_bit
,mp_set_bit
The one complement bitwise functions could also be internalized, since the two complement functions for positive ints are the equivalent.(DEPRECATED)mp_xor
,mp_or
,mp_and
->mp_tc_*
(already there)(DEPRECATED)mp_tc_div_2d
->mp_bit_rsh
The text was updated successfully, but these errors were encountered: