From acec7b6fa11ff0f48cf6ba4e3226e1620fa5a545 Mon Sep 17 00:00:00 2001
From: Gilles Peskine <Gilles.Peskine@arm.com>
Date: Thu, 13 Sep 2018 20:34:11 +0200
Subject: [PATCH] exercise_export_key: fix public key case

Public keys are always exportable, even if their usage doesn't include
the EXPORT flag.
---
 tests/suites/test_suite_psa_crypto.function | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 2b1a946ec..81ddee003 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -692,14 +692,16 @@ static int exercise_export_key( psa_key_slot_t slot,
     size_t exported_length = 0;
     int ok = 0;
 
-    if( ( usage & PSA_KEY_USAGE_EXPORT ) == 0 )
+    TEST_ASSERT( psa_get_key_information( slot, &type, &bits ) == PSA_SUCCESS );
+
+    if( ( usage & PSA_KEY_USAGE_EXPORT ) == 0 &&
+        ! PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) )
     {
         TEST_ASSERT( psa_export_key( slot, NULL, 0, &exported_length ) ==
                      PSA_ERROR_NOT_PERMITTED );
         return( 1 );
     }
 
-    TEST_ASSERT( psa_get_key_information( slot, &type, &bits ) == PSA_SUCCESS );
     exported_size = PSA_KEY_EXPORT_MAX_SIZE( type, bits );
     exported = mbedtls_calloc( 1, exported_size );
     TEST_ASSERT( exported != NULL );