Skip to content

Commit

Permalink
Fixed gmpy requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroferretti committed Feb 23, 2019
1 parent bf1509d commit 28b1dbf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ env:
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
install:
- pip install pytest pycryptodome pytest-cov coveralls
- pip install -r requirements.txt
- pip install -r requirements_extra.txt
- pip install .
script:
- pytest --cov-config .coveragerc --cov=ctftools tests
Expand Down
17 changes: 12 additions & 5 deletions ctftools/rsatools.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
# low private exponent: wiener attack
# low public exponent: coppersmith theorem, hastad's broadcast attack, related messages

import gmpy2
from pkgutil import iter_modules
from six import iterbytes, binary_type, int2byte
from .utils import egcd


def module_exists(module_name):
return module_name in (name for loader, name, ispkg in iter_modules())


def phi(p, q):
return (p - 1) * (q - 1)

Expand All @@ -46,11 +50,14 @@ def modinv(a, m):

def compute_root(n, r, precision=300):
"""Compute the r-th root of n"""
gmpy2.get_context().precision = precision
m = gmpy2.mpz(n)
root, exact = gmpy2.iroot(m, r)
if not module_exists('gmpy'):
raise ImportError("`compute_root` needs the gmpy module to work!")
import gmpy
gmpy.set_minprec(precision)
m = gmpy.mpz(n)
root, exact = gmpy.root(m, r)
if not exact:
raise ValueError("The root is not exact, maybe try increasing the precision?")
raise ValueError("No exact root found, maybe try increasing the precision?")
return int(root)


Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
six
gmpy2
1 change: 1 addition & 0 deletions requirements_extra.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gmpy
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package_data={"ctftools": ["data/english_words.txt"]},
install_requires=requirements,
extras_require={
"rsa": ["gmpy"],
"tests": ["pytest", "pycryptodome"]
},
classifiers=[
Expand Down

0 comments on commit 28b1dbf

Please sign in to comment.