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/crypto/p256_key_exchange.h" | 5 #include "net/quic/crypto/p256_key_exchange.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/numerics/safe_conversions.h" |
8 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
9 | 10 |
10 using base::StringPiece; | 11 using base::StringPiece; |
11 using std::string; | 12 using std::string; |
12 using std::vector; | 13 using std::vector; |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // NSS lacks the ability to import an ECC private key without | 125 // NSS lacks the ability to import an ECC private key without |
125 // also importing the public key, so it is necessary to also | 126 // also importing the public key, so it is necessary to also |
126 // store the public key. | 127 // store the public key. |
127 vector<uint8> public_key; | 128 vector<uint8> public_key; |
128 if (!key_pair->ExportPublicKey(&public_key)) { | 129 if (!key_pair->ExportPublicKey(&public_key)) { |
129 DVLOG(1) << "Can't export public key."; | 130 DVLOG(1) << "Can't export public key."; |
130 return string(); | 131 return string(); |
131 } | 132 } |
132 | 133 |
133 // TODO(thaidn): determine how large encrypted private key can be | 134 // TODO(thaidn): determine how large encrypted private key can be |
134 uint16 private_key_size = private_key.size(); | 135 uint16 private_key_size = base::checked_cast<uint16>(private_key.size()); |
135 const size_t result_size = sizeof(private_key_size) + | 136 const size_t result_size = sizeof(private_key_size) + |
136 private_key_size + | 137 private_key_size + |
137 public_key.size(); | 138 public_key.size(); |
138 vector<char> result(result_size); | 139 vector<char> result(result_size); |
139 char* resultp = &result[0]; | 140 char* resultp = &result[0]; |
140 // Export the key string. | 141 // Export the key string. |
141 // The first two bytes are the private key's size in little endian. | 142 // The first two bytes are the private key's size in little endian. |
142 private_key_size = base::ByteSwapToLE16(private_key_size); | 143 private_key_size = base::ByteSwapToLE16(private_key_size); |
143 memcpy(resultp, &private_key_size, sizeof(private_key_size)); | 144 memcpy(resultp, &private_key_size, sizeof(private_key_size)); |
144 resultp += sizeof(private_key_size); | 145 resultp += sizeof(private_key_size); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 224 } |
224 | 225 |
225 StringPiece P256KeyExchange::public_value() const { | 226 StringPiece P256KeyExchange::public_value() const { |
226 return StringPiece(reinterpret_cast<const char*>(public_key_), | 227 return StringPiece(reinterpret_cast<const char*>(public_key_), |
227 sizeof(public_key_)); | 228 sizeof(public_key_)); |
228 } | 229 } |
229 | 230 |
230 QuicTag P256KeyExchange::tag() const { return kP256; } | 231 QuicTag P256KeyExchange::tag() const { return kP256; } |
231 | 232 |
232 } // namespace net | 233 } // namespace net |
OLD | NEW |