libtom / libtomcrypt

LibTomCrypt is a fairly comprehensive, modular and portable cryptographic toolkit that provides developers with a vast array of well known published block ciphers, one-way hash functions, chaining modes, pseudo-random number generators, public key cryptography and a plethora of other routines.
https://www.libtom.net
Other
1.57k stars 461 forks source link

Constify unsigned_read in ltc_math_descriptor #654

Closed levitte closed 1 month ago

levitte commented 3 months ago

Drop the corresponding deconstying casts in code.

Fixes #581

levitte commented 3 months ago

There's oh so much more to do regarding constification, but a lot of it breaks against tomsfastmath, so that will need to change first.

sjaeckel commented 2 months ago

Thanks for the PR! I also believe we should constify the API where possible.

This PR is slightly related to #174 #175 and #176

Regarding breaking tfm ... we could also constify the ltc API now and cast the const for tfm away. I checked tfm and it uses the arguments as if they were const anyway.

Maybe we should then introduce a macro instead of adding the cast explicitely? So we don't have to manually fix it again once tfm has been adapted resp. we can keep it as is, if someone has to build against an old tfm.

#if TFM_VERSION_something_something
/* oh yeah LTC_TFM_UNCOST is such a bad name */
#define LTC_TFM_UNCOST(type) (type)
#else
#define LTC_TFM_UNCOST(type)
#endif

We'd then also need to introduce TFM_VERSION_something_something in tfm, so we know what to compare against ;) I've opened https://github.com/libtom/tomsfastmath/pull/36 to tackle that.

For now we could just add the "old path" in ltc and add the version compatibility once it's done in tfm.

sjaeckel commented 2 months ago

I checked tfm and it uses the arguments as if they were const anyway.

haha, naive me :D looking at something and then doing it is sometimes very different ...

levitte commented 2 months ago

I hate having to cast.... but your idea is sane, and I do like the TFM_VERSION_3() thing you added over in tomfastmath. So, I'm game, and will have at least a draft PR submitted fairly soon, based on TFM_VERSION_3().

levitte commented 2 months ago

Have a look at #667, which is the full constification of the math stuff, which also subsumes this PR.

levitte commented 1 month ago

Closing this in favor of #667