Tool/software:
I want to use KeyStore_PSA_importKey, so we implemented it according to the sample code and checked its operation.
I found that the code entered an infinite loop of Exception_handlerSpin.
I suspect that psa_import_key() is used internally for KeyStore_PSA_importKey.
To check the operation of psa_import_key(),
I created the following code ① and checked its operation with the same parameters as the sample code.
Then, we received the error "PSA_ERROR_INVALID_ARGUMENT".
I also created and ran code ②, but it returned "PSA_ERROR_INSUFFICIENT_MEMORY".
Could you please explain why these error codes are reported by psa_import_key()?
Also, when using KeyStore_PSA_importKey(), it goes into an infinite Exception_handlerSpin loop. Is there a way to resolve this?
--
①
simplelink_lowpower_f3_sdk_9_10_00_83\source\ti\drivers\ECDSA.h
When I run the following source code, imitating the sample code, the status value is -135 (The (The parameters passed to the function are invalid.)
* When using KeyStore_PSA_importKey, the Exception_handlerSpin function goes into an infinite loop.
static uint8_t theirPublicKeyingMaterial[65] = {0x04,
// X
0xB7,0xE0,0x8A,0xFD,0xFE,0x94,0xBA,0xD3,
0xF1,0xDC,0x8C,0x73,0x47,0x98,0xBA,0x1C,
0x62,0xB3,0xA0,0xAD,0x1E,0x9E,0xA2,0xA3,
0x82,0x01,0xCD,0x08,0x89,0xBC,0x7A,0x19,
//Y
0x36,0x03,0xF7,0x47,0x95,0x9D,0xBF,0x7A,
0x4B,0xB2,0x26,0xE4,0x19,0x28,0x72,0x90,
0x63,0xAD,0xC7,0xAE,0x43,0x52,0x9E,0x61,
0xB5,0x63,0xBB,0xC6,0x06,0xCC,0x5E,0x09};
static void vos_keystore_test( void )
{
CryptoKey theirPublicKey;
KeyStore_PSA_KeyFileId publicKeyID;
KeyStore_PSA_KeyAttributes pubKeyAttributes = KEYSTORE_PSA_KEY_ATTRIBUTES_INIT;
KeyStore_PSA_KeyType keyType = KEYSTORE_PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE;
int_fast16_t status = KEYSTORE_PSA_STATUS_GENERIC_ERROR;
// Public key
KeyStore_PSA_setKeyAlgorithm(&pubKeyAttributes, KEYSTORE_PSA_ALG_ECDSA);
KeyStore_PSA_setKeyUsageFlags(&pubKeyAttributes, KEYSTORE_PSA_KEY_USAGE_VERIFY_HASH);
// Set key ID for persistent keys
GET_KEY_ID(publicKeyID, KEYSTORE_PSA_KEY_ID_USER_MIN);
KeyStore_PSA_setKeyLifetime(&pubKeyAttributes, KEYSTORE_PSA_KEY_LIFETIME_PERSISTENT);
// In this example, we assume public key to be stored is for NIST-P256
KeyStore_PSA_setKeyType(&pubKeyAttributes, keyType | KEYSTORE_PSA_ECC_CURVE_SECP256R1);
#if 0
status = KeyStore_PSA_importKey(&pubKeyAttributes,
theirPublicKeyingMaterial,
sizeof(theirPublicKeyingMaterial),
&publicKeyID);
#else
status = psa_import_key(&pubKeyAttributes,
theirPublicKeyingMaterial,
sizeof(theirPublicKeyingMaterial),
&publicKeyID);
#endif
if (status != KEYSTORE_PSA_STATUS_SUCCESS)
{
while(1); // handle error
}
KeyStore_PSA_initKey(&theirPublicKey, publicKeyID, sizeof(theirPublicKeyingMaterial), NULL);
}

②
simplelink_lowpower_f3_sdk_9_10_00_83\source\ti\drivers\cryptoutils\cryptokey\CryptoKeyKeyStore_PSA.h
When I run the following source code, imitating the sample code, the status value will be -141 (There is not enough runtime memory.)
* When using KeyStore_PSA_importKey, the Exception_handlerSpin function goes into an infinite loop.
static uint8_t keyingMaterial[16] = {0x1f, 0x8e, 0x49, 0x73, 0x95, 0x3f, 0x3f, 0xb0,
0xbd, 0x6b, 0x16, 0x66, 0x2e, 0x9a, 0x3c, 0x17};
static void vos_keystore_test( void )
{
CryptoKey cryptoKey;
KeyStore_PSA_KeyFileId keyID;
int_fast16_t status;
KeyStore_PSA_KeyAttributes attributes = KEYSTORE_PSA_KEY_ATTRIBUTES_INIT;
// Assign key attributes
KeyStore_PSA_setKeyUsageFlags(&attributes, (KEYSTORE_PSA_KEY_USAGE_DECRYPT | KEYSTORE_PSA_KEY_USAGE_ENCRYPT));
KeyStore_PSA_setKeyAlgorithm(&attributes, KEYSTORE_PSA_ALG_CCM);
KeyStore_PSA_setKeyType(&attributes, KEYSTORE_PSA_KEY_TYPE_AES);
KeyStore_PSA_setKeyLifetime(&attributes, KEYSTORE_PSA_KEY_LIFETIME_PERSISTENT);
// Set key ID
GET_KEY_ID(keyID, KEYSTORE_PSA_KEY_ID_USER_MIN);
KeyStore_PSA_setKeyId(&attributes, keyID);
// Import the keyingMaterial
#if 0
status = KeyStore_PSA_importKey(&attributes,
keyingMaterial,
sizeof(keyingMaterial),
&keyID);
#else
status = psa_import_key(&attributes,
keyingMaterial,
sizeof(keyingMaterial),
&keyID);
#endif
if (status != KEYSTORE_PSA_STATUS_SUCCESS)
{
while(1); // handle error
}
KeyStore_PSA_initKey(&cryptoKey, keyID, sizeof(keyingMaterial), NULL);
}

---