* Perform the key exchange, and when that is correct fill the \c Packet with the appropriate data. * @param p The packet that has to be sent. * @param derived_key_extra_payload The extra payload to pass to the key exchange. * @return Whether the key exchange was successful or not. */
| 217 | * @return Whether the key exchange was successful or not. |
| 218 | */ |
| 219 | bool X25519AuthenticationHandler::SendResponse(Packet &p, std::string_view derived_key_extra_payload) |
| 220 | { |
| 221 | if (!this->derived_keys.Exchange(this->peer_public_key, X25519KeyExchangeSide::CLIENT, |
| 222 | this->our_secret_key, this->our_public_key, derived_key_extra_payload)) { |
| 223 | Debug(net, 0, "[crypto] Peer sent an illegal public key; authentication aborted."); |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | X25519KeyExchangeMessage message; |
| 228 | RandomBytesWithFallback(message); |
| 229 | X25519Mac mac; |
| 230 | |
| 231 | crypto_aead_lock(message.data(), mac.data(), this->derived_keys.ClientToServer().data(), this->key_exchange_nonce.data(), |
| 232 | this->our_public_key.data(), this->our_public_key.size(), message.data(), message.size()); |
| 233 | |
| 234 | p.Send_bytes(this->our_public_key); |
| 235 | p.Send_bytes(mac); |
| 236 | p.Send_bytes(message); |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Get the public key the peer provided for the key exchange. |
no test coverage detected