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 | |
estark | 03206a1 | 2015-04-25 04:52:25 | [diff] [blame] | 10 | #include "base/strings/string_piece.h" |
| 11 | #include "crypto/crypto_export.h" |
| 12 | |
| 13 | struct evp_aead_st; |
| 14 | |
| 15 | namespace crypto { |
| 16 | |
svaldez | 22de42fe | 2016-04-21 19:42:22 | [diff] [blame^] | 17 | // This class exposes the AES-128-CTR-HMAC-SHA256 AEAD. |
estark | 03206a1 | 2015-04-25 04:52:25 | [diff] [blame] | 18 | class CRYPTO_EXPORT Aead { |
| 19 | public: |
| 20 | enum AeadAlgorithm { AES_128_CTR_HMAC_SHA256 }; |
| 21 | |
| 22 | explicit Aead(AeadAlgorithm algorithm); |
| 23 | |
| 24 | ~Aead(); |
| 25 | |
| 26 | void Init(const std::string* key); |
| 27 | |
| 28 | bool Seal(const base::StringPiece& plaintext, |
| 29 | const base::StringPiece& nonce, |
| 30 | const base::StringPiece& additional_data, |
| 31 | std::string* ciphertext) const; |
| 32 | |
| 33 | bool Open(const base::StringPiece& ciphertext, |
| 34 | const base::StringPiece& nonce, |
| 35 | const base::StringPiece& additional_data, |
| 36 | std::string* plaintext) const; |
| 37 | |
| 38 | size_t KeyLength() const; |
| 39 | |
| 40 | size_t NonceLength() const; |
| 41 | |
| 42 | private: |
| 43 | const std::string* key_; |
| 44 | const evp_aead_st* aead_; |
| 45 | }; |
| 46 | |
| 47 | } // namespace crypto |
| 48 | |
| 49 | #endif // CRYPTO_ENCRYPTOR_H_ |