diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-04-21 16:50:56 -0700 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-04-21 17:14:59 -0700 |
commit | 9ea17b0bb9238739785516e97dd2bdffe9755e8d (patch) | |
tree | f10ecf1d6aaf79079eceb9440f5026d355e1ad17 | |
parent | 721e05d5326087589dcdb8886b2c10c8e4b5b55c (diff) | |
download | pycrypto-2.6-winbuild2-wip.tar.gz |
Skip RSA/DSA/ElGamal tests when --skip-slow-tests is specified.2.6-winbuild2-wip
-rw-r--r-- | lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py | 3 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py | 3 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_DSA.py | 6 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_ElGamal.py | 96 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_RSA.py | 3 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/Signature/test_pkcs1_15.py | 3 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/Signature/test_pkcs1_pss.py | 3 |
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 accca61..45b4ff3 100644 --- a/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py +++ b/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py @@ -362,7 +362,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 c971042..e47be03 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_RSA.py +++ b/lib/Crypto/SelfTest/PublicKey/test_RSA.py @@ -390,7 +390,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 bc36696..ab56835 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 f5256a5..17745dc 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__': |