1 // Copyright 2017 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/aead/aead_config.h"
18
19 #include "absl/memory/memory.h"
20 #include "absl/status/status.h"
21 #include "tink/aead/aead_wrapper.h"
22 #include "tink/aead/aes_ctr_hmac_aead_key_manager.h"
23 #include "tink/aead/aes_eax_key_manager.h"
24 #include "tink/aead/aes_gcm_key_manager.h"
25 #include "tink/aead/aes_gcm_proto_serialization.h"
26 #include "tink/aead/aes_gcm_siv_key_manager.h"
27 #include "tink/aead/kms_aead_key_manager.h"
28 #include "tink/aead/kms_envelope_aead_key_manager.h"
29 #include "tink/aead/xchacha20_poly1305_key_manager.h"
30 #include "tink/config/tink_fips.h"
31 #include "tink/mac/mac_config.h"
32 #include "tink/registry.h"
33 #include "tink/util/status.h"
34 #include "proto/config.pb.h"
35
36 namespace crypto {
37 namespace tink {
38 // static
Register()39 util::Status AeadConfig::Register() {
40 auto status = MacConfig::Register();
41 if (!status.ok()) return status;
42
43 // Register primitive wrapper.
44 status = Registry::RegisterPrimitiveWrapper(absl::make_unique<AeadWrapper>());
45 if (!status.ok()) return status;
46
47 // Register key managers which utilize the FIPS validated BoringCrypto
48 // implementations.
49 status = Registry::RegisterKeyTypeManager(
50 absl::make_unique<AesCtrHmacAeadKeyManager>(), true);
51 if (!status.ok()) return status;
52 status = Registry::RegisterKeyTypeManager(
53 absl::make_unique<AesGcmKeyManager>(), true);
54 if (!status.ok()) return status;
55
56 status = RegisterAesGcmProtoSerialization();
57 if (!status.ok()) return status;
58
59 if (IsFipsModeEnabled()) {
60 return util::OkStatus();
61 }
62
63 // Register all the other key managers.
64 status = Registry::RegisterKeyTypeManager(
65 absl::make_unique<AesGcmSivKeyManager>(), true);
66 if (!status.ok()) return status;
67 status = Registry::RegisterKeyTypeManager(
68 absl::make_unique<AesEaxKeyManager>(), true);
69 if (!status.ok()) return status;
70 status = Registry::RegisterKeyTypeManager(
71 absl::make_unique<XChaCha20Poly1305KeyManager>(), true);
72 if (!status.ok()) return status;
73 status = Registry::RegisterKeyTypeManager(
74 absl::make_unique<KmsAeadKeyManager>(), true);
75 if (!status.ok()) return status;
76 status = Registry::RegisterKeyTypeManager(
77 absl::make_unique<KmsEnvelopeAeadKeyManager>(), true);
78 if (!status.ok()) return status;
79
80 return util::OkStatus();
81 }
82
83 } // namespace tink
84 } // namespace crypto
85