xref: /aosp_15_r20/external/tink/cc/signature/signature_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/signature/signature_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/registry.h"
23 #include "tink/signature/ecdsa_verify_key_manager.h"
24 #include "tink/signature/ed25519_proto_serialization.h"
25 #include "tink/signature/ed25519_sign_key_manager.h"
26 #include "tink/signature/ed25519_verify_key_manager.h"
27 #include "tink/signature/public_key_sign_wrapper.h"
28 #include "tink/signature/public_key_verify_wrapper.h"
29 #include "tink/signature/rsa_ssa_pkcs1_sign_key_manager.h"
30 #include "tink/signature/rsa_ssa_pkcs1_verify_key_manager.h"
31 #include "tink/signature/rsa_ssa_pss_sign_key_manager.h"
32 #include "tink/signature/rsa_ssa_pss_verify_key_manager.h"
33 #include "tink/util/status.h"
34 #include "tink/signature/ecdsa_sign_key_manager.h"
35 #include "proto/config.pb.h"
36 
37 namespace crypto {
38 namespace tink {
39 
40 // static
Register()41 util::Status SignatureConfig::Register() {
42   // Register primitive wrappers.
43   auto status = Registry::RegisterPrimitiveWrapper(
44       absl::make_unique<PublicKeySignWrapper>());
45   if (!status.ok()) return status;
46   status = Registry::RegisterPrimitiveWrapper(
47       absl::make_unique<PublicKeyVerifyWrapper>());
48   if (!status.ok()) return status;
49 
50   // Register key managers which utilize FIPS validated BoringCrypto
51   // implementations.
52   // ECDSA
53   status = Registry::RegisterAsymmetricKeyManagers(
54       absl::make_unique<EcdsaSignKeyManager>(),
55       absl::make_unique<EcdsaVerifyKeyManager>(), true);
56   if (!status.ok()) return status;
57 
58   // RSA SSA PSS
59   status = Registry::RegisterAsymmetricKeyManagers(
60       absl::make_unique<RsaSsaPssSignKeyManager>(),
61       absl::make_unique<RsaSsaPssVerifyKeyManager>(), true);
62   if (!status.ok()) return status;
63 
64   // RSA SSA PKCS1
65   status = Registry::RegisterAsymmetricKeyManagers(
66       absl::make_unique<RsaSsaPkcs1SignKeyManager>(),
67       absl::make_unique<RsaSsaPkcs1VerifyKeyManager>(), true);
68   if (!status.ok()) return status;
69 
70   if (IsFipsModeEnabled()) {
71     return util::OkStatus();
72   }
73 
74   // ED25519
75   status = Registry::RegisterAsymmetricKeyManagers(
76       absl::make_unique<Ed25519SignKeyManager>(),
77       absl::make_unique<Ed25519VerifyKeyManager>(), true);
78   if (!status.ok()) return status;
79 
80   status = RegisterEd25519ProtoSerialization();
81   if (!status.ok()) return status;
82 
83   return util::OkStatus();
84 }
85 
86 }  // namespace tink
87 }  // namespace crypto
88