OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/core/crypto/p256_key_exchange.h" | 5 #include "net/quic/core/crypto/p256_key_exchange.h" |
6 | 6 |
| 7 #include <cstdint> |
| 8 #include <memory> |
| 9 #include <string> |
7 #include <utility> | 10 #include <utility> |
8 | 11 |
9 #include "base/logging.h" | 12 #include "base/logging.h" |
10 #include "third_party/boringssl/src/include/openssl/ec.h" | 13 #include "third_party/boringssl/src/include/openssl/ec.h" |
11 #include "third_party/boringssl/src/include/openssl/ecdh.h" | 14 #include "third_party/boringssl/src/include/openssl/ecdh.h" |
| 15 #include "third_party/boringssl/src/include/openssl/err.h" |
12 #include "third_party/boringssl/src/include/openssl/evp.h" | 16 #include "third_party/boringssl/src/include/openssl/evp.h" |
13 | 17 |
14 using base::StringPiece; | 18 using base::StringPiece; |
15 using std::string; | 19 using std::string; |
16 | 20 |
17 namespace net { | 21 namespace net { |
18 | 22 |
19 P256KeyExchange::P256KeyExchange(bssl::UniquePtr<EC_KEY> private_key, | 23 P256KeyExchange::P256KeyExchange(bssl::UniquePtr<EC_KEY> private_key, |
20 const uint8_t* public_key) | 24 const uint8_t* public_key) |
21 : private_key_(std::move(private_key)) { | 25 : private_key_(std::move(private_key)) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 85 |
82 bool P256KeyExchange::CalculateSharedKey(StringPiece peer_public_value, | 86 bool P256KeyExchange::CalculateSharedKey(StringPiece peer_public_value, |
83 string* out_result) const { | 87 string* out_result) const { |
84 if (peer_public_value.size() != kUncompressedP256PointBytes) { | 88 if (peer_public_value.size() != kUncompressedP256PointBytes) { |
85 DVLOG(1) << "Peer public value is invalid"; | 89 DVLOG(1) << "Peer public value is invalid"; |
86 return false; | 90 return false; |
87 } | 91 } |
88 | 92 |
89 bssl::UniquePtr<EC_POINT> point( | 93 bssl::UniquePtr<EC_POINT> point( |
90 EC_POINT_new(EC_KEY_get0_group(private_key_.get()))); | 94 EC_POINT_new(EC_KEY_get0_group(private_key_.get()))); |
91 if (!point || | 95 if (!point.get() || |
92 !EC_POINT_oct2point(/* also test if point is on curve */ | 96 !EC_POINT_oct2point(/* also test if point is on curve */ |
93 EC_KEY_get0_group(private_key_.get()), point.get(), | 97 EC_KEY_get0_group(private_key_.get()), point.get(), |
94 reinterpret_cast<const uint8_t*>( | 98 reinterpret_cast<const uint8_t*>( |
95 peer_public_value.data()), | 99 peer_public_value.data()), |
96 peer_public_value.size(), nullptr)) { | 100 peer_public_value.size(), nullptr)) { |
97 DVLOG(1) << "Can't convert peer public value to curve point."; | 101 DVLOG(1) << "Can't convert peer public value to curve point."; |
98 return false; | 102 return false; |
99 } | 103 } |
100 | 104 |
101 uint8_t result[kP256FieldBytes]; | 105 uint8_t result[kP256FieldBytes]; |
(...skipping 10 matching lines...) Expand all Loading... |
112 StringPiece P256KeyExchange::public_value() const { | 116 StringPiece P256KeyExchange::public_value() const { |
113 return StringPiece(reinterpret_cast<const char*>(public_key_), | 117 return StringPiece(reinterpret_cast<const char*>(public_key_), |
114 sizeof(public_key_)); | 118 sizeof(public_key_)); |
115 } | 119 } |
116 | 120 |
117 QuicTag P256KeyExchange::tag() const { | 121 QuicTag P256KeyExchange::tag() const { |
118 return kP256; | 122 return kP256; |
119 } | 123 } |
120 | 124 |
121 } // namespace net | 125 } // namespace net |
OLD | NEW |