S32K314 question about TLS API with HSE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K314 question about TLS API with HSE

Jump to solution
7,979 Views
Changhawn
Contributor IV

In S32K314,
We are using Mbedtls RTM 1.0.0 provided by NXP w/ HSE.

After TLS Handshake, we need to compute shared secret, so we are using mbedtls_ecdh_compute_shared() API,

But that API(mbedtls_ecdh_compute_shared) assign key handle as z value parameter like below picture.

In working operation, we need to derive actual shared secret key value, not key handle value. How can we do that? Please guide.

 

TLS Code)

Changhawn_0-1731469557649.png

application code)

uint8_t sharedSecret[32];
 
~~~
 
        rc = mbedtls_ecdh_compute_shared(&ecdh.grp, &z, &ecdh.Qp, &d, myrand, NULL);
        if (rc != 0)
            SYS_CONSOLE_PRINT("!!! mbedtls_ecdh_compute_shared returned %d\r\n", rc);
 
        tmp_rc = mbedtls_mpi_write_binary(&z, sharedSecret, 32);
        if (tmp_rc != 0)
            SYS_CONSOLE_PRINT("!!! mbedtls_mpi_write_binary returned %d\r\n", tmp_rc);
 
        PrintDumpBytes("sharedSecret", sharedSecret, 32);
 
 

test log)

Private keyHandle 0x20400 | Peer KeyHandle : 0x20500 | Shared Secret KeyHandle 0x20600
Z is 20600
sharedSecret=
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 06 00

0 Kudos
Reply
1 Solution
7,781 Views
Changhawn
Contributor IV

Dear NXP guys.

In KDF,  I know that NIST 800-56A is not supported currently in NXP HSE.

So implemented it without HSE. 

View solution in original post

0 Kudos
Reply
3 Replies
7,782 Views
Changhawn
Contributor IV

Dear NXP guys.

In KDF,  I know that NIST 800-56A is not supported currently in NXP HSE.

So implemented it without HSE. 

0 Kudos
Reply
7,925 Views
Changhawn
Contributor IV
Below is the code written on the Platform where HSE is running, that is, with MBEDTLS_USE_NXP_HSE_CRYPTO enabled, after tls handshaked processing is done.
 
It includes the process of generating a derived key using a certificate and DH public key, decrypting the private key through AES, and assigning it to the ECC context, as well as the signature generation process.
 
That is, an encryption key was created using the certificate and DH public key, and the key was derived using mbedtls_ssl_tls_prf(), and then the private key (output) was created through AES and assigned to the ECC context.
 
But, in the authorization req process, the SignatureValue created is responded with a wrong signature in the authorization res.
 
1. For key derivation, use mbedtls_ssl_tls_prf(), label is correct ? or not?
which one "externed master secret" or "key expansion" ?
 
2. Is there anything wrong in the code below?
 
 
certificationInstatllResponse
{
/* omission */
 
    {
        mbedtls_pk_context oem_key;
        mbedtls_ecp_keypair *oem_ecp;
 
        mbedtls_pk_init(&oem_key);
        mbedtls_mpi_init(&d);
 
        rc = mbedtls_pk_parse_key(&oem_key, PKI_1_CRT_OEM_LEAF_VALID_key, PKI_1_CRT_OEM_LEAF_VALID_key_len,
                                  gq_cert_passphrase, gq_cert_passphrase_len);
        if (rc != 0)
            SYS_CONSOLE_PRINT("!!! failed - mbedtls_pk_parse_key(oem_key) - 0x%x\r\n", -rc);
 
        oem_ecp = mbedtls_pk_ec(oem_key);
        rc = mbedtls_mpi_copy(&d, &oem_ecp->d);
        if (rc != 0)
            SYS_CONSOLE_PRINT("!!! mbedtls_mpi_copy returned %d\r\n", rc);
 
        mbedtls_pk_free(&oem_key);
    }
 
    /* DHpublickey */
    /* ContractSignatureEncryptedPrivateKey */
    {
 
        /* Initialize a group of ecdh structures with a SECP256R1 curve. */
        rc = mbedtls_ecp_group_load(&ecdh.grp, MBEDTLS_ECP_DP_SECP256R1);
        if (rc != 0)
            SYS_CONSOLE_PRINT("!!! mbedtls_ecp_group_load returned %d\r\n", rc);
 
        /* Read and apply public keys from other systems in binary data format to ecdh.Qp */
        bytes = res->DHpublickey->CONTENT->bytes;
        bytesLen = res->DHpublickey->CONTENT->bytesLen;
 
        SYS_CONSOLE_PRINT("%s DHpublickey (%x %x %x %x... len %d)\r\n", __func__, bytes[0], bytes[1], bytes[2], bytes[3], bytesLen);
        {
            temp_shared = pvPortMalloc(bytesLen);
            if (temp_shared)
            {
                memcpy(temp_shared, bytes, bytesLen);
                rc = mbedtls_ecp_point_read_binary(&ecdh.grp, &ecdh.Qp, temp_shared, bytesLen);
                //rc = nxp_hse_ecp_point_read_binary(&ecdh.grp, &ecdh.Qp, temp_shared, bytesLen);
                if (rc != 0)
                    SYS_CONSOLE_PRINT("!!! mbedtls_ecp_point_read_binary %d\r\n", rc);
            }
            else
            {
                SYS_CONSOLE_PRINT(LABEL_ISO "!!! memalloc failed -> anyway go\r\n");
                rc = mbedtls_ecp_point_read_binary(&ecdh.grp, &ecdh.Qp, bytes, bytesLen);
                if (rc != 0)
                    SYS_CONSOLE_PRINT("!!! mbedtls_ecp_point_read_binary %d\r\n", rc);
            }
        }
        isoPrintDumpBytes("DHpublickey", bytes, bytesLen);
 
        /* Verify that the d value is a valid private key in SECP256R1 */
        rc = mbedtls_ecp_check_privkey(&ecdh.grp, &d);
        if (rc != 0)
        {
            SYS_CONSOLE_PRINT("Invalid private key: -0x%04X\n", -rc);
        }
 
        /* Verify that the public key is within the valid range of SECP256R1 */
        rc = mbedtls_ecp_check_pubkey(&ecdh.grp, &ecdh.Qp);
        if (rc != 0)
        {
            SYS_CONSOLE_PRINT("DHpublickey is not valid: -0x%04X\n", -rc);
        }
 
 
        /* Calculate the shared secret key, where d is the private key generated in the previous step. */
        rc = mbedtls_ecdh_compute_shared(&ecdh.grp, &z, &ecdh.Qp, &d, myrand, NULL);
        if (rc != 0)
            SYS_CONSOLE_PRINT("!!! mbedtls_ecdh_compute_shared returned %d\r\n", rc);
 
 
        /* Use the shared secret, label, and other info to derive the key */
        rc = mbedtls_ssl_tls_prf(
            MBEDTLS_SSL_TLS_PRF_SHA256,                      /*  Hash function (usually SHA-256 for TLS) */
            &z, //&keyhandle,                     /* Secret data (shared secret) */
            32,                             /* Length of the shared secret */
            "externed master secret", //"extended master secret",   //"master secret",  //"key expansion"
            otherInfo,                   /* Additional data (optional) */
            (int)sizeof(otherInfo),               /* Length of additional data */
            key,                   /* Output buffer for derived key */
            (int)sizeof(key)                /* Desired length of derived key, key handle */
        );
        if (rc != 0)
        {
            SYS_CONSOLE_PRINT("!!! mbedtls_ssl_tls_prf() failed with error -0x%04X\n", -rc);
        }
 
        tmp_rc = mbedtls_aes_setkey_dec(&aes, key, 128);
        if (tmp_rc != 0)
        {
            SYS_CONSOLE_PRINT("!!! mbedtls_aes_setkey_dec returned %d\r\n", tmp_rc);
        }
 
        bytes = res->ContractSignatureEncryptedPrivateKey->CONTENT->bytes;
        bytesLen = res->ContractSignatureEncryptedPrivateKey->CONTENT->bytesLen;
        gq_memcpy(iv, bytes, 16);
        input = bytes + 16;
        bytesLen -= 16u;
 
        {
            uint8_t *temp_input;
            temp_input = pvPortMalloc(bytesLen);
            if (temp_input)
            {
                memcpy(temp_input, input, bytesLen);
                tmp_rc = mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, bytesLen, iv, temp_input, output);
                if (tmp_rc != 0)
                {
                    SYS_CONSOLE_PRINT("!!! mbedtls_aes_crypt_cbc returned %d\r\n", tmp_rc);
                }
                vPortFree(temp_input);
            }
            else
            {
                SYS_CONSOLE_PRINT(LABEL_ISO "!!! mbedtls_aes_crypt_cbc memalloc failed\r\n");
            }
        }
 
        pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY);
        mbedtls_pk_init(&iso->contract_key);
        rc = mbedtls_pk_setup(&iso->contract_key, pk_info);
        if (rc < 0)
        {
            SYS_CONSOLE_MESSAGE("!!! failed-mbedtls_pk_setup\r\n");
        }
 
        ec = mbedtls_pk_ec(iso->contract_key);
        rc = mbedtls_ecp_group_load(&ec->grp, MBEDTLS_ECP_DP_SECP256R1);
        if (rc < 0)
        {
            SYS_CONSOLE_MESSAGE("!!! failed-mbedtls_ecp_group_load\r\n");
        }
 
        isoPrintDumpBytes("PrivateKey", output, bytesLen);
        {
            uint8_t *uds_buf = (uint8_t *)get_gq_uds_buffer();
            memset(uds_buf, 0, 64);
            memcpy(uds_buf+64, output, bytesLen);
 
            no = pki_get_index(KEY_CONTRACT_LEAF);
            if(no < 0)
                pki_add(KEY_CONTRACT_LEAF, uds_buf, bytesLen+64);
            else
                pki_replace(no, KEY_CONTRACT_LEAF, uds_buf, bytesLen+64);
            /* Release the uds buffer */
            put_gq_uds_buffer();
        }
 
        rc = mbedtls_mpi_read_binary(&ec->d, output, bytesLen);
        if (rc < 0)
        {
            SYS_CONSOLE_MESSAGE("!!! failed-mbedtls_mp_read_binary\n");
        }
 
        if (temp_shared != NULL)
        {
            vPortFree(temp_shared);
        }
        mbedtls_mpi_free(&z);
        mbedtls_aes_free(&aes);
        mbedtls_ecdh_free(&ecdh);
    }
 
/* omission */
}
 
createSignature
{
/* omission */
            rc = mbedtls_pk_sign(&iso->contract_key, MBEDTLS_MD_SHA256, hash2, 32, asn, &siglen, mbedtls_ctr_drbg_random,
                                 &ctr_drbg);
       
            if (rc != 0)
            {
                 SYS_CONSOLE_PRINT("mbedtls_pk_sign failed %d\r\n", rc );
            }
 
            /*-----------------------------------------------------------------------------------*/
            /* Signature->SignatureValue 내용 채우기 */
            /*-----------------------------------------------------------------------------------*/
            SignatureValue->Id_isUsed = 0;
            /* SignatureValue->CONTENT 할당 */
            requiredLen = sizeof(struct iso1SignatureValueType_CONTENT);
            retalloc = iso1AllocZCodecEncBuffer(requiredLen);
            if (retalloc != NULL)
            {
                GQ_ISO_MEMCPY(&(SignatureValue->CONTENT), &(retalloc), sizeof(void *));
 
                /* SignatureValue->CONTENT 값 */
                SignatureValue->CONTENT->bytesLen = 64;
                /* MISRA_C_2012_17_07 */
                pasn1 = &asn[4];
            s_index = 37;
            if (asn[3] == 33)
            {
            pasn1++;
            s_index++;
            }
            memcpy(&SignatureValue->CONTENT->bytes[0], pasn1, 32);
 
            pasn1+= 32 + 2;
            if (asn[s_index] == 33)
            pasn1++;
            memcpy(&SignatureValue->CONTENT->bytes[32], pasn1, 32);
 
            }
/* omission */
}
0 Kudos
Reply
7,948 Views
Changhawn
Contributor IV

Dear

About problem, program copy an additional key handler through the key handler and exported it to obtain the key value, and  implemented the program as follow sw. I have two questions.
 
1. When I execute the following, HSE_MY_KeyDeriveCopyKey() returns HSE_SRV_RSP_INVALID_PARAM. Can you tell me what is wrong?
2. Can I obtain the Shared secret (used by DH key exchange protocols) value normally like this?
 
 
static hseSrvResponse_t HSE_KeyDeriveCopyKeyContent
(
    hseKeyHandle_t      targetKeyHandle,
    hseKeyInfo_t        keyInfo,
uint16_t *pPubKeyLength,
uint8_t *pPubKey
)
{
    uint8_t u8MuChannel;
    hseSrvResponse_t srvResponse = -5;
 
    /* Get a free channel on u8MuInstance */
    u8MuChannel = Hse_Ip_GetFreeChannel(APP_MU_INSTANCE_U8);
    if(HSE_IP_INVALID_MU_CHANNEL_U8 == u8MuChannel)
    {
    goto exit;
    }
 
/*note: which MU channel need to specify?*/
    hseSrvDescriptor_t *pHseSrvDesc = &Hse_aSrvDescriptor[u8MuChannel];
    hseExportKeySrv_t*  pExportKeyReq = &pHseSrvDesc->hseSrv.exportKeyReq;
    memset(pHseSrvDesc, 0, sizeof(hseSrvDescriptor_t));
    pHseSrvDesc->srvId = HSE_SRV_ID_EXPORT_KEY;
    pExportKeyReq->targetKeyHandle = targetKeyHandle;
 
    pExportKeyReq->pKey[0] = (HOST_ADDR)pPubKey;
    pExportKeyReq->pKeyLen[0] = (HOST_ADDR)pPubKeyLength;
 
    pExportKeyReq->cipher.cipherKeyHandle = HSE_INVALID_KEY_HANDLE;
    pExportKeyReq->keyContainer.authKeyHandle = HSE_INVALID_KEY_HANDLE;
 
/* Build the request to be sent to Hse Ip layer */
    HseIp_aRequest[u8MuChannel].eReqType   = HSE_IP_REQTYPE_SYNC;
    HseIp_aRequest[u8MuChannel].u32Timeout = TIMEOUT_TICKS_U32;
 
    /*note: which MU channel need to specify?*/
    srvResponse = Hse_Ip_ServiceRequest(APP_MU_INSTANCE_U8, u8MuChannel, &HseIp_aRequest[u8MuChannel], pHseSrvDesc);
 
exit:
 
    return srvResponse;
}
 
hseSrvResponse_t HSE_MY_KeyDeriveCopyKey
(
    hseKeyHandle_t      keyHandle,
    uint16_t            startOffset,
    hseKeyHandle_t      targetKeyHandle,
    hseKeyInfo_t        keyInfo
)
{
    uint8_t u8MuChannel;
    hseSrvResponse_t srvResponse = HSE_SRV_RSP_GENERAL_ERROR;
 
    /* Get a free channel on u8MuInstance */
    u8MuChannel = Hse_Ip_GetFreeChannel(APP_MU_INSTANCE_U8);
    if(HSE_IP_INVALID_MU_CHANNEL_U8 == u8MuChannel)
    {
    goto exit;
    }
 
/*note: which MU channel need to specify?*/
    hseSrvDescriptor_t *pHseSrvDesc = &Hse_aSrvDescriptor[u8MuChannel];
 
    hseKeyDeriveCopyKeySrv_t *pExtractKeySrv = &(pHseSrvDesc->hseSrv.keyDeriveCopyKeyReq);
 
    memset(pHseSrvDesc, 0, sizeof(hseSrvDescriptor_t));
    pHseSrvDesc->srvId = HSE_SRV_ID_KEY_DERIVE_COPY;
 
    pExtractKeySrv->keyHandle = keyHandle;
    pExtractKeySrv->startOffset = startOffset;
    pExtractKeySrv->targetKeyHandle = targetKeyHandle;
    pExtractKeySrv->keyInfo = keyInfo;
 
/* Build the request to be sent to Hse Ip layer */
    HseIp_aRequest[u8MuChannel].eReqType   = HSE_IP_REQTYPE_SYNC;
    HseIp_aRequest[u8MuChannel].u32Timeout = TIMEOUT_TICKS_U32;
 
    /*note: which MU channel need to specify?*/
    srvResponse = Hse_Ip_ServiceRequest(APP_MU_INSTANCE_U8, u8MuChannel, &HseIp_aRequest[u8MuChannel], pHseSrvDesc);
 
exit:
    return srvResponse;
}
 
int32_t gq_getComputeSharedKey(uint32_t keyHandle, uint8_t *keyBuf)
{
    /* uint8_t keyBuf[32]; */
    uint16_t keyBufLen = 32; 
hseKeyInfo_t KeyInfo;
hseSrvResponse_t srvResponse;
int32_t ret = 0;
uint32_t copykeyslot = HSE_INVALID_KEY_HANDLE;
/* uint8_t export_key[32]={ 0, }; */
 
key_import_param_t key_import_param_shared;
 
memset(&key_import_param_shared, 0x00, sizeof(key_import_param_t));
 
/* copy shared secret key */
key_import_param_shared.key_type = HSE_KEY_TYPE_SHARED_SECRET;
key_import_param_shared.key_catalog = HSE_KEY_CATALOG_ID_RAM;
key_import_param_shared.key_param.sym_key_param.size = 256u;
 
KeystoreMgmt_FindAllocateSlot(&key_import_param_shared, &copykeyslot);
 
memset(keyBuf, 0, keyBufLen);
 
srvResponse = HSE_GetKeyInfo(keyHandle, &KeyInfo);
if(srvResponse == HSE_SRV_RSP_OK)
{
KeyInfo.keyFlags = (HSE_KF_USAGE_ENCRYPT | HSE_KF_USAGE_DECRYPT | HSE_KF_USAGE_SIGN | HSE_KF_USAGE_VERIFY | HSE_KF_USAGE_DERIVE);
KeyInfo.keyType = HSE_KEY_TYPE_SHARED_SECRET;
 
printf("copykeyslot=0x%08x\n", copykeyslot);
/* copykeyslot = 0x00020601; */
srvResponse = HSE_MY_KeyDeriveCopyKey(keyHandle, 0, copykeyslot, KeyInfo);
if(srvResponse != HSE_SRV_RSP_OK)
{
ret = srvResponse;
}
else
{
printf("HSE_KeyDeriveCopyKey() is ok\r\n");
srvResponse = HSE_KeyDeriveCopyKeyContent(copykeyslot, KeyInfo, &keyBufLen, keyBuf);
if(srvResponse != HSE_SRV_RSP_OK)
{
ret = srvResponse;
}
else
{
printf("HSE_KeyDeriveCopyKeyContent() is ok\r\n");
}
}
}
else
{
ret = -2;
}
 
return ret;
}
0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1993308%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K314%20question%20about%20TLS%20API%20with%20HSE%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1993308%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EIn%20S32K314%2C%3CBR%20%2F%3EWe%20are%20using%20Mbedtls%20RTM%201.0.0%20provided%20by%20NXP%20w%2F%20HSE.%3C%2FP%3E%3CP%3EAfter%20TLS%20Handshake%2C%20we%20need%20to%20compute%20shared%20secret%2C%20so%20we%20are%20using%20mbedtls_ecdh_compute_shared()%20API%2C%3C%2FP%3E%3CP%3EBut%20that%20API(mbedtls_ecdh_compute_shared)%20assign%20key%20handle%20as%20z%20value%20parameter%20like%20below%20picture.%3C%2FP%3E%3CP%3EIn%20working%20operation%2C%20we%20need%20to%20derive%20actual%20shared%20secret%20key%20value%2C%20not%20key%20handle%20value.%20How%20can%20we%20do%20that%3F%20Please%20guide.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ETLS%20Code)%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Changhawn_0-1731469557649.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Changhawn_0-1731469557649.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F310183i3E6EACE63E1E93CF%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Changhawn_0-1731469557649.png%22%20alt%3D%22Changhawn_0-1731469557649.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Eapplication%20code)%3C%2FP%3E%3CDIV%3Euint8_t%20sharedSecret%5B32%5D%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E~~~%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecdh_compute_shared(%26amp%3Becdh.grp%2C%20%26amp%3Bz%2C%20%26amp%3Becdh.Qp%2C%20%26amp%3Bd%2C%20myrand%2C%20NULL)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_ecdh_compute_shared%20returned%20%25d%5Cr%5Cn%22%2C%20rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20tmp_rc%20%3D%20mbedtls_mpi_write_binary(%26amp%3Bz%2C%20sharedSecret%2C%2032)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(tmp_rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_mpi_write_binary%20returned%20%25d%5Cr%5Cn%22%2C%20tmp_rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20PrintDumpBytes(%22sharedSecret%22%2C%20sharedSecret%2C%2032)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3Etest%20log)%3C%2FP%3E%3CP%3EPrivate%20keyHandle%200x20400%20%7C%20Peer%20KeyHandle%20%3A%200x20500%20%7C%20Shared%20Secret%20KeyHandle%200x20600%3CBR%20%2F%3EZ%20is%2020600%3CBR%20%2F%3EsharedSecret%3D%3CBR%20%2F%3E00%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2000%2002%2006%2000%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2007786%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20S32K314%20question%20about%20TLS%20API%20with%20HSE%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2007786%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EDear%20NXP%20guys.%3C%2FP%3E%3CP%3EIn%20KDF%2C%26nbsp%3B%20I%20know%20that%20NIST%20800-56A%20is%20not%20supported%20currently%20in%26nbsp%3BNXP%20HSE.%3C%2FP%3E%3CP%3ESo%20implemented%20it%20without%20HSE.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1995790%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20S32K314%20question%20about%20TLS%20API%20with%20HSE%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1995790%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CDIV%3EBelow%20is%20the%20code%20written%20on%20the%20Platform%20where%20HSE%20is%20running%2C%20that%20is%2C%20with%20MBEDTLS_USE_NXP_HSE_CRYPTO%20enabled%2C%20after%20tls%20handshaked%20processing%20is%20done.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EIt%20includes%20the%20process%20of%20generating%20a%20derived%20key%20using%20a%20certificate%20and%20DH%20public%20key%2C%20decrypting%20the%20private%20key%20through%20AES%2C%20and%20assigning%20it%20to%20the%20ECC%20context%2C%20as%20well%20as%20the%20signature%20generation%20process.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EThat%20is%2C%20an%20encryption%20key%20was%20created%20using%20the%20certificate%20and%20DH%20public%20key%2C%20and%20the%20key%20was%20derived%20using%20mbedtls_ssl_tls_prf()%2C%20and%20then%20the%20private%20key%20(output)%20was%20created%20through%20AES%20and%20assigned%20to%20the%20ECC%20context.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EBut%2C%20in%20the%20authorization%20req%20process%2C%20the%20SignatureValue%20created%20is%20responded%20with%20a%20wrong%20signature%20in%20the%20authorization%20res.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E1.%20For%20key%20derivation%2C%20use%20mbedtls_ssl_tls_prf()%2C%20label%20is%20correct%20%3F%20or%20not%3F%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3Ewhich%20one%20%22externed%20master%20secret%22%20or%20%22key%20expansion%22%20%3F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E2.%20Is%20there%20anything%20wrong%20in%20the%20code%20below%3F%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EcertificationInstatllResponse%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%2F*%20omission%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_pk_context%20oem_key%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_ecp_keypair%20*oem_ecp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_pk_init(%26amp%3Boem_key)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_mpi_init(%26amp%3Bd)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_pk_parse_key(%26amp%3Boem_key%2C%20PKI_1_CRT_OEM_LEAF_VALID_key%2C%20PKI_1_CRT_OEM_LEAF_VALID_key_len%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20gq_cert_passphrase%2C%20gq_cert_passphrase_len)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20failed%20-%20mbedtls_pk_parse_key(oem_key)%20-%200x%25x%5Cr%5Cn%22%2C%20-rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20oem_ecp%20%3D%20mbedtls_pk_ec(oem_key)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_mpi_copy(%26amp%3Bd%2C%20%26amp%3Boem_ecp-%26gt%3Bd)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_mpi_copy%20returned%20%25d%5Cr%5Cn%22%2C%20rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_pk_free(%26amp%3Boem_key)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20DHpublickey%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20ContractSignatureEncryptedPrivateKey%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Initialize%20a%20group%20of%20ecdh%20structures%20with%20a%20SECP256R1%20curve.%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecp_group_load(%26amp%3Becdh.grp%2C%20MBEDTLS_ECP_DP_SECP256R1)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_ecp_group_load%20returned%20%25d%5Cr%5Cn%22%2C%20rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Read%20and%20apply%20public%20keys%20from%20other%20systems%20in%20binary%20data%20format%20to%20ecdh.Qp%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20bytes%20%3D%20res-%26gt%3BDHpublickey-%26gt%3BCONTENT-%26gt%3Bbytes%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20bytesLen%20%3D%20res-%26gt%3BDHpublickey-%26gt%3BCONTENT-%26gt%3BbytesLen%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22%25s%20DHpublickey%20(%25x%20%25x%20%25x%20%25x...%20len%20%25d)%5Cr%5Cn%22%2C%20__func__%2C%20bytes%5B0%5D%2C%20bytes%5B1%5D%2C%20bytes%5B2%5D%2C%20bytes%5B3%5D%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20temp_shared%20%3D%20pvPortMalloc(bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(temp_shared)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20memcpy(temp_shared%2C%20bytes%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecp_point_read_binary(%26amp%3Becdh.grp%2C%20%26amp%3Becdh.Qp%2C%20temp_shared%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F%2Frc%20%3D%20nxp_hse_ecp_point_read_binary(%26amp%3Becdh.grp%2C%20%26amp%3Becdh.Qp%2C%20temp_shared%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_ecp_point_read_binary%20%25d%5Cr%5Cn%22%2C%20rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20else%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(LABEL_ISO%20%22!!!%20memalloc%20failed%20-%26gt%3B%20anyway%20go%5Cr%5Cn%22)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecp_point_read_binary(%26amp%3Becdh.grp%2C%20%26amp%3Becdh.Qp%2C%20bytes%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_ecp_point_read_binary%20%25d%5Cr%5Cn%22%2C%20rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20isoPrintDumpBytes(%22DHpublickey%22%2C%20bytes%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Verify%20that%20the%20d%20value%20is%20a%20valid%20private%20key%20in%20SECP256R1%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecp_check_privkey(%26amp%3Becdh.grp%2C%20%26amp%3Bd)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22Invalid%20private%20key%3A%20-0x%2504X%5Cn%22%2C%20-rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Verify%20that%20the%20public%20key%20is%20within%20the%20valid%20range%20of%20SECP256R1%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecp_check_pubkey(%26amp%3Becdh.grp%2C%20%26amp%3Becdh.Qp)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22DHpublickey%20is%20not%20valid%3A%20-0x%2504X%5Cn%22%2C%20-rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Calculate%20the%20shared%20secret%20key%2C%20where%20d%20is%20the%20private%20key%20generated%20in%20the%20previous%20step.%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecdh_compute_shared(%26amp%3Becdh.grp%2C%20%26amp%3Bz%2C%20%26amp%3Becdh.Qp%2C%20%26amp%3Bd%2C%20myrand%2C%20NULL)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_ecdh_compute_shared%20returned%20%25d%5Cr%5Cn%22%2C%20rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Use%20the%20shared%20secret%2C%20label%2C%20and%20other%20info%20to%20derive%20the%20key%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ssl_tls_prf(%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20MBEDTLS_SSL_TLS_PRF_SHA256%2C%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%26nbsp%3B%20Hash%20function%20(usually%20SHA-256%20for%20TLS)%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26amp%3Bz%2C%20%2F%2F%26amp%3Bkeyhandle%2C%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20Secret%20data%20(shared%20secret)%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2032%2C%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20Length%20of%20the%20shared%20secret%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22externed%20master%20secret%22%2C%20%2F%2F%22extended%20master%20secret%22%2C%26nbsp%3B%20%26nbsp%3B%2F%2F%22master%20secret%22%2C%26nbsp%3B%20%2F%2F%22key%20expansion%22%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20otherInfo%2C%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20Additional%20data%20(optional)%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20(int)sizeof(otherInfo)%2C%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20Length%20of%20additional%20data%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20key%2C%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2F*%20Output%20buffer%20for%20derived%20key%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20(int)sizeof(key)%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Desired%20length%20of%20derived%20key%2C%20key%20handle%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_ssl_tls_prf()%20failed%20with%20error%20-0x%2504X%5Cn%22%2C%20-rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20tmp_rc%20%3D%20mbedtls_aes_setkey_dec(%26amp%3Baes%2C%20key%2C%20128)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(tmp_rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_aes_setkey_dec%20returned%20%25d%5Cr%5Cn%22%2C%20tmp_rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20bytes%20%3D%20res-%26gt%3BContractSignatureEncryptedPrivateKey-%26gt%3BCONTENT-%26gt%3Bbytes%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20bytesLen%20%3D%20res-%26gt%3BContractSignatureEncryptedPrivateKey-%26gt%3BCONTENT-%26gt%3BbytesLen%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20gq_memcpy(iv%2C%20bytes%2C%2016)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20input%20%3D%20bytes%20%2B%2016%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20bytesLen%20-%3D%2016u%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20uint8_t%20*temp_input%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20temp_input%20%3D%20pvPortMalloc(bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(temp_input)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20memcpy(temp_input%2C%20input%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20tmp_rc%20%3D%20mbedtls_aes_crypt_cbc(%26amp%3Baes%2C%20MBEDTLS_AES_DECRYPT%2C%20bytesLen%2C%20iv%2C%20temp_input%2C%20output)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(tmp_rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(%22!!!%20mbedtls_aes_crypt_cbc%20returned%20%25d%5Cr%5Cn%22%2C%20tmp_rc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20vPortFree(temp_input)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20else%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_PRINT(LABEL_ISO%20%22!!!%20mbedtls_aes_crypt_cbc%20memalloc%20failed%5Cr%5Cn%22)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pk_info%20%3D%20mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_pk_init(%26amp%3Biso-%26gt%3Bcontract_key)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_pk_setup(%26amp%3Biso-%26gt%3Bcontract_key%2C%20pk_info)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20%26lt%3B%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_MESSAGE(%22!!!%20failed-mbedtls_pk_setup%5Cr%5Cn%22)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ec%20%3D%20mbedtls_pk_ec(iso-%26gt%3Bcontract_key)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_ecp_group_load(%26amp%3Bec-%26gt%3Bgrp%2C%20MBEDTLS_ECP_DP_SECP256R1)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20%26lt%3B%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_MESSAGE(%22!!!%20failed-mbedtls_ecp_group_load%5Cr%5Cn%22)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20isoPrintDumpBytes(%22PrivateKey%22%2C%20output%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20uint8_t%20*uds_buf%20%3D%20(uint8_t%20*)get_gq_uds_buffer()%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20memset(uds_buf%2C%200%2C%2064)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20memcpy(uds_buf%2B64%2C%20output%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20no%20%3D%20pki_get_index(KEY_CONTRACT_LEAF)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if(no%20%26lt%3B%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pki_add(KEY_CONTRACT_LEAF%2C%20uds_buf%2C%20bytesLen%2B64)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20else%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pki_replace(no%2C%20KEY_CONTRACT_LEAF%2C%20uds_buf%2C%20bytesLen%2B64)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Release%20the%20uds%20buffer%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20put_gq_uds_buffer()%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_mpi_read_binary(%26amp%3Bec-%26gt%3Bd%2C%20output%2C%20bytesLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20%26lt%3B%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SYS_CONSOLE_MESSAGE(%22!!!%20failed-mbedtls_mp_read_binary%5Cn%22)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(temp_shared%20!%3D%20NULL)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20vPortFree(temp_shared)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_mpi_free(%26amp%3Bz)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_aes_free(%26amp%3Baes)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20mbedtls_ecdh_free(%26amp%3Becdh)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20omission%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EcreateSignature%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20omission%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20rc%20%3D%20mbedtls_pk_sign(%26amp%3Biso-%26gt%3Bcontract_key%2C%20MBEDTLS_MD_SHA256%2C%20hash2%2C%2032%2C%20asn%2C%20%26amp%3Bsiglen%2C%20mbedtls_ctr_drbg_random%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%26amp%3Bctr_drbg)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(rc%20!%3D%200)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BSYS_CONSOLE_PRINT(%22mbedtls_pk_sign%20failed%20%25d%5Cr%5Cn%22%2C%20rc%20)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*-----------------------------------------------------------------------------------*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Signature-%26gt%3BSignatureValue%20%EB%82%B4%EC%9A%A9%20%EC%B1%84%EC%9A%B0%EA%B8%B0%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*-----------------------------------------------------------------------------------*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SignatureValue-%26gt%3BId_isUsed%20%3D%200%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20SignatureValue-%26gt%3BCONTENT%20%ED%95%A0%EB%8B%B9%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20requiredLen%20%3D%20sizeof(struct%20iso1SignatureValueType_CONTENT)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20retalloc%20%3D%20iso1AllocZCodecEncBuffer(requiredLen)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(retalloc%20!%3D%20NULL)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20GQ_ISO_MEMCPY(%26amp%3B(SignatureValue-%26gt%3BCONTENT)%2C%20%26amp%3B(retalloc)%2C%20sizeof(void%20*))%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20SignatureValue-%26gt%3BCONTENT%20%EA%B0%92%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SignatureValue-%26gt%3BCONTENT-%26gt%3BbytesLen%20%3D%2064%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20MISRA_C_2012_17_07%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pasn1%20%3D%20%26amp%3Basn%5B4%5D%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20s_index%20%3D%2037%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(asn%5B3%5D%20%3D%3D%2033)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pasn1%2B%2B%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20s_index%2B%2B%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20memcpy(%26amp%3BSignatureValue-%26gt%3BCONTENT-%26gt%3Bbytes%5B0%5D%2C%20pasn1%2C%2032)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pasn1%2B%3D%2032%20%2B%202%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(asn%5Bs_index%5D%20%3D%3D%2033)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pasn1%2B%2B%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20memcpy(%26amp%3BSignatureValue-%26gt%3BCONTENT-%26gt%3Bbytes%5B32%5D%2C%20pasn1%2C%2032)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20omission%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1994187%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20S32K314%20question%20about%20TLS%20API%20with%20HSE%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1994187%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EDear%3C%2FP%3E%3CDIV%3EAbout%20problem%2C%20program%20copy%20an%20additional%20key%20handler%20through%20the%20key%20handler%20and%20exported%20it%20to%20obtain%20the%20key%20value%2C%20and%26nbsp%3B%20implemented%20the%20program%20as%20follow%20sw.%20I%20have%20two%20questions.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E1.%20When%20I%20execute%20the%20following%2C%20HSE_MY_KeyDeriveCopyKey()%20returns%20HSE_SRV_RSP_INVALID_PARAM.%20Can%20you%20tell%20me%20what%20is%20wrong%3F%3C%2FDIV%3E%3CDIV%3E2.%20Can%20I%20obtain%20the%20Shared%20secret%20(used%20by%20DH%20key%20exchange%20protocols)%20value%20normally%20like%20this%3F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Estatic%20hseSrvResponse_t%20HSE_KeyDeriveCopyKeyContent%3C%2FDIV%3E%3CDIV%3E(%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseKeyHandle_t%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20targetKeyHandle%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseKeyInfo_t%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20keyInfo%2C%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Euint16_t%20*pPubKeyLength%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Euint8_t%20*pPubKey%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20uint8_t%20u8MuChannel%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseSrvResponse_t%20srvResponse%20%3D%20-5%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Get%20a%20free%20channel%20on%20u8MuInstance%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20u8MuChannel%20%3D%20Hse_Ip_GetFreeChannel(APP_MU_INSTANCE_U8)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20if(HSE_IP_INVALID_MU_CHANNEL_U8%20%3D%3D%20u8MuChannel)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20goto%20exit%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*note%3A%20which%20MU%20channel%20need%20to%20specify%3F*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseSrvDescriptor_t%20*pHseSrvDesc%20%3D%20%26amp%3BHse_aSrvDescriptor%5Bu8MuChannel%5D%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseExportKeySrv_t*%26nbsp%3B%20pExportKeyReq%20%3D%20%26amp%3BpHseSrvDesc-%26gt%3BhseSrv.exportKeyReq%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20memset(pHseSrvDesc%2C%200%2C%20sizeof(hseSrvDescriptor_t))%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pHseSrvDesc-%26gt%3BsrvId%20%3D%20HSE_SRV_ID_EXPORT_KEY%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExportKeyReq-%26gt%3BtargetKeyHandle%20%3D%20targetKeyHandle%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExportKeyReq-%26gt%3BpKey%5B0%5D%20%3D%20(HOST_ADDR)pPubKey%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExportKeyReq-%26gt%3BpKeyLen%5B0%5D%20%3D%20(HOST_ADDR)pPubKeyLength%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExportKeyReq-%26gt%3Bcipher.cipherKeyHandle%20%3D%20HSE_INVALID_KEY_HANDLE%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExportKeyReq-%26gt%3BkeyContainer.authKeyHandle%20%3D%20HSE_INVALID_KEY_HANDLE%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20Build%20the%20request%20to%20be%20sent%20to%20Hse%20Ip%20layer%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20HseIp_aRequest%5Bu8MuChannel%5D.eReqType%26nbsp%3B%20%26nbsp%3B%3D%20HSE_IP_REQTYPE_SYNC%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20HseIp_aRequest%5Bu8MuChannel%5D.u32Timeout%20%3D%20TIMEOUT_TICKS_U32%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*note%3A%20which%20MU%20channel%20need%20to%20specify%3F*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20srvResponse%20%3D%20Hse_Ip_ServiceRequest(APP_MU_INSTANCE_U8%2C%20u8MuChannel%2C%20%26amp%3BHseIp_aRequest%5Bu8MuChannel%5D%2C%20pHseSrvDesc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Eexit%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20return%20srvResponse%3B%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EhseSrvResponse_t%20HSE_MY_KeyDeriveCopyKey%3C%2FDIV%3E%3CDIV%3E(%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseKeyHandle_t%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20keyHandle%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20uint16_t%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20startOffset%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseKeyHandle_t%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20targetKeyHandle%2C%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseKeyInfo_t%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20keyInfo%3C%2FDIV%3E%3CDIV%3E)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20uint8_t%20u8MuChannel%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseSrvResponse_t%20srvResponse%20%3D%20HSE_SRV_RSP_GENERAL_ERROR%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Get%20a%20free%20channel%20on%20u8MuInstance%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20u8MuChannel%20%3D%20Hse_Ip_GetFreeChannel(APP_MU_INSTANCE_U8)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20if(HSE_IP_INVALID_MU_CHANNEL_U8%20%3D%3D%20u8MuChannel)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20goto%20exit%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*note%3A%20which%20MU%20channel%20need%20to%20specify%3F*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseSrvDescriptor_t%20*pHseSrvDesc%20%3D%20%26amp%3BHse_aSrvDescriptor%5Bu8MuChannel%5D%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20hseKeyDeriveCopyKeySrv_t%20*pExtractKeySrv%20%3D%20%26amp%3B(pHseSrvDesc-%26gt%3BhseSrv.keyDeriveCopyKeyReq)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20memset(pHseSrvDesc%2C%200%2C%20sizeof(hseSrvDescriptor_t))%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pHseSrvDesc-%26gt%3BsrvId%20%3D%20HSE_SRV_ID_KEY_DERIVE_COPY%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExtractKeySrv-%26gt%3BkeyHandle%20%3D%20keyHandle%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExtractKeySrv-%26gt%3BstartOffset%20%3D%20startOffset%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExtractKeySrv-%26gt%3BtargetKeyHandle%20%3D%20targetKeyHandle%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pExtractKeySrv-%26gt%3BkeyInfo%20%3D%20keyInfo%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20Build%20the%20request%20to%20be%20sent%20to%20Hse%20Ip%20layer%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20HseIp_aRequest%5Bu8MuChannel%5D.eReqType%26nbsp%3B%20%26nbsp%3B%3D%20HSE_IP_REQTYPE_SYNC%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20HseIp_aRequest%5Bu8MuChannel%5D.u32Timeout%20%3D%20TIMEOUT_TICKS_U32%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*note%3A%20which%20MU%20channel%20need%20to%20specify%3F*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20srvResponse%20%3D%20Hse_Ip_ServiceRequest(APP_MU_INSTANCE_U8%2C%20u8MuChannel%2C%20%26amp%3BHseIp_aRequest%5Bu8MuChannel%5D%2C%20pHseSrvDesc)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Eexit%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20return%20srvResponse%3B%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Eint32_t%20gq_getComputeSharedKey(uint32_t%20keyHandle%2C%20uint8_t%20*keyBuf)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20uint8_t%20keyBuf%5B32%5D%3B%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20uint16_t%20keyBufLen%20%3D%2032%3B%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EhseKeyInfo_t%20KeyInfo%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EhseSrvResponse_t%20srvResponse%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eint32_t%20ret%20%3D%200%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Euint32_t%20copykeyslot%20%3D%20HSE_INVALID_KEY_HANDLE%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20uint8_t%20export_key%5B32%5D%3D%7B%200%2C%20%7D%3B%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ekey_import_param_t%20key_import_param_shared%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ememset(%26amp%3Bkey_import_param_shared%2C%200x00%2C%20sizeof(key_import_param_t))%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20copy%20shared%20secret%20key%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ekey_import_param_shared.key_type%20%3D%20HSE_KEY_TYPE_SHARED_SECRET%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ekey_import_param_shared.key_catalog%20%3D%20HSE_KEY_CATALOG_ID_RAM%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ekey_import_param_shared.key_param.sym_key_param.size%20%3D%20256u%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EKeystoreMgmt_FindAllocateSlot(%26amp%3Bkey_import_param_shared%2C%20%26amp%3Bcopykeyslot)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ememset(keyBuf%2C%200%2C%20keyBufLen)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EsrvResponse%20%3D%20HSE_GetKeyInfo(keyHandle%2C%20%26amp%3BKeyInfo)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif(srvResponse%20%3D%3D%20HSE_SRV_RSP_OK)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EKeyInfo.keyFlags%20%3D%20(HSE_KF_USAGE_ENCRYPT%20%7C%20HSE_KF_USAGE_DECRYPT%20%7C%20HSE_KF_USAGE_SIGN%20%7C%20HSE_KF_USAGE_VERIFY%20%7C%20HSE_KF_USAGE_DERIVE)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EKeyInfo.keyType%20%3D%20HSE_KEY_TYPE_SHARED_SECRET%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eprintf(%22copykeyslot%3D0x%2508x%5Cn%22%2C%20copykeyslot)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20copykeyslot%20%3D%200x00020601%3B%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EsrvResponse%20%3D%20HSE_MY_KeyDeriveCopyKey(keyHandle%2C%200%2C%20copykeyslot%2C%20KeyInfo)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif(srvResponse%20!%3D%20HSE_SRV_RSP_OK)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eret%20%3D%20srvResponse%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eprintf(%22HSE_KeyDeriveCopyKey()%20is%20ok%5Cr%5Cn%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EsrvResponse%20%3D%20HSE_KeyDeriveCopyKeyContent(copykeyslot%2C%20KeyInfo%2C%20%26amp%3BkeyBufLen%2C%20keyBuf)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif(srvResponse%20!%3D%20HSE_SRV_RSP_OK)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eret%20%3D%20srvResponse%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eprintf(%22HSE_KeyDeriveCopyKeyContent()%20is%20ok%5Cr%5Cn%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eret%20%3D%20-2%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ereturn%20ret%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3C%2FLINGO-BODY%3E