xref: /aosp_15_r20/external/tink/cc/hybrid/hybrid_config.cc (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2018 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/hybrid/hybrid_config.h"
18 
19 #include "absl/memory/memory.h"
20 #include "tink/aead/aead_config.h"
21 #include "tink/config/config_util.h"
22 #include "tink/config/tink_fips.h"
23 #include "tink/hybrid/ecies_aead_hkdf_private_key_manager.h"
24 #include "tink/hybrid/ecies_aead_hkdf_public_key_manager.h"
25 #include "tink/hybrid/hybrid_decrypt_wrapper.h"
26 #include "tink/hybrid/hybrid_encrypt_wrapper.h"
27 #include "tink/registry.h"
28 #include "tink/util/status.h"
29 #include "proto/config.pb.h"
30 
31 namespace crypto {
32 namespace tink {
33 
34 // static
Register()35 util::Status HybridConfig::Register() {
36   auto status = AeadConfig::Register();
37   if (!status.ok()) return status;
38 
39   // Register primitive wrappers.
40   status = Registry::RegisterPrimitiveWrapper(
41       absl::make_unique<HybridEncryptWrapper>());
42   if (!status.ok()) return status;
43   status = Registry::RegisterPrimitiveWrapper(
44       absl::make_unique<HybridDecryptWrapper>());
45   if (!status.ok()) return status;
46 
47   // Currently there are no hybrid encryption key managers which only use
48   // FIPS-validated implementations, therefore none will be registered in
49   // FIPS only mode.
50   if (IsFipsModeEnabled()) {
51     return util::OkStatus();
52   }
53 
54   // Register non-FIPS key managers.
55   status = Registry::RegisterAsymmetricKeyManagers(
56       absl::make_unique<EciesAeadHkdfPrivateKeyManager>(),
57       absl::make_unique<EciesAeadHkdfPublicKeyManager>(), true);
58   if (!status.ok()) return status;
59 
60   return util::OkStatus();
61 }
62 
63 }  // namespace tink
64 }  // namespace crypto
65