blob: 220ae42029d2e530c7062c51fd387a6be2ff72ea [file] [log] [blame]
estark03206a12015-04-25 04:52:251// 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
avidd373b8b2015-12-21 21:34:438#include <stddef.h>
9
davidben6004dc52017-02-03 04:15:2910#include <string>
11
estark03206a12015-04-25 04:52:2512#include "base/strings/string_piece.h"
13#include "crypto/crypto_export.h"
14
15struct evp_aead_st;
16
17namespace crypto {
18
svaldez22de42fe2016-04-21 19:42:2219// This class exposes the AES-128-CTR-HMAC-SHA256 AEAD.
estark03206a12015-04-25 04:52:2520class 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(const base::StringPiece& plaintext,
31 const base::StringPiece& nonce,
32 const base::StringPiece& additional_data,
33 std::string* ciphertext) const;
34
35 bool Open(const base::StringPiece& ciphertext,
36 const base::StringPiece& nonce,
37 const 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
davidben6004dc52017-02-03 04:15:2951#endif // CRYPTO_AEAD_H_