blob: 5802c7ef56138a031c2d24731d2d626c20bfd017 [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
Kim Paulhamus98e3cb92c2018-05-01 16:49:4219// This class exposes the AES-128-CTR-HMAC-SHA256 and AES_256_GCM AEAD.
estark03206a12015-04-25 04:52:2520class CRYPTO_EXPORT Aead {
21 public:
Martin Kreichgaueraa06bffa2018-06-29 07:54:1022 enum AeadAlgorithm { AES_128_CTR_HMAC_SHA256, AES_256_GCM, AES_256_GCM_SIV };
estark03206a12015-04-25 04:52:2523
24 explicit Aead(AeadAlgorithm algorithm);
25
26 ~Aead();
27
28 void Init(const std::string* key);
29
David Benjamincda45eb2017-11-06 18:16:5230 bool Seal(base::StringPiece plaintext,
31 base::StringPiece nonce,
32 base::StringPiece additional_data,
estark03206a12015-04-25 04:52:2533 std::string* ciphertext) const;
34
David Benjamincda45eb2017-11-06 18:16:5235 bool Open(base::StringPiece ciphertext,
36 base::StringPiece nonce,
37 base::StringPiece additional_data,
estark03206a12015-04-25 04:52:2538 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_