7.3.1 Crypto_Kas_Ecdh_SharedSecret

crypto_Kas_Status_E Crypto_Kas_Ecdh_SharedSecret(
    crypto_HandlerType_E ecdhHandlerType_en, 
    uint8_t *ptr_privKey, 
    uint32_t privKeyLen, 
    uint8_t *ptr_pubKey, 
    uint32_t pubKeyLen, 
    uint8_t *ptr_sharedSecret, 
    uint32_t sharedSecretLen, 
    crypto_EccCurveType_E eccCurveType_en, 
    uint32_t ecdhSessionId
    );

Description

This API is utilized to generate a shared secret using the ECDH algorithm. It requires the ECC private key of one party and the ECC public key of another party as inputs to generate the shared secret. These keys must adhere to the ANSI X9.63 format. Additionally, it's crucial that the ECC keys used in this API are generated from the same curve type.

Parameters

No.Argument TypeArgument NameTypeDescription
1crypto_HandlerType_EecdhHandlerType_enInputEnum for crypto operation handler i.e., SW, HW
2uint8_t*ptr_privKeyInputPointer to hold private key in x9.63 format
3uint32_tprivKeyLenInputLength of ECC private key in bytes
4uint8_t*ptr_pubKeyInputPointer to hold public key in x9.63 format
4uint32_tpubKeyLenInputLength of ECC public key in bytes
6uint8_t*ptr_sharedSecretOutputPointer holds the generated Shared Secret
7uint32_tsharedSecretLenInputLength of Shared Secret in bytes
8crypto_EccCurveType_EeccCurveType_enInputCurve type used for the ECC keys
9uint32_tecdhSessionIdInputIt defines the session ID, must be more than zero

Returns

Return TypeDescription
crypto_Kas_Status_EFunction returns the status of the API.

Example

#define sessionID 1
crypto_Kas_Status_E status;
crypto_HandlerType_E handlerType_en = CRYPTO_HANDLER_HW_INTERNAL;
uint8_t privKey[32] = {/*data*/};
uint32_t privKeyLen = sizeof(privKey);
uint8_t pubKey[32] = {/*data*/};
uint32_t pubKeyLen = sizeof(pubKey);
uint8_t sharedSecret[64];
uint32_t sharedSecretLen = sizeof(sharedSecret);
crypto_EccCurveType_E eccCurveType_en = CRYPTO_ECC_CURVE_SECP256R1;

status = Crypto_Kas_Ecdh_SharedSecret (
    handlerType_en,
    privKey,
    privKeyLen,
    pubKey,
    pubKeyLen,
    sharedSecret,
    sharedSecretLen,
    eccCurveType_en,
    sessionID
    );