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_MAC_H_ 18 #define TINK_MAC_H_ 19 20 #include <string> 21 22 #include "absl/strings/string_view.h" 23 #include "tink/util/status.h" 24 #include "tink/util/statusor.h" 25 26 namespace crypto { 27 namespace tink { 28 29 /////////////////////////////////////////////////////////////////////////////// 30 // Interface for MACs (Message Authentication Codes). 31 // This interface should be used for authentication only, and not for other 32 // purposes (e.g., it should not be used to generate pseudorandom bytes). 33 class Mac { 34 public: 35 // Computes and returns the message authentication code (MAC) for 'data'. 36 virtual crypto::tink::util::StatusOr<std::string> ComputeMac( 37 absl::string_view data) const = 0; 38 39 // Verifies if 'mac' is a correct authentication code (MAC) for 'data'. 40 // Returns Status::OK if 'mac' is correct, and a non-OK-Status otherwise. 41 virtual crypto::tink::util::Status VerifyMac( 42 absl::string_view mac_value, 43 absl::string_view data) const = 0; 44 45 virtual ~Mac() = default; 46 }; 47 48 } // namespace tink 49 } // namespace crypto 50 51 #endif // TINK_MAC_H_ 52