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