HMAC based Key exchange 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?
If they have a pre-shared key $K$ and want to authenticate public keys, the simplest way would be for Alice to compute $T = HMAC(K, PubKeyAlice)$ and send $(PubKeyAlice,T)$ to Bob.
This authenticates the public key of Alice. There is no need to encrypt it, since it is a  public value anyway.