1
$\begingroup$

My end goal is to encrypt data with AES-128, send it to other process and decrypt it there. While using DH key exchange protocol.

I have used DH to generate a 256 bytes shared secret, but I can't use that key to fit the 128-bit encrypting function.

I read that the secret needs to be fed through a "Key-based key derivation function" (KBKDF), but as I understand that gives you a hash which then you won't be able to dehash... so how does the other program can decrypt the message?

Can I just truncate the secret message to 128-bit? (I don't think this is the right solution though).

How would the encryption and decryption of the hashed secret work?

Side note. I am trying to do all this with OpenSSL library in C

Thanks.

$\endgroup$

2 Answers 2

1
$\begingroup$

I read that the secret needs to be fed through a "Key based key derivation function" (KBKDF), but as I understand that gives you a hash which then you won't be able to dehash... so how does the other program can decrypt the message?

The encryptor sends the DH shared secret through the KDF, which gives him a key, which he uses as (for example) an AES key, and uses that AES key to encrypt his data.

The decryptor sends the same DH shared secret through the KDF, which gives him the same key, which he uses as an AES key, and uses that AES key to decrypt his data.

There's no need to 'invert' the KDF; both sides use it in the forward direction

$\endgroup$
3
  • $\begingroup$ It makes sense now. I wasn't sure both ends were going to give the same key. Got the KDF by using the Bytes2Key() function on openSSL. Thanks for the help. $\endgroup$
    – Farynx
    Mar 15, 2019 at 16:56
  • $\begingroup$ @Farynx: if you found this answer helpful, please upvote it $\endgroup$
    – poncho
    Mar 15, 2019 at 17:28
  • $\begingroup$ I did but because my reputation score is not big enough it wont show it publicly $\endgroup$
    – Farynx
    Mar 15, 2019 at 18:06
0
$\begingroup$

Diffie Hellman is a key exchange protocol with perfect forward secrecy. Actually, both sides agree on the key, that is at the end of the protocol both sides have the key $g^{ab}$ where

  • Alice chooses a random secret $a$ and sent $g^a$ to Bob, and
  • Bob chooses a random secret $b$ and sent $g^b$ to Alice.

Alice calculates $(g^b)^a = g^{ab}$ and similarly Bob $(g^a)^b = g^{ab}$ by using their secrets.

Truncate is an option, however, it is usually applied with KDF.

Note: you should use Elliptic Curve-based DHKE.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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