Alice and Bob need to share public keys to sign/verify ephemeral keys. They have a secret key $K$.
- Alice generates a 32 bytes random number $A$, computes $\operatorname{HMAC-SHA256}(K, M||A)$ and sends Bob the hash and plain $M$, $A$
- Bob computes $\operatorname{HMAC-SHA256}(K, M||A)$ to check the hashes
- If hashes match, Bob computes $N=\operatorname{HKDF}(A||K)$
- Bob encrypts his public key $E_N(\mathit{PubKeyBob})$ using AES 256 GCM, and sends the cipher to Alice
- Alice computes $N$ and decrypts the cipher, encrypts her public key $E_N(\mathit{PubKeyAlice})$, and sends Bob the cipher
- Bob decrypts the cipher and they both have each other's public key
Is this a safe way to share public keys?