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_verify_key_manager.h" 18 19 #include <memory> 20 21 #include "absl/memory/memory.h" 22 #include "absl/strings/str_cat.h" 23 #include "absl/strings/string_view.h" 24 #include "tink/experimental/pqcrypto/signature/subtle/falcon_subtle_utils.h" 25 #include "tink/experimental/pqcrypto/signature/subtle/falcon_verify.h" 26 #include "tink/public_key_verify.h" 27 #include "tink/util/errors.h" 28 #include "tink/util/input_stream_util.h" 29 #include "tink/util/protobuf_helper.h" 30 #include "tink/util/secret_data.h" 31 #include "tink/util/status.h" 32 #include "tink/util/statusor.h" 33 #include "tink/util/validation.h" 34 35 namespace crypto { 36 namespace tink { 37 38 using ::crypto::tink::subtle::FalconPublicKeyPqclean; 39 using ::crypto::tink::util::Status; 40 using ::crypto::tink::util::StatusOr; 41 using ::google::crypto::tink::FalconPublicKey; 42 43 StatusOr<std::unique_ptr<PublicKeyVerify>> Create(const FalconPublicKey & public_key) const44FalconVerifyKeyManager::PublicKeyVerifyFactory::Create( 45 const FalconPublicKey& public_key) const { 46 StatusOr<FalconPublicKeyPqclean> falcon_public_key_pqclean = 47 FalconPublicKeyPqclean::NewPublicKey(public_key.key_value()); 48 49 if (!falcon_public_key_pqclean.ok()) { 50 return falcon_public_key_pqclean.status(); 51 } 52 53 return subtle::FalconVerify::New(*falcon_public_key_pqclean); 54 } 55 ValidateKey(const FalconPublicKey & key) const56Status FalconVerifyKeyManager::ValidateKey(const FalconPublicKey& key) const { 57 Status status = ValidateVersion(key.version(), get_version()); 58 if (!status.ok()) { 59 return status; 60 } 61 62 status = subtle::ValidateFalconPublicKeySize(key.key_value().length()); 63 if (!status.ok()) { 64 return status; 65 } 66 67 return util::OkStatus(); 68 } 69 70 } // namespace tink 71 } // namespace crypto 72