summaryrefslogtreecommitdiff
path: root/tests/test_rsa.py
diff options
context:
space:
mode:
authorHeikki Toivonen <heikki@heikkitoivonen.net>2009-07-28 03:50:13 +0000
committerHeikki Toivonen <heikki@heikkitoivonen.net>2009-07-28 03:50:13 +0000
commiteb1af97b03f0dd6570288409ca52e5a76c8f4703 (patch)
tree66d23ad9b3cf565430c2188c236266e50112d38b /tests/test_rsa.py
parentc3c3dd3589280ae6b9323bcdb19da942c36c7b82 (diff)
downloadm2crypto-eb1af97b03f0dd6570288409ca52e5a76c8f4703.tar.gz
Part of bug 12442, make C code follow the way fips_rsa_sign.c does it in OpenSSL. Make the tests use the same digest algorithm as we are testing the signature with. These fix the tests for 64-bit platforms.
git-svn-id: http://svn.osafoundation.org/m2crypto/trunk@697 2715db39-9adf-0310-9c64-84f055769b4b
Diffstat (limited to 'tests/test_rsa.py')
-rw-r--r--tests/test_rsa.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/tests/test_rsa.py b/tests/test_rsa.py
index e23a2fb..9f1ec48 100644
--- a/tests/test_rsa.py
+++ b/tests/test_rsa.py
@@ -5,7 +5,7 @@
Copyright (c) 2000 Ng Pheng Siong. All rights reserved."""
import unittest
-import sha, md5, os
+import sha, md5, os, sys
from M2Crypto import RSA, BIO, Rand, m2, EVP, X509
class RSATestCase(unittest.TestCase):
@@ -179,24 +179,35 @@ class RSATestCase(unittest.TestCase):
size of the digest increases because of the size of
our test key limits it.
"""
- algos = {'sha1':43,
- 'ripemd160':43,
- 'md5':47}
-
- if m2.OPENSSL_VERSION_NUMBER >= 0x90800F:
- algos['sha224'] = 35
- algos['sha256'] = 31
- algos['sha384'] = 15
- algos['sha512'] = 0
-
message = "This is the message string"
- digest = sha.sha(message).digest()
+ if sys.version_info < (2, 5):
+ algos = {'sha1': (43, sha.sha(message).digest()),
+ 'md5': (47, md5.md5(message).digest())}
+
+ else:
+ import hashlib
+ algos = {'sha1': 43,
+ 'ripemd160': 43,
+ 'md5': 47}
+
+ if m2.OPENSSL_VERSION_NUMBER >= 0x90800F:
+ algos['sha224'] = 35
+ algos['sha256'] = 31
+ algos['sha384'] = 15
+ 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)
+
rsa = RSA.load_key(self.privkey)
rsa2 = RSA.load_pub_key(self.pubkey)
- for algo, salt_max in algos.iteritems():
+ 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)
+ verify = rsa2.verify_rsassa_pss(digest, signature, algo, salt_length)
assert verify == 1, 'verification failed with algorithm %s salt length %d' % (algo, salt_length)
def test_sign_bad_method(self):