test_suite_psa_crypto_not_supported.function (2353B)
1 /* BEGIN_HEADER */ 2 3 #include "psa/crypto.h" 4 #include "test/psa_crypto_helpers.h" 5 6 #define INVALID_KEY_ID mbedtls_svc_key_id_make(0, 0xfedcba98) 7 8 /* END_HEADER */ 9 10 /* BEGIN_DEPENDENCIES 11 * depends_on:MBEDTLS_PSA_CRYPTO_C 12 * END_DEPENDENCIES 13 */ 14 15 /* BEGIN_CASE */ 16 void import_not_supported(int key_type, data_t *key_material) 17 { 18 psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; 19 mbedtls_svc_key_id_t key_id = INVALID_KEY_ID; 20 21 PSA_ASSERT(psa_crypto_init()); 22 psa_set_key_type(&attributes, key_type); 23 psa_status_t actual_status = 24 psa_import_key(&attributes, key_material->x, key_material->len, &key_id); 25 26 #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) 27 if (actual_status == PSA_ERROR_INVALID_ARGUMENT) { 28 /* Edge case: when importing an ECC public key with an unspecified 29 * bit-size (as we do here), the implementation of psa_import_key() 30 * infers the bit-size from the input. If the key type specifies an 31 * unknown curve, the validation might reject the data as invalid 32 * before it checks that the curve is supported. If so, that's ok. 33 * In practice, at the time of writing, this happens with Ed25519, 34 * for which a valid but unsupported 32-byte input causes 35 * psa_import_key() to fail because it assumes a Weierstrass curve 36 * which must have an odd-length encoding. 37 * 38 * In other cases, we do not expect an INVALID_ARGUMENT error here. */ 39 TEST_ASSERT(PSA_KEY_TYPE_IS_ECC(key_type)); 40 } else 41 #endif /* defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) */ 42 { 43 TEST_EQUAL(actual_status, PSA_ERROR_NOT_SUPPORTED); 44 } 45 TEST_ASSERT(mbedtls_svc_key_id_equal(key_id, MBEDTLS_SVC_KEY_ID_INIT)); 46 47 exit: 48 psa_destroy_key(key_id); 49 PSA_DONE(); 50 } 51 /* END_CASE */ 52 53 /* BEGIN_CASE */ 54 void generate_not_supported(int key_type, int bits) 55 { 56 psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; 57 mbedtls_svc_key_id_t key_id = INVALID_KEY_ID; 58 59 PSA_ASSERT(psa_crypto_init()); 60 psa_set_key_type(&attributes, key_type); 61 psa_set_key_bits(&attributes, bits); 62 TEST_EQUAL(psa_generate_key(&attributes, &key_id), 63 PSA_ERROR_NOT_SUPPORTED); 64 TEST_ASSERT(mbedtls_svc_key_id_equal(key_id, MBEDTLS_SVC_KEY_ID_INIT)); 65 66 exit: 67 psa_destroy_key(key_id); 68 PSA_DONE(); 69 } 70 /* END_CASE */