xref: /aosp_15_r20/external/tink/cc/aead/cord_aead.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2020 Google LLC
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 #ifndef TINK_AEAD_CORD_AEAD_H_
17 #define TINK_AEAD_CORD_AEAD_H_
18 
19 #include "absl/strings/cord.h"
20 #include "tink/util/statusor.h"
21 
22 namespace crypto {
23 namespace tink {
24 
25 ///////////////////////////////////////////////////////////////////////////////
26 // The interface for authenticated encryption with associated data.
27 // Implementations of this interface are secure against adaptive
28 // chosen ciphertext attacks.  Encryption with associated data ensures
29 // authenticity and integrity of that data, but not its secrecy.
30 // (see RFC 5116, https://tools.ietf.org/html/rfc5116)
31 //
32 // Implementations are expected to be thread safe.
33 class CordAead {
34  public:
35   // Encrypts 'plaintext' with 'associated_data' as associated data,
36   // and returns the resulting ciphertext.
37   // The ciphertext allows for checking authenticity and integrity
38   // of the associated data, but does not guarantee its secrecy.
39   // The ciphertext is returned as a Cord and protects the secrecy, authenticity
40   // and integrity of the plaintext.
41   // An implementation of this interface must ensure that the Cord-structure
42   // of the returned ciphertext gives no information about the Cord-structure
43   // of the given plaintext.
44   virtual crypto::tink::util::StatusOr<absl::Cord> Encrypt(
45       absl::Cord plaintext, absl::Cord associated_data) const = 0;
46 
47   // Decrypts 'ciphertext' with 'associated_data' as associated data,
48   // and returns the resulting plaintext.
49   // The decryption verifies the authenticity and integrity
50   // of the associated data, but there are no guarantees wrt. secrecy
51   // of that data.
52   // The plaintext is returned as a Cord. The structure of the Cord
53   // might differ from the original plaintext Cord, but the content will be the
54   // same.
55   virtual crypto::tink::util::StatusOr<absl::Cord> Decrypt(
56       absl::Cord ciphertext,
57       absl::Cord associated_data) const = 0;
58 
59   virtual ~CordAead() = default;
60 };
61 
62 }  // namespace tink
63 }  // namespace crypto
64 
65 #endif  // TINK_AEAD_CORD_AEAD_H_
66