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