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 // Some helpers for quic crypto | 5 // Some helpers for quic crypto |
6 | 6 |
7 #ifndef NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ | 7 #ifndef NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ |
8 #define NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ | 8 #define NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
14 #include "net/quic/crypto/crypto_handshake.h" | 14 #include "net/quic/crypto/crypto_handshake.h" |
15 #include "net/quic/crypto/crypto_protocol.h" | 15 #include "net/quic/crypto/crypto_protocol.h" |
| 16 #include "net/quic/quic_time.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 class QuicTime; | 20 class QuicTime; |
20 class QuicRandom; | 21 class QuicRandom; |
21 struct QuicCryptoNegotiatedParameters; | 22 struct QuicCryptoNegotiatedParameters; |
22 | 23 |
23 class NET_EXPORT_PRIVATE CryptoUtils { | 24 class NET_EXPORT_PRIVATE CryptoUtils { |
24 public: | 25 public: |
25 enum Priority { | 26 enum Priority { |
26 LOCAL_PRIORITY, | 27 LOCAL_PRIORITY, |
27 PEER_PRIORITY, | 28 PEER_PRIORITY, |
28 }; | 29 }; |
29 | 30 |
30 enum Perspective { | 31 enum Perspective { |
31 SERVER, | 32 SERVER, |
32 CLIENT, | 33 CLIENT, |
33 }; | 34 }; |
34 | 35 |
35 // FindMutualTag sets |out_result| to the first tag in the priority list that | 36 // FindMutualTag sets |out_result| to the first tag in the priority list that |
36 // is also in the other list and returns true. If there is no intersection it | 37 // is also in the other list and returns true. If there is no intersection it |
37 // returns false. | 38 // returns false. |
38 // | 39 // |
39 // Which list has priority is determined by |priority|. | 40 // Which list has priority is determined by |priority|. |
40 // | 41 // |
41 // If |out_index| is non-NULL and a match is found then the index of that | 42 // If |out_index| is non-NULL and a match is found then the index of that |
42 // match in |their_tags| is written to |out_index|. | 43 // match in |their_tags| is written to |out_index|. |
43 static bool FindMutualTag(const CryptoTagVector& our_tags, | 44 static bool FindMutualTag(const QuicTagVector& our_tags, |
44 const CryptoTag* their_tags, | 45 const QuicTag* their_tags, |
45 size_t num_their_tags, | 46 size_t num_their_tags, |
46 Priority priority, | 47 Priority priority, |
47 CryptoTag* out_result, | 48 QuicTag* out_result, |
48 size_t* out_index); | 49 size_t* out_index); |
49 | 50 |
50 // Generates the connection nonce. The nonce is formed as: | 51 // Generates the connection nonce. The nonce is formed as: |
51 // <4 bytes> current time | 52 // <4 bytes> current time |
52 // <8 bytes> |orbit| (or random if |orbit| is empty) | 53 // <8 bytes> |orbit| (or random if |orbit| is empty) |
53 // <20 bytes> random | 54 // <20 bytes> random |
54 static void GenerateNonce(QuicTime::Delta now, | 55 static void GenerateNonce(QuicWallTime now, |
55 QuicRandom* random_generator, | 56 QuicRandom* random_generator, |
56 base::StringPiece orbit, | 57 base::StringPiece orbit, |
57 std::string* nonce); | 58 std::string* nonce); |
58 | 59 |
59 // DeriveKeys populates |params->encrypter| and |params->decrypter| given the | 60 // DeriveKeys populates |out->encrypter| and |out->decrypter| given the |
60 // contents of |params->premaster_secret|, |client_nonce|, | 61 // contents of |premaster_secret|, |client_nonce|, |server_nonce| and |
61 // |params->server_nonce| and |hkdf_input|. |perspective| controls whether | 62 // |hkdf_input|. |aead| determines which cipher will be used. |perspective| |
62 // the server's keys are assigned to |encrypter| or |decrypter|. | 63 // controls whether the server's keys are assigned to |encrypter| or |
63 // |params->server_nonce| is optional and, if non-empty, is mixed into the | 64 // |decrypter|. |server_nonce| is optional and, if non-empty, is mixed into |
64 // key derivation. | 65 // the key derivation. |
65 static void DeriveKeys(QuicCryptoNegotiatedParameters* params, | 66 static void DeriveKeys(base::StringPiece premaster_secret, |
| 67 QuicTag aead, |
66 base::StringPiece client_nonce, | 68 base::StringPiece client_nonce, |
| 69 base::StringPiece server_nonce, |
67 const std::string& hkdf_input, | 70 const std::string& hkdf_input, |
68 Perspective perspective); | 71 Perspective perspective, |
| 72 CrypterPair* out); |
69 }; | 73 }; |
70 | 74 |
71 } // namespace net | 75 } // namespace net |
72 | 76 |
73 #endif // NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ | 77 #endif // NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ |
OLD | NEW |