Fix T9050 accidentally valid padding issue
[platform/core/test/security-tests.git] / src / yaca / yaca-test-rsa.cpp
index 3fcd2a5..4bc7b21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Dariusz Michaluk (d.michaluk@samsung.com)
  *
@@ -197,9 +197,14 @@ void test_rsa_padding(const KeyPair& kp, const PaddingInfo& pi, EncryptionType e
                               (p.padding == padding))))
             expected = YACA_ERROR_NONE;
 
-        YACA_RESULT(expected, decrypt(p.padding, dec_key.get(),
-                                      ciphertext.get(), ciphertext_len,
-                                      &tmp, &plaintext_len));
+        int ret = decrypt(p.padding, dec_key.get(),
+                          ciphertext.get(), ciphertext_len,
+                          &tmp, &plaintext_len);
+        if (ret != expected && expected == YACA_ERROR_INVALID_PARAMETER) {
+            YACA_ASSERT_MSG(ret == YACA_ERROR_NONE, "Got unexpected error " << ret);
+            YACA_ASSERT_MSG(plaintext_len != max_len,
+                            "Message unpadded with invalid padding has correct length");
+        }
     }
 
     /* decryption with SSLV23 will fail if it was used during encryption */