Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / quic / crypto / quic_decrypter.h
blob309834930969158c946cdf4585c2c595177ac31f
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
3 // found in the LICENSE file.
5 #ifndef NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_
6 #define NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_
8 #include "net/base/net_export.h"
9 #include "net/quic/quic_protocol.h"
11 namespace net {
13 class NET_EXPORT_PRIVATE QuicDecrypter {
14 public:
15 virtual ~QuicDecrypter() {}
17 static QuicDecrypter* Create(QuicTag algorithm);
19 // Sets the encryption key. Returns true on success, false on failure.
21 // NOTE: The key is the client_write_key or server_write_key derived from
22 // the master secret.
23 virtual bool SetKey(base::StringPiece key) = 0;
25 // Sets the fixed initial bytes of the nonce. Returns true on success,
26 // false on failure.
28 // NOTE: The nonce prefix is the client_write_iv or server_write_iv
29 // derived from the master secret. A 64-bit packet sequence number will
30 // be appended to form the nonce.
32 // <------------ 64 bits ----------->
33 // +---------------------+----------------------------------+
34 // | Fixed prefix | Packet sequence number |
35 // +---------------------+----------------------------------+
36 // Nonce format
38 // The security of the nonce format requires that QUIC never reuse a
39 // packet sequence number, even when retransmitting a lost packet.
40 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) = 0;
42 // Decrypt authenticates |associated_data| and |ciphertext| and then decrypts
43 // |ciphertext| into |output|, using |nonce|. |nonce| must be 8 bytes longer
44 // than the nonce prefix length returned by GetNoncePrefixSize() (of the
45 // encrypter). |output| must be as long as |ciphertext| on entry and, on
46 // successful return, the true length of the plaintext will be written to
47 // |*output_length|.
48 virtual bool Decrypt(base::StringPiece nonce,
49 base::StringPiece associated_data,
50 base::StringPiece ciphertext,
51 unsigned char* output,
52 size_t* output_length) = 0;
54 // Returns a newly created QuicData object containing the decrypted
55 // |ciphertext| or NULL if there is an error. |sequence_number| is
56 // appended to the |nonce_prefix| value provided in SetNoncePrefix()
57 // to form the nonce.
58 // TODO(wtc): add a way for DecryptPacket to report decryption failure due
59 // to non-authentic inputs, as opposed to other reasons for failure.
60 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number,
61 base::StringPiece associated_data,
62 base::StringPiece ciphertext) = 0;
64 // For use by unit tests only.
65 virtual base::StringPiece GetKey() const = 0;
66 virtual base::StringPiece GetNoncePrefix() const = 0;
69 } // namespace net
71 #endif // NET_QUIC_CRYPTO_QUIC_DECRYPTER_H_