| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_QUIC_ENCRYPTER_H_ | 5 #ifndef NET_QUIC_CRYPTO_QUIC_ENCRYPTER_H_ |
| 6 #define NET_QUIC_CRYPTO_QUIC_ENCRYPTER_H_ | 6 #define NET_QUIC_CRYPTO_QUIC_ENCRYPTER_H_ |
| 7 | 7 |
| 8 #include "net/base/net_export.h" | 8 #include "net/base/net_export.h" |
| 9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
| 10 #include "net/quic/quic_protocol.h" | 10 #include "net/quic/quic_protocol.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 class NET_EXPORT_PRIVATE QuicEncrypter { | 14 class NET_EXPORT_PRIVATE QuicEncrypter { |
| 15 public: | 15 public: |
| 16 virtual ~QuicEncrypter() {} | 16 virtual ~QuicEncrypter() {} |
| 17 | 17 |
| 18 static QuicEncrypter* Create(CryptoTag algorithm); | 18 static QuicEncrypter* Create(CryptoTag algorithm); |
| 19 | 19 |
| 20 // Sets the encryption key. Returns true on success, false on failure. |
| 21 // |
| 22 // NOTE: The key is the client_write_key or server_write_key derived from |
| 23 // the master secret. |
| 24 virtual bool SetKey(base::StringPiece key) = 0; |
| 25 |
| 26 // Sets the fixed initial bytes of the nonce. Returns true on success, |
| 27 // false on failure. |
| 28 // |
| 29 // NOTE: The nonce prefix is the client_write_iv or server_write_iv |
| 30 // derived from the master secret. A 64-bit packet sequence number will |
| 31 // be appended to form the nonce. |
| 32 // |
| 33 // <------------ 64 bits -----------> |
| 34 // +---------------------+----------------------------------+ |
| 35 // | Fixed prefix | Packet sequence number | |
| 36 // +---------------------+----------------------------------+ |
| 37 // Nonce format |
| 38 // |
| 39 // The security of the nonce format requires that QUIC never reuse a |
| 40 // packet sequence number, even when retransmitting a lost packet. |
| 41 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) = 0; |
| 42 |
| 20 // Returns a newly created QuicData object containing the encrypted | 43 // Returns a newly created QuicData object containing the encrypted |
| 21 // |plaintext| as well as a MAC over both |plaintext| and |associated_data|, | 44 // |plaintext| as well as a MAC over both |plaintext| and |associated_data|, |
| 22 // or NULL if there is an error. | 45 // or NULL if there is an error. |sequence_number| is appended to the |
| 23 virtual QuicData* Encrypt(base::StringPiece associated_data, | 46 // |nonce_prefix| value provided in SetNoncePrefix() to form the nonce. |
| 47 virtual QuicData* Encrypt(QuicPacketSequenceNumber sequence_number, |
| 48 base::StringPiece associated_data, |
| 24 base::StringPiece plaintext) = 0; | 49 base::StringPiece plaintext) = 0; |
| 25 | 50 |
| 51 // GetKeySize() and GetNoncePrefixSize() tell the HKDF class how many bytes |
| 52 // of key material needs to be derived from the master secret. |
| 53 // NOTE: the sizes returned by GetKeySize() and GetNoncePrefixSize() are |
| 54 // also correct for the QuicDecrypter of the same algorithm. So only |
| 55 // QuicEncrypter has these two methods. |
| 56 |
| 57 // Returns the size in bytes of a key for the algorithm. |
| 58 virtual size_t GetKeySize() const = 0; |
| 59 // Returns the size in bytes of the fixed initial part of the nonce. |
| 60 virtual size_t GetNoncePrefixSize() const = 0; |
| 61 |
| 26 // Returns the maximum length of plaintext that can be encrypted | 62 // Returns the maximum length of plaintext that can be encrypted |
| 27 // to ciphertext no larger than |ciphertext_size|. | 63 // to ciphertext no larger than |ciphertext_size|. |
| 28 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) = 0; | 64 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const = 0; |
| 29 | 65 |
| 30 // Returns the length of the ciphertext that would be generated by encrypting | 66 // Returns the length of the ciphertext that would be generated by encrypting |
| 31 // to plaintext of size |plaintext_size|. | 67 // to plaintext of size |plaintext_size|. |
| 32 virtual size_t GetCiphertextSize(size_t plaintext_size) = 0; | 68 virtual size_t GetCiphertextSize(size_t plaintext_size) const = 0; |
| 33 | |
| 34 }; | 69 }; |
| 35 | 70 |
| 36 } // namespace net | 71 } // namespace net |
| 37 | 72 |
| 38 #endif // NET_QUIC_CRYPTO_QUIC_ENCRYPTER_H_ | 73 #endif // NET_QUIC_CRYPTO_QUIC_ENCRYPTER_H_ |
| OLD | NEW |