Actually, I am working on a project to combine symmetric and asymmetric cryptographic algorithms.

The shared secret key for AES will be generated through the Elliptic Curve Diffie Hellman Key Exchange (ECDH) Method. I have one question that ECDH will generate a shared secret key of 256 bit or more length key. For AES-128 I need a secret key of 128 bit but ECDH is not generating the 128-bit key.

So how can I convert the variable-length key into 128 bit?

  • $\begingroup$ In SO, if the answer is useful, one usually upvotes, and if you are the asker, if the answer satisfies you, you can accept the answer. Have fun. $\endgroup$
    – kelalaka
    Oct 19 at 14:44

There is already good scheme for this, Elliptic Curve Integrated Encryption Scheme (ECIES);

Once you exchanged the keys with ECDH, then you can use a KDF to derive any key length, HKDF is fine.

ECIES also authenticates the ciphertext as Encrypted-then-MAC. In order to use MAC, you need another key. You can use HKDF to derive many keys by providing different info parameters for each required key. Since your key is random you don't need the extract part of the HKDF, if available, just use expand part.

As an advice, use AES-256, it is only %40 times slower than AES-128, however, it is secure against Quantum and Multi-target attacks.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.