| 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 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 class QuicClock; | 19 class QuicTime; |
| 20 class QuicRandom; | 20 class QuicRandom; |
| 21 struct QuicCryptoNegotiatedParameters; | 21 struct QuicCryptoNegotiatedParameters; |
| 22 | 22 |
| 23 class NET_EXPORT_PRIVATE CryptoUtils { | 23 class NET_EXPORT_PRIVATE CryptoUtils { |
| 24 public: | 24 public: |
| 25 enum Priority { | 25 enum Priority { |
| 26 LOCAL_PRIORITY, | 26 LOCAL_PRIORITY, |
| 27 PEER_PRIORITY, | 27 PEER_PRIORITY, |
| 28 }; | 28 }; |
| 29 | 29 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 const CryptoTag* their_tags, | 44 const CryptoTag* their_tags, |
| 45 size_t num_their_tags, | 45 size_t num_their_tags, |
| 46 Priority priority, | 46 Priority priority, |
| 47 CryptoTag* out_result, | 47 CryptoTag* out_result, |
| 48 size_t* out_index); | 48 size_t* out_index); |
| 49 | 49 |
| 50 // Generates the connection nonce. The nonce is formed as: | 50 // Generates the connection nonce. The nonce is formed as: |
| 51 // <4 bytes> current time | 51 // <4 bytes> current time |
| 52 // <8 bytes> |orbit| (or random if |orbit| is empty) | 52 // <8 bytes> |orbit| (or random if |orbit| is empty) |
| 53 // <20 bytes> random | 53 // <20 bytes> random |
| 54 static void GenerateNonce(const QuicClock* clock, | 54 static void GenerateNonce(QuicTime::Delta now, |
| 55 QuicRandom* random_generator, | 55 QuicRandom* random_generator, |
| 56 const std::string& orbit, | 56 base::StringPiece orbit, |
| 57 std::string* nonce); | 57 std::string* nonce); |
| 58 | 58 |
| 59 // DeriveKeys populates the |encrypter| and |decrypter| members of |params| | 59 // DeriveKeys populates |params->encrypter| and |params->decrypter| given the |
| 60 // given the contents of |premaster_secret|, |nonce| and |hkdf_input|. | 60 // contents of |params->premaster_secret|, |client_nonce|, |
| 61 // |perspective| controls whether the server's keys are assigned to | 61 // |params->server_nonce| and |hkdf_input|. |perspective| controls whether |
| 62 // |encrypter| or |decrypter|. | 62 // the server's keys are assigned to |encrypter| or |decrypter|. |
| 63 // |params->server_nonce| is optional and, if non-empty, is mixed into the |
| 64 // key derivation. |
| 63 static void DeriveKeys(QuicCryptoNegotiatedParameters* params, | 65 static void DeriveKeys(QuicCryptoNegotiatedParameters* params, |
| 64 base::StringPiece nonce, | 66 base::StringPiece client_nonce, |
| 65 const std::string& hkdf_input, | 67 const std::string& hkdf_input, |
| 66 Perspective perspective); | 68 Perspective perspective); |
| 67 }; | 69 }; |
| 68 | 70 |
| 69 } // namespace net | 71 } // namespace net |
| 70 | 72 |
| 71 #endif // NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ | 73 #endif // NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ |
| OLD | NEW |