hu_ECDHCofacRawXYSharedGen()

Generates a shared secret that is the output of an ECDH key agreement using cofactor multiplication with optional y-coordinate output.

Synopsis:

#include "huecc.h"
 
int hu_ECDHCofacRawXYSharedGen(sb_Params eccParams, sb_PrivateKey privateKey, sb_PublicKey remotePublicKey, size_t *secretLen, unsigned char *sharedSecretX, unsigned char *sharedSecretY, sb_GlobalCtx sbCtx)

Since:

BlackBerry 10.0.0

Arguments:

eccParams

An ECC parameters object.

privateKey

An ECC private key object.

remotePublicKey

An ECC public key object.

secretLen

The length (in bytes) of the shared secret (x- or y- coordinate).

sharedSecretX

The shared secret buffer for x-coordinate.

sharedSecretY

The shared secret buffer for y-coordinate.

sbCtx

A global context.

Library:

libhuapi (For the qcc command, use the -l huapi option to link against this library)

Description:

The x-coordinate of the resultant elliptic curve point from the ECDH Cofactor operation is the raw shared secret. If the length of the shared secret is known, a pointer to a buffer large enough to hold the shared secret should be passed in sharedSecretX and its length in secretLen. This function will copy the shared secret (x-coordinate) into sharedSecretX and set the actual length of the shared secret (i.e. the x-coordinate) in secretLen.

If sharedSecretX is NULL, this function will set the correct length of the shared secret (i.e. the x-coordinate) in secretLen.

If sharedSecretX is not NULL but secretLen is too small, this function will return an error and set the correct length of the shared secret (i.e. the x-coordinate) in secretLen.

The output of y-coordinate is optional. Set sharedSecretY to NULL if the y-coordinate is not required. If sharedSecretX is NULL, this argument is ignored. Note that the length of x- and y-coordinates are the same. Therefore, secretLen is shared to contain the size of each buffer.

The length of the shared secret can also be determined by calling hu_ECCParamsGet() and retrieving the reducLen argument.

Returns:

SB_ERR_NULL_PARAMS

The eccParams object is NULL.

SB_ERR_BAD_PARAMS

The tag for the params object is not of the expected type.

SB_ERR_NULL_PRIVATE_KEY

The privateKey object NULL.

SB_ERR_BAD_PRIVATE_KEY

The privateKey object invalid.

SB_ERR_NULL_PUBLIC_KEY

The publicKey object is NULL.

SB_ERR_BAD_PUBLIC_KEY

The publicKey object is invalid.

SB_ERR_NULL_OUTPUT_BUF_LEN

The shared secret buffer is NULL.

SB_ERR_BAD_OUTPUT_BUF_LEN

The shared secret length is invalid.

SB_FAIL_ALLOC

Memory allocation failure.

SB_SUCCESS

Success.