EcdhP256.sharedSecret

ubyte[] sharedSecret(const(ubyte)[] peerX, const(ubyte)[] peerY)

Compute the ECDH shared secret with a peer's public key.

The shared secret is the x-coordinate of d * Q_peer, as a 32-byte big-endian unsigned integer.

The peer point is validated (on-curve, coordinates in [0, p), not the point at infinity) before any multiplication. An invalid point would otherwise enable invalid-curve and small-subgroup attacks that can recover the private scalar.

Parameters

peerXPeer public key x-coordinate (32 bytes).
peerYPeer public key y-coordinate (32 bytes).

Returns

The 32-byte shared secret.

Throws

CryptoException if the peer point is not a valid P-256

point.