xref: /aosp_15_r20/external/tink/cc/subtle/aes_cmac_boringssl.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_SUBTLE_AES_CMAC_BORINGSSL_H_
18 #define TINK_SUBTLE_AES_CMAC_BORINGSSL_H_
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 
24 #include "tink/internal/fips_utils.h"
25 #include "tink/mac.h"
26 #include "tink/util/secret_data.h"
27 #include "tink/util/statusor.h"
28 
29 namespace crypto {
30 namespace tink {
31 namespace subtle {
32 
33 class AesCmacBoringSsl : public Mac {
34  public:
35   static crypto::tink::util::StatusOr<std::unique_ptr<Mac>> New(
36       util::SecretData key, uint32_t tag_size);
37 
38   // Computes and returns the CMAC for 'data'.
39   crypto::tink::util::StatusOr<std::string> ComputeMac(
40       absl::string_view data) const override;
41 
42   // Verifies if 'mac' is a correct CMAC for 'data'.
43   // Returns Status::OK if 'mac' is correct, and a non-OK-Status otherwise.
44   crypto::tink::util::Status VerifyMac(absl::string_view mac,
45                                        absl::string_view data) const override;
46 
47   static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus =
48       crypto::tink::internal::FipsCompatibility::kNotFips;
49 
50  private:
AesCmacBoringSsl(util::SecretData key,uint32_t tag_size)51   AesCmacBoringSsl(util::SecretData key, uint32_t tag_size)
52       : key_(std::move(key)), tag_size_(tag_size) {}
53 
54   const util::SecretData key_;
55   const uint32_t tag_size_;
56 };
57 
58 }  // namespace subtle
59 }  // namespace tink
60 }  // namespace crypto
61 
62 #endif  // TINK_SUBTLE_AES_CMAC_BORINGSSL_H_
63