1 // Copyright 2019 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 #ifndef TINK_KEYDERIVATION_INTERNAL_PRF_BASED_DERIVER_H_ 18 #define TINK_KEYDERIVATION_INTERNAL_PRF_BASED_DERIVER_H_ 19 20 #include <memory> 21 #include <utility> 22 23 #include "tink/keyderivation/keyset_deriver.h" 24 #include "tink/keyset_handle.h" 25 #include "tink/subtle/prf/streaming_prf.h" 26 27 namespace crypto { 28 namespace tink { 29 namespace internal { 30 31 // The PrfBasedDeriver first uses a PRF to get some randomness, then gives this 32 // to the Tink registry to derive a key. 33 class PrfBasedDeriver : public KeysetDeriver { 34 public: 35 static crypto::tink::util::StatusOr<std::unique_ptr<KeysetDeriver>> New( 36 const ::google::crypto::tink::KeyData& prf_key, 37 const ::google::crypto::tink::KeyTemplate& key_template); 38 39 crypto::tink::util::StatusOr<std::unique_ptr<KeysetHandle>> DeriveKeyset( 40 absl::string_view salt) const override; 41 42 private: PrfBasedDeriver(std::unique_ptr<StreamingPrf> streaming_prf,const::google::crypto::tink::KeyTemplate & key_template)43 PrfBasedDeriver(std::unique_ptr<StreamingPrf> streaming_prf, 44 const ::google::crypto::tink::KeyTemplate& key_template) 45 : streaming_prf_(std::move(streaming_prf)), key_template_(key_template) {} 46 47 const ::std::unique_ptr<StreamingPrf> streaming_prf_; 48 const ::google::crypto::tink::KeyTemplate key_template_; 49 }; 50 51 } // namespace internal 52 } // namespace tink 53 } // namespace crypto 54 55 #endif // TINK_KEYDERIVATION_INTERNAL_PRF_BASED_DERIVER_H_ 56