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/falcon_key_template.h" 18 19 #include <memory> 20 21 #include "tink/experimental/pqcrypto/signature/subtle/falcon_subtle_utils.h" 22 #include "tink/util/constants.h" 23 #include "proto/experimental/pqcrypto/falcon.pb.h" 24 #include "proto/tink.pb.h" 25 26 namespace crypto { 27 namespace tink { 28 namespace { 29 30 using google::crypto::tink::FalconKeyFormat; 31 using google::crypto::tink::FalconPrivateKey; 32 using google::crypto::tink::KeyTemplate; 33 using google::crypto::tink::OutputPrefixType; 34 NewFalconKeyTemplate(int32_t key_size)35std::unique_ptr<KeyTemplate> NewFalconKeyTemplate(int32_t key_size) { 36 auto key_template = absl::make_unique<KeyTemplate>(); 37 key_template->set_type_url( 38 absl::StrCat(kTypeGoogleapisCom, FalconPrivateKey().GetTypeName())); 39 key_template->set_output_prefix_type(OutputPrefixType::TINK); 40 41 FalconKeyFormat key_format; 42 key_format.set_key_size(key_size); 43 key_format.SerializeToString(key_template->mutable_value()); 44 45 return key_template; 46 } 47 48 } // anonymous namespace 49 Falcon512KeyTemplate()50const google::crypto::tink::KeyTemplate& Falcon512KeyTemplate() { 51 static const KeyTemplate* key_template = 52 NewFalconKeyTemplate(subtle::kFalcon512PrivateKeySize).release(); 53 return *key_template; 54 } 55 Falcon1024KeyTemplate()56const google::crypto::tink::KeyTemplate& Falcon1024KeyTemplate() { 57 static const KeyTemplate* key_template = 58 NewFalconKeyTemplate(subtle::kFalcon1024PrivateKeySize).release(); 59 return *key_template; 60 } 61 62 } // namespace tink 63 } // namespace crypto 64