Skip to main content

SecurityLocalGenerateSharedSecret

Valid for: CANoe DE • CANoe4SW DE Note
Replaces SecurityLocalGenerateSharedSecretECDH and respectively LocalSecurityGenerateSharedSecretECDH.

Function Syntax

Description

Generates a shared secret between A and B using the Elliptic Curve Diffie-Hellman (ECDH) protocol. Currently the curves NIST P-256, NIST P-384, NIST P-521 and X25519 are supported.

Parameters

  • dword curve
    The elliptic curve to use for shared secret generation.
    Possible Values:
    • 10 → NIST P-256
    • 11 → NIST P-384
    • 12 → NIST P-521
    • 20 → X25519
  • byte publicKey[]
    The public key of A. Supported are the uncompressed form 0x04 | HEX(x) | HEX(y) as well as the compressed forms 0x02 | HEX(x) (for even y) OR 0x03 | HEX(x) (for odd y).
  • dword publicKeyLength
    The length of the generated public key.
    • NIST P-256: 65 bytes (uncompressed) or 32 bytes (compressed)
    • NIST P-384: 97 bytes (uncompressed) or 49 bytes (compressed)
    • NIST P-521: 133 bytes (uncompressed) or 67 bytes (compressed)
    • X25519: 32 bytes
  • byte privateKey[]
    The private key of B.
  • dword privateKeyLength
    The length of the private key of B.
    • NIST P-256: 32 bytes
    • NIST P-384: 48 bytes
    • NIST P-521: 66 bytes
    • X25519: 32 bytes
  • byte sharedSecret[] [OUT]
    The generated shared secret.
  • dword sharedSecretLength [IN/OUT]
    The length of the generated shared secret.
    • NIST P-256: 32 bytes
    • NIST P-384: 48 bytes
    • NIST P-521: 66 bytes
    • X25519: 32 bytes

Return Values

  • 1
    Success
    A value of 1 means that the action was successful.
  • <= 0
    Error
    A value less than or equal to 0 means error.

Example

SecurityLocalGenerateEphemeralKeyPair