xref: /aosp_15_r20/external/tink/cc/mac/mac_config.cc (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 #include "tink/mac/mac_config.h"
18 
19 #include "absl/memory/memory.h"
20 #include "tink/config/config_util.h"
21 #include "tink/config/tink_fips.h"
22 #include "tink/mac/aes_cmac_key_manager.h"
23 #include "tink/mac/aes_cmac_proto_serialization.h"
24 #include "tink/mac/hmac_key_manager.h"
25 #include "tink/mac/hmac_proto_serialization.h"
26 #include "tink/mac/internal/chunked_mac_wrapper.h"
27 #include "tink/mac/mac_wrapper.h"
28 #include "tink/registry.h"
29 #include "tink/util/status.h"
30 #include "proto/config.pb.h"
31 
32 using google::crypto::tink::RegistryConfig;
33 
34 namespace crypto {
35 namespace tink {
36 
37 // static
Register()38 util::Status MacConfig::Register() {
39   // Register primitive wrappers.
40   auto status =
41       Registry::RegisterPrimitiveWrapper(absl::make_unique<MacWrapper>());
42   if (!status.ok()) return status;
43 
44   status = Registry::RegisterPrimitiveWrapper(
45       absl::make_unique<internal::ChunkedMacWrapper>());
46   if (!status.ok()) return status;
47 
48   // Register key managers which utilize the FIPS validated BoringCrypto
49   // implementations.
50   status = Registry::RegisterKeyTypeManager(absl::make_unique<HmacKeyManager>(),
51                                             true);
52   if (!status.ok()) return status;
53 
54   status = RegisterHmacProtoSerialization();
55   if (!status.ok()) return status;
56 
57   if (IsFipsModeEnabled()) {
58     return util::OkStatus();
59   }
60 
61   // CMac in BoringSSL is not FIPS validated.
62   status = Registry::RegisterKeyTypeManager(
63       absl::make_unique<AesCmacKeyManager>(), true);
64   if (!status.ok()) return status;
65 
66   status = RegisterAesCmacProtoSerialization();
67   if (!status.ok()) return status;
68 
69   return util::OkStatus();
70 }
71 
72 }  // namespace tink
73 }  // namespace crypto
74