xref: /aosp_15_r20/external/tink/cc/aead.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 #ifndef TINK_AEAD_H_
18 #define TINK_AEAD_H_
19 
20 #include <string>
21 
22 #include "absl/strings/string_view.h"
23 #include "tink/util/statusor.h"
24 
25 namespace crypto {
26 namespace tink {
27 
28 ///////////////////////////////////////////////////////////////////////////////
29 // The interface for authenticated encryption with associated data.
30 // Implementations of this interface are secure against adaptive
31 // chosen ciphertext attacks.  Encryption with associated data ensures
32 // authenticity and integrity of that data, but not its secrecy.
33 // (see RFC 5116, https://tools.ietf.org/html/rfc5116)
34 //
35 // Implementations are expected to be thread safe.
36 class Aead {
37  public:
38   // Encrypts 'plaintext' with 'associated_data' as associated data,
39   // and returns the resulting ciphertext.
40   // The ciphertext allows for checking authenticity and integrity
41   // of the associated data, but does not guarantee its secrecy.
42   virtual crypto::tink::util::StatusOr<std::string> Encrypt(
43       absl::string_view plaintext, absl::string_view associated_data) const = 0;
44 
45   // Decrypts 'ciphertext' with 'associated_data' as associated data,
46   // and returns the resulting plaintext.
47   // The decryption verifies the authenticity and integrity
48   // of the associated data, but there are no guarantees wrt. secrecy
49   // of that data.
50   virtual crypto::tink::util::StatusOr<std::string> Decrypt(
51       absl::string_view ciphertext,
52       absl::string_view associated_data) const = 0;
53 
54   virtual ~Aead() = default;
55 };
56 
57 }  // namespace tink
58 }  // namespace crypto
59 
60 #endif  // TINK_AEAD_H_
61