I'm currently working in a constrained environment and need to derive a symmetric key (that will be used for AES-256 in GCM mode later) based on a low-entropy shared secret obtained via X25519.
To derive a symmetric key RFC 7748 states: Alice and Bob can then use a key-derivation function that includes K, K_A, and K_B to derive a symmetric key, where K is the shared secret, K_A is the public key of one participant in the key exchange and K_B is the public key of the other participant.
Since the RFC is rather vague here, I took a look at the implementation of libsodium. They implement the following key derivation (described in this page): rx || tx = BLAKE2B-512(p.n || client_pk || server_pk), where p.n is the shared secret, client_pk is the public key of the client and server_pk is the public key of the server.
The problem I am currently facing is that my constrained environment does not support BLAKE2B. So, I thought of the following options:
- Use another hash function implemented in my environment like SHA-512
- Use a known key derivation function like HKDF (also available in my environment)
Are both options 1 and 2 appropriate or do you see any security risks in either of them?