1.23 CRYPT_ECC_DHE_SharedSecretMake Function

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

ParametersDescription
privPointer to the private ECC context (with the private key).
pubPointer to the public ECC context (with the public key).
outDestination of the shared secret.
outSzThe max size of the shared secret.
usedSzResulting 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);