How to calculate shared secret in ECDH protocol

How to calculate shared secret in ECDH protocol

I have to implement a protocol where the client sends his EC public key
and my fist step is to generate my own ephemeral EC public/private key
pair and then calculate shared secret, which will be used later to generate session keys.

The elliptic curve in question is brainpoolP224r1. Below is my code (with hardcoded values), which either returs wrong result or throws an expection 'The multiplicator cannot be negative'. Any help would be very appreciated.

I have to implement a protocol where the client sends his EC public key and my fist step is to generate my own ephemeral EC public/private key pair and then calculate shared secret, which will be used later
to generate session keys.

The elliptic curve in question is brainpoolP224r1. Below is my code (with hardcoded values), which either returs wrong result or throws an expection 'The multiplicator cannot be negative'. Any help would be
very appreciated.