estark | 03206a1 | 2015-04-25 04:52:25 | [diff] [blame] | 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 | |
avi | dd373b8 | 2015-12-21 21:34:43 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
davidben | 6004dc5 | 2017-02-03 04:15:29 | [diff] [blame] | 10 | #include <string> |
| 11 | |
estark | 03206a1 | 2015-04-25 04:52:25 | [diff] [blame] | 12 | #include "base/strings/string_piece.h" |
| 13 | #include "crypto/crypto_export.h" |
| 14 | |
| 15 | struct evp_aead_st; |
| 16 | |
| 17 | namespace crypto { |
| 18 | |
svaldez | 22de42fe | 2016-04-21 19:42:22 | [diff] [blame] | 19 | // This class exposes the AES-128-CTR-HMAC-SHA256 AEAD. |
estark | 03206a1 | 2015-04-25 04:52:25 | [diff] [blame] | 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 | |
David Benjamin | cda45eb | 2017-11-06 18:16:52 | [diff] [blame^] | 30 | bool Seal(base::StringPiece plaintext, |
| 31 | base::StringPiece nonce, |
| 32 | base::StringPiece additional_data, |
estark | 03206a1 | 2015-04-25 04:52:25 | [diff] [blame] | 33 | std::string* ciphertext) const; |
| 34 | |
David Benjamin | cda45eb | 2017-11-06 18:16:52 | [diff] [blame^] | 35 | bool Open(base::StringPiece ciphertext, |
| 36 | base::StringPiece nonce, |
| 37 | base::StringPiece additional_data, |
estark | 03206a1 | 2015-04-25 04:52:25 | [diff] [blame] | 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 | |
davidben | 6004dc5 | 2017-02-03 04:15:29 | [diff] [blame] | 51 | #endif // CRYPTO_AEAD_H_ |