Adjust to openssl 1.1.1j padding changes
[platform/core/test/security-tests.git] / src / yaca / yaca-test-rsa.cpp
index 89634ac..93c41c9 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)
  *
@@ -187,19 +187,23 @@ void test_rsa_padding(const KeyPair& kp, const PaddingInfo& pi, EncryptionType e
             continue;
 
         /*
-         * - YACA_PADDING_PKCS1 & YACA_PADDING_PKCS1_SSLV23 are compatible in case of
-         *   public_encrypt/private_decrypt
+         * - YACA_PADDING_PKCS1 & YACA_PADDING_PKCS1_SSLV23 are compatible
          * - YACA_PADDING_NONE checks only the input length
          */
         expected = YACA_ERROR_INVALID_PARAMETER;
         if (p.padding == YACA_PADDING_NONE ||
-            (et == ET_PUB && ((p.padding == YACA_PADDING_PKCS1 && padding == YACA_PADDING_PKCS1_SSLV23) ||
-                              (p.padding == YACA_PADDING_PKCS1_SSLV23 && padding == YACA_PADDING_PKCS1))))
+            (p.padding == YACA_PADDING_PKCS1 && padding == YACA_PADDING_PKCS1_SSLV23) ||
+            (p.padding == YACA_PADDING_PKCS1_SSLV23 && padding == YACA_PADDING_PKCS1))
             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 */