Chromium Code Reviews| 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 #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" | |
| 11 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| 12 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
| 13 #include "net/quic/crypto/quic_decrypter.h" | |
| 14 #include "net/quic/crypto/quic_encrypter.h" | |
| 15 | 12 |
| 16 namespace net { | 13 namespace net { |
| 17 | 14 |
| 18 class QuicRandom; | 15 class QuicRandom; |
| 19 | 16 |
| 20 // CryptoSecretBoxer encrypts small chunks of plaintext (called 'boxing') and | 17 // CryptoSecretBoxer encrypts small chunks of plaintext (called 'boxing') and |
| 21 // then, later, can authenticate+decrypt the resulting boxes. This object is | 18 // then, later, can authenticate+decrypt the resulting boxes. This object is |
| 22 // thread-safe. | 19 // thread-safe. |
| 23 class NET_EXPORT_PRIVATE CryptoSecretBoxer { | 20 class NET_EXPORT_PRIVATE CryptoSecretBoxer { |
| 24 public: | 21 public: |
| 25 // Initializes |encrypter_| and |decrypter_| data members. | 22 CryptoSecretBoxer() {} |
|
ramant (doing other things)
2014/04/29 00:41:49
Will merge this line into internal source tree.
| |
| 26 CryptoSecretBoxer(); | |
| 27 ~CryptoSecretBoxer(); | |
| 28 | 23 |
| 29 // GetKeySize returns the number of bytes in a key. | 24 // GetKeySize returns the number of bytes in a key. |
| 30 static size_t GetKeySize(); | 25 static size_t GetKeySize(); |
| 31 | 26 |
| 32 // SetKey sets the key for this object. This must be done before |Box| or | 27 // SetKey sets the key for this object. This must be done before |Box| or |
| 33 // |Unbox| are called. |key| must be |GetKeySize()| bytes long. Returns false | 28 // |Unbox| are called. |key| must be |GetKeySize()| bytes long. |
| 34 // if |encrypter_| or |decrypter_|'s SetKey method fails. | 29 void SetKey(base::StringPiece key); |
| 35 bool SetKey(base::StringPiece key); | |
| 36 | 30 |
| 37 // Box encrypts |plaintext| using a random nonce generated from |rand| and | 31 // Box encrypts |plaintext| using a random nonce generated from |rand| and |
| 38 // returns the resulting ciphertext. Since an authenticator and nonce are | 32 // returns the resulting ciphertext. Since an authenticator and nonce are |
| 39 // included, the result will be slightly larger than |plaintext|. | 33 // included, the result will be slightly larger than |plaintext|. |
| 40 std::string Box(QuicRandom* rand, base::StringPiece plaintext) const; | 34 std::string Box(QuicRandom* rand, base::StringPiece plaintext) const; |
| 41 | 35 |
| 42 // Unbox takes the result of a previous call to |Box| in |ciphertext| and | 36 // Unbox takes the result of a previous call to |Box| in |ciphertext| and |
| 43 // authenticates+decrypts it. If |ciphertext| is not authentic then it | 37 // authenticates+decrypts it. If |ciphertext| is not authentic then it |
| 44 // returns false. Otherwise, |out_storage| is used to store the result and | 38 // returns false. Otherwise, |out_storage| is used to store the result and |
| 45 // |out| is set to point into |out_storage| and contains the original | 39 // |out| is set to point into |out_storage| and contains the original |
| 46 // plaintext. | 40 // plaintext. |
| 47 bool Unbox(base::StringPiece ciphertext, | 41 bool Unbox(base::StringPiece ciphertext, |
| 48 std::string* out_storage, | 42 std::string* out_storage, |
| 49 base::StringPiece* out) const; | 43 base::StringPiece* out) const; |
| 50 | 44 |
| 51 private: | 45 private: |
| 52 scoped_ptr<QuicEncrypter> encrypter_; | 46 std::string key_; |
| 53 scoped_ptr<QuicDecrypter> decrypter_; | |
| 54 | 47 |
| 55 DISALLOW_COPY_AND_ASSIGN(CryptoSecretBoxer); | 48 DISALLOW_COPY_AND_ASSIGN(CryptoSecretBoxer); |
|
ramant (doing other things)
2014/04/29 00:41:49
Will merge this line into internal source tree.
| |
| 56 }; | 49 }; |
| 57 | 50 |
| 58 } // namespace net | 51 } // namespace net |
| 59 | 52 |
| 60 #endif // NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_ | 53 #endif // NET_QUIC_CRYPTO_CRYPTO_SECRET_BOXER_H_ |
| OLD | NEW |