diff options
-rw-r--r-- | src/lib/pubkey/rsa/rsa.cpp | 2 | ||||
-rw-r--r-- | src/scripts/test_python.py | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/lib/pubkey/rsa/rsa.cpp b/src/lib/pubkey/rsa/rsa.cpp index 195c35bcc..5f597b811 100644 --- a/src/lib/pubkey/rsa/rsa.cpp +++ b/src/lib/pubkey/rsa/rsa.cpp @@ -110,6 +110,8 @@ const BigInt& RSA_PublicKey::get_e() const { return m_public->get_e(); } void RSA_PublicKey::init(BigInt&& n, BigInt&& e) { + if(n.is_negative() || n.is_even() || e.is_negative() || e.is_even()) + throw Decoding_Error("Invalid RSA public key parameters"); m_public = std::make_shared<RSA_Public_Data>(std::move(n), std::move(e)); } diff --git a/src/scripts/test_python.py b/src/scripts/test_python.py index f662d8e88..04b0c949e 100644 --- a/src/scripts/test_python.py +++ b/src/scripts/test_python.py @@ -283,8 +283,10 @@ ofvkP1EDmpx50fHLawIDAQAB self.assertTrue(rsapub.check_key(rng)) # invalid - rsapub = botan2.PublicKey.load_rsa(n - 1, e) - self.assertFalse(rsapub.check_key(rng)) + try: + rsapub = botan2.PublicKey.load_rsa(n - 1, e) + except botan2.BotanException as e: + self.assertEqual(str(e), "botan_pubkey_load_rsa failed: -1 (Invalid input)") def test_rsa(self): # pylint: disable=too-many-locals |