Upload upstream chromium 67.0.3396
[platform/framework/web/chromium-efl.git] / crypto / aead.h
1 // Copyright 2015 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 CRYPTO_AEAD_H_
6 #define CRYPTO_AEAD_H_
7
8 #include <stddef.h>
9
10 #include <string>
11
12 #include "base/strings/string_piece.h"
13 #include "crypto/crypto_export.h"
14
15 struct evp_aead_st;
16
17 namespace crypto {
18
19 // This class exposes the AES-128-CTR-HMAC-SHA256 AEAD.
20 class CRYPTO_EXPORT Aead {
21  public:
22   enum AeadAlgorithm { AES_128_CTR_HMAC_SHA256 };
23
24   explicit Aead(AeadAlgorithm algorithm);
25
26   ~Aead();
27
28   void Init(const std::string* key);
29
30   bool Seal(base::StringPiece plaintext,
31             base::StringPiece nonce,
32             base::StringPiece additional_data,
33             std::string* ciphertext) const;
34
35   bool Open(base::StringPiece ciphertext,
36             base::StringPiece nonce,
37             base::StringPiece additional_data,
38             std::string* plaintext) const;
39
40   size_t KeyLength() const;
41
42   size_t NonceLength() const;
43
44  private:
45   const std::string* key_;
46   const evp_aead_st* aead_;
47 };
48
49 }  // namespace crypto
50
51 #endif  // CRYPTO_AEAD_H_