xref: /aosp_15_r20/external/tink/cc/subtle/mac/stateful_mac.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2019 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 
17 // The interface for stateful message authentication codes.
18 //
19 // WARNING: implementations of this interface are thread-compatible,
20 // but not thread-safe. Therefore, a streaming mac implemented with this
21 // interface is required to additionally enforce thread safety.
22 //
23 // This interface supports the implementation of both streaming
24 // and non-streaming MACs. It does not enforce thread-safety in order to avoid
25 // an unnecessary performance overhead for non-streaming MAC implementations.
26 
27 #ifndef TINK_SUBTLE_MAC_STATEFUL_MAC_H_
28 #define TINK_SUBTLE_MAC_STATEFUL_MAC_H_
29 
30 #include <memory>
31 #include <string>
32 
33 #include "absl/strings/string_view.h"
34 #include "tink/util/status.h"
35 #include "tink/util/statusor.h"
36 
37 namespace crypto {
38 namespace tink {
39 namespace subtle {
40 
41 class StatefulMac {
42  public:
43   StatefulMac() = default;
44   virtual ~StatefulMac() = default;
45 
46   virtual util::Status Update(absl::string_view data) = 0;
47   virtual util::StatusOr<std::string> Finalize() = 0;
48 };
49 
50 class StatefulMacFactory {
51  public:
52   virtual ~StatefulMacFactory() = default;
53 
54   virtual util::StatusOr<std::unique_ptr<StatefulMac>> Create() const = 0;
55 };
56 
57 }  // namespace subtle
58 }  // namespace tink
59 }  // namespace crypto
60 
61 #endif  // TINK_SUBTLE_MAC_STATEFUL_MAC_H_
62