xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/crypto/key_exchange.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/quic/core/crypto/key_exchange.h"
6 
7 #include "absl/strings/string_view.h"
8 #include "quiche/quic/core/crypto/curve25519_key_exchange.h"
9 #include "quiche/quic/core/crypto/p256_key_exchange.h"
10 #include "quiche/quic/platform/api/quic_bug_tracker.h"
11 
12 namespace quic {
13 
CreateLocalSynchronousKeyExchange(QuicTag type,absl::string_view private_key)14 std::unique_ptr<SynchronousKeyExchange> CreateLocalSynchronousKeyExchange(
15     QuicTag type, absl::string_view private_key) {
16   switch (type) {
17     case kC255:
18       return Curve25519KeyExchange::New(private_key);
19     case kP256:
20       return P256KeyExchange::New(private_key);
21     default:
22       QUIC_BUG(quic_bug_10712_1)
23           << "Unknown key exchange method: " << QuicTagToString(type);
24       return nullptr;
25   }
26 }
27 
CreateLocalSynchronousKeyExchange(QuicTag type,QuicRandom * rand)28 std::unique_ptr<SynchronousKeyExchange> CreateLocalSynchronousKeyExchange(
29     QuicTag type, QuicRandom* rand) {
30   switch (type) {
31     case kC255:
32       return Curve25519KeyExchange::New(rand);
33     case kP256:
34       return P256KeyExchange::New();
35     default:
36       QUIC_BUG(quic_bug_10712_2)
37           << "Unknown key exchange method: " << QuicTagToString(type);
38       return nullptr;
39   }
40 }
41 
42 }  // namespace quic
43