Hi everone, now I want to set RSA private key into SE050 but this function return fail: sss_key_store_set_key(). Is there a problem with the way I pass parameters to that function? Please help me.
My code below:
sss_status_t ex_sss_entry_user_set_privKey(ex_sss_boot_ctx_t *pCtx, uint32_t objectID, uint8_t *key_inject, size_t keyLen,)
{
sss_status_t status = kStatus_SSS_Success;
/* Policies for key */
const sss_policy_u key_withPol = {
.type = KPolicy_Asym_Key,
/*Authentication object based on SE05X_AUTH*/
.auth_obj_id = objectID,
.policy = {
/*Asymmetric key policy*/
.asymmkey = {
/*Policy for sign*/
.can_Sign = 1,
/*Policy for verify*/
.can_Verify = 1,
/*Policy for encrypt*/
.can_Encrypt = 1,
/*Policy for decrypt*/
.can_Decrypt = 1,
/*Policy for Key Derivation*/
.can_KD = 1,
/*Policy for wrapped object*/
.can_Wrap = 1,
/*Policy to re-write object*/
.can_Write = 1,
/*Policy for reading object*/
.can_Read = 1,
/*Policy to use object for attestation*/
.can_Attest = 1,
}
}
};
/* Common rules */
const sss_policy_u common = {
.type = KPolicy_Common,
/*Authentication object based on SE05X_AUTH*/
.auth_obj_id = objectID,
.policy = {
.common = {
/*Secure Messaging*/
.req_Sm = 0,
/*Policy to Delete object*/
.can_Delete = 1,
/*Forbid all operations on object*/
.forbid_All = 0,
}
}
};
/* create policy set */
sss_policy_t policy_for_ec_key = {
.nPolicies = 2,
.policies = { &key_withPol, &common }
};
#ifdef GET_FREE_MEM
sss_se05x_session_t *pSession = (sss_se05x_session_t *)&pCtx->session;
uint16_t free_mem = 0;
#endif
/* initialize keyObject with key store */
status = sss_key_object_init(&key_object, &pCtx->ks);
if (status != kStatus_SSS_Success)
{
return status; /* return error if can't initialize keyObject */
}
/* allocate/pre-provision memory for new key */
status = sss_key_object_allocate_handle(&key_object,
objectID,
kSSS_KeyPart_Private,
kSSS_CipherType_RSA_CRT,
keyLen,
kKeyObject_Mode_Persistent);
if (status != kStatus_SSS_Success)
{
return status;
}
/* moves data[] from memory to the destination key store */
status = sss_key_store_set_key(&pCtx->ks, &key_object, key_inject, keyLen, keyLen * 8, &policy_for_ec_key, 0);
if (status != kStatus_SSS_Success)
{
return status;
}
return status; /* return successful if save data successfully */
}