| 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_DECRYPTER_H_ | 5 #ifndef NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_ |
| 6 #define NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_ | 6 #define NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // <------------ 64 bits -----------> | 35 // <------------ 64 bits -----------> |
| 36 // +---------------------+----------------------------------+ | 36 // +---------------------+----------------------------------+ |
| 37 // | Fixed prefix | packet number | | 37 // | Fixed prefix | packet number | |
| 38 // +---------------------+----------------------------------+ | 38 // +---------------------+----------------------------------+ |
| 39 // Nonce format | 39 // Nonce format |
| 40 // | 40 // |
| 41 // The security of the nonce format requires that QUIC never reuse a | 41 // The security of the nonce format requires that QUIC never reuse a |
| 42 // packet number, even when retransmitting a lost packet. | 42 // packet number, even when retransmitting a lost packet. |
| 43 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) = 0; | 43 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) = 0; |
| 44 | 44 |
| 45 // Sets the encryption key. Returns true on success, false on failure. |
| 46 // |DecryptPacket| may not be called until |SetDiversificationNonce| is |
| 47 // called and the preliminary keying material will be combined with that |
| 48 // nonce in order to create the actual key and nonce-prefix. |
| 49 // |
| 50 // If this function is called, neither |SetKey| nor |SetNoncePrefix| may be |
| 51 // called. |
| 52 virtual bool SetPreliminaryKey(base::StringPiece key) = 0; |
| 53 |
| 54 // SetDiversificationNonce uses |nonce| to derive final keys based on the |
| 55 // input keying material given by calling |SetPreliminaryKey|. |
| 56 // |
| 57 // Calling this function is a no-op if |SetPreliminaryKey| hasn't been |
| 58 // called. |
| 59 virtual bool SetDiversificationNonce(DiversificationNonce nonce) = 0; |
| 60 |
| 45 // Populates |output| with the decrypted |ciphertext| and populates | 61 // Populates |output| with the decrypted |ciphertext| and populates |
| 46 // |output_length| with the length. Returns 0 if there is an error. | 62 // |output_length| with the length. Returns 0 if there is an error. |
| 47 // |output| size is specified by |max_output_length| and must be | 63 // |output| size is specified by |max_output_length| and must be |
| 48 // at least as large as the ciphertext. |packet_number| is | 64 // at least as large as the ciphertext. |packet_number| is |
| 49 // appended to the |nonce_prefix| value provided in SetNoncePrefix() | 65 // appended to the |nonce_prefix| value provided in SetNoncePrefix() |
| 50 // to form the nonce. | 66 // to form the nonce. |
| 51 // TODO(wtc): add a way for DecryptPacket to report decryption failure due | 67 // TODO(wtc): add a way for DecryptPacket to report decryption failure due |
| 52 // to non-authentic inputs, as opposed to other reasons for failure. | 68 // to non-authentic inputs, as opposed to other reasons for failure. |
| 53 virtual bool DecryptPacket(QuicPathId path_id, | 69 virtual bool DecryptPacket(QuicPathId path_id, |
| 54 QuicPacketNumber packet_number, | 70 QuicPacketNumber packet_number, |
| 55 base::StringPiece associated_data, | 71 base::StringPiece associated_data, |
| 56 base::StringPiece ciphertext, | 72 base::StringPiece ciphertext, |
| 57 char* output, | 73 char* output, |
| 58 size_t* output_length, | 74 size_t* output_length, |
| 59 size_t max_output_length) = 0; | 75 size_t max_output_length) = 0; |
| 60 | 76 |
| 61 // The name of the cipher. | 77 // The name of the cipher. |
| 62 virtual const char* cipher_name() const = 0; | 78 virtual const char* cipher_name() const = 0; |
| 63 // The ID of the cipher. Return 0x03000000 ORed with the 'cryptographic suite | 79 // The ID of the cipher. Return 0x03000000 ORed with the 'cryptographic suite |
| 64 // selector'. | 80 // selector'. |
| 65 virtual uint32_t cipher_id() const = 0; | 81 virtual uint32_t cipher_id() const = 0; |
| 66 | 82 |
| 67 // For use by unit tests only. | 83 // For use by unit tests only. |
| 68 virtual base::StringPiece GetKey() const = 0; | 84 virtual base::StringPiece GetKey() const = 0; |
| 69 virtual base::StringPiece GetNoncePrefix() const = 0; | 85 virtual base::StringPiece GetNoncePrefix() const = 0; |
| 86 |
| 87 static void DiversifyPreliminaryKey(base::StringPiece preliminary_key, |
| 88 base::StringPiece nonce_prefix, |
| 89 DiversificationNonce nonce, |
| 90 size_t key_size, |
| 91 size_t nonce_prefix_size, |
| 92 std::string* out_key, |
| 93 std::string* out_nonce_prefix); |
| 70 }; | 94 }; |
| 71 | 95 |
| 72 } // namespace net | 96 } // namespace net |
| 73 | 97 |
| 74 #endif // NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_ | 98 #endif // NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_ |
| OLD | NEW |