JHUISI / charm

Charm: A Framework for Rapidly Prototyping Cryptosystems
http://charm-crypto.io
GNU Lesser General Public License v3.0
542 stars 166 forks source link

Improve conversion of Python integers to Big Numbers in EC module #211

Closed davidstritzl closed 5 years ago

davidstritzl commented 5 years ago

This commit removes the conversion to MPZ integers when converting a Python long object to an OpenSSL bignum. For the intermediate conversion to a decimal string representation, Python internal functions are used here, however this is arguably less prone to breakage due to potential upcoming CPython changes than accessing internal fields as in the current code. This commit fixes an issue where for instance group.init(-1) == group.init(1) or g == -1 * g for some group element g. As for performance, on my local machine using Python 3.7, this reduces the time spent on group.init(...) by more than half; on Python 2.7 I see no significant change.

timothymctim commented 5 years ago

Any progress on merging this patch so far? It fixes several bugs and also gives a speedup of the Python code “for free.”

jakinyele commented 5 years ago

Apologies for the delay. Wanted to review/test to verify there were no unintended breaking changes and dropped the ball on testing. Anyway, merging now.