xref: /aosp_15_r20/external/tink/cc/experimental/pqcrypto/signature/signature_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/experimental/pqcrypto/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/experimental/pqcrypto/signature/dilithium_sign_key_manager.h"
23 #include "tink/experimental/pqcrypto/signature/dilithium_verify_key_manager.h"
24 #include "tink/experimental/pqcrypto/signature/falcon_sign_key_manager.h"
25 #include "tink/experimental/pqcrypto/signature/falcon_verify_key_manager.h"
26 #include "tink/experimental/pqcrypto/signature/sphincs_sign_key_manager.h"
27 #include "tink/experimental/pqcrypto/signature/sphincs_verify_key_manager.h"
28 #include "tink/registry.h"
29 #include "tink/signature/public_key_sign_wrapper.h"
30 #include "tink/signature/public_key_verify_wrapper.h"
31 #include "tink/util/status.h"
32 #include "proto/config.pb.h"
33 
34 namespace crypto {
35 namespace tink {
36 
PqSignatureConfigRegister()37 util::Status PqSignatureConfigRegister() {
38   // Register primitive wrappers.
39   auto status = Registry::RegisterPrimitiveWrapper(
40       absl::make_unique<PublicKeySignWrapper>());
41   if (!status.ok()) return status;
42   status = Registry::RegisterPrimitiveWrapper(
43       absl::make_unique<PublicKeyVerifyWrapper>());
44   if (!status.ok()) return status;
45 
46   if (IsFipsModeEnabled()) {
47     return util::OkStatus();
48   }
49 
50   // Dilithium
51   status = Registry::RegisterAsymmetricKeyManagers(
52       absl::make_unique<DilithiumSignKeyManager>(),
53       absl::make_unique<DilithiumVerifyKeyManager>(), true);
54 
55   // Sphincs
56   status = Registry::RegisterAsymmetricKeyManagers(
57       absl::make_unique<SphincsSignKeyManager>(),
58       absl::make_unique<SphincsVerifyKeyManager>(), true);
59 
60   // Falcon
61   status = Registry::RegisterAsymmetricKeyManagers(
62       absl::make_unique<FalconSignKeyManager>(),
63       absl::make_unique<FalconVerifyKeyManager>(), true);
64   return status;
65 }
66 
67 }  // namespace tink
68 }  // namespace crypto
69