Skip to content

Commit b6a3c71

Browse files
committed
more test vectors for the 2049 bit RSA key
1 parent 6bd403a commit b6a3c71

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

unit_tests/test_tlslite_utils_rsakey.py

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,31 +2421,6 @@ def test_simple(self):
24212421
msg,
24222422
self.priv_key.decrypt(self.pub_key.encrypt(msg)))
24232423

2424-
def test_with_ciphertext_length_from_third_prf_value(self):
2425-
# malformed plaintext that generates a fake plaintext of length
2426-
# specified by 3rd length from the end of PRF output
2427-
ciphertext = a2b_hex(remove_whitespace("""
2428-
00b26f6404b82649629f2704494282443776929122e279a9cf30b0c6fe8122a0a9042870d97c
2429-
c8ef65490fe58f031eb2442352191f5fbc311026b5147d32df914599f38b825ebb824af0d63f
2430-
2d541a245c5775d1c4b78630e4996cc5fe413d38455a776cf4edcc0aa7fccb31c584d60502ed
2431-
2b77398f536e137ff7ba6430e9258e21c2db5b82f5380f566876110ac4c759178900fbad7ab7
2432-
0ea07b1daf7a1639cbb4196543a6cbe8271f35dddb8120304f6eef83059e1c5c5678710f904a
2433-
6d760c4d1d8ad076be17904b9e69910040b47914a0176fb7eea0c06444a6c4b86d674d19a556
2434-
a1de5490373cb01ce31bbd15a5633362d3d2cd7d4af1b4c5121288b894"""))
2435-
self.assertEqual(len(ciphertext), numBytes(self.pub_key.n))
2436-
2437-
# sanity check that the decrypted ciphertext is invalid
2438-
dec = self.priv_key._raw_private_key_op_bytes(ciphertext)
2439-
self.assertEqual(dec[0:1], b'\x00')
2440-
self.assertNotEqual(dec[1:2], b'\x02')
2441-
self.assertEqual(dec[-2:], b'\xc8\xfa')
2442-
2443-
plaintext = b'\x42'
2444-
2445-
msg = self.priv_key.decrypt(ciphertext)
2446-
2447-
self.assertEqual(msg, plaintext)
2448-
24492424
def test_positive_11_bytes_long(self):
24502425
# a valid ciphertext that decrypts to 11 byte long message
24512426
ciphertext = a2b_hex(remove_whitespace("""
@@ -2463,6 +2438,21 @@ def test_positive_11_bytes_long(self):
24632438

24642439
self.assertEqual(msg, plaintext)
24652440

2441+
def test_positive_empty_message(self):
2442+
ciphertext = a2b_hex(remove_whitespace("""
2443+
00cc52e83755a4526fea5e62450450638430a84a5878fd12c2a571f33c55729cfab6e35c2e17
2444+
03c452cff65731249460919aeb1b40084bdef573407851e48b3c72923e48d5c4f3e80990c462
2445+
bc291a3e635515636ab9ebeb317ca0d75b04b80c17e2f4851f8929f72c9bea4ec4a6a1fbc515
2446+
5837813567062d6b4b2a6b6e40be545d25da39b08c52f3543e2f2cdfa314832dcbf475fcbb8d
2447+
3565a64bb09b55f922e6ec6cd8bb5203a11e2fa0c1b383674c4f0b63acd78f3690e3a16ad1b7
2448+
1f6cfe48c56533e2ae42b1393b2d156c2323272490a574ce4f14055249b6a34c3e08d4a41703
2449+
9450910ec34bd5f08eb06078f51bdd6e50334ee64c9695a5bde52938e3"""))
2450+
self.assertEqual(len(ciphertext), numBytes(self.pub_key.n))
2451+
2452+
msg = self.priv_key.decrypt(ciphertext)
2453+
2454+
self.assertEqual(msg, b"")
2455+
24662456
def test_positive_11_bytes_long_with_null_padded_ciphertext(self):
24672457
# a valid ciphertext that starts with a null byte, decrypts to 11 byte
24682458
# long value
@@ -2577,6 +2567,31 @@ def test_negative_11_byte_long_wrong_type_byte(self):
25772567
self.assertNotEqual(msg, b'lorem ipsum')
25782568
self.assertEqual(msg, plaintext)
25792569

2570+
def test_with_ciphertext_length_from_third_prf_value(self):
2571+
# malformed plaintext that generates a fake plaintext of length
2572+
# specified by 3rd length from the end of PRF output
2573+
ciphertext = a2b_hex(remove_whitespace("""
2574+
00b26f6404b82649629f2704494282443776929122e279a9cf30b0c6fe8122a0a9042870d97c
2575+
c8ef65490fe58f031eb2442352191f5fbc311026b5147d32df914599f38b825ebb824af0d63f
2576+
2d541a245c5775d1c4b78630e4996cc5fe413d38455a776cf4edcc0aa7fccb31c584d60502ed
2577+
2b77398f536e137ff7ba6430e9258e21c2db5b82f5380f566876110ac4c759178900fbad7ab7
2578+
0ea07b1daf7a1639cbb4196543a6cbe8271f35dddb8120304f6eef83059e1c5c5678710f904a
2579+
6d760c4d1d8ad076be17904b9e69910040b47914a0176fb7eea0c06444a6c4b86d674d19a556
2580+
a1de5490373cb01ce31bbd15a5633362d3d2cd7d4af1b4c5121288b894"""))
2581+
self.assertEqual(len(ciphertext), numBytes(self.pub_key.n))
2582+
2583+
# sanity check that the decrypted ciphertext is invalid
2584+
dec = self.priv_key._raw_private_key_op_bytes(ciphertext)
2585+
self.assertEqual(dec[0:1], b'\x00')
2586+
self.assertNotEqual(dec[1:2], b'\x02')
2587+
self.assertEqual(dec[-2:], b'\xc8\xfa')
2588+
2589+
plaintext = b'\x42'
2590+
2591+
msg = self.priv_key.decrypt(ciphertext)
2592+
2593+
self.assertEqual(msg, plaintext)
2594+
25802595

25812596
class TestRSA3072Decrypt(unittest.TestCase):
25822597
@classmethod

0 commit comments

Comments
 (0)