test: pake: fail in case the opaque key is destroyed unexpectedly

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 02fbbd3..02ee7cf 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -3338,9 +3338,15 @@
         psa_key_attributes_t check_attributes = PSA_KEY_ATTRIBUTES_INIT;
 
         /* Verify that the key is still valid before destroying it */
-        if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) ==
+        if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) !=
                 PSA_SUCCESS )
         {
+            if( ret == 0 )
+                ret = 1;
+            mbedtls_printf( "The EC J-PAKE password key has unexpectedly been already destroyed\n" );
+        }
+        else
+        {
             psa_destroy_key( ecjpake_pw_slot );
         }
     }
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index d8c20c2..06c8090 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -4448,9 +4448,15 @@
         psa_key_attributes_t check_attributes = PSA_KEY_ATTRIBUTES_INIT;
 
         /* Verify that the key is still valid before destroying it */
-        if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) ==
+        if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) !=
                 PSA_SUCCESS )
         {
+            if( ret == 0 )
+                ret = 1;
+            mbedtls_printf( "The EC J-PAKE password key has unexpectedly been already destroyed\n" );
+        }
+        else
+        {
             psa_destroy_key( ecjpake_pw_slot );
         }
     }