| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_utils.h" | 5 #include "net/quic/quic_utils.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 for (int i = 0; i < len; ++i) { | 35 for (int i = 0; i < len; ++i) { |
| 36 hash = hash ^ octets[i]; | 36 hash = hash ^ octets[i]; |
| 37 hash = hash * kPrime; | 37 hash = hash * kPrime; |
| 38 } | 38 } |
| 39 | 39 |
| 40 return hash; | 40 return hash; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // static | 43 // static |
| 44 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { | 44 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { |
| 45 // The following two constants are defined as part of the hash algorithm. | 45 return FNV1a_128_Hash_Two(data, len, nullptr, 0); |
| 46 } |
| 47 |
| 48 // static |
| 49 uint128 QuicUtils::FNV1a_128_Hash_Two(const char* data1, |
| 50 int len1, |
| 51 const char* data2, |
| 52 int len2) { |
| 53 // The two constants are defined as part of the hash algorithm. |
| 46 // see http://www.isthe.com/chongo/tech/comp/fnv/ | 54 // see http://www.isthe.com/chongo/tech/comp/fnv/ |
| 47 // 309485009821345068724781371 | |
| 48 const uint128 kPrime(16777216, 315); | |
| 49 // 144066263297769815596495629667062367629 | 55 // 144066263297769815596495629667062367629 |
| 50 const uint128 kOffset(GG_UINT64_C(7809847782465536322), | 56 const uint128 kOffset(GG_UINT64_C(7809847782465536322), |
| 51 GG_UINT64_C(7113472399480571277)); | 57 GG_UINT64_C(7113472399480571277)); |
| 52 | 58 |
| 59 uint128 hash = IncrementalHash(kOffset, data1, len1); |
| 60 if (data2 == nullptr) { |
| 61 return hash; |
| 62 } |
| 63 return IncrementalHash(hash, data2, len2); |
| 64 } |
| 65 |
| 66 // static |
| 67 uint128 QuicUtils::IncrementalHash(uint128 hash, const char* data, size_t len) { |
| 68 // 309485009821345068724781371 |
| 69 const uint128 kPrime(16777216, 315); |
| 53 const uint8* octets = reinterpret_cast<const uint8*>(data); | 70 const uint8* octets = reinterpret_cast<const uint8*>(data); |
| 54 | 71 for (size_t i = 0; i < len; ++i) { |
| 55 uint128 hash = kOffset; | |
| 56 | |
| 57 for (int i = 0; i < len; ++i) { | |
| 58 hash = hash ^ uint128(0, octets[i]); | 72 hash = hash ^ uint128(0, octets[i]); |
| 59 hash = hash * kPrime; | 73 hash = hash * kPrime; |
| 60 } | 74 } |
| 61 | |
| 62 return hash; | 75 return hash; |
| 63 } | 76 } |
| 64 | 77 |
| 65 // static | 78 // static |
| 66 bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, | 79 bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, |
| 67 const QuicTag* their_tags, | 80 const QuicTag* their_tags, |
| 68 size_t num_their_tags, | 81 size_t num_their_tags, |
| 69 Priority priority, | 82 Priority priority, |
| 70 QuicTag* out_result, | 83 QuicTag* out_result, |
| 71 size_t* out_index) { | 84 size_t* out_index) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 RETURN_STRING_LITERAL(QUIC_CRYPTO_DUPLICATE_TAG); | 227 RETURN_STRING_LITERAL(QUIC_CRYPTO_DUPLICATE_TAG); |
| 215 RETURN_STRING_LITERAL(QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT); | 228 RETURN_STRING_LITERAL(QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT); |
| 216 RETURN_STRING_LITERAL(QUIC_CRYPTO_SERVER_CONFIG_EXPIRED); | 229 RETURN_STRING_LITERAL(QUIC_CRYPTO_SERVER_CONFIG_EXPIRED); |
| 217 RETURN_STRING_LITERAL(QUIC_INVALID_CHANNEL_ID_SIGNATURE); | 230 RETURN_STRING_LITERAL(QUIC_INVALID_CHANNEL_ID_SIGNATURE); |
| 218 RETURN_STRING_LITERAL(QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED); | 231 RETURN_STRING_LITERAL(QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED); |
| 219 RETURN_STRING_LITERAL(QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO); | 232 RETURN_STRING_LITERAL(QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO); |
| 220 RETURN_STRING_LITERAL(QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE); | 233 RETURN_STRING_LITERAL(QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE); |
| 221 RETURN_STRING_LITERAL(QUIC_VERSION_NEGOTIATION_MISMATCH); | 234 RETURN_STRING_LITERAL(QUIC_VERSION_NEGOTIATION_MISMATCH); |
| 222 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS); | 235 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS); |
| 223 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS); | 236 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS); |
| 237 RETURN_STRING_LITERAL(QUIC_CONNECTION_CANCELLED); |
| 224 RETURN_STRING_LITERAL(QUIC_LAST_ERROR); | 238 RETURN_STRING_LITERAL(QUIC_LAST_ERROR); |
| 225 // Intentionally have no default case, so we'll break the build | 239 // Intentionally have no default case, so we'll break the build |
| 226 // if we add errors and don't put them here. | 240 // if we add errors and don't put them here. |
| 227 } | 241 } |
| 228 // Return a default value so that we return this when |error| doesn't match | 242 // Return a default value so that we return this when |error| doesn't match |
| 229 // any of the QuicErrorCodes. This can happen when the ConnectionClose | 243 // any of the QuicErrorCodes. This can happen when the ConnectionClose |
| 230 // frame sent by the peer (attacker) has invalid error code. | 244 // frame sent by the peer (attacker) has invalid error code. |
| 231 return "INVALID_ERROR_CODE"; | 245 return "INVALID_ERROR_CODE"; |
| 232 } | 246 } |
| 233 | 247 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 QuicPriority QuicUtils::LowestPriority() { | 350 QuicPriority QuicUtils::LowestPriority() { |
| 337 return QuicWriteBlockedList::kLowestPriority; | 351 return QuicWriteBlockedList::kLowestPriority; |
| 338 } | 352 } |
| 339 | 353 |
| 340 // static | 354 // static |
| 341 QuicPriority QuicUtils::HighestPriority() { | 355 QuicPriority QuicUtils::HighestPriority() { |
| 342 return QuicWriteBlockedList::kHighestPriority; | 356 return QuicWriteBlockedList::kHighestPriority; |
| 343 } | 357 } |
| 344 | 358 |
| 345 } // namespace net | 359 } // namespace net |
| OLD | NEW |