Fix negative CBC decryption test 50/248850/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 2 Dec 2020 17:07:09 +0000 (18:07 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 2 Dec 2020 17:07:09 +0000 (18:07 +0100)
There's a high chance that the padding ^ 0x1 will produce a 0x01
trailing byte which happens to be a valid padding. In such case make
sure that the length of the decrypted data is different.

Change-Id: I60b7f9e708d850c49dbddbdda64ff178d730b4f7

unit-tests/test_sw-backend.cpp

index c740e9a..0232d99 100644 (file)
@@ -558,7 +558,20 @@ NEGATIVE_TEST_CASE(symmetricEncryptDecryptCbc)
 
        // broken padding
        encrypted.back() ^= 0x1;
-       BOOST_REQUIRE_THROW(key->decrypt(ca, encrypted), Exc::Crypto::InputParam);
+       try {
+               auto decrypted = key->decrypt(ca, encrypted);
+
+               /*
+                * There's a high chance that the above ^= 0x1 will produce a 0x01 trailing byte which
+                * happens to be a valid padding. In such case make sure that the length of the
+                * decrypted data is different.
+                */
+               BOOST_REQUIRE(decrypted.size() != data.size());
+       } catch (const Exc::Crypto::InputParam&) {
+               // This is fine
+       } catch (...) {
+               BOOST_FAIL("Exc::Crypto::InputParam expected");
+       }
 }
 
 POSITIVE_TEST_CASE(asymmetricEncryptDecrypt)