Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: net/quic/crypto/crypto_secret_boxer.h

Issue 213473003: This change introduces a way to tie source address token keys to specific QUIC server configs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge internal change: 65382861 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_ 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_
6 #define NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_ 6 #define NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
11 #include "net/base/net_export.h" 12 #include "net/base/net_export.h"
13 #include "net/quic/crypto/crypto_protocol.h"
wtc 2014/04/22 19:12:10 We should not need to include this header.
ramant (doing other things) 2014/04/25 23:40:58 Done.
14 #include "net/quic/crypto/quic_decrypter.h"
15 #include "net/quic/crypto/quic_encrypter.h"
wtc 2014/04/22 19:12:10 Nit: using a forward declaration of QuicDecrypter
ramant (doing other things) 2014/04/25 23:40:58 Was running into compilation errors ../../net/qui
wtc 2014/04/28 18:44:58 Now the |encrypter_| member is a scoped_ptr: sc
ramant (doing other things) 2014/04/29 00:31:18 Deleted the include files. Done.
12 16
13 namespace net { 17 namespace net {
14 18
15 class QuicRandom; 19 class QuicRandom;
16 20
17 // CryptoSecretBoxer encrypts small chunks of plaintext (called 'boxing') and 21 // CryptoSecretBoxer encrypts small chunks of plaintext (called 'boxing') and
18 // then, later, can authenticate+decrypt the resulting boxes. This object is 22 // then, later, can authenticate+decrypt the resulting boxes. This object is
19 // thread-safe. 23 // thread-safe.
20 class NET_EXPORT_PRIVATE CryptoSecretBoxer { 24 class NET_EXPORT_PRIVATE CryptoSecretBoxer {
21 public: 25 public:
22 // GetKeySize returns the number of bytes in a key. 26 // GetKeySize returns the number of bytes in a key.
23 static size_t GetKeySize(); 27 static size_t GetKeySize();
wtc 2014/04/22 19:12:10 The Style Guide recommends that static methods sho
ramant (doing other things) 2014/04/25 23:40:58 Done.
24 28
29 // Initializes |encrypter_| and |decrypter_| data members.
30 CryptoSecretBoxer();
31 virtual ~CryptoSecretBoxer();
wtc 2014/04/22 19:12:10 Since this class has no virtual methods, I think t
ramant (doing other things) 2014/04/25 23:40:58 Done.
32
25 // SetKey sets the key for this object. This must be done before |Box| or 33 // SetKey sets the key for this object. This must be done before |Box| or
26 // |Unbox| are called. |key| must be |GetKeySize()| bytes long. 34 // |Unbox| are called. |key| must be |GetKeySize()| bytes long.
27 void SetKey(base::StringPiece key); 35 void SetKey(base::StringPiece key);
28 36
29 // Box encrypts |plaintext| using a random nonce generated from |rand| and 37 // Box encrypts |plaintext| using a random nonce generated from |rand| and
30 // returns the resulting ciphertext. Since an authenticator and nonce are 38 // returns the resulting ciphertext. Since an authenticator and nonce are
31 // included, the result will be slightly larger than |plaintext|. 39 // included, the result will be slightly larger than |plaintext|.
32 std::string Box(QuicRandom* rand, base::StringPiece plaintext) const; 40 std::string Box(QuicRandom* rand, base::StringPiece plaintext) const;
33 41
34 // Unbox takes the result of a previous call to |Box| in |ciphertext| and 42 // Unbox takes the result of a previous call to |Box| in |ciphertext| and
35 // authenticates+decrypts it. If |ciphertext| is not authentic then it 43 // authenticates+decrypts it. If |ciphertext| is not authentic then it
36 // returns false. Otherwise, |out_storage| is used to store the result and 44 // returns false. Otherwise, |out_storage| is used to store the result and
37 // |out| is set to point into |out_storage| and contains the original 45 // |out| is set to point into |out_storage| and contains the original
38 // plaintext. 46 // plaintext.
39 bool Unbox(base::StringPiece ciphertext, 47 bool Unbox(base::StringPiece ciphertext,
40 std::string* out_storage, 48 std::string* out_storage,
41 base::StringPiece* out) const; 49 base::StringPiece* out) const;
42 50
43 private: 51 private:
44 std::string key_; 52 std::string key_;
wtc 2014/04/22 19:12:10 Remove the key_ member. I explain this in the .cc
ramant (doing other things) 2014/04/25 23:40:58 nit/small concern: this file is diverging from int
wtc 2014/04/28 18:44:58 That's true. I think we can keep the .h files in s
ramant (doing other things) 2014/04/29 00:31:18 Done.
53 scoped_ptr<QuicEncrypter> encrypter_;
54 scoped_ptr<QuicDecrypter> decrypter_;
55
56 DISALLOW_COPY_AND_ASSIGN(CryptoSecretBoxer);
45 }; 57 };
46 58
47 } // namespace net 59 } // namespace net
48 60
49 #endif // NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_ 61 #endif // NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_
OLDNEW
« no previous file with comments | « no previous file | net/quic/crypto/crypto_secret_boxer.cc » ('j') | net/quic/crypto/crypto_secret_boxer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698