Currently, I am working on implementing an ECDH key-exchange using the P-384 curve. While other curves could be used, I believe the implementations should be fairly similar in nature.
The goal is for the Client (Javascript) and Server(Java) to establish a shared secret by following these steps:
1) The server generates both a public and private key.
2) The server then sends its public key to the client, which is 120 bytes long.
3) Subsequently, the client generates its own private and public keys. The public key is 97 bytes long while the private key is 48 bytes.
4) However, when the client attempts to calculate the shared secret, it encounters a "Bad argument" error.
On the client side, Google-Closure-Library with the e2e package is being utilized. You can find more information here: https://code.google.com/p/end-to-end/source/browse/javascript/crypto/e2e#e2e%2Fecc
I examined the ecdh.js and ecdh_test.html files for implementation guidance.
My current client-side implementation looks like this:
var serverPublicKeyStringAsHex = "3076301006072a8648ce3d020106052b8104....." //*
var serverPublicKey = goog.crypt.hexToByteArray(serverPublicKeyStringAsHex)
var bobKeyPair = e2e.ecc.Protocol.generateKeyPair("P_384");
var bobECDH = new e2e.ecc.Ecdh("P_384");
var bobMessage = bobECDH.bob(serverPublicKey, bobKeyPair['privKey']);
Despite following these steps, the console displays a "bad argument" error message.
Could the issue be related to the incorrect length of the server's public key? If so, how might the problem be resolved considering that the same EC is used on the server-side?
After researching key lengths in this "public-key-length" question, I learned about uncompressed and compressed representations of keys. Nevertheless, it seems unlikely that this is the cause of my problem since the key lengths (server public key: 120 bytes, client public key: 97 bytes) do not align with the specified patterns (field size + 1 versus 2* field size + 1)
Your assistance is greatly appreciated as I have dedicated many hours to troubleshooting this issue and am unsure of what steps to take next.
*If relevant, here is the full public key: 3076301006072a8648ce3d020106052b8104002203620004f87dc79943b20e0f57d61f8b7d02425baa4d1220b8b8c1e3596f5ab49ae6ad2acffad95e5860231821b4aedefe5cf1d0262563cffdc8dbe4f28973ebebf3985ba50c7b275888934dcd607007c288a5afaf196834395983cd7f01c548e5edca0b