[Pkg-privacy-commits] [obfsproxy] 242/353: Also support gmpy2 for doing modular exponentiation.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:02:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository obfsproxy.
commit 851560fa63afdca53cb300abc42b90fb01619f67
Author: Yawning Angel <yawning at schwanenlied.me>
Date: Sun Feb 23 01:45:39 2014 +0000
Also support gmpy2 for doing modular exponentiation.
There is no performance difference between gmpy1 and gmpy2 for obfsproxy, but according to the gmpy authors "gmpy2 is now the recommended version, especially if you use the pre-compiled versions for Windows.".
---
ChangeLog | 5 +++++
obfsproxy/common/modexp.py | 24 ++++++++++++++----------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9b315af..53791f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Changes in version 0.2.7 - UNRELEASED
+ - Support gmpy2 if it is available in addition to gmpy.
+ Patch by Yawning Angel.
+
+
Changes in version 0.2.6 - 2014-02-03
- Stop having 'gmpy' as a hard dependency by removing it from setup.py.
Now gmpy is only used if it was already installed on the system.
diff --git a/obfsproxy/common/modexp.py b/obfsproxy/common/modexp.py
index 410514b..3f90ea8 100644
--- a/obfsproxy/common/modexp.py
+++ b/obfsproxy/common/modexp.py
@@ -1,3 +1,13 @@
+try:
+ from gmpy2 import mpz as mpz
+except ImportError:
+ try:
+ from gmpy import mpz as mpz
+ except ImportError:
+ def mpz( x ):
+ return x
+ pass
+
def powMod( x, y, mod ):
"""
(Efficiently) Calculate and return `x' to the power of `y' mod `mod'.
@@ -7,13 +17,7 @@ def powMod( x, y, mod ):
built-in exponentiation is used.
"""
- try:
- import gmpy
- x = gmpy.mpz(x)
- y = gmpy.mpz(y)
- mod = gmpy.mpz(mod)
- except ImportError:
- # gmpy is not installed but that doesn't matter.
- pass
- finally:
- return pow(x, y, mod)
+ x = mpz(x)
+ y = mpz(y)
+ mod = mpz(mod)
+ return pow(x, y, mod)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git
More information about the Pkg-privacy-commits
mailing list