| 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/crypto_utils.h" | 5 #include "net/quic/core/crypto/crypto_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "crypto/hkdf.h" | 9 #include "crypto/hkdf.h" |
| 10 #include "net/quic/core/crypto/crypto_handshake.h" | 10 #include "net/quic/core/crypto/crypto_handshake.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 !crypters->encrypter->SetNoncePrefix(nonce_prefix)) { | 130 !crypters->encrypter->SetNoncePrefix(nonce_prefix)) { |
| 131 return false; | 131 return false; |
| 132 } | 132 } |
| 133 break; | 133 break; |
| 134 } | 134 } |
| 135 default: | 135 default: |
| 136 DCHECK(false); | 136 DCHECK(false); |
| 137 } | 137 } |
| 138 | 138 |
| 139 if (subkey_secret != nullptr) { | 139 if (subkey_secret != nullptr) { |
| 140 hkdf.subkey_secret().CopyToString(subkey_secret); | 140 *subkey_secret = string(hkdf.subkey_secret()); |
| 141 } | 141 } |
| 142 | 142 |
| 143 return true; | 143 return true; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // static | 146 // static |
| 147 bool CryptoUtils::ExportKeyingMaterial(QuicStringPiece subkey_secret, | 147 bool CryptoUtils::ExportKeyingMaterial(QuicStringPiece subkey_secret, |
| 148 QuicStringPiece label, | 148 QuicStringPiece label, |
| 149 QuicStringPiece context, | 149 QuicStringPiece context, |
| 150 size_t result_len, | 150 size_t result_len, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 161 return false; | 161 return false; |
| 162 } | 162 } |
| 163 uint32_t context_length = static_cast<uint32_t>(context.length()); | 163 uint32_t context_length = static_cast<uint32_t>(context.length()); |
| 164 string info = label.as_string(); | 164 string info = label.as_string(); |
| 165 info.push_back('\0'); | 165 info.push_back('\0'); |
| 166 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length)); | 166 info.append(reinterpret_cast<char*>(&context_length), sizeof(context_length)); |
| 167 info.append(context.data(), context.length()); | 167 info.append(context.data(), context.length()); |
| 168 | 168 |
| 169 crypto::HKDF hkdf(subkey_secret, QuicStringPiece() /* no salt */, info, | 169 crypto::HKDF hkdf(subkey_secret, QuicStringPiece() /* no salt */, info, |
| 170 result_len, 0 /* no fixed IV */, 0 /* no subkey secret */); | 170 result_len, 0 /* no fixed IV */, 0 /* no subkey secret */); |
| 171 hkdf.client_write_key().CopyToString(result); | 171 *result = string(hkdf.client_write_key()); |
| 172 return true; | 172 return true; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // static | 175 // static |
| 176 uint64_t CryptoUtils::ComputeLeafCertHash(QuicStringPiece cert) { | 176 uint64_t CryptoUtils::ComputeLeafCertHash(QuicStringPiece cert) { |
| 177 return QuicUtils::FNV1a_64_Hash(cert); | 177 return QuicUtils::FNV1a_64_Hash(cert); |
| 178 } | 178 } |
| 179 | 179 |
| 180 QuicErrorCode CryptoUtils::ValidateServerHello( | 180 QuicErrorCode CryptoUtils::ValidateServerHello( |
| 181 const CryptoHandshakeMessage& server_hello, | 181 const CryptoHandshakeMessage& server_hello, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 string* output, | 295 string* output, |
| 296 Perspective perspective) { | 296 Perspective perspective) { |
| 297 const QuicData& serialized = message.GetSerialized(perspective); | 297 const QuicData& serialized = message.GetSerialized(perspective); |
| 298 uint8_t digest[SHA256_DIGEST_LENGTH]; | 298 uint8_t digest[SHA256_DIGEST_LENGTH]; |
| 299 SHA256(reinterpret_cast<const uint8_t*>(serialized.data()), | 299 SHA256(reinterpret_cast<const uint8_t*>(serialized.data()), |
| 300 serialized.length(), digest); | 300 serialized.length(), digest); |
| 301 output->assign(reinterpret_cast<const char*>(digest), sizeof(digest)); | 301 output->assign(reinterpret_cast<const char*>(digest), sizeof(digest)); |
| 302 } | 302 } |
| 303 | 303 |
| 304 } // namespace net | 304 } // namespace net |
| OLD | NEW |