summaryrefslogtreecommitdiff
path: root/tests/test_rsa.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2015-10-19 19:28:51 +0200
committerMatěj Cepl <mcepl@cepl.eu>2015-10-27 18:02:22 +0100
commit835a98cc13e5f451cc3a45446412063f110a676e (patch)
tree07e8d0ffa0f2d87bbca90f6ce893024d7777f5e4 /tests/test_rsa.py
parentb1c2d5681a4950b6bfcf548ac724cf50649d5400 (diff)
downloadm2crypto-835a98cc13e5f451cc3a45446412063f110a676e.tar.gz
Pure whitespace changes ... NOOP difference
Diffstat (limited to 'tests/test_rsa.py')
-rw-r--r--tests/test_rsa.py68
1 files changed, 36 insertions, 32 deletions
diff --git a/tests/test_rsa.py b/tests/test_rsa.py
index f939527..96dd8b3 100644
--- a/tests/test_rsa.py
+++ b/tests/test_rsa.py
@@ -10,7 +10,7 @@ try:
except ImportError:
import unittest
-from M2Crypto import RSA, BIO, Rand, m2, EVP, X509
+from M2Crypto import BIO, RSA, Rand, X509, m2
from fips import fips_mode
@@ -48,7 +48,7 @@ class RSATestCase(unittest.TestCase):
def test_loadkey_pp(self):
rsa = RSA.load_key(self.privkey2, self.pp_callback)
assert len(rsa) == 1024
- assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
+ assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
assert rsa.check_key() == 1
def test_loadkey_pp_bad_cb(self):
@@ -57,28 +57,28 @@ class RSATestCase(unittest.TestCase):
def test_loadkey(self):
rsa = RSA.load_key(self.privkey)
assert len(rsa) == 1024
- assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
+ assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
self.assertEqual(rsa.n, "\x00\x00\x00\x81\x00\xcde!\x15\xdah\xb5`\xce[\xd6\x17d\xba8\xc1I\xb1\xf1\xber\x86K\xc7\xda\xb3\x98\xd6\xf6\x80\xae\xaa\x8f!\x9a\xefQ\xdeh\xbb\xc5\x99\x01o\xebGO\x8e\x9b\x9a\x18\xfb6\xba\x12\xfc\xf2\x17\r$\x00\xa1\x1a \xfc/\x13iUm\x04\x13\x0f\x91D~\xbf\x08\x19C\x1a\xe2\xa3\x91&\x8f\xcf\xcc\xf3\xa4HRf\xaf\xf2\x19\xbd\x05\xe36\x9a\xbbQ\xc86|(\xad\x83\xf2Eu\xb2EL\xdf\xa4@\x7f\xeel|\xfcU\x03\xdb\x89'")
self.assertRaises(AttributeError, getattr, rsa, 'nosuchprop')
assert rsa.check_key() == 1
def test_loadkey_bio(self):
- keybio = BIO.MemoryBuffer(open(self.privkey).read())
+ keybio = BIO.MemoryBuffer(open(self.privkey).read())
rsa = RSA.load_key_bio(keybio)
assert len(rsa) == 1024
- assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
+ assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
assert rsa.check_key() == 1
def test_keygen(self):
rsa = RSA.gen_key(1024, 65537, self.gen_callback)
assert len(rsa) == 1024
- assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
+ assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
assert rsa.check_key() == 1
def test_keygen_bad_cb(self):
rsa = RSA.gen_key(1024, 65537, self.gen2_callback)
assert len(rsa) == 1024
- assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
+ assert rsa.e == '\000\000\000\003\001\000\001' # aka 65537 aka 0xf4
assert rsa.check_key() == 1
def test_private_encrypt(self):
@@ -116,7 +116,7 @@ class RSATestCase(unittest.TestCase):
x509 = X509.load_cert("tests/recipient.pem")
rsa = x509.get_pubkey().get_rsa()
rsa.public_encrypt("data", RSA.pkcs1_padding)
-
+
def test_loadpub(self):
rsa = RSA.load_pub_key(self.pubkey)
assert len(rsa) == 1024
@@ -131,7 +131,7 @@ class RSATestCase(unittest.TestCase):
def test_savepub(self):
rsa = RSA.load_pub_key(self.pubkey)
- assert rsa.as_pem() # calls save_key_bio
+ assert rsa.as_pem() # calls save_key_bio
f = 'tests/rsa_test.pub'
try:
self.assertEquals(rsa.save_key(f), 1)
@@ -157,15 +157,15 @@ class RSATestCase(unittest.TestCase):
"""
Testing signing and verifying digests
"""
- algos = {'sha1':'',
- 'ripemd160':'',
- 'md5':''}
+ algos = {'sha1': '',
+ 'ripemd160': '',
+ 'md5': ''}
if m2.OPENSSL_VERSION_NUMBER >= 0x90800F:
algos['sha224'] = ''
algos['sha256'] = ''
- algos['sha384'] = ''
- algos['sha512'] = ''
+ algos['sha384'] = ''
+ algos['sha512'] = ''
message = "This is the message string"
digest = sha.sha(message).digest()
@@ -173,17 +173,19 @@ class RSATestCase(unittest.TestCase):
rsa2 = RSA.load_pub_key(self.pubkey)
for algo in algos.keys():
signature = rsa.sign(digest, algo)
- #assert signature == algos[algo], 'mismatched signature with algorithm %s: signature=%s' % (algo, signature)
- verify = rsa2.verify(digest, signature, algo)
+ # assert signature == algos[algo],
+ # 'mismatched signature with algorithm %s:
+ # signature=%s' % (algo, signature)
+ verify = rsa2.verify(digest, signature, algo)
assert verify == 1, 'verification failed with algorithm %s' % algo
-
+
if m2.OPENSSL_VERSION_NUMBER >= 0x90708F:
def test_sign_and_verify_rsassa_pss(self):
"""
Testing signing and verifying using rsassa_pss
-
+
The maximum size of the salt has to decrease as the
- size of the digest increases because of the size of
+ size of the digest increases because of the size of
our test key limits it.
"""
message = "This is the message string"
@@ -197,33 +199,36 @@ class RSATestCase(unittest.TestCase):
if not fips_mode:
algos['md5'] = 47
algos['ripemd160'] = 43
-
+
if m2.OPENSSL_VERSION_NUMBER >= 0x90800F:
algos['sha224'] = 35
algos['sha256'] = 31
algos['sha384'] = 15
- algos['sha512'] = 0
-
+ algos['sha512'] = 0
+
for algo, salt_max in algos.iteritems():
h = hashlib.new(algo)
h.update(message)
digest = h.digest()
- algos[algo] = (salt_max, digest)
-
+ algos[algo] = (salt_max, digest)
+
rsa = RSA.load_key(self.privkey)
rsa2 = RSA.load_pub_key(self.pubkey)
for algo, (salt_max, digest) in algos.iteritems():
for salt_length in range(0, salt_max):
signature = rsa.sign_rsassa_pss(digest, algo, salt_length)
- verify = rsa2.verify_rsassa_pss(digest, signature, algo, salt_length)
- assert verify == 1, 'verification failed with algorithm %s salt length %d' % (algo, salt_length)
+ verify = rsa2.verify_rsassa_pss(digest, signature,
+ algo, salt_length)
+ self.assertEqual(verify, 1,
+ 'verification failed with algorithm '
+ '%s salt length %d' % (algo, salt_length))
def test_sign_bad_method(self):
"""
Testing calling sign with an unsupported message digest algorithm
"""
rsa = RSA.load_key(self.privkey)
- message = "This is the message string"
+ #message = "This is the message string"
digest = 'a' * 16
self.assertRaises(ValueError, rsa.sign,
digest, 'bad_digest_method')
@@ -262,9 +267,9 @@ class RSATestCase(unittest.TestCase):
rsa = RSA.load_key(self.privkey)
digest = """This string should be long enough to warrant an error in
RSA_sign""" * 2
-
+
self.assertRaises(RSA.RSAError, rsa.sign, digest)
-
+
def test_verify_bad_signature(self):
"""
Testing verify to make sure it fails when we use a bad signature
@@ -283,10 +288,9 @@ class RSATestCase(unittest.TestCase):
def suite():
return unittest.makeSuite(RSATestCase)
-
+
if __name__ == '__main__':
- Rand.load_file('randpool.dat', -1)
+ Rand.load_file('randpool.dat', -1)
unittest.TextTestRunner().run(suite())
Rand.save_file('randpool.dat')
-