xref: /aosp_15_r20/external/tink/cc/keyderivation/key_derivation_config.cc (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2020 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 #include "tink/keyderivation/key_derivation_config.h"
18 
19 #include "tink/config/tink_fips.h"
20 #include "tink/keyderivation/internal/prf_based_deriver_key_manager.h"
21 #include "tink/keyderivation/keyset_deriver_wrapper.h"
22 #include "tink/prf/hkdf_prf_key_manager.h"
23 
24 namespace crypto {
25 namespace tink {
26 
27 // static
Register()28 util::Status KeyDerivationConfig::Register() {
29   // Register primitive wrappers.
30   util::Status status = Registry::RegisterPrimitiveWrapper(
31       absl::make_unique<KeysetDeriverWrapper>());
32   if (!status.ok()) {
33     return status;
34   }
35 
36   // Currently, no KeysetDeriver key managers only use FIPS-validated
37   // implementations, so none are registered in FIPS-only mode.
38   if (IsFipsModeEnabled()) {
39     return util::OkStatus();
40   }
41 
42   // Register required key manager for PrfBasedDeriverKeyManager.
43   status = Registry::RegisterKeyTypeManager(
44       absl::make_unique<HkdfPrfKeyManager>(), true);
45   if (!status.ok()) {
46     return status;
47   }
48 
49   // Register key managers.
50   return Registry::RegisterKeyTypeManager(
51       absl::make_unique<internal::PrfBasedDeriverKeyManager>(), true);
52 }
53 
54 }  // namespace tink
55 }  // namespace crypto
56