chacha20_poly1305_encrypter.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1// Copyright 2014 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.
4
5#ifndef NET_QUIC_CRYPTO_CHACHA20_POLY1305_ENCRYPTER_H_
6#define NET_QUIC_CRYPTO_CHACHA20_POLY1305_ENCRYPTER_H_
7
8#include "net/quic/crypto/aead_base_encrypter.h"
9
10namespace net {
11
12// A ChaCha20Poly1305Encrypter is a QuicEncrypter that implements the
13// AEAD_CHACHA20_POLY1305 algorithm specified in
14// draft-agl-tls-chacha20poly1305-04. Create an instance by calling
15// QuicEncrypter::Create(kCC12).
16//
17// It uses an authentication tag of 16 bytes (128 bits). There is no
18// fixed nonce prefix.
19class NET_EXPORT_PRIVATE ChaCha20Poly1305Encrypter : public AeadBaseEncrypter {
20 public:
21  enum {
22    kAuthTagSize = 16,
23  };
24
25  ChaCha20Poly1305Encrypter();
26  virtual ~ChaCha20Poly1305Encrypter();
27
28  // Returns true if the underlying crypto library supports ChaCha20+Poly1305.
29  static bool IsSupported();
30
31#if !defined(USE_OPENSSL)
32 protected:
33  // AeadBaseEncrypter methods:
34  virtual void FillAeadParams(base::StringPiece nonce,
35                              base::StringPiece associated_data,
36                              size_t auth_tag_size,
37                              AeadParams* aead_params) const OVERRIDE;
38#endif
39};
40
41}  // namespace net
42
43#endif  // NET_QUIC_CRYPTO_CHACHA20_POLY1305_ENCRYPTER_H_
44