~ubuntu-branches/ubuntu/wily/python-crypto/wily-proposed

« back to all changes in this revision

Viewing changes to lib/Crypto/PublicKey/_slowmath.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Ramacher, Sebastian Ramacher, Jan Dittberner
  • Date: 2011-10-24 21:10:19 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111024211019-ovsyzkazekk1f53x
Tags: 2.4-1
[ Sebastian Ramacher ]
* New upstream release.
* debian/rules: export CFLAGS and LDFLAGS to build with hardening flags.
* debian/patches:
  - Add dont-drop-g.patch to compile non debug builds with -g.
  - Remove epydoc-exclude-introspect.patch, fix-RSA-generate-exception.patch
    and no-usr-local.patch: all applied upstream.
  - Remove setup-dont-check-gmp.patch: not needed anymore.
* Add python3-crypto and python3-crypto-dbg packages.
  - debian/rules: build, install and test for all available versions of
    Python 2 and Python 3.
  - debian/control: add Build-Dep on python3-all-dev and python3-all-dbg.

[ Jan Dittberner ]
* add debian/control: DM-Upload-Allowed: yes

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
__all__ = ['rsa_construct']
30
30
 
31
 
from Crypto.Util.python_compat import *
 
31
import sys
32
32
 
 
33
if sys.version_info[0] == 2 and sys.version_info[1] == 1:
 
34
    from Crypto.Util.py21compat import *
33
35
from Crypto.Util.number import size, inverse
34
36
 
35
37
class error(Exception):
48
50
        # compute c**d (mod n)
49
51
        if not self.has_private():
50
52
            raise TypeError("No private key")
51
 
        return pow(c, self.d, self.n) # TODO: CRT exponentiation
 
53
        if (hasattr(self,'p') and hasattr(self,'q') and hasattr(self,'u')):
 
54
            m1 = pow(c, self.d % (self.p-1), self.p) 
 
55
            m2 = pow(c, self.d % (self.q-1), self.q)
 
56
            h = m2 - m1
 
57
            if (h<0):
 
58
                h = h + self.q
 
59
            h = h*self.u % self.q
 
60
            return h*self.p+m1
 
61
        return pow(c, self.d, self.n)
52
62
 
53
63
    def _encrypt(self, m):
54
64
        # compute m**d (mod n)