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/crypto_utils.h" | 5 #include "net/quic/crypto/crypto_utils.h" |
6 | 6 |
7 #include "crypto/hkdf.h" | 7 #include "crypto/hkdf.h" |
8 #include "net/quic/crypto/crypto_handshake.h" | 8 #include "net/quic/crypto/crypto_handshake.h" |
9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
10 #include "net/quic/crypto/quic_decrypter.h" | 10 #include "net/quic/crypto/quic_decrypter.h" |
11 #include "net/quic/crypto/quic_encrypter.h" | 11 #include "net/quic/crypto/quic_encrypter.h" |
12 #include "net/quic/crypto/quic_random.h" | 12 #include "net/quic/crypto/quic_random.h" |
13 #include "net/quic/quic_time.h" | 13 #include "net/quic/quic_time.h" |
14 | 14 |
15 using base::StringPiece; | 15 using base::StringPiece; |
16 using std::string; | 16 using std::string; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 // static | |
21 bool CryptoUtils::FindMutualTag(const QuicTagVector& our_tags_vector, | |
22 const QuicTag* their_tags, | |
23 size_t num_their_tags, | |
24 Priority priority, | |
25 QuicTag* out_result, | |
26 size_t* out_index) { | |
27 if (our_tags_vector.empty()) { | |
28 return false; | |
29 } | |
30 const size_t num_our_tags = our_tags_vector.size(); | |
31 const QuicTag* our_tags = &our_tags_vector[0]; | |
32 | |
33 size_t num_priority_tags, num_inferior_tags; | |
34 const QuicTag* priority_tags; | |
35 const QuicTag* inferior_tags; | |
36 if (priority == LOCAL_PRIORITY) { | |
37 num_priority_tags = num_our_tags; | |
38 priority_tags = our_tags; | |
39 num_inferior_tags = num_their_tags; | |
40 inferior_tags = their_tags; | |
41 } else { | |
42 num_priority_tags = num_their_tags; | |
43 priority_tags = their_tags; | |
44 num_inferior_tags = num_our_tags; | |
45 inferior_tags = our_tags; | |
46 } | |
47 | |
48 for (size_t i = 0; i < num_priority_tags; i++) { | |
49 for (size_t j = 0; j < num_inferior_tags; j++) { | |
50 if (priority_tags[i] == inferior_tags[j]) { | |
51 *out_result = priority_tags[i]; | |
52 if (out_index) { | |
53 if (priority == LOCAL_PRIORITY) { | |
54 *out_index = j; | |
55 } else { | |
56 *out_index = i; | |
57 } | |
58 } | |
59 return true; | |
60 } | |
61 } | |
62 } | |
63 | |
64 return false; | |
65 } | |
66 | |
67 void CryptoUtils::GenerateNonce(QuicWallTime now, | 20 void CryptoUtils::GenerateNonce(QuicWallTime now, |
68 QuicRandom* random_generator, | 21 QuicRandom* random_generator, |
69 StringPiece orbit, | 22 StringPiece orbit, |
70 string* nonce) { | 23 string* nonce) { |
71 // a 4-byte timestamp + 28 random bytes. | 24 // a 4-byte timestamp + 28 random bytes. |
72 nonce->reserve(kNonceSize); | 25 nonce->reserve(kNonceSize); |
73 nonce->resize(kNonceSize); | 26 nonce->resize(kNonceSize); |
74 uint32 gmt_unix_time = now.ToUNIXSeconds(); | 27 uint32 gmt_unix_time = now.ToUNIXSeconds(); |
75 // The time in the nonce must be encoded in big-endian because the | 28 // The time in the nonce must be encoded in big-endian because the |
76 // strike-register depends on the nonces being ordered by time. | 29 // strike-register depends on the nonces being ordered by time. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 out->decrypter->SetNoncePrefix(hkdf.client_write_iv()); | 69 out->decrypter->SetNoncePrefix(hkdf.client_write_iv()); |
117 } else { | 70 } else { |
118 out->encrypter->SetKey(hkdf.client_write_key()); | 71 out->encrypter->SetKey(hkdf.client_write_key()); |
119 out->encrypter->SetNoncePrefix(hkdf.client_write_iv()); | 72 out->encrypter->SetNoncePrefix(hkdf.client_write_iv()); |
120 out->decrypter->SetKey(hkdf.server_write_key()); | 73 out->decrypter->SetKey(hkdf.server_write_key()); |
121 out->decrypter->SetNoncePrefix(hkdf.server_write_iv()); | 74 out->decrypter->SetNoncePrefix(hkdf.server_write_iv()); |
122 } | 75 } |
123 } | 76 } |
124 | 77 |
125 } // namespace net | 78 } // namespace net |
OLD | NEW |