forked from tink-crypto/tink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding C++ HybridConfig, to replace HybridEncrypt/Decrypt-Configs.
PiperOrigin-RevId: 191628409 GitOrigin-RevId: 133207901a7eeea3973c966dd79cbc98a4c5348a
- Loading branch information
Showing
12 changed files
with
370 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "tink/hybrid/hybrid_config.h" | ||
|
||
#include "tink/config.h" | ||
#include "tink/aead/aead_config.h" | ||
#include "tink/hybrid/hybrid_decrypt_catalogue.h" | ||
#include "tink/hybrid/hybrid_encrypt_catalogue.h" | ||
#include "tink/util/status.h" | ||
#include "proto/config.pb.h" | ||
|
||
namespace util = crypto::tink::util; | ||
|
||
namespace crypto { | ||
namespace tink { | ||
|
||
namespace { | ||
|
||
google::crypto::tink::RegistryConfig* GenerateRegistryConfig() { | ||
google::crypto::tink::RegistryConfig* config = | ||
new google::crypto::tink::RegistryConfig(); | ||
config->MergeFrom(AeadConfig::Tink_1_1_0()); | ||
config->add_entry()->MergeFrom(*Config::GetTinkKeyTypeEntry( | ||
HybridConfig::kHybridDecryptCatalogueName, | ||
HybridConfig::kHybridDecryptPrimitiveName, | ||
"EciesAeadHkdfPrivateKey", 0, true)); | ||
config->add_entry()->MergeFrom(*Config::GetTinkKeyTypeEntry( | ||
HybridConfig::kHybridEncryptCatalogueName, | ||
HybridConfig::kHybridEncryptPrimitiveName, | ||
"EciesAeadHkdfPublicKey", 0, true)); | ||
config->set_config_name("TINK_HYBRID_1_1_0"); | ||
return config; | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
constexpr char HybridConfig::kHybridDecryptCatalogueName[]; | ||
constexpr char HybridConfig::kHybridDecryptPrimitiveName[]; | ||
constexpr char HybridConfig::kHybridEncryptCatalogueName[]; | ||
constexpr char HybridConfig::kHybridEncryptPrimitiveName[]; | ||
|
||
// static | ||
const google::crypto::tink::RegistryConfig& HybridConfig::Tink_1_1_0() { | ||
static const auto config = GenerateRegistryConfig(); | ||
return *config; | ||
} | ||
|
||
// static | ||
util::Status HybridConfig::Init() { | ||
AeadConfig::Init(); | ||
auto status = Registry::AddCatalogue( | ||
kHybridDecryptCatalogueName, new HybridDecryptCatalogue()); | ||
if (!status.ok()) return status; | ||
return Registry::AddCatalogue( | ||
kHybridEncryptCatalogueName, new HybridEncryptCatalogue()); | ||
} | ||
|
||
} // namespace tink | ||
} // namespace crypto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef TINK_HYBRID_HYBRID_CONFIG_H_ | ||
#define TINK_HYBRID_HYBRID_CONFIG_H_ | ||
|
||
#include "tink/util/status.h" | ||
#include "proto/config.pb.h" | ||
|
||
namespace crypto { | ||
namespace tink { | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// Static methods and constants for registering with the Registry | ||
// all instances of hybrid encryption key types supported in a particular | ||
// release of Tink, i.e. key types that correspond to primitives | ||
// HybridEncrypt and HybridDecrypt. | ||
// | ||
// To register all hybrid encryption key types provided in Tink release 1.1.0 | ||
// one can do: | ||
// | ||
// auto status = Config::Register(HybridConfig::Tink_1_1_0()); | ||
// | ||
// For more information on creation and usage of instances of HybridDecrypt | ||
// and HybridDecrypt see HybridEncryptFactory resp. HybridDecryptFactory. | ||
class HybridConfig { | ||
public: | ||
static constexpr char kHybridDecryptCatalogueName[] = "TinkHybridDecrypt"; | ||
static constexpr char kHybridDecryptPrimitiveName[] = "HybridDecrypt"; | ||
static constexpr char kHybridEncryptCatalogueName[] = "TinkHybridEncrypt"; | ||
static constexpr char kHybridEncryptPrimitiveName[] = "HybridEncrypt"; | ||
|
||
// Returns config of HybridDecrypt implementations supported in Tink 1.1.0. | ||
static const google::crypto::tink::RegistryConfig& Tink_1_1_0(); | ||
|
||
// Initialization: | ||
// registers the catalogue of Tink HybridDecrypt-implementations. | ||
static crypto::tink::util::Status Init(); | ||
|
||
private: | ||
HybridConfig() {} | ||
}; | ||
|
||
} // namespace tink | ||
} // namespace crypto | ||
|
||
#endif // TINK_HYBRID_HYBRID_CONFIG_H_ |
Oops, something went wrong.