I am looking to perform ECDH between 2 platforms to derive a shared secret. I am planning to use a named curve (which curve not yet determined). The flow would look something like this:
- Alice picks a curve
- Alice generates a random key pair for her curve
- Alice serializes some data about her curve
- Alice sends her public key and curve data to Bob
- Bob initializes a curve with Alice's data
- Bob creates a key pair based on Alice's data
- Bob performs ECDH to derive shared secret
- Bob responds to Alice with his public key
- Alice performs ECDH to derive shared secret
Using bouncycastle, what is the cleanest way to accomplish this?
Almost all examples I've seen (like this one: https://gist.github.com/wuyongzheng/0e2ed6d8a075153efcd3) illustrate the process of arriving at the shared secret, but none seem to factor in the process of actually serializing information about the curve / starting point (G) to "Bob" and how to use that data on Bob's side to rebuild the curve and generate corresponding keys. What data would you need to send to Bob?
I believe i found a relatively succinct way of demonstrating the problem / solution for this. I was originally missing the fact that named curves include a common starting point, so no need to serialize that data if you have an agreed-upon curve.
And on first run, this yielded: