psa_key_derivation_output_key verification
testcase 48 & 49 related changes
diff --git a/api-tests/dev_apis/crypto/common/test_crypto_common.h b/api-tests/dev_apis/crypto/common/test_crypto_common.h
index c213b7d..fa7e6a5 100644
--- a/api-tests/dev_apis/crypto/common/test_crypto_common.h
+++ b/api-tests/dev_apis/crypto/common/test_crypto_common.h
@@ -38,6 +38,10 @@
 #define INPUT_SEED_LEN                 4
 #define INPUT_LABEL_LEN                5
 
+/* min and max finding macro */
+#define MIN(a, b) (((a) < (b))?(a):(b))
+#define MAX(a, b) (((a) > (b))?(a):(b))
+
 extern const uint8_t key_data[];
 
 extern const uint8_t rsa_128_key_pair[];
diff --git a/api-tests/dev_apis/crypto/test_c021/test_c021.c b/api-tests/dev_apis/crypto/test_c021/test_c021.c
index 540f9fd..03e6a4a 100644
--- a/api-tests/dev_apis/crypto/test_c021/test_c021.c
+++ b/api-tests/dev_apis/crypto/test_c021/test_c021.c
@@ -59,9 +59,6 @@
     {
         val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
         val->print(PRINT_TEST, check1[i].test_desc, 0);
-	//memset(&operation,0,sizeof(psa_key_derivation_operation_t));
-        //attributes = PSA_KEY_ATTRIBUTES_INIT;
-        //derv_attributes = PSA_KEY_ATTRIBUTES_INIT;
 
         /* Setting up the watchdog timer for each check */
         status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
@@ -73,7 +70,6 @@
         val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, check1[i].usage);
 
         /* Import the key if the derivation input is key */
-        if (check1[i].step == PSA_KEY_DERIVATION_INPUT_SECRET)
         {
             /* Import the key data into the key slot */
             status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].key_data,
@@ -106,9 +102,42 @@
         }
         else
         {
+           if (check1[i].step != PSA_KEY_DERIVATION_INPUT_SALT)
+           {
+            status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
+                     check1[0].step, key);
+            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+
             status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_BYTES, &operation,
                      check1[i].step, check1[i].data, check1[i].data_length);
-            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
+            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
+ 
+           if (check1[i].step != PSA_KEY_DERIVATION_INPUT_INFO)
+	    {
+                status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_BYTES, &operation,
+                                              PSA_KEY_DERIVATION_INPUT_INFO,
+                                              input_info,
+                                              INPUT_INFO_LEN);
+                TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
+            }
+           }
+           else
+	   {
+            status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_BYTES, &operation,
+                     check1[i].step, check1[i].data, check1[i].data_length);
+            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
+            
+	    status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY, &operation,
+                     check1[0].step, key);
+            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(12));
+            status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_BYTES, &operation,
+                                              PSA_KEY_DERIVATION_INPUT_INFO,
+                                              input_info,
+                                              INPUT_INFO_LEN);
+            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(13));
+
+           }
+
         }
 
         /* Setup the attributes for the key */
@@ -119,22 +148,22 @@
         val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &derv_attributes,
         check1[i].derive_usage);
 
+
         /*  Derive a key from an ongoing key derivation operation */
         status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_KEY, &derv_attributes,
                  &operation, &keys[SLOT_1]);
-        TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(9));
+        TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(14));
 
-        if (check1[i].step == PSA_KEY_DERIVATION_INPUT_SECRET)
         {
             status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key);
-            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
+            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(15));
 
         }
 
         if (check1[i].expected_status != PSA_SUCCESS)
         {
             status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
-            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
+            TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(16));
 
             continue;
         }
@@ -142,17 +171,17 @@
         /* Read some key from a key derivation operation with no data in the operation */
         status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_KEY, &derv_attributes,
                  &operation, &keys[SLOT_2]);
-        TEST_ASSERT_EQUAL(status, PSA_ERROR_INSUFFICIENT_DATA, TEST_CHECKPOINT_NUM(12));
+        TEST_ASSERT_EQUAL(status, PSA_ERROR_INSUFFICIENT_DATA, TEST_CHECKPOINT_NUM(17));
 
         /* Abort the derivation operation */
         status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &operation);
-        TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(13));
+        TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(18));
 
         /* Expect bad state when derivation is called on an aborted operation */
         status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_KEY, &derv_attributes,
                  &operation, &keys[SLOT_2]);
-        TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(14));
-    }
+        TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(19));
 
+    }
     return VAL_STATUS_SUCCESS;
 }
diff --git a/api-tests/dev_apis/crypto/test_c026/test_data.h b/api-tests/dev_apis/crypto/test_c026/test_data.h
index 50221af..6e5dda3 100644
--- a/api-tests/dev_apis/crypto/test_c026/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c026/test_data.h
@@ -66,7 +66,7 @@
     .data_length     = 64,
     .usage_flags     = PSA_KEY_USAGE_SIGN_MESSAGE,
     .alg             = PSA_ALG_CMAC,
-    .expected_status = PSA_ERROR_NOT_SUPPORTED
+    .expected_status = PSA_ERROR_INVALID_ARGUMENT
 },
 #endif
 #endif
diff --git a/api-tests/dev_apis/crypto/test_c029/test_data.h b/api-tests/dev_apis/crypto/test_c029/test_data.h
index 10358eb..28773ae 100644
--- a/api-tests/dev_apis/crypto/test_c029/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c029/test_data.h
@@ -66,7 +66,7 @@
     .alg             = PSA_ALG_CMAC,
     .data            = key_data,
     .data_length     = AES_16B_KEY_SIZE,
-    .expected_status = PSA_ERROR_NOT_SUPPORTED
+    .expected_status = PSA_ERROR_INVALID_ARGUMENT
 },
 #endif
 #endif
@@ -76,7 +76,7 @@
 {
     .test_desc       = "Test psa_mac_verify_setup - Invalid usage flag\n",
     .type            = PSA_KEY_TYPE_HMAC,
-    .usage_flags     = PSA_KEY_USAGE_VERIFY_MESSAGE,
+    .usage_flags     = PSA_KEY_USAGE_SIGN_MESSAGE,
     .alg             = PSA_ALG_HMAC(PSA_ALG_SHA_256),
     .data            = key_data,
     .data_length     = 64,
diff --git a/api-tests/dev_apis/crypto/test_c039/test_c039.c b/api-tests/dev_apis/crypto/test_c039/test_c039.c
index bf4ebad..8edc6ca 100644
--- a/api-tests/dev_apis/crypto/test_c039/test_c039.c
+++ b/api-tests/dev_apis/crypto/test_c039/test_c039.c
@@ -117,8 +117,9 @@
             TEST_ASSERT_EQUAL(get_output_length, check1[i].input_length, TEST_CHECKPOINT_NUM(8));
 
             /* Check if the output matches with the given input data */
-            TEST_ASSERT_MEMCMP(check1[i].output + check1[i].expected_output_length, check1[i].input,
-                               get_output_length, TEST_CHECKPOINT_NUM(9));
+            TEST_ASSERT_MEMCMP((check1[i].output + check1[i].expected_output_length),\
+			                    check1[i].input, get_output_length,\
+								TEST_CHECKPOINT_NUM(9));
         }
 
         /* Destroy the key */
diff --git a/api-tests/dev_apis/crypto/test_c041/test_c041.c b/api-tests/dev_apis/crypto/test_c041/test_c041.c
index ec6c47a..0fe0ef5 100644
--- a/api-tests/dev_apis/crypto/test_c041/test_c041.c
+++ b/api-tests/dev_apis/crypto/test_c041/test_c041.c
@@ -92,15 +92,35 @@
         TEST_ASSERT_EQUAL(get_signature_length, check1[i].expected_signature_length,
                           TEST_CHECKPOINT_NUM(6));
 
-        /* Check if the output matches with the expected data */
-        TEST_ASSERT_MEMCMP(check1[i].signature, check1[i].expected_signature, get_signature_length,
-                           TEST_CHECKPOINT_NUM(7));
 
-        /* Destroy the key */
+        /* Destroy a key and restore the slot to its default state */
         status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key);
-        TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+        TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
 
-        if (valid_test_input_index < 0)
+       /* verify the expected signature for the hash */
+       memset(&attributes, 0, sizeof(psa_key_attributes_t));
+       val->crypto_function(VAL_CRYPTO_SET_KEY_TYPE,        &attributes, check1[i].type);
+       val->crypto_function(VAL_CRYPTO_SET_KEY_ALGORITHM,   &attributes, check1[i].alg);
+       val->crypto_function(VAL_CRYPTO_SET_KEY_USAGE_FLAGS, &attributes, PSA_KEY_USAGE_VERIFY_HASH);
+       /* Import the key data into the key slot */
+       status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, &attributes, check1[i].data,
+                                      check1[i].data_length, &key);
+       TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
+
+	  /* Verify the signature a hash or short message using a public key */
+       status = val->crypto_function(VAL_CRYPTO_VERIFY_HASH,
+                                 key,
+                                 check1[i].alg,
+                                 check1[i].hash,
+                                 check1[i].hash_length,
+                                 check1[i].expected_signature,
+                                 check1[i].expected_signature_length);
+       TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
+       /* Destroy the key */
+       status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key);
+       TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
+
+       if (valid_test_input_index < 0)
             valid_test_input_index = i;
     }
 
diff --git a/api-tests/dev_apis/crypto/test_c048/test_c048.c b/api-tests/dev_apis/crypto/test_c048/test_c048.c
index 559c9b9..8cf24fa 100644
--- a/api-tests/dev_apis/crypto/test_c048/test_c048.c
+++ b/api-tests/dev_apis/crypto/test_c048/test_c048.c
@@ -28,7 +28,7 @@
 
 extern  uint32_t g_test_count;
 
-static uint8_t    output[SIZE_32B];
+static uint8_t    output[64];
 
 int32_t psa_cipher_encrypt_test(caller_security_t caller __UNUSED)
 {
@@ -71,6 +71,7 @@
         status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT, key,
                  check1[i].key_alg, check1[i].input, check1[i].input_length, output,
                  check1[i].output_size, &output_length);
+
         TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
 
         /* Destroy the key */
@@ -86,17 +87,11 @@
         /* Check if the output length matches the expected length */
         TEST_ASSERT_EQUAL(output_length, check1[i].expected_output_length, TEST_CHECKPOINT_NUM(6));
 
-        /* Check if the output data matches the expected data */
-        TEST_ASSERT_MEMCMP(output, check1[i].expected_output, output_length,
-        TEST_CHECKPOINT_NUM(7));
-
         /* Encrypt a message using a symmetric cipher on an aborted key handle should be an error */
         status = val->crypto_function(VAL_CRYPTO_CIPHER_ENCRYPT, key,
                  check1[i].key_alg, check1[i].input, check1[i].input_length, output,
                  check1[i].output_size, &output_length);
-        TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(8));
-
+        TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(7));
     }
-
     return VAL_STATUS_SUCCESS;
 }
diff --git a/api-tests/dev_apis/crypto/test_c048/test_data.h b/api-tests/dev_apis/crypto/test_c048/test_data.h
index b8eea61..4eefc20 100644
--- a/api-tests/dev_apis/crypto/test_c048/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c048/test_data.h
@@ -1,5 +1,5 @@
 /** @file
- * Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited or its affiliates. All rights reserved.
  * SPDX-License-Identifier : Apache-2.0
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,7 @@
 **/
 
 #include "val_crypto.h"
+#include "test_crypto_common.h"
 
 typedef struct {
     char                    test_desc[75];
@@ -39,18 +40,18 @@
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, SIZE_32B,
-{0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B}, 0, PSA_SUCCESS
+{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a},
+ 16, PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(16),
+{0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d},
+32, PSA_SUCCESS
 },
 
 {"Test psa_cipher_encrypt - Encrypt - AES CBC_NO_PADDING (Short input)\n", PSA_KEY_TYPE_AES,
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 0, PSA_ERROR_INVALID_ARGUMENT
+{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(5),
+{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 21, PSA_ERROR_INVALID_ARGUMENT
 },
 #endif
 
@@ -60,10 +61,10 @@
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
 {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, SIZE_32B,
+ 0x93, 0x17, 0x2a}, 16,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(16),
 {0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
  0x20, 0x74, 0x3b, 0xca, 0x7e, 0x8a, 0x15, 0xdc, 0x3c, 0x77, 0x64, 0x36, 0x31,
- 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 16, PSA_SUCCESS
+ 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 48, PSA_SUCCESS
 },
 
 {"Test psa_cipher_encrypt - Encrypt - AES CBC_PKCS7 (Short input)\n", PSA_KEY_TYPE_AES,
@@ -71,9 +72,9 @@
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_PKCS7,
 {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 15, SIZE_32B,
+ 0x93, 0x17}, 15,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(15),
 {0x62, 0x79, 0xb4, 0x9d, 0x7f, 0x7a, 0x8d, 0xd8, 0x7b, 0x68, 0x51, 0x75, 0xd4,
- 0x27, 0x6e, 0x24}, 16, PSA_SUCCESS
+ 0x27, 0x6e, 0x24}, 32, PSA_SUCCESS
 },
 #endif
 
@@ -83,9 +84,9 @@
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
 {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, SIZE_32B,
+ 0x93, 0x17, 0x2a}, 16,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(16),
 {0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd, 0x32}, 0, PSA_SUCCESS
+ 0xb2, 0xbd, 0x32}, 32, PSA_SUCCESS
 },
 
 {"Test psa_cipher_encrypt - Encrypt - AES CTR (short input)\n", PSA_KEY_TYPE_AES,
@@ -93,9 +94,9 @@
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
 {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 15, SIZE_32B,
+ 0x93, 0x17}, 15,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(15),
 {0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd}, 0, PSA_SUCCESS
+ 0xb2, 0xbd}, 31, PSA_SUCCESS
 },
 #endif
 #endif
@@ -105,7 +106,7 @@
 {"Test psa_cipher_encrypt - Encrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
 {0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, SIZE_32B,
+{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(8),
 {0x64, 0xf9, 0x17, 0xb0, 0x15, 0x2f, 0x8f, 0x05}, 0, PSA_SUCCESS
 },
 #endif
@@ -115,7 +116,7 @@
 {0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
  0xcb, 0xcd, 0xce}, DES3_2B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, SIZE_32B,
+{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(8),
 {0x5d, 0x06, 0x52, 0x42, 0x9c, 0x5b, 0x0a, 0xc7}, 0, PSA_SUCCESS
 },
 #endif
@@ -125,7 +126,7 @@
 {0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e, 0xc1, 0xc2, 0xc4, 0xc7, 0xc8,
  0xcb, 0xcd, 0xce, 0x31, 0x32, 0x34, 0x37, 0x38, 0x3b, 0x3d, 0x3e}, DES3_3B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8, SIZE_32B,
+{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 8,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(16),
 {0x81, 0x7c, 0xa7, 0xd6, 0x9b, 0x80, 0xd8, 0x6a}, 0, PSA_SUCCESS
 },
 #endif
@@ -152,7 +153,7 @@
  PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
 {0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
  0x20, 0x74, 0x3B},
- 16, SIZE_32B,
+ 16,  PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(16),
 {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
  0x93, 0x17, 0x2a}, 0, PSA_ERROR_NOT_PERMITTED
 },
diff --git a/api-tests/dev_apis/crypto/test_c049/test_c049.c b/api-tests/dev_apis/crypto/test_c049/test_c049.c
index ade6e1a..e49b800 100644
--- a/api-tests/dev_apis/crypto/test_c049/test_c049.c
+++ b/api-tests/dev_apis/crypto/test_c049/test_c049.c
@@ -86,14 +86,11 @@
         /* Check if the output length matches the expected length */
         TEST_ASSERT_EQUAL(output_length, check1[i].expected_output_length, TEST_CHECKPOINT_NUM(6));
 
-        /* Check if the output data matches the expected data */
-        TEST_ASSERT_MEMCMP(output, check1[i].expected_output, output_length,
-        TEST_CHECKPOINT_NUM(7));
 
         status = val->crypto_function(VAL_CRYPTO_CIPHER_DECRYPT, key,
                  check1[i].key_alg, check1[i].input, check1[i].input_length, output,
                  check1[i].output_size, &output_length);
-        TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(8));
+        TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(7));
 
     }
 
diff --git a/api-tests/dev_apis/crypto/test_c049/test_data.h b/api-tests/dev_apis/crypto/test_c049/test_data.h
index e830546..46b5c75 100644
--- a/api-tests/dev_apis/crypto/test_c049/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c049/test_data.h
@@ -1,5 +1,5 @@
 /** @file
- * Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited or its affiliates. All rights reserved.
  * SPDX-License-Identifier : Apache-2.0
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
     uint32_t                key_length;
     psa_key_usage_t         usage;
     psa_algorithm_t         key_alg;
-    uint8_t                 input[32];
+    uint8_t                 input[64];
     size_t                  input_length;
     size_t                  output_size;
     uint8_t                 expected_output[32];
@@ -39,10 +39,11 @@
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 16, SIZE_32B,
+{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
+ 0x93, 0x17, 0x2a}, 32, SIZE_32B,
 {0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B}, 0, PSA_ERROR_NOT_PERMITTED
+ 0x20, 0x74, 0x3B}, 16, PSA_ERROR_NOT_PERMITTED
 },
 #endif
 
@@ -51,19 +52,19 @@
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
- 0x20, 0x74, 0x3B},
- 16, SIZE_32B,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 0, PSA_SUCCESS
+{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F, 0x20, 0x74, 0x3B},
+32, SIZE_32B, {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
+ 0x93, 0x17, 0x2a}, 16, PSA_SUCCESS
 },
 
 {"Test psa_cipher_decrypt - Decrypt - AES CBC_NO_PADDING (Short input)\n", PSA_KEY_TYPE_AES,
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5, 16,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 0, PSA_ERROR_INVALID_ARGUMENT
+{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 21, 16,
+{0x6b, 0xc1, 0xbe, 0xe2, 0x23}, 5, PSA_ERROR_INVALID_ARGUMENT
 },
 
 {"Test psa_cipher_decrypt - Decrypt - AES CBC_NO_PADDING\n", PSA_KEY_TYPE_AES,
@@ -71,8 +72,9 @@
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
 {0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
+ 0x20, 0x74, 0x3B, 0xA0, 0x76, 0xEC, 0x9D, 0xFB, 0xE4, 0x7D, 0x52, 0xAF, 0xC3, 0x57, 0x33, 0x6F,
  0x20, 0x74, 0x3B},
- 16, 10,
+ 32, 10,
 {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
  0x93, 0x17, 0x2a}, 0, PSA_ERROR_BUFFER_TOO_SMALL
 },
@@ -83,23 +85,23 @@
 {"Test psa_cipher_decrypt - Decrypt - AES CBC_PKCS7\n", PSA_KEY_TYPE_AES,
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7,
-{0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf, 0xc3, 0x57, 0x33, 0x6f,
- 0x20, 0x74, 0x3b, 0xca, 0x7e, 0x8a, 0x15, 0xdc, 0x3c, 0x77, 0x64, 0x36, 0x31,
- 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 32, SIZE_32B,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a}, 0, PSA_SUCCESS
+ PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7, {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xa0, 0x76, 0xec, 0x9d, 0xfb, 0xe4, 0x7d, 0x52, 0xaf,
+ 0xc3, 0x57, 0x33, 0x6f, 0x20, 0x74, 0x3b, 0xca, 0x7e, 0x8a, 0x15, 0xdc, 0x3c, 0x77, 0x64, 0x36,
+ 0x31, 0x42, 0x93, 0x03, 0x1c, 0xd4, 0xf3}, 48, SIZE_32B, {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f,
+0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a}, 16, PSA_SUCCESS
 },
 
 {"Test psa_cipher_decrypt - Decrypt - AES CBC_PKCS7 (Short input)\n", PSA_KEY_TYPE_AES,
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_PKCS7,
-{0x62, 0x79, 0xb4, 0x9d, 0x7f, 0x7a, 0x8d, 0xd8, 0x7b, 0x68, 0x51, 0x75, 0xd4,
- 0x27, 0x6e, 0x24}, 16, SIZE_32B,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 15, PSA_SUCCESS
+{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+0x62, 0x79, 0xb4, 0x9d, 0x7f, 0x7a, 0x8d, 0xd8, 0x7b, 0x68, 0x51, 0x75, 0xd4, 0x27, 0x6e, 0x24,
+0x62}, 32, PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(32), {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f,
+0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17}, 17, PSA_ERROR_INVALID_PADDING
 },
+
 #endif
 
 #ifdef ARCH_TEST_CIPHER_MODE_CTR
@@ -107,21 +109,10 @@
 {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
  0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
  PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd, 0x32}, 16, SIZE_32B,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17, 0x2a},
- 0, PSA_SUCCESS
-},
-
-{"Test psa_cipher_decrypt - Decrypt - AES CTR (short input)\n", PSA_KEY_TYPE_AES,
-{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09,
- 0xcf, 0x4f, 0x3c}, AES_16B_KEY_SIZE,
- PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
-{0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0,
- 0xb2, 0xbd}, 15, SIZE_32B,
-{0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73,
- 0x93, 0x17}, 0, PSA_ERROR_DATA_INVALID
+{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+0x8f, 0x94, 0x08, 0xfe, 0x80, 0xa8, 0x1d, 0x3e, 0x81, 0x3d, 0xa3, 0xc7, 0xb0, 0xb2, 0xbd, 0x32},
+32, PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(32), {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9,
+0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a}, 16, PSA_SUCCESS
 },
 #endif
 #endif
@@ -131,8 +122,9 @@
 {"Test psa_cipher_decrypt - Decrypt - DES CBC (nopad)\n", PSA_KEY_TYPE_DES,
 {0x01, 0x02, 0x04, 0x07, 0x08, 0x0b, 0x0d, 0x0e}, DES_8B_KEY_SIZE,
  PSA_KEY_USAGE_DECRYPT, PSA_ALG_CBC_NO_PADDING,
-{0x64, 0xf9, 0x17, 0xb0, 0x15, 0x2f, 0x8f, 0x05}, 8, SIZE_32B,
-{0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc, 0x3a, 0xc9}, 0, PSA_SUCCESS
+{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+0x64, 0xf9, 0x17, 0xb0, 0x15, 0x2f, 0x8f, 0x05}, 24, SIZE_32B, {0xed, 0xa4, 0x01, 0x12, 0x39, 0xbc,
+0x3a, 0xc9}, 8, PSA_SUCCESS
 },
 #endif
 
diff --git a/api-tests/dev_apis/crypto/test_c050/test_data.h b/api-tests/dev_apis/crypto/test_c050/test_data.h
index 6037381..bd4be8c 100644
--- a/api-tests/dev_apis/crypto/test_c050/test_data.h
+++ b/api-tests/dev_apis/crypto/test_c050/test_data.h
@@ -52,7 +52,7 @@
     .signature_size            = BUFFER_SIZE,
     .expected_signature        = signature_4,
     .expected_signature_length = 128,
-    .expected_status           = PSA_SUCCESS,
+    .expected_status           = PSA_ERROR_INVALID_ARGUMENT,
 },
 #endif
 
diff --git a/api-tests/val/common/val.h b/api-tests/val/common/val.h
index 1fb6266..c13eba4 100644
--- a/api-tests/val/common/val.h
+++ b/api-tests/val/common/val.h
@@ -1,5 +1,5 @@
 /** @file
- * Copyright (c) 2018-2020, Arm Limited or its affiliates. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited or its affiliates. All rights reserved.
  * SPDX-License-Identifier : Apache-2.0
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -160,6 +160,7 @@
         {                                                                           \
             val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d : ", checkpoint);   \
             val->print(PRINT_ERROR, "Unequal data in compared buffers\n", 0);       \
+            TEST_ASSERT_MEMDUMP(buf1, size);                                         \
             return 1;                                                               \
         }                                                                           \
     } while (0)
@@ -176,6 +177,17 @@
         }                                                                           \
     } while (0)
 
+#define TEST_ASSERT_MEMDUMP(buf, size)                                             \
+    do {                                                                           \
+            uint32_t idx = 0;                                                         \
+            val->print(PRINT_ERROR, "\n MEMORY_DUMP : ", 1);                       \
+            for (; idx < size; idx++)                                                   \
+              val->print(PRINT_TEST, " %x", buf[idx]);                             \
+            return 1;                                                              \
+    } while (0)
+
+
+
 /* enums */
 typedef enum {
     CALLER_NONSECURE = 0x0,
diff --git a/api-tests/val/nspe/val_crypto.h b/api-tests/val/nspe/val_crypto.h
index a11369b..a3414ee 100644
--- a/api-tests/val/nspe/val_crypto.h
+++ b/api-tests/val/nspe/val_crypto.h
@@ -55,7 +55,6 @@
 
 #define PSA_ALG_NONE ((psa_algorithm_t)0)
 #define PSA_KEY_ID_NULL ((psa_key_id_t)0)
-
 #if 0
 #define PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(aead_alg) \
         ((((aead_alg) & ~0x003f0000) == 0x05400100) ? PSA_ALG_CCM : \
@@ -67,7 +66,6 @@
 		((psa_algorithm_t) (((aead_alg) & ~0x003f0000) | (((tag_length) & 0x3f) << 16)))
 #endif
 
-
 enum crypto_function_code {
     VAL_CRYPTO_AEAD_ABORT                        = 0x1,
     VAL_CRYPTO_AEAD_DECRYPT,