Sam
Sam

Reputation: 1535

How to use HKDF with ECDiffieHellmanCng

I am attempting to use the ECDiffieHellmanCng class to perform key exchange operations between a desktop and a device connected over BLE. The specs of the system require that HKDF be used to derive the key. That doesn't appear to be an option for the hash functions in the ECDiffieHellmanCng class. Is there a way to do this? I would then need to take the resulting key and pass it into a AesCng object.

Upvotes: 4

Views: 542

Answers (2)

vcsjones
vcsjones

Reputation: 141703

For .NET 8 and newer, ECDiffieHellman now exposes DeriveRawSecretAgreement, which exposes the raw secret that can be fed in to HKDF (or any other KDF algorithm).

Upvotes: 0

Emil
Emil

Reputation: 18517

The ECDiffieHellmanCng sucks since it forces you to use one of three pre-defined post processing key derivation functions (Hash, Hmac or Tls). If none of these match your protocol you are out of luck.

You might be able to use the Hmac variant however since that is the first internal operation for HKDF ("extract"). Just set the HmacKey property to the salt in HKDF. Then manually perform the second Hmac operation yourself ("expand") to get the final HKDF result.

Upvotes: 3

Related Questions