Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using gmpy2's mulmod to accelerate the mulmod operation #99

Merged
merged 3 commits into from
Apr 19, 2022

Conversation

tanjuntao
Copy link
Contributor

According to #98, the mulmod operation(mulmod(a, b, c) = a * b % c)
could be accelerated by using gmpy2.mpz when a, b, and c
are very large numbers.

The main changes are:

  • add a mulmod funciton in util.py
  • use util.mulmod function to wrap the mulmod operation in paillier.py

According to data61#98, the mulmod operation(mulmod(a, b, c) = a * b % c)
could be accelerated by using gmpy2.mpz when a, b, and c
are very large numbers.

The main changes are:
* add a mulmod funciton in util.py
* use util.mulmod function to wrap the mulmod operation in paillier.py
Copy link
Collaborator

@hardbyte hardbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff, thanks!

phe/paillier.py Outdated Show resolved Hide resolved
@@ -125,6 +125,7 @@ def raw_encrypt(self, plaintext, r_value=None):
if self.n - self.max_int <= plaintext < self.n:
# Very large plaintext, take a sneaky shortcut using inverses
neg_plaintext = self.n - plaintext # = abs(plaintext - nsquare)
# avoid using gmpy2's mulmod when a * b < c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@hardbyte hardbyte merged commit 275231e into data61:master Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants