lcx_ecdh.h | Developers

lcx_ecdh.h

Back to the files list

ECDH (Elliptic Curve Diffie Hellman) key exchange. More...

Functions

cx_err_t cx_ecdh_no_throw (const cx_ecfp_private_key_t *pvkey, uint32_t mode, const uint8_t *P, size_t P_len, uint8_t *secret, size_t secret_len)
 Computes an ECDH shared secret. More...
static int cx_ecdh (const cx_ecfp_private_key_t *pvkey, int mode, const unsigned char *P, unsigned int P_len, unsigned char *secret, unsigned int secret_len)
 Computes an ECDH shared secret. More...

Detailed Description

ECDH (Elliptic Curve Diffie Hellman) key exchange.

ECDH is a key agreement protocol that allows two parties to calculate a shared secret over an insecure channel. The public and private keys are elements of a chosen elliptic curve.

Function Documentation

cx_ecdh()

static int cx_ecdh ( const cx_ecfp_private_key_t pvkey,
int  mode,
const unsigned char *  P,
unsigned int  P_len,
unsigned char *  secret,
unsigned int  secret_len 
)

Computes an ECDH shared secret.

Depending on the mode, the shared secret is either the full point or only the x coordinate. This function throws an exception if the computation doesn't succeed.

Warning
It is recommended to use cx_ecdh_no_throw rather than this function.
Parameters
[in]pvkeyPrivate key. Shall be initialized with cx_ecfp_init_private_key_no_throw.
[in]modeCrypto mode flags. Supported flags:
  • CX_ECDH_POINT
  • CX_ECDH_X
[in]PPointer to the public key encoded as 04 || x || y: x and y are encoded as big endian raw values and have a binary length equal to curve domain size.
[in]P_lenLength of the public key in octets.
[out]secretBuffer where to store the shared secret (full or compressed).
[in]secret_lenLength of the buffer in octets.
Returns
Length of the shared secret.
Exceptions
CX_INVALID_PARAMETER
INVALID_PARAMETER
CX_EC_INVALID_CURVE
CX_MEMORY_FULL
CX_NOT_LOCKED
CX_EC_INVALID_POINT
CX_INVALID_PARAMETER_SIZE
CX_EC_INFINITE_POINT

cx_ecdh_no_throw()

cx_err_t cx_ecdh_no_throw ( const cx_ecfp_private_key_t pvkey,
uint32_t  mode,
const uint8_t *  P,
size_t  P_len,
uint8_t *  secret,
size_t  secret_len 
)

Computes an ECDH shared secret.

Depending on the mode, the shared secret is either the full point or only the x coordinate.

Parameters
[in]pvkeyPrivate key. Shall be initialized with cx_ecfp_init_private_key_no_throw.
[in]modeCrypto mode flags. Supported flags:
  • CX_ECDH_POINT
  • CX_ECDH_X
[in]PPointer to the public key encoded as 04 || x || y: x and y are encoded as big endian raw values and have a binary length equal to curve domain size.
[in]P_lenLength of the public key in octets.
[out]secretBuffer where to store the shared secret (full or compressed).
[in]secret_lenLength of the buffer in octets.
Returns
Error code:
  • CX_OK on success
  • CX_INVALID_PARAMETER
  • INVALID_PARAMETER
  • CX_EC_INVALID_CURVE
  • CX_MEMORY_FULL
  • CX_NOT_LOCKED
  • CX_EC_INVALID_POINT
  • CX_INVALID_PARAMETER_SIZE
  • CX_EC_INFINITE_POINT

Back to the files list


Did you find this page helpful?


How would you improve this page for developers?



Getting Started
Theme Features
Customization

Nano Apps