summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-04-21 16:50:56 -0700
committerDwayne Litzenberger <dlitz@dlitz.net>2013-05-26 20:21:31 -0700
commit06e6538b108bd459523f72ffb5303d9d62e36188 (patch)
tree8879bcf841a592c94c79628fb5a8324e4d15e03e
parent852fc4819c60f392652caca7398c4558765b4c12 (diff)
downloadpycrypto-06e6538b108bd459523f72ffb5303d9d62e36188.tar.gz
Skip RSA/DSA/ElGamal tests when --skip-slow-tests is specified.
-rw-r--r--lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py3
-rw-r--r--lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py3
-rw-r--r--lib/Crypto/SelfTest/PublicKey/test_DSA.py6
-rw-r--r--lib/Crypto/SelfTest/PublicKey/test_ElGamal.py96
-rw-r--r--lib/Crypto/SelfTest/PublicKey/test_RSA.py3
-rw-r--r--lib/Crypto/SelfTest/Signature/test_pkcs1_15.py3
-rw-r--r--lib/Crypto/SelfTest/Signature/test_pkcs1_pss.py3
7 files changed, 64 insertions, 53 deletions
diff --git a/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py b/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py
index 7aa1703..1a0ac33 100644
--- a/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py
+++ b/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py
@@ -164,7 +164,8 @@ HKukWBcq9f/UOmS0oEhai/6g+Uf7VHJdWaeO5LzuvwU=
def get_tests(config={}):
tests = []
- tests += list_test_cases(PKCS1_15_Tests)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(PKCS1_15_Tests)
return tests
if __name__ == '__main__':
diff --git a/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py b/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py
index 86c38a3..a95b986 100644
--- a/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py
+++ b/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py
@@ -363,7 +363,8 @@ class PKCS1_OAEP_Tests(unittest.TestCase):
def get_tests(config={}):
tests = []
- tests += list_test_cases(PKCS1_OAEP_Tests)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(PKCS1_OAEP_Tests)
return tests
if __name__ == '__main__':
diff --git a/lib/Crypto/SelfTest/PublicKey/test_DSA.py b/lib/Crypto/SelfTest/PublicKey/test_DSA.py
index b05f69a..1b4452b 100644
--- a/lib/Crypto/SelfTest/PublicKey/test_DSA.py
+++ b/lib/Crypto/SelfTest/PublicKey/test_DSA.py
@@ -220,7 +220,8 @@ class DSASlowMathTest(DSATest):
def get_tests(config={}):
tests = []
- tests += list_test_cases(DSATest)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(DSATest)
try:
from Crypto.PublicKey import _fastmath
tests += list_test_cases(DSAFastMathTest)
@@ -234,7 +235,8 @@ def get_tests(config={}):
raise ImportError("While the _fastmath module exists, importing "+
"it failed. This may point to the gmp or mpir shared library "+
"not being in the path. _fastmath was found at "+_fm_path)
- tests += list_test_cases(DSASlowMathTest)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(DSASlowMathTest)
return tests
if __name__ == '__main__':
diff --git a/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py b/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py
index cdee8cf..00dd0da 100644
--- a/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py
+++ b/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py
@@ -31,7 +31,7 @@ from Crypto.PublicKey import ElGamal
from Crypto.Util.number import *
from Crypto.Util.py3compat import *
-class ElGamalTest(unittest.TestCase):
+class ElGamalTestBase(unittest.TestCase):
#
# Test vectors
@@ -93,49 +93,6 @@ class ElGamalTest(unittest.TestCase):
}
]
- def test_generate_128(self):
- self._test_random_key(128)
-
- def test_generate_512(self):
- self._test_random_key(512)
-
- def test_encryption(self):
- for tv in self.tve:
- for as_longs in (0,1):
- d = self.convert_tv(tv, as_longs)
- key = ElGamal.construct(d['key'])
- ct = key.encrypt(d['pt'], d['k'])
- self.assertEquals(ct[0], d['ct1'])
- self.assertEquals(ct[1], d['ct2'])
-
- def test_decryption(self):
- for tv in self.tve:
- for as_longs in (0,1):
- d = self.convert_tv(tv, as_longs)
- key = ElGamal.construct(d['key'])
- pt = key.decrypt((d['ct1'], d['ct2']))
- self.assertEquals(pt, d['pt'])
-
- def test_signing(self):
- for tv in self.tvs:
- for as_longs in (0,1):
- d = self.convert_tv(tv, as_longs)
- key = ElGamal.construct(d['key'])
- sig1, sig2 = key.sign(d['h'], d['k'])
- self.assertEquals(sig1, d['sig1'])
- self.assertEquals(sig2, d['sig2'])
-
- def test_verification(self):
- for tv in self.tvs:
- for as_longs in (0,1):
- d = self.convert_tv(tv, as_longs)
- key = ElGamal.construct(d['key'])
- # Positive test
- res = key.verify( d['h'], (d['sig1'],d['sig2']) )
- self.failUnless(res)
- # Negative test
- res = key.verify( d['h'], (d['sig1']+1,d['sig2']) )
- self.failIf(res)
def convert_tv(self, tv, as_longs=0):
"""Convert a test vector from textual form (hexadecimal ascii
@@ -199,12 +156,59 @@ class ElGamalTest(unittest.TestCase):
plaintext = b("Test")
ciphertext = elgObj.encrypt(plaintext, 123456789L)
+class ElGamalTest(ElGamalTestBase):
+ def test_generate_128(self):
+ self._test_random_key(128)
+
+ def test_encryption(self):
+ for tv in self.tve:
+ for as_longs in (0,1):
+ d = self.convert_tv(tv, as_longs)
+ key = ElGamal.construct(d['key'])
+ ct = key.encrypt(d['pt'], d['k'])
+ self.assertEquals(ct[0], d['ct1'])
+ self.assertEquals(ct[1], d['ct2'])
+
+ def test_decryption(self):
+ for tv in self.tve:
+ for as_longs in (0,1):
+ d = self.convert_tv(tv, as_longs)
+ key = ElGamal.construct(d['key'])
+ pt = key.decrypt((d['ct1'], d['ct2']))
+ self.assertEquals(pt, d['pt'])
+
+ def test_signing(self):
+ for tv in self.tvs:
+ for as_longs in (0,1):
+ d = self.convert_tv(tv, as_longs)
+ key = ElGamal.construct(d['key'])
+ sig1, sig2 = key.sign(d['h'], d['k'])
+ self.assertEquals(sig1, d['sig1'])
+ self.assertEquals(sig2, d['sig2'])
+
+ def test_verification(self):
+ for tv in self.tvs:
+ for as_longs in (0,1):
+ d = self.convert_tv(tv, as_longs)
+ key = ElGamal.construct(d['key'])
+ # Positive test
+ res = key.verify( d['h'], (d['sig1'],d['sig2']) )
+ self.failUnless(res)
+ # Negative test
+ res = key.verify( d['h'], (d['sig1']+1,d['sig2']) )
+ self.failIf(res)
+
+class ElGamalSlowTest(ElGamalTestBase):
+ def test_generate_512(self):
+ self._test_random_key(512)
+
def get_tests(config={}):
tests = []
- tests += list_test_cases(ElGamalTest)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(ElGamalTest)
+ tests += list_test_cases(ElGamalSlowTest)
return tests
if __name__ == '__main__':
suite = lambda: unittest.TestSuite(get_tests())
unittest.main(defaultTest='suite')
-
diff --git a/lib/Crypto/SelfTest/PublicKey/test_RSA.py b/lib/Crypto/SelfTest/PublicKey/test_RSA.py
index 2884317..b66fb4c 100644
--- a/lib/Crypto/SelfTest/PublicKey/test_RSA.py
+++ b/lib/Crypto/SelfTest/PublicKey/test_RSA.py
@@ -456,7 +456,8 @@ class RSASlowMathTest(RSATest):
def get_tests(config={}):
tests = []
- tests += list_test_cases(RSATest)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(RSATest)
try:
from Crypto.PublicKey import _fastmath
tests += list_test_cases(RSAFastMathTest)
diff --git a/lib/Crypto/SelfTest/Signature/test_pkcs1_15.py b/lib/Crypto/SelfTest/Signature/test_pkcs1_15.py
index d56ba95..7edf9cf 100644
--- a/lib/Crypto/SelfTest/Signature/test_pkcs1_15.py
+++ b/lib/Crypto/SelfTest/Signature/test_pkcs1_15.py
@@ -209,7 +209,8 @@ class PKCS1_15_Tests(unittest.TestCase):
def get_tests(config={}):
tests = []
- tests += list_test_cases(PKCS1_15_Tests)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(PKCS1_15_Tests)
return tests
if __name__ == '__main__':
diff --git a/lib/Crypto/SelfTest/Signature/test_pkcs1_pss.py b/lib/Crypto/SelfTest/Signature/test_pkcs1_pss.py
index 314d2b8..f321823 100644
--- a/lib/Crypto/SelfTest/Signature/test_pkcs1_pss.py
+++ b/lib/Crypto/SelfTest/Signature/test_pkcs1_pss.py
@@ -436,7 +436,8 @@ class PKCS1_PSS_Tests(unittest.TestCase):
def get_tests(config={}):
tests = []
- tests += list_test_cases(PKCS1_PSS_Tests)
+ if config.get('slow_tests', 1):
+ tests += list_test_cases(PKCS1_PSS_Tests)
return tests
if __name__ == '__main__':