Skip to content

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!

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