Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 1.57 KB

GUID-16831BD0-5D75-4ABB-9D38-9730C6AD53E6.md

File metadata and controls

65 lines (45 loc) · 1.57 KB

CRYPT_ECC_DHE_SharedSecretMake Function

Parent topic:MPLAB® Harmony Crypto Library

C

int CRYPT_ECC_DHE_SharedSecretMake(
    CRYPT_ECC_CTX* priv, 
    CRYPT_ECC_CTX* pub, 
    unsigned char* out, 
    unsigned int outSz, 
    unsigned int* usedSz
);

Description

This function takes two ECC contexts (one public, one private) and creates a shared secret between the two. The secret conforms to EC-DH from ANSU X9.63.

Preconditions

Both contexts must have been initialized with a call to CRYPT_ECC_Initialize. Both contexts have had their respective keys imported or created.

Parameters

Parameters Description
priv Pointer to the private ECC context (with the private key).
pub Pointer to the public ECC context (with the public key).
out Destination of the shared secret.
outSz The max size of the shared secret.
usedSz Resulting size of the shared secret.

Returns

  • BAD_FUNC_ARG - An invalid pointer was passed to the function.

  • MEMORY_E - Could not create the memory buffer for the shared secret.

  • 0 - An invalid pointer was not passed to the function.

Remarks

None.

Example

CRYPT_ECC_CTX userA; 
CRYPT_ECC_CTX userB;
int           ret;
byte          sharedA[100];
unsigned int  aSz   = (unsigned int)sizeof(sharedA);
unsigned int  usedA = 0;

ret = CRYPT_ECC_Initialize(&userA);
ret = CRYPT_ECC_Initialize(&userB);
...
// Make or import the appropriate keys
...
ret = CRYPT_ECC_DHE_SharedSecretMake(&userA, &userB, sharedA, aSz, &usedA);