summaryrefslogtreecommitdiff
path: root/lib/Crypto/SelfTest/Cipher
diff options
context:
space:
mode:
authorLegrandin <gooksankoo@hoiptorrow.mailexpire.com>2011-10-02 22:30:07 +0200
committerLegrandin <gooksankoo@hoiptorrow.mailexpire.com>2011-10-02 22:37:36 +0200
commit9cb1a2d35d916180dee8351fe6f2ddf4f6dba72d (patch)
treebb891e868546746a8a756ba8052bb70e79100a16 /lib/Crypto/SelfTest/Cipher
parent02103e2a5aca97b299b63723fb6752c2cbc00b23 (diff)
downloadpycrypto-9cb1a2d35d916180dee8351fe6f2ddf4f6dba72d.tar.gz
To simplify, no RNG needs to be provided with PKCS1 encryption: the one belonging to each RSA key is reused.
Error detection is internally implemented in a simpler (and safer) way for PKCS1 OAEP decryption. General fixes to documentation for PKCS1.
Diffstat (limited to 'lib/Crypto/SelfTest/Cipher')
-rw-r--r--lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py7
-rw-r--r--lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py16
2 files changed, 13 insertions, 10 deletions
diff --git a/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py b/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py
index f1329b1..1609770 100644
--- a/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py
+++ b/lib/Crypto/SelfTest/Cipher/test_pkcs1_15.py
@@ -114,13 +114,14 @@ HKukWBcq9f/UOmS0oEhai/6g+Uf7VHJdWaeO5LzuvwU=
self.idx += N
return r
# The real test
- ct = PKCS.encrypt(test[1], key, randGen(t2b(test[3])))
+ key._randfunc = randGen(t2b(test[3]))
+ ct = PKCS.encrypt(test[1], key)
self.assertEqual(ct, t2b(test[2]))
def testEncrypt2(self):
# Verify that encryption fail if plaintext is too long
pt = '\x00'*(128-11+1)
- self.assertRaises(ValueError, PKCS.encrypt, pt, self.key1024, self.rng)
+ self.assertRaises(ValueError, PKCS.encrypt, pt, self.key1024)
def testVerify1(self):
for test in self._testData:
@@ -150,7 +151,7 @@ HKukWBcq9f/UOmS0oEhai/6g+Uf7VHJdWaeO5LzuvwU=
# and therefore padding [8..117]
for pt_len in xrange(0,128-11+1):
pt = self.rng(pt_len)
- ct = PKCS.encrypt(pt, self.key1024, self.rng)
+ ct = PKCS.encrypt(pt, self.key1024)
pt2 = PKCS.decrypt(ct, self.key1024, "---")
self.assertEqual(pt,pt2)
diff --git a/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py b/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py
index cffbd3b..ad1fd91 100644
--- a/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py
+++ b/lib/Crypto/SelfTest/Cipher/test_pkcs1_oaep.py
@@ -280,13 +280,14 @@ class PKCS1_OAEP_Tests(unittest.TestCase):
self.idx += N
return r
# The real test
- ct = PKCS.encrypt(t2b(test[1]), key, randGen(t2b(test[3])), test[4])
+ key._randfunc = randGen(t2b(test[3]))
+ ct = PKCS.encrypt(t2b(test[1]), key, test[4])
self.assertEqual(ct, t2b(test[2]))
def testEncrypt2(self):
# Verify that encryption fails if plaintext is too long
pt = '\x00'*(128-2*20-2+1)
- self.assertRaises(ValueError, PKCS.encrypt, pt, self.key1024, self.rng)
+ self.assertRaises(ValueError, PKCS.encrypt, pt, self.key1024)
def testDecrypt1(self):
# Verify decryption using all test vectors
@@ -308,7 +309,7 @@ class PKCS1_OAEP_Tests(unittest.TestCase):
# Encrypt/Decrypt messages of length [0..128-2*20-2]
for pt_len in xrange(0,128-2*20-2):
pt = self.rng(pt_len)
- ct = PKCS.encrypt(pt, self.key1024, self.rng)
+ ct = PKCS.encrypt(pt, self.key1024)
pt2 = PKCS.decrypt(ct, self.key1024)
self.assertEqual(pt,pt2)
@@ -325,15 +326,16 @@ class PKCS1_OAEP_Tests(unittest.TestCase):
# as the hash output size
asked = 0
pt = self.rng(40)
- ct = PKCS.encrypt(pt, self.key1024, localRng, hashmod)
+ self.key1024._randfunc = localRng
+ ct = PKCS.encrypt(pt, self.key1024, hashmod)
self.assertEqual(PKCS.decrypt(ct, self.key1024, hashmod), pt)
- self.assertEqual(asked, hashmod.digest_size)
+ self.assertTrue(asked > hashmod.digest_size)
def testEncryptDecrypt2(self):
# Verify that OAEP supports labels
pt = self.rng(35)
xlabel = self.rng(22)
- ct = PKCS.encrypt(pt, self.key1024, self.rng, label=xlabel)
+ ct = PKCS.encrypt(pt, self.key1024, label=xlabel)
self.assertEqual(PKCS.decrypt(ct, self.key1024, label=xlabel), pt)
def testEncryptDecrypt3(self):
@@ -346,7 +348,7 @@ class PKCS1_OAEP_Tests(unittest.TestCase):
return '\x00'*maskLen
mgfcalls = 0
pt = self.rng(32)
- ct = PKCS.encrypt(pt, self.key1024, self.rng, mgfunc=newMGF)
+ ct = PKCS.encrypt(pt, self.key1024, mgfunc=newMGF)
self.assertEqual(mgfcalls, 2)
self.assertEqual(PKCS.decrypt(ct, self.key1024, mgfunc=newMGF), pt)